CA-142451: Failed to report all LUNs advertised on targets sharing the same IQN

If a multicontroller array advertises its targets using the same IQN
but different IPs and the LUNs in those targets are distinct,
we are able to show only LUNs coming from the first IP address.

The fix reinstates a line that was removed in commit 391bdf055dff
in our old sm.hg repository.
The purporse of the line is to first check that we have
a valid active iscsi connection using the original pair IP,IQN.
Only if it fails (it should not in my opinion) we fall back to
other ip addresses.

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

GitHub: closes #207 on xapi-project/sm
CA-141002: Enable ALUA auto-detection for DGC arrays

We have seen quite a few incidents where a configuration mismatch (ALUA vs.
DGC) between XS and the array caused confusion and got escalated: SCTX-1780,
SCTX-1333, CA-112771, CA-124429. This updated configuration will prevent such
misconfiguration incidents from reocurring, as XS will dynamically adapt to the
configuration on the array.

The partner has completed the qualification of the updated multipath
configuration with their storage arrays.

Signed-off-by: Robert Breker <robert.breker@citrix.com>
Acked-by: Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #214 on xapi-project/sm
CA-87112: Fix LVM space leak during VDI.create

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Imported-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-123175: Filter iSCSI dom0 boot disk LUN.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Reviewed-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Imported-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-119317: Use kenel blkback for raw LUNs

Imported-by: Thanos Makatos <thanos.makatos@citrix.com>
CP 8320: Improved formatting in README and INSTALL files

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

(cherry picked from commit d60003a24ac53bfaf788ec64e511a2a671cef868)
CAR-1442: Change NFS mount options

In preparation for read caching, change actimeo=0 to acdirmin=0,acdirmax=0.
Using "actimeo=0" prevents caching file attributes which means that each read
requires a GETATTR call to the NFS server.  This prevents read caching from
being effective.  Changing the mount options to "acdirmin=0,acdirmax=0"
prevents caching directory attributes but allows caching file attributes.  This
allows read caching to be effective.

This reverts the change made to the mount options in CA-63601.  The issue in
that ticket was a transient issue, fixed by a later build, before the change to
the mount options was made.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
Imported-by: Thanos Makatos <thanos.makatos@citrix.com>

(cherry picked from commit 8e505ad9d82dc66c06edf22588d0f7d8e8fac1cb)
CAR-1442: Enable no-O_DIRECT read caching for VDIs on EXT and NFS SRs

Pass the "-D" argument to tap-ctl when opening an EXTFileVDI or an NFSFileVDI
to allow read caching by removing O_DIRECT.

Allow disabling read caching per-SR by setting other-config:o_direct to true.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
Imported-by: Thanos Makatos <thanos.makatos@citrix.com>

(cherry picked from commit 4be47e0b137652ef4799931a87bca6ea4ef0dd67)

Conflicts:

	drivers/blktap2.py
CA-136654: Don't rely on a XAPI session existing

With static VDIs, the SR code is run without a XAPI session.  In this
case, set O_DIRECT to be on for safety since there is external knob to
adjust it.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
Imported-by: Thanos Makatos <thanos.makatos@citrix.com>

(cherry picked from commit 6c2d966ee492d756aa90dae84a0fc2298d4d4002)
CP-8514: Add xapi-plugin 'trim' to facilitate trim

The xapi plugin 'trim' could be used to enable trim on LVM based
SRs to free up storage space from Storage arrays. The plugin creates
a LV using all of the free space in the VG, and then issue a lvremove
setting the issue_discards to 1. lvremove should trigger a trim / unmap
by lvm that should result in freeing up the storage space in the array

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

(cherry picked from commit a34ef9c15f9b98c3b4c0d5cba74dafaa430f76cc)

Conflicts:

	drivers/lvutil.py
CP-8514: issue_discards should be placed under devices section

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

(cherry picked from commit 6e6afbce763fff5ae135f6dfcd404b9d29696547)
CP-8744:  SR trim limited to compatible SRs

Limited SR trim capability to LVHD based SRs. Also error handling
was modified to return a XML string response on failure containing
errcode and errmsg as a key value pair. Trim functionality was
separated from the trim plugin entry point.

Signed-off-by: Vineeth Raveendran <vineeth.thampi@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
Imported-by: Thanos Makatos <thanos.makatos@citrix.com>

(cherry picked from commit 1ae07e0233cc021056404cafd64bffcb685a143d)

Conflicts:

	Makefile
CP-8744: [UnitTest] Add unittest for trim plugin

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Vineeth Raveendran <vineeth.thampi@citrix.com>
Imported-by: Thanos Makatos <thanos.makatos@citrix.com>

(cherry picked from commit b2db2a9b76c1110370fd8c9e31bdd73ba60c4f0b)
CP-8657: Remove iSL references from storage manager.

- Removed all code references
- Removed all CSLG error codes
- Replaced CSLGXMLParse to XMLParse

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

(cherry picked from commit 0b1e794152b8a97746985776edc5388e1b841ee4)

Methods util.get_isl_scsiids, util.get_scsiid_from_svid, and
util.getCslDevPath have been kept back as they are used by OCFS.

Conflicts:

	drivers/mpathcount.py
CP-8657: Fix XE_SR_ERRORCODES.xml

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

(cherry picked from commit 004465eb3d9506d0c0707414ef693abe76f0ad92)
CA-134784: [UnitTest] Mimic rmdir, open('w')

Mimic the behavior of rmdir, and also raise the appropriate exceptions
if client wants to open a file in a non-existing directory. Enable the
client to open files with 'w' flag.

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

(cherry picked from commit 3090c20534f6a900cea1489f72ba1e3d729d1374)
CA-134784: [UnitTest] cover refcounter

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

(cherry picked from commit 019f1404e60f21ff632af14c386428b1449c88e3)
CA-134784: Fix race conditions in refcounter

Concurrent refcounter operations on two different refcounters sharing
the same namespace can lead to race conditions:
 A.) By the time the refcounter file is written, the namespace directory
     has already been removed
 B.) Removing a namespace directory fails, because a a new refcounter file
     has been created within the same directory

_writeCount now returns False if the file was not found

A is solved by spinning on _writeCount until it succeeds.
B is solved by ignoring the errors

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@cirix.com>
Imported-by: Thanos Makatos <thanos.makatos@citrix.com>

(cherry picked from commit 63491d7b74e864436715e2a77d921be495445cbe)

Conflicts:

	drivers/refcounter.py
CA-134784: [UnitTest] Tests for refcounter

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

(cherry picked from commit f5693a167e271e90b09f34b10f68c571171e186a)
CA-135017: notify toolstack about tapdisk unpause errors in coalesce

Coalesce is an asynchronous operation so if a tapdisk refresh fails the
VM will lose the disk but the administrator will realise that when the
VM hangs. This patch notifies the toolstack as soon as the failure
occurs.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Acked-by: Germano Percossi <germano.percossi@citrix.com>
Imported-by: Thanos Makatos <thanos.makatos@tcitrix.com>

(cherry picked from commit 5d3a649127036e0c2ceeeb169d55e451e22cdd91)