From: Arvin Schnell Date: Fri, 3 Feb 2017 10:30:31 +0000 (+0100) Subject: - deal with CaaSP btrfs setup where certain subvolumes are read-only (bsc#1018302... X-Git-Tag: v0.5.0~9^2 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=refs%2Fpull%2F323%2Fhead;p=thirdparty%2Fsnapper.git - deal with CaaSP btrfs setup where certain subvolumes are read-only (bsc#1018302 and bsc#1018095) --- diff --git a/VERSION b/VERSION index 2b7c5ae0..17b2ccd9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.2 +0.4.3 diff --git a/package/snapper.changes b/package/snapper.changes index e9e3bab2..34ea4dfd 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Feb 02 19:07:40 CET 2017 - aschnell@suse.com + +- deal with CaaSP btrfs setup where certain subvolumes are + read-only (bsc#1018302 and bsc#1018095) +- version 0.4.3 + ------------------------------------------------------------------- Thu Feb 02 14:49:59 CET 2017 - aschnell@suse.com diff --git a/snapper/Btrfs.cc b/snapper/Btrfs.cc index efc6363a..6be6e868 100644 --- a/snapper/Btrfs.cc +++ b/snapper/Btrfs.cc @@ -296,6 +296,13 @@ namespace snapper } + SDir + Btrfs::openGeneralDir() const + { + return openInfosDir(); + } + + void Btrfs::createSnapshot(unsigned int num, unsigned int num_parent, bool read_only, bool quota) const @@ -1446,19 +1453,19 @@ namespace snapper { try { + SDir general_dir = openGeneralDir(); + if (num == 0) { SDir subvolume_dir = openSubvolumeDir(); subvolid_t id = get_id(subvolume_dir.fd()); - set_default_id(subvolume_dir.fd(), id); + set_default_id(general_dir.fd(), id); } else { SDir snapshot_dir = openSnapshotDir(num); subvolid_t id = get_id(snapshot_dir.fd()); - - SDir subvolume_dir = openSubvolumeDir(); - set_default_id(subvolume_dir.fd(), id); + set_default_id(general_dir.fd(), id); } } catch (const runtime_error& e) diff --git a/snapper/Btrfs.h b/snapper/Btrfs.h index 6636b718..7b427828 100644 --- a/snapper/Btrfs.h +++ b/snapper/Btrfs.h @@ -60,6 +60,13 @@ namespace snapper virtual SDir openInfosDir() const; virtual SDir openSnapshotDir(unsigned int num) const; + /** + * A general read-write directory that can be used for ioctls. The + * exact directory can change to adapt to the system changes, + * e.g. which subvolumes are read-only. + */ + SDir openGeneralDir() const; + virtual void createSnapshot(unsigned int num, unsigned int num_parent, bool read_only, bool quota) const; virtual void createSnapshotOfDefault(unsigned int num, bool read_only, bool quota) const; diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index d6ee3802..9159e11f 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -661,15 +661,15 @@ namespace snapper if (btrfs->getQGroup() != no_qgroup) SN_THROW(QuotaException("qgroup already set")); - SDir subvolume_dir = openSubvolumeDir(); + SDir general_dir = btrfs->openGeneralDir(); - quota_enable(subvolume_dir.fd()); + quota_enable(general_dir.fd()); - qgroup_t qgroup = qgroup_find_free(subvolume_dir.fd(), 1); + qgroup_t qgroup = qgroup_find_free(general_dir.fd(), 1); y2mil("free qgroup:" << format_qgroup(qgroup)); - qgroup_create(subvolume_dir.fd(), qgroup); + qgroup_create(general_dir.fd(), qgroup); setConfigInfo({ { "QGROUP", format_qgroup(qgroup) } }); @@ -694,15 +694,15 @@ namespace snapper if (btrfs->getQGroup() == no_qgroup) SN_THROW(QuotaException("qgroup not set")); - SDir subvolume_dir = openSubvolumeDir(); + SDir general_dir = btrfs->openGeneralDir(); try { - vector children = qgroup_query_children(subvolume_dir.fd(), btrfs->getQGroup()); + vector children = qgroup_query_children(general_dir.fd(), btrfs->getQGroup()); sort(children.begin(), children.end()); - // Iterate all snapshot and ensure that those and only those with a - // cleanup algorithm are included in the high level qgroup. + // Iterate all snapshots and ensure that those and only those with + // a cleanup algorithm are included in the high level qgroup. for (const Snapshot& snapshot : snapshots) { @@ -716,11 +716,11 @@ namespace snapper if (!snapshot.getCleanup().empty() && !included) { - qgroup_assign(subvolume_dir.fd(), qgroup, btrfs->getQGroup()); + qgroup_assign(general_dir.fd(), qgroup, btrfs->getQGroup()); } else if (snapshot.getCleanup().empty() && included) { - qgroup_remove(subvolume_dir.fd(), qgroup, btrfs->getQGroup()); + qgroup_remove(general_dir.fd(), qgroup, btrfs->getQGroup()); } } } @@ -750,23 +750,23 @@ namespace snapper if (btrfs->getQGroup() == no_qgroup) SN_THROW(QuotaException("qgroup not set")); - SDir subvolume_dir = openSubvolumeDir(); + SDir general_dir = btrfs->openGeneralDir(); // Tests have shown that without a rescan and sync here the quota data // is incorrect. - quota_rescan(subvolume_dir.fd()); - sync(subvolume_dir.fd()); + quota_rescan(general_dir.fd()); + sync(general_dir.fd()); struct statvfs64 fsbuf; - if (fstatvfs64(subvolume_dir.fd(), &fsbuf) != 0) + if (fstatvfs64(general_dir.fd(), &fsbuf) != 0) SN_THROW(QuotaException("statvfs64 failed")); QuotaData quota_data; quota_data.size = fsbuf.f_blocks * fsbuf.f_bsize; - QGroupUsage qgroup_usage = qgroup_query_usage(subvolume_dir.fd(), btrfs->getQGroup()); + QGroupUsage qgroup_usage = qgroup_query_usage(general_dir.fd(), btrfs->getQGroup()); quota_data.used = qgroup_usage.exclusive; y2mil("size:" << quota_data.size << " used:" << quota_data.used);