[CA-106558] & [CA-94713]: parameterise NFS request timeout value.

Allow the user to specify the maximum time a VBD should wait before reporting
errors in the case of NFS outages. The new parameter is
SR.other-config:nfs-timeout and it is specified as an integer number of
seconds. This parameter will affect the NFS timeo mount option and the tapdisk
request timeout limit.

Signed-off-by: Andrei Lifchits <andrei.lifchits@citrix.com>
[Chandrika Srinivasan imported and modified patch for xs64bit branch]
Signed-off-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@citrix.com>
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
CA-110835: check XAPI session existence before trying to get the timeout

The NFS timeout config setting was introduced by CA-106558 as a
SR.other-config field. So when mounting a NFS share, the SM backend will
call back to XAPI to get this config. Normally this won't be a problem,
because SM backend driver is usually launched up by XAPI, so there is (almost)
always a XAPI session available in hand. However, in some cases, this is
not true. E.g. when HA is enabled, the heartbeat VDI needs to be mounted even
before XAPI starts, and it's invoked by the attach-static-vdi script not XAPI.
In such case, calling XAPI to get config will fail ultimately.

The patch is a shortcut fix, it verifies whether there is a valid XAPI session
around before attempting to read the config, and will just fall back to
default if there is none. A better approach would be putting the timeout
setting as part of the SMmaster's PBD device config, so that the information
will always be accessible during a relevant SMAPI call (no need for the extra
XAPI field getting), and will be dumped/loaded automatically as part of the
static VDI attaching configuration file. This could be a future improvement,
currently registered as CP-5683.

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
Imported-by: Chandrika Srinivasan <chandrika.srinivasan@citrix.com>
(cherry picked from commit 7ddc2498b71bf036f573a84047d70d865acdf9d9)
Ported changes for CA-106558 and CA-110835

GitHub: closes #153 on xapi-project/sm
CA-130987: Forward any exceptions thrown inside _snapshot

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

GitHub: closes #169 on xapi-project/sm
[CA-137573]: Fix "Unrecognised bus type" VDIs.

Use "device/subsystem" to obtain SCSI details of the host CDROM drive.

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

(cherry picked from commit 6ad534df70013f8f24dbf3f7d646694f606702a6)
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>

GitHub: closes #182 xapi-project/sm
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>
CA-134864: Fix plugin-call for SXM.

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

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

GitHub: closes #183 xapi-project/sm
CP-8657: Fix XE_SR_ERRORCODES.xml

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

GitHub: closes #184 xapi-project/sm
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>
CA-134784: [UnitTest] cover refcounter

Signed-off-by: Mate Lakat <mate.lakat@citrix.com>
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>
CA-134784: [UnitTest] Tests for refcounter

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