]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore: fix NVMEDevice::open failure if serial number ends with a number
authorHongtong Liu <hongtong.liu@istuary.com>
Sun, 22 Jan 2017 09:25:04 +0000 (17:25 +0800)
committerHongtong Liu <hongtong.liu@istuary.com>
Sun, 22 Jan 2017 09:25:04 +0000 (17:25 +0800)
buf in effect is the serial number in ceph.conf and
the serial number consists of 16 hexadecimal characters.
1. In order to avoid ignoring the numbers, scan buf
with isxdigit.
2. In order to ignore all the potential garbage,
scan buf from the beginning.

Signed-off-by: Hongtong Liu <hongtong.liu@istuary.com>
src/os/bluestore/NVMEDevice.cc

index c0bccd7ddcafe337cab5c6f4ef11effde08a9710..b38fad154aa78f475b24967ad12c2619555ae454 100644 (file)
@@ -798,10 +798,12 @@ int NVMEDevice::open(string p)
     derr << __func__ << " unable to read " << p << ": " << cpp_strerror(r) << dendl;
     return r;
   }
-  while (r > 0 && !isalpha(buf[r-1])) {
-    --r;
+  /* scan buf from the beginning with isxdigit. */
+  int i = 0;
+  while (i < r && isxdigit(buf[i])) {
+    i++;
   }
-  serial_number = string(buf, r);
+  serial_number = string(buf, i);
   r = manager.try_get(serial_number, &driver);
   if (r < 0) {
     derr << __func__ << " failed to get nvme device with sn " << serial_number << dendl;