libxl: Enable stubdom cdrom changing
PATCH v4 1/1 libxl: Enable stubdom cdrom changing
To change the cd-rom medium, libxl will:
- QMP eject the medium from QEMU
- block-detach the old PV disk
- block-attach the new PV disk
- QMP change the medium to the new PV disk by fdset-id
The QMP code is reused, and remove and attach are implemented here.
The stubdom must internally handle adding /dev/xvdc to the appropriate fdset. libxl in dom0 doesn't see the result of adding to the fdset as that is internal to the stubdom, but the fdset's opaque fields will be set to stub-devid:$devid, so libxl can identify it. $devid is common between the stubdom and libxl, so it can be identified on both side. The stubdom will name the device xvdY regardless of the guest name hdY, sdY, or xvdY, but the stubdom will be assigned the same devid facilitating lookup. Because the stubdom add-fd call is asynchronous, libxl needs to poll query-fdsets to identify when add-fd has completed.
For cd-eject, we still need to attach the empty vbd. This is necessary since xenstore is used to determine that hdc exists. Otherwise after eject, hdc would be gone and the cd-insert would fail to find the drive to insert new media.
---
QEMU inside the stubdom can be sandboxed disallowing opening the devices by path name, so QMP add-fd is used like with dom0 QEMU depriv.
v1 allowed ERROR_JSON_CONFIG_EMPTY "because a stubdom don't have a json config," but it is re-introduced in v2 since the guest should be acted on. It seems fine in testing. The missing JSON was probably from OpenXT having disabled JSON configs in the past.
v2
Use query-fdsets for removal and addition - stub-devid:$devid Re-use aodev instead of 2nd aodev_del
Rename some functions
Support sdX vdevs
Get stubdomid from cis->disk_domid in stubdom callbacks Use if (rc) not if (rc != 0)
Remove comment about libxl_device_disk_remove
Use EGC_GC not STATE_AO_GC
Re-work and eliminate cdrom_insert_stubdom_query_fdset_retry Change some messages
Allow missing removal fdset in case it wasn't added during startup. Drop LOGD(... rc=%d)
v3:
Remove LOG DEBUGs
s/timeout_retry/retry_timer/
Init stubdom_fdset = -1 and use as flag to pase fdset-id Drop AO_GC
Avoid non-error goto
Expect ERROR_TIMEOUT as non-error
Drop some comments
close payload_fd and set to -1
Remove limit on query-fdset retries
By removing the limit on query-fdset retries, we lose an explicity error message for the stubdom not performing the add-fd, but we give more time which may let more cases succeed.
v4:
Add "must be last" in cdrom_insert_stubdom_parse_fdset_rm() Add "must be last" in cdrom_insert_stubdom_disk_add_cb()
Move ERROR_NOTFOUND handling earlier in cdrom_insert_stubdom_parse_fdset()
--- docs/misc/stubdom.txt | 10 + tools/libs/light/libxl_disk.c | 382 ++++++++++++++++++++++++++++++++-- 2 files changed, 371 insertions(+), 21 deletions(-)
docs/misc/stubdom.txt +10 -0
@@ -127,6 +127,16 @@ Limitations: - at most 26 emulated disks are supported (more are still available as PV disks) - graphics output (VNC/SDL/Spice) not supported +CD-ROM changing: + +To change the CD-ROM medium, libxl will: + - QMP eject the medium from QEMU + - block-detach the old PV disk + - block-attach the new PV disk + - QMP change the medium to the new PV disk by fdset-id + +The stubdom must internally add /dev/xvdc to an fdset in QEMU with opaque set +to "stub-devid:$devid". libxl will lookup the fdset with that string. PV-GRUB =======
tools/libs/light/libxl_disk.c +361 -21
498 lines not on this page · raw message
Signature · 1 line
2.40.1
Quoted 13 lines · Jason Andryuk
tools/libs/light/libxl_disk.c +13
-0+static void cdrom_insert_stubdom_parse_fdset (libxl__egc *egc, +libxl__ev_qmp *qmp, +const libxl__json_object *response, +int rc) +{ +EGC_GC ; +libxl__cdrom_insert_state *cis =CONTAINER_OF (qmp, *cis, qmp); +int devid; +int fdset; + +if (rc) goto out; + +/* Only called for qemu-xen/linux stubdom. */
tools/libs/light/libxl_disk.c out: · line 1306
Quoted 10 lines
tools/libs/light/libxl_disk.c +10
-0+assert (cis->dm_ver ==LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN ); + + devid =libxl__device_disk_dev_number (cis->disk->vdev,NULL ,NULL ); + fdset =query_fdsets_find_fdset (gc, response, devid); +if (fdset ==ERROR_NOTFOUND ) { +/* Give the stubdom a little time before trying again. */ + rc =libxl__ev_time_register_rel (cis->ao, &cis->retry_timer, + cdrom_insert_stubdom_query_fdset, +200 ); +if (rc) goto out;
There's a missing "return;" here.
And looks like it's the only issue,
with that fixed: Reviewed-by: Anthony PERARD <[email protected]>
Quoted 5 lines
tools/libs/light/libxl_disk.c +5
-0+ }else if (fdset <0 ) { + rc = fdset; + goto out; + } +
tools/libs/light/libxl_disk.c out: · line 1321
Quoted 10 lines
tools/libs/light/libxl_disk.c +10
-0+ cis->stubdom_fdset = fdset; + +LOGD (DEBUG , cis->domid,"Found fdset %d" , cis->stubdom_fdset); +cdrom_insert_ejected (egc, &cis->qmp,NULL , rc); +return ; + + out: +cdrom_insert_done (egc, cis, rc);/* must be last */ +} +
Cheers,
Signature · 5 lines
Anthony Perard | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Quoted 19 lines · Anthony PERARD
Quoted 17 lines · Jason Andryuk
tools/libs/light/libxl_disk.c +17
-0+static void cdrom_insert_stubdom_parse_fdset (libxl__egc *egc, +libxl__ev_qmp *qmp, +const libxl__json_object *response, +int rc) +{ +EGC_GC ; +libxl__cdrom_insert_state *cis =CONTAINER_OF (qmp, *cis, qmp); +int devid; +int fdset; + +if (rc) goto out; + +/* Only called for qemu-xen/linux stubdom. */ +assert (cis->dm_ver ==LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN ); + + devid =libxl__device_disk_dev_number (cis->disk->vdev,NULL ,NULL ); + fdset =query_fdsets_find_fdset (gc, response, devid);
Quoted 8 lines
tools/libs/light/libxl_disk.c out: · line 1306
Quoted 6 lines
tools/libs/light/libxl_disk.c +6
-0+if (fdset ==ERROR_NOTFOUND ) { +/* Give the stubdom a little time before trying again. */ + rc =libxl__ev_time_register_rel (cis->ao, &cis->retry_timer, + cdrom_insert_stubdom_query_fdset, +200 ); +if (rc) goto out;There's a missing "return;" here.
Thank you for spotting that! Now I feel silly that I missed it. My quick testing yesterday succeeded, but it must not have needed a retry. So I did not notice. I have re-tested with your change and verified that retries happen properly - I see two 'query-fdsets' QMP commands sometimes.
Quoted 2 lines
And looks like it's the only issue,
with that fixed: Reviewed-by: Anthony PERARD <[email protected]>
Thanks,
Jason