* [pbs-devel] [PATCH proxmox] fs: link fallback for atomic create
@ 2021-07-22 7:33 Wolfgang Bumiller
2021-07-22 7:44 ` [pbs-devel] applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Wolfgang Bumiller @ 2021-07-22 7:33 UTC (permalink / raw)
To: pbs-devel
Some file systems don't support renameat2's RENAME_NOREPLACE
flag (eg. ZFS), at the some time, some other file systems
don't support hardlinks via link (eg. vfat, cifs), so we now
try both: first the rename (since it's more efficient), then
link+unlink for the rest.
If both fail, the file system is simply not supported for
our purposes anyway...
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
proxmox/src/tools/fs.rs | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/proxmox/src/tools/fs.rs b/proxmox/src/tools/fs.rs
index 8087cc8..1a2a51f 100644
--- a/proxmox/src/tools/fs.rs
+++ b/proxmox/src/tools/fs.rs
@@ -236,14 +236,22 @@ pub fn atomic_open_or_create_file<P: AsRef<Path>>(
// the initialization, the first one wins!
let rename_result = temp_file_name.with_nix_path(|c_file_name| {
path.with_nix_path(|new_path| unsafe {
- let rc = libc::renameat2(
+ // This also works on file systems which don't support hardlinks (eg. vfat)
+ match Errno::result(libc::renameat2(
libc::AT_FDCWD,
c_file_name.as_ptr(),
libc::AT_FDCWD,
new_path.as_ptr(),
libc::RENAME_NOREPLACE,
- );
- nix::errno::Errno::result(rc)
+ )) {
+ Err(nix::Error::Sys(Errno::EINVAL)) => (), // dumb file system, try `link`+`unlink`
+ other => return other,
+ };
+ // but some file systems don't support `RENAME_NOREPLACE`
+ // so we just use `link` + `unlink` instead
+ let result = Errno::result(libc::link(c_file_name.as_ptr(), new_path.as_ptr()));
+ let _ = libc::unlink(c_file_name.as_ptr());
+ result
})
});
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pbs-devel] applied: [PATCH proxmox] fs: link fallback for atomic create
2021-07-22 7:33 [pbs-devel] [PATCH proxmox] fs: link fallback for atomic create Wolfgang Bumiller
@ 2021-07-22 7:44 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2021-07-22 7:44 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Wolfgang Bumiller
On 22.07.21 09:33, Wolfgang Bumiller wrote:
> Some file systems don't support renameat2's RENAME_NOREPLACE
> flag (eg. ZFS), at the some time, some other file systems
> don't support hardlinks via link (eg. vfat, cifs), so we now
> try both: first the rename (since it's more efficient), then
> link+unlink for the rest.
>
> If both fail, the file system is simply not supported for
> our purposes anyway...
>
> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
> ---
> proxmox/src/tools/fs.rs | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
>
applied, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-07-22 7:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22 7:33 [pbs-devel] [PATCH proxmox] fs: link fallback for atomic create Wolfgang Bumiller
2021-07-22 7:44 ` [pbs-devel] applied: " Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox