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 8FE5E6622B for ; Thu, 5 Nov 2020 17:06:59 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8C3F81A791 for ; Thu, 5 Nov 2020 17:06:59 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 9527F1A775 for ; Thu, 5 Nov 2020 17:06:55 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 56A694604C for ; Thu, 5 Nov 2020 17:06:55 +0100 (CET) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Thu, 5 Nov 2020 17:06:29 +0100 Message-Id: <20201105160631.26834-2-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201105160631.26834-1-s.ivanov@proxmox.com> References: <20201105160631.26834-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.096 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [tools.pm] Subject: [pve-devel] [PATCH common] add fsfreeze helper: X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Nov 2020 16:06:59 -0000 fsfreeze_mountpoint issues the same ioctl's as fsfreeze(8) on the provided directory (the $thaw parameter deciding between '--freeze' and '--unfreeze') This is used for container backups on RBD, where snapshots on containers, which are heavy on IO, are not mountable readonly, because the ext4 is not consistent Needed to fix #2991 and #2528. The ioctl numbers were found via strace -X verbose (and compared with the kernel source). Signed-off-by: Stoiko Ivanov --- src/PVE/Tools.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 4b445ea..c61fc49 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -100,6 +100,9 @@ use constant {O_PATH => 0x00200000, use constant {AT_EMPTY_PATH => 0x1000, AT_FDCWD => -100}; +use constant {FIFREEZE => 0xc0045877, + FITHAW => 0xc0045878}; + sub run_with_timeout { my ($timeout, $code, @param) = @_; @@ -1442,6 +1445,21 @@ sub sync_mountpoint { die "syncfs '$path' failed - $syncfs_err\n" if defined $syncfs_err; } +sub fsfreeze_mountpoint { + my ($path, $thaw) = @_; + + my $op = $thaw ? 'thaw' : 'freeze'; + my $ioctl = $thaw ? FITHAW : FIFREEZE; + + sysopen my $fd, $path, O_RDONLY|O_CLOEXEC or die "failed to open $path: $!\n"; + my $ioctl_err; + if (!ioctl($fd, $ioctl, 0)) { + $ioctl_err = "$!"; + } + close($fd); + die "fs$op '$path' failed - $ioctl_err\n" if defined $ioctl_err; +} + # support sending multi-part mail messages with a text and or a HTML part # mailto may be a single email string or an array of receivers sub sendmail { -- 2.20.1