Skip to content

Commit 38c1579

Browse files
committed
initramfs: Allow mounting overlay with flags
1 parent c3c1602 commit 38c1579

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

crates/initramfs/src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ fn overlay_state(
217217
state: impl AsFd,
218218
source: &str,
219219
mode: Option<rustix::fs::Mode>,
220+
mount_attr_flags: Option<MountAttrFlags>,
220221
) -> Result<()> {
221222
let upper = ensure_dir(state.as_fd(), "upper", mode)?;
222223
let work = ensure_dir(state.as_fd(), "work", mode)?;
@@ -230,16 +231,26 @@ fn overlay_state(
230231
let fs = fsmount(
231232
overlayfs.as_fd(),
232233
FsMountFlags::FSMOUNT_CLOEXEC,
233-
MountAttrFlags::empty(),
234+
mount_attr_flags.unwrap_or(MountAttrFlags::empty()),
234235
)?;
235236

236237
mount_at_wrapper(fs, base, ".").context("Moving mount")
237238
}
238239

239240
/// Mounts a transient overlayfs with passed in fd as the lowerdir
240241
#[context("Mounting transient overlayfs")]
241-
pub fn overlay_transient(base: impl AsFd, mode: Option<rustix::fs::Mode>) -> Result<()> {
242-
overlay_state(base, prepare_mount(mount_tmpfs()?)?, "transient", mode)
242+
pub fn overlay_transient(
243+
base: impl AsFd,
244+
mode: Option<rustix::fs::Mode>,
245+
mount_attr_flags: Option<MountAttrFlags>,
246+
) -> Result<()> {
247+
overlay_state(
248+
base,
249+
prepare_mount(mount_tmpfs()?)?,
250+
"transient",
251+
mode,
252+
mount_attr_flags,
253+
)
243254
}
244255

245256
#[context("Opening rootfs")]
@@ -307,8 +318,9 @@ pub fn mount_subdir(
307318
open_dir(&state, subdir)?,
308319
"overlay",
309320
None,
321+
None,
310322
),
311-
MountType::Transient => overlay_transient(open_dir(&new_root, subdir)?, None),
323+
MountType::Transient => overlay_transient(open_dir(&new_root, subdir)?, None, None),
312324
}
313325
}
314326

@@ -371,7 +383,7 @@ pub fn setup_root(args: Args) -> Result<()> {
371383
}
372384

373385
if config.root.transient {
374-
overlay_transient(&new_root, None)?;
386+
overlay_transient(&new_root, None, None)?;
375387
}
376388

377389
match composefs::mount::mount_at(&sysroot_clone, &new_root, "sysroot") {

0 commit comments

Comments
 (0)