From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 620701FF15E for <inbox@lore.proxmox.com>; Tue, 11 Mar 2025 14:27:51 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0A6FE10E11; Tue, 11 Mar 2025 14:27:43 +0100 (CET) From: Christoph Heiss <c.heiss@proxmox.com> To: pve-devel@lists.proxmox.com Date: Tue, 11 Mar 2025 14:27:29 +0100 Message-ID: <20250311132733.820837-1-c.heiss@proxmox.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [main.rs] Subject: [pve-devel] [PATCH installer] proxmox-chroot: replace nix::(u)mount calls with external (u)mount X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Comes with a reduction of 52 -> 40 in terms of crate dependencies for proxmox-chroot, 198 -> 192 for a full workspace build. Currently, this is done inconsistently anyway, i.e. there are calls to the external mount(8) as well as mount(2) and umount(2) via `nix`. Just switch over to calling the external programs completely, which in turn allows to drop the `nix` crate dependency from the tree. No functional changes. Signed-off-by: Christoph Heiss <c.heiss@proxmox.com> --- debian/control | 1 - proxmox-chroot/Cargo.toml | 1 - proxmox-chroot/src/main.rs | 81 +++++++++++++++++++++++++------------- 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/debian/control b/debian/control index 1ab4f19..dec07ed 100644 --- a/debian/control +++ b/debian/control @@ -15,7 +15,6 @@ Build-Depends: cargo:native, librust-glob-0.3-dev, librust-hex-0.4-dev, librust-native-tls-dev, - librust-nix-0.26+default-dev, librust-pretty-assertions-1.4-dev, librust-regex-1+default-dev (>= 1.7~~), librust-rustls-0.21+dangerous-configuration-dev, diff --git a/proxmox-chroot/Cargo.toml b/proxmox-chroot/Cargo.toml index a23f757..7a1390a 100644 --- a/proxmox-chroot/Cargo.toml +++ b/proxmox-chroot/Cargo.toml @@ -14,4 +14,3 @@ serde_json.workspace = true regex.workspace = true clap = { version = "4.0", features = ["derive"] } -nix = "0.26.1" diff --git a/proxmox-chroot/src/main.rs b/proxmox-chroot/src/main.rs index f51f6d0..ef339ed 100644 --- a/proxmox-chroot/src/main.rs +++ b/proxmox-chroot/src/main.rs @@ -1,12 +1,11 @@ use std::{ fs, io, - path::{self, PathBuf}, + path::{self, Path, PathBuf}, process::Command, }; use anyhow::{Result, bail}; use clap::{Args, Parser, Subcommand, ValueEnum}; -use nix::mount::{MsFlags, mount, umount}; use proxmox_installer_common::{ RUNTIME_DIR, options::FsType, @@ -118,9 +117,7 @@ fn cleanup(args: &CommandCleanup) -> Result<()> { match fs { Filesystems::Zfs => umount_zpool(), - Filesystems::Xfs => umount_fs()?, - Filesystems::Ext4 => umount_fs()?, - _ => (), + Filesystems::Btrfs | Filesystems::Xfs | Filesystems::Ext4 => umount(Path::new(TARGET_DIR))?, } println!("Chroot cleanup done. You can now reboot or leave the shell."); @@ -213,7 +210,7 @@ fn mount_fs() -> Result<()> { match Command::new("mount") .arg(format!("/dev/mapper/{product}-root")) - .arg("/target") + .arg(TARGET_DIR) .output() { Err(e) => bail!("{e}"), @@ -232,9 +229,25 @@ fn mount_fs() -> Result<()> { Ok(()) } -fn umount_fs() -> Result<()> { - umount(TARGET_DIR)?; - Ok(()) +fn umount(path: &Path) -> Result<()> { + match Command::new("umount") + .arg("--recursive") + .arg("--verbose") + .arg(path) + .output() + { + Ok(output) => { + if output.status.success() { + Ok(()) + } else { + bail!( + "unmounting of {path:?} failed: {}", + String::from_utf8(output.stderr)? + ) + } + } + Err(err) => bail!("unmounting of {path:?} failed: {:#}", err), + } } fn mount_btrfs(btrfs_uuid: Option<String>) -> Result<()> { @@ -246,7 +259,7 @@ fn mount_btrfs(btrfs_uuid: Option<String>) -> Result<()> { match Command::new("mount") .arg("--uuid") .arg(uuid) - .arg("/target") + .arg(TARGET_DIR) .output() { Err(e) => bail!("{e}"), @@ -303,36 +316,48 @@ fn get_btrfs_uuid() -> Result<String> { Ok(uuids[0].into()) } -fn bindmount() -> Result<()> { - println!("Bind mounting"); - // https://github.com/nix-rust/nix/blob/7badbee1e388618457ed0d725c1091359f253012/test/test_mount.rs#L19 - // https://github.com/nix-rust/nix/blob/7badbee1e388618457ed0d725c1091359f253012/test/test_mount.rs#L146 - const NONE: Option<&'static [u8]> = None; +fn do_bindmount(source: &Path, target: &Path) -> Result<()> { + match Command::new("mount") + .arg("--bind") + .arg(source) + .arg(target) + .output() + { + Ok(output) => { + if output.status.success() { + Ok(()) + } else { + bail!( + "bind-mount of {source:?} to {target:?} failed: {}", + String::from_utf8(output.stderr)? + ) + } + } + Err(err) => bail!("bind-mount of {source:?} to {target:?} failed: {:#}", err), + } +} + +fn bindmount() -> Result<()> { + println!("Bind-mounting virtual filesystems"); - let flags = MsFlags::MS_BIND; for item in BINDMOUNTS { let source = path::Path::new("/").join(item); let target = path::Path::new(TARGET_DIR).join(item); - println!("Bindmount {source:?} to {target:?}"); - mount(Some(source.as_path()), target.as_path(), NONE, flags, NONE)?; + println!("Bind-mounting {source:?} to {target:?}"); + do_bindmount(&source, &target)?; } let answer_path = path::Path::new("/mnt").join(ANSWER_MP); + if answer_path.exists() { let target = path::Path::new(TARGET_DIR).join("mnt").join(ANSWER_MP); - println!("Create dir {target:?}"); + println!("Creating target directory {target:?}"); fs::create_dir_all(&target)?; - println!("Bindmount {answer_path:?} to {target:?}"); - mount( - Some(answer_path.as_path()), - target.as_path(), - NONE, - flags, - NONE, - )?; + println!("Bind-mounting {answer_path:?} to {target:?}"); + do_bindmount(&answer_path, &target)?; } Ok(()) } @@ -349,7 +374,7 @@ fn bind_umount() -> Result<()> { let answer_target = path::Path::new(TARGET_DIR).join("mnt").join(ANSWER_MP); if answer_target.exists() { println!("Unmounting and removing answer mountpoint"); - if let Err(e) = umount(answer_target.as_os_str()) { + if let Err(e) = umount(&answer_target) { eprintln!("{e}"); } if let Err(e) = fs::remove_dir(answer_target) { -- 2.48.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel