summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins/source
diff options
context:
space:
mode:
authorPaul Barker <pbarker@konsulko.com>2021-01-19 16:26:09 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-02-03 14:13:54 +0000
commit14dcd18f6cf77d119fc9436f5afdf33437a6c01c (patch)
treeb9081fcab9745578a0900e118c7f7df18428b2e8 /scripts/lib/wic/plugins/source
parent16a131cad91ba8d7a607b849179d2c279974d60f (diff)
downloadpoky-14dcd18f6cf77d119fc9436f5afdf33437a6c01c.tar.gz
wic: Copy rootfs dir if fstab needs updating
By default, wic updates the /etc/fstab in the rootfs to include details of additional partitions described in the selected wks file. If this modification is performed in place, other tasks which create an image file from the rootfs directory (e.g. do_image_tar and do_image_ext4) will pick up the modified fstab file which would not be appropriate for those images as they do not include the additional partitions described in the wks file. wic does undo modifications to the fstab file once it has finished creating the filesystem image, however this leaves open a race condition if one of the other tasks reads the contents of the fstab file from the rootfs directory between the point where wic modifies the fstab file and the point where wic restores the files original content. This could be solved by adding a lockfile for tasks which use the rootfs directory to ensure that no other such task is reading the rootfs directory while do_image_wic is running. This would serialize several do_image_* tasks and result in slower builds, especially for large images. Another drawback of this solution is that it is hard to selectively optimise - adding lockfiles to do_image_* tasks would result in these tasks always being serialized even if no fstab modification will take place. An alternative solution is to copy the rootfs directory when fstab needs to be modified. The code to do this in wic already exists as it is needed when including or excluding content in the rootfs. This still results in an impact on build times but the copy uses hardlinks if possible (so little data is actually copied) and we can make selective optimisations to improve things. The rootfs copy will only take place if fstab modification is required (or if it was already needed to include or exclude rootfs content). We can also follow up with further optimisations after this commit. So this second solution is chosen. Fixes [Yocto #13994] (From OE-Core rev: 9414007dd73ffd41d1e9c68bae152e8cbb3c28a2) Signed-off-by: Paul Barker <pbarker@konsulko.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit ce682a73b7447652f898ce1d1d0416a456df5416) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/plugins/source')
-rw-r--r--scripts/lib/wic/plugins/source/rootfs.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py
index ff1313717e..f19ec3312b 100644
--- a/scripts/lib/wic/plugins/source/rootfs.py
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -86,9 +86,9 @@ class RootfsPlugin(SourcePlugin):
86 new_rootfs = None 86 new_rootfs = None
87 new_pseudo = None 87 new_pseudo = None
88 # Handle excluded paths. 88 # Handle excluded paths.
89 if part.exclude_path or part.include_path or part.change_directory: 89 if part.exclude_path or part.include_path or part.change_directory or part.updated_fstab_path:
90 # We need a new rootfs directory we can delete files from. Copy to 90 # We need a new rootfs directory we can safely modify without
91 # workdir. 91 # interfering with other tasks. Copy to workdir.
92 new_rootfs = os.path.realpath(os.path.join(cr_workdir, "rootfs%d" % part.lineno)) 92 new_rootfs = os.path.realpath(os.path.join(cr_workdir, "rootfs%d" % part.lineno))
93 93
94 if os.path.lexists(new_rootfs): 94 if os.path.lexists(new_rootfs):
@@ -159,6 +159,17 @@ class RootfsPlugin(SourcePlugin):
159 rm_cmd = "rm -rf %s" % (full_path) 159 rm_cmd = "rm -rf %s" % (full_path)
160 exec_native_cmd(rm_cmd, native_sysroot, pseudo) 160 exec_native_cmd(rm_cmd, native_sysroot, pseudo)
161 161
162 has_fstab = os.path.exists(os.path.join(new_rootfs, "etc/fstab"))
163 if part.updated_fstab_path and has_fstab:
164 fstab_path = os.path.join(new_rootfs, "etc/fstab")
165 # Assume that fstab should always be owned by root with fixed permissions
166 install_cmd = "install -m 0644 %s %s" % (part.updated_fstab_path, fstab_path)
167 if new_pseudo:
168 pseudo = cls.__get_pseudo(native_sysroot, new_rootfs, new_pseudo)
169 else:
170 pseudo = None
171 exec_native_cmd(install_cmd, native_sysroot, pseudo)
172
162 part.prepare_rootfs(cr_workdir, oe_builddir, 173 part.prepare_rootfs(cr_workdir, oe_builddir,
163 new_rootfs or part.rootfs_dir, native_sysroot, 174 new_rootfs or part.rootfs_dir, native_sysroot,
164 pseudo_dir = new_pseudo or pseudo_dir) 175 pseudo_dir = new_pseudo or pseudo_dir)