]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
fix LVM setup for LVM with one character long names 552/head
authorArvin Schnell <aschnell@suse.de>
Mon, 31 Aug 2020 15:29:53 +0000 (17:29 +0200)
committerArvin Schnell <aschnell@suse.de>
Mon, 31 Aug 2020 15:29:53 +0000 (17:29 +0200)
package/snapper.changes
snapper/Lvm.cc
snapper/LvmUtils.cc [new file with mode: 0644]
snapper/LvmUtils.h [new file with mode: 0644]
snapper/Makefile.am
testsuite/Makefile.am
testsuite/lvm-utils.cc [new file with mode: 0644]

index 0e1e56f2c4110ba05cbd88cde6ce1103bc4f6a97..0935c99031d81b89086fe5cad8e717365187ac37 100644 (file)
@@ -1,3 +1,9 @@
+-------------------------------------------------------------------
+Mon Aug 31 17:18:14 CEST 2020 - aschnell@suse.com
+
+- fix LVM setup for volume groups and logical volumes with one
+  character long names (gh#openSUSE/snapper#465)
+
 -------------------------------------------------------------------
 Fri Aug 28 11:06:23 CEST 2020 - aschnell@suse.com
 
index a944800d5d922f8ef6b50e5a647e103a74c498b8..3a97b82990cb3ac60e9f1b881c89f8c0af316f21 100644 (file)
@@ -35,6 +35,7 @@
 #include "snapper/Log.h"
 #include "snapper/Filesystem.h"
 #include "snapper/Lvm.h"
+#include "snapper/LvmUtils.h"
 #include "snapper/Snapper.h"
 #include "snapper/SnapperTmpl.h"
 #include "snapper/SystemCmd.h"
@@ -48,6 +49,8 @@
 
 namespace snapper
 {
+    using namespace std;
+
 
     Filesystem*
     Lvm::create(const string& fstype, const string& subvolume, const string& root_prefix)
@@ -387,16 +390,19 @@ namespace snapper
     bool
     Lvm::detectThinVolumeNames(const MtabData& mtab_data)
     {
-       Regex rx("^/dev/mapper/(.+[^-])-([^-].+)$");
-       if (!rx.match(mtab_data.device))
+       try
+       {
+           pair<string, string> names = LvmUtils::split_device_name(mtab_data.device);
+
+           vg_name = names.first;
+           lv_name = names.second;
+       }
+       catch (const runtime_error& e)
        {
            y2err("could not detect lvm names from '" << mtab_data.device << "'");
            return false;
        }
 
-       vg_name = boost::replace_all_copy(rx.cap(1), "--", "-");
-       lv_name = boost::replace_all_copy(rx.cap(2), "--", "-");
-
        try
        {
            cache->add_or_update(vg_name, lv_name);
diff --git a/snapper/LvmUtils.cc b/snapper/LvmUtils.cc
new file mode 100644 (file)
index 0000000..47e7695
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) [2011-2014] Novell, Inc.
+ * Copyright (c) 2020 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 <boost/algorithm/string.hpp>
+
+#include "snapper/LvmUtils.h"
+#include "snapper/Regex.h"
+#include "snapper/AppUtil.h"
+
+
+namespace snapper
+{
+
+    namespace LvmUtils
+    {
+
+       pair<string, string>
+       split_device_name(const string& name)
+       {
+           Regex rx("^/dev/mapper/(.*[^-])-([^-].*)$");
+           if (!rx.match(name))
+               throw std::runtime_error("faild to split device name into volume group and "
+                                        "logical volume name");
+
+           string vg_name = boost::replace_all_copy(rx.cap(1), "--", "-");
+           string lv_name = boost::replace_all_copy(rx.cap(2), "--", "-");
+
+           return make_pair(vg_name, lv_name);
+       }
+
+    }
+}
diff --git a/snapper/LvmUtils.h b/snapper/LvmUtils.h
new file mode 100644 (file)
index 0000000..3bd4caf
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) [2011-2014] Novell, Inc.
+ * Copyright (c) 2020 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.
+ */
+
+
+#ifndef SNAPPER_LVM_UTILS_H
+#define SNAPPER_LVM_UTILS_H
+
+
+#include <utility>
+#include <string>
+
+
+namespace snapper
+{
+    using std::string;
+    using std::pair;
+
+
+    namespace LvmUtils
+    {
+
+       std::pair<string, string> split_device_name(const string& name);
+
+    }
+
+}
+
+
+#endif
index 3e8b0c071754f2037d7c628789d3c1160c1a6b94..988b9e32d7169b83983643e46caf7130674d2043 100644 (file)
@@ -48,7 +48,8 @@ endif
 if ENABLE_LVM
 libsnapper_la_SOURCES +=                               \
        Lvm.cc                  Lvm.h                   \
-       LvmCache.cc             LvmCache.h
+       LvmCache.cc             LvmCache.h              \
+       LvmUtils.cc             LvmUtils.h
 endif
 
 if ENABLE_ROLLBACK
index 0ff300c6add5ffeb15025604b2c713cadc36e780..f79ad66eb766083b638cae2670799a122eeb0298 100644 (file)
@@ -8,7 +8,7 @@ LDADD = ../snapper/libsnapper.la ../dbus/libdbus.la -lboost_unit_test_framework
 
 check_PROGRAMS = sysconfig-get1.test dirname1.test basename1.test                  \
        equal-date.test dbus-escape.test cmp-lt.test humanstring.test table.test    \
-       csv-formatter.test json-formatter.test getopts.test
+       csv-formatter.test json-formatter.test getopts.test lvm-utils.test
 
 if ENABLE_BTRFS_QUOTA
 check_PROGRAMS += qgroup1.test
@@ -31,3 +31,5 @@ csv_formatter_test_LDADD = -lboost_unit_test_framework ../client/utils/libutils.
 json_formatter_test_LDADD = -lboost_unit_test_framework ../client/utils/libutils.la
 
 getopts_test_LDADD = -lboost_unit_test_framework ../client/utils/libutils.la
+
+lvm_utils_test_LDADD = -lboost_unit_test_framework ../snapper/libsnapper.la
diff --git a/testsuite/lvm-utils.cc b/testsuite/lvm-utils.cc
new file mode 100644 (file)
index 0000000..ed4360d
--- /dev/null
@@ -0,0 +1,25 @@
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE basename1
+
+#include <boost/test/unit_test.hpp>
+
+#include <snapper/LvmUtils.h>
+
+using namespace snapper;
+
+
+BOOST_AUTO_TEST_CASE(split_device_name)
+{
+    std::pair<string, string> n1 = LvmUtils::split_device_name("/dev/mapper/system-root");
+    BOOST_CHECK_EQUAL(n1.first, "system");
+    BOOST_CHECK_EQUAL(n1.second, "root");
+
+    std::pair<string, string> n2 = LvmUtils::split_device_name("/dev/mapper/vg--system-lv--root");
+    BOOST_CHECK_EQUAL(n2.first, "vg-system");
+    BOOST_CHECK_EQUAL(n2.second, "lv-root");
+
+    std::pair<string, string> n3 = LvmUtils::split_device_name("/dev/mapper/s-r");
+    BOOST_CHECK_EQUAL(n3.first, "s");
+    BOOST_CHECK_EQUAL(n3.second, "r");
+}