add volume remount

This commit is contained in:
Johannes Zellner
2021-10-11 15:51:16 +02:00
parent f01764617c
commit 9eed3af8b6
8 changed files with 70 additions and 0 deletions
+13
View File
@@ -6,6 +6,7 @@ exports = module.exports = {
removeMount,
validateMountOptions,
getStatus,
remount
};
const assert = require('assert'),
@@ -21,6 +22,7 @@ const assert = require('assert'),
const ADD_MOUNT_CMD = path.join(__dirname, 'scripts/addmount.sh');
const RM_MOUNT_CMD = path.join(__dirname, 'scripts/rmmount.sh');
const REMOUNT_MOUNT_CMD = path.join(__dirname, 'scripts/remountmount.sh');
const SYSTEMD_MOUNT_EJS = fs.readFileSync(path.join(__dirname, 'systemd-mount.ejs'), { encoding: 'utf8' });
// https://man7.org/linux/man-pages/man8/mount.8.html
@@ -184,3 +186,14 @@ async function tryAddMount(mount, options) {
throw new BoxError(BoxError.MOUNT_ERROR, `Failed to mount (${status.state}): ${status.message}`);
}
}
async function remount(mount) {
assert.strictEqual(typeof mount, 'object'); // { name, hostPath, mountType, mountOptions }
if (mount.mountType === 'mountpoint') return;
if (constants.TEST) return;
const [error] = await safe(shell.promises.sudo('remountMount', [ REMOUNT_MOUNT_CMD, mount.hostPath ], {}));
if (error && error.code === 2) throw new BoxError(BoxError.MOUNT_ERROR, 'Failed to remount existing mount'); // at this point, the old mount config is still there
}