From 9caff5e4559e197021176b7f40a1da5ea9e038de Mon Sep 17 00:00:00 2001 From: Hongtong Liu Date: Sun, 22 Jan 2017 17:25:04 +0800 Subject: [PATCH] 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 --- src/os/bluestore/NVMEDevice.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/os/bluestore/NVMEDevice.cc b/src/os/bluestore/NVMEDevice.cc index c0bccd7ddca..b38fad154aa 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; -- 2.39.5