Skip to content

Commit 7838b53

Browse files
Wei Liuwenlingz
authored andcommitted
acrn-config: add virtio-net mediator support for launch config
Add virtio-net mediator support to parse and get 'virtio-network' item value from launch config files, these values are editable by user. Tracked-On: #4185 Signed-off-by: Wei Liu <weix.w.liu@intel.com> Acked-by: Victor Sun <victor.sun@intel.com>
1 parent 25b2a26 commit 7838b53

File tree

3 files changed

+66
-31
lines changed

3 files changed

+66
-31
lines changed

misc/acrn-config/launch_config/com.py

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ def is_mount_needed(virt_io, vmid):
3333
return False
3434

3535

36-
def tap_uos_net(names, vmid, config):
36+
def tap_uos_net(names, virt_io, vmid, config):
3737
uos_type = names['uos_types'][vmid]
3838
board_name = names['board_name']
3939

4040
vm_name = launch_cfg_lib.undline_name(uos_type).lower()
41+
4142
if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"):
4243
if board_name in ("apl-mrb", "apl-up2"):
4344
print('if [ ! -f "/data/{}/{}.img" ]; then'.format(vm_name, vm_name), file=config)
@@ -54,26 +55,13 @@ def tap_uos_net(names, vmid, config):
5455
if uos_type in ("VXWORKS", "ZEPHYR", "WINDOWS", "PREEMPT-RT LINUX"):
5556
print("vm_name={}_vm$1".format(vm_name), file=config)
5657

57-
if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"):
58-
if board_name in ("apl-mrb", "apl-up2"):
59-
print("# create a unique tap device for each VM", file=config)
60-
print("tap=tap_$3", file=config)
61-
print('tap_exist=$(ip a | grep "$tap" | awk \'{print $1}\')', file=config)
62-
print('if [ "$tap_exist"x != "x" ]; then', file=config)
63-
print(' echo "tap device existed, reuse $tap"', file=config)
64-
print("else", file=config)
65-
print(" ip tuntap add dev $tap mode tap", file=config)
66-
print("fi", file=config)
67-
print("", file=config)
68-
print("# if acrn-br0 exists, add VM's unique tap device under it", file=config)
69-
print("br_exist=$(ip a | grep acrn-br0 | awk '{print $1}')", file=config)
70-
print('if [ "$br_exist"x != "x" -a "$tap_exist"x = "x" ]; then', file=config)
71-
print(' echo "acrn-br0 bridge aleady exists, adding new tap device to it..."', file=config)
72-
print(' ip link set "$tap" master acrn-br0', file=config)
73-
print(' ip link set dev "$tap" down', file=config)
74-
print(' ip link set dev "$tap" up', file=config)
75-
print("fi", file=config)
76-
print("", file=config)
58+
for net in virt_io['network'][vmid]:
59+
if net:
60+
net_name = net
61+
if ',' in net:
62+
net_name = net.split(',')[0]
63+
print("tap_net {}".format(net_name), file=config)
64+
7765
print("#check if the vm is running or not", file=config)
7866
print("vm_ps=$(pgrep -a -f acrn-dm)", file=config)
7967
print('result=$(echo $vm_ps | grep -w "${vm_name}")', file=config)
@@ -252,9 +240,44 @@ def log_level_set(uos_type, config):
252240
print('logger_setting="--logger_setting console,level=4;kmsg,level=3;disk,level=5"', file=config)
253241
print("", file=config)
254242

243+
def tap_network(virt_io, vmid, config):
244+
245+
none_i = 0
246+
tap_net_list = virt_io['network'][vmid]
247+
for net in tap_net_list:
248+
if net == None:
249+
none_i += 1
250+
tap_net_num = len(tap_net_list) - none_i
251+
252+
if tap_net_num >= 1:
253+
print("function tap_net() {", file=config)
254+
print("# create a unique tap device for each VM", file=config)
255+
print("tap=$1", file=config)
256+
print('tap_exist=$(ip a | grep "$tap" | awk \'{print $1}\')', file=config)
257+
print('if [ "$tap_exist"x != "x" ]; then', file=config)
258+
print(' echo "tap device existed, reuse $tap"', file=config)
259+
print("else", file=config)
260+
print(" ip tuntap add dev $tap mode tap", file=config)
261+
print("fi", file=config)
262+
print("", file=config)
263+
print("# if acrn-br0 exists, add VM's unique tap device under it", file=config)
264+
print("br_exist=$(ip a | grep acrn-br0 | awk '{print $1}')", file=config)
265+
print('if [ "$br_exist"x != "x" -a "$tap_exist"x = "x" ]; then', file=config)
266+
print(' echo "acrn-br0 bridge aleady exists, adding new tap device to it..."', file=config)
267+
print(' ip link set "$tap" master acrn-br0', file=config)
268+
print(' ip link set dev "$tap" down', file=config)
269+
print(' ip link set dev "$tap" up', file=config)
270+
print("fi", file=config)
271+
print("}", file=config)
272+
print("", file=config)
273+
274+
275+
def launch_begin(names, virt_io, vmid, config):
276+
board_name = names['board_name']
277+
uos_type = names['uos_types'][vmid]
255278

256-
def launch_begin(board_name, uos_type, config):
257279
launch_uos = launch_cfg_lib.undline_name(uos_type).lower()
280+
tap_network(virt_io, vmid, config)
258281
run_container(board_name, uos_type, config)
259282
print("function launch_{}()".format(launch_uos), file=config)
260283
print("{", file=config)
@@ -434,6 +457,14 @@ def virtio_args_set(dm, virt_io, vmid, config):
434457
if blk:
435458
print(" -s {},virtio-blk,{} \\".format(launch_cfg_lib.virtual_dev_slot("virtio-blk{}".format(blk)), blk.strip(':')), file=config)
436459

460+
# virtio-net set, the value type is a list
461+
for net in virt_io['network'][vmid]:
462+
if net:
463+
net_name = net
464+
if ',' in net:
465+
net_name = net.split(',')[0]
466+
print(" -s {},virtio-net,{} \\".format(launch_cfg_lib.virtual_dev_slot("virtio-net{}".format(net)), net_name), file=config)
467+
437468

438469
def dm_arg_set(names, sel, virt_io, dm, vmid, config):
439470

@@ -473,7 +504,6 @@ def dm_arg_set(names, sel, virt_io, dm, vmid, config):
473504
print(" --pm_notify_channel uart \\", file=config)
474505
print(' --pm_by_vuart pty,/run/acrn/life_mngr_$vm_name \\', file=config)
475506
print(' -l com2,/run/acrn/life_mngr_$vm_name \\', file=config)
476-
print(" -s {},virtio-net,tap0 \\".format(launch_cfg_lib.virtual_dev_slot("virtio-net")), file=config)
477507

478508
# mac_seed
479509
if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"):
@@ -525,10 +555,6 @@ def dm_arg_set(names, sel, virt_io, dm, vmid, config):
525555
launch_cfg_lib.virtual_dev_slot("virtio-console(hvc0)"),
526556
launch_cfg_lib.RE_CONSOLE_MAP['virtio-console(hvc0)']), file=config)
527557

528-
if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"):
529-
if board_name in ("apl-mrb", "apl-up2"):
530-
print(" -s {},virtio-net,$tap \\".format(launch_cfg_lib.virtual_dev_slot("virtio-net")), file=config)
531-
532558
if uos_type in ("CLEARLINUX", "ANDROID", "ALIOS"):
533559
print(" -s {},virtio-hyper_dmabuf \\".format(launch_cfg_lib.virtual_dev_slot("virtio-hyper_dmabuf")), file=config)
534560
if board_name == "apl-mrb":
@@ -558,8 +584,8 @@ def gen(names, pt_sel, virt_io, dm, vmid, config):
558584
pt.gen_pt_head(names, pt_sel, vmid, config)
559585

560586
# gen launch header
561-
launch_begin(board_name, uos_type, config)
562-
tap_uos_net(names, vmid, config)
587+
launch_begin(names, virt_io, vmid, config)
588+
tap_uos_net(names, virt_io, vmid, config)
563589

564590
# passthrough device
565591
pt.gen_pt(names, pt_sel, vmid, config)

misc/acrn-config/launch_config/launch_item.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,4 @@ def __init__(self, launch_info):
151151
def get_virtio(self):
152152
self.dev["input"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "input")
153153
self.dev["block"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "block")
154+
self.dev["network"] = launch_cfg_lib.get_leaf_tag_map(self.launch_info, "virtio_devices", "network")

misc/acrn-config/library/common.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
START_HPA_SIZE_LIST = ['0x20000000', '0x40000000', '0x80000000', 'CONFIG_SOS_RAM_SIZE', 'VM0_MEM_SIZE']
2424

2525

26-
MULTI_ITEM = ["guest_flag", "pcpu_id", "input", "block"]
26+
MULTI_ITEM = ["guest_flag", "pcpu_id", "input", "block", "network"]
2727

2828

2929
class MultiItem():
@@ -34,7 +34,7 @@ def __init__(self):
3434
self.vir_input = []
3535
self.vir_block = []
3636
self.vir_console = []
37-
self.vir_net = []
37+
self.vir_network = []
3838

3939
class TmpItem():
4040

@@ -420,6 +420,10 @@ def get_leaf_value(tmp, tag_str, leaf):
420420
if leaf.tag == "block" and tag_str == "block":
421421
tmp.multi.vir_block.append(leaf.text)
422422

423+
# get virtio-net for vm
424+
if leaf.tag == "network" and tag_str == "network":
425+
tmp.multi.vir_network.append(leaf.text)
426+
423427

424428
def get_sub_value(tmp, tag_str, vm_id):
425429

@@ -440,6 +444,10 @@ def get_sub_value(tmp, tag_str, vm_id):
440444
if tmp.multi.vir_block and tag_str == "block":
441445
tmp.tag[vm_id] = tmp.multi.vir_block
442446

447+
# append virtio network for vm
448+
if tmp.multi.vir_network and tag_str == "network":
449+
tmp.tag[vm_id] = tmp.multi.vir_network
450+
443451

444452
def get_leaf_tag_map(config_file, branch_tag, tag_str):
445453
"""

0 commit comments

Comments
 (0)