]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added generic plugin action used when setting snapshot read-only 1048/head
authorArvin Schnell <aschnell@suse.de>
Tue, 2 Sep 2025 13:08:03 +0000 (15:08 +0200)
committerArvin Schnell <aschnell@suse.de>
Tue, 2 Sep 2025 13:08:03 +0000 (15:08 +0200)
19 files changed:
client/proxy/proxy-dbus.cc
client/proxy/proxy-dbus.h
client/proxy/proxy-lib.h
client/proxy/proxy.h
client/snapper/cmd-modify.cc
doc/snapper.xml.in
package/snapper.changes
server/Client.cc
snapper/Bcachefs.cc
snapper/Bcachefs.h
snapper/Btrfs.cc
snapper/Btrfs.h
snapper/Filesystem.h
snapper/Lvm.cc
snapper/Lvm.h
snapper/PluginsImpl.cc
snapper/PluginsImpl.h
snapper/Snapshot.cc
snapper/Snapshot.h

index 743e705e7cda89fdf4e6ff37b49cc41fa134c77f..2f4768f0efc952b93d6aaa0fd7843cd18270e8eb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2016-2024] SUSE LLC
+ * Copyright (c) [2016-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -64,7 +64,7 @@ ProxySnapshotDbus::isReadOnly() const
 
 
 void
-ProxySnapshotDbus::setReadOnly(bool read_only)
+ProxySnapshotDbus::setReadOnly(bool read_only, Plugins::Report& report)
 {
     command_set_snapshot_read_only(conn(), configName(), num, read_only);
 }
index 1b0cd8a36e9c6aedb629f2fe3bf0bfb25395d172..030bc0368a0f78bc9a29343748829181b0c31865 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2016-2024] SUSE LLC
+ * Copyright (c) [2016-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -59,7 +59,7 @@ public:
     virtual time_t getDate() const override { return date; }
     virtual uid_t getUid() const override { return uid; }
     virtual bool isReadOnly() const override;
-    virtual void setReadOnly(bool read_only) override;
+    virtual void setReadOnly(bool read_only, Plugins::Report& report) override;
     virtual unsigned int getPreNum() const override { return pre_num; }
     virtual const string& getDescription() const override { return description; }
     virtual const string& getCleanup() const override { return cleanup; }
index a3baa48526578425a4fa8b7700b284e0093ed613..8d34fdd21d8bb21f15922235de56ba70fa8c7a65 100644 (file)
@@ -47,7 +47,7 @@ public:
     virtual time_t getDate() const override { return it->getDate(); }
     virtual uid_t getUid() const override { return it->getUid(); }
     virtual bool isReadOnly() const override { return it->isReadOnly(); }
-    virtual void setReadOnly(bool read_only) override { it->setReadOnly(read_only); }
+    virtual void setReadOnly(bool read_only, Plugins::Report& report) override { it->setReadOnly(read_only, report); }
     virtual unsigned int getPreNum() const override { return it->getPreNum(); }
     virtual const string& getDescription() const override { return it->getDescription(); }
     virtual const string& getCleanup() const override { return it->getCleanup(); }
index 3f24358f8d7e22faf1a4de931298d43e6fca96d6..65c7a45b446933b5bf440756a799b2fc21b2253c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2016-2024] SUSE LLC
+ * Copyright (c) [2016-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -102,7 +102,7 @@ public:
     time_t getDate() const { return impl->getDate(); }
     uid_t getUid() const { return impl->getUid(); }
     bool isReadOnly() const { return impl->isReadOnly(); }
-    void setReadOnly(bool read_only) { impl->setReadOnly(read_only); }
+    void setReadOnly(bool read_only, Plugins::Report& report) { impl->setReadOnly(read_only, report); }
     unsigned int getPreNum() const { return impl->getPreNum(); }
     const string& getDescription() const { return impl->getDescription(); }
     const string& getCleanup() const { return impl->getCleanup(); }
@@ -134,7 +134,7 @@ public:
        virtual time_t getDate() const = 0;
        virtual uid_t getUid() const = 0;
        virtual bool isReadOnly() const = 0;
-       virtual void setReadOnly(bool read_only) = 0;
+       virtual void setReadOnly(bool read_only, Plugins::Report& report) = 0;
        virtual unsigned int getPreNum() const = 0;
        virtual const string& getDescription() const = 0;
        virtual const string& getCleanup() const = 0;
index e9304c55b6633eef1564c9c99225be1ae1d85f7b..0c9d7e9a99d7323802f54fcc4d07d2042ffd76ca 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2023] SUSE LLC
+ * Copyright (c) [2016-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -135,7 +135,7 @@ namespace snapper
 
            if (set_read_only)
            {
-               snapshot->setReadOnly(read_only);
+               snapshot->setReadOnly(read_only, report);
            }
 
            if (set_default)
index c9b33ddd39e8f3e294d00d65f5bfd5454dfb79a3..613e07d0261ac74e7532d40396723d501cba15e2 100644 (file)
@@ -2,13 +2,13 @@
 <refentry id='snapper8' xmlns:xlink="http://www.w3.org/1999/xlink">
 
   <refentryinfo>
-    <date>2025-07-23</date>
+    <date>2025-09-02</date>
   </refentryinfo>
 
   <refmeta>
     <refentrytitle>snapper</refentrytitle>
     <manvolnum>8</manvolnum>
-    <refmiscinfo class='date'>2025-07-23</refmiscinfo>
+    <refmiscinfo class='date'>2025-09-02</refmiscinfo>
     <refmiscinfo class='version'>@VERSION@</refmiscinfo>
     <refmiscinfo class='manual'>Filesystem Snapshot Management</refmiscinfo>
   </refmeta>
          <para>Executed after a snapshot was removed</para>
        </listitem>
       </varlistentry>
+      <varlistentry>
+       <term><option>set-read-only-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <listitem>
+         <para>Executed before a snapshot is set read-only or read-write</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><option>set-read-only-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+       <listitem>
+         <para>Executed after  a snapshot is set read-only or read-write</para>
+       </listitem>
+      </varlistentry>
       <varlistentry>
        <term><option>set-default-snapshot-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
        <listitem>
index 3fd6a250227c7f12a1dd2919d88872a67744a718..ae3ead1599214e687b5939117cf3520e8062d544 100644 (file)
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Tue Sep 02 14:29:41 CEST 2025 - aschnell@suse.com
+
+- added generic plugin action used when setting snapshot read-only
+  (bsc#1246172)
+
 -------------------------------------------------------------------
 Mon Aug 04 17:00:45 CEST 2025 - Arvin Schnell <aschnell@suse.com>
 
index eec19dd289f2719377eb552497c27930a87890c8..538b38da0d29cbff32aabdfc17a54ecbf6ec134b 100644 (file)
@@ -1199,7 +1199,7 @@ Client::set_snapshot_read_only(DBus::Connection& conn, DBus::Message& msg)
     if (snap == snapshots.end())
        SN_THROW(IllegalSnapshotException());
 
-    snap->setReadOnly(read_only);
+    snap->setReadOnly(read_only, report);
 
     DBus::MessageMethodReturn reply(msg);
 
index 6ea886dca51a1b37ef4967fa0a1fffe4d9ac5e1a..e83f6f76f1eabbed70b86bc8af93c1162307a34a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 SUSE LLC
+ * Copyright (c) [2024-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -35,7 +35,7 @@
 #include "snapper/Snapper.h"
 #include "snapper/SnapperTmpl.h"
 #include "snapper/SnapperDefines.h"
-
+#include "snapper/PluginsImpl.h"
 #include "snapper/Acls.h"
 #include "snapper/Exception.h"
 #ifdef ENABLE_SELINUX
@@ -292,10 +292,14 @@ namespace snapper
 
 
     void
-    Bcachefs::setSnapshotReadOnly(unsigned int num, bool read_only) const
+    Bcachefs::setSnapshotReadOnly(unsigned int num, bool read_only, Plugins::Report& report) const
     {
+       Plugins::set_read_only(Plugins::Stage::PRE_ACTION, subvolume, this, num, report);
+
        SDir snapshot_dir = openSnapshotDir(num);
        set_subvolume_read_only(snapshot_dir.fd(), read_only);
+
+       Plugins::set_read_only(Plugins::Stage::POST_ACTION, subvolume, this, num, report);
     }
 
 
index 30696ececf8997875837498a7768d30f22d85deb..119a9bc78981d7bf6dd5f4183935ffbae26516a7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 SUSE LLC
+ * Copyright (c) [2024-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -59,7 +59,7 @@ namespace snapper
        virtual void umountSnapshot(unsigned int num) const override;
 
        virtual bool isSnapshotReadOnly(unsigned int num) const override;
-       virtual void setSnapshotReadOnly(unsigned int num, bool read_only) const override;
+       virtual void setSnapshotReadOnly(unsigned int num, bool read_only, Plugins::Report& report) const override;
 
        virtual bool checkSnapshot(unsigned int num) const override;
 
index e10053dc40e7b7965ede835c655cfc40947bb06d..9513c136cbac9f1395641e921049d1642eee57ab 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2024] SUSE LLC
+ * Copyright (c) [2016-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -460,10 +460,14 @@ namespace snapper
 
 
     void
-    Btrfs::setSnapshotReadOnly(unsigned int num, bool read_only) const
+    Btrfs::setSnapshotReadOnly(unsigned int num, bool read_only, Plugins::Report& report) const
     {
+       Plugins::set_read_only(Plugins::Stage::PRE_ACTION, subvolume, this, num, report);
+
        SDir snapshot_dir = openSnapshotDir(num);
        set_subvolume_read_only(snapshot_dir.fd(), read_only);
+
+       Plugins::set_read_only(Plugins::Stage::POST_ACTION, subvolume, this, num, report);
     }
 
 
index 4357ef046e66fcbb482bb21cb3151ec27bd76819..21dc759c5b675d59e0326f321e98403f0cac15fb 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2023] SUSE LLC
+ * Copyright (c) [2016-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -77,7 +77,7 @@ namespace snapper
        virtual void umountSnapshot(unsigned int num) const override;
 
        virtual bool isSnapshotReadOnly(unsigned int num) const override;
-       virtual void setSnapshotReadOnly(unsigned int num, bool read_only) const override;
+       virtual void setSnapshotReadOnly(unsigned int num, bool read_only, Plugins::Report& report) const override;
 
        virtual bool checkSnapshot(unsigned int num) const override;
 
index 42ebd6effbf590104c855d50c659f9ca3022bf33..3b14df0610a3e0c4d001ddd4868114072f9cb3ac 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2023] SUSE LLC
+ * Copyright (c) [2016-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -81,7 +81,7 @@ namespace snapper
        virtual void umountSnapshot(unsigned int num) const = 0;
 
        virtual bool isSnapshotReadOnly(unsigned int num) const = 0;
-       virtual void setSnapshotReadOnly(unsigned int num, bool read_only) const = 0;
+       virtual void setSnapshotReadOnly(unsigned int num, bool read_only, Plugins::Report& report) const = 0;
 
        virtual bool checkSnapshot(unsigned int num) const = 0;
 
index c6276a7fc013f5a33f2a127dbe67bd8834f2f633..339de48294d764c819055a69333cbaa4e1db0392 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2020-2023] SUSE LLC
+ * Copyright (c) [2020-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -43,6 +43,7 @@
 #include "snapper/SystemCmd.h"
 #include "snapper/SnapperDefines.h"
 #include "snapper/LvmCache.h"
+#include "snapper/PluginsImpl.h"
 #ifdef ENABLE_SELINUX
 #include "snapper/Selinux.h"
 #endif
@@ -383,11 +384,15 @@ namespace snapper
 
 
     void
-    Lvm::setSnapshotReadOnly(unsigned int num, bool read_only) const
+    Lvm::setSnapshotReadOnly(unsigned int num, bool read_only, Plugins::Report& report) const
     {
        try
        {
+           Plugins::set_read_only(Plugins::Stage::PRE_ACTION, subvolume, this, num, report);
+
            cache->set_read_only(vg_name, snapshotLvName(num), read_only);
+
+           Plugins::set_read_only(Plugins::Stage::POST_ACTION, subvolume, this, num, report);
        }
        catch (const LvmCacheException& e)
        {
index bb6da1c87dd3b78779a3e14a24f6b9bdf3915e38..5fcccb3ed7d63f44be13736c9187df58c7fab475 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) 2023 SUSE LLC
+ * Copyright (c) [2023-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -107,7 +107,7 @@ namespace snapper
        virtual void umountSnapshot(unsigned int num) const override;
 
        virtual bool isSnapshotReadOnly(unsigned int num) const override;
-       virtual void setSnapshotReadOnly(unsigned int num, bool read_only) const override;
+       virtual void setSnapshotReadOnly(unsigned int num, bool read_only, Plugins::Report& report) const override;
 
        virtual bool checkSnapshot(unsigned int num) const override;
 
index ad1dc2f31243ae533f784218803efc2c876b5f62..aff46dd9b59882538523c9696eed07a384ed589d 100644 (file)
@@ -208,6 +208,26 @@ namespace snapper
     }
 
 
+    void
+    Plugins::set_read_only(Stage stage, const string& subvolume, const Filesystem* filesystem,
+                          unsigned int num, Report& report)
+    {
+       switch (stage)
+       {
+           case Stage::PRE_ACTION:
+               run_scripts({ "set-read-only-pre", subvolume, filesystem->fstype(),
+                       std::to_string(num) }, report);
+               break;
+
+           case Stage::POST_ACTION:
+               grub(subvolume, filesystem, "--enable", report);
+               run_scripts({ "set-read-only-post", subvolume, filesystem->fstype(),
+                       std::to_string(num) }, report);
+               break;
+       }
+    }
+
+
     void
     Plugins::set_default_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
                                  unsigned int num, Report& report)
index fff5eddd570395b4646d39085feb256a058a9425..40b5f6c9a812eb009942fdbde7d422b2ef81f427 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2022-2023] SUSE LLC
+ * Copyright (c) [2022-2025] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -52,6 +52,9 @@ namespace snapper
        void delete_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
                             const Snapshot& snapshot, Report& report);
 
+       void set_read_only(Stage stage, const string& subvolume, const Filesystem* filesystem,
+                          unsigned int num, Report& report);
+
        void set_default_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
                                  unsigned int num, Report& report);
 
index fbfbb1e6550669f21c423052957bf7d2150cdcb5..dde63b404b3e0d13cf0a13b91d99d1296a118d0a 100644 (file)
@@ -134,7 +134,7 @@ namespace snapper
 
 
     void
-    Snapshot::setReadOnly(bool read_only)
+    Snapshot::setReadOnly(bool read_only, Plugins::Report& report)
     {
        if (isCurrent())
            SN_THROW(IllegalSnapshotException());
@@ -144,7 +144,7 @@ namespace snapper
 
        Snapshot::read_only = read_only;
 
-       snapper->getFilesystem()->setSnapshotReadOnly(num, read_only);
+       snapper->getFilesystem()->setSnapshotReadOnly(num, read_only, report);
 
        if (!read_only)
            deleteFilelists();
index 9f8c2e49659bb23bc21f1ffba4baadee9d9f9a22..a1739a89b67e6d795790ccfc32c364e2eb66920b 100644 (file)
@@ -107,14 +107,14 @@ namespace snapper
        SDir openSnapshotDir() const;
 
        /**
-        * Determine iff snapshot is read-only (only for btrfs).
+        * Determine iff snapshot is read-only (may not be supported by all file system types).
         */
        bool isReadOnly() const;
 
        /**
-        * Set snapshot read-only or read-write (only for btrfs).
+        * Set snapshot read-only or read-write (may not be supported by all file system types).
         */
-       void setReadOnly(bool read_only);
+       void setReadOnly(bool read_only, Plugins::Report& report);
 
        /**
         * Determine iff snapshot is default (will be activated on next boot time).