Skip to content

Commit d5cb32f

Browse files
Deepti Doharechipchilders
authored andcommitted
Multiple Secondary Storage Issue
1 parent 345114d commit d5cb32f

7 files changed

Lines changed: 55 additions & 25 deletions

File tree

api/src/com/cloud/agent/api/BackupSnapshotCommand.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class BackupSnapshotCommand extends SnapshotCommand {
3535
private SwiftTO swift;
3636
private S3TO s3;
3737
StorageFilerTO pool;
38+
private Long secHostId;
3839

3940
protected BackupSnapshotCommand() {
4041

@@ -49,12 +50,14 @@ protected BackupSnapshotCommand() {
4950
* @param firstBackupUuid This is the backup of the first ever snapshot taken by the volume.
5051
* @param isFirstSnapshotOfRootVolume true if this is the first snapshot of a root volume. Set the parent of the backup to null.
5152
* @param isVolumeInactive True if the volume belongs to a VM that is not running or is detached.
53+
* @param secHostId This is the Id of the secondary storage.
5254
*/
5355
public BackupSnapshotCommand(String secondaryStoragePoolURL,
5456
Long dcId,
5557
Long accountId,
5658
Long volumeId,
5759
Long snapshotId,
60+
Long secHostId,
5861
String volumePath,
5962
StoragePool pool,
6063
String snapshotUuid,
@@ -71,6 +74,7 @@ public BackupSnapshotCommand(String secondaryStoragePoolURL,
7174
this.prevBackupUuid = prevBackupUuid;
7275
this.isVolumeInactive = isVolumeInactive;
7376
this.vmName = vmName;
77+
this.secHostId = secHostId;
7478
setVolumePath(volumePath);
7579
setWait(wait);
7680
}
@@ -111,4 +115,7 @@ public Long getSnapshotId() {
111115
return snapshotId;
112116
}
113117

118+
public Long getSecHostId() {
119+
return secHostId;
120+
}
114121
}

api/test/org/apache/cloudstack/api/agent/test/BackupSnapshotAnswerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void setUp() {
3737
StoragePool pool = Mockito.mock(StoragePool.class);
3838

3939
bsc = new BackupSnapshotCommand(
40-
"secondaryStoragePoolURL", 101L, 102L, 103L, 104L,
40+
"secondaryStoragePoolURL", 101L, 102L, 103L, 104L, 105L,
4141
"volumePath", pool, "snapshotUuid", "snapshotName",
4242
"prevSnapshotUuid", "prevBackupUuid", false, "vmName", 5);
4343
bsa = new BackupSnapshotAnswer(bsc, true, "results", "bussname", false);

api/test/org/apache/cloudstack/api/agent/test/BackupSnapshotCommandTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ public boolean isInMaintenance() {
147147

148148
BackupSnapshotCommand bsc = new BackupSnapshotCommand(
149149
"http://secondary.Storage.Url",
150-
101L, 102L, 103L, 104L, "vPath", pool,
150+
101L, 102L, 103L, 104L, 105L, "vPath", pool,
151151
"420fa39c-4ef1-a83c-fd93-46dc1ff515ae", "sName",
152152
"9012793e-0657-11e2-bebc-0050568b0057",
153153
"7167e0b2-f5b0-11e1-8414-0050568b0057", false, "vmName", 5);
154154

155155
BackupSnapshotCommand bsc1 = new BackupSnapshotCommand(
156156
"http://secondary.Storage.Url",
157-
101L, 102L, 103L, 104L, "vPath", pool,
157+
101L, 102L, 103L, 104L, 105L,"vPath", pool,
158158
"420fa39c-4ef1-a83c-fd93-46dc1ff515ae", "sName",
159159
"9012793e-0657-11e2-bebc-0050568b0057",
160160
"7167e0b2-f5b0-11e1-8414-0050568b0057", false, "vmName", 5);

engine/storage/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ protected Answer copySnapshot(DataObject srcObject, DataObject destObject) {
660660
Long accountId = baseVolume.getAccountId();
661661

662662
HostVO secHost = getSecHost(baseVolume.getId(), baseVolume.getDataCenterId());
663-
663+
Long secHostId = secHost.getId();
664664
String secondaryStoragePoolUrl = secHost.getStorageUrl();
665665
String snapshotUuid = srcSnapshot.getPath();
666666
// In order to verify that the snapshot is not empty,
@@ -693,7 +693,7 @@ protected Answer copySnapshot(DataObject srcObject, DataObject destObject) {
693693
StoragePool srcPool = (StoragePool)dataStoreMgr.getPrimaryDataStore(baseVolume.getPoolId());
694694
String value = configDao.getValue(Config.BackupSnapshotWait.toString());
695695
int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
696-
BackupSnapshotCommand backupSnapshotCommand = new BackupSnapshotCommand(secondaryStoragePoolUrl, dcId, accountId, baseVolume.getId(), srcSnapshot.getId(), baseVolume.getPath(), srcPool, snapshotUuid,
696+
BackupSnapshotCommand backupSnapshotCommand = new BackupSnapshotCommand(secondaryStoragePoolUrl, dcId, accountId, baseVolume.getId(), srcSnapshot.getId(), secHostId, baseVolume.getPath(), srcPool, snapshotUuid,
697697
srcSnapshot.getName(), prevSnapshotUuid, prevBackupUuid, isVolumeInactive, vmName, _backupsnapshotwait);
698698

699699
if ( swift != null ) {

plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,7 +3552,7 @@ private void swiftBackupSnapshot(Connection conn, SwiftTO swift, String srUuid,
35523552

35533553

35543554
protected String backupSnapshot(Connection conn, String primaryStorageSRUuid, Long dcId, Long accountId,
3555-
Long volumeId, String secondaryStorageMountPath, String snapshotUuid, String prevBackupUuid, Boolean isISCSI, int wait) {
3555+
Long volumeId, String secondaryStorageMountPath, String snapshotUuid, String prevBackupUuid, Boolean isISCSI, int wait, Long secHostId) {
35563556
String backupSnapshotUuid = null;
35573557

35583558
if (prevBackupUuid == null) {
@@ -3565,7 +3565,7 @@ protected String backupSnapshot(Connection conn, String primaryStorageSRUuid, Lo
35653565
String results = callHostPluginAsync(conn, "vmopsSnapshot", "backupSnapshot", wait,
35663566
"primaryStorageSRUuid", primaryStorageSRUuid, "dcId", dcId.toString(), "accountId", accountId.toString(),
35673567
"volumeId", volumeId.toString(), "secondaryStorageMountPath", secondaryStorageMountPath,
3568-
"snapshotUuid", snapshotUuid, "prevBackupUuid", prevBackupUuid, "backupUuid", backupUuid, "isISCSI", isISCSI.toString());
3568+
"snapshotUuid", snapshotUuid, "prevBackupUuid", prevBackupUuid, "backupUuid", backupUuid, "isISCSI", isISCSI.toString(), "secHostId", secHostId.toString());
35693569
String errMsg = null;
35703570
if (results == null || results.isEmpty()) {
35713571
errMsg = "Could not copy backupUuid: " + backupSnapshotUuid + " of volumeId: " + volumeId
@@ -6837,6 +6837,7 @@ protected BackupSnapshotAnswer execute(final BackupSnapshotCommand cmd) {
68376837
String prevBackupUuid = cmd.getPrevBackupUuid();
68386838
String prevSnapshotUuid = cmd.getPrevSnapshotUuid();
68396839
int wait = cmd.getWait();
6840+
Long secHostId = cmd.getSecHostId();
68406841
// By default assume failure
68416842
String details = null;
68426843
boolean success = false;
@@ -6915,7 +6916,7 @@ protected BackupSnapshotAnswer execute(final BackupSnapshotCommand cmd) {
69156916
} else if (cmd.getS3() != null) {
69166917
backupSnapshotToS3(conn, cmd.getS3(), primaryStorageSRUuid, snapshotPaUuid, isISCSI, wait);
69176918
} else {
6918-
snapshotBackupUuid = backupSnapshot(conn, primaryStorageSRUuid, dcId, accountId, volumeId, secondaryStorageMountPath, snapshotUuid, prevBackupUuid, isISCSI, wait);
6919+
snapshotBackupUuid = backupSnapshot(conn, primaryStorageSRUuid, dcId, accountId, volumeId, secondaryStorageMountPath, snapshotUuid, prevBackupUuid, isISCSI, wait, secHostId);
69196920
success = (snapshotBackupUuid != null);
69206921
}
69216922
}

scripts/vm/hypervisor/xenserver/vmopsSnapshot

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,24 @@ def umount(localDir):
321321
util.SMlog("Successfully unmounted " + localDir)
322322
return
323323

324-
def mountSnapshotsDir(secondaryStorageMountPath, relativeDir, dcId, accountId, instanceId):
324+
def mountSnapshotsDir(secondaryStorageMountPath, relativeDir, dcId, accountId, instanceId, secHostId):
325325
# The aim is to mount secondaryStorageMountPath on
326326
# And create <accountId>/<instanceId> dir on it, if it doesn't exist already.
327327
# Assuming that secondaryStorageMountPath exists remotely
328328

329-
# Alex's suggestion and currently implemented:
330-
# Just mount secondaryStorageMountPath/<relativeDir> everytime
329+
# Just mount secondaryStorageMountPath/<relativeDir>/SecondaryStorageHost/ everytime
331330
# Never unmount.
332331
snapshotsDir = os.path.join(secondaryStorageMountPath, relativeDir)
333332

334333
# Mkdir local mount point dir, if it doesn't exist.
335334
localMountPointPath = os.path.join(CLOUD_DIR, dcId)
336-
localMountPointPath = os.path.join(localMountPointPath, relativeDir)
335+
localMountPointPath = os.path.join(localMountPointPath, relativeDir, secHostId)
337336

338337
makedirs(localMountPointPath)
339-
# if something is not mounted already on localMountPointPath,
338+
# if something is not mounted already on localMountPointPath,
340339
# mount secondaryStorageMountPath on localMountPath
341340
if os.path.ismount(localMountPointPath):
342-
# There is only one secondary storage per zone.
341+
# There is more than one secondary storage per zone.
343342
# And we are mounting each sec storage under a zone-specific directory
344343
# So two secondary storage snapshot dirs will never get mounted on the same point on the same XenServer.
345344
util.SMlog("The remote snapshots directory has already been mounted on " + localMountPointPath)
@@ -352,11 +351,22 @@ def mountSnapshotsDir(secondaryStorageMountPath, relativeDir, dcId, accountId, i
352351
makedirs(backupsDir)
353352
return backupsDir
354353

354+
def unmountAll(path):
355+
try:
356+
for dir in os.listdir(path):
357+
if dir.isdigit():
358+
util.SMlog("Unmounting Sub-Directory: " + dir)
359+
localMountPointPath = os.path.join(path, dir)
360+
umount(localMountPointPath)
361+
except:
362+
util.SMlog("Ignoring the error while trying to unmount the snapshots dir")
363+
355364
@echo
356365
def unmountSnapshotsDir(session, args):
357366
dcId = args['dcId']
358367
localMountPointPath = os.path.join(CLOUD_DIR, dcId)
359368
localMountPointPath = os.path.join(localMountPointPath, "snapshots")
369+
unmountAll(localMountPointPath)
360370
try:
361371
umount(localMountPointPath)
362372
except:
@@ -482,7 +492,8 @@ def backupSnapshot(session, args):
482492
snapshotUuid = args['snapshotUuid']
483493
prevBackupUuid = args['prevBackupUuid']
484494
backupUuid = args['backupUuid']
485-
isISCSI = getIsTrueString(args['isISCSI'])
495+
isISCSI = getIsTrueString(args['isISCSI'])
496+
secHostId = args['secHostId']
486497

487498
primarySRPath = getPrimarySRPath(primaryStorageSRUuid, isISCSI)
488499
util.SMlog("primarySRPath: " + primarySRPath)
@@ -496,10 +507,10 @@ def backupSnapshot(session, args):
496507
# Mount secondary storage mount path on XenServer along the path
497508
# /var/run/sr-mount/<dcId>/snapshots/ and create <accountId>/<volumeId> dir
498509
# on it.
499-
backupsDir = mountSnapshotsDir(secondaryStorageMountPath, "snapshots", dcId, accountId, volumeId)
510+
backupsDir = mountSnapshotsDir(secondaryStorageMountPath, "snapshots", dcId, accountId, volumeId, secHostId)
500511
util.SMlog("Backups dir " + backupsDir)
501512

502-
# Check existence of snapshot on primary storage
513+
# Check existence of snapshot on primary storage
503514
isfile(baseCopyPath, isISCSI)
504515
if prevBackupUuid:
505516
# Check existence of prevBackupFile

scripts/vm/hypervisor/xenserver/xcposs/vmopsSnapshot

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,24 @@ def umount(localDir):
321321
util.SMlog("Successfully unmounted " + localDir)
322322
return
323323

324-
def mountSnapshotsDir(secondaryStorageMountPath, relativeDir, dcId, accountId, instanceId):
324+
def mountSnapshotsDir(secondaryStorageMountPath, relativeDir, dcId, accountId, instanceId, secHostId):
325325
# The aim is to mount secondaryStorageMountPath on
326326
# And create <accountId>/<instanceId> dir on it, if it doesn't exist already.
327327
# Assuming that secondaryStorageMountPath exists remotely
328328

329-
# Alex's suggestion and currently implemented:
330-
# Just mount secondaryStorageMountPath/<relativeDir> everytime
329+
# Just mount secondaryStorageMountPath/<relativeDir>/SecondaryStorageHost/ everytime
331330
# Never unmount.
332331
snapshotsDir = os.path.join(secondaryStorageMountPath, relativeDir)
333332

334333
# Mkdir local mount point dir, if it doesn't exist.
335334
localMountPointPath = os.path.join(CLOUD_DIR, dcId)
336-
localMountPointPath = os.path.join(localMountPointPath, relativeDir)
335+
localMountPointPath = os.path.join(localMountPointPath, relativeDir, secHostId)
337336

338337
makedirs(localMountPointPath)
339338
# if something is not mounted already on localMountPointPath,
340339
# mount secondaryStorageMountPath on localMountPath
341340
if os.path.ismount(localMountPointPath):
342-
# There is only one secondary storage per zone.
341+
# There can be more than one secondary storage per zone.
343342
# And we are mounting each sec storage under a zone-specific directory
344343
# So two secondary storage snapshot dirs will never get mounted on the same point on the same XenServer.
345344
util.SMlog("The remote snapshots directory has already been mounted on " + localMountPointPath)
@@ -352,11 +351,22 @@ def mountSnapshotsDir(secondaryStorageMountPath, relativeDir, dcId, accountId, i
352351
makedirs(backupsDir)
353352
return backupsDir
354353

354+
def unmountAll(path):
355+
try:
356+
for dir in os.listdir(path):
357+
if dir.isdigit():
358+
util.SMlog("Unmounting Sub-Directory: " + dir)
359+
localMountPointPath = os.path.join(path, dir)
360+
umount(localMountPointPath)
361+
except:
362+
util.SMlog("Ignoring the error while trying to unmount the snapshots dir")
363+
355364
@echo
356365
def unmountSnapshotsDir(session, args):
357366
dcId = args['dcId']
358367
localMountPointPath = os.path.join(CLOUD_DIR, dcId)
359368
localMountPointPath = os.path.join(localMountPointPath, "snapshots")
369+
unmountAll(localMountPointPath)
360370
try:
361371
umount(localMountPointPath)
362372
except:
@@ -490,7 +500,8 @@ def backupSnapshot(session, args):
490500
snapshotUuid = args['snapshotUuid']
491501
prevBackupUuid = args['prevBackupUuid']
492502
backupUuid = args['backupUuid']
493-
isISCSI = getIsTrueString(args['isISCSI'])
503+
isISCSI = getIsTrueString(args['isISCSI'])
504+
secHostId = args['secHostId']
494505

495506
primarySRPath = getPrimarySRPath(session, primaryStorageSRUuid, isISCSI)
496507
util.SMlog("primarySRPath: " + primarySRPath)
@@ -504,10 +515,10 @@ def backupSnapshot(session, args):
504515
# Mount secondary storage mount path on XenServer along the path
505516
# /var/run/sr-mount/<dcId>/snapshots/ and create <accountId>/<volumeId> dir
506517
# on it.
507-
backupsDir = mountSnapshotsDir(secondaryStorageMountPath, "snapshots", dcId, accountId, volumeId)
518+
backupsDir = mountSnapshotsDir(secondaryStorageMountPath, "snapshots", dcId, accountId, volumeId, secHostId)
508519
util.SMlog("Backups dir " + backupsDir)
509520

510-
# Check existence of snapshot on primary storage
521+
# Check existence of snapshot on primary storage
511522
isfile(baseCopyPath, isISCSI)
512523
if prevBackupUuid:
513524
# Check existence of prevBackupFile

0 commit comments

Comments
 (0)