CP-6337: Added multipath.conf manipulator

This script is a basic multipath.conf to add and remove
WWIDs in the blacklist_exceptions section

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Keith Petley <keith.petley@citrix.com>
CP-6337: Added locking mechanism to wwid_conf

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Keith Petley <keith.petley@citrix.com>
CP-6337: Use reconfigure and wwid utils

This patch ensure the new mechanism for explicit multipath
mapping is active.
The corresponding patch in dm-multipath can be removed.

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Keith Petley <keith.petley@citrix.com>
CP-6337: Ensure multipath kernel modules are present

Once started the multipath daemon does not load the needed
kernel modules.
In the past it was not a problem because they are loaded as soon as
a device is added using the CLI.
Now we need some checks before doing this and they fail if this modules
are not loaded.

Loading modules while starting multipath is the standard behaviour in
more recent versions of multipath.
We just ensure this is always true.

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Keith Petley <keith.petley@citrix.com>
Merge changes for CP-6337

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #54 on xapi-project/sm
CA-120469: Fail gracefully in case rmdir returns ENOTEMPTY

Parallel vm-suspend operations on vm that has got vdi's in the same SR
could result in reference files, ignoring rmdir error (ENOTEMPTY)
instead of lsdir looks a better option.

Signed-off-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
Reviewed-by:Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #53 on xapi-project/sm
CP-5818: Productise removal of lvm2-lvcreate-inactive-flag.patch

Snapshot and leaf coalesce operations use journaling files with
additional info like parent UUID in the name of the file. Since the
resultant file name is too long for LVM, the file was created in an
inactive mode. This patch changes the logic to create a journal file
with a shorter name and writes additional informaton into the file.
Inactive flag for lvcreate is no longer required.

This changeset includes the fix made for ticket [CA-117034].

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>

GitHub: closes #50 on xapi-project/sm
CA-107356: Fix tapdisk unpause issue in case of VM migration failed.

VDI has driver name set to nbd in case VM migration failed. While
unpause tapdisk, it was always using mirror driver name. In a snapshot
failure scenario, the fix will pass None as driver name to unpause
tapdisk.

Signed-off-by: Sisimon Soman <sisimon.soman@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>

GitHub: closes #27 on xapi-project/sm
CA-121481: Ensure root disk is not blacklisted if booting from SAN

By default, every device is blacklisted, unless explicitly managed
by the Storage Manager.
When the root disk is managed by multipath, this happens at boot
time and the initrd must be able to add the device to multipath.
This patch ensures that, if the root disk is multipathed, it is
never blacklisted.

This patch can only guarantee that multipath is not broken for
the root disk but it is not responsible for making it multipathed
in the first place.

To make it working at installation time, dracut or mkinitrd should
call it explicitly.

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-121481: No need to use the daemon

The script does not need the daemon to get the needed info.
This script is executed both as a standard boot script and
during the installation ensure the root disk is whitelisted.
In the latter case the daemon is not supposed to be running
but the root disk can be managed by the device mapper.

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-121481: Improved wwid_conf script

Added the following:
- usage message
- command line options
- ability to both add and remove
- force addition or removal

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-121481: make sure 'stat' follows symlinks

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
CA-121481: /dev/root does not exist at installation time

sm-multipath was meant to start at run time only.
We use this function to fix boot from SAN at installation time, too.
We cannot rely on /dev/root so we borrowed some utility functions
from dracut with a slight modification

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Merge changes for CA-121481

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>

GitHub: closes #56 on xapi-project/sm
CA-115035: mpath-boot and multipathed host other-config keys missing

Before upgrading to the new kernel, the output of
multipath -k"show maps"
and
echo "show maps" |multipathd -k
were different.

Now they are the same but previous code in mpathcount.py was
relying exclusively on the wrong output in the previous version.

Now it is fixed in both cases

Signed-off-by: Germano Percossi <germano.percossi@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>

GitHub: closes #57 on xapi-project/sm
CA-122445: get_current_initiator_name fails to parse initiatorname.iscsi file on Debian

On Debian, the /etc/iscsi/initiatorname.iscsi file has comments telling you
what to do with the InitiatorName parameter;  the previous code would try
to interpret this comment as the InitiatorName setting and fail to parse it.

Signed-off-by: Euan Harris <euan.harris@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com

GitHub: closes #55 on xapi-project/sm
CA-118742: Drop whitelisting of HBA device drivers from devscan.py

CA-14825 introduced device driver whitelisting when probing HBAs to avoid that
local disks are listed when calling "xe sr-probe type=lvmohba".

Today the use of shared storage using SAS, FC, FCOE and iSCSI is the norm and
it is becoming increasingly difficult to ensure that the whitelisting of device
drivers is current.

Replacing the whitelisting with blacklisting for explicitly local device driver
groups should improve the customer experience, interoperability of SM, reduce
the maintenance effort and at the same time reduce the complexity of the code.

It seems less concerning that users might end up provisioning a local disk, if
it happens to have scsi id, with LVHDoHBA instead of LVHD, than that users end
up not beeing able to provision their shared storage at all. Also the chance of
missing a local device driver appears much lower due to the more consistent
naming.

After all there is the question, whether we should really prevent users from
provisioning local disks using lvhdohba - but changing this is only a 1-line
change, to adapt the blacklist, after this commit.

Signed-off-by: Robert Breker <robert.breker@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>

GitHub: closes #45 on xapi-project/sm
CA-113323: Wait for multipath links under mapper to be created before proceeding with SR creation.

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
CA-113323: Do not issue udevadm trigger on SR creation.

Rolled back original fix for CA-105130 which triggers udev events
for all devices in the system when a new SR is created. New events
for existing devices coupled with the ignore_device option in the
event handling rules caused the device to be removed.

The bug addressed in CA-105130 doesn't exist in the new release and
it should be safe to roll back the patch.

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
CA-113323: Use new udev device links for setting disk scheduler.

Links under /dev/disk/by-scsid have changed for the new kernel.
Setting scheduler for block devices when multipath is enabled
was broken due to reference to the old style of links. Updated
code to reflect corresponding changes in udev.

Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>