[CP-6333][CP-6334]: rm dm-multipath-dm-event, dm-multipath-disable-udev-rules

This patch is the counterpart of 2 patches removed in
dm-multipath (formerly dm-multipath in guest-packages.hg):
- dm-multipath-disable-udev-rules
- dm-multipath-dm-event

This patch basically does the following:
- ship and override multipath udev rules from sm RPM
- add rules to invoke mpathcount from udev

Note: for udev to catch the relevant events, the kernel must have
      DM_UEVENT enabled

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

GitHub: closes #40 on xapi-project/sm
CA-111813: race condition setting "iscsi_sessions" in other_conf

This changeset basically reinstate previous code,
backing out "changeset:   1555:ac091775c8ea" in the Mercurial
repository.
To be safe, we remove the key before adding, just in case.

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

GitHub: closes #41 on xapi-project/sm
CP-5050: Notify XAPI about critical coalesce errors

The rate XAPI is notified is throttled to avoid spamming (currently
defaults to one message per hour, per SR). This rate can be overridden
by setting the "coalesce-error-rate" key in an SR's other-config.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Suggested-by: Andrei Lifchits <andrei.lifchits@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #38 on xapi-project/sm
CA-106886: Don't update vhd-blocks during SR.scan

Don't bother updating the vhd-blocks in the XAPI database as this is
owned by the GC and there's no synchronisation for this.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>

GitHub: closes #37 on xapi-project/sm
CP-6335: Removal of dm-multipath-init patch

This functionality has stopped being a patch to upstream
multipath and it is shipped in its own startup script
provided by sm RPM

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

GitHub: closes #42 on xapi-project/sm
CA-118762: Bring self.ty back

My previous pylint change 96e56bf7 replaced self.ty as it was not defined
anywhere in the VDI object. But this breaks some horrible hack in the
underlying layer, which was probably implementated that way for backward
"compatability" reason by itself.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
CA-118781: Initialize parent class first

Another incompatability issue introduced by my pylint serie. On the
other hand, the root cause was some bad code manifested due by this
change.

In some subclass of VDI.VDI, we set some fields before initializting
the VDI.VDI parent class, so that these fields might be overwritten
during the parent class initialization.

As a common rule of thumb, we should generally do parent class
initialization first and then do overwritten and extention in
the following steps in the children initializor.

And any information essential for parent class initialization should
be defined as a parameter of the parent __init__ method. E.g. uuid
is a predefined parameter of the initialization method in the parent
class (VDI.VDI), but many children classes still don't use this
parameter, and instead do uuid assignment in the children classes
instead and then call the parent initializor. This patchset doesn't
correct these issues for the moment, but we should pay attention to
this, otherwise we might get bitten in the future.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>

GitHub: closes #43 on xapi-project/sm
CP-5817: Productise removal of lvm2-environment-device.patch

Part of the change for rolling back lvm2-environment-device.patch.
Removed code that exports special environment variable to direct LVM
to look for an abbreviated device cache.

The second part of the change (actual removal of lvm patch) is under
guest-packages.

Signed-off-by: Chandrikas Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Zheng Li <zheng.li@eu.citrix.com>

GitHub: closes #28 on xapi-project/sm
CP-5831: Productise removal of lvm2-lvchange-idempotent.patch

Part of changes required to remove lvm2-lvchange-idempotent.patch.
LVM throws an error if an LV that is already RO is set to RO again
or an RW lv is set to RW. Added additional check on XS side to check
LV status before changing access permissions.

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

GitHub: closes #26 on xapi-project/sm
CA-118781: revert init order changes

Unfortunately we have to revert the previous 7018eaa and 7ac48731 on
the stricter initialization order.

This is due to some spaghetti calling pattern in our code. In VDI class
and its children, we have the following calling stack:

   Child.__init__ -> Parent.__init__ -> Child.load

When Child.load is called, it assumes that some attributes have already
been initialized, but at this point neither Child.__init__ nor
Parent.__init__ has completed their execution. This code pattern
forces us to initialize those particular attributes in the Child class's
__init___ method before ever calling  Parent.__init__.

This is not pretty, but changing this pattern demands many other changes.
To unblock trunk integration, here we reverted the previous changes.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>
CA-118781: Avoid the dangling "path" attribute of class VDI

The self.path attribute is referenced in VDI class's attach
method but it was not defined/initialized anywhere in class.
The correctness then depends on the children classes always do
the right thing (i.e. do not forget to init the path attribute
if they will ever call parent class's attach method directly
or indirectly).

This is considered as a ERRROR level issue by pylint. As a
fix, here we conditionally set self.path in the __init__
method based on whether a uuid argument is passed to the
initializer or not. For VDI classes whose physical
paths/locations have no direct connection with their UUID
string values (e.g. ISOSR, udevSR and SHMSR), they will not
pass any uuid to the parent class's initialiser and will be
responsible for setup the correct self.path/self.location
value by themselves. We want to make sure that their
customized value won't get overwritten here.

Also fixed the indentation suggested by Vinneth.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
Reviewed-by: Vineeth Thampi Raveendran <vineeth.thampi@citrix.com>
Reviewed-by: Germano Percossi <germano.percossi@citrix.com>
Merge for CA-116802

GitHub: closes #46 on xapi-project/sm
CA-116160: Python exception in HBA SR create.

len() on dictionary iterkeys is not valid in Python 2.6.
Replaced it with len() directly on the dictionary.

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

GitHub: closes #47 on xapi-project/sm
CA-118899: Support UTF-8 iSCSI target names.

Signed-off-by: Rob Dobson <rob@rdobson.co.uk>
Acked-by: Thanos Makatos <thanos.makatos@citrix.co.uk>

GitHub: closes #44 on xapi-project/sm
CA-119833: snapwatchd fails to link on some systems

snapwatchd fails to link a shared .so with -shared:

  /usr/bin/ld: xslib.o: relocation R_X86_64_32 against `.rodata.str1.1'
  can not be used when making a shared object
  xslib.o: could not read symbols: Bad value

We need to explicitly compile our objects as position-independent
code with -fPIC

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Acked-by: Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #49 on xapi-project/sm
[CA-118876] & [SCTX-1536]: Always use the back-up VHD footer.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Keith Petley <keith.petley@citrix.com>

GitHub: closes #51 on xapi-project/sm
[CP-5830]: Productise removal of lvm2-master-mode.patch

Removed the --master switch from lvm commands. We now use two separate
lvm conf files for master and slave nodes. Appropriate conf file is
chosen through an environment variable.

This changeset includes the fix made for [CA-116958] in addition to the
original work done for patch removal.

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

GitHub: closes #48 on xapi-project/sm