Browse Source

Merge "Adding multipath info to output disk information"

Jenkins 3 years ago
parent
commit
e2b35cd9ed
1 changed files with 57 additions and 10 deletions
  1. 57
    10
      agent

+ 57
- 10
agent View File

@@ -156,6 +156,7 @@ class NodeAgent
156 156
     @logger.info("API URL is #{@api_url}")
157 157
     @os = ohai_system_info
158 158
     @numa_topology = get_numa_topology
159
+    @mpath_devices, @skip_devices = multipath_devices
159 160
   end
160 161
 
161 162
   def get_scheme_and_port
@@ -443,9 +444,21 @@ class NodeAgent
443 444
     begin
444 445
       Timeout::timeout(30) do
445 446
         @logger.debug("Trying to find block devices")
447
+
448
+        # ohai reports the disk size according to /sys/block/#{bname}
449
+        # which is always measured in 512 bytes blocks, no matter what
450
+        # the physical (minimal unit which can be atomically written)
451
+        # or logical (minimal # unit which can be addressed) block sizes are, see
452
+        # http://lxr.free-electrons.com/source/include/linux/types.h?v=4.4#L124
453
+        # http://lxr.free-electrons.com/source/drivers/scsi/sd.c?v=4.4#L2340
454
+        block_size = 512
455
+
446 456
         (@os[:block_device] or {} rescue {}).each do |bname, binfo|
447 457
           @logger.debug("Found block device: #{bname}")
448 458
           @logger.debug("Block device info: #{binfo.inspect}")
459
+          dname = bname.gsub(/!/, '/')
460
+          next if @skip_devices.include?(dname)
461
+
449 462
           if physical_data_storage_devices.map{|d| d[:name]}.include?(bname) && binfo
450 463
             @logger.debug("Block device seems to be physical data storage: #{bname}")
451 464
             block = physical_data_storage_devices.select{|d| d[:name] == bname}[0]
@@ -457,22 +470,27 @@ class NodeAgent
457 470
               end
458 471
               @logger.debug("Block device #{bname} is accepted by PCI vendor ID")
459 472
             end
460
-            dname = bname.gsub(/!/, '/')
461
-
462
-            # ohai reports the disk size according to /sys/block/#{bname}
463
-            # which is always measured in 512 bytes blocks, no matter what
464
-            # the physical (minimal unit which can be atomically written)
465
-            # or logical (minimal # unit which can be addressed) block sizes are, see
466
-            # http://lxr.free-electrons.com/source/include/linux/types.h?v=4.4#L124
467
-            # http://lxr.free-electrons.com/source/drivers/scsi/sd.c?v=4.4#L2340
468
-            block_size = 512
473
+
469 474
             detailed_meta[:disks] << {
470 475
               :name => dname,
471 476
               :model => binfo[:model],
472 477
               :size => (binfo[:size].to_i * block_size),
473 478
               :disk => block[:disk],
474 479
               :extra => block[:extra],
475
-              :removable => block[:removable]
480
+              :removable => block[:removable],
481
+              :paths => nil
482
+            }
483
+
484
+          elsif @mpath_devices.has_key?(dname)
485
+            device = @mpath_devices[dname]
486
+            detailed_meta[:disks] << {
487
+              :name => 'mapper/' + device["DM_NAME"],
488
+              :model => binfo[:model],
489
+              :size => (binfo[:size].to_i * block_size),
490
+              :disk => dname,
491
+              :extra => _disk_id_by_name(dname),
492
+              :removable => 0,
493
+              :paths => device["DM_BLKDEVS_USED"].map{|name| _disk_path_by_name(name)}.join(', ')
476 494
             }
477 495
           end
478 496
         end
@@ -485,6 +503,35 @@ class NodeAgent
485 503
     detailed_meta
486 504
   end
487 505
 
506
+  def multipath_devices
507
+    dmsetup = `/sbin/dmsetup info -c --nameprefixes --noheadings -o blkdevname,subsystem,blkdevs_used,name,uuid`
508
+    # Example output:
509
+    # DM_BLKDEVNAME='dm-0':DM_SUBSYSTEM='mpath':DM_BLKDEVS_USED='sdb,sda':DM_NAME='31234567890abcdef':DM_UUID='mpath-31234567890abcdef'
510
+    # DM_BLKDEVNAME='dm-1':DM_SUBSYSTEM='mpath':DM_BLKDEVS_USED='sdc,sdd':DM_NAME='92344567890abcdef':DM_UUID='mpath-92344567890abcdef'
511
+
512
+    mpath_devices = {}
513
+    mapping = []
514
+    unless dmsetup.include?("No devices found")
515
+      dmsetup.lines.each do |line|
516
+        device = {}
517
+        line.split(/:/).each do |key_value|
518
+          k, v = key_value.split('=')
519
+          device[k] = v.strip().gsub(/'/, '')
520
+        end
521
+        next unless device["DM_SUBSYSTEM"] == 'mpath'
522
+        device["DM_BLKDEVS_USED"] = device["DM_BLKDEVS_USED"].split(',')
523
+        device["DM_BLKDEVS_USED"].each do | name |
524
+          mapping << name
525
+        end
526
+        mpath_devices[device["DM_BLKDEVNAME"]] = device
527
+      end
528
+    end
529
+    [mpath_devices, mapping]
530
+  rescue => e
531
+    @logger.error("Error '#{e.message}' while scanning for multipath devices.")
532
+    [{}, []]
533
+  end
534
+
488 535
   def _get_pci_vendor_id(devname)
489 536
     Timeout::timeout(30) do
490 537
       udevadm_walk = {}

Loading…
Cancel
Save