mirror of https://gitee.com/openkylin/libvirt.git
virsh: sata support for virsh attach-disk --address
Adding sata bus address support to the optional address parameter of virsh attach-disk. The address is used as controller.bus.unit. e.g. sata:0.0.0 Signed-off-by: Han Han <hhan@redhat.com>
This commit is contained in:
parent
31cd4dd8e7
commit
e11515ef8d
|
@ -320,6 +320,7 @@ enum {
|
||||||
DISK_ADDR_TYPE_IDE,
|
DISK_ADDR_TYPE_IDE,
|
||||||
DISK_ADDR_TYPE_CCW,
|
DISK_ADDR_TYPE_CCW,
|
||||||
DISK_ADDR_TYPE_USB,
|
DISK_ADDR_TYPE_USB,
|
||||||
|
DISK_ADDR_TYPE_SATA,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PCIAddress {
|
struct PCIAddress {
|
||||||
|
@ -352,6 +353,12 @@ struct USBAddress {
|
||||||
unsigned int port;
|
unsigned int port;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SATAAddress {
|
||||||
|
unsigned int controller;
|
||||||
|
unsigned int bus;
|
||||||
|
unsigned long long unit;
|
||||||
|
};
|
||||||
|
|
||||||
struct DiskAddress {
|
struct DiskAddress {
|
||||||
int type;
|
int type;
|
||||||
union {
|
union {
|
||||||
|
@ -360,6 +367,7 @@ struct DiskAddress {
|
||||||
struct IDEAddress ide;
|
struct IDEAddress ide;
|
||||||
struct CCWAddress ccw;
|
struct CCWAddress ccw;
|
||||||
struct USBAddress usb;
|
struct USBAddress usb;
|
||||||
|
struct SATAAddress sata;
|
||||||
} addr;
|
} addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -488,11 +496,37 @@ static int str2USBAddress(const char *str, struct USBAddress *usbAddr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int str2SATAAddress(const char *str, struct SATAAddress *sataAddr)
|
||||||
|
{
|
||||||
|
char *controller, *bus, *unit;
|
||||||
|
|
||||||
|
if (!sataAddr)
|
||||||
|
return -1;
|
||||||
|
if (!str)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
controller = (char *)str;
|
||||||
|
|
||||||
|
if (virStrToLong_uip(controller, &bus, 10, &sataAddr->controller) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
bus++;
|
||||||
|
if (virStrToLong_uip(bus, &unit, 10, &sataAddr->bus) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
unit++;
|
||||||
|
if (virStrToLong_ullp(unit, NULL, 10, &sataAddr->unit) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* pci address pci:0000.00.0x0a.0 (domain:bus:slot:function)
|
/* pci address pci:0000.00.0x0a.0 (domain:bus:slot:function)
|
||||||
* ide disk address: ide:00.00.0 (controller:bus:unit)
|
* ide disk address: ide:00.00.0 (controller:bus:unit)
|
||||||
* scsi disk address: scsi:00.00.0 (controller:bus:unit)
|
* scsi disk address: scsi:00.00.0 (controller:bus:unit)
|
||||||
* ccw disk address: ccw:0xfe.0.0000 (cssid:ssid:devno)
|
* ccw disk address: ccw:0xfe.0.0000 (cssid:ssid:devno)
|
||||||
* usb disk address: usb:00.00 (bus:port)
|
* usb disk address: usb:00.00 (bus:port)
|
||||||
|
* sata disk address: sata:00.00.0 (controller:bus:unit)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr)
|
static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr)
|
||||||
|
@ -524,6 +558,9 @@ static int str2DiskAddress(const char *str, struct DiskAddress *diskAddr)
|
||||||
} else if (STREQLEN(type, "usb", addr - type)) {
|
} else if (STREQLEN(type, "usb", addr - type)) {
|
||||||
diskAddr->type = DISK_ADDR_TYPE_USB;
|
diskAddr->type = DISK_ADDR_TYPE_USB;
|
||||||
return str2USBAddress(addr + 1, &diskAddr->addr.usb);
|
return str2USBAddress(addr + 1, &diskAddr->addr.usb);
|
||||||
|
} else if (STREQLEN(type, "sata", addr - type)) {
|
||||||
|
diskAddr->type = DISK_ADDR_TYPE_SATA;
|
||||||
|
return str2SATAAddress(addr + 1, &diskAddr->addr.sata);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -684,8 +721,15 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
|
||||||
virBufferAsprintf(&buf,
|
virBufferAsprintf(&buf,
|
||||||
"<address type='usb' bus='%u' port='%u' />\n",
|
"<address type='usb' bus='%u' port='%u' />\n",
|
||||||
diskAddr.addr.usb.bus, diskAddr.addr.usb.port);
|
diskAddr.addr.usb.bus, diskAddr.addr.usb.port);
|
||||||
|
} else if (diskAddr.type == DISK_ADDR_TYPE_SATA) {
|
||||||
|
virBufferAsprintf(&buf,
|
||||||
|
"<address type='drive' controller='%u'"
|
||||||
|
" bus='%u' unit='%llu' />\n",
|
||||||
|
diskAddr.addr.sata.controller, diskAddr.addr.sata.bus,
|
||||||
|
diskAddr.addr.sata.unit);
|
||||||
} else {
|
} else {
|
||||||
vshError(ctl, "%s", _("expecting a scsi:00.00.00 or usb:00.00 address."));
|
vshError(ctl, "%s",
|
||||||
|
_("expecting a scsi:00.00.00 or usb:00.00 or sata:00.00.00 address."));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else if (STRPREFIX((const char *)target, "hd")) {
|
} else if (STRPREFIX((const char *)target, "hd")) {
|
||||||
|
|
|
@ -3061,9 +3061,10 @@ I<serial> is the serial of disk device. I<wwn> is the wwn of disk device.
|
||||||
I<rawio> indicates the disk needs rawio capability.
|
I<rawio> indicates the disk needs rawio capability.
|
||||||
I<address> is the address of disk device in the form of
|
I<address> is the address of disk device in the form of
|
||||||
pci:domain.bus.slot.function, scsi:controller.bus.unit,
|
pci:domain.bus.slot.function, scsi:controller.bus.unit,
|
||||||
ide:controller.bus.unit, usb:bus.port or ccw:cssid.ssid.devno. Virtio-ccw
|
ide:controller.bus.unit, usb:bus.port, sata:controller.bus.unit or
|
||||||
devices must have their cssid set to 0xfe. I<multifunction> indicates
|
ccw:cssid.ssid.devno. Virtio-ccw devices must have their cssid set to 0xfe.
|
||||||
specified pci address is a multifunction pci device address.
|
I<multifunction> indicates specified pci address is a multifunction pci device
|
||||||
|
address.
|
||||||
|
|
||||||
If I<--print-xml> is specified, then the XML of the disk that would be attached
|
If I<--print-xml> is specified, then the XML of the disk that would be attached
|
||||||
is printed instead.
|
is printed instead.
|
||||||
|
|
Loading…
Reference in New Issue