Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore: add lsm-profile and lsm-mount-context options #1578

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libcrun/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ struct libcrun_checkpoint_restore_s
char *parent_path;
bool pre_dump;
int manage_cgroups_mode;
char *lsm_profile;
char *lsm_mount_context;
};
typedef struct libcrun_checkpoint_restore_s libcrun_checkpoint_restore_t;

Expand Down
16 changes: 16 additions & 0 deletions src/libcrun/criu.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ struct libcriu_wrapper_s
void (*criu_set_tcp_established) (bool tcp_established);
void (*criu_set_track_mem) (bool track_mem);
void (*criu_set_work_dir_fd) (int fd);
int (*criu_set_lsm_profile) (const char *name);
int (*criu_set_lsm_mount_context) (const char *name);
};

static struct libcriu_wrapper_s *libcriu_wrapper;
Expand Down Expand Up @@ -826,6 +828,20 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
cr_options->work_path = cr_options->image_path;
}

if (cr_options->lsm_profile != NULL)
{
ret = libcriu_wrapper->criu_set_lsm_profile (cr_options->lsm_profile);
if (UNLIKELY (ret != 0))
return crun_make_error (err, 0, "error setting LSM profile to `%s`", cr_options->lsm_profile);
}

if (cr_options->lsm_mount_context != NULL)
{
ret = libcriu_wrapper->criu_set_lsm_mount_context (cr_options->lsm_mount_context);
if (UNLIKELY (ret != 0))
return crun_make_error (err, 0, "error setting LSM mount context to `%s`", cr_options->lsm_mount_context);
}

/* Tell CRIU about external bind mounts. */
for (i = 0; i < def->mounts_len; i++)
{
Expand Down
12 changes: 12 additions & 0 deletions src/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ enum
OPTION_CONSOLE_SOCKET,
OPTION_FILE_LOCKS,
OPTION_MANAGE_CGROUPS_MODE,
OPTION_LSM_PROFILE,
OPTION_LSM_MOUNT_CONTEXT,
};

static char doc[] = "OCI runtime";
Expand All @@ -67,6 +69,8 @@ static struct argp_option options[]
"path to a socket that will receive the ptmx end of the tty", 0 },
{ "file-locks", OPTION_FILE_LOCKS, 0, 0, "allow file locks", 0 },
{ "manage-cgroups-mode", OPTION_MANAGE_CGROUPS_MODE, "MODE", 0, "cgroups mode: 'soft' (default), 'ignore', 'full' and 'strict'", 0 },
{ "lsm-profile", OPTION_LSM_PROFILE, "VALUE", 0, "Specify an LSM profile to be used during restore in the form of TYPE:NAME", 0 },
{ "lsm-mount-context", OPTION_LSM_MOUNT_CONTEXT, "VALUE", 0, "Specify an LSM mount context to be used during restore", 0 },
{
0,
} };
Expand Down Expand Up @@ -125,6 +129,14 @@ parse_opt (int key, char *arg, struct argp_state *state)
cr_options.manage_cgroups_mode = crun_parse_manage_cgroups_mode (argp_mandatory_argument (arg, state));
break;

case OPTION_LSM_PROFILE:
cr_options.lsm_profile = argp_mandatory_argument (arg, state);
break;

case OPTION_LSM_MOUNT_CONTEXT:
cr_options.lsm_mount_context = argp_mandatory_argument (arg, state);
break;

default:
return ARGP_ERR_UNKNOWN;
}
Expand Down
Loading