From 22bedd897d8a0374fa01aa3e409d22c9841d5ef1 Mon Sep 17 00:00:00 2001 From: Winston Wen Date: Fri, 2 Feb 2024 14:35:00 +0800 Subject: [PATCH 1/2] virtme: use $MODDIR/modules.dep to check the module folder If vng is interrupted during the virtme-prep-kdir-mods command, the next time we run vng we'll get the following error report: Traceback (most recent call last): File "/usr/bin/virtme-run", line 33, in sys.exit(load_entry_point('virtme-ng==1.19', 'console_scripts', 'virtme-run')()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/virtme/commands/run.py", line 1314, in main return do_it() ^^^^^^^ File "/usr/lib/python3/dist-packages/virtme/commands/run.py", line 783, in do_it kernel = find_kernel_and_mods(arch, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/virtme/commands/run.py", line 486, in find_kernel_and_mods if not os.path.exists(virtme_mods) or is_file_more_recent( ^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3/dist-packages/virtme/commands/run.py", line 307, in is_file_more_recent return os.stat(a).st_mtime > os.stat(b).st_mtime ^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: './.virtme_mods/lib/modules/0.0.0/modules.dep' This is because the .virtme_mods folder has been created while the .virtme_mods/lib/modules/0.0.0/modules.dep file is still missing. So use the $MODDIR/modules.dep file to check if virtme's kernel modules directory needs to be updated. This fixes issue #87: https://github.com/amluto/virtme/issues/87 Signed-off-by: Winston Wen --- virtme/commands/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virtme/commands/run.py b/virtme/commands/run.py index 9ed64b6..15856e5 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -489,7 +489,7 @@ def find_kernel_and_mods(arch, args) -> Kernel: # Check if modules.order exists, otherwise fallback to mods=none if os.path.exists(mod_file): # Check if virtme's kernel modules directory needs to be updated - if not os.path.exists(virtme_mods) or is_file_more_recent( + if not os.path.exists(virtme_mod_file) or is_file_more_recent( mod_file, virtme_mod_file ): if modmode == "use": From 5f4cdc516e08daa6a22b4ed107b1763a3df9c1e6 Mon Sep 17 00:00:00 2001 From: Winston Wen Date: Fri, 2 Feb 2024 15:06:01 +0800 Subject: [PATCH 2/2] virtme-prep-kdir-mods: delete existing $MODDIR/modules.dep at beginning If preparation process of .virtme_mods is interrupted, the directory will be in an inconsistent state and needs to updated on the next run. Now we use $MODDIR/modules.dep file in run.py to check if virtme_mods needs to be updated, so we can delete the modules.dep file at the beginning to ensure that if the command is interrupted, we will update the directory on the next run. Signed-off-by: Winston Wen --- bin/virtme-prep-kdir-mods | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/virtme-prep-kdir-mods b/bin/virtme-prep-kdir-mods index aec9177..dd3643a 100755 --- a/bin/virtme-prep-kdir-mods +++ b/bin/virtme-prep-kdir-mods @@ -43,6 +43,16 @@ if ! [ -f "modules.order" ]; then exit 1 fi + +# Delete existing .virtme_modes/lib/modules/0.0.0/modules.dep file at the beginning, +# and regenerated by depmod at the end. So if we are interrupted during the +# preparation of .virtme_mods folder, the next run command can correctly trigger the +# prepararion work again. + +if [ -f "$MODDIR/modules.dep" ]; then + rm $MODDIR/modules.dep +fi + # Set up .virtme_mods/lib/modules/0.0.0 as a module directory for this kernel, # but fill it with symlinks instead of actual modules.