From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2AF07687A6 for ; Thu, 22 Jul 2021 09:33:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 12810E3A7 for ; Thu, 22 Jul 2021 09:33:21 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 7271EE39E for ; Thu, 22 Jul 2021 09:33:20 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3853A425AD for ; Thu, 22 Jul 2021 09:33:20 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Thu, 22 Jul 2021 09:33:19 +0200 Message-Id: <20210722073319.55913-1-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.662 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 Subject: [pbs-devel] [PATCH proxmox] fs: link fallback for atomic create X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Jul 2021 07:33:51 -0000 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 --- 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>( // 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