Skip to content

Commit

Permalink
ksud: use bind mount to serve module webui
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed Feb 22, 2024
1 parent e85646f commit 355b55a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
12 changes: 12 additions & 0 deletions userspace/ksud/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ enum Module {
#[arg(default_value = "8080")]
port: u16,
},
/// Link modules for manager
LinkManager {
/// module id
mid: String,
/// Manager's pid
pid: i32,
/// Manager's package name
pkg: String,
},
}

#[derive(clap::Subcommand, Debug)]
Expand Down Expand Up @@ -273,6 +282,9 @@ pub fn run() -> Result<()> {
Module::List => module::list_modules(),
Module::Shrink => module::shrink_ksu_images(),
Module::Serve { id, port } => server::serve_module(&id, port),
Module::LinkManager { mid, pid, pkg } => {
module::link_module_for_manager(pid, &pkg, &mid)
}
}
}
Commands::Install => event::install(),
Expand Down
21 changes: 21 additions & 0 deletions userspace/ksud/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,3 +703,24 @@ pub fn shrink_ksu_images() -> Result<()> {
}
Ok(())
}

#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn link_module_for_manager(pid: i32, pkg: &str, mid: &str) -> Result<()> {
// switch to manager's mnt ns
utils::switch_mnt_ns(pid)?;
let target = PathBuf::from("/data/data").join(pkg).join("webroot");

// umount previous mount
let _ = mount::umount_dir(&target);

let src = PathBuf::from(defs::MODULE_DIR)
.join(mid)
.join(defs::MODULE_WEB_DIR);
mount::bind_mount(src, &target)?;
Ok(())
}

#[cfg(not(any(target_os = "linux", target_os = "android")))]
pub fn link_module_for_manager(_pid: i32, _pkg: &str, _mid: &str) -> Result<()> {
unimplemented!()
}
2 changes: 1 addition & 1 deletion userspace/ksud/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn mount_tmpfs(dest: impl AsRef<Path>) -> Result<()> {
}

#[cfg(any(target_os = "linux", target_os = "android"))]
fn bind_mount(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
pub fn bind_mount(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
info!(
"bind mount {} -> {}",
from.as_ref().display(),
Expand Down

0 comments on commit 355b55a

Please sign in to comment.