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>

(cherry picked from commit f93497ba)
Signed-off-by: Germano Percossi <germano.percossi@citrix.com>

GitHub: closes #215 on xapi-project/sm
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>

(cherry picked from commit 66c89ea0f7f70176fbfcb69654f77afbb2c4111d)
Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
CA-142451: Unit tests

Covering changes related to CA-142451.

Signed-off-by: Flavien Quesnel <flavien.quesnel@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-144709: Merge CA-142451 into xs64bit

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #217 on xapi-project/sm
CA-142595: [UnitTest] support non-block devices

Add testing framework enhancements to enable us to check what happens if
a given (SCSI) device does not have a block subdirectory.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Flavien Quesnel <flavien.quesnel@citrix.com>
CA-142595: Non-block devices causing IndexError

Some device (e.g. a scsi security manager device.) has no subdir
"block/" , this will cause _extract_dev_name "IndexError: list index
out of range" error.
The following is the traceback info:
run this cmd: xe sr-probe type=lvmohba
There was an SR backend failure.
status: non-zero exit
stdout:
stderr: Traceback (most recent call last):
File "/opt/xensource/sm/LVMoHBASR", line 239, in ?
SRCommand.run(LVHDoHBASR, DRIVER_INFO)
File "/opt/xensource/sm/SRCommand.py", line 343, in run
sr = driver(cmd, cmd.sr_uuid)
File "/opt/xensource/sm/SR.py", line 139, in init
self.load(sr_uuid)
File "/opt/xensource/sm/LVMoHBASR", line 98, in load
print >>sys.stderr,self.hbasr.print_devs()
File "/opt/xensource/sm/HBASR.py", line 242, in print_devs
self._init_hbadict()
File "/opt/xensource/sm/HBASR.py", line 63, in _init_hbadict
dict = devscan.adapters(filterstr=self.type)
File "/opt/xensource/sm/devscan.py", line 75, in adapters
(dev, entry) = _extract_dev(dir, proc, id, lun)
File "/opt/xensource/sm/devscan.py", line 235, in _extract_dev
dev = _extract_dev_name(device_dir)
File "/opt/xensource/sm/devscan.py", line 226, in _extract_dev_name
dev = glob.glob(os.path.join(device_dir, 'block/*'))[0]
IndexError: list index out of range

Signed-off-by: Wang Yanbin wangyanbin@dayang.com.cn
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-142595: [UnitTest] Add tests for the fix

Add unit tests relating to the fix proposed by Wang Yanbin.

Signed-off-by: Flavien Quesnel <flavien.quesnel@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-142595: Refactor devscan.py

 * extract INVALID_DEVICE_NAME
 * extract update_devs_dict
 * extract _get_block_device_name_with_kernel_3x

Signed-off-by: Flavien Quesnel <flavien.quesnel@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-142595: [UnitTest] cover devscan.py

Add unit tests, following the refactoring of devscan.py

Signed-off-by: Flavien Quesnel <flavien.quesnel@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-142595: Merged into xs64bit

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #216 on xapi-project/sm
CA-138452: [UnitTest] Tests for cleanup.SR.lock

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-138452: Fix SR locking

If lock acquisition failed, SR._locked would still report that one lock
is acquired, thus leaving the SR object in an inconsistent state.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
CA-138452: Merged into xs64bit

GitHub: closes #218 on xapi-project/sm
CA-146822: fix intermittent test failures

As the lock test was querying the GC for the collected locks, it might
be possible that when the test starts, there is already an uncollected
lock in the GC. To avoid this situation, run the GC, so only the garbage
created by the test will be collected.

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Flavien Quesnel <flavien.quesnel@citrix.com>

GitHub: closes #222 on xapi-project/sm
CA-146138: don't refresh slaves for local SRs

Don't try to synchronise logical volumes on other slaves for a SR that
is local to the host, it doesn't make any sense and can cause all sorts
of problems.

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-146138: improve error message when srcmd.params is malformed

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-146138: unit test for LV refresh on other hosts

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>
CA-146138: various improvements over unit test

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
Merge branch 'CA-146138' into xs64bit

Signed-off-by: Thanos Makatos <thanos.makatos@citrix.com>

GitHub: closes #221 on xapi-project/sm
CA-146822: Remove TestLockDestruction

Remove TestLockDestruction to avoid intermittent test failures

Signed-off-by: Flavien Quesnel <flavien.quesnel@citrix.com>
Reviewed-by: Mate Lakat <mate.lakat@citrix.com>

GitHub: closes #224 on xapi-project/sm