multipath: Fix some minor issues in path reordering code

There were a couple of small issues with the path reordering code.

Since you may fail to get the adapter name at any time while looping
through the paths, you need to clean up when this fails, instead of
just exitting group_by_host_adapter().

I've looked at a couple kernels, and I don't see any sysfs file named:
/sys/class/iscsi_host/host<n>/ip_address
It's always:
/sys/class/iscsi_host/host<n>/ipaddress

Also /sys/class/iscsi_host/host<n>/ipaddress could be an IPv6 address,
in which case we need 40 bytes to hold is, so SLOT_NAME_SIZE needs to
be 40 bytes large.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
libmultipath: Use existing user friendly name if possible

When a system is booted to the SAN, a condition can occur where one
user friendly name is given to a disk during boot, but multipathd tries
to allocate a different one after boot. If the second alias is already
used by another device, multipathd can't rename it. Multipathd then has
incorrect information about the alias/wwid relationships, which can
result in paths being added to the wrong map.

This patch works around this problem by first trying to use the alias
already bound to a device during boot.  If the bindings file has that
alias bound to a different device, it'll auto generate a new alias to
rename it to.

The alias prioritization is:
1. multipath.conf per-device alias
2. Currently bound alias
3. New auto-generated alias
4. wwid

Signed-off-by: Sean Stewart <sean.stewart@netapp.com>
Reviewed-by: Shiva Krishna Merla <shivakrishna.merla@netapp.com>
Remove trailing whitespaces from previous patch
kpartx: fix extended partition size for >512b sectors

Extended partitions only get 2 sectors for 512 byte sector size,
to allow LILO the 1024 bytes of room it needs.  Larger sector size
disks already have room and so only use 1 sector.

Signed-off-by: Phillip Susi <psusi@ubuntu.com>
multipath-tools: Mismatch between allocation length and transfer length in rdac prio

Fix mismatch between allocation length and dxfer len in rdac prio.

Signed-off-by: shiva krishna merla <shivakrishna.merla@netapp.com>
multipath-tools: mismatch between CDB allocation length and SG_IO dxfer_len

Hello,

while playing with multipath-tools and scst I got the following warning:

[ 6382.467569] [3806]: scst: scst_parse_cmd:826:Warning: expected
transfer length 256 for opcode 0x12 (handler vdisk_blockio, target
scst_local) doesn't match decoded value 128
[ 6382.467574] [3806]: scst_parse_cmd:828:Suspicious CDB:
[ 6382.467579]  (h)___0__1__2__3__4__5__6__7__8__9__A__B__C__D__E__F
[ 6382.467581]    0: 12 01 c0 00 80 00   ......

This happened when my scst target pretended to be a CLARiiON.
I noticed a mismatch in emc_clariion_prio (libmultipath/prioritizers/emc.c)
between the allocation length and dxfer_len:

int emc_clariion_prio(const char *dev, int fd)
{
        unsigned char sense_buffer[256];
        unsigned char sb[128];
        unsigned char inqCmdBlk[INQUIRY_CMDLEN] = {INQUIRY_CMD, 1, 0xC0, 0,
                                                sizeof(sb), 0};

...

        memset(&sense_buffer, 0, 256);
        io_hdr.interface_id = 'S';
        io_hdr.cmd_len = sizeof (inqCmdBlk);
        io_hdr.mx_sb_len = sizeof (sb);
        io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
        io_hdr.dxfer_len = sizeof (sense_buffer);
        io_hdr.dxferp = sense_buffer;
        io_hdr.cmdp = inqCmdBlk;
        io_hdr.sbp = sb;
        io_hdr.timeout = 60000;
        io_hdr.pack_id = 0;

The following change shrinks the size of sense_buffer to 128.

Sebastian
check info.exists to get valid value

dm_task_get_info will still return 1 if device doesn't exist.
Check info.exists to ensure major and minor values are valid.

There is no reason to assign info.open_count to @r here.

Signed-off-by: Vaughan Cao <vaughan.cao@oracle.com>
Don't forget to reload table when both reload and rename is required

We encounter the following case:

@ After adding a multipaths section into /etc/multipath.conf to specify 'alias'
@ and other attributes for a particular multipath device and
@ reloading/restarting the multipathd service, only renaming of the multipath
@ device is done, other attribute changes are ignored.
@
@ It is more evident if you directly run 'multipath -r' to reload devmap after
@ adding the 'multipaths' section with alias into /etc/multipath.conf.
@
@ When reload/restart multipathd service or 'multipath -r' again, new settings
@ can be applied right.

It's because that in select_action() when force_reload is set, if we also need
rename the mpp device, reload action won't be taken any more.

I did this patch by introducing a new action ACT_RENAME2 to group these two
action. Test passed. However, it seems to be a rough patch and I am not
certain if this bind is fine refering to dm_reassign. Please comment, Thanks.

Signed-off-by: Vaughan Cao <vaughan.cao@oracle.com>
Fix memory issues in path reordering failure code paths

There were some possible NULL pointer dereferences and multiple frees
in the failure code paths of the path reordering code.  This patch
cleans them up.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Return the correct size buffer in set_value()

When multipath was mallocing the buffer in set_value, it was using
sizeof(char *), instead of sizeof(char), so it was allocating a buffer
big enough for an array of pointers instead of characters.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
enable gcc format-security check

-Wformat-security warns about format-strigs that represent possible
security problems.  This is check is now enabled for fedora builds, and it
seems like a reasonable thing to always be checking.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
change conf->dry_run to conf->cmd

conf->dry_run is getting used for many different things besides running
multipath in dry_run mode, and the name and values were getting
increasingly confusing.  This patch switches the variable from
conf->dry_run to conf->cmd, and folds in conf->list.  It also changes
the value to a enum.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
allow users to add wwids to /etc/multipath/wwids with -a

The patch adds a "-a" option to multipath, that allows it to add wwids
to the /etc/multipath wwids file.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Add missing interactive commands to multipathd man page

This patch adds the missing options from the multipathd.8 man page.  It
also fixes a typo in a log message from the alua prioritizer.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>