From 92db9cb0f848e3bff0b63279ffb58ca2dd1aa4f9 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Fri, 4 Apr 2025 12:12:01 +0200 Subject: [PATCH] - improved logging --- snapper/Comparison.cc | 2 +- snapper/FileUtils.cc | 22 ++++++++++++++++------ snapper/FileUtils.h | 6 ++++-- snapper/Lvm.cc | 10 ++++++---- snapper/Snapshot.cc | 22 ++++++++++++++-------- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/snapper/Comparison.cc b/snapper/Comparison.cc index 7bcd80e5..ee272ae9 100644 --- a/snapper/Comparison.cc +++ b/snapper/Comparison.cc @@ -366,7 +366,7 @@ namespace snapper { SN_CAUGHT(e); - info_dir.unlink(tmp_name, 0); + info_dir.unlink(tmp_name); return false; } diff --git a/snapper/FileUtils.cc b/snapper/FileUtils.cc index ca3f9de3..17868232 100644 --- a/snapper/FileUtils.cc +++ b/snapper/FileUtils.cc @@ -1,6 +1,6 @@ /* * Copyright (c) [2011-2014] Novell, Inc. - * Copyright (c) [2018-2024] SUSE LLC + * Copyright (c) [2018-2025] SUSE LLC * * All Rights Reserved. * @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include @@ -335,12 +335,22 @@ namespace snapper int - SDir::unlink(const string& name, int flags) const + SDir::rmdir(const string& name) const { assert(name.find('/') == string::npos); assert(name != ".."); - return ::unlinkat(dirfd, name.c_str(), flags); + return ::unlinkat(dirfd, name.c_str(), AT_REMOVEDIR); + } + + + int + SDir::unlink(const string& name) const + { + assert(name.find('/') == string::npos); + assert(name != ".."); + + return ::unlinkat(dirfd, name.c_str(), 0); } @@ -880,8 +890,8 @@ namespace snapper TmpDir::~TmpDir() { - if (base_dir.unlink(name, AT_REMOVEDIR) != 0) - y2err("unlink failed, errno:" << errno); + if (base_dir.rmdir(name) != 0) + y2err("rmdir failed, errno:" << errno << " (" << stringerror(errno) << ")"); } diff --git a/snapper/FileUtils.h b/snapper/FileUtils.h index 7cf0d689..088ab0aa 100644 --- a/snapper/FileUtils.h +++ b/snapper/FileUtils.h @@ -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. * @@ -26,6 +26,7 @@ #include +#include #include #include #include @@ -87,7 +88,8 @@ namespace snapper int open(const string& name, int flags, mode_t mode) const; ssize_t readlink(const string& name, string& buf) const; int mkdir(const string& name, mode_t mode) const; - int unlink(const string& name, int flags) const; + int rmdir(const string& name) const; + int unlink(const string& name) const; int chmod(const string& name, mode_t mode, int flags) const; int chown(const string& name, uid_t owner, gid_t group, int flags) const; int rename(const string& oldname, const string& newname) const; diff --git a/snapper/Lvm.cc b/snapper/Lvm.cc index 625a98c9..2b64bdbe 100644 --- a/snapper/Lvm.cc +++ b/snapper/Lvm.cc @@ -182,10 +182,10 @@ namespace snapper { SDir subvolume_dir = openSubvolumeDir(); - int r1 = subvolume_dir.unlink(SNAPSHOTS_NAME, AT_REMOVEDIR); + int r1 = subvolume_dir.rmdir(SNAPSHOTS_NAME); if (r1 != 0) { - y2err("rmdir failed errno:" << errno << " (" << strerror(errno) << ")"); + y2err("rmdir '" SNAPSHOTS_NAME "' failed errno:" << errno << " (" << strerror(errno) << ")"); SN_THROW(DeleteConfigFailedException("rmdir failed")); } } @@ -293,10 +293,12 @@ namespace snapper } SDir info_dir = openInfoDir(num); - info_dir.unlink(SNAPSHOT_NAME, AT_REMOVEDIR); + if (info_dir.rmdir(SNAPSHOT_NAME) < 0) + y2err("rmdir '" SNAPSHOT_NAME "' failed errno: " << errno << " (" << stringerror(errno) << ")"); SDir infos_dir = openInfosDir(); - infos_dir.unlink(decString(num), AT_REMOVEDIR); + if (infos_dir.rmdir(decString(num)) < 0) + y2err("rmdir '" << num << "' failed errno: " << errno << " (" << stringerror(errno) << ")"); } diff --git a/snapper/Snapshot.cc b/snapper/Snapshot.cc index 200c128e..efee43a0 100644 --- a/snapper/Snapshot.cc +++ b/snapper/Snapshot.cc @@ -215,7 +215,8 @@ namespace snapper // remove all filelists in the info directory of this snapshot for (const string& name : info_dir.entries(is_filelist_file)) { - info_dir.unlink(name, 0); + if (info_dir.unlink(name) < 0) + y2err("unlink '" << name << "' failed errno: " << errno << " (" << stringerror(errno) << ")"); } // remove all filelists of the snapshot in the info directories of other snapshots @@ -226,8 +227,11 @@ namespace snapper SDir tmp = snapshot.openInfoDir(); string name = filelist_name(snapshot.getNum()); - tmp.unlink(name, 0); - tmp.unlink(name + ".gz", 0); + + if (tmp.unlink(name) < 0 && errno != ENOENT) + y2err("unlink '" << name << "' failed errno: " << errno << " (" << stringerror(errno) << ")"); + if (tmp.unlink(name + ".gz") < 0 && errno != ENOENT) + y2err("unlink '" << name << ".gz' failed errno: " << errno << " (" << stringerror(errno) << ")"); } } @@ -571,7 +575,7 @@ namespace snapper { SN_CAUGHT(e); - info_dir.unlink(tmp_name, 0); + info_dir.unlink(tmp_name); SN_RETHROW(e); } @@ -776,7 +780,7 @@ namespace snapper SN_CAUGHT(e); SDir infos_dir = snapper->openInfosDir(); - infos_dir.unlink(decString(snapshot.getNum()), AT_REMOVEDIR); + infos_dir.rmdir(decString(snapshot.getNum())); SN_RETHROW(e); } @@ -791,7 +795,7 @@ namespace snapper snapshot.deleteFilesystemSnapshot(); SDir infos_dir = snapper->openInfosDir(); - infos_dir.unlink(decString(snapshot.getNum()), AT_REMOVEDIR); + infos_dir.rmdir(decString(snapshot.getNum())); SN_RETHROW(e); } @@ -839,10 +843,12 @@ namespace snapper snapshot->deleteFilelists(); SDir info_dir = snapshot->openInfoDir(); - info_dir.unlink("info.xml", 0); + if (info_dir.unlink("info.xml") < 0) + y2err("unlink 'info.xml' failed errno: " << errno << " (" << stringerror(errno) << ")"); SDir infos_dir = snapper->openInfosDir(); - infos_dir.unlink(decString(snapshot->getNum()), AT_REMOVEDIR); + if (infos_dir.rmdir(decString(snapshot->getNum())) < 0) + y2err("rmdir '" << snapshot->getNum() << "' failed errno: " << errno << " (" << stringerror(errno) << ")"); Plugins::delete_snapshot(Plugins::Stage::POST_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(), *snapshot, report); -- 2.47.3