[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XEN PATCH 4/8] libxl: Use -device for cd-rom drives


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Date: Fri, 23 Apr 2021 17:15:54 +0100
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 23 Apr 2021 16:16:19 +0000
  • Ironport-hdrordr: A9a23:+qZ+da8YtjclBQLNrL5uk+FRcL1zdoIgy1knxilNYDRvWIixi9 2ukPMH1RX9lTYWXzUalcqdPbSbKEmwybdc2qNUGbu5RgHptC+TLI9k5Zb/2DGIIUfD38Zn/+ Nbf6B6YeeaMXFTh8z3+RT9Nt4mzsWO/qzAv5ak815GZ2hRGsJdxi1+DRuWFVAzYQFAC4YwGp b03Ls8mxOLf3MLYsOnQkQURuSrnayAqLvKQz4jQyQm5g6HkC+y5NfBfySw8x8CX1p0sNAf2E fflQiR3MSemtG9jiTRzmrCq6lR8eGRsudrIOyppowrJi73igCuDb4RFoGqmDwuuumg5BILvb D30nEdFv9+4X/QYW25yCGFs2aP7B8U53Dv0lOei3f4yPaJPQ4SMdZLho5Sb3Limigdlex8y6 5C0ia4sJdaHHr77UDAzuXITB1jmw6Ip2Mjm4co/hlieLYZAYUwkaUvuGduVLsQFiPz744qVM N0CtvH2fpQeVSGK1jEo2hG2rWXLzsONybDZnJHlt2e0jBQknw85VAf3tYjknAJ8494Y4VY5t 7DLr9jmNh1P4ErRJM4IN1Ebdq8C2TLTx6JGnmVO07bGKYOPG+IjJLr/rMv5qWPdIYTxJU/3L TNOWko9FIaSgbLM4mjzZdL+hfCTCGWRjL20PxT4JB/p/nyX7zuPSqfSE0/kseprvkFa/erGM qbCdZzObvOPGHuEYFG00nVQJ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DPk8G/7Fn/dGaxoD4OhVhiPKnsFf5yml9xsFjIYI1 gRSHDf/3LeJNqFaDAF2p7RR+QKk6odVgZu5+Uv1Fc6hL3I7Lk8OtKVpszpLhW2E1duknXuy5/U 44LgaUDnHMmw3OpQj7UGhG44JONhE87ZBCa3UMH+1C4I/5THSZJ2FGtgNrsP0pfcP4kohqRter Orw=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

This allows to set an `id` on the device instead of only the drive. We
are going to need the `id` with the "eject" and
"blockdev-change-media" QMP command as using `device` parameter on
those is deprecated. (`device` is the `id` of the `-drive` on the
command line).

We set the same `id` on both -device and -drive as QEMU doesn't
complain and we can then either do "eject id=$id" or "eject
device=$id".

Using "-drive + -device" instead of only "-drive" has been
available since at least QEMU 0.15, and seems to be the preferred way as it
separates the host part (-drive which describe the disk image location
and format) from the guest part (-device which describe the emulated
device). More information in qemu.git/docs/qdev-device-use.txt .

Changing the command line during migration for the cdrom seems fine.
Also the documentation about migration in QEMU explains that the device
state ID is "been formed from a bus name and device address", so
second IDE bus and first device address on bus is still thus and
doesn't matter if written "-drive if=ide,index=2" or "-drive
ide-cd,bus=ide.1,unit=0".
See qemu.git/docs/devel/migration.rst .

Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
 tools/libs/light/libxl_dm.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c
index 0a0c1ef7c62e..5b01cf284163 100644
--- a/tools/libs/light/libxl_dm.c
+++ b/tools/libs/light/libxl_dm.c
@@ -1913,6 +1913,7 @@ static int libxl__build_device_model_args_new(libxl__gc 
*gc,
             }
 
             if (disks[i].is_cdrom) {
+                const char *drive_id;
                 if (disk > 4) {
                     LOGD(WARN, guest_domid, "Emulated CDROM can be only one of 
the first 4 disks.\n"
                          "Disk %s will be available via PV drivers but not as 
an "
@@ -1920,13 +1921,22 @@ static int libxl__build_device_model_args_new(libxl__gc 
*gc,
                          disks[i].vdev);
                     continue;
                 }
-                drive = libxl__sprintf(gc,
-                         "if=ide,index=%d,readonly=on,media=cdrom,id=ide-%i",
-                         disk, dev_number);
+
+                drive_id = GCSPRINTF("ide-%i", dev_number);
+                drive = GCSPRINTF("if=none,readonly=on,id=%s", drive_id);
 
                 if (target_path)
                     drive = libxl__sprintf(gc, "%s,file=%s,format=%s",
                                            drive, target_path, format);
+
+                flexarray_vappend(dm_args,
+                    "-drive", drive,
+                    "-device",
+                    GCSPRINTF("ide-cd,id=%s,drive=%s,bus=ide.%u,unit=%u",
+                              drive_id, drive_id,
+                              disk / 2, disk % 2),
+                    NULL);
+                continue;
             } else {
                 /*
                  * Explicit sd disks are passed through as is.
-- 
Anthony PERARD




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.