Browse Source

Fix multipath device search

When nailgun-agent starts before device mapper
assembles multipath devices it reports physical disks
that are used for multipath devices as usual disks.

This patch does the following

* filter out devices that are DM_MULTIPATH_DEVICE_PATH = 1
* run 'udevadm settle' before scanning multipath devices
* delays scanning multipath devices until building block device info

Change-Id: I088aede0cf3bd1d16a57e7cdec4e50cab2c19175
Closes-Bug: #1652788
(cherry picked from commit 8fbc4d6405)
Vladimir Kozhukalov 2 years ago
parent
commit
fd0f4664b3
1 changed files with 27 additions and 13 deletions
  1. 27
    13
      agent

+ 27
- 13
agent View File

@@ -167,7 +167,6 @@ class NodeAgent
167 167
     @facter = facter_system_info
168 168
     @network = _network
169 169
     @numa_topology = get_numa_topology
170
-    @mpath_devices, @skip_devices = multipath_devices
171 170
   end
172 171
 
173 172
   def get_scheme_and_port
@@ -746,11 +745,13 @@ class NodeAgent
746 745
         # http://lxr.free-electrons.com/source/drivers/scsi/sd.c?v=4.4#L2340
747 746
         block_size = 512
748 747
 
748
+        mpath_devices, skip_devices = _multipath_devices
749
+
749 750
         (_get_blkdev_info or {} rescue {}).each do |bname, binfo|
750 751
           @logger.debug("Found block device: #{bname}")
751 752
           @logger.debug("Block device info: #{binfo.inspect}")
752 753
           dname = bname.gsub(/!/, '/')
753
-          next if @skip_devices.include?(dname)
754
+          next if skip_devices.include?(dname)
754 755
 
755 756
           if physical_data_storage_devices.map{|d| d[:name]}.include?(bname) && binfo
756 757
             @logger.debug("Block device seems to be physical data storage: #{bname}")
@@ -775,8 +776,8 @@ class NodeAgent
775 776
               :opt_io => get_opt_io.fetch(dname, block_size)
776 777
             }
777 778
 
778
-          elsif @mpath_devices.has_key?(dname)
779
-            device = @mpath_devices[dname]
779
+          elsif mpath_devices.has_key?(dname)
780
+            device = mpath_devices[dname]
780 781
             detailed_meta[:disks] << {
781 782
               :name => 'mapper/' + device["DM_NAME"],
782 783
               :model => binfo[:model],
@@ -807,8 +808,13 @@ class NodeAgent
807 808
     [nil, nil]
808 809
   end
809 810
 
810
-  def multipath_devices
811
-    dmsetup = `/sbin/dmsetup info -c --nameprefixes --noheadings -o blkdevname,subsystem,blkdevs_used,name,uuid`
811
+  def _multipath_devices
812
+    @logger.debug("Waiting for udev to complete evaluating rules")
813
+    `udevadm settle`
814
+
815
+    dmsetup_command = "/sbin/dmsetup info -c --nameprefixes --noheadings -o blkdevname,subsystem,blkdevs_used,name,uuid"
816
+    @logger.debug("Running command: #{dmsetup_command}")
817
+    dmsetup = `#{dmsetup_command}`
812 818
     # Example output:
813 819
     # DM_BLKDEVNAME='dm-0':DM_SUBSYSTEM='mpath':DM_BLKDEVS_USED='sdb,sda':DM_NAME='31234567890abcdef':DM_UUID='mpath-31234567890abcdef'
814 820
     # DM_BLKDEVNAME='dm-1':DM_SUBSYSTEM='mpath':DM_BLKDEVS_USED='sdc,sdd':DM_NAME='92344567890abcdef':DM_UUID='mpath-92344567890abcdef'
@@ -829,7 +835,10 @@ class NodeAgent
829 835
         end
830 836
         mpath_devices[device["DM_BLKDEVNAME"]] = device
831 837
       end
838
+      mapping.uniq!
832 839
     end
840
+    @logger.debug("Multipath devices: #{mpath_devices}")
841
+    @logger.debug("Physical devices that are used in multipath devices: #{mapping}")
833 842
     [mpath_devices, mapping]
834 843
   rescue => e
835 844
     @logger.error("Error '#{e.message}' while scanning for multipath devices.")
@@ -1013,6 +1022,9 @@ class NodeAgent
1013 1022
       end
1014 1023
       @logger.debug("Device #{devname} udev properties: #{properties.inspect}")
1015 1024
 
1025
+      @logger.debug("Filtering out devices that are used in multipath devices: 'DM_MULTIPATH_DEVICE_PATH' = '1'")
1026
+      next if properties['DM_MULTIPATH_DEVICE_PATH'] == '1'
1027
+
1016 1028
       @logger.debug("Trying to find out if device #{devname} is removable or not")
1017 1029
       if File.exists?("/sys/block/#{basename_dir}/removable")
1018 1030
         removable = File.open("/sys/block/#{basename_dir}/removable"){ |f| f.read_nonblock(1024).strip }
@@ -1020,18 +1032,20 @@ class NodeAgent
1020 1032
       @logger.debug("Device #{devname} removable parameter: #{removable.inspect}")
1021 1033
 
1022 1034
       if STORAGE_CODES.include?(properties['MAJOR'].to_i)
1023
-        @logger.debug("Device #{devname} seems to be appropriate")
1024 1035
         # Exclude LVM volumes (in CentOS - 253, in Ubuntu - 252) using additional check
1025 1036
         # Exclude any storage device connected through USB by the default
1037
+        @logger.debug("Trying to exclude LVM volumes and USB devices")
1026 1038
         next if properties['DEVPATH'].include?('virtual/block/dm') ||
1027 1039
                 (properties['ID_BUS'] == 'usb' &&
1028 1040
                  !@settings.has_key?("report_usb_block_devices"))
1029
-          @blocks << {
1030
-            :name => basename_dir,
1031
-            :disk => _disk_path_by_name(devname) || devname,
1032
-            :extra => _disk_id_by_name(devname) || [],
1033
-            :removable => removable,
1034
-          }
1041
+
1042
+        @logger.debug("Device #{devname} seems to be appropriate")
1043
+        @blocks << {
1044
+          :name => basename_dir,
1045
+          :disk => _disk_path_by_name(devname) || devname,
1046
+          :extra => _disk_id_by_name(devname) || [],
1047
+          :removable => removable,
1048
+        }
1035 1049
       end
1036 1050
     end
1037 1051
     @logger.debug("Final list of physical devices is: #{@blocks.inspect}")

Loading…
Cancel
Save