* [pve-devel] [PATCH installer] proxmox-chroot: replace nix::(u)mount calls with external (u)mount
@ 2025-03-11 13:27 Christoph Heiss
2025-04-04 8:17 ` Thomas Lamprecht
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Christoph Heiss @ 2025-03-11 13:27 UTC (permalink / raw)
To: pve-devel
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [pve-devel] [PATCH installer] proxmox-chroot: replace nix::(u)mount calls with external (u)mount
2025-03-11 13:27 [pve-devel] [PATCH installer] proxmox-chroot: replace nix::(u)mount calls with external (u)mount Christoph Heiss
@ 2025-04-04 8:17 ` Thomas Lamprecht
2025-04-04 8:28 ` [pve-devel] applied: " Thomas Lamprecht
2025-04-04 11:37 ` [pve-devel] " Wolfgang Bumiller
2 siblings, 0 replies; 5+ messages in thread
From: Thomas Lamprecht @ 2025-04-04 8:17 UTC (permalink / raw)
To: Proxmox VE development discussion, Christoph Heiss
Am 11.03.25 um 14:27 schrieb Christoph Heiss:
> 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.
I'm general a big fan of dropping crates (or using as many as needed but
as few as possible), but nix is a very general thing, actually I'm
surprised we do not use it more often; maybe if we would write more of
the actual installer in rust. OTOH, nothing limits us from reintroducing
this, and then handle mounting in a more consistent manner implementation
wise - so fine by me...
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [pve-devel] applied: [PATCH installer] proxmox-chroot: replace nix::(u)mount calls with external (u)mount
2025-03-11 13:27 [pve-devel] [PATCH installer] proxmox-chroot: replace nix::(u)mount calls with external (u)mount Christoph Heiss
2025-04-04 8:17 ` Thomas Lamprecht
@ 2025-04-04 8:28 ` Thomas Lamprecht
2025-04-04 8:39 ` Christoph Heiss
2025-04-04 11:37 ` [pve-devel] " Wolfgang Bumiller
2 siblings, 1 reply; 5+ messages in thread
From: Thomas Lamprecht @ 2025-04-04 8:28 UTC (permalink / raw)
To: Proxmox VE development discussion, Christoph Heiss
Am 11.03.25 um 14:27 schrieb Christoph Heiss:
> 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(-)
>
>
applied, thanks!
btw. to throw in a crate I'd not be sad to see get removed: clap, at least
if upstream still is full in the refactoring for the sake of it and adding
yet another way to do things...
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [pve-devel] applied: [PATCH installer] proxmox-chroot: replace nix::(u)mount calls with external (u)mount
2025-04-04 8:28 ` [pve-devel] applied: " Thomas Lamprecht
@ 2025-04-04 8:39 ` Christoph Heiss
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Heiss @ 2025-04-04 8:39 UTC (permalink / raw)
To: Thomas Lamprecht; +Cc: Proxmox VE development discussion
On Fri Apr 4, 2025 at 10:28 AM CEST, Thomas Lamprecht wrote:
> Am 11.03.25 um 14:27 schrieb Christoph Heiss:
>> 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(-)
>>
>>
>
> applied, thanks!
>
> btw. to throw in a crate I'd not be sad to see get removed: clap, at least
> if upstream still is full in the refactoring for the sake of it and adding
> yet another way to do things...
Yeah, definitely, agreed! I have already been previously working on
removing it and got a ~half done local branch - but its unfortunately
bit of a bigger refactor/rewrite. I'll try to get to it again tho and
finish it.
(fwiw, looking at my notes, dropping clap would also be quite a sizeable
win w.r.t. binary sizes, with ~20% reduction for one of the binaries)
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [pve-devel] [PATCH installer] proxmox-chroot: replace nix::(u)mount calls with external (u)mount
2025-03-11 13:27 [pve-devel] [PATCH installer] proxmox-chroot: replace nix::(u)mount calls with external (u)mount Christoph Heiss
2025-04-04 8:17 ` Thomas Lamprecht
2025-04-04 8:28 ` [pve-devel] applied: " Thomas Lamprecht
@ 2025-04-04 11:37 ` Wolfgang Bumiller
2 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Bumiller @ 2025-04-04 11:37 UTC (permalink / raw)
To: Christoph Heiss; +Cc: pve-devel
On Tue, Mar 11, 2025 at 02:27:29PM +0100, Christoph Heiss wrote:
> 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`.
This makes sense in general. The `mount(2)` syscall is very raw and requires
knowledge of how a file system is to be mounted while additionally
adding a lot more features (especially when the new mount api is used
instead). The `mount(1)` call on the other hand calls out to various
file system specific helpers which provide a more user friendly
interface for various things. (Eg. you *can* definitely use `mount(2)` to
mount a ZFS, but you'd need to know the internals of how that works, and
it may change with zfs versions I think...)
Mounting is complicated in some cases ;-)
Unmounting on the other hand is rather simple and really just needs a
path... (the only sad part there is that there is no
path-file-descriptor based version)
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-04 11:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-11 13:27 [pve-devel] [PATCH installer] proxmox-chroot: replace nix::(u)mount calls with external (u)mount Christoph Heiss
2025-04-04 8:17 ` Thomas Lamprecht
2025-04-04 8:28 ` [pve-devel] applied: " Thomas Lamprecht
2025-04-04 8:39 ` Christoph Heiss
2025-04-04 11:37 ` [pve-devel] " Wolfgang Bumiller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal