<div dir="ltr">how to update this for my test proxmox backup server?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 12, 2024 at 3:55 AM Christoph Heiss <<a href="mailto:c.heiss@proxmox.com">c.heiss@proxmox.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Saves us from converting the paths to raw C strings ourselves, thus<br>
simplifying it quite a bit.<br>
<br>
Since the `nix` crate does not provide link() directly, only linkat(),<br>
that is used instead - which behaves exactly the same as link() when<br>
using AT_FDCWD and an empty flag set.<br>
<br>
No functional changes.<br>
<br>
Signed-off-by: Christoph Heiss <<a href="mailto:c.heiss@proxmox.com" target="_blank">c.heiss@proxmox.com</a>><br>
---<br>
Changes v1 -> v2:<br>
* use `AtFlags` instead of deprecated `LinkatFlags` (thanks Christian!)<br>
* use an empty flag set, as AT_SYMLINK_NOFOLLOW is the default anyway<br>
for linkat()<br>
* adjust accompanying comment to mention `linkat` instead of `link`<br>
<br>
proxmox-sys/src/fs/<a href="http://file.rs" rel="noreferrer" target="_blank">file.rs</a> | 53 +++++++++++++++++---------------------<br>
1 file changed, 23 insertions(+), 30 deletions(-)<br>
<br>
diff --git a/proxmox-sys/src/fs/<a href="http://file.rs" rel="noreferrer" target="_blank">file.rs</a> b/proxmox-sys/src/fs/<a href="http://file.rs" rel="noreferrer" target="_blank">file.rs</a><br>
index ac513891..b2d6ddf6 100644<br>
--- a/proxmox-sys/src/fs/<a href="http://file.rs" rel="noreferrer" target="_blank">file.rs</a><br>
+++ b/proxmox-sys/src/fs/<a href="http://file.rs" rel="noreferrer" target="_blank">file.rs</a><br>
@@ -10,7 +10,6 @@ use nix::errno::Errno;<br>
use nix::fcntl::OFlag;<br>
use nix::sys::stat;<br>
use nix::unistd;<br>
-use nix::NixPath;<br>
use serde_json::Value;<br>
<br>
use proxmox_lang::try_block;<br>
@@ -266,30 +265,32 @@ pub fn atomic_open_or_create_file<P: AsRef<Path>>(<br>
<br>
// rotate the file into place, but use `RENAME_NOREPLACE`, so in case 2 processes race against<br>
// the initialization, the first one wins!<br>
- let rename_result = temp_file_name.with_nix_path(|c_file_name| {<br>
- path.with_nix_path(|new_path| unsafe {<br>
- // This also works on file systems which don't support hardlinks (eg. vfat)<br>
- match Errno::result(libc::renameat2(<br>
- libc::AT_FDCWD,<br>
- c_file_name.as_ptr(),<br>
- libc::AT_FDCWD,<br>
- new_path.as_ptr(),<br>
- libc::RENAME_NOREPLACE,<br>
- )) {<br>
- Err(Errno::EINVAL) => (), // dumb file system, try `link`+`unlink`<br>
- other => return other,<br>
- };<br>
- // but some file systems don't support `RENAME_NOREPLACE`<br>
- // so we just use `link` + `unlink` instead<br>
- let result = Errno::result(libc::link(c_file_name.as_ptr(), new_path.as_ptr()));<br>
- let _ = libc::unlink(c_file_name.as_ptr());<br>
+ let rename_result = match nix::fcntl::renameat2(<br>
+ None, // AT_FDCWD<br>
+ &temp_file_name,<br>
+ None, // AT_FDCWD<br>
+ path,<br>
+ nix::fcntl::RenameFlags::RENAME_NOREPLACE,<br>
+ ) {<br>
+ Err(Errno::EINVAL) => {<br>
+ // some file systems don't support `RENAME_NOREPLACE`<br>
+ // so we just use `linkat` + `unlink` instead<br>
+ let result = nix::unistd::linkat(<br>
+ None,<br>
+ &temp_file_name,<br>
+ None,<br>
+ &path.to_path_buf(),<br>
+ nix::unistd::AtFlags::empty(),<br>
+ );<br>
+ let _ = nix::unistd::unlink(&temp_file_name);<br>
result<br>
- })<br>
- });<br>
+ }<br>
+ other => other,<br>
+ };<br>
<br>
match rename_result {<br>
- Ok(Ok(Ok(_))) => Ok(file),<br>
- Ok(Ok(Err(err))) => {<br>
+ Ok(_) => Ok(file),<br>
+ Err(err) => {<br>
// if another process has already raced ahead and created<br>
// the file, let's just open theirs instead:<br>
let _ = nix::unistd::unlink(&temp_file_name);<br>
@@ -308,14 +309,6 @@ pub fn atomic_open_or_create_file<P: AsRef<Path>>(<br>
);<br>
}<br>
}<br>
- Ok(Err(err)) => {<br>
- let _ = nix::unistd::unlink(&temp_file_name);<br>
- bail!("with_nix_path {:?} failed - {}", path, err);<br>
- }<br>
- Err(err) => {<br>
- let _ = nix::unistd::unlink(&temp_file_name);<br>
- bail!("with_nix_path {:?} failed - {}", temp_file_name, err);<br>
- }<br>
}<br>
}<br>
<br>
-- <br>
2.45.1<br>
<br>
<br>
<br>
_______________________________________________<br>
pbs-devel mailing list<br>
<a href="mailto:pbs-devel@lists.proxmox.com" target="_blank">pbs-devel@lists.proxmox.com</a><br>
<a href="https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel" rel="noreferrer" target="_blank">https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel</a><br>
<br>
</blockquote></div>