]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/blkdev: remove double _'s from device_id 41459/head
authorSage Weil <sage@newdream.net>
Thu, 20 May 2021 20:12:11 +0000 (15:12 -0500)
committerSage Weil <sage@newdream.net>
Thu, 20 May 2021 20:12:11 +0000 (15:12 -0500)
For some unknown reason some devices have double spaces in their
ID_MODEL_ENC string from udev:

cpach:build (devid-underscores) 03:10 PM $ udevadm  info /dev/sdt | grep ID_MODEL_ENC
E: ID_MODEL_ENC=WDC\x20\x20WDS400T2B0A-00SM50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
cpach:build (devid-underscores) 03:10 PM $ udevadm  info /dev/sdn | grep ID_MODEL_ENC
E: ID_MODEL_ENC=WDC\x20WDS200T2B0A-00SM50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20

It's not clear why this only happens on some devices and not others,
especially when they are the same model of device.  Regardless, removing
the duplicate ' '/'_' is straightforward.

Signed-off-by: Sage Weil <sage@newdream.net>
src/common/blkdev.cc
src/test/common/test_blkdev.cc

index 3fbffe65ae7115db81e0285e68be346fee6109b8..ca5e9eb0c5961747aa084680928fc430f4c11842 100644 (file)
@@ -429,6 +429,14 @@ std::string _decode_model_enc(const std::string& in)
     v.erase(found + 1);
   }
   std::replace(v.begin(), v.end(), ' ', '_');
+
+  // remove "__", which seems to come up on by ubuntu box for some reason.
+  while (true) {
+    auto p = v.find("__");
+    if (p == std::string::npos) break;
+    v.replace(p, 2, "_");
+  }
+
   return v;
 }
 
@@ -498,6 +506,12 @@ std::string get_device_id(const std::string& devname,
   udev_device_unref(dev);
   udev_unref(udev);
 
+  cout << " vendor '" << id_vendor << "'" << std::endl;
+  cout << " model '" << id_model << "'" << std::endl;
+  cout << " serial_short '" << id_serial_short << "'" << std::endl;
+  cout << " scsi_serial '" << id_scsi_serial << "'" << std::endl;
+  cout << " serial '" << id_serial << "'" << std::endl;
+
   // ID_SERIAL is usually $vendor_$model_$serial, but not always
   // ID_SERIAL_SHORT is mostly always just the serial
   // ID_MODEL is sometimes $vendor_$model, but
index 952fb84d1974c037a8cb9f23b31cf6e7d6ebe6ff..733273ad41eef3c4fc76deea70f227bf49b61e77 100644 (file)
@@ -99,3 +99,16 @@ TEST(blkdev, _decode_model_enc)
     ASSERT_EQ(std::string(foo[i][1]), d);
   }
 }
+
+TEST(blkdev, get_device_id)
+{
+  // this doesn't really test anything; it's just a way to exercise the
+  // get_device_id() code.
+  for (char c = 'a'; c < 'z'; ++c) {
+    char devname[4] = {'s', 'd', c, 0};
+    std::string err;
+    auto i = get_device_id(devname, &err);
+    cout << "devname " << devname << " -> '" << i
+        << "' (" << err << ")" << std::endl;
+  }
+}