From: Ondrej Kozina Date: Wed, 24 Oct 2012 11:25:07 +0000 (+0200) Subject: - reject create-config on non-thin LVM volumes X-Git-Tag: v0.1.3~72^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad46372173795dbc225c4d87cc34135a0b0ff8aa;p=thirdparty%2Fsnapper.git - reject create-config on non-thin LVM volumes --- diff --git a/snapper/Filesystem.cc b/snapper/Filesystem.cc index 74f960d5..3ccaf2bf 100644 --- a/snapper/Filesystem.cc +++ b/snapper/Filesystem.cc @@ -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 diff --git a/snapper/Filesystem.h b/snapper/Filesystem.h index 6e49f67d..f4fe2ed2 100644 --- a/snapper/Filesystem.h +++ b/snapper/Filesystem.h @@ -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; diff --git a/snapper/SnapperDefines.h b/snapper/SnapperDefines.h index c060ad13..a7ed9a19 100644 --- a/snapper/SnapperDefines.h +++ b/snapper/SnapperDefines.h @@ -43,6 +43,7 @@ #define LVCREATE "/sbin/lvcreate" #define LVREMOVE "/sbin/lvremove" +#define LVS "/sbin/lvs" #endif