From 9f468f93f5f5e32acd792b8cb11a7e4596633026 Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Fri, 16 Feb 2018 21:47:32 +0000 Subject: [PATCH 1/6] lvm_thin: fill in volume's revisions_to_keep from pool Otherwise, the base class defaults revisions_to_keep to 0. --- qubes/storage/lvm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qubes/storage/lvm.py b/qubes/storage/lvm.py index e814bb06..8cae3115 100644 --- a/qubes/storage/lvm.py +++ b/qubes/storage/lvm.py @@ -78,6 +78,8 @@ class ThinPool(qubes.storage.Pool): ''' Initialize a :py:class:`qubes.storage.Volume` from `volume_config`. ''' + if 'revisions_to_keep' not in volume_config.keys(): + volume_config['revisions_to_keep'] = self.revisions_to_keep if 'vid' not in volume_config.keys(): if vm and hasattr(vm, 'name'): vm_name = vm.name From 86998b0815d39b148c2cdd2820f6f1d2bb91d96a Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Fri, 16 Feb 2018 21:47:33 +0000 Subject: [PATCH 2/6] lvm_thin: really remove revision --- qubes/storage/lvm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qubes/storage/lvm.py b/qubes/storage/lvm.py index 8cae3115..070523cc 100644 --- a/qubes/storage/lvm.py +++ b/qubes/storage/lvm.py @@ -267,7 +267,7 @@ class ThinVolume(qubes.storage.Volume): for rev_id in revisions: try: - cmd = ['remove', self.vid + rev_id] + cmd = ['remove', self.vid + '-' + rev_id] qubes_lvm(cmd, self.log) except qubes.storage.StoragePoolException: pass From ade49d44b78a241ecd9ecae0aa904b849afc586f Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Fri, 16 Feb 2018 21:47:35 +0000 Subject: [PATCH 3/6] lvm_thin: don't purge one revision too few We just added one that must be taken into account. --- qubes/storage/lvm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/qubes/storage/lvm.py b/qubes/storage/lvm.py index 070523cc..bec33ee1 100644 --- a/qubes/storage/lvm.py +++ b/qubes/storage/lvm.py @@ -286,6 +286,7 @@ class ThinVolume(qubes.storage.Volume): cmd = ['clone', self.vid, '{}-{}-back'.format(self.vid, int(time.time()))] qubes_lvm(cmd, self.log) + reset_cache() self._remove_revisions() # TODO: when converting this function to coroutine, this _must_ be From f6542effc57916e99451efd9edc27391c8d0306a Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Fri, 16 Feb 2018 21:47:36 +0000 Subject: [PATCH 4/6] lvm_thin: _remove_revisions() on revisions_to_keep==0 If revisions_to_keep is 0, it may nevertheless have been > 0 before, so it makes sense to call _remove_revisions() and hold back none (not all) of the revisions in this case. --- qubes/storage/lvm.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qubes/storage/lvm.py b/qubes/storage/lvm.py index bec33ee1..641b1bcd 100644 --- a/qubes/storage/lvm.py +++ b/qubes/storage/lvm.py @@ -262,7 +262,8 @@ class ThinVolume(qubes.storage.Volume): if revisions is None: revisions = sorted(self.revisions.items(), key=operator.itemgetter(1)) - revisions = revisions[:-self.revisions_to_keep] + # pylint: disable=invalid-unary-operand-type + revisions = revisions[:(-self.revisions_to_keep) or None] revisions = [rev_id for rev_id, _ in revisions] for rev_id in revisions: @@ -287,7 +288,7 @@ class ThinVolume(qubes.storage.Volume): '{}-{}-back'.format(self.vid, int(time.time()))] qubes_lvm(cmd, self.log) reset_cache() - self._remove_revisions() + self._remove_revisions() # TODO: when converting this function to coroutine, this _must_ be # under a lock From c871424fb09aa8764f44c4c5f03de3ed57ffe430 Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Fri, 16 Feb 2018 21:47:37 +0000 Subject: [PATCH 5/6] storage: typo fix --- qubes/storage/lvm.py | 4 ++-- qubes/storage/reflink.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/qubes/storage/lvm.py b/qubes/storage/lvm.py index 641b1bcd..778de397 100644 --- a/qubes/storage/lvm.py +++ b/qubes/storage/lvm.py @@ -58,7 +58,7 @@ class ThinPool(qubes.storage.Pool): self.volume_group = volume_group self.thin_pool = thin_pool self._pool_id = "{!s}/{!s}".format(volume_group, thin_pool) - self.log = logging.getLogger('qube.storage.lvm.%s' % self._pool_id) + self.log = logging.getLogger('qubes.storage.lvm.%s' % self._pool_id) self._volume_objects_cache = {} @@ -198,7 +198,7 @@ class ThinVolume(qubes.storage.Volume): def __init__(self, volume_group, size=0, **kwargs): self.volume_group = volume_group super(ThinVolume, self).__init__(size=size, **kwargs) - self.log = logging.getLogger('qube.storage.lvm.%s' % str(self.pool)) + self.log = logging.getLogger('qubes.storage.lvm.%s' % str(self.pool)) if self.snap_on_start or self.save_on_stop: self._vid_snap = self.vid + '-snap' diff --git a/qubes/storage/reflink.py b/qubes/storage/reflink.py index 00d17d00..9ff1c06b 100644 --- a/qubes/storage/reflink.py +++ b/qubes/storage/reflink.py @@ -37,7 +37,7 @@ import qubes.storage BLKSIZE = 512 FICLONE = 1074041865 # see ioctl_ficlone manpage -LOGGER = logging.getLogger('qube.storage.reflink') +LOGGER = logging.getLogger('qubes.storage.reflink') class ReflinkPool(qubes.storage.Pool): From 37e1aedfa337ce989d5b64aab5716800eee9d257 Mon Sep 17 00:00:00 2001 From: Rusty Bird Date: Fri, 16 Feb 2018 21:47:39 +0000 Subject: [PATCH 6/6] reflink: style fix --- qubes/storage/reflink.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qubes/storage/reflink.py b/qubes/storage/reflink.py index 9ff1c06b..7cb9ca10 100644 --- a/qubes/storage/reflink.py +++ b/qubes/storage/reflink.py @@ -187,9 +187,9 @@ class ReflinkVolume(qubes.storage.Volume): _rename_file(self._path_dirty, self._path_clean) def _add_revision(self): - if self.revisions_to_keep is 0: + if self.revisions_to_keep == 0: return - if _get_file_disk_usage(self._path_clean) is 0: + if _get_file_disk_usage(self._path_clean) == 0: return ctime = os.path.getctime(self._path_clean) revision = qubes.storage.isodate(int(ctime)) + 'Z'