Skip to content

Commit

Permalink
Discard mounts when attaching to an existing container
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Abecassis <[email protected]>
  • Loading branch information
flx42 committed Feb 25, 2022
1 parent 071de4b commit 54b34b0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
16 changes: 12 additions & 4 deletions args.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved.
*/

#include <stdio.h>
Expand Down Expand Up @@ -229,6 +229,16 @@ int add_mount(const char *source, const char *target, const char *flags)
return (rv);
}

void remove_all_mounts(void)
{
for (int i = 0; i < pyxis_args.mounts_len; ++i)
free(pyxis_args.mounts[i]);
free(pyxis_args.mounts);

pyxis_args.mounts = NULL;
pyxis_args.mounts_len = 0;
}

static int parse_mount_option(const char *option)
{
int ret;
Expand Down Expand Up @@ -460,9 +470,7 @@ bool pyxis_args_enabled(void)
void pyxis_args_free(void)
{
free(pyxis_args.image);
for (int i = 0; i < pyxis_args.mounts_len; ++i)
free(pyxis_args.mounts[i]);
free(pyxis_args.mounts);
remove_all_mounts();
free(pyxis_args.workdir);
free(pyxis_args.container_name);
free(pyxis_args.container_save);
Expand Down
4 changes: 3 additions & 1 deletion args.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved.
*/

#ifndef ARGS_H_
Expand Down Expand Up @@ -29,6 +29,8 @@ bool pyxis_args_enabled(void);

int add_mount(const char *source, const char *target, const char *flags);

void remove_all_mounts(void);

void pyxis_args_free(void);

#endif /* ARGS_H_ */
7 changes: 6 additions & 1 deletion pyxis_slurmstepd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2019-2022, NVIDIA CORPORATION. All rights reserved.
*/

#include <linux/limits.h>
Expand Down Expand Up @@ -938,6 +938,11 @@ int slurm_spank_user_init(spank_t sp, int ac, char **av)
context.container.temporary = true;
}

if (context.container.reuse_ns && context.args->mounts_len > 0) {
slurm_spank_log("pyxis: ignoring --container-mounts when attaching to a running container");
remove_all_mounts();
}

if (context.args->container_save != NULL)
context.container.save_path = strdup(context.args->container_save);

Expand Down
13 changes: 11 additions & 2 deletions tests/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ function teardown() {
run_srun --container-name=exec-test --container-remap-root bash -c "mount -t tmpfs none /mymnt && sleep 30s" &

sleep 5s # FIXME...
run_srun --container-name=exec-test findmnt /mymnt
run_srun --overlap --container-name=exec-test findmnt /mymnt
}

@test "attach to running container after directory change" {
run_srun --container-image=ubuntu:20.04 --container-name=exec-test bash -c "cd /var && sleep 30s" &

sleep 5s
run_srun --container-name=exec-test pwd
run_srun --overlap --container-name=exec-test pwd
[ "${lines[-1]}" == "/" ]
}

@test "attach to running container with --container--mounts" {
run_srun --container-image=ubuntu:20.04 --container-name=exec-test bash -c "sleep 30s" &

sleep 5s
# Verify that --container-mounts is ignored when attaching to a running container.
run_srun --overlap --container-name=exec-test --container-mounts /tmp:/mnt/pyxis_test bash -c '[ ! -d "/mnt/pyxis_test" ]'
grep -q -- 'ignoring --container-mounts' <<< "${output}"
}

0 comments on commit 54b34b0

Please sign in to comment.