]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: avoid double counting NVMe devices in host facts 67669/head
authorUjjawal Anand <ujjawal.anand@ibm.com>
Thu, 5 Mar 2026 06:18:03 +0000 (11:48 +0530)
committerUjjawal Anand <ujjawal.anand@ibm.com>
Mon, 9 Mar 2026 06:36:52 +0000 (12:06 +0530)
- On some systems,the same NVMe drive appears twice in /sys/block,once as the real device
(ex: nvme2n1) and once as a sysfs only alias (ex: nvme2c2n1).
- To avoid counting the same disk twice, we filter /sys/block and only consider entries that have a
valid 'dev' attribute and a corresponding '/dev' node.

Fixes: https://tracker.ceph.com/issues/75342
Signed-off-by: Ujjawal Anand <ujjawal.anand@ibm.com>
src/cephadm/cephadmlib/host_facts.py
src/cephadm/tests/test_host_facts.py

index 387a4a3cb0a2b63a43d01284442a05ba20f85ab0..af5d2e23a67bcfc340046363a41910f6100bbe09 100644 (file)
@@ -222,6 +222,13 @@ class HostFacts:
             dev
             for dev in os.listdir('/sys/block')
             if not dev.startswith(HostFacts._excluded_block_devices)
+            # Some systems expose multiple /sys/block entries for the same NVMe drive
+            # (ex: nvme2n1 (the real disk) and nvme2c2n1(an extra sysfs alias).
+            # To avoid counting the same disk twice,only consider entries that
+            # represent a real block device (the one with a valid sysfs 'dev'
+            # attribute and a corresponding /dev node).
+            and os.path.exists(os.path.join('/sys/block', dev, 'dev'))
+            and os.path.exists(os.path.join('/dev', dev))
         ]
 
     @property
index a48089f77f6c8fda87f928b74d21fc0434aeaa43..8869ed257322ffedf40ab7417dd213415e54dadc 100644 (file)
@@ -115,3 +115,23 @@ def test_host_facts_security(cephadm_fs):
     assert ksec['complain'] == 0
     assert ksec['enforce'] == 1
     assert ksec['unconfined'] == 2
+
+
+def test_host_facts_skips_sysfs_only_nvme_alias_entries(cephadm_fs):
+    """
+    Some platforms expose extra /sys/block nvme entries that don't have a real
+    /dev node (ex:nvme2c2n1 alongside nvme2n1),duplicates should not be counted.
+    """
+    from cephadmlib.host_facts import HostFacts
+
+    # nvme2n1 is the "real" block device (has /sys/block/../dev and /dev/..).
+    cephadm_fs.create_dir('/dev')
+    cephadm_fs.create_dir('/sys/block/nvme2n1')
+    cephadm_fs.create_file('/sys/block/nvme2n1/dev', contents='259:7')
+    cephadm_fs.create_file('/dev/nvme2n1')
+
+    # nvme2c2n1 is a sysfs-only alias (no /dev node), and it should be ignored.
+    cephadm_fs.create_dir('/sys/block/nvme2c2n1')
+
+    hfacts = object.__new__(HostFacts)
+    assert hfacts._get_block_devs() == ['nvme2n1']