all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH container v2 1/2] add fsfreeze helper:
Date: Fri,  6 Nov 2020 12:24:24 +0100	[thread overview]
Message-ID: <20201106112425.8282-4-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20201106112425.8282-1-s.ivanov@proxmox.com>

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 verified with the
kernel documentation).

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 src/PVE/LXC.pm | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 9c150d9..ee86b37 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -35,6 +35,10 @@ use PVE::LXC::CGroup;
 use PVE::LXC::Monitor;
 
 use Time::HiRes qw (gettimeofday);
+
+use constant {FIFREEZE => 0xc0045877,
+              FITHAW   => 0xc0045878};
+
 my $have_sdn;
 eval {
     require PVE::Network::SDN::Zones;
@@ -1090,6 +1094,21 @@ my $get_container_namespace = sub {
     return $open_namespace->($vmid, $pid, $kind);
 };
 
+sub fsfreeze_mountpoint {
+    my ($path, $thaw) = @_;
+
+    my $op = $thaw ? 'thaw' : 'freeze';
+    my $ioctl = $thaw ? FITHAW : FIFREEZE;
+
+    sysopen my $fd, $path, O_RDONLY 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;
+}
+
 my $do_syncfs = sub {
     my ($vmid, $pid, $socket) = @_;
 
-- 
2.20.1





  parent reply	other threads:[~2020-11-06 11:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-06 11:24 [pve-devel] [PATCH container/storage v2] add fsfreeze/thaw for rbd snapshots Stoiko Ivanov
2020-11-06 11:24 ` [pve-devel] [PATCH storage v2 1/2] fix typo in comment Stoiko Ivanov
2020-11-06 11:24 ` [pve-devel] [PATCH storage v2 2/2] add check for fsfreeze before snapshot Stoiko Ivanov
2020-11-06 11:24 ` Stoiko Ivanov [this message]
2020-11-06 11:24 ` [pve-devel] [PATCH container v2 2/2] snapshot creation: fsfreeze mountpoints, if needed Stoiko Ivanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201106112425.8282-4-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal