Skip to content

Commit e5b43a0

Browse files
committed
nspawn: add volatile mode multiplexer call setup_volatile_mode()
Just some refactoring, no change in behaviour.
1 parent 0646d3c commit e5b43a0

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

src/nspawn/nspawn-mount.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,8 @@ int mount_custom(
856856
return 0;
857857
}
858858

859-
int setup_volatile_state(
859+
static int setup_volatile_state(
860860
const char *directory,
861-
VolatileMode mode,
862861
bool userns, uid_t uid_shift, uid_t uid_range,
863862
const char *selinux_apifs_context) {
864863

@@ -868,11 +867,7 @@ int setup_volatile_state(
868867

869868
assert(directory);
870869

871-
if (mode != VOLATILE_STATE)
872-
return 0;
873-
874-
/* --volatile=state means we simply overmount /var
875-
with a tmpfs, and the rest read-only. */
870+
/* --volatile=state means we simply overmount /var with a tmpfs, and the rest read-only. */
876871

877872
r = bind_remount_recursive(directory, true, NULL);
878873
if (r < 0)
@@ -893,9 +888,8 @@ int setup_volatile_state(
893888
return mount_verbose(LOG_ERR, "tmpfs", p, "tmpfs", MS_STRICTATIME, options);
894889
}
895890

896-
int setup_volatile(
891+
static int setup_volatile_yes(
897892
const char *directory,
898-
VolatileMode mode,
899893
bool userns, uid_t uid_shift, uid_t uid_range,
900894
const char *selinux_apifs_context) {
901895

@@ -907,11 +901,8 @@ int setup_volatile(
907901

908902
assert(directory);
909903

910-
if (mode != VOLATILE_YES)
911-
return 0;
912-
913-
/* --volatile=yes means we mount a tmpfs to the root dir, and
914-
the original /usr to use inside it, and that read-only. */
904+
/* --volatile=yes means we mount a tmpfs to the root dir, and the original /usr to use inside it, and that
905+
read-only. */
915906

916907
if (!mkdtemp(template))
917908
return log_error_errno(errno, "Failed to create temporary directory: %m");
@@ -968,6 +959,25 @@ int setup_volatile(
968959
return r;
969960
}
970961

962+
int setup_volatile_mode(
963+
const char *directory,
964+
VolatileMode mode,
965+
bool userns, uid_t uid_shift, uid_t uid_range,
966+
const char *selinux_apifs_context) {
967+
968+
switch (mode) {
969+
970+
case VOLATILE_YES:
971+
return setup_volatile_yes(directory, userns, uid_shift, uid_range, selinux_apifs_context);
972+
973+
case VOLATILE_STATE:
974+
return setup_volatile_state(directory, userns, uid_shift, uid_range, selinux_apifs_context);
975+
976+
default:
977+
return 0;
978+
}
979+
}
980+
971981
/* Expects *pivot_root_new and *pivot_root_old to be initialised to allocated memory or NULL. */
972982
int pivot_root_parse(char **pivot_root_new, char **pivot_root_old, const char *s) {
973983
_cleanup_free_ char *root_new = NULL, *root_old = NULL;

src/nspawn/nspawn-mount.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ int mount_sysfs(const char *dest, MountSettingsMask mount_settings);
4949

5050
int mount_custom(const char *dest, CustomMount *mounts, size_t n, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
5151

52-
int setup_volatile(const char *directory, VolatileMode mode, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
53-
int setup_volatile_state(const char *directory, VolatileMode mode, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
52+
int setup_volatile_mode(const char *directory, VolatileMode mode, bool userns, uid_t uid_shift, uid_t uid_range, const char *selinux_apifs_context);
5453

5554
int pivot_root_parse(char **pivot_root_new, char **pivot_root_old, const char *s);
5655
int setup_pivot_root(const char *directory, const char *pivot_root_new, const char *pivot_root_old);

src/nspawn/nspawn.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,17 +2933,7 @@ static int outer_child(
29332933
if (r < 0)
29342934
return r;
29352935

2936-
r = setup_volatile(
2937-
directory,
2938-
arg_volatile_mode,
2939-
arg_userns_mode != USER_NAMESPACE_NO,
2940-
arg_uid_shift,
2941-
arg_uid_range,
2942-
arg_selinux_context);
2943-
if (r < 0)
2944-
return r;
2945-
2946-
r = setup_volatile_state(
2936+
r = setup_volatile_mode(
29472937
directory,
29482938
arg_volatile_mode,
29492939
arg_userns_mode != USER_NAMESPACE_NO,

0 commit comments

Comments
 (0)