[PATCH] virsh: Allow attach-disk to specify disk target bus

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

 



From: Yanbing Du <ydu@xxxxxxxxxxxxxxxxxxxx>

By default, the bus type is inferred from the style of the device
name('target' in this command), e.g. a device named 'sda' will
typically be exported using a SCSI bus. Actually, not only SCSI bus,
but USB/SATA bus also use this kind of device name. So add '--bus'
option for attach-disk command to allow user specify the target bus.

Signed-off-by: Yanbing Du <ydu@xxxxxxxxxx>
---
 tools/virsh-domain.c | 14 ++++++++++++--
 tools/virsh.pod      |  9 +++++++--
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f55dae4..4488250 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -277,6 +277,10 @@ static const vshCmdOptDef opts_attach_disk[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("target of disk device")
     },
+    {.name = "bus",
+     .type = VSH_OT_STRING,
+     .help = N_("target bus of disk device")
+    },
     {.name = "driver",
      .type = VSH_OT_STRING,
      .help = N_("driver of disk device")
@@ -502,7 +506,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     const char *source = NULL, *target = NULL, *driver = NULL,
                 *subdriver = NULL, *type = NULL, *mode = NULL,
                 *cache = NULL, *serial = NULL, *straddr = NULL,
-                *wwn = NULL;
+                *wwn = NULL, *targetbus = NULL;
     struct DiskAddress diskAddr;
     bool isFile = false, functionReturn = false;
     int ret;
@@ -536,6 +540,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
         vshCommandOptStringReq(ctl, cmd, "serial", &serial) < 0 ||
         vshCommandOptStringReq(ctl, cmd, "wwn", &wwn) < 0 ||
         vshCommandOptStringReq(ctl, cmd, "address", &straddr) < 0 ||
+        vshCommandOptStringReq(ctl, cmd, "bus", &targetbus) < 0 ||
         vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0)
         goto cleanup;
 
@@ -590,7 +595,12 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     if (source)
         virBufferAsprintf(&buf, "<source %s='%s'/>\n",
                           isFile ? "file" : "dev", source);
-    virBufferAsprintf(&buf, "<target dev='%s'/>\n", target);
+    virBufferAsprintf(&buf, "<target dev='%s'", target);
+    if (targetbus) {
+        virBufferAsprintf(&buf, " bus='%s'", targetbus);
+    }
+    virBufferAddLit(&buf, "/>\n");
+
     if (mode)
         virBufferAsprintf(&buf, "<%s/>\n", mode);
 
diff --git a/tools/virsh.pod b/tools/virsh.pod
index b248c9a..3550825 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2091,7 +2091,7 @@ expected.
 
 =item B<attach-disk> I<domain> I<source> I<target>
 [[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]]
-[I<--driver driver>] [I<--subdriver subdriver>] [I<--cache cache>]
+[I<--bus>] [I<--driver driver>] [I<--subdriver subdriver>] [I<--cache cache>]
 [I<--type type>] [I<--mode mode>] [I<--sourcetype sourcetype>]
 [I<--serial serial>] [I<--wwn wwn>] [I<--rawio>]
 [I<--address address>] [I<--multifunction>] [I<--print-xml>]
@@ -2099,7 +2099,12 @@ expected.
 Attach a new disk device to the domain.
 I<source> is path for the files and devices. I<target> controls the bus or
 device under which the disk is exposed to the guest OS. It indicates the
-"logical" device name.  I<driver> can be I<file>, I<tap> or I<phy> for the Xen
+"logical" device name; the optional I<bus> attribute specifies the type of
+disk device to emulate; possible values are driver specific, with typical
+values being I<ide>, I<scsi>, I<virtio>, I<xen>, I<usb>, I<sata>, or I<sd>,
+if omitted, the bus type is inferred from the style of the device name (e.g.
+a device named 'sda' will typically be exported using a SCSI bus).
+I<driver> can be I<file>, I<tap> or I<phy> for the Xen
 hypervisor depending on the kind of access; or I<qemu> for the QEMU emulator.
 Further details to the driver can be passed using I<subdriver>. For Xen
 I<subdriver> can be I<aio>, while for QEMU subdriver should match the format
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]