From 7f74e6e9a9f544c6e9e4ce5fb36e32c89e37ea91 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 18 Dec 2019 16:49:37 +0800 Subject: [PATCH] acrn-config: refine mount device for virtio-blk Previous launch config tool doesn't handle the situation that 'virtio-blk' is set with rootfs partition with rootfs image, in such scenario, VM would be failed to start when launching This patch refine the mount device while use rootfs partiton and image from vritio block device. Tracked-On: #4248 Signed-off-by: Wei Liu Acked-by: Victor Sun --- misc/acrn-config/launch_config/com.py | 76 ++++++++++++------- .../launch_config/launch_cfg_gen.py | 1 + misc/acrn-config/launch_config/launch_item.py | 3 + misc/acrn-config/library/launch_cfg_lib.py | 26 +++++++ 4 files changed, 79 insertions(+), 27 deletions(-) diff --git a/misc/acrn-config/launch_config/com.py b/misc/acrn-config/launch_config/com.py index ff1579b2e..7e6c0ff06 100644 --- a/misc/acrn-config/launch_config/com.py +++ b/misc/acrn-config/launch_config/com.py @@ -18,17 +18,9 @@ def is_nuc_whl_clr(names, vmid): def is_mount_needed(virt_io, vmid): - rootfs_img = '' - blk_dev_list = launch_cfg_lib.get_rootdev_info(launch_cfg_lib.BOARD_INFO_FILE) - if virt_io['block'][vmid]: - if ':' in virt_io['block'][vmid]: - blk_dev = virt_io['block'][vmid].split(':')[0] - rootfs_img = virt_io['block'][vmid].split(':')[1] - else: - blk_dev = virt_io['block'][vmid] - if blk_dev in blk_dev_list and rootfs_img: - return True + if True in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]: + return True return False @@ -40,12 +32,20 @@ def tap_uos_net(names, virt_io, vmid, config): vm_name = launch_cfg_lib.undline_name(uos_type).lower() if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"): - if board_name in ("apl-mrb", "apl-up2"): - print('if [ ! -f "/data/{}/{}.img" ]; then'.format(vm_name, vm_name), file=config) - print(' echo "no /data/{}/{}.img, exit"'.format(vm_name, vm_name), file=config) + i = 0 + for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]: + if not mount_flag: + i += 1 + continue + blk = virt_io['block'][vmid][i] + rootfs_img = blk.split(':')[1].strip(':') + print('if [ ! -f "/data{}/{}" ]; then'.format(i, rootfs_img), file=config) + print(' echo "no /data{}/{}, exit"'.format(i, rootfs_img), file=config) print(" exit", file=config) print("fi", file=config) print("", file=config) + i += 1 + print("#vm-name used to generate uos-mac address", file=config) print("mac=$(cat /sys/class/net/e*/address)", file=config) print("vm_name=vm$1", file=config) @@ -331,7 +331,14 @@ def uos_launch(names, args, virt_io, vmid, config): print("", file=config) print('launch_{} {} "{}" "{}" $debug'.format(launch_uos, vmid, gvt_args, vmid), file=config) print("", file=config) - print("umount /data", file=config) + + i = 0 + for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]: + if not mount_flag: + i += 1 + continue + print("umount /data{}".format(i), file=config) + i += 1 def launch_end(names, args, virt_io, vmid, config): @@ -361,16 +368,21 @@ def launch_end(names, args, virt_io, vmid, config): print("", file=config) if is_mount_needed(virt_io, vmid): - root_fs = virt_io['block'][vmid].split(':')[0] - - print('if [ ! -b "{}" ]; then'.format(root_fs), file=config) - print(' echo "no {} data partition, exit"'.format(root_fs), file=config) - print(" exit", file=config) - print("fi", file=config) - print("", file=config) - print("mkdir -p /data", file=config) - print("mount {} /data".format(root_fs), file=config) - print("", file=config) + i = 0 + for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]: + if not mount_flag: + i += 1 + continue + blk = virt_io['block'][vmid][i] + root_fs = blk.split(':')[0] + print('if [ ! -b "{}" ]; then'.format(root_fs), file=config) + print(' echo "no {} data partition, exit"'.format(root_fs), file=config) + print(" exit", file=config) + print("fi", file=config) + print("mkdir -p /data{}".format(i), file=config) + print("mount {} /data{}".format(root_fs, i), file=config) + print("", file=config) + i += 1 off_line_cpus(args, vmid, uos_type, config) @@ -455,9 +467,19 @@ def virtio_args_set(dm, virt_io, vmid, config): launch_cfg_lib.virtual_dev_slot("virtio-input{}".format(input_val)), input_val), file=config) # virtio-blk set, the value type is a list - for blk in virt_io['block'][vmid]: - if blk: - print(" -s {},virtio-blk,{} \\".format(launch_cfg_lib.virtual_dev_slot("virtio-blk{}".format(blk)), blk.strip(':')), file=config) + i = 0 + for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]: + blk = virt_io['block'][vmid][i] + if not mount_flag: + if blk: + rootfs_img = blk.strip(':') + print(" -s {},virtio-blk,{} \\".format(launch_cfg_lib.virtual_dev_slot("virtio-blk{}".format(blk)), rootfs_img), file=config) + i += 1 + continue + + rootfs_img = blk.split(':')[1].strip(':') + print(" -s {},virtio-blk,/data{}/{} \\".format(launch_cfg_lib.virtual_dev_slot("blk_mount_{}".format(i)), i, rootfs_img), file=config) + i += 1 # virtio-net set, the value type is a list for net in virt_io['network'][vmid]: diff --git a/misc/acrn-config/launch_config/launch_cfg_gen.py b/misc/acrn-config/launch_config/launch_cfg_gen.py index 8229664c8..cba044211 100644 --- a/misc/acrn-config/launch_config/launch_cfg_gen.py +++ b/misc/acrn-config/launch_config/launch_cfg_gen.py @@ -74,6 +74,7 @@ def validate_launch_setting(board_info, scenario_info, launch_info): # virt-io devices virtio = VirtioDeviceSelect(launch_info) virtio.get_virtio() + virtio.check_virtio() # acrn dm arguments dm = AcrnDmArgs(board_info, scenario_info, launch_info) diff --git a/misc/acrn-config/launch_config/launch_item.py b/misc/acrn-config/launch_config/launch_item.py index c73cc711a..61d6d72e8 100644 --- a/misc/acrn-config/launch_config/launch_item.py +++ b/misc/acrn-config/launch_config/launch_item.py @@ -156,3 +156,6 @@ class VirtioDeviceSelect(): self.dev["block"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "block") self.dev["network"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "network") self.dev["console"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "console") + + def check_virtio(self): + launch_cfg_lib.check_block_mount(self.dev["block"]) diff --git a/misc/acrn-config/library/launch_cfg_lib.py b/misc/acrn-config/library/launch_cfg_lib.py index 88c545ef6..9d602010c 100644 --- a/misc/acrn-config/library/launch_cfg_lib.py +++ b/misc/acrn-config/library/launch_cfg_lib.py @@ -56,6 +56,8 @@ PM_CHANNEL_DIC = { 'vuart1(tty)':'--pm_notify_channel uart --pm_by_vuart tty,/dev/ttyS1', } +MOUNT_FLAG_DIC = {} + def prepare(check_git): """ Check environment """ @@ -617,3 +619,27 @@ def pt_devs_check_audio(audio_map, audio_codec_map): if not bdf_audio and bdf_codec: key = "uos:id={},passthrough_devices,{}".format(vmid, 'audio_codec') ERR_LIST[key] = "Audio codec device should be pass through together with Audio devcie!" + + +def check_block_mount(virtio_blk_dic): + blk_dev_list = get_rootdev_info(BOARD_INFO_FILE) + for vmid in list(virtio_blk_dic.keys()): + mount_flags = [] + for blk in virtio_blk_dic[vmid]: + rootfs_img = '' + if not blk: + mount_flags.append(False) + continue + + if ':' in blk: + blk_dev = blk.split(':')[0] + rootfs_img = blk.split(':')[1] + else: + blk_dev = blk + + if blk_dev in blk_dev_list and rootfs_img: + mount_flags.append(True) + else: + mount_flags.append(False) + + MOUNT_FLAG_DIC[vmid] = mount_flags