Skip to content

Commit

Permalink
qemu_storage: support the vdpa device
Browse files Browse the repository at this point in the history
add vdpa device support to the related functions

Signed-off-by: Houqi (Nick) Zuo <[email protected]>
  • Loading branch information
nickzhq committed Sep 14, 2023
1 parent c5225ad commit 51bc9ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
18 changes: 16 additions & 2 deletions virttest/env_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,10 @@ def check_image(test, params, image_name, vm_process_status=None):
"""
clone_master = params.get("clone_master", None)
base_dir = data_dir.get_data_dir()
image = qemu_storage.QemuImg(params, base_dir, image_name)
check_image_flag = params.get("check_image") == "yes"
if not check_image_flag:
return
image = qemu_storage.QemuImg(params, base_dir, image_name)

if vm_process_status == "running" and check_image_flag:
if params.get("skip_image_check_during_running") == "yes":
Expand Down Expand Up @@ -498,9 +500,11 @@ def postprocess_image(test, params, image_name, vm_process_status=None):
restored, removed = (False, False)
clone_master = params.get("clone_master", None)
base_dir = params.get("images_base_dir", data_dir.get_data_dir())
image = qemu_storage.QemuImg(params, base_dir, image_name)
image = None

if params.get("img_check_failed") == "yes":
image = qemu_storage.QemuImg(params, base_dir,
image_name) if not image else image
if params.get("restore_image_on_check_error", "no") == "yes":
image.backup_image(params, base_dir, "restore", True)
restored = True
Expand All @@ -509,26 +513,36 @@ def postprocess_image(test, params, image_name, vm_process_status=None):
# with a new backup. i.e. assume pre-existing image/backup
# would not be usable after this test succeeds. The best
# example for this is when 'unattended_install' is run.
image = qemu_storage.QemuImg(params, base_dir,
image_name) if not image else image
if (params.get("backup_image_after_testing_passed", "no") == "yes" and
params.get("test_passed") == "True"):
image.backup_image(params, base_dir, "backup", True)

if (not restored and params.get("restore_image", "no") == "yes"):
image = qemu_storage.QemuImg(params, base_dir,
image_name) if not image else image
image.backup_image(params, base_dir, "restore", True)
restored = True

if (not restored and
params.get("restore_image_after_testing", "no") == "yes"):
image = qemu_storage.QemuImg(params, base_dir,
image_name) if not image else image
image.backup_image(params, base_dir, "restore", True)

if params.get("img_check_failed") == "yes":
image = qemu_storage.QemuImg(params, base_dir,
image_name) if not image else image
if params.get("remove_image_on_check_error", "no") == "yes":
cl_images = params.get("master_images_clone", "")
if image_name in cl_images.split():
image.remove()
removed = True

if (not removed and params.get("remove_image", "yes") == "yes"):
image = qemu_storage.QemuImg(params, base_dir,
image_name) if not image else image
LOG.info("Remove image on %s." % image.storage_type)
if clone_master is None:
image.remove()
Expand Down
10 changes: 10 additions & 0 deletions virttest/qemu_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ def filename_to_file_opts(filename):

if matches['user'] is not None:
file_opts['username'] = matches['user']
# FIXME: vdpa is a customized protocol instead of a standard protocol.
elif filename.startswith("vdpa:"):
# filename[7:] mean: remove the prefix "vdpa://"
file_opts = {'driver': 'virtio-blk-vhost-vdpa',
'path': filename[7:]}
# FIXME: Judge the host device by the string starts with "/dev/".
elif filename.startswith('/dev/'):
file_opts = {'driver': 'host_device', 'filename': filename}
Expand Down Expand Up @@ -517,7 +522,12 @@ def __init__(self, params, root_dir, tag):
:param params: Dictionary containing the test parameters.
:param root_dir: Base directory for relative filenames.
:param tag: Image tag defined in parameter images
:raise NotImplementedError: If the image type is not supported.
"""
if params.get("storage_type") == "vhost-vdpa":
raise NotImplementedError("Vdpa is NOT supported to handle "
"the image!")
storage.QemuImg.__init__(self, params, root_dir, tag)
self.image_cmd = utils_misc.get_qemu_img_binary(params)
q_result = process.run(self.image_cmd + ' -h', ignore_status=True,
Expand Down

0 comments on commit 51bc9ce

Please sign in to comment.