]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- reject create-config on non-thin LVM volumes
authorOndrej Kozina <okozina@redhat.com>
Wed, 24 Oct 2012 11:25:07 +0000 (13:25 +0200)
committerOndrej Kozina <okozina@redhat.com>
Thu, 25 Oct 2012 14:57:04 +0000 (16:57 +0200)
snapper/Filesystem.cc
snapper/Filesystem.h
snapper/SnapperDefines.h

index 74f960d5422ca54a7fe5d5213acd7c83603d495d..3ccaf2bfcbc6b6b6ebdd0cb49e669484ead5edfd 100644 (file)
@@ -667,6 +667,11 @@ namespace snapper
            throw ProgramNotInstalledException(LVCREATE " not installed");
        }
 
+       if (access(LVS, X_OK) != 0)
+       {
+           throw ProgramNotInstalledException(LVS " not installed");
+       }
+
        bool found = false;
        MtabData mtab_data;
 
@@ -679,7 +684,7 @@ namespace snapper
            throw InvalidConfigException();
        }
 
-       if (!detectLvmNames(mtab_data))
+       if (!detectThinVolumeNames(mtab_data))
            throw InvalidConfigException();
 
        mount_options = filter_mount_options(mtab_data.options);
@@ -867,20 +872,35 @@ namespace snapper
 
 
     bool
-    Lvm::detectLvmNames(const MtabData& mtab_data)
+    Lvm::detectThinVolumeNames(const MtabData& mtab_data)
     {
        Regex rx("^/dev/mapper/(.+[^-])-([^-].+)$");
-       if (rx.match(mtab_data.device))
+       if (!rx.match(mtab_data.device))
        {
-           vg_name = boost::replace_all_copy(rx.cap(1), "--", "-");
-           lv_name = boost::replace_all_copy(rx.cap(2), "--", "-");
-           return true;
+           y2err("could not detect lvm names from '" << mtab_data.device << "'");
+           return false;
        }
 
-       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), "--", "-");
+
+       SystemCmd cmd(LVS " -o segtype --noheadings " + quote(vg_name + "/" + lv_name));
+
+       if (cmd.retcode() != 0) {
+           y2err("could not detect segment type infromation from: " << vg_name << "/" << lv_name);
+           return false;
+       }
+
+       string str = cmd.getLine(0);
+       boost::trim(str);
+
+       if (str.compare("thin")) {
+           y2err(vg_name << "/" << lv_name << " is not a LVM thin volume");
+           return false;
+       }
 
+       return true;
+    }
 
     string
     Lvm::getDevice(unsigned int num) const
index 6e49f67d78b3ef86693b6658569625c1d9b12948..f4fe2ed24a3d40680c576fbcf8882e36e7007c0b 100644 (file)
@@ -188,7 +188,7 @@ namespace snapper
 
        const string mount_type;
 
-       bool detectLvmNames(const MtabData& mtab_data);
+       bool detectThinVolumeNames(const MtabData& mtab_data);
 
        string getDevice(unsigned int num) const;
 
index c060ad13b3d9137def6b4139fa1650ab55e37950..a7ed9a19c66f800646a83079480c93a1efa4e5c5 100644 (file)
@@ -43,6 +43,7 @@
 
 #define LVCREATE "/sbin/lvcreate"
 #define LVREMOVE "/sbin/lvremove"
+#define LVS     "/sbin/lvs"
 
 
 #endif