Updated Branches: refs/heads/4.2-workplace ca2f84408 -> 514c3da7f
fix backupsnapshot using fileSR Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4cd6f31c Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4cd6f31c Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4cd6f31c Branch: refs/heads/4.2-workplace Commit: 4cd6f31cd2407e9adffc54a9c33da49d0f06f55c Parents: ca2f844 Author: Edison Su <[email protected]> Authored: Mon Dec 9 16:08:52 2013 -0800 Committer: Edison Su <[email protected]> Committed: Mon Dec 9 16:08:52 2013 -0800 ---------------------------------------------------------------------- .../xen/resource/CitrixResourceBase.java | 32 +++++++++++++---- .../xen/resource/XenServerStorageProcessor.java | 38 ++++++++++---------- .../hypervisor/xenserver/cloud-plugin-snapshot | 14 ++++++-- 3 files changed, 58 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4cd6f31c/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 4c6314f..4d0002d 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -3876,18 +3876,39 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return lfilename; } - protected SR createFileSR(Connection conn, String path, String location) { + protected SR createFileSR(Connection conn, String path) { + SR sr = null; + PBD pbd = null; try { Map<String, String> smConfig = new HashMap<String, String>(); - smConfig.put("location", path); Host host = Host.getByUuid(conn, _host.uuid); String uuid = UUID.randomUUID().toString(); - SR sr = SR.introduce(conn,uuid, uuid, uuid, "file", "file", false, smConfig); - - //sr.scan(conn); + sr = SR.introduce(conn,uuid, uuid, uuid, "file", "file", false, smConfig); + PBD.Record record = new PBD.Record(); + record.host = host; + record.SR = sr; + smConfig.put("location", path); + record.deviceConfig = smConfig; + pbd = PBD.create(conn, record); + pbd.plug(conn); + sr.scan(conn); return sr; } catch (Exception e) { + try { + if (pbd != null) { + pbd.destroy(conn); + } + } catch (Exception e1) { + s_logger.debug("Failed to destroy pbd", e); + } + try { + if (sr != null) { + sr.forget(conn); + } + } catch (Exception e2) { + s_logger.error("Failed to forget sr", e); + } String msg = "createFileSR failed! due to " + e.toString(); s_logger.warn(msg, e); throw new CloudRuntimeException(msg, e); @@ -3918,7 +3939,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } mounted = true; - ssSR = createFileSR(conn, localDir, remoteDir); filesrcreated = true; VDI snapshotvdi = VDI.getByUuid(conn, snapshotUuid); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4cd6f31c/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java index f51d280..a90c829 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java @@ -31,13 +31,6 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeoutException; -import com.xensource.xenapi.*; -import org.apache.log4j.Logger; -import org.apache.xmlrpc.XmlRpcException; - -import com.xensource.xenapi.Types.BadServerResponse; -import com.xensource.xenapi.Types.XenAPIException; - import org.apache.cloudstack.storage.command.AttachAnswer; import org.apache.cloudstack.storage.command.AttachCommand; import org.apache.cloudstack.storage.command.AttachPrimaryDataStoreAnswer; @@ -54,6 +47,8 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; +import org.apache.log4j.Logger; +import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CreateStoragePoolCommand; @@ -76,6 +71,19 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.storage.encoding.DecodedDataObject; import com.cloud.utils.storage.encoding.DecodedDataStore; import com.cloud.utils.storage.encoding.Decoder; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Host; +import com.xensource.xenapi.PBD; +import com.xensource.xenapi.Pool; +import com.xensource.xenapi.SR; +import com.xensource.xenapi.Task; +import com.xensource.xenapi.Types; +import com.xensource.xenapi.Types.BadServerResponse; +import com.xensource.xenapi.Types.XenAPIException; +import com.xensource.xenapi.VBD; +import com.xensource.xenapi.VDI; +import com.xensource.xenapi.VM; +import com.xensource.xenapi.VMGuestMetrics; public class XenServerStorageProcessor implements StorageProcessor { private static final Logger s_logger = Logger.getLogger(XenServerStorageProcessor.class); @@ -1111,7 +1119,7 @@ public class XenServerStorageProcessor implements StorageProcessor { } SR ssSR = null; String localDir = "/var/cloud_mount/" + UUID.randomUUID().toString(); - String remoteDir = secondaryStorageMountPath + File.separator + path; + String remoteDir = secondaryStorageMountPath; try { String results = hypervisorResource.callHostPluginAsync(conn, "cloud-plugin-snapshot", "mountNfsSecondaryStorage", wait, @@ -1121,9 +1129,8 @@ public class XenServerStorageProcessor implements StorageProcessor { s_logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } - mounted = true; - ssSR = hypervisorResource.createFileSR(conn, localDir, remoteDir); + ssSR = hypervisorResource.createFileSR(conn, localDir + "/" + path); filesrcreated = true; VDI snapshotvdi = VDI.getByUuid(conn, snapshotUuid); @@ -1164,16 +1171,11 @@ public class XenServerStorageProcessor implements StorageProcessor { } finally { try { if (filesrcreated && ssSR != null) { + Set<PBD> pbds = ssSR.getPBDs(conn); + PBD pbd = pbds.iterator().next(); + pbd.unplug(conn); ssSR.forget(conn); } - if (mounted) { - String results = hypervisorResource.callHostPluginAsync(conn, "cloud-plugin-snapshot", "umountNfsSecondaryStorage", - wait, "localDir", localDir); - if (results == null || results.isEmpty()) { - errMsg = "Could not umount secondary storage " + remoteDir + " on host "; - s_logger.debug(errMsg); - } - } } catch (Exception e) { s_logger.debug("Exception in backupsnapshot cleanup stage due to " + e.toString()); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4cd6f31c/scripts/vm/hypervisor/xenserver/cloud-plugin-snapshot ---------------------------------------------------------------------- diff --git a/scripts/vm/hypervisor/xenserver/cloud-plugin-snapshot b/scripts/vm/hypervisor/xenserver/cloud-plugin-snapshot index 7001987..5150ae8 100644 --- a/scripts/vm/hypervisor/xenserver/cloud-plugin-snapshot +++ b/scripts/vm/hypervisor/xenserver/cloud-plugin-snapshot @@ -380,6 +380,16 @@ def unmountSnapshotsDir(session, args): def mountNfsSecondaryStorage(session, args): remoteDir = args['remoteDir'] localDir = args['localDir'] + mounted = False + f = open("/proc/mounts", 'r') + for line in f: + tokens = line.split(" ") + if len(tokens) > 2 and tokens[0] == remoteDir and tokens[1] == localDir: + mounted = True + + if mounted: + return "true" + makedirs(localDir) options = "soft,tcp,timeo=133,retrans=1" try: @@ -392,7 +402,7 @@ def mountNfsSecondaryStorage(session, args): raise xs_errors.XenError(errMsg) logging.debug("Successfully mounted " + remoteDir + " to " + localDir) - return + return "true" @echo def umountNfsSecondaryStorage(session, args): @@ -409,7 +419,7 @@ def umountNfsSecondaryStorage(session, args): except: pass logging.debug("Successfully unmounted " + localDir) - return + return "true" def getPrimarySRPath(primaryStorageSRUuid, isISCSI):
