mirror of
https://github.com/ceph/ceph
synced 2025-03-11 02:39:05 +00:00
Merge pull request #32440 from rosinL/wip-spdk
os/bluestore/spdk: Fix the overflow error of parsing spdk coremask Reviewed-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
commit
b57403de20
@ -561,6 +561,35 @@ static void attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
||||
ctx->manager->register_ctrlr(ctx->trid, ctrlr, &ctx->driver);
|
||||
}
|
||||
|
||||
static int hex2dec(unsigned char c)
|
||||
{
|
||||
if (isdigit(c))
|
||||
return c - '0';
|
||||
else if (isupper(c))
|
||||
return c - 'A' + 10;
|
||||
else
|
||||
return c - 'a' + 10;
|
||||
}
|
||||
|
||||
static int find_first_bitset(const string& s)
|
||||
{
|
||||
auto e = s.rend();
|
||||
if (s.compare(0, 2, "0x") == 0 ||
|
||||
s.compare(0, 2, "0X") == 0) {
|
||||
advance(e, -2);
|
||||
}
|
||||
auto p = s.rbegin();
|
||||
for (int pos = 0; p != e; ++p, pos += 4) {
|
||||
if (!isxdigit(*p)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
if (int val = hex2dec(*p); val != 0) {
|
||||
return pos + ffs(val);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int NVMEManager::try_get(const spdk_nvme_transport_id& trid, SharedDriverData **driver)
|
||||
{
|
||||
std::lock_guard l(lock);
|
||||
@ -572,17 +601,9 @@ int NVMEManager::try_get(const spdk_nvme_transport_id& trid, SharedDriverData **
|
||||
}
|
||||
|
||||
auto coremask_arg = g_conf().get_val<std::string>("bluestore_spdk_coremask");
|
||||
int m_core_arg = -1;
|
||||
try {
|
||||
auto core_value = stoull(coremask_arg, nullptr, 16);
|
||||
m_core_arg = ffsll(core_value);
|
||||
} catch (const std::logic_error& e) {
|
||||
derr << __func__ << " invalid bluestore_spdk_coremask: "
|
||||
<< coremask_arg << dendl;
|
||||
return -EINVAL;
|
||||
}
|
||||
int m_core_arg = find_first_bitset(coremask_arg);
|
||||
// at least one core is needed for using spdk
|
||||
if (m_core_arg == 0) {
|
||||
if (m_core_arg <= 0) {
|
||||
derr << __func__ << " invalid bluestore_spdk_coremask, "
|
||||
<< "at least one core is needed" << dendl;
|
||||
return -ENOENT;
|
||||
|
Loading…
Reference in New Issue
Block a user