]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added functions to query default and active snapshot
authorArvin Schnell <aschnell@suse.de>
Thu, 11 Oct 2018 09:24:48 +0000 (11:24 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 11 Oct 2018 09:36:39 +0000 (11:36 +0200)
LIBVERSION
snapper/Btrfs.cc
snapper/Btrfs.h
snapper/Exception.h
snapper/Filesystem.cc
snapper/Filesystem.h
snapper/Snapshot.cc
snapper/Snapshot.h

index 6aba2b245a847cc30a9b9dc009fc9d2522fff998..80895903a15c8a6a7df7ca72da9a3ed78fe07eca 100644 (file)
@@ -1 +1 @@
-4.2.0
+4.3.0
index 6e98e252bb4cdb92744c6fda18eddac18f030f06..b3bafb4ac24182d71c0308cb4cf01d2a002df19d 100644 (file)
@@ -1453,13 +1453,9 @@ namespace snapper
 
 
     std::pair<bool, unsigned int>
-    Btrfs::getDefault() const
+    Btrfs::idToNum(int fd, subvolid_t id) const
     {
-       SDir subvolume_dir = openSubvolumeDir();
-
-       subvolid_t id = get_default_id(subvolume_dir.fd());
-
-       string path = get_subvolume(subvolume_dir.fd(), id);
+       string path = get_subvolume(fd, id);
 
        Regex rx("/([0-9]+)/snapshot$");
        if (!rx.match(path))
@@ -1474,6 +1470,16 @@ namespace snapper
     }
 
 
+    std::pair<bool, unsigned int>
+    Btrfs::getDefault() const
+    {
+       SDir subvolume_dir = openSubvolumeDir();
+       int fd = subvolume_dir.fd();
+
+       return idToNum(fd, get_default_id(fd));
+    }
+
+
     void
     Btrfs::setDefault(unsigned int num) const
     {
@@ -1501,6 +1507,16 @@ namespace snapper
     }
 
 
+    std::pair<bool, unsigned int>
+    Btrfs::getActive() const
+    {
+       SDir subvolume_dir = openSubvolumeDir();
+       int fd = subvolume_dir.fd();
+
+       return idToNum(fd, get_id(fd));
+    }
+
+
     bool
     Btrfs::isActive(unsigned int num) const
     {
@@ -1528,28 +1544,40 @@ namespace snapper
     bool
     Btrfs::isDefault(unsigned int num) const
     {
-       throw std::logic_error("not implemented");
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
     }
 
 
     std::pair<bool, unsigned int>
     Btrfs::getDefault() const
     {
-       throw std::logic_error("not implemented");
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
     }
 
 
     void
     Btrfs::setDefault(unsigned int num) const
     {
-       throw std::logic_error("not implemented");
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
+    }
+
+
+    std::pair<bool, unsigned int>
+    Btrfs::getActive() const
+    {
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
     }
 
 
     bool
     Btrfs::isActive(unsigned int num) const
     {
-       throw std::logic_error("not implemented");
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
     }
 
 #endif
index 3d312898c2bdc3fdb80188b5d437b6c790d64e81..6f766b6226cebb9c74b6c236f4498126425f2235 100644 (file)
@@ -89,6 +89,8 @@ namespace snapper
 
        virtual bool isActive(unsigned int num) const;
 
+       virtual std::pair<bool, unsigned int> getActive() const;
+
        virtual void sync() const;
 
        virtual qgroup_t getQGroup() const { return qgroup; }
@@ -102,6 +104,12 @@ namespace snapper
        void addToFstabHelper(const string& default_subvolume_name) const;
        void removeFromFstabHelper() const;
 
+       /**
+        * Find the snapper snapshot number corresponding to the btrfs
+        * subvol id.
+        */
+       std::pair<bool, unsigned int> idToNum(int fd, subvolid_t id) const;
+
     };
 
 }
index dcadfa34211875a80f2892e1e45f40973062eae1..5cefc779d9e2650fc7678ee53f98da9bf85bc57a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2015] SUSE LLC
+ * Copyright (c) [2015,2018] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -393,6 +393,11 @@ namespace snapper
        explicit InvalidGroupException() : Exception("invalid group") {}
     };
 
+    struct UnsupportedException : public Exception
+    {
+        explicit UnsupportedException() : Exception("unsupported") {}
+    };
+
 }
 
 
index 204ae98c215bd4df032ddd8818f8e7b1bfbbe0c4..6c70552330f78f3495e7550f25155bd870be2de8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2017] SUSE LLC
+ * Copyright (c) [2016-2018] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -166,35 +166,48 @@ namespace snapper
     void
     Filesystem::createSnapshotOfDefault(unsigned int num, bool read_only, bool quota) const
     {
-       throw std::logic_error("not implemented");
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
     }
 
 
     bool
     Filesystem::isDefault(unsigned int num) const
     {
-       throw std::logic_error("not implemented");
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
     }
 
 
     std::pair<bool, unsigned int>
     Filesystem::getDefault() const
     {
-       throw std::logic_error("not implemented");
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
     }
 
 
     void
     Filesystem::setDefault(unsigned int num) const
     {
-       throw std::logic_error("not implemented");
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
+    }
+
+
+    std::pair<bool, unsigned int>
+    Filesystem::getActive() const
+    {
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
     }
 
 
     bool
     Filesystem::isActive(unsigned int num) const
     {
-       throw std::logic_error("not implemented");
+       SN_THROW(UnsupportedException());
+       __builtin_unreachable();
     }
 
 
index 81ff41695b3135563a26720c72dfabc041936e28..63b4dd2a1a4709eed65cc188b70cb96124687274 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2017] SUSE LLC
+ * Copyright (c) [2016-2018] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -94,6 +94,8 @@ namespace snapper
 
        virtual void setDefault(unsigned int num) const;
 
+       virtual std::pair<bool, unsigned int> getActive() const;
+
        virtual bool isActive(unsigned int num) const;
 
        virtual void sync() const;
index 3b1d7c2ef488d19857f747e7a66665326363a571..985440f1f2cfc9e5e908aa24ae5b9b7807aaaee2 100644 (file)
@@ -767,6 +767,24 @@ namespace snapper
     }
 
 
+    Snapshots::const_iterator
+    Snapshots::getDefault() const
+    {
+       std::pair<bool, unsigned int> tmp = snapper->getFilesystem()->getDefault();
+
+       return tmp.first ? find(tmp.second) : end();
+    }
+
+
+    Snapshots::const_iterator
+    Snapshots::getActive() const
+    {
+       std::pair<bool, unsigned int> tmp = snapper->getFilesystem()->getActive();
+
+       return tmp.first ? find(tmp.second) : end();
+    }
+
+
     struct num_is
     {
        num_is(unsigned int num) : num(num) {}
index 700196bd085d8011bde1d95cb0806771dba342b0..dc9764560fc86a0963614405d5c5a5eb8d3bf5b5 100644 (file)
@@ -235,6 +235,27 @@ namespace snapper
 
        const_iterator getSnapshotCurrent() const { return entries.begin(); }
 
+       /**
+        * Query the default snapshot. Only supported for btrfs.
+        *
+        * For btrfs the default btrfs snapshot will be mounted next
+        * time the filesystem is mounted (unless overridden).
+        *
+        * The default btrfs snapshot may not be controlled by snapper
+        * in which this function returns end().
+        */
+       const_iterator getDefault() const;
+
+       /**
+        * Query the active snapshot. Only supported for btrfs.
+        *
+        * For btrfs the active btrfs snapshot is the one currently mounted.
+        *
+        * The active btrfs snapshot may not be controlled by snapper
+        * in which this function returns end().
+        */
+       const_iterator getActive() const;
+
     private:
 
        void initialize();