* [pve-devel] [PATCH common 1/2] tools: add fchmodat syscall
2025-12-16 18:08 [pve-devel] [PATCH common/container 0/2] inherit attributes from preexisting directory during mountpoint setup Filip Schauer
@ 2025-12-16 18:08 ` Filip Schauer
2025-12-16 18:08 ` [pve-devel] [PATCH container 2/2] mountpoint_insert_staged: inherit attributes if directory already exists Filip Schauer
1 sibling, 0 replies; 3+ messages in thread
From: Filip Schauer @ 2025-12-16 18:08 UTC (permalink / raw)
To: pve-devel
The fchmodat syscall changes the mode of a file relative to a file
descriptor.
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
src/PVE/Syscall.pm | 1 +
src/PVE/Tools.pm | 11 +++++++++++
2 files changed, 12 insertions(+)
diff --git a/src/PVE/Syscall.pm b/src/PVE/Syscall.pm
index 68e16fe..606cc56 100644
--- a/src/PVE/Syscall.pm
+++ b/src/PVE/Syscall.pm
@@ -22,6 +22,7 @@ BEGIN {
setresuid => &SYS_setresuid,
fallocate => &SYS_fallocate,
fchownat => &SYS_fchownat,
+ fchmodat => &SYS_fchmodat,
mount => &SYS_mount,
renameat2 => &SYS_renameat2,
open_tree => &SYS_open_tree,
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 3c6f2fb..a7bb3da 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -1505,6 +1505,17 @@ sub fchownat($$$$$) {
) == 0;
}
+sub fchmodat($$$$) {
+ my ($dirfd, $pathname, $mode, $flags) = @_;
+ return syscall(
+ PVE::Syscall::fchmodat,
+ int($dirfd),
+ $pathname,
+ int($mode),
+ int($flags),
+ ) == 0;
+}
+
my $salt_starter = time();
sub encrypt_pw {
--
2.47.3
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 3+ messages in thread* [pve-devel] [PATCH container 2/2] mountpoint_insert_staged: inherit attributes if directory already exists
2025-12-16 18:08 [pve-devel] [PATCH common/container 0/2] inherit attributes from preexisting directory during mountpoint setup Filip Schauer
2025-12-16 18:08 ` [pve-devel] [PATCH common 1/2] tools: add fchmodat syscall Filip Schauer
@ 2025-12-16 18:08 ` Filip Schauer
1 sibling, 0 replies; 3+ messages in thread
From: Filip Schauer @ 2025-12-16 18:08 UTC (permalink / raw)
To: pve-devel
Make mount points inherit the uid, gid, and access mode if the directory
already exists in the container file system. This makes setting up mount
points more convenient when attributes different from uid=0, gid=0,
mode=755 are required.
As an example, this ensures that directories like /app/data and
/app/cache in the docker.io/weblate/weblate OCI image retain the correct
permissions when adding mount points over them.
While not explicitly specified by the OCI spec, this matches the
behaviour of implementations such as Docker and Podman.
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
src/PVE/LXC.pm | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index e5ff3a1..bf4899f 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -2130,6 +2130,13 @@ sub mountpoint_insert_staged {
my $dest_fd = walk_tree_nofollow_fd('/', $rootdir_fd, $mp_dir, 1, $root_uid, $root_gid);
+ # Preserve attributes of destination directory
+ my ($mode, $uid, $gid) = (stat($dest_fd))[2, 4, 5];
+ PVE::Tools::fchownat(fileno($mount_fd), '', $uid, $gid, PVE::Tools::AT_EMPTY_PATH)
+ or die "failed to propagate uid and gid to mountpoint: $!\n";
+ PVE::Tools::fchmodat(fileno($mount_fd), '.', $mode, 0)
+ or die "failed to propagate access mode to mountpoint: $!\n";
+
PVE::Tools::move_mount(
fileno($mount_fd),
'',
--
2.47.3
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
^ permalink raw reply [flat|nested] 3+ messages in thread