Hooks::rollback(filesystem->snapshotDir(snapshot1->getNum()),
filesystem->snapshotDir(snapshot2->getNum()));
- Hooks::rollback(subvolume, filesystem, snapshot1->getNum(), snapshot2->getNum());
+ Hooks::rollback(Hooks::Stage::POST_ACTION, subvolume, filesystem, snapshot1->getNum(),
+ snapshot2->getNum());
if (print_number)
cout << snapshot2->getNum() << endl;
Hooks::rollback(filesystem->snapshotDir(previous_default->getNum()),
filesystem->snapshotDir(snapshot->getNum()));
- Hooks::rollback(subvolume, filesystem, previous_default->getNum(), snapshot->getNum());
+ Hooks::rollback(Hooks::Stage::POST_ACTION, subvolume, filesystem, previous_default->getNum(),
+ snapshot->getNum());
}
break;
cout << "running external programs" << endl;
- Hooks::create_config("/", &btrfs);
+ Hooks::create_config(Hooks::Stage::POST_ACTION, "/", &btrfs);
cout << "done" << endl;
}
<refentry id='snapper8' xmlns:xlink="http://www.w3.org/1999/xlink">
<refentryinfo>
- <date>2022-06-02</date>
+ <date>2022-12-22</date>
</refentryinfo>
<refmeta>
<refentrytitle>snapper</refentrytitle>
<manvolnum>8</manvolnum>
- <refmiscinfo class='date'>2022-06-02</refmiscinfo>
+ <refmiscinfo class='date'>2022-12-22</refmiscinfo>
<refmiscinfo class='version'>@VERSION@</refmiscinfo>
<refmiscinfo class='manual'>Filesystem Snapshot Management</refmiscinfo>
</refmeta>
following actions are defined:</para>
<variablelist>
<varlistentry>
- <term><option>create-config <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
+ <term><option>create-config-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
<listitem>
- <para>Executed when a new config gets created</para>
+ <para>Executed before a new config is created</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>delete-config <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
+ <term><option>create-config-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
<listitem>
- <para>Executed when a config gets deleted</para>
+ <para>Executed after a new config was created</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>create-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <term><option>delete-config-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
<listitem>
- <para>Executed when a new snapshot gets created</para>
+ <para>Executed before a config is deleted</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>delete-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <term><option>delete-config-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable></option></term>
<listitem>
- <para>Executed when a snapshot is removed</para>
+ <para>Executed after a config was deleted</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>modify-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <term><option>create-snapshot-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
<listitem>
- <para>Executed when a snapshot gets modified</para>
+ <para>Executed before a new snapshot is created</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>set-default-snapshot <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <term><option>create-snapshot-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
<listitem>
- <para>Executed when the default snapshot gets changed</para>
+ <para>Executed after a new snapshot was created</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>rollback <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>old-snapshot-number</replaceable> <replaceable>new-snapshot-number</replaceable></option></term>
+ <term><option>modify-snapshot-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
<listitem>
- <para>Executed when a rollback is done</para>
+ <para>Executed before a snapshot is modified</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>modify-snapshot-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <listitem>
+ <para>Executed after a snapshot was modified</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>delete-snapshot-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <listitem>
+ <para>Executed before a snapshot is removed</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>delete-snapshot-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <listitem>
+ <para>Executed after a snapshot was removed</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>set-default-snapshot-pre <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <listitem>
+ <para>Executed before the default snapshot is changed</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>set-default-snapshot-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>snapshot-number</replaceable></option></term>
+ <listitem>
+ <para>Executed after the default snapshot was changed</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>rollback-post <replaceable>subvolume</replaceable> <replaceable>fstype</replaceable> <replaceable>old-snapshot-number</replaceable> <replaceable>new-snapshot-number</replaceable></option></term>
+ <listitem>
+ <para>Executed after a rollback was done</para>
</listitem>
</varlistentry>
</variablelist>
+-------------------------------------------------------------------
+Thu Dec 22 09:03:33 CET 2022 - aschnell@suse.com
+
+- call generic plugins before and after the action
+
-------------------------------------------------------------------
Mon Dec 05 08:13:07 CET 2022 - aschnell@suse.com
{
try
{
+ Hooks::set_default_snapshot(Hooks::Stage::PRE_ACTION, subvolume, this, num);
+
SDir general_dir = openGeneralDir();
if (num == 0)
set_default_id(general_dir.fd(), id);
}
- Hooks::set_default_snapshot(subvolume, this, num);
+ Hooks::set_default_snapshot(Hooks::Stage::POST_ACTION, subvolume, this, num);
}
catch (const runtime_error& e)
{
}
+ // Actions without -pre/-post are legacy and deprecated (2022-12-22).
+
+
void
- Hooks::create_config(const string& subvolume, const Filesystem* filesystem)
+ Hooks::create_config(Stage stage, const string& subvolume, const Filesystem* filesystem)
{
- grub(subvolume, filesystem, "--enable");
- run_scripts({ "create-config", subvolume, filesystem->fstype() });
+ switch (stage)
+ {
+ case Stage::PRE_ACTION:
+ run_scripts({ "create-config-pre", subvolume, filesystem->fstype() });
+ break;
+
+ case Stage::POST_ACTION:
+ grub(subvolume, filesystem, "--enable");
+ run_scripts({ "create-config", subvolume, filesystem->fstype() });
+ run_scripts({ "create-config-post", subvolume, filesystem->fstype() });
+ break;
+ }
}
void
- Hooks::delete_config(const string& subvolume, const Filesystem* filesystem)
+ Hooks::delete_config(Stage stage, const string& subvolume, const Filesystem* filesystem)
{
- grub(subvolume, filesystem, "--disable");
- run_scripts({ "delete-config", subvolume, filesystem->fstype() });
+ switch (stage)
+ {
+ case Stage::PRE_ACTION:
+ grub(subvolume, filesystem, "--disable");
+ run_scripts({ "delete-config-pre", subvolume, filesystem->fstype() });
+ run_scripts({ "delete-config", subvolume, filesystem->fstype() });
+ break;
+
+ case Stage::POST_ACTION:
+ run_scripts({ "delete-config-post", subvolume, filesystem->fstype() });
+ break;
+ }
}
void
- Hooks::create_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
+ Hooks::create_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
{
- grub(subvolume, filesystem, "--refresh");
- run_scripts({ "create-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ switch (stage)
+ {
+ case Stage::PRE_ACTION:
+ run_scripts({ "create-snapshot-pre", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ break;
+
+ case Stage::POST_ACTION:
+ grub(subvolume, filesystem, "--refresh");
+ run_scripts({ "create-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ run_scripts({ "create-snapshot-post", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ break;
+ }
}
void
- Hooks::modify_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
+ Hooks::modify_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
{
- grub(subvolume, filesystem, "--refresh");
- run_scripts({ "modify-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ switch (stage)
+ {
+ case Stage::PRE_ACTION:
+ run_scripts({ "modify-snapshot-pre", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ break;
+
+ case Stage::POST_ACTION:
+ grub(subvolume, filesystem, "--refresh");
+ run_scripts({ "modify-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ run_scripts({ "modify-snapshot-post", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ break;
+ }
}
void
- Hooks::delete_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
+ Hooks::delete_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot)
{
- grub(subvolume, filesystem, "--refresh");
- run_scripts({ "delete-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ switch (stage)
+ {
+ case Stage::PRE_ACTION:
+ run_scripts({ "delete-snapshot-pre", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ break;
+
+ case Stage::POST_ACTION:
+ grub(subvolume, filesystem, "--refresh");
+ run_scripts({ "delete-snapshot", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ run_scripts({ "delete-snapshot-post", subvolume, filesystem->fstype(), std::to_string(snapshot.getNum()) });
+ break;
+ }
}
void
- Hooks::set_default_snapshot(const string& subvolume, const Filesystem* filesystem, unsigned int num)
+ Hooks::set_default_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem, unsigned int num)
{
- run_scripts({ "set-default-snapshot", subvolume, filesystem->fstype(), std::to_string(num) });
+ switch (stage)
+ {
+ case Stage::PRE_ACTION:
+ run_scripts({ "set-default-snapshot-pre", subvolume, filesystem->fstype(), std::to_string(num) });
+ break;
+
+ case Stage::POST_ACTION:
+ run_scripts({ "set-default-snapshot", subvolume, filesystem->fstype(), std::to_string(num) });
+ run_scripts({ "set-default-snapshot-post", subvolume, filesystem->fstype(), std::to_string(num) });
+ break;
+ }
}
void
- Hooks::rollback(const string& subvolume, const Filesystem* filesystem, unsigned int old_num, unsigned int new_num)
+ Hooks::rollback(const string& subvolume, const Filesystem* filesystem, unsigned int old_num,
+ unsigned int new_num)
+ {
+ rollback(Stage::POST_ACTION, subvolume, filesystem, old_num, new_num);
+ }
+
+
+ void
+ Hooks::rollback(Stage stage, const string& subvolume, const Filesystem* filesystem, unsigned int old_num,
+ unsigned int new_num)
{
- run_scripts({ "rollback", subvolume, filesystem->fstype(), std::to_string(old_num), std::to_string(new_num) });
+ switch (stage)
+ {
+ case Stage::PRE_ACTION:
+ run_scripts({ "rollback-pre", subvolume, filesystem->fstype(), std::to_string(old_num),
+ std::to_string(new_num) });
+ break;
+
+ case Stage::POST_ACTION:
+ run_scripts({ "rollback", subvolume, filesystem->fstype(), std::to_string(old_num),
+ std::to_string(new_num) });
+ run_scripts({ "rollback-post", subvolume, filesystem->fstype(), std::to_string(old_num),
+ std::to_string(new_num) });
+ break;
+ }
}
}
{
public:
- static void create_config(const string& subvolume, const Filesystem* filesystem);
- static void delete_config(const string& subvolume, const Filesystem* filesystem);
+ enum class Stage { PRE_ACTION, POST_ACTION };
- static void create_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot);
- static void modify_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot);
- static void delete_snapshot(const string& subvolume, const Filesystem* filesystem, const Snapshot& snapshot);
+ static void create_config(Stage stage, const string& subvolume, const Filesystem* filesystem);
+ static void delete_config(Stage stage, const string& subvolume, const Filesystem* filesystem);
- static void set_default_snapshot(const string& subvolume, const Filesystem* filesystem, unsigned int num);
+ static void create_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
+ const Snapshot& snapshot);
+ static void modify_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
+ const Snapshot& snapshot);
+ static void delete_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
+ const Snapshot& snapshot);
+
+ static void set_default_snapshot(Stage stage, const string& subvolume, const Filesystem* filesystem,
+ unsigned int num);
static void rollback(const string& old_root, const string& new_root);
- static void rollback(const string& subvolume, const Filesystem* filesystem, unsigned int old_num, unsigned int new_num);
+
+ static void rollback(const string& subvolume, const Filesystem* filesystem, unsigned int old_num,
+ unsigned int new_num) __attribute__((deprecated));
+ static void rollback(Stage stage, const string& subvolume, const Filesystem* filesystem, unsigned int old_num,
+ unsigned int new_num);
private:
SN_THROW(CreateConfigFailedException(e.what()));
}
+ Hooks::create_config(Hooks::Stage::PRE_ACTION, subvolume, filesystem.get());
+
try
{
SysconfigFile sysconfig(SYSCONFIG_FILE);
SN_RETHROW(e);
}
- Hooks::create_config(subvolume, filesystem.get());
+ Hooks::create_config(Hooks::Stage::POST_ACTION, subvolume, filesystem.get());
}
unique_ptr<Snapper> snapper(new Snapper(config_name, root_prefix));
- Hooks::delete_config(snapper->subvolumeDir(), snapper->getFilesystem());
+ Hooks::delete_config(Hooks::Stage::PRE_ACTION, snapper->subvolumeDir(), snapper->getFilesystem());
Snapshots& snapshots = snapper->getSnapshots();
SN_THROW(DeleteConfigFailedException("modifying sysconfig-file failed"));
}
+
+ Hooks::delete_config(Hooks::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem());
}
// parent == end indicates the btrfs default subvolume. Unclean, but
// adding a special snapshot like current needs too many API changes.
+ Hooks::create_snapshot(Hooks::Stage::PRE_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+ snapshot);
+
try
{
if (parent != end())
SN_RETHROW(e);
}
- Hooks::create_snapshot(snapper->subvolumeDir(), snapper->getFilesystem(), snapshot);
+ Hooks::create_snapshot(Hooks::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+ snapshot);
return entries.insert(entries.end(), snapshot);
}
checkUserdata(smd.userdata);
+ Hooks::modify_snapshot(Hooks::Stage::PRE_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+ *snapshot);
+
snapshot->description = smd.description;
snapshot->cleanup = smd.cleanup;
snapshot->userdata = smd.userdata;
snapshot->writeInfo();
- Hooks::modify_snapshot(snapper->subvolumeDir(), snapper->getFilesystem(), *snapshot);
+ Hooks::modify_snapshot(Hooks::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+ *snapshot);
}
snapshot->isActive())
SN_THROW(IllegalSnapshotException());
+ Hooks::delete_snapshot(Hooks::Stage::PRE_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+ *snapshot);
+
snapshot->deleteFilesystemSnapshot();
SDir info_dir = snapshot->openInfoDir();
SDir infos_dir = snapper->openInfosDir();
infos_dir.unlink(decString(snapshot->getNum()), AT_REMOVEDIR);
- Hooks::delete_snapshot(snapper->subvolumeDir(), snapper->getFilesystem(), *snapshot);
+ Hooks::delete_snapshot(Hooks::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
+ *snapshot);
entries.erase(snapshot);
}