libxl: Add support for blktap vbd3

This patch re-introduces blktap support to libxl.  Unlike earlier
versions, it does not link against any blktap library.  libxl changes
are needed to write to the vbd3 backend XenStore nodes.

blktap has three components.  tapdisk is a daemon implementing the disk
IO, NBD (Network Block Device), and Xen PV interfaces.  tap-ctl is a
tool to control tapdisks - creating, starting, stopping and freeing.
tapback manages the XenStore operations and instructs tapdisk to
connect.

It is notable that tapdisk performs the grant and event channel ops, but
doesn't interact with XenStore.  tapback performs XenStore operations
and notifies tapdisks of values and changes.

The flow is: libxl writes to the "vbd3" XenStore nodes and runs the
block-tap script.  The block-tap script runs tap-ctl to create a tapdisk
instance as the physical device.  tapback then sees the tapdisk and
instructs the tapdisk to connect up the PV blkif interface.

This is expected to work without the kernel blktap driver, so the
block-tap script is modified accordingly to write the UNIX NBD path.

backendtype=tap was not fully removed previously, but it would never
succeed since it would hit the hardcoded error in disk_try_backend().
It is reused now.

An example command to attach a vhd:
xl block-attach vm 'vdev=xvdf,backendtype=tap,format=vhd,target=/srv/target.vhd'

Format raw also works to run an "aio:" tapdisk.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
This commit is contained in:
Jason Andryuk authored and Jan Beulich committed 2024-02-13 09:28:58 +01:00
1 parent cbbca7be4a
commit 6d7d8d2b3e
6 files changed
+32 -10

No files matched your search

+3 -1
View File
@@ -232,7 +232,7 @@ Specifies the backend implementation to use
=item Supported values
phy, qdisk, standalone
phy, qdisk, standalone, tap
=item Mandatory
@@ -254,6 +254,8 @@ and "standalone" does not support specifications other than "virtio".
Normally this option should not be specified, in which case libxl will
automatically determine the most suitable backend.
"tap" needs blktap's tapback to be running.
=item B<script>=I<SCRIPT>
+10 -4
View File
@@ -328,9 +328,15 @@ static int disk_try_backend(disk_try_backend_args *a,
return 0;
case LIBXL_DISK_BACKEND_TAP:
LOG(DEBUG, "Disk vdev=%s, backend tap unsuitable because blktap "
"not available", a->disk->vdev);
return 0;
if (a->disk->format != LIBXL_DISK_FORMAT_RAW &&
a->disk->format != LIBXL_DISK_FORMAT_VHD)
goto bad_format;
if (libxl_defbool_val(a->disk->colo_enable))
goto bad_colo;
LOG(DEBUG, "Disk vdev=%s, returning blktap", a->disk->vdev);
return backend;
case LIBXL_DISK_BACKEND_QDISK:
if (a->disk->script) goto bad_script;
@@ -478,7 +484,7 @@ char *libxl__device_disk_string_of_backend(libxl_disk_backend backend)
{
switch (backend) {
case LIBXL_DISK_BACKEND_QDISK: return "qdisk";
case LIBXL_DISK_BACKEND_TAP: return "phy";
case LIBXL_DISK_BACKEND_TAP: return "vbd3";
case LIBXL_DISK_BACKEND_PHY: return "phy";
case LIBXL_DISK_BACKEND_STANDALONE: return "standalone";
default: return NULL;
+15 -5
View File
@@ -56,7 +56,9 @@ static void disk_eject_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
"/local/domain/%d/backend/%" TOSTRING(BACKEND_STRING_SIZE)
"[a-z]/%*d/%*d",
&disk->backend_domid, backend_type);
if (!strcmp(backend_type, "tap") || !strcmp(backend_type, "vbd")) {
if (!strcmp(backend_type, "tap") ||
!strcmp(backend_type, "vbd") ||
!strcmp(backend_type, "vbd3")) {
disk->backend = LIBXL_DISK_BACKEND_TAP;
} else if (!strcmp(backend_type, "qdisk")) {
disk->backend = LIBXL_DISK_BACKEND_QDISK;
@@ -224,7 +226,7 @@ static int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
device->backend_kind = LIBXL__DEVICE_KIND_VBD;
break;
case LIBXL_DISK_BACKEND_TAP:
device->backend_kind = LIBXL__DEVICE_KIND_VBD;
device->backend_kind = LIBXL__DEVICE_KIND_VBD3;
break;
case LIBXL_DISK_BACKEND_QDISK:
device->backend_kind = LIBXL__DEVICE_KIND_QDISK;
@@ -368,9 +370,17 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
assert(device->backend_kind == LIBXL__DEVICE_KIND_VIRTIO_DISK);
break;
case LIBXL_DISK_BACKEND_TAP:
LOG(ERROR, "blktap is not supported");
rc = ERROR_FAIL;
goto out;
flexarray_append(back, "params");
flexarray_append(back, GCSPRINTF("%s:%s",
libxl__device_disk_string_of_format(disk->format),
disk->pdev_path ? : ""));
script = libxl__abs_path(gc, disk->script?: "block-tap",
libxl__xen_script_dir_path());
flexarray_append_pair(back, "script", script);
assert(device->backend_kind == LIBXL__DEVICE_KIND_VBD3);
break;
case LIBXL_DISK_BACKEND_QDISK:
flexarray_append(back, "params");
flexarray_append(back, GCSPRINTF("%s:%s",
+1
View File
@@ -207,6 +207,7 @@ int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
switch (dev->backend_kind) {
case LIBXL__DEVICE_KIND_VBD:
case LIBXL__DEVICE_KIND_VBD3:
if (num_exec != 0) {
LOGD(DEBUG, dev->domid,
"num_exec %d, not running hotplug scripts", num_exec);
@@ -34,6 +34,7 @@ libxl__device_kind = Enumeration("device_kind", [
(16, "VINPUT"),
(17, "VIRTIO_DISK"),
(18, "VIRTIO"),
(19, "VBD3"),
])
libxl__console_backend = Enumeration("console_backend", [
+2
View File
@@ -295,6 +295,8 @@ int libxl_string_to_backend(libxl_ctx *ctx, char *s, libxl_disk_backend *backend
*backend = LIBXL_DISK_BACKEND_PHY;
} else if (!strcmp(s, "file")) {
*backend = LIBXL_DISK_BACKEND_TAP;
} else if (!strcmp(s, "vbd3")) {
*backend = LIBXL_DISK_BACKEND_TAP;
} else if (!strcmp(s, "qdisk")) {
*backend = LIBXL_DISK_BACKEND_QDISK;
} else if (!strcmp(s, "standalone")) {
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.