Skip to content

Commit c05ec6b

Browse files
virtio_fs_rlimit_nofile: new case
1. Create a shared directory for testing on the host. 2. Touch 1024 files in the shared directory. 3. Start the virtiofsd daemon with rlimit-nofile and check. Signed-off-by: Tingting Mao <[email protected]>
1 parent 39966b3 commit c05ec6b

File tree

2 files changed

+278
-0
lines changed

2 files changed

+278
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
- virtio_fs_rlimit_nofile:
2+
only Linux
3+
no RHEL.6 RHEL.7 RHEL.8.0 RHEL.8.1
4+
no Host_RHEL.m6 Host_RHEL.m7 Host_RHEL.m8.u0 Host_RHEL.m8.u1
5+
type = virtio_fs_rlimit_nofile
6+
required_virtiofsd_version = [1.13.2-1,)
7+
virtiofsd_version_cmd = rpm -q virtiofsd | cut -d- -f2
8+
Win10.i386:
9+
mem = 4096
10+
fs_source_dir = /var/tmp/virtiofs_rlimit_nofile
11+
force_create_fs_source = yes
12+
remove_fs_source = yes
13+
14+
pre_command = "cd ${fs_source_dir}"
15+
pre_command += " && for i in $(seq 1 1024); do touch file_$i.txt; done"
16+
virtiofs_socket_path = '/var/tmp/virtiofs_rlimit_nofile.sock'
17+
cmd_run_virtiofsd = '/usr/libexec/virtiofsd --socket-path ${virtiofs_socket_path} --shared-dir ${fs_source_dir}'
18+
19+
vm_mem_share = yes
20+
vm_mem_backend = memory-backend-file
21+
vm_mem_backend_path = /dev/shm
22+
share_mem = yes
23+
!s390, s390x:
24+
mem_devs = mem1
25+
backend_mem_mem1 = memory-backend-file
26+
mem-path_mem1 = /dev/shm
27+
size_mem1 = ${mem}M
28+
use_mem_mem1 = no
29+
guest_numa_nodes = shm0
30+
numa_memdev_shm0 = mem-mem1
31+
numa_nodeid_shm0 = 0
32+
Windows:
33+
# install winfsp tool
34+
i386, i686:
35+
install_winfsp_path = 'C:\Program Files'
36+
devcon_dirname = 'x86'
37+
x86_64:
38+
install_winfsp_path = 'C:\Program Files (x86)'
39+
devcon_dirname = 'amd64'
40+
install_winfsp_cmd = 'msiexec /i WIN_UTILS:\winfsp.msi /qn'
41+
check_installed_cmd = 'dir "%s" |findstr /I winfsp'
42+
viofs_log_file = C:\viofs_log.txt
43+
viofs_svc_name = VirtioFsSvc
44+
viofs_exe_path = C:\virtiofs.exe
45+
viofs_exe_copy_cmd = xcopy %s C:\ /Y
46+
viofs_sc_create_cmd = 'sc create ${viofs_svc_name} binpath=${viofs_exe_path} start=auto'
47+
viofs_sc_create_cmd += ' depend="WinFsp.Launcher/VirtioFsDrv" DisplayName="Virtio FS Service"'
48+
viofs_sc_start_cmd = 'sc start ${viofs_svc_name}'
49+
viofs_sc_query_cmd = 'sc query ${viofs_svc_name}'
50+
viofs_sc_delete_cmd = 'sc delete ${viofs_svc_name}'
51+
debug_log_operation = 'enable'
52+
viofs_debug_enable_cmd = 'reg add HKLM\Software\VirtIO-FS /v DebugFlags /d 0xFFFFFFFF /t REG_DWORD'
53+
viofs_log_enable_cmd = 'reg add HKLM\Software\VirtIO-FS /v DebugLogFile /d ${viofs_log_file} /t REG_SZ'
54+
viofs_debug_delete_cmd = 'reg delete HKLM\Software\VirtIO-FS /v DebugFlags /f'
55+
viofs_log_delete_cmd = 'reg delete HKLM\Software\VirtIO-FS /v DebugLogFile /f'
56+
viofs_reg_query_cmd = 'reg query HKLM\Software\VirtIO-FS'
57+
virtio_win_media_type = iso
58+
cdroms += " virtio"
59+
check_str = 'A device attached to the system is not functioning'
60+
list_file_cmd = "dir %s"
61+
variants:
62+
- rlimit_nofile_512:
63+
rlimit_nofile = 512
64+
cmd_run_virtiofsd += " --rlimit-nofile ${rlimit_nofile}"
65+
expected_msg = "Maximum number of file descriptors too small: Limit is 512, must be at least 610"
66+
- rlimit_nofile_610:
67+
rlimit_nofile = 610
68+
cmd_run_virtiofsd += " --rlimit-nofile ${rlimit_nofile}"
69+
expected_msg = "File descriptor count limit is very small, leaving only 0 file descriptors for the guest"
70+
- rlimit_nofile_1000:
71+
kill_vm = yes
72+
start_vm = yes
73+
filesystems = fs
74+
fs_driver = virtio-fs
75+
fs_source_type = mount
76+
force_create_fs_source = yes
77+
remove_fs_source = yes
78+
fs_target = 'myfs'
79+
fs_driver_props = {"queue-size": 1024}
80+
fs_dest = '/mnt/${fs_target}'
81+
driver_name = viofs
82+
rlimit_nofile = 1000
83+
fs_binary_extra_options += " --rlimit-nofile ${rlimit_nofile}"
84+
list_file_cmd = "ls %s"
85+
ls_check_content = "Too many open files"
86+
qemu_check_content = "No more file descriptors available to the guest (0 available out of 390 initially), consider increasing the --rlimit-nofile value"
87+
- rlimit_nofile_2048:
88+
kill_vm = yes
89+
start_vm = yes
90+
filesystems = fs
91+
fs_driver = virtio-fs
92+
fs_source_type = mount
93+
force_create_fs_source = yes
94+
remove_fs_source = yes
95+
fs_target = 'myfs'
96+
fs_driver_props = {"queue-size": 1024}
97+
fs_dest = '/mnt/${fs_target}'
98+
driver_name = viofs
99+
rlimit_nofile = 2048
100+
fs_binary_extra_options += " --rlimit-nofile ${rlimit_nofile}"
101+
list_file_cmd = "ls %s"

qemu/tests/virtio_fs_rlimit_nofile.py

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
import aexpect
2+
from virttest import error_context
3+
from avocado.utils import process
4+
from virttest import (
5+
error_context, utils_disk, utils_misc, utils_test
6+
)
7+
from provider import virtio_fs_utils
8+
9+
10+
@error_context.context_aware
11+
def run(test, params, env):
12+
"""
13+
Test virtio-fs rlimit-nofile.
14+
Steps:
15+
1. Create a shared directory for testing on the host.
16+
2. Touch 1024 files in the shared directory.
17+
3. Start the virtiofsd daemon with rlimit-nofile and check.
18+
19+
:param test: QEMU test object.
20+
:param params: Dictionary with the test parameters.
21+
:param env: Dictionary with test environment.
22+
"""
23+
24+
def create_service(session):
25+
if os_type == "windows":
26+
error_context.context("Create virtiofs service in guest.", test.log.info)
27+
28+
driver_name = params["driver_name"]
29+
30+
session = utils_test.qemu.windrv_check_running_verifier(
31+
session, vm, test, driver_name
32+
)
33+
viofs_svc_name = params["viofs_svc_name"]
34+
virtio_fs_utils.create_viofs_service(
35+
test, params, session, service=viofs_svc_name
36+
)
37+
return session
38+
39+
def delete_service():
40+
if os_type == "windows":
41+
error_context.context("Delete virtiofs service in guest.", test.log.info)
42+
session = vm.wait_for_login()
43+
virtio_fs_utils.delete_viofs_serivce(test, params, session)
44+
session.close()
45+
46+
def start_service(session):
47+
fs = params["filesystems"]
48+
fs_params = params.object_params(fs)
49+
50+
fs_target = fs_params["fs_target"]
51+
fs_dest = fs_params["fs_dest"]
52+
53+
if os_type == "linux":
54+
utils_misc.make_dirs(fs_dest, session)
55+
error_context.context(
56+
"Mount virtiofs target %s to %s inside guest." % (fs_target, fs_dest),
57+
test.log.info,
58+
)
59+
if not utils_disk.mount(fs_target, fs_dest, "virtiofs", session=session):
60+
utils_misc.safe_rmdir(fs_dest, session=session)
61+
test.fail("Failed to mount virtiofs {fs_target}.")
62+
else:
63+
error_context.context("Start virtiofs service in guest.", test.log.info)
64+
debug_log_operation = params.get("debug_log_operation")
65+
if debug_log_operation:
66+
session = virtio_fs_utils.operate_debug_log(
67+
test, params, session, vm, debug_log_operation
68+
)
69+
virtio_fs_utils.start_viofs_service(test, params, session)
70+
71+
fs_dest = "%s:" % virtio_fs_utils.get_virtiofs_driver_letter(
72+
test, fs_target, session
73+
)
74+
75+
guest_mnts[fs_target] = fs_dest
76+
return session
77+
78+
def stop_service(session):
79+
error_context.context("Stop virtiofs service in guest.", test.log.info)
80+
81+
if os_type == "linux":
82+
for fs_target, fs_dest in guest_mnts.items():
83+
utils_disk.umount(fs_target, fs_dest, "virtiofs", session=session)
84+
utils_misc.safe_rmdir(fs_dest, session=session)
85+
else:
86+
if guest_mnts:
87+
virtio_fs_utils.stop_viofs_service(test, params, session)
88+
session.close()
89+
90+
rlimit_nofile = params.get("rlimit_nofile")
91+
cmd_run_virtiofsd = params["cmd_run_virtiofsd"]
92+
guest_mnts = dict()
93+
os_type = params["os_type"]
94+
95+
if rlimit_nofile == "512":
96+
expected_msg = params["expected_msg"]
97+
error_context.context(
98+
"Starting virtiofsd with rlimit-nofile=%s" % rlimit_nofile,
99+
test.log.info)
100+
result = process.run(
101+
cmd_run_virtiofsd,
102+
shell=True,
103+
ignore_status=True,
104+
verbose=True,
105+
)
106+
status, out = result.exit_status, result.stdout.decode()
107+
if status == 0:
108+
test.fail(
109+
"virtiofsd unexpectedly started successfully with "
110+
"rlimit-nofile=512"
111+
)
112+
elif expected_msg not in out:
113+
test.fail(
114+
"virtiofsd failed but without expected message. Output: %s" % out)
115+
error_context.context(
116+
"virtiofsd failed as expected with the required message present",
117+
test.log.info)
118+
elif rlimit_nofile == "610":
119+
expected_msg = params["expected_msg"]
120+
error_context.context(
121+
"Starting virtiofsd with rlimit-nofile=%s" % rlimit_nofile,
122+
test.log.info)
123+
session = aexpect.ShellSession(
124+
cmd_run_virtiofsd,
125+
auto_close=False,
126+
output_func=utils_misc.log_line,
127+
output_params=("virtiofs_fs-virtiofs.log",),
128+
prompt=r"^\[.*\][\#\$]\s*$",
129+
)
130+
try:
131+
session.expect(expected_msg, timeout=10)
132+
test.log.info(
133+
"virtiofsd started successfully with the required message "
134+
"present"
135+
)
136+
except aexpect.ExpectTimeout as e:
137+
test.fail("Timeout for virtiofsd start with rlimit-nofile=610: %s" % e)
138+
finally:
139+
session.close()
140+
elif rlimit_nofile == "1000":
141+
error_context.context(
142+
"Starting virtiofsd with rlimit-nofile=%s" % rlimit_nofile,
143+
test.log.info)
144+
vm = env.get_vm(params.get("main_vm"))
145+
vm.verify_alive()
146+
session = vm.wait_for_login()
147+
try:
148+
session = create_service(session)
149+
session = start_service(session)
150+
for fs_dest in guest_mnts.values():
151+
out = session.cmd_output(params["list_file_cmd"] % fs_dest).strip()
152+
test.log.debug("The dir output in guest: %s", out)
153+
if params["ls_check_content"] not in out:
154+
test.fail(f"Wrong content found: {out}")
155+
output = vm.process.get_output()
156+
if params["qemu_check_content"] not in output:
157+
test.fail(f"Wrong qemu content found: {out}")
158+
finally:
159+
stop_service(session)
160+
delete_service()
161+
elif rlimit_nofile == "2048":
162+
error_context.context(
163+
"Starting virtiofsd with rlimit-nofile=%s" % rlimit_nofile,
164+
test.log.info)
165+
vm = env.get_vm(params.get("main_vm"))
166+
vm.verify_alive()
167+
session = vm.wait_for_login()
168+
try:
169+
session = create_service(session)
170+
session = start_service(session)
171+
for fs_dest in guest_mnts.values():
172+
status, output = session.cmd_status_output(params["list_file_cmd"] % fs_dest).strip()
173+
if status != 0:
174+
test.fail("list failed: $s" % output)
175+
finally:
176+
stop_service(session)
177+
delete_service()

0 commit comments

Comments
 (0)