2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 01:51:51 +00:00

zdtm/lib: add "bind" desc option

Add {'bind': 'path/to/bindmount'} zdtm descriptor option, so that in
test mount namespace a directory bindmount can be created before running
the test.

This is useful to leave test directory writable (e.g. for logs) while
the test makes root mount readonly. note: We create this bindmount early
so that all test files are opened on it initially and not on the below
mount. Will be used in mnt_ro_root test.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
Pavel Tikhomirov 2025-04-02 12:47:46 +08:00 committed by Andrei Vagin
parent 6a91ad8f71
commit 7362ad2f02
2 changed files with 17 additions and 1 deletions

View File

@ -443,6 +443,7 @@ class zdtm_test:
self._bins = [name]
self._env = {'TMPDIR': os.environ.get('TMPDIR', '/tmp')}
self._deps = desc.get('deps', [])
self._bind = desc.get('bind')
self.auto_reap = True
def __make_action(self, act, env=None, root=None):
@ -513,6 +514,8 @@ class zdtm_test:
if self.__flavor.ns:
env['ZDTM_NEWNS'] = "1"
env['ZDTM_ROOT'] = self.__flavor.root
if self._bind:
env['ZDTM_BIND'] = self._bind
env['ZDTM_DEV'] = self.__flavor.devpath
env['PATH'] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

View File

@ -28,8 +28,9 @@ extern int pivot_root(const char *new_root, const char *put_old);
static int prepare_mntns(void)
{
int dfd, ret;
char *root, *criu_path, *dev_path;
char *root, *criu_path, *dev_path, *zdtm_bind;
char path[PATH_MAX];
char bind_path[PATH_MAX];
root = getenv("ZDTM_ROOT");
if (!root) {
@ -52,6 +53,18 @@ static int prepare_mntns(void)
return -1;
}
zdtm_bind = getenv("ZDTM_BIND");
if (zdtm_bind) {
/*
* Bindmount the directory to itself.
*/
snprintf(bind_path, sizeof(bind_path), "%s/%s", root, zdtm_bind);
if (mount(bind_path, bind_path, NULL, MS_BIND, NULL)) {
fprintf(stderr, "Can't bind-mount ZDTM_BIND: %m\n");
return -1;
}
}
dev_path = getenv("ZDTM_DEV");
if (dev_path) {
snprintf(path, sizeof(path), "%s/dev", root);