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))
}
+ 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
{
}
+ 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
{
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
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; }
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;
+
};
}
/*
* Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) [2015] SUSE LLC
+ * Copyright (c) [2015,2018] SUSE LLC
*
* All Rights Reserved.
*
explicit InvalidGroupException() : Exception("invalid group") {}
};
+ struct UnsupportedException : public Exception
+ {
+ explicit UnsupportedException() : Exception("unsupported") {}
+ };
+
}
/*
* Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2017] SUSE LLC
+ * Copyright (c) [2016-2018] SUSE LLC
*
* All Rights Reserved.
*
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();
}
/*
* Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) [2016-2017] SUSE LLC
+ * Copyright (c) [2016-2018] SUSE LLC
*
* All Rights Reserved.
*
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;
}
+ 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) {}
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();