summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2021-04-22 10:54:49 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-04-23 00:08:38 +0100
commitd5eb86b3aa2fe41c39845c5dc9a7d50d86736509 (patch)
treec93d9314497d1776c4ff88d7df93fff112cf2fb2 /scripts
parent6f7bc9e4aff8923bcc45479aa1b269764fb9a20b (diff)
downloadpoky-d5eb86b3aa2fe41c39845c5dc9a7d50d86736509.tar.gz
runqemu: Ensure we cleanup snapshot files after image run
We need to cleanup snapshot files if we make a copy of them to ensure the tmpfs doesn't run out of space. There is already NFS code needing this so make it a generic code path. (From OE-Core rev: a3e0eec5a4785a0c4859455eb10b43aa832e606d) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/runqemu18
1 files changed, 12 insertions, 6 deletions
diff --git a/scripts/runqemu b/scripts/runqemu
index ba0b701aff..edd17d09c4 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -145,7 +145,6 @@ class BaseConfig(object):
145 self.qemu_opt = '' 145 self.qemu_opt = ''
146 self.qemu_opt_script = '' 146 self.qemu_opt_script = ''
147 self.qemuparams = '' 147 self.qemuparams = ''
148 self.clean_nfs_dir = False
149 self.nfs_server = '' 148 self.nfs_server = ''
150 self.rootfs = '' 149 self.rootfs = ''
151 # File name(s) of a OVMF firmware file or variable store, 150 # File name(s) of a OVMF firmware file or variable store,
@@ -210,6 +209,8 @@ class BaseConfig(object):
210 self.qemupid = None 209 self.qemupid = None
211 # avoid cleanup twice 210 # avoid cleanup twice
212 self.cleaned = False 211 self.cleaned = False
212 # Files to cleanup after run
213 self.cleanup_files = []
213 214
214 def acquire_taplock(self, error=True): 215 def acquire_taplock(self, error=True):
215 logger.debug("Acquiring lockfile %s..." % self.taplock) 216 logger.debug("Acquiring lockfile %s..." % self.taplock)
@@ -1020,8 +1021,9 @@ class BaseConfig(object):
1020 logger.info('Running %s...' % str(cmd)) 1021 logger.info('Running %s...' % str(cmd))
1021 if subprocess.call(cmd) != 0: 1022 if subprocess.call(cmd) != 0:
1022 raise RunQemuError('Failed to run %s' % cmd) 1023 raise RunQemuError('Failed to run %s' % cmd)
1023 self.clean_nfs_dir = True
1024 self.rootfs = dest 1024 self.rootfs = dest
1025 self.cleanup_files.append(self.rootfs)
1026 self.cleanup_files.append('%s.pseudo_state' % self.rootfs)
1025 1027
1026 # Start the userspace NFS server 1028 # Start the userspace NFS server
1027 cmd = ('runqemu-export-rootfs', 'start', self.rootfs) 1029 cmd = ('runqemu-export-rootfs', 'start', self.rootfs)
@@ -1204,6 +1206,7 @@ class BaseConfig(object):
1204 self.rootfs = newrootfs 1206 self.rootfs = newrootfs
1205 # Don't need a second copy now! 1207 # Don't need a second copy now!
1206 self.snapshot = False 1208 self.snapshot = False
1209 self.cleanup_files.append(newrootfs)
1207 1210
1208 qb_rootfs_opt = self.get('QB_ROOTFS_OPT') 1211 qb_rootfs_opt = self.get('QB_ROOTFS_OPT')
1209 if qb_rootfs_opt: 1212 if qb_rootfs_opt:
@@ -1476,10 +1479,13 @@ class BaseConfig(object):
1476 if self.saved_stty: 1479 if self.saved_stty:
1477 subprocess.check_call(("stty", self.saved_stty)) 1480 subprocess.check_call(("stty", self.saved_stty))
1478 1481
1479 if self.clean_nfs_dir: 1482 if self.cleanup_files:
1480 logger.info('Removing %s' % self.rootfs) 1483 for ent in self.cleanup_files:
1481 shutil.rmtree(self.rootfs) 1484 logger.info('Removing %s' % ent)
1482 shutil.rmtree('%s.pseudo_state' % self.rootfs) 1485 if os.path.isfile(ent):
1486 os.remove(ent)
1487 else:
1488 shutil.rmtree(ent)
1483 1489
1484 self.cleaned = True 1490 self.cleaned = True
1485 1491