Saturday, February 19, 2011

multipath I/O

Multipath is used to detect multiple paths to devices for fail-over or performance reasons.  The  multipathd daemon is in charge of checking for failed paths. When a path fails, multipathd will reconfigure the multipath map for that path. The multipathd daemon executes the external multipath tool when failures occur.  When a failure occurs, the multipath tool signals the multipathd daemon once the device map reconfiguration is complete.  This article will show you the basic steps to get multipath working.  There are many tuning and configuration parameters for multipath.  However, those options are out of the scope of this document.


What you need...For Ubuntu anyways...

# Ensure you are using supported hardware.  See "External Links" section for a link to the supported hardware page.
# Install the multipath-tools package.
   If performing a "Boot from SAN", the multipath-tools-boot package also needs to be installed.
# Create a valid multipath.conf file.

Setup
Install the multipath package

$ sudo apt-get install multipath-tools


If booting from a SAN device, also install multipath-tools-boot:

$ sudo apt-get install multipath-tools-boot


Create a valid multipath.conf file for your environement


Take a look at the examples in /usr/share/doc/multipath-tools/examples. Although multipath does work without a multipath.conf configuration file, you will only be able access your storage device(LUNs/Volumes) by their WWID. It is reccomended to use a multipath.conf file to at least be able to blacklist devices and assign **friendly** aliases for device names. This allows a greater ease of administration.


To create a multipath.conf file, you first need to identify the WWIDs for your LUNS/Volumes.  This is done with the multipath command.  Note the option **-v2** this can be changed to increase the output verbosity, such as **v3**, **v4**, ect.  The WWID for each volume is the first column on the first and seventh line(Note, this shows two LUNS/Volumes).  In this example, the WWIDs are: **320000004cfb59a33** and **320000004cfacaaee**.  Later in this article, you will see this output again for these two WWIDs, but the output will also report the alias names that are configured.




$ sudo multipath -v2 -ll

320000004cfb59a33 dm-4 COMPAQ  ,BD03654499   
[size=34G][features=0][hwhandler=0]
\_ round-robin 0 [prio=1][active]
 \_ 4:0:0:0  sdl 8:176 [active][ready]
\_ round-robin 0 [prio=1][enabled]
 \_ 2:0:0:0  sda 8:0   [active][ready]
320000004cfacaaee dm-8 COMPAQ  ,BD03654499   
[size=34G][features=0][hwhandler=0]
\_ round-robin 0 [prio=1][active]
 \_ 4:0:1:0  sdm 8:192 [active][ready]
\_ round-robin 0 [prio=1][enabled]
 \_ 2:0:1:0  sdb 8:16  [active][ready]





You want to copy the WWIDs to enter them into the multipath.conf file.


Example multipath.conf file(See /usr/share/doc/multipath-tools/examples/multipath.conf.annotated for full details):



blacklist {
       devnode "^sda$"
       devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
       devnode "^hd[a-z]"
       devnode "^cciss!c[0-9]d[0-9]*"
}

defaults {
        udev_dir                /dev
        polling_interval        10
        selector                "round-robin 0"
        path_grouping_policy    multibus
        getuid_callout          "/lib/udev/scsi_id -g -u -d /dev/%n"
        prio_callout            /bin/true
        path_checker            readsector0
        rr_min_io               100
        max_fds                 8192
        rr_weight               priorities
        failback                immediate
        no_path_retry           fail
        user_friendly_names     yes
}

multipaths {
        multipath {
                wwid            320000004cfb59a33                               
                alias                   volume-alias1
                path_grouping_policy    multibus
                path_checker            readsector0
                path_selector           "round-robin 0"
                failback                manual
                rr_weight               priorities
                no_path_retry           5
        }
        multipath {
                wwid            320000004cfacaaee
                alias                   volume-alias2
                path_grouping_policy    multibus
                path_checker            readsector0
                path_selector           "round-robin 0"
                failback                manual
                rr_weight               priorities
                no_path_retry           5
        }
}
devices {
    device {
                vendor                  "(COMPAQ|HP)"
                product                 "HSV1[01]1|HSV2[01]0|HSV300"
                getuid_callout          "/sbin/scsi_id -g -u -s /dev/%n"
                prio_callout            "/sbin/mpath_prio_alua /dev/%n"
                features                "0"
                hardware_handler        "0"
                path_selector           "round-robin 0"
                path_grouping_policy    group_by_prio
                failback                immediate
                rr_weight               uniform
                no_path_retry           12
                rr_min_io               100
                path_checker            tur
        }


}




=Breakdown of multipath.conf file example=

**devnode_blacklist**
This section lists devices to be excluded by multipath (with regex matching). It is a good idea to blacklist the local/internal disks and any other devices to not be used by multipath.



blacklist {
       devnode "^sda$"
       devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
       devnode "^hd[a-z]"
       devnode "^cciss!c[0-9]d[0-9]*"
}



**multipaths**
This is were you map LUNS/Volumes to a friendly alias. You will have multiple multipath stanzas for every LUN/Volume used on your storage array.


multipaths {
        multipath {
                wwid            YOUR_FIRST_WWID_HERE                   
                alias                   VOL1
                path_grouping_policy    multibus
                path_checker            readsector0
                path_selector           "round-robin 0"
                failback                manual
                rr_weight               priorities
                no_path_retry           5
        }
        multipath {
                wwid            YOUR_SECOND_WWID_HERE                   
                alias                   VOL2
                path_grouping_policy    multibus
                path_checker            readsector0
                path_selector           "round-robin 0"
                failback                manual
                rr_weight               priorities
                no_path_retry           5
        }
}


**devices**

This is where you provide the model specific information for your storage array.  The details for the device are usually provided by the manufacturer with reccomended values for each parameter. This following provides examples for EMC, HP and Equallogic arrays. These examples are to illustrate the how each type of device can differ.



devices {
   
    device {
        vendor "EMC "
        product "SYMMETRIX"
        path_grouping_policy multibus
        getuid_callout "/lib/udev/scsi_id -g -u -d /dev/%n"
        path_selector "round-robin 0"
        features "0"
        hardware_handler "0"
        failback immediate
        }
    device {
               vendor                  "COMPAQ"
               product                 "HSV110 (C)COMPAQ"
               path_grouping_policy    multibus
               getuid_callout          "/sbin/scsi_id -g -u -s /dev/%n"
               path_checker            readsector0
               path_selector           "round-robin 0"
               hardware_handler        "0"
               failback                15
               rr_weight               priorities
               no_path_retry           queue
       }
       device {
               vendor                  "COMPAQ"
               product                 "MSA1000"
               path_grouping_policy    multibus
       }
       device {
                vendor                  "(COMPAQ|HP)"
                product                 "HSV1[01]1|HSV2[01]0|HSV300"
                getuid_callout          "/sbin/scsi_id -g -u -s /dev/%n"
                prio_callout            "/sbin/mpath_prio_alua /dev/%n"
                features                "0"
                hardware_handler        "0"
                path_selector           "round-robin 0"
                path_grouping_policy    group_by_prio
                failback                immediate
                rr_weight               uniform
                no_path_retry           12
                rr_min_io               100
                path_checker            tur
        }
    device {
               vendor "EQLOGIC"
               product "100E-00"
               path_grouping_policy multibus
               getuid_callout "/sbin/scsi_id -g -u -s /dev/%n"
               features "1 queue_if_no_path"
               path_checker readsector0
               failback immediate
               path_selector "round-robin 0"
               rr_min_io 10
               rr_weight priorities
}

}





Once the multipath.conf file is created, you need to copy it to the /etc directory.  The multipath-tools daemon then needs to be restarted.



sudo /etc/init.d/multipath-tools restart



You can then re-issue the multipath -v2 -ll command and notice the output now contins the alias name you created in the multipath.conf file, followed by the wwid in parentheses.  Also notice you can see two paths for each LUN/Volume.  Depending on your environment, you may have more than two paths.



sudo multipath -v2 -ll

volume-alias1 (320000004cfb59a33) dm-4 COMPAQ  ,BD03654499   
[size=34G][features=1 queue_if_no_path][hwhandler=0]
\_ round-robin 0 [prio=0][active]
 \_ 4:0:0:0  sdl 8:176 [active][ready]
 \_ 2:0:0:0  sda 8:0   [active][ready]
volume-alias2 (320000004cfacaaee) dm-8 COMPAQ  ,BD03654499   
[size=34G][features=1 queue_if_no_path][hwhandler=0]
\_ round-robin 0 [prio=0][active]
 \_ 4:0:1:0  sdm 8:192 [active][ready]
 \_ 2:0:1:0  sdb 8:16  [active][ready]




= Accessing Your LUNS/Volumes =

Your LUNS/Volumes will now be accessable under /dev/mapper/YOUR_ALIAS_NAME.  You can treat this device like a reagular block device.  You can partition it, and create a filesystem on it.  However, "Under the covers" you can loose a path or have the real block device name change, you your applicaiton will not be affected.  Here is what the /dev/mapper directory looks like from the previous examples:



$ ls -l /dev/mapper/

lrwxrwxrwx 1 root root      7 2011-02-18 15:35 volume-alias1 -> ../dm-4
lrwxrwxrwx 1 root root      7 2011-02-18 15:35 volume-alias2 -> ../dm-8



Example of partitioning this new device:


sudo fdisk /dev/mapper/volume-alias

$ sudo fdisk /dev/mapper/volume-alias1

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-4427, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-4427, default 4427):
Using default value 4427

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.



Review the contents of /dev/mapper after partitioning the device(Notice there is now volume-alias1-part1):


$ ls -l /dev/mapper/

lrwxrwxrwx 1 root root      7 2011-02-18 16:08 volume-alias1 -> ../dm-4
lrwxrwxrwx 1 root root      8 2011-02-18 16:08 volume-alias1-part1 -> ../dm-16
lrwxrwxrwx 1 root root      7 2011-02-18 15:35 volume-alias2 -> ../dm-8




Example of creating a filesystem on the newly partitioned device:


sudo mkfs -t ext4 /dev/mapper/volume-alias1-part1



Now the filesytem can be mounted(Assumes /mnt/volume-alias1-part1-mountpoint exists):



sudo mount /dev/mapper/volume-alias1-part1 /mnt/volume-alias1-part1-mountpoint

$ df /mnt/volume-alias1-part1-mountpoint/
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/volume-alias1-part1
                      35001508    180104  33043412   1% /mnt/volume-alias1-part1-mountpoint





= Useful Tools =
In the case you add a new storage array(s) to your system, there is a useful tool that can be used to perform a rescan of FibreChannel devices. This tool is a shell script named rescan-scsi-bus.sh.  To obtain this script, you need to install the scsitools package. The package can be installed by running the following:


sudo apt-get install scsitools


The rescan-scsi-bus.sh script is now install and can be run as the following:

sudo rescan-scsi-bus.sh


This script basically performs tasks similar to a FibreChannel LIP reset.

For iSCSI device, the iscsiadm tool is used.  The full details of iscsiadm is not covered in this article.  However, see the "External Links" section for iSCSI man page..


= External Links =
* Multipathd man page: http://manpages.ubuntu.com/manpages/lucid/man8/multipathd.8.html
* Multipath man page: http://manpages.ubuntu.com/manpages/lucid/man8/multipath.8.html
* Multipath.conf man page: http://manpages.ubuntu.com/manpages/lucid/man5/multipath.conf.5.html
* Hardware Support: https://wiki.ubuntu.com/HardwareSupport
* Component Support: http://www.ubuntu.com/certification/catalog
* rescan-scsi-bus.sh man page: http://manpages.ubuntu.com/manpages/lucid/man8/rescan-scsi-bus.sh.8.html
* iscsiadm man page: http://manpages.ubuntu.com/manpages/lucid/man8/iscsiadm.8.html
 

1 comment: