Skip to content

Commit 7f74e6e

Browse files
Wei Liuwenlingz
authored andcommitted
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 <weix.w.liu@intel.com> Acked-by: Victor Sun <victor.sun@intel.com>
1 parent fc357a7 commit 7f74e6e

File tree

4 files changed

+79
-27
lines changed

4 files changed

+79
-27
lines changed

misc/acrn-config/launch_config/com.py

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,9 @@ def is_nuc_whl_clr(names, vmid):
1818

1919

2020
def is_mount_needed(virt_io, vmid):
21-
rootfs_img = ''
22-
blk_dev_list = launch_cfg_lib.get_rootdev_info(launch_cfg_lib.BOARD_INFO_FILE)
23-
if virt_io['block'][vmid]:
24-
if ':' in virt_io['block'][vmid]:
25-
blk_dev = virt_io['block'][vmid].split(':')[0]
26-
rootfs_img = virt_io['block'][vmid].split(':')[1]
27-
else:
28-
blk_dev = virt_io['block'][vmid]
2921

30-
if blk_dev in blk_dev_list and rootfs_img:
31-
return True
22+
if True in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]:
23+
return True
3224

3325
return False
3426

@@ -40,12 +32,20 @@ def tap_uos_net(names, virt_io, vmid, config):
4032
vm_name = launch_cfg_lib.undline_name(uos_type).lower()
4133

4234
if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"):
43-
if board_name in ("apl-mrb", "apl-up2"):
44-
print('if [ ! -f "/data/{}/{}.img" ]; then'.format(vm_name, vm_name), file=config)
45-
print(' echo "no /data/{}/{}.img, exit"'.format(vm_name, vm_name), file=config)
35+
i = 0
36+
for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]:
37+
if not mount_flag:
38+
i += 1
39+
continue
40+
blk = virt_io['block'][vmid][i]
41+
rootfs_img = blk.split(':')[1].strip(':')
42+
print('if [ ! -f "/data{}/{}" ]; then'.format(i, rootfs_img), file=config)
43+
print(' echo "no /data{}/{}, exit"'.format(i, rootfs_img), file=config)
4644
print(" exit", file=config)
4745
print("fi", file=config)
4846
print("", file=config)
47+
i += 1
48+
4949
print("#vm-name used to generate uos-mac address", file=config)
5050
print("mac=$(cat /sys/class/net/e*/address)", file=config)
5151
print("vm_name=vm$1", file=config)
@@ -331,7 +331,14 @@ def uos_launch(names, args, virt_io, vmid, config):
331331
print("", file=config)
332332
print('launch_{} {} "{}" "{}" $debug'.format(launch_uos, vmid, gvt_args, vmid), file=config)
333333
print("", file=config)
334-
print("umount /data", file=config)
334+
335+
i = 0
336+
for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]:
337+
if not mount_flag:
338+
i += 1
339+
continue
340+
print("umount /data{}".format(i), file=config)
341+
i += 1
335342

336343

337344
def launch_end(names, args, virt_io, vmid, config):
@@ -361,16 +368,21 @@ def launch_end(names, args, virt_io, vmid, config):
361368
print("", file=config)
362369

363370
if is_mount_needed(virt_io, vmid):
364-
root_fs = virt_io['block'][vmid].split(':')[0]
365-
366-
print('if [ ! -b "{}" ]; then'.format(root_fs), file=config)
367-
print(' echo "no {} data partition, exit"'.format(root_fs), file=config)
368-
print(" exit", file=config)
369-
print("fi", file=config)
370-
print("", file=config)
371-
print("mkdir -p /data", file=config)
372-
print("mount {} /data".format(root_fs), file=config)
373-
print("", file=config)
371+
i = 0
372+
for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]:
373+
if not mount_flag:
374+
i += 1
375+
continue
376+
blk = virt_io['block'][vmid][i]
377+
root_fs = blk.split(':')[0]
378+
print('if [ ! -b "{}" ]; then'.format(root_fs), file=config)
379+
print(' echo "no {} data partition, exit"'.format(root_fs), file=config)
380+
print(" exit", file=config)
381+
print("fi", file=config)
382+
print("mkdir -p /data{}".format(i), file=config)
383+
print("mount {} /data{}".format(root_fs, i), file=config)
384+
print("", file=config)
385+
i += 1
374386

375387
off_line_cpus(args, vmid, uos_type, config)
376388

@@ -455,9 +467,19 @@ def virtio_args_set(dm, virt_io, vmid, config):
455467
launch_cfg_lib.virtual_dev_slot("virtio-input{}".format(input_val)), input_val), file=config)
456468

457469
# virtio-blk set, the value type is a list
458-
for blk in virt_io['block'][vmid]:
459-
if blk:
460-
print(" -s {},virtio-blk,{} \\".format(launch_cfg_lib.virtual_dev_slot("virtio-blk{}".format(blk)), blk.strip(':')), file=config)
470+
i = 0
471+
for mount_flag in launch_cfg_lib.MOUNT_FLAG_DIC[vmid]:
472+
blk = virt_io['block'][vmid][i]
473+
if not mount_flag:
474+
if blk:
475+
rootfs_img = blk.strip(':')
476+
print(" -s {},virtio-blk,{} \\".format(launch_cfg_lib.virtual_dev_slot("virtio-blk{}".format(blk)), rootfs_img), file=config)
477+
i += 1
478+
continue
479+
480+
rootfs_img = blk.split(':')[1].strip(':')
481+
print(" -s {},virtio-blk,/data{}/{} \\".format(launch_cfg_lib.virtual_dev_slot("blk_mount_{}".format(i)), i, rootfs_img), file=config)
482+
i += 1
461483

462484
# virtio-net set, the value type is a list
463485
for net in virt_io['network'][vmid]:

misc/acrn-config/launch_config/launch_cfg_gen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def validate_launch_setting(board_info, scenario_info, launch_info):
7474
# virt-io devices
7575
virtio = VirtioDeviceSelect(launch_info)
7676
virtio.get_virtio()
77+
virtio.check_virtio()
7778

7879
# acrn dm arguments
7980
dm = AcrnDmArgs(board_info, scenario_info, launch_info)

misc/acrn-config/launch_config/launch_item.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,6 @@ def get_virtio(self):
156156
self.dev["block"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "block")
157157
self.dev["network"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "network")
158158
self.dev["console"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "console")
159+
160+
def check_virtio(self):
161+
launch_cfg_lib.check_block_mount(self.dev["block"])

misc/acrn-config/library/launch_cfg_lib.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
'vuart1(tty)':'--pm_notify_channel uart --pm_by_vuart tty,/dev/ttyS1',
5757
}
5858

59+
MOUNT_FLAG_DIC = {}
60+
5961

6062
def prepare(check_git):
6163
""" Check environment """
@@ -617,3 +619,27 @@ def pt_devs_check_audio(audio_map, audio_codec_map):
617619
if not bdf_audio and bdf_codec:
618620
key = "uos:id={},passthrough_devices,{}".format(vmid, 'audio_codec')
619621
ERR_LIST[key] = "Audio codec device should be pass through together with Audio devcie!"
622+
623+
624+
def check_block_mount(virtio_blk_dic):
625+
blk_dev_list = get_rootdev_info(BOARD_INFO_FILE)
626+
for vmid in list(virtio_blk_dic.keys()):
627+
mount_flags = []
628+
for blk in virtio_blk_dic[vmid]:
629+
rootfs_img = ''
630+
if not blk:
631+
mount_flags.append(False)
632+
continue
633+
634+
if ':' in blk:
635+
blk_dev = blk.split(':')[0]
636+
rootfs_img = blk.split(':')[1]
637+
else:
638+
blk_dev = blk
639+
640+
if blk_dev in blk_dev_list and rootfs_img:
641+
mount_flags.append(True)
642+
else:
643+
mount_flags.append(False)
644+
645+
MOUNT_FLAG_DIC[vmid] = mount_flags

0 commit comments

Comments
 (0)