From 7e157858b4b215090e9e1980e1ce1485a9641874 Mon Sep 17 00:00:00 2001 From: Yanbing Du Date: Tue, 1 Jul 2014 18:02:03 +0800 Subject: [PATCH] virsh: Allow attach-disk to specify disk target bus 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 Signed-off-by: Michal Privoznik --- tools/virsh-domain.c | 13 +++++++++++-- tools/virsh.pod | 18 +++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f55dae4bac..b1ab9117fd 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 = "targetbus", + .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, "targetbus", &targetbus) < 0 || vshCommandOptStringReq(ctl, cmd, "sourcetype", &stype) < 0) goto cleanup; @@ -590,7 +595,11 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) if (source) virBufferAsprintf(&buf, "\n", isFile ? "file" : "dev", source); - virBufferAsprintf(&buf, "\n", target); + virBufferAsprintf(&buf, "\n"); + if (mode) virBufferAsprintf(&buf, "<%s/>\n", mode); diff --git a/tools/virsh.pod b/tools/virsh.pod index b248c9a346..620ea369eb 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -2089,17 +2089,21 @@ B: using of partial device definition XML files may lead to unexpected results as some fields may be autogenerated and thus match devices other than expected. -=item B I I I -[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]] -[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>] +=item B I I I [[[I<--live>] [I<--config>] +| [I<--current>]] | [I<--persistent>]] [I<--targetbus 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>] Attach a new disk device to the domain. I is path for the files and devices. I controls the bus or device under which the disk is exposed to the guest OS. It indicates the -"logical" device name. I can be I, I or I for the Xen +"logical" device name; the optional I attribute specifies the type +of disk device to emulate; possible values are driver specific, with typical +values being I, I, I, I, I, I, or I, 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 can +be I, I or I for the Xen hypervisor depending on the kind of access; or I for the QEMU emulator. Further details to the driver can be passed using I. For Xen I can be I, while for QEMU subdriver should match the format -- GitLab