Skip to content

Commit 862211c

Browse files
committed
Fix restoration of VM / volumes with cifs
1 parent 59464be commit 862211c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
221221
restoreCommand.setBackupPath(backup.getExternalId());
222222
restoreCommand.setBackupRepoType(backupRepository.getType());
223223
restoreCommand.setBackupRepoAddress(backupRepository.getAddress());
224+
restoreCommand.setMountOptions(backupRepository.getMountOptions());
224225
restoreCommand.setVmName(vm.getName());
225226
restoreCommand.setVolumePaths(getVolumePaths(volumes));
226227
restoreCommand.setVmExists(vm.getRemoved() == null);
@@ -289,6 +290,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
289290
restoreCommand.setVmName(vmNameAndState.first());
290291
restoreCommand.setVolumePaths(Collections.singletonList(String.format("%s/%s", dataStore.getLocalPath(), volumeUUID)));
291292
restoreCommand.setDiskType(volume.getVolumeType().name().toLowerCase(Locale.ROOT));
293+
restoreCommand.setMountOptions(backupRepository.getMountOptions());
292294
restoreCommand.setVmExists(null);
293295
restoreCommand.setVmState(vmNameAndState.second());
294296
restoreCommand.setRestoreVolumeUUID(volumeUuid);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Answer execute(RestoreBackupCommand command, LibvirtComputingResource ser
6767
int lastIndex = volumePath.lastIndexOf("/");
6868
newVolumeId = volumePath.substring(lastIndex + 1);
6969
restoreVolume(backupPath, backupRepoType, backupRepoAddress, volumePath, diskType, restoreVolumeUuid,
70-
new Pair<>(vmName, command.getVmState()));
70+
new Pair<>(vmName, command.getVmState()), mountOptions);
7171
} else if (Boolean.TRUE.equals(vmExists)) {
7272
restoreVolumesOfExistingVM(volumePaths, backupPath, backupRepoType, backupRepoAddress, mountOptions);
7373
} else {
@@ -80,7 +80,7 @@ public Answer execute(RestoreBackupCommand command, LibvirtComputingResource ser
8080
private void restoreVolumesOfExistingVM(List<String> volumePaths, String backupPath,
8181
String backupRepoType, String backupRepoAddress, String mountOptions) {
8282
String diskType = "root";
83-
String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType);
83+
String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType, mountOptions);
8484
try {
8585
for (int idx = 0; idx < volumePaths.size(); idx++) {
8686
String volumePath = volumePaths.get(idx);
@@ -101,7 +101,7 @@ private void restoreVolumesOfExistingVM(List<String> volumePaths, String backupP
101101

102102
private void restoreVolumesOfDestroyedVMs(List<String> volumePaths, String vmName, String backupPath,
103103
String backupRepoType, String backupRepoAddress, String mountOptions) {
104-
String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType);
104+
String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType, mountOptions);
105105
String diskType = "root";
106106
try {
107107
for (int i = 0; i < volumePaths.size(); i++) {
@@ -121,8 +121,8 @@ private void restoreVolumesOfDestroyedVMs(List<String> volumePaths, String vmNam
121121
}
122122

123123
private void restoreVolume(String backupPath, String backupRepoType, String backupRepoAddress, String volumePath,
124-
String diskType, String volumeUUID, Pair<String, VirtualMachine.State> vmNameAndState) {
125-
String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType);
124+
String diskType, String volumeUUID, Pair<String, VirtualMachine.State> vmNameAndState, String mountOptions) {
125+
String mountDirectory = mountBackupDirectory(backupRepoAddress, backupRepoType, mountOptions);
126126
Pair<String, String> bkpPathAndVolUuid;
127127
try {
128128
bkpPathAndVolUuid = getBackupPath(mountDirectory, volumePath, backupPath, diskType, volumeUUID);
@@ -145,12 +145,22 @@ private void restoreVolume(String backupPath, String backupRepoType, String back
145145
}
146146

147147

148-
private String mountBackupDirectory(String backupRepoAddress, String backupRepoType) {
148+
private String mountBackupDirectory(String backupRepoAddress, String backupRepoType, String mountOptions) {
149149
String randomChars = RandomStringUtils.random(5, true, false);
150150
String mountDirectory = String.format("%s.%s",BACKUP_TEMP_FILE_PREFIX , randomChars);
151151
try {
152152
mountDirectory = Files.createTempDirectory(mountDirectory).toString();
153+
String mountOpts = null;
154+
if (Objects.nonNull(mountOptions)) {
155+
mountOpts = mountOptions;
156+
if ("cifs".equals(backupRepoType)) {
157+
mountOpts += ",nobrl";
158+
}
159+
}
153160
String mount = String.format(MOUNT_COMMAND, backupRepoType, backupRepoAddress, mountDirectory);
161+
if (Objects.nonNull(mountOpts)) {
162+
mount += " -o " + mountOpts;
163+
}
154164
Script.runSimpleBashScript(mount);
155165
} catch (Exception e) {
156166
throw new CloudRuntimeException(String.format("Failed to mount %s to %s", backupRepoType, backupRepoAddress), e);

0 commit comments

Comments
 (0)