From: Arvin Schnell Date: Wed, 25 Jul 2012 09:07:24 +0000 (+0200) Subject: - take mount options from original filesystem when mounting snapshots X-Git-Tag: v0.1.3~134^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da73c5602a4b6ebc7e06b29749cda5170ff2128e;p=thirdparty%2Fsnapper.git - take mount options from original filesystem when mounting snapshots --- diff --git a/package/snapper.changes b/package/snapper.changes index 432d662b..4308654f 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Jul 25 10:44:38 CEST 2012 - aschnell@suse.de + +- take mount options from original filesystem when mounting + snapshots + ------------------------------------------------------------------- Tue Jul 24 14:35:44 CEST 2012 - aschnell@suse.de diff --git a/snapper/AppUtil.cc b/snapper/AppUtil.cc index 64dc2656..146d9e4b 100644 --- a/snapper/AppUtil.cc +++ b/snapper/AppUtil.cc @@ -230,8 +230,10 @@ namespace snapper { found = true; mtab_data.device = m->mnt_fsname; - mtab_data.mount_point = m->mnt_dir; + mtab_data.dir = m->mnt_dir; mtab_data.type = m->mnt_type; + boost::split(mtab_data.options, m->mnt_opts, boost::is_any_of(","), + boost::token_compress_on); break; } } diff --git a/snapper/AppUtil.h b/snapper/AppUtil.h index 0446d9e0..14433eda 100644 --- a/snapper/AppUtil.h +++ b/snapper/AppUtil.h @@ -31,6 +31,7 @@ #include #include #include +#include namespace snapper @@ -38,6 +39,7 @@ namespace snapper using std::string; using std::list; using std::map; + using std::vector; void createPath(const string& Path_Cv); @@ -60,8 +62,9 @@ namespace snapper struct MtabData { string device; - string mount_point; + string dir; string type; + vector options; }; bool getMtabData(const string& mount_point, bool& found, MtabData& mtab_data); diff --git a/snapper/Filesystem.cc b/snapper/Filesystem.cc index 9ab83f28..2d170de8 100644 --- a/snapper/Filesystem.cc +++ b/snapper/Filesystem.cc @@ -41,8 +41,12 @@ namespace snapper bool mount(const string& device, const string& mount_point, const string& mount_type, - const vector& options) + const vector& old_options, const vector& new_options) { + vector options = old_options; + options.erase(remove(options.begin(), options.end(), "rw"), options.end()); + options.insert(options.end(), new_options.begin(), new_options.end()); + string cmd_line = MOUNTBIN " -t " + mount_type + " --read-only"; if (!options.empty()) @@ -202,6 +206,20 @@ namespace snapper { throw ProgramNotInstalledException(CHATTRBIN " not installed"); } + + bool found = false; + MtabData mtab_data; + + if (!getMtabData(subvolume, found, mtab_data)) + throw InvalidConfigException(); + + if (!found) + { + y2err("filesystem not mounted"); + throw InvalidConfigException(); + } + + mount_options = mtab_data.options; } @@ -333,7 +351,7 @@ namespace snapper options.push_back("loop"); options.push_back("noload"); - if (!mount(snapshotFile(num), snapshotDir(num), "ext4", options)) + if (!mount(snapshotFile(num), snapshotDir(num), "ext4", mount_options, options)) throw MountSnapshotFailedException(); } @@ -384,10 +402,22 @@ namespace snapper throw ProgramNotInstalledException(LVCREATE " not installed"); } - if (!detectLvmNames()) + bool found = false; + MtabData mtab_data; + + if (!getMtabData(subvolume, found, mtab_data)) + throw InvalidConfigException(); + + if (!found) { + y2err("filesystem not mounted"); throw InvalidConfigException(); } + + if (!detectLvmNames(mtab_data)) + throw InvalidConfigException(); + + mount_options = mtab_data.options; } @@ -491,7 +521,7 @@ namespace snapper if (mount_type == "xfs") options.push_back("nouuid"); - if (!mount(getDevice(num), snapshotDir(num), mount_type, options)) + if (!mount(getDevice(num), snapshotDir(num), mount_type, mount_options, options)) throw MountSnapshotFailedException(); } @@ -515,20 +545,8 @@ namespace snapper bool - Lvm::detectLvmNames() + Lvm::detectLvmNames(const MtabData& mtab_data) { - bool found = false; - MtabData mtab_data; - - if (!getMtabData(subvolume, found, mtab_data)) - return false; - - if (!found) - { - y2err("logical volume not mounted"); - return false; - } - Regex rx("^/dev/mapper/([^-]+)-([^-]+)$"); if (rx.match(mtab_data.device)) { diff --git a/snapper/Filesystem.h b/snapper/Filesystem.h index 2520a8f1..6383b4f3 100644 --- a/snapper/Filesystem.h +++ b/snapper/Filesystem.h @@ -25,14 +25,17 @@ #include +#include namespace snapper { using std::string; + using std::vector; class Snapper; + class MtabData; class Filesystem @@ -122,6 +125,10 @@ namespace snapper virtual bool checkSnapshot(unsigned int num) const; + private: + + vector mount_options; + }; @@ -155,13 +162,15 @@ namespace snapper const string mount_type; - bool detectLvmNames(); + bool detectLvmNames(const MtabData& mtab_data); string getDevice(unsigned int num) const; string vg_name; string lv_name; + vector mount_options; + }; }