Fix tryAddMount usage

This commit is contained in:
Girish Ramakrishnan
2021-06-21 22:37:32 -07:00
parent 3ba2f96d51
commit ceddabd691
4 changed files with 20 additions and 21 deletions

View File

@@ -408,29 +408,33 @@ function setBackupConfig(backupConfig, callback) {
backups.injectPrivateFields(backupConfig, oldConfig);
let oldMount = null, newMount = null;
if (backups.isMountProvider(oldConfig.provider)) {
oldMount = {
name: 'backup',
hostPath: oldConfig.mountPoint,
mountType: oldConfig.provider,
mountOptions: oldConfig.mountOptions
};
}
if (backups.isMountProvider(backupConfig.provider) && (!backups.isMountProvider(oldConfig.provider) || mountOptionsChanged(oldConfig, backupConfig))) {
error = mounts.validateMountOptions(backupConfig.provider, backupConfig.mountOptions);
if (error) return callback(error);
newMount = {
const newMount = {
name: 'backup',
hostPath: backupConfig.mountPoint,
mountType: backupConfig.provider,
mountOptions: backupConfig.mountOptions
};
[error] = await safe(mounts.tryAddMount(newMount, oldMount, { times: 20, interval: 500 })); // 10 seconds
if (error) return callback(error);
[error] = await safe(mounts.tryAddMount(newMount, { timeout: 10 })); // 10 seconds
if (error) {
if (backups.isMountProvider(oldConfig.provider)) { // put back the old mount configuration
debug('setBackupConfig: rolling back to previous mount configuration');
await safe(mounts.tryAddMount({
name: 'backup',
hostPath: oldConfig.mountPoint,
mountType: oldConfig.provider,
mountOptions: oldConfig.mountOptions
}, { timeout: 10 }));
}
return callback(error);
}
}
backups.testConfig(backupConfig, async function (error) {
@@ -450,11 +454,6 @@ function setBackupConfig(backupConfig, callback) {
settingsdb.set(exports.BACKUP_CONFIG_KEY, JSON.stringify(backupConfig), async function (error) {
if (error) return callback(error);
if (oldMount && (!backups.isMountProvider(backupConfig.provider) || (newMount && newMount.hostPath !== oldMount.hostPath))) {
debug('setBackupConfig: removing old mount configuration');
await safe(mounts.removeMount(oldMount));
}
notifyChange(exports.BACKUP_CONFIG_KEY, backupConfig);
backups.configureCollectd(backupConfig, callback);