Skip to content

Commit

Permalink
Add method to return known options for MountOption
Browse files Browse the repository at this point in the history
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
  • Loading branch information
musaprg committed Jan 2, 2025
1 parent f2af633 commit a53a124
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion crates/libcontainer/src/syscall/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,50 @@ pub enum MountOption {
Nostrictatime(bool, MsFlags),
}

impl MountOption {
// Return all possible mount options
pub fn known_options() -> Vec<String> {
[
"defaults",
"ro",
"rw",
"suid",
"nosuid",
"dev",
"nodev",
"exec",
"noexec",
"sync",
"async",
"dirsync",
"remount",
"mand",
"nomand",
"atime",
"noatime",
"diratime",
"nodiratime",
"bind",
"rbind",
"unbindable",
"runbindable",
"private",
"rprivate",
"shared",
"rshared",
"slave",
"rslave",
"relatime",
"norelatime",
"strictatime",
"nostrictatime",
]
.iter()
.map(|s| s.to_string())
.collect()
}
}

impl FromStr for MountOption {
type Err = String;

Expand Down Expand Up @@ -694,12 +738,13 @@ mod tests {

use std::fs;
use std::os::unix::prelude::AsRawFd;
use std::str::FromStr;

use anyhow::{bail, Context, Result};
use nix::{fcntl, sys, unistd};
use serial_test::serial;

use super::LinuxSyscall;
use super::{LinuxSyscall, MountOption};
use crate::syscall::Syscall;

#[test]
Expand Down Expand Up @@ -761,4 +806,15 @@ mod tests {
unistd::close(fd)?;
Ok(())
}

#[test]
fn test_known_mount_options_implemented() -> Result<()> {
for option in MountOption::known_options() {
match MountOption::from_str(&option) {
Ok(_) => {}
Err(e) => bail!("failed to parse mount option: {}", e),
}
}
Ok(())
}
}

0 comments on commit a53a124

Please sign in to comment.