From f47e49ebfd6bcda2e20e3251ef9bdf96016f8164 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 2 Jan 2019 10:42:39 +0200 Subject: Change: cache all explicitly mounted filesystems, not just / --- NEWS | 3 +++ vmdb/plugins/mount_plugin.py | 2 +- vmdb/plugins/rootfs_cache_plugin.py | 26 +++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index ddbbde0..c228134 100644 --- a/NEWS +++ b/NEWS @@ -40,6 +40,9 @@ Version 0.13.2+git, not yet released This allows a rootfs tarball that is old to be used, without the Packages files being too old to be usable. +* The `cache_rootfs` step now caches all the explicitly mounted + filesystems, not just the root filesystem. + Version 0.13.2, released 2018-05-06 ------------------------------------ diff --git a/vmdb/plugins/mount_plugin.py b/vmdb/plugins/mount_plugin.py index 06c1464..2ef3ef1 100644 --- a/vmdb/plugins/mount_plugin.py +++ b/vmdb/plugins/mount_plugin.py @@ -66,7 +66,7 @@ class MountStepRunner(vmdb.StepRunnerInterface): mount_point = tempfile.mkdtemp() vmdb.runcmd(['mount', device, mount_point]) - state.tags.set_mount_point(tag, mount_point) + state.tags.set_mount_point(tag, mount_point, cached=True) return mount_point diff --git a/vmdb/plugins/rootfs_cache_plugin.py b/vmdb/plugins/rootfs_cache_plugin.py index ba46d85..5c9a894 100644 --- a/vmdb/plugins/rootfs_cache_plugin.py +++ b/vmdb/plugins/rootfs_cache_plugin.py @@ -48,8 +48,32 @@ class MakeCacheStepRunner(vmdb.StepRunnerInterface): opts = step.get('options', '--one-file-system').split() if not tar_path: raise Exception('--rootfs-tarball MUST be set') + dirs = self._find_cacheable_mount_points(state.tags, rootdir) + + tags = state.tags + for tag in tags.get_tags(): + vmdb.progress( + 'tag {} mounted {} cached {}'.format( + tag, tags.get_mount_point(tag), tags.is_cached(tag))) + + vmdb.progress('caching rootdir'.format(rootdir)) + vmdb.progress('caching relative {}'.format(dirs)) if not os.path.exists(tar_path): - vmdb.runcmd(['tar'] + opts + ['-C', rootdir, '-caf', tar_path, '.']) + vmdb.runcmd( + ['tar'] + opts + ['-C', rootdir, '-caf', tar_path] + dirs) + + def _find_cacheable_mount_points(self, tags, rootdir): + return list(sorted( + self._make_relative(rootdir, tags.get_mount_point(tag)) + for tag in tags.get_tags() + if tags.is_cached(tag) + )) + + def _make_relative(self, rootdir, dirname): + assert dirname == rootdir or dirname.startswith(rootdir + '/') + if dirname == rootdir: + return '.' + return dirname[len(rootdir) + 1:] class UnpackCacheStepRunner(vmdb.StepRunnerInterface): -- cgit v1.2.1