From: Hongtong Liu Date: Sun, 22 Jan 2017 09:25:04 +0000 (+0800) Subject: os/bluestore: fix NVMEDevice::open failure if serial number ends with a number X-Git-Tag: v12.0.0~109^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9caff5e4559e197021176b7f40a1da5ea9e038de;p=ceph.git os/bluestore: fix NVMEDevice::open failure if serial number ends with a number 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 --- diff --git a/src/os/bluestore/NVMEDevice.cc b/src/os/bluestore/NVMEDevice.cc index c0bccd7ddcafe..b38fad154aa78 100644 --- a/src/os/bluestore/NVMEDevice.cc +++ b/src/os/bluestore/NVMEDevice.cc @@ -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;