]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- take mount options from original filesystem when mounting snapshots
authorArvin Schnell <aschnell@suse.de>
Wed, 25 Jul 2012 09:07:24 +0000 (11:07 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 25 Jul 2012 09:07:24 +0000 (11:07 +0200)
package/snapper.changes
snapper/AppUtil.cc
snapper/AppUtil.h
snapper/Filesystem.cc
snapper/Filesystem.h

index 432d662b7179d92024a1511d8c0e1584b9cf0ee7..4308654fd749d8e9b2df3483262997fc3fa8b6f6 100644 (file)
@@ -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
 
index 64dc2656ea1feaeb055a05549a6bcbcd4c46d3bc..146d9e4b42ced8c024a2bdac8e43faf0bc83df64 100644 (file)
@@ -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;
            }
        }
index 0446d9e02ade3ec49f12137ba7371ff260f0cbc3..14433eda9ff381c0c396480d3ed2e17581de6c31 100644 (file)
@@ -31,6 +31,7 @@
 #include <string>
 #include <list>
 #include <map>
+#include <vector>
 
 
 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<string> options;
     };
 
     bool getMtabData(const string& mount_point, bool& found, MtabData& mtab_data);
index 9ab83f28fd2cc43ac9552c298b591a7f2638c9eb..2d170de8e5975ef6b7faa00cece4d49efb044348 100644 (file)
@@ -41,8 +41,12 @@ namespace snapper
 
     bool
     mount(const string& device, const string& mount_point, const string& mount_type,
-         const vector<string>& options)
+         const vector<string>& old_options, const vector<string>& new_options)
     {
+       vector<string> 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))
        {
index 2520a8f1e25e0dd89f657b6ac55d7b391de84d58..6383b4f3f3a058affd76cb4ab23503504442b987 100644 (file)
 
 
 #include <string>
+#include <vector>
 
 
 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<string> 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<string> mount_options;
+
     };
 
 }