From: Arvin Schnell Date: Wed, 7 Feb 2024 10:20:08 +0000 (+0100) Subject: - lock config during list and cleanup commands and in zypper plugin X-Git-Tag: v0.11.0~49^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c23da187ec7c5b08e4dfa4a8b728a66e84e61347;p=thirdparty%2Fsnapper.git - lock config during list and cleanup commands and in zypper plugin --- diff --git a/client/Makefile.am b/client/Makefile.am index 814f5051..80a2a41b 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -43,6 +43,7 @@ snapper_SOURCES = \ proxy.cc proxy.h \ proxy-dbus.cc proxy-dbus.h \ proxy-lib.cc proxy-lib.h \ + locker.cc locker.h \ misc.cc misc.h \ MyFiles.cc MyFiles.h \ GlobalOptions.cc GlobalOptions.h @@ -64,6 +65,7 @@ systemd_helper_SOURCES = \ proxy.cc proxy.h \ proxy-dbus.cc proxy-dbus.h \ proxy-lib.cc proxy-lib.h \ + locker.cc locker.h \ misc.cc misc.h systemd_helper_LDADD = libclient.la ../snapper/libsnapper.la utils/libutils.la ../dbus/libdbus.la diff --git a/client/cleanup.cc b/client/cleanup.cc index 626a0b65..cb67b389 100644 --- a/client/cleanup.cc +++ b/client/cleanup.cc @@ -1,6 +1,6 @@ /* * Copyright (c) [2011-2014] Novell, Inc. - * Copyright (c) [2016-2021] SUSE LLC + * Copyright (c) [2016-2024] SUSE LLC * * All Rights Reserved. * @@ -34,6 +34,7 @@ #include "utils/equal-date.h" #include "utils/HumanString.h" #include "cleanup.h" +#include "locker.h" using namespace std; @@ -106,7 +107,7 @@ class Cleaner public: Cleaner(ProxySnapper* snapper, bool verbose, const Parameters& parameters) - : snapper(snapper), verbose(verbose), parameters(parameters) {} + : snapper(snapper), locker(snapper), verbose(verbose), parameters(parameters) {} virtual ~Cleaner() {} @@ -158,6 +159,8 @@ protected: ProxySnapper* snapper; + Locker locker; + const bool verbose; const Parameters& parameters; diff --git a/client/cmd-list.cc b/client/cmd-list.cc index 352a8f03..75d66f3a 100644 --- a/client/cmd-list.cc +++ b/client/cmd-list.cc @@ -1,6 +1,6 @@ /* * Copyright (c) [2011-2015] Novell, Inc. - * Copyright (c) [2016-2023] SUSE LLC + * Copyright (c) [2016-2024] SUSE LLC * * All Rights Reserved. * @@ -32,6 +32,7 @@ #include "utils/text.h" #include "GlobalOptions.h" #include "proxy.h" +#include "locker.h" #include "misc.h" #include "utils/TableFormatter.h" #include "utils/CsvFormatter.h" @@ -138,6 +139,13 @@ namespace snapper bool skip_snapshot(const ProxySnapshot& snapshot, ListMode list_mode) const; const ProxySnapper* snapper; + + private: + + Locker locker; + + public: + const ProxySnapshots& snapshots; private: @@ -168,8 +176,8 @@ namespace snapper OutputHelper::OutputHelper(const ProxySnapper* snapper, const vector& columns) - : snapper(snapper), snapshots(snapper->getSnapshots()), default_snapshot(snapshots.end()), - active_snapshot(snapshots.end()) + : snapper(snapper), locker(snapper), snapshots(snapper->getSnapshots()), + default_snapshot(snapshots.end()), active_snapshot(snapshots.end()) { try { diff --git a/client/commands.cc b/client/commands.cc index 54fd6fd3..d4673710 100644 --- a/client/commands.cc +++ b/client/commands.cc @@ -1,6 +1,6 @@ /* * Copyright (c) [2012-2015] Novell, Inc. - * Copyright (c) [2016-2023] SUSE LLC + * Copyright (c) [2016-2024] SUSE LLC * * All Rights Reserved. * @@ -690,6 +690,30 @@ command_sync(DBus::Connection& conn, const string& config_name) } +void +command_lock_config(DBus::Connection& conn, const string& config_name) +{ + DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "LockConfig"); + + DBus::Marshaller marshaller(call); + marshaller << config_name; + + conn.send_with_reply_and_block(call); +} + + +void +command_unlock_config(DBus::Connection& conn, const string& config_name) +{ + DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "UnlockConfig"); + + DBus::Marshaller marshaller(call); + marshaller << config_name; + + conn.send_with_reply_and_block(call); +} + + vector command_get_plugins_report(DBus::Connection& conn) { diff --git a/client/commands.h b/client/commands.h index 6550b0b5..f5139be7 100644 --- a/client/commands.h +++ b/client/commands.h @@ -1,6 +1,6 @@ /* * Copyright (c) [2012-2015] Novell, Inc. - * Copyright (c) [2016-2023] SUSE LLC + * Copyright (c) [2016-2024] SUSE LLC * * All Rights Reserved. * @@ -149,6 +149,12 @@ command_query_quota(DBus::Connection& conn, const string& config_name); FreeSpaceData command_query_free_space(DBus::Connection& conn, const string& config_name); +void +command_lock_config(DBus::Connection& conn, const string& config_name); + +void +command_unlock_config(DBus::Connection& conn, const string& config_name); + void command_sync(DBus::Connection& conn, const string& config_name); diff --git a/client/locker.cc b/client/locker.cc new file mode 100644 index 00000000..bea024e6 --- /dev/null +++ b/client/locker.cc @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include "locker.h" + + +namespace snapper +{ + + Locker::Locker(const ProxySnapper* snapper) + : snapper(snapper) + { + snapper->lock_config(); + } + + + Locker::~Locker() + { + snapper->unlock_config(); + } + +} diff --git a/client/locker.h b/client/locker.h new file mode 100644 index 00000000..41d30ae1 --- /dev/null +++ b/client/locker.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include "proxy.h" + + +namespace snapper +{ + + class Locker + { + + public: + + Locker(const ProxySnapper* snapper); + ~Locker(); + + private: + + const ProxySnapper* snapper; + + }; + +} diff --git a/client/proxy-dbus.cc b/client/proxy-dbus.cc index eba552c6..7d998d5a 100644 --- a/client/proxy-dbus.cc +++ b/client/proxy-dbus.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) [2016-2023] SUSE LLC + * Copyright (c) [2016-2024] SUSE LLC * * All Rights Reserved. * @@ -81,6 +81,20 @@ ProxySnapshotDbus::getUsedSpace() const } +void +ProxySnapperDbus::lock_config() const +{ + command_lock_config(conn(), config_name); +} + + +void +ProxySnapperDbus::unlock_config() const +{ + command_unlock_config(conn(), config_name); +} + + string ProxySnapshotDbus::mountFilesystemSnapshot(bool user_request) const { diff --git a/client/proxy-dbus.h b/client/proxy-dbus.h index f7f06adc..205fc92c 100644 --- a/client/proxy-dbus.h +++ b/client/proxy-dbus.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2016-2023] SUSE LLC + * Copyright (c) [2016-2024] SUSE LLC * * All Rights Reserved. * @@ -155,6 +155,9 @@ public: virtual void calculateUsedSpace() const override; + virtual void lock_config() const override; + virtual void unlock_config() const override; + DBus::Connection& conn() const; private: diff --git a/client/proxy-lib.h b/client/proxy-lib.h index 89357f0d..e17fd84f 100644 --- a/client/proxy-lib.h +++ b/client/proxy-lib.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2016-2023] SUSE LLC + * Copyright (c) [2016-2024] SUSE LLC * * All Rights Reserved. * @@ -138,6 +138,9 @@ public: virtual void calculateUsedSpace() const override { snapper->calculateUsedSpace(); } + virtual void lock_config() const override {} + virtual void unlock_config() const override {} + std::unique_ptr snapper; private: diff --git a/client/proxy.h b/client/proxy.h index 56a46a6f..0156a2b2 100644 --- a/client/proxy.h +++ b/client/proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2016-2023] SUSE LLC + * Copyright (c) [2016-2024] SUSE LLC * * All Rights Reserved. * @@ -253,6 +253,9 @@ public: virtual void calculateUsedSpace() const = 0; + virtual void lock_config() const = 0; + virtual void unlock_config() const = 0; + }; diff --git a/examples/python/lock-config.py b/examples/python/lock-config.py index 0a626428..fa68e29c 100755 --- a/examples/python/lock-config.py +++ b/examples/python/lock-config.py @@ -10,7 +10,15 @@ snapper = dbus.Interface(bus.get_object('org.opensuse.Snapper', '/org/opensuse/S snapper.LockConfig("root") +print("locked") + +snapper.LockConfig("root") +snapper.UnlockConfig("root") +print("still locked") sleep(10) snapper.UnlockConfig("root") +print("unlocked") + +sleep(10) diff --git a/package/snapper.changes b/package/snapper.changes index 1e05f94b..8ffe4e6f 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Feb 07 11:16:40 CET 2024 - aschnell@suse.com + +- lock config during list and cleanup commands and in zypper plugin + (gh#openSUSE/snapper#867) + ------------------------------------------------------------------- Fri Dec 08 09:06:30 CET 2023 - aschnell@suse.com diff --git a/zypp-plugin/snapper-zypp-plugin.cc b/zypp-plugin/snapper-zypp-plugin.cc index aee4b80f..7d1e9dbb 100644 --- a/zypp-plugin/snapper-zypp-plugin.cc +++ b/zypp-plugin/snapper-zypp-plugin.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019-2023] SUSE LLC + * Copyright (c) [2019-2024] SUSE LLC * * All Rights Reserved. * @@ -97,7 +97,7 @@ SnapperZyppCommitPlugin::SnapperZyppCommitPlugin(const ProgramOptions& opts) ZyppCommitPlugin::Message SnapperZyppCommitPlugin::plugin_begin(const Message& msg) { - y2mil("PLUGINBEGIN"); + y2mil("PLUGIN BEGIN"); userdata = get_userdata(msg); @@ -108,7 +108,7 @@ SnapperZyppCommitPlugin::plugin_begin(const Message& msg) ZyppCommitPlugin::Message SnapperZyppCommitPlugin::plugin_end(const Message& msg) { - y2mil("PLUGINEND"); + y2mil("PLUGIN END"); return ack(); } @@ -117,7 +117,7 @@ SnapperZyppCommitPlugin::plugin_end(const Message& msg) ZyppCommitPlugin::Message SnapperZyppCommitPlugin::commit_begin(const Message& msg) { - y2mil("COMMITBEGIN"); + y2mil("COMMIT BEGIN"); set solvables = get_solvables(msg, Phase::BEFORE); y2deb("solvables: " << solvables); @@ -128,6 +128,16 @@ SnapperZyppCommitPlugin::commit_begin(const Message& msg) if (found || important) { + try + { + y2deb("lock config"); + command_lock_config(dbus_conn, snapper_cfg); + } + catch (const Exception& ex) + { + SN_CAUGHT(ex); + } + userdata["important"] = important ? "yes" : "no"; try @@ -155,7 +165,7 @@ SnapperZyppCommitPlugin::commit_begin(const Message& msg) ZyppCommitPlugin::Message SnapperZyppCommitPlugin::commit_end(const Message& msg) { - y2mil("COMMITEND"); + y2mil("COMMIT END"); if (pre_snapshot_num != 0) { @@ -228,6 +238,16 @@ SnapperZyppCommitPlugin::commit_end(const Message& msg) SN_CAUGHT(ex); } } + + try + { + y2deb("unlock config"); + command_unlock_config(dbus_conn, snapper_cfg); + } + catch (const Exception& ex) + { + SN_CAUGHT(ex); + } } return ack(); diff --git a/zypp-plugin/snapper-zypp-plugin.h b/zypp-plugin/snapper-zypp-plugin.h index c2c2215b..023e923e 100644 --- a/zypp-plugin/snapper-zypp-plugin.h +++ b/zypp-plugin/snapper-zypp-plugin.h @@ -65,7 +65,7 @@ private: const string snapper_cfg; DBus::Connection dbus_conn; - unsigned int pre_snapshot_num; + unsigned int pre_snapshot_num = 0; string snapshot_description; map userdata;