@@ -807,6 +807,19 @@ def holder_inner_loop():
807807 result .append ([name , kname , "part" ])
808808 return sorted (result , key = lambda x : x [0 ])
809809
810+ def get_partitions (_sys_dev_block_path = '/sys/dev/block' ):
811+ devices = os .listdir (_sys_dev_block_path )
812+ result = dict ()
813+ for device in devices :
814+ device_path = os .path .join (_sys_dev_block_path , device )
815+ is_partition = get_file_contents (os .path .join (device_path , 'partition' )) == "1"
816+ if not is_partition :
817+ continue
818+
819+ partition_sys_name = os .path .basename (os .readlink (device_path ))
820+ parent_device_sys_name = os .readlink (device_path ).split ('/' )[- 2 :- 1 ][0 ]
821+ result [partition_sys_name ] = parent_device_sys_name
822+ return result
810823
811824def get_devices (_sys_block_path = '/sys/block' , device = '' ):
812825 """
@@ -822,8 +835,9 @@ def get_devices(_sys_block_path='/sys/block', device=''):
822835 device_facts = {}
823836
824837 block_devs = get_block_devs_sysfs (_sys_block_path )
838+ partitions = get_partitions ()
825839
826- block_types = ['disk' , 'mpath' , 'lvm' ]
840+ block_types = ['disk' , 'mpath' , 'lvm' , 'part' ]
827841 if allow_loop_devices ():
828842 block_types .append ('loop' )
829843
@@ -835,6 +849,8 @@ def get_devices(_sys_block_path='/sys/block', device=''):
835849 if block [2 ] not in block_types :
836850 continue
837851 sysdir = os .path .join (_sys_block_path , devname )
852+ if block [2 ] == 'part' :
853+ sysdir = os .path .join (_sys_block_path , partitions [devname ], devname )
838854 metadata = {}
839855
840856 # If the device is ceph rbd it gets excluded
@@ -862,11 +878,17 @@ def get_devices(_sys_block_path='/sys/block', device=''):
862878 for key , file_ in facts :
863879 metadata [key ] = get_file_contents (os .path .join (sysdir , file_ ))
864880
865- device_slaves = os .listdir (os .path .join (sysdir , 'slaves' ))
881+ if block [2 ] != 'part' :
882+ device_slaves = os .listdir (os .path .join (sysdir , 'slaves' ))
883+ metadata ['partitions' ] = get_partitions_facts (sysdir )
884+
866885 if device_slaves :
867886 metadata ['device_nodes' ] = ',' .join (device_slaves )
868887 else :
869- metadata ['device_nodes' ] = devname
888+ if block [2 ] == 'part' :
889+ metadata ['device_nodes' ] = partitions [devname ]
890+ else :
891+ metadata ['device_nodes' ] = devname
870892
871893 metadata ['actuators' ] = None
872894 if os .path .isdir (sysdir + "/queue/independent_access_ranges/" ):
0 commit comments