[libvirt] [PATCH V2 3/7] libxl: support usb controller hotplug

2016-06-15 Thread Chunyan Liu
Support USB controller hot-plug and hot-unplug.

 #virsh attach-device dom usbctrl.xml
 #virsh detach-device dom usbctrl.xml
 usbctrl.xml example:
 

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 144 +++
 1 file changed, 144 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index f507265..f614769 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3006,6 +3006,60 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 
 #ifdef LIBXL_HAVE_PVUSB
 static int
+libxlDomainAttachControllerDevice(libxlDriverPrivatePtr driver,
+  virDomainObjPtr vm,
+  virDomainControllerDefPtr controller)
+{
+libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+const char *type = virDomainControllerTypeToString(controller->type);
+libxl_device_usbctrl usbctrl;
+int ret = -1;
+
+libxl_device_usbctrl_init();
+
+if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_USB) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+   _("'%s' controller cannot be hot plugged."),
+   type);
+goto cleanup;
+}
+
+if (controller->idx == -1)
+controller->idx = virDomainControllerFindUnusedIndex(vm->def,
+ controller->type);
+
+if (controller->opts.usbopts.ports == -1)
+controller->opts.usbopts.ports = 8;
+
+if (virDomainControllerFind(vm->def, controller->type, controller->idx) >= 
0) {
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("target %s:%d already exists"),
+   type, controller->idx);
+goto cleanup;
+}
+
+if (VIR_REALLOC_N(vm->def->controllers, vm->def->ncontrollers + 1) < 0)
+goto cleanup;
+
+if (libxlMakeUSBController(controller, ) < 0)
+goto cleanup;
+
+if (libxl_device_usbctrl_add(cfg->ctx, vm->def->id, , 0) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("libxenlight failed to attach USB controller"));
+goto cleanup;
+}
+
+virDomainControllerInsertPreAlloced(vm->def, controller);
+ret = 0;
+
+ cleanup:
+virObjectUnref(cfg);
+libxl_device_usbctrl_dispose();
+return ret;
+}
+
+static int
 libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr driver,
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
@@ -3240,6 +3294,12 @@ libxlDomainAttachDeviceLive(libxlDriverPrivatePtr driver,
 dev->data.disk = NULL;
 break;
 
+case VIR_DOMAIN_DEVICE_CONTROLLER:
+ret = libxlDomainAttachControllerDevice(driver, vm, 
dev->data.controller);
+if (!ret)
+dev->data.controller = NULL;
+break;
+
 case VIR_DOMAIN_DEVICE_NET:
 ret = libxlDomainAttachNetDevice(driver, vm,
  dev->data.net);
@@ -3270,6 +3330,7 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
 virDomainDiskDefPtr disk;
 virDomainNetDefPtr net;
 virDomainHostdevDefPtr hostdev;
+virDomainControllerDefPtr controller;
 virDomainHostdevDefPtr found;
 char mac[VIR_MAC_STRING_BUFLEN];
 
@@ -3287,6 +3348,21 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
 dev->data.disk = NULL;
 break;
 
+case VIR_DOMAIN_DEVICE_CONTROLLER:
+controller = dev->data.controller;
+if (controller->idx != -1 &&
+virDomainControllerFind(vmdef, controller->type,
+controller->idx) >= 0) {
+virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+   _("Target already exists"));
+return -1;
+}
+
+if (virDomainControllerInsert(vmdef, controller) < 0)
+return -1;
+dev->data.controller = NULL;
+break;
+
 case VIR_DOMAIN_DEVICE_NET:
 net = dev->data.net;
 if (virDomainHasNet(vmdef, net)) {
@@ -3425,6 +3501,57 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 
 #ifdef LIBXL_HAVE_PVUSB
 static int
+libxlDomainDetachControllerDevice(libxlDriverPrivatePtr driver,
+  virDomainObjPtr vm,
+  virDomainDeviceDefPtr dev)
+{
+int idx, ret = -1;
+virDomainControllerDefPtr detach = NULL;
+virDomainControllerDefPtr controller = dev->data.controller;
+const char *type = virDomainControllerType

[libvirt] [PATCH V2 4/7] libxl: check available controller and port when hotplugging USB device

2016-06-15 Thread Chunyan Liu
When hotplug a USB device, check if there is available controller
and port, if not, automatically create a USB controller of version
2.0 and 8 ports.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 32 
 1 file changed, 32 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index f614769..d9d7e3c 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3068,6 +3068,8 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr 
driver,
 libxl_device_usbdev usbdev;
 virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
 int ret = -1;
+size_t i;
+int ports = 0, usbdevs = 0;
 
 libxl_device_usbdev_init();
 
@@ -3075,6 +3077,36 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr 
driver,
 hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
 goto cleanup;
 
+/* search for available controller:port */
+for (i = 0; i < vm->def->ncontrollers; i++)
+ports += vm->def->controllers[i]->opts.usbopts.ports;
+
+for (i = 0; i < vm->def->nhostdevs; i++) {
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
+usbdevs++;
+}
+
+if (ports <= usbdevs) {
+/* no free ports, we will create a new usb controller */
+virDomainControllerDefPtr controller;
+
+if (!(controller = 
virDomainControllerDefNew(VIR_DOMAIN_CONTROLLER_TYPE_USB)))
+goto cleanup;
+
+controller->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2;
+controller->idx = -1;
+controller->opts.usbopts.ports = 8;
+
+if (libxlDomainAttachControllerDevice(driver, vm, controller) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("No available USB controller and port, and "
+ "failed to attach a new USB controller"));
+virDomainControllerDefFree(controller);
+goto cleanup;
+}
+}
+
 if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
 goto cleanup;
 
-- 
2.1.4

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


[libvirt] [PATCH V2 5/7] xenconfig: add conversion of usb controller config to and from xml

2016-06-15 Thread Chunyan Liu
Signed-off-by: Chunyan Liu <cy...@suse.com>
---
Changes:
  drop pvusb1 and pvusb2 models

 src/xenconfig/xen_xl.c | 190 +
 1 file changed, 190 insertions(+)

diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
index 5879c66..90213ec 100644
--- a/src/xenconfig/xen_xl.c
+++ b/src/xenconfig/xen_xl.c
@@ -503,6 +503,110 @@ xenParseXLInputDevs(virConfPtr conf, virDomainDefPtr def)
 }
 
 static int
+xenParseXLUSBController(virConfPtr conf, virDomainDefPtr def)
+{
+virConfValuePtr list = virConfGetValue(conf, "usbctrl");
+virDomainControllerDefPtr controller = NULL;
+
+if (list && list->type == VIR_CONF_LIST) {
+list = list->list;
+while (list) {
+char type[8];
+char version[4];
+char ports[4];
+char *key;
+int usbctrl_version = 2; /* by default USB 2.0 */
+int usbctrl_ports = 8; /* by default 8 ports */
+int usbctrl_type = -1;
+
+type[0] = version[0] = ports[0] = '\0';
+
+if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
+goto skipusbctrl;
+/* usbctrl=['type=pv,version=2,ports=8'] */
+key = list->str;
+while (key) {
+char *data;
+char *nextkey = strchr(key, ',');
+
+if (!(data = strchr(key, '=')))
+goto skipusbctrl;
+data++;
+
+if (STRPREFIX(key, "type=")) {
+int len = nextkey ? (nextkey - data) : sizeof(type) - 1;
+if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("type %s invalid"),
+   data);
+goto skipusbctrl;
+}
+} else if (STRPREFIX(key, "version=")) {
+int len = nextkey ? (nextkey - data) : sizeof(version) - 1;
+if (virStrncpy(version, data, len, sizeof(version)) == 
NULL) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("version %s invalid"),
+   data);
+goto skipusbctrl;
+}
+if (virStrToLong_i(version, NULL, 16, _version) < 
0)
+goto skipusbctrl;
+} else if (STRPREFIX(key, "ports=")) {
+int len = nextkey ? (nextkey - data) : sizeof(ports) - 1;
+if (virStrncpy(ports, data, len, sizeof(ports)) == NULL) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("version %s invalid"),
+   data);
+goto skipusbctrl;
+}
+if (virStrToLong_i(ports, NULL, 16, _ports) < 0)
+goto skipusbctrl;
+}
+
+while (nextkey && (nextkey[0] == ',' ||
+   nextkey[0] == ' ' ||
+   nextkey[0] == '\t'))
+nextkey++;
+key = nextkey;
+}
+
+if (type[0] == '\0') {
+if (usbctrl_version == 1)
+usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1;
+else
+usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2;
+} else {
+if (STREQLEN(type, "qusb", 4)) {
+if (usbctrl_version == 1)
+usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1;
+else
+usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2;
+} else {
+goto skipusbctrl;
+}
+}
+
+if (!(controller = 
virDomainControllerDefNew(VIR_DOMAIN_CONTROLLER_TYPE_USB)))
+return -1;
+
+controller->type = VIR_DOMAIN_CONTROLLER_TYPE_USB;
+controller->model = usbctrl_type;
+controller->opts.usbopts.ports = usbctrl_ports;
+
+if (VIR_APPEND_ELEMENT(def->controllers, def->ncontrollers, 
controller) < 0) {
+virDomainControllerDefFree(controller);
+return -1;
+}
+
+skipusbctrl:
+list = list->next;
+}
+}
+
+return 0;
+}
+
+static int
 xenParseXLUSB(virConfPtr conf, virDomainDefPtr def)
 {
 virConfValuePtr list = virConfGetValue(conf, "usbdev");
@@ -612,6 +716,9 @@ xenParseXL(virConfPtr conf,
 if (xenParseXLUSB(conf, def) < 0)
 goto c

[libvirt] [PATCH V2 6/7] xlconfigtest: add test for usb controller conversion

2016-06-15 Thread Chunyan Liu
Signed-off-by: Chunyan Liu <cy...@suse.com>
---
Changes:
  drop pvusb items

 tests/xlconfigdata/test-usbctrl.cfg | 13 +
 tests/xlconfigdata/test-usbctrl.xml | 31 +++
 tests/xlconfigtest.c|  1 +
 3 files changed, 45 insertions(+)
 create mode 100644 tests/xlconfigdata/test-usbctrl.cfg
 create mode 100644 tests/xlconfigdata/test-usbctrl.xml

diff --git a/tests/xlconfigdata/test-usbctrl.cfg 
b/tests/xlconfigdata/test-usbctrl.cfg
new file mode 100644
index 000..91e9460
--- /dev/null
+++ b/tests/xlconfigdata/test-usbctrl.cfg
@@ -0,0 +1,13 @@
+name = "XenGuest1"
+uuid = "45b60f51-88a9-47a8-a3b3-5e66d71b2283"
+maxmem = 512
+memory = 512
+vcpus = 1
+localtime = 0
+on_poweroff = "preserve"
+on_reboot = "restart"
+on_crash = "preserve"
+vif = [ "mac=5a:36:0e:be:00:09" ]
+bootloader = "/usr/bin/pygrub"
+disk = [ 
"format=qcow2,vdev=xvda,access=rw,backendtype=qdisk,target=/var/lib/xen/images/debian/disk.qcow2"
 ]
+usbctrl = [ "type=qusb,version=2,ports=6" ]
diff --git a/tests/xlconfigdata/test-usbctrl.xml 
b/tests/xlconfigdata/test-usbctrl.xml
new file mode 100644
index 000..3c03f37
--- /dev/null
+++ b/tests/xlconfigdata/test-usbctrl.xml
@@ -0,0 +1,31 @@
+
+  XenGuest1
+  45b60f51-88a9-47a8-a3b3-5e66d71b2283
+  524288
+  524288
+  1
+  /usr/bin/pygrub
+  
+linux
+  
+  
+  preserve
+  restart
+  preserve
+  
+
+  
+  
+  
+
+
+
+  
+
+
+  
+
+
+
+  
+
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index 4248da1..401e560 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -278,6 +278,7 @@ mymain(void)
 #endif
 DO_TEST("vif-typename");
 DO_TEST("usb");
+DO_TEST("usbctrl");
 
 virObjectUnref(caps);
 virObjectUnref(xmlopt);
-- 
2.1.4

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


[libvirt] [PATCH V2 2/7] libxl: support USB controllers in creation time

2016-06-15 Thread Chunyan Liu
To support USB Controller in xen guest domains, just add
USB controller in domain config xml as following:


Signed-off-by: Chunyan Liu <cy...@suse.com>
---
Changes:
  drop pvusb1 and pvusb2 models

 src/libxl/libxl_conf.c | 84 ++
 src/libxl/libxl_conf.h |  4 +++
 2 files changed, 88 insertions(+)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 5989819..a7d91d3 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1516,6 +1516,87 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
 
 #ifdef LIBXL_HAVE_PVUSB
 int
+libxlMakeUSBController(virDomainControllerDefPtr controller,
+   libxl_device_usbctrl *usbctrl)
+{
+usbctrl->devid = controller->idx;
+
+if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_USB)
+return -1;
+
+if (controller->model == -1) {
+usbctrl->version = 2;
+usbctrl->type = LIBXL_USBCTRL_TYPE_QUSB;
+} else {
+switch (controller->model) {
+case VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1:
+usbctrl->version = 1;
+usbctrl->type = LIBXL_USBCTRL_TYPE_QUSB;
+break;
+
+case VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2:
+usbctrl->version = 2;
+usbctrl->type = LIBXL_USBCTRL_TYPE_QUSB;
+break;
+
+default:
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("unsupported usb model"));
+return -1;
+}
+}
+
+if (controller->opts.usbopts.ports == -1)
+usbctrl->ports = 8;
+else
+usbctrl->ports = controller->opts.usbopts.ports;
+
+return 0;
+}
+
+static int
+libxlMakeUSBControllerList(virDomainDefPtr def, libxl_domain_config *d_config)
+{
+virDomainControllerDefPtr *l_controllers = def->controllers;
+size_t ncontrollers = def->ncontrollers;
+size_t nusbctrls = 0;
+libxl_device_usbctrl *x_usbctrls;
+size_t i;
+
+if (ncontrollers == 0)
+return 0;
+
+if (VIR_ALLOC_N(x_usbctrls, ncontrollers) < 0)
+return -1;
+
+for (i = 0; i < ncontrollers; i++) {
+if (l_controllers[i]->type != VIR_DOMAIN_CONTROLLER_TYPE_USB)
+continue;
+
+libxl_device_usbctrl_init(_usbctrls[nusbctrls]);
+
+if (libxlMakeUSBController(l_controllers[i],
+   _usbctrls[nusbctrls]) < 0)
+goto error;
+
+nusbctrls++;
+}
+
+VIR_SHRINK_N(x_usbctrls, ncontrollers, ncontrollers - nusbctrls);
+d_config->usbctrls = x_usbctrls;
+d_config->num_usbctrls = nusbctrls;
+
+return 0;
+
+ error:
+for (i = 0; i < nusbctrls; i++)
+libxl_device_usbctrl_dispose(_usbctrls[i]);
+
+VIR_FREE(x_usbctrls);
+return -1;
+}
+
+int
 libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev)
 {
 virDomainHostdevSubsysUSBPtr usbsrc = >source.subsys.u.usb;
@@ -1787,6 +1868,9 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
 return -1;
 
 #ifdef LIBXL_HAVE_PVUSB
+if (libxlMakeUSBControllerList(def, d_config) < 0)
+return -1;
+
 if (libxlMakeUSBList(def, d_config) < 0)
 return -1;
 #endif
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index 8cb2b14..ed5a3de 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -186,6 +186,10 @@ libxlMakePCI(virDomainHostdevDefPtr hostdev, 
libxl_device_pci *pcidev);
 
 # ifdef LIBXL_HAVE_PVUSB
 int
+libxlMakeUSBController(virDomainControllerDefPtr controller,
+   libxl_device_usbctrl *usbctrl);
+
+int
 libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev);
 # endif
 
-- 
2.1.4

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


[libvirt] [PATCH V2 1/7] extend usb controller model to support xen pvusb

2016-06-15 Thread Chunyan Liu
According to libxl implementation, it supports pvusb
controller of version 1.1 and version 2.0, and it
supports two types of backend, 'pvusb' (dom0 backend)
and 'qusb' (qemu backend). But currently pvusb backend
is not checked in yet.

To match libxl support, extend usb controller schema
to support two more models: qusb1 (qusb, version 1.1)
and 'qusb2' (qusb version 2.0).

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
Changes:
  drop pvusb1 and pvusb2 definition

 docs/formatdomain.html.in | 4 +++-
 docs/schemas/domaincommon.rng | 2 ++
 src/conf/domain_conf.c| 2 ++
 src/conf/domain_conf.h| 2 ++
 src/qemu/qemu_command.c   | 2 ++
 5 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 82b6aae..b778705 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3075,7 +3075,9 @@
 A usb controller has an optional attribute
 model, which is one of "piix3-uhci", "piix4-uhci",
 "ehci", "ich9-ehci1", "ich9-uhci1", "ich9-uhci2", "ich9-uhci3",
-"vt82c686b-uhci", "pci-ohci" or "nec-xhci".  Additionally,
+"vt82c686b-uhci", "pci-ohci", "nec-xhci", "qusb1" (xen pvusb
+with qemu backend, version 1.1) or "qusb2" (xen pvusb with qemu
+backend, version 2.0). Additionally,
  since 0.10.0, if the USB bus needs to
  be explicitly disabled for the guest, model='none'
  may be used.  Since 1.0.5, no default
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 2e07505..311c1bf 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1780,6 +1780,8 @@
   pci-ohci
   nec-xhci
   none
+  qusb1
+  qusb2
 
   
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9504e5f..5fb18cc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -356,6 +356,8 @@ VIR_ENUM_IMPL(virDomainControllerModelUSB, 
VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST,
   "vt82c686b-uhci",
   "pci-ohci",
   "nec-xhci",
+  "qusb1",
+  "qusb2",
   "none")
 
 VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 15f9c80..4c9e1e3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -685,6 +685,8 @@ typedef enum {
 VIR_DOMAIN_CONTROLLER_MODEL_USB_VT82C686B_UHCI,
 VIR_DOMAIN_CONTROLLER_MODEL_USB_PCI_OHCI,
 VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI,
+VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1,
+VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2,
 VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE,
 
 VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 48be399..1998384 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -133,6 +133,8 @@ VIR_ENUM_IMPL(qemuControllerModelUSB, 
VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST,
   "vt82c686b-usb-uhci",
   "pci-ohci",
   "nec-usb-xhci",
+  "qusb1",
+  "qusb2",
   "none");
 
 VIR_ENUM_DECL(qemuDomainFSDriver)
-- 
2.1.4

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


[libvirt] [PATCH V2 0/7] libxl: add support of pvusb controller

2016-06-15 Thread Chunyan Liu
This patch series is to add pvusb controller support in libxl driver.
It should be applied on previous pvusb device support patch series.

---
Changes:
  * drop pvusb1 and pvusb2 model
  * add check in qemu device post-parse to report error of
unsupported 'qusb1' and 'qusb2' model

Chunyan Liu (7):
  extend usb controller model to support xen pvusb
  libxl: support USB controllers in creation time
  libxl: support usb controller hotplug
  libxl: check available controller and port when hotplugging USB device
  xenconfig: add conversion of usb controller config to and from xml
  xlconfigtest: add test for usb controller conversion
  qemuDomainDeviceDefPostParse: add USB controller model check

 docs/formatdomain.html.in   |   4 +-
 docs/schemas/domaincommon.rng   |   2 +
 src/conf/domain_conf.c  |   2 +
 src/conf/domain_conf.h  |   2 +
 src/libxl/libxl_conf.c  |  84 
 src/libxl/libxl_conf.h  |   4 +
 src/libxl/libxl_driver.c| 176 +
 src/qemu/qemu_command.c |   2 +
 src/qemu/qemu_domain.c  |  13 +++
 src/xenconfig/xen_xl.c  | 190 
 tests/xlconfigdata/test-usbctrl.cfg |  13 +++
 tests/xlconfigdata/test-usbctrl.xml |  31 ++
 tests/xlconfigtest.c|   1 +
 13 files changed, 523 insertions(+), 1 deletion(-)
 create mode 100644 tests/xlconfigdata/test-usbctrl.cfg
 create mode 100644 tests/xlconfigdata/test-usbctrl.xml

-- 
2.1.4

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


[libvirt] [PATCH V2 7/7] qemuDomainDeviceDefPostParse: add USB controller model check

2016-06-15 Thread Chunyan Liu
To sync with virDomainControllerModelUSB, we add two models
in qemuControllerModelUSB 'qusb1' and 'qusb2', but those
models are not supported in qemu driver. So add check in
device post parse to report errors if 'qusb1' and 'qusb2'
are specified.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/qemu/qemu_domain.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index d1f8175..ed72393 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2301,6 +2301,19 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 ARCH_IS_S390(def->os.arch))
 dev->data.controller->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE;
 
+/* forbid usb model 'qusb1' and 'qusb2' in this kind of hyperviosr */
+if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER &&
+dev->data.controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
+(dev->data.controller->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1 
||
+ dev->data.controller->model == 
VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("USB controller model type 'qusb1' or 'qusb2' "
+ "is not supported in %s"),
+   virDomainVirtTypeToString(def->virtType));
+goto cleanup;
+}
+
+
 /* set the default SCSI controller model for S390 arches */
 if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER &&
 dev->data.controller->type == VIR_DOMAIN_CONTROLLER_TYPE_SCSI &&
-- 
2.1.4

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


[libvirt] [PATCH 1/6] extend usb controller model to support xen pvusb

2016-06-12 Thread Chunyan Liu
According to libxl implementation, it supports pvusb
controller of version 1.1 and version 2.0, and it
supports two types of backend, 'pvusb' (dom0 backend)
and 'qusb' (qemu backend).

To match libxl support, extend usb controller schema
to support more models: pvusb1 (pvusb, version 1.1),
pvusb2 (pvusb, version 2.0), qusb1 (qusb, version 1.1)
and 'qusb2' (qusb version 2.0).

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 docs/formatdomain.html.in | 6 +-
 docs/schemas/domaincommon.rng | 4 
 src/conf/domain_conf.c| 4 
 src/conf/domain_conf.h| 4 
 src/qemu/qemu_command.c   | 4 
 5 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index fb3ec5e..1492915 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3063,7 +3063,11 @@
 A usb controller has an optional attribute
 model, which is one of "piix3-uhci", "piix4-uhci",
 "ehci", "ich9-ehci1", "ich9-uhci1", "ich9-uhci2", "ich9-uhci3",
-"vt82c686b-uhci", "pci-ohci" or "nec-xhci".  Additionally,
+"vt82c686b-uhci", "pci-ohci", "nec-xhci", "pvusb1" (xen pvusb
+with dom0 backend, version 1.1), "pvusb2" (xen pvusb with dom0
+backend, version 2.0), "qusb1" (xen pvusb with qemu backend,
+version 1.1) or "qusb2" (xen pvusb with qemu backend, version 2.0).
+Additionally,
  since 0.10.0, if the USB bus needs to
  be explicitly disabled for the guest, model='none'
  may be used.  Since 1.0.5, no default
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 02078d7..5afa15d 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1768,6 +1768,10 @@
   pci-ohci
   nec-xhci
   none
+  pvusb1
+  pvusb2
+  qusb1
+  qusb2
 
   
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 10e61da..ff3285f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -356,6 +356,10 @@ VIR_ENUM_IMPL(virDomainControllerModelUSB, 
VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST,
   "vt82c686b-uhci",
   "pci-ohci",
   "nec-xhci",
+  "pvusb1",
+  "pvusb2",
+  "qusb1",
+  "qusb2",
   "none")
 
 VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 3792562..6733b2d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -675,6 +675,10 @@ typedef enum {
 VIR_DOMAIN_CONTROLLER_MODEL_USB_VT82C686B_UHCI,
 VIR_DOMAIN_CONTROLLER_MODEL_USB_PCI_OHCI,
 VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI,
+VIR_DOMAIN_CONTROLLER_MODEL_USB_PVUSB1,
+VIR_DOMAIN_CONTROLLER_MODEL_USB_PVUSB2,
+VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1,
+VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2,
 VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE,
 
 VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 490260f..5c3de83 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -133,6 +133,10 @@ VIR_ENUM_IMPL(qemuControllerModelUSB, 
VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST,
   "vt82c686b-usb-uhci",
   "pci-ohci",
   "nec-usb-xhci",
+  "pvusb1",
+  "pvusb2",
+  "qusb1",
+  "qusb2",
   "none");
 
 VIR_ENUM_DECL(qemuDomainFSDriver)
-- 
2.1.4

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


[libvirt] [PATCH 3/6] libxl: support usb controller hotplug

2016-06-12 Thread Chunyan Liu
Support USB controller hot-plug and hot-unplug.

 #virsh attach-device dom usbctrl.xml
 #virsh detach-device dom usbctrl.xml
 usbctrl.xml example:
 

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 144 +++
 1 file changed, 144 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 069616f..d1dd160 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3029,6 +3029,60 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 
 #ifdef LIBXL_HAVE_PVUSB
 static int
+libxlDomainAttachControllerDevice(libxlDriverPrivatePtr driver,
+  virDomainObjPtr vm,
+  virDomainControllerDefPtr controller)
+{
+libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+const char *type = virDomainControllerTypeToString(controller->type);
+libxl_device_usbctrl usbctrl;
+int ret = -1;
+
+libxl_device_usbctrl_init();
+
+if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_USB) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+   _("'%s' controller cannot be hot plugged."),
+   type);
+goto cleanup;
+}
+
+if (controller->idx == -1)
+controller->idx = virDomainControllerFindUnusedIndex(vm->def,
+ controller->type);
+
+if (controller->opts.usbopts.ports == -1)
+controller->opts.usbopts.ports = 8;
+
+if (virDomainControllerFind(vm->def, controller->type, controller->idx) >= 
0) {
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("target %s:%d already exists"),
+   type, controller->idx);
+goto cleanup;
+}
+
+if (VIR_REALLOC_N(vm->def->controllers, vm->def->ncontrollers + 1) < 0)
+goto cleanup;
+
+if (libxlMakeUSBController(controller, ) < 0)
+goto cleanup;
+
+if (libxl_device_usbctrl_add(cfg->ctx, vm->def->id, , 0) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("libxenlight failed to attach USB controller"));
+goto cleanup;
+}
+
+virDomainControllerInsertPreAlloced(vm->def, controller);
+ret = 0;
+
+ cleanup:
+virObjectUnref(cfg);
+libxl_device_usbctrl_dispose();
+return ret;
+}
+
+static int
 libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr driver,
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
@@ -3263,6 +3317,12 @@ libxlDomainAttachDeviceLive(libxlDriverPrivatePtr driver,
 dev->data.disk = NULL;
 break;
 
+case VIR_DOMAIN_DEVICE_CONTROLLER:
+ret = libxlDomainAttachControllerDevice(driver, vm, 
dev->data.controller);
+if (!ret)
+dev->data.controller = NULL;
+break;
+
 case VIR_DOMAIN_DEVICE_NET:
 ret = libxlDomainAttachNetDevice(driver, vm,
  dev->data.net);
@@ -3293,6 +3353,7 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
 virDomainDiskDefPtr disk;
 virDomainNetDefPtr net;
 virDomainHostdevDefPtr hostdev;
+virDomainControllerDefPtr controller;
 virDomainHostdevDefPtr found;
 char mac[VIR_MAC_STRING_BUFLEN];
 
@@ -3310,6 +3371,21 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
 dev->data.disk = NULL;
 break;
 
+case VIR_DOMAIN_DEVICE_CONTROLLER:
+controller = dev->data.controller;
+if (controller->idx != -1 &&
+virDomainControllerFind(vmdef, controller->type,
+controller->idx) >= 0) {
+virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+   _("Target already exists"));
+return -1;
+}
+
+if (virDomainControllerInsert(vmdef, controller) < 0)
+return -1;
+dev->data.controller = NULL;
+break;
+
 case VIR_DOMAIN_DEVICE_NET:
 net = dev->data.net;
 if (virDomainHasNet(vmdef, net)) {
@@ -3455,6 +3531,57 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 
 #ifdef LIBXL_HAVE_PVUSB
 static int
+libxlDomainDetachControllerDevice(libxlDriverPrivatePtr driver,
+  virDomainObjPtr vm,
+  virDomainDeviceDefPtr dev)
+{
+int idx, ret = -1;
+virDomainControllerDefPtr detach = NULL;
+virDomainControllerDefPtr controller = dev->data.controller;
+const char *type = virDomainControllerType

[libvirt] [PATCH 5/6] xenconfig: add conversion of usb controller config to and from xml

2016-06-12 Thread Chunyan Liu
Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/xenconfig/xen_xl.c | 203 +
 1 file changed, 203 insertions(+)

diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
index c11cd1b..36d352c 100644
--- a/src/xenconfig/xen_xl.c
+++ b/src/xenconfig/xen_xl.c
@@ -486,6 +486,115 @@ xenParseXLInputDevs(virConfPtr conf, virDomainDefPtr def)
 }
 
 static int
+xenParseXLUSBController(virConfPtr conf, virDomainDefPtr def)
+{
+virConfValuePtr list = virConfGetValue(conf, "usbctrl");
+virDomainControllerDefPtr controller = NULL;
+
+if (list && list->type == VIR_CONF_LIST) {
+list = list->list;
+while (list) {
+char type[8];
+char version[4];
+char ports[4];
+char *key;
+int usbctrl_version = 2; /* by default USB 2.0 */
+int usbctrl_ports = 8; /* by default 8 ports */
+int usbctrl_type = -1;
+
+type[0] = version[0] = ports[0] = '\0';
+
+if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
+goto skipusbctrl;
+/* usbctrl=['type=pv,version=2,ports=8'] */
+key = list->str;
+while (key) {
+char *data;
+char *nextkey = strchr(key, ',');
+
+if (!(data = strchr(key, '=')))
+goto skipusbctrl;
+data++;
+
+if (STRPREFIX(key, "type=")) {
+int len = nextkey ? (nextkey - data) : sizeof(type) - 1;
+if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("type %s invalid"),
+   data);
+goto skipusbctrl;
+}
+} else if (STRPREFIX(key, "version=")) {
+int len = nextkey ? (nextkey - data) : sizeof(version) - 1;
+if (virStrncpy(version, data, len, sizeof(version)) == 
NULL) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("version %s invalid"),
+   data);
+goto skipusbctrl;
+}
+if (virStrToLong_i(version, NULL, 16, _version) < 
0)
+goto skipusbctrl;
+} else if (STRPREFIX(key, "ports=")) {
+int len = nextkey ? (nextkey - data) : sizeof(ports) - 1;
+if (virStrncpy(ports, data, len, sizeof(ports)) == NULL) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("version %s invalid"),
+   data);
+goto skipusbctrl;
+}
+if (virStrToLong_i(ports, NULL, 16, _ports) < 0)
+goto skipusbctrl;
+}
+
+while (nextkey && (nextkey[0] == ',' ||
+   nextkey[0] == ' ' ||
+   nextkey[0] == '\t'))
+nextkey++;
+key = nextkey;
+}
+
+if (type[0] == '\0') {
+if (usbctrl_version == 1)
+usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1;
+else
+usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2;
+} else {
+if (STREQLEN(type, "pv", 2)) {
+if (usbctrl_version == 1)
+usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_PVUSB1;
+else
+usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_PVUSB2;
+} else if (STREQLEN(type, "qusb", 4)) {
+if (usbctrl_version == 1)
+usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1;
+else
+usbctrl_type = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2;
+} else {
+goto skipusbctrl;
+}
+}
+
+if (!(controller = 
virDomainControllerDefNew(VIR_DOMAIN_CONTROLLER_TYPE_USB)))
+return -1;
+
+controller->type = VIR_DOMAIN_CONTROLLER_TYPE_USB;
+controller->model = usbctrl_type;
+controller->opts.usbopts.ports = usbctrl_ports;
+
+if (VIR_APPEND_ELEMENT(def->controllers, def->ncontrollers, 
controller) < 0) {
+virDomainControllerDefFree(controller);
+return -1;
+}
+
+skipusbctrl:
+list = list->next;
+}
+}
+
+return 0;
+}
+
+stat

[libvirt] [PATCH 0/6] libxl: add support of pvusb controller

2016-06-12 Thread Chunyan Liu
This patch series is to add pvusb controller support in libxl driver.
It should be applied on previous pvusb device support patch series.

Chunyan Liu (6):
  extend usb controller model to support xen pvusb
  libxl: support USB controllers in creation time
  libxl: support usb controller hotplug
  libxl: check available controller and port when hotplugging USB device
  xenconfig: add conversion of usb controller config to and from xml
  xlconfigtest: add test for usb controller conversion

 docs/formatdomain.html.in   |   6 +-
 docs/schemas/domaincommon.rng   |   4 +
 src/conf/domain_conf.c  |   4 +
 src/conf/domain_conf.h  |   4 +
 src/libxl/libxl_conf.c  |  94 +
 src/libxl/libxl_conf.h  |   4 +
 src/libxl/libxl_driver.c| 176 +++
 src/qemu/qemu_command.c |   4 +
 src/xenconfig/xen_xl.c  | 203 
 tests/xlconfigdata/test-usbctrl.cfg |  13 +++
 tests/xlconfigdata/test-usbctrl.xml |  32 ++
 tests/xlconfigtest.c|   1 +
 12 files changed, 544 insertions(+), 1 deletion(-)
 create mode 100644 tests/xlconfigdata/test-usbctrl.cfg
 create mode 100644 tests/xlconfigdata/test-usbctrl.xml

-- 
2.1.4

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


[libvirt] [PATCH 6/6] xlconfigtest: add test for usb controller conversion

2016-06-12 Thread Chunyan Liu
Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 tests/xlconfigdata/test-usbctrl.cfg | 13 +
 tests/xlconfigdata/test-usbctrl.xml | 32 
 tests/xlconfigtest.c|  1 +
 3 files changed, 46 insertions(+)
 create mode 100644 tests/xlconfigdata/test-usbctrl.cfg
 create mode 100644 tests/xlconfigdata/test-usbctrl.xml

diff --git a/tests/xlconfigdata/test-usbctrl.cfg 
b/tests/xlconfigdata/test-usbctrl.cfg
new file mode 100644
index 000..319d493
--- /dev/null
+++ b/tests/xlconfigdata/test-usbctrl.cfg
@@ -0,0 +1,13 @@
+name = "XenGuest1"
+uuid = "45b60f51-88a9-47a8-a3b3-5e66d71b2283"
+maxmem = 512
+memory = 512
+vcpus = 1
+localtime = 0
+on_poweroff = "preserve"
+on_reboot = "restart"
+on_crash = "preserve"
+vif = [ "mac=5a:36:0e:be:00:09" ]
+bootloader = "/usr/bin/pygrub"
+disk = [ 
"format=qcow2,vdev=xvda,access=rw,backendtype=qdisk,target=/var/lib/xen/images/debian/disk.qcow2"
 ]
+usbctrl = [ "type=pv,version=1,ports=4", "type=qusb,version=2,ports=6" ]
diff --git a/tests/xlconfigdata/test-usbctrl.xml 
b/tests/xlconfigdata/test-usbctrl.xml
new file mode 100644
index 000..55dd0e0
--- /dev/null
+++ b/tests/xlconfigdata/test-usbctrl.xml
@@ -0,0 +1,32 @@
+
+  XenGuest1
+  45b60f51-88a9-47a8-a3b3-5e66d71b2283
+  524288
+  524288
+  1
+  /usr/bin/pygrub
+  
+linux
+  
+  
+  preserve
+  restart
+  preserve
+  
+
+  
+  
+  
+
+
+
+
+  
+
+
+  
+
+
+
+  
+
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index c5e2252..4c4ebf2 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -230,6 +230,7 @@ mymain(void)
 #endif
 DO_TEST("vif-typename");
 DO_TEST("usb");
+DO_TEST("usbctrl");
 
 virObjectUnref(caps);
 virObjectUnref(xmlopt);
-- 
2.1.4

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


[libvirt] [PATCH 4/6] libxl: check available controller and port when hotplugging USB device

2016-06-12 Thread Chunyan Liu
When hotplug a USB device, check if there is available controller
and port, if not, automatically create a USB controller of version
2.0 and 8 ports.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 32 
 1 file changed, 32 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index d1dd160..d95aa8d 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3091,6 +3091,8 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr 
driver,
 libxl_device_usbdev usbdev;
 virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
 int ret = -1;
+size_t i;
+int ports = 0, usbdevs = 0;
 
 libxl_device_usbdev_init();
 
@@ -3098,6 +3100,36 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr 
driver,
 hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
 goto cleanup;
 
+/* search for available controller:port */
+for (i = 0; i < vm->def->ncontrollers; i++)
+ports += vm->def->controllers[i]->opts.usbopts.ports;
+
+for (i = 0; i < vm->def->nhostdevs; i++) {
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
+usbdevs++;
+}
+
+if (ports <= usbdevs) {
+/* no free ports, we will create a new usb controller */
+virDomainControllerDefPtr controller;
+
+if (!(controller = 
virDomainControllerDefNew(VIR_DOMAIN_CONTROLLER_TYPE_USB)))
+goto cleanup;
+
+controller->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2;
+controller->idx = -1;
+controller->opts.usbopts.ports = 8;
+
+if (libxlDomainAttachControllerDevice(driver, vm, controller) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("No available USB controller and port, and "
+ "failed to attach a new USB controller"));
+virDomainControllerDefFree(controller);
+goto cleanup;
+}
+}
+
 if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
 goto cleanup;
 
-- 
2.1.4

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


[libvirt] [PATCH 2/6] libxl: support USB controllers in creation time

2016-06-12 Thread Chunyan Liu
To support USB Controller in xen guest domains, just add
USB controller in domain config xml as following:


Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_conf.c | 94 ++
 src/libxl/libxl_conf.h |  4 +++
 2 files changed, 98 insertions(+)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index f66264e..7bc9e7a 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1866,6 +1866,97 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
 
 #ifdef LIBXL_HAVE_PVUSB
 int
+libxlMakeUSBController(virDomainControllerDefPtr controller,
+   libxl_device_usbctrl *usbctrl)
+{
+usbctrl->devid = controller->idx;
+
+if (controller->type != VIR_DOMAIN_CONTROLLER_TYPE_USB)
+return -1;
+
+if (controller->model == -1) {
+usbctrl->version = 2;
+usbctrl->type = LIBXL_USBCTRL_TYPE_QUSB;
+} else {
+switch (controller->model) {
+case VIR_DOMAIN_CONTROLLER_MODEL_USB_PVUSB1:
+usbctrl->version = 1;
+usbctrl->type = LIBXL_USBCTRL_TYPE_PV;
+break;
+
+case VIR_DOMAIN_CONTROLLER_MODEL_USB_PVUSB2:
+usbctrl->version = 2;
+usbctrl->type = LIBXL_USBCTRL_TYPE_PV;
+break;
+
+case VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1:
+usbctrl->version = 1;
+usbctrl->type = LIBXL_USBCTRL_TYPE_QUSB;
+break;
+
+case VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB2:
+usbctrl->version = 2;
+usbctrl->type = LIBXL_USBCTRL_TYPE_QUSB;
+break;
+
+default:
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("unsupported usb model"));
+return -1;
+}
+}
+
+if (controller->opts.usbopts.ports == -1)
+usbctrl->ports = 8;
+else
+usbctrl->ports = controller->opts.usbopts.ports;
+
+return 0;
+}
+
+static int
+libxlMakeUSBControllerList(virDomainDefPtr def, libxl_domain_config *d_config)
+{
+virDomainControllerDefPtr *l_controllers = def->controllers;
+size_t ncontrollers = def->ncontrollers;
+size_t nusbctrls = 0;
+libxl_device_usbctrl *x_usbctrls;
+size_t i;
+
+if (ncontrollers == 0)
+return 0;
+
+if (VIR_ALLOC_N(x_usbctrls, ncontrollers) < 0)
+return -1;
+
+for (i = 0; i < ncontrollers; i++) {
+if (l_controllers[i]->type != VIR_DOMAIN_CONTROLLER_TYPE_USB)
+continue;
+
+libxl_device_usbctrl_init(_usbctrls[nusbctrls]);
+
+if (libxlMakeUSBController(l_controllers[i],
+   _usbctrls[nusbctrls]) < 0)
+goto error;
+
+nusbctrls++;
+}
+
+VIR_SHRINK_N(x_usbctrls, ncontrollers, ncontrollers - nusbctrls);
+d_config->usbctrls = x_usbctrls;
+d_config->num_usbctrls = nusbctrls;
+
+return 0;
+
+ error:
+for (i = 0; i < nusbctrls; i++)
+libxl_device_usbctrl_dispose(_usbctrls[i]);
+
+VIR_FREE(x_usbctrls);
+return -1;
+}
+
+int
 libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev)
 {
 virDomainHostdevSubsysUSBPtr usbsrc = >source.subsys.u.usb;
@@ -2165,6 +2256,9 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
 return -1;
 
 #ifdef LIBXL_HAVE_PVUSB
+if (libxlMakeUSBControllerList(def, d_config) < 0)
+return -1;
+
 if (libxlMakeUSBList(def, d_config) < 0)
 return -1;
 #endif
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index df318f4..de2a883 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -198,6 +198,10 @@ libxlMakePCI(virDomainHostdevDefPtr hostdev, 
libxl_device_pci *pcidev);
 
 #ifdef LIBXL_HAVE_PVUSB
 int
+libxlMakeUSBController(virDomainControllerDefPtr controller,
+   libxl_device_usbctrl *usbctrl);
+
+int
 libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev);
 #endif
 
-- 
2.1.4

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


[libvirt] [PATCH V2 2/4] libxl: support hotplug USB host device

2016-05-19 Thread Chunyan Liu
Support hot attach/detach a USB host device to guest.
Curretnly libxl only supports xen PV guest, and only
supports specifying USB host device by 'bus number'
and 'device number'.

For example:
 usb.xml:

  

  

 #xl attach-device dom usb.xml
 #xl detach-device dom usb.xml

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
Changes:
  * add LIBXL_HAVE_PVUSB check
  * fix Jim's comments

 src/libxl/libxl_driver.c | 136 ++-
 1 file changed, 135 insertions(+), 1 deletion(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 960673f..a171efe 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3028,6 +3028,56 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 return ret;
 }
 
+#ifdef LIBXL_HAVE_PVUSB
+static int
+libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr driver,
+   virDomainObjPtr vm,
+   virDomainHostdevDefPtr hostdev)
+{
+libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+libxl_device_usbdev usbdev;
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+int ret = -1;
+
+libxl_device_usbdev_init();
+
+if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
+goto cleanup;
+
+if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
+goto cleanup;
+
+if (virHostdevPrepareUSBDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
+vm->def->name, , 1, 0) < 0)
+goto cleanup;
+
+if (libxlMakeUSB(hostdev, ) < 0)
+goto reattach;
+
+if (libxl_device_usbdev_add(cfg->ctx, vm->def->id, , 0) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("libxenlight failed to attach usb device Busnum:%3x, 
Devnum:%3x"),
+   hostdev->source.subsys.u.usb.bus,
+   hostdev->source.subsys.u.usb.device);
+goto reattach;
+}
+
+vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
+ret = 0;
+goto cleanup;
+
+ reattach:
+virHostdevReAttachUSBDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
+ vm->def->name, , 1);
+
+ cleanup:
+virObjectUnref(cfg);
+libxl_device_usbdev_dispose();
+return ret;
+}
+#endif
+
 static int
 libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver,
 virDomainObjPtr vm,
@@ -3046,6 +3096,13 @@ libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver,
 return -1;
 break;
 
+#ifdef LIBXL_HAVE_PVUSB
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
+if (libxlDomainAttachHostUSBDevice(driver, vm, hostdev) < 0)
+return -1;
+break;
+#endif
+
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("hostdev subsys type '%s' not supported"),
@@ -3271,7 +3328,9 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
 case VIR_DOMAIN_DEVICE_HOSTDEV:
 hostdev = dev->data.hostdev;
 
-if (hostdev->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+if (hostdev->source.subsys.type !=
+(VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI ||
+ VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB))
 return -1;
 
 if (virDomainHostdevFind(vmdef, hostdev, ) >= 0) {
@@ -3389,6 +3448,76 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 return ret;
 }
 
+#ifdef LIBXL_HAVE_PVUSB
+static int
+libxlDomainDetachHostUSBDevice(libxlDriverPrivatePtr driver,
+   virDomainObjPtr vm,
+   virDomainHostdevDefPtr hostdev)
+{
+libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+virDomainHostdevSubsysPtr subsys = >source.subsys;
+virDomainHostdevSubsysUSBPtr usbsrc = >u.usb;
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+libxl_device_usbdev usbdev;
+libxl_device_usbdev *usbdevs = NULL;
+int num = 0;
+virDomainHostdevDefPtr detach;
+int idx;
+size_t i;
+bool found = false;
+int ret = -1;
+
+libxl_device_usbdev_init();
+
+idx = virDomainHostdevFind(vm->def, hostdev, );
+if (idx < 0) {
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("host USB device Busnum: %3x, Devnum: %3x not found"),
+   usbsrc->bus, usbsrc->device);
+goto cleanup;
+}
+
+usbdevs = libxl_device_usbdev_list(cfg->ctx, vm->def->id, );
+for (i = 0; i < num; i++) {
+if (usbdevs[i].u.hostdev.hostbus == usbsrc->bus &&
+usbdevs[i].u.hostdev.hostaddr == usbsrc->device) {
+libxl

[libvirt] [PATCH V2 3/4] Add convertion domxml USB config to/from xl.cfg

2016-05-19 Thread Chunyan Liu
xl.cfg:
usbdev = [ "hostbus=1,hostaddr=3" ]

usb.xml:
  

  

  

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/xenconfig/xen_xl.c | 151 +
 1 file changed, 151 insertions(+)

diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
index 15350f9..11e90b6 100644
--- a/src/xenconfig/xen_xl.c
+++ b/src/xenconfig/xen_xl.c
@@ -485,6 +485,85 @@ xenParseXLInputDevs(virConfPtr conf, virDomainDefPtr def)
 return 0;
 }
 
+static int
+xenParseXLUSB(virConfPtr conf, virDomainDefPtr def)
+{
+virConfValuePtr list = virConfGetValue(conf, "usbdev");
+virDomainHostdevDefPtr hostdev = NULL;
+
+if (list && list->type == VIR_CONF_LIST) {
+list = list->list;
+while (list) {
+char bus[3];
+char device[3];
+char *key;
+int busNum;
+int devNum;
+
+bus[0] = device[0] = '\0';
+
+if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
+goto skipusb;
+/* usbdev=['hostbus=1,hostaddr=3'] */
+key = list->str;
+while (key) {
+char *data;
+char *nextkey = strchr(key, ',');
+
+if (!(data = strchr(key, '=')))
+goto skipusb;
+data++;
+
+if (STRPREFIX(key, "hostbus=")) {
+int len = nextkey ? (nextkey - data) : sizeof(bus) - 1;
+if (virStrncpy(bus, data, len, sizeof(bus)) == NULL) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("bus %s too big for destination"),
+   data);
+goto skipusb;
+}
+} else if (STRPREFIX(key, "hostaddr=")) {
+int len = nextkey ? (nextkey - data) : sizeof(device) - 1;
+if (virStrncpy(device, data, len, sizeof(device)) == NULL) 
{
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("device %s too big for destination"),
+   data);
+goto skipusb;
+}
+}
+
+while (nextkey && (nextkey[0] == ',' ||
+   nextkey[0] == ' ' ||
+   nextkey[0] == '\t'))
+nextkey++;
+key = nextkey;
+}
+
+if (virStrToLong_i(bus, NULL, 16, ) < 0)
+goto skipusb;
+if (virStrToLong_i(device, NULL, 16, ) < 0)
+goto skipusb;
+if (!(hostdev = virDomainHostdevDefAlloc(NULL)))
+   return -1;
+
+hostdev->managed = false;
+hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB;
+hostdev->source.subsys.u.usb.bus = busNum;
+hostdev->source.subsys.u.usb.device = devNum;
+
+if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 
0) {
+virDomainHostdevDefFree(hostdev);
+return -1;
+}
+
+skipusb:
+list = list->next;
+}
+}
+
+return 0;
+}
+
 virDomainDefPtr
 xenParseXL(virConfPtr conf,
virCapsPtr caps,
@@ -513,6 +592,9 @@ xenParseXL(virConfPtr conf,
 if (xenParseXLInputDevs(conf, def) < 0)
 goto cleanup;
 
+if (xenParseXLUSB(conf, def) < 0)
+goto cleanup;
+
 if (virDomainDefPostParse(def, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
   xmlopt) < 0)
 goto cleanup;
@@ -984,6 +1066,72 @@ xenFormatXLInputDevs(virConfPtr conf, virDomainDefPtr def)
 return -1;
 }
 
+static int
+xenFormatXLUSB(virConfPtr conf,
+   virDomainDefPtr def)
+{
+virConfValuePtr usbVal = NULL;
+int hasUSB = 0;
+size_t i;
+
+for (i = 0; i < def->nhostdevs; i++) {
+if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+def->hostdevs[i]->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+hasUSB = 1;
+break;
+}
+}
+
+if (!hasUSB)
+return 0;
+
+if (VIR_ALLOC(usbVal) < 0)
+return -1;
+
+usbVal->type = VIR_CONF_LIST;
+usbVal->list = NULL;
+
+for (i = 0; i < def->nhostdevs; i++) {
+if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+def->hostdevs[i]->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+virConfValuePtr val, tmp;
+char *buf;
+
+if (virAsprintf(, "hostbus=%x,hostaddr=%x",
+def->hostdev

[libvirt] [PATCH V2 0/4] libxl: support pvusb

2016-05-19 Thread Chunyan Liu
This patch series is to support pvusb in libxl driver.

---
Changes in v2:
  * add LIBXL_HAVE_PVUSB check
  * add convertion of domxml USB config to/from xl.cfg
  * address other comments

Chunyan Liu (4):
  libxl: support creating guest with USB hostdev
  libxl: support hotplug USB host device
  Add convertion domxml USB config to/from xl.cfg
  xlconfigtest: add test on USB convertion

 src/libxl/libxl_conf.c  |  74 
 src/libxl/libxl_conf.h  |   5 ++
 src/libxl/libxl_domain.c|  16 -
 src/libxl/libxl_driver.c| 144 +-
 src/xenconfig/xen_xl.c  | 151 
 tests/xlconfigdata/test-usb.cfg |  13 
 tests/xlconfigdata/test-usb.xml |  35 ++
 tests/xlconfigtest.c|   1 +
 8 files changed, 435 insertions(+), 4 deletions(-)
 create mode 100644 tests/xlconfigdata/test-usb.cfg
 create mode 100644 tests/xlconfigdata/test-usb.xml

-- 
2.1.4

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


[libvirt] [PATCH V2 4/4] xlconfigtest: add test on USB convertion

2016-05-19 Thread Chunyan Liu
Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 tests/xlconfigdata/test-usb.cfg | 13 +
 tests/xlconfigdata/test-usb.xml | 35 +++
 tests/xlconfigtest.c|  1 +
 3 files changed, 49 insertions(+)
 create mode 100644 tests/xlconfigdata/test-usb.cfg
 create mode 100644 tests/xlconfigdata/test-usb.xml

diff --git a/tests/xlconfigdata/test-usb.cfg b/tests/xlconfigdata/test-usb.cfg
new file mode 100644
index 000..f0e616c
--- /dev/null
+++ b/tests/xlconfigdata/test-usb.cfg
@@ -0,0 +1,13 @@
+name = "XenGuest1"
+uuid = "45b60f51-88a9-47a8-a3b3-5e66d71b2283"
+maxmem = 512
+memory = 512
+vcpus = 1
+localtime = 0
+on_poweroff = "preserve"
+on_reboot = "restart"
+on_crash = "preserve"
+vif = [ "mac=5a:36:0e:be:00:09" ]
+bootloader = "/usr/bin/pygrub"
+disk = [ 
"format=qcow2,vdev=xvda,access=rw,backendtype=qdisk,target=/var/lib/xen/images/debian/disk.qcow2"
 ]
+usbdev = [ "hostbus=1,hostaddr=3" ]
diff --git a/tests/xlconfigdata/test-usb.xml b/tests/xlconfigdata/test-usb.xml
new file mode 100644
index 000..7b5853d
--- /dev/null
+++ b/tests/xlconfigdata/test-usb.xml
@@ -0,0 +1,35 @@
+
+  XenGuest1
+  45b60f51-88a9-47a8-a3b3-5e66d71b2283
+  524288
+  524288
+  1
+  /usr/bin/pygrub
+  
+linux
+  
+  
+  preserve
+  restart
+  preserve
+  
+
+  
+  
+  
+
+
+  
+
+
+  
+
+
+
+
+  
+
+  
+
+  
+
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index 6819bad..456f373 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -229,6 +229,7 @@ mymain(void)
 DO_TEST_FORMAT("fullvirt-direct-kernel-boot-bogus-extra");
 #endif
 DO_TEST("vif-typename");
+DO_TEST("usb");
 
 virObjectUnref(caps);
 virObjectUnref(xmlopt);
-- 
2.1.4

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


[libvirt] [PATCH V2 1/4] libxl: support creating guest with USB hostdev

2016-05-19 Thread Chunyan Liu
Support creating guest with USB host device in config file.
Currently libxl only supports xen PV guest, and only supports
specifying USB host device by 'bus number' and 'device number',
for example:

  

  


Signed-off-by: Chunyan Liu <cy...@suse.com>
---
Changes:
  * add LIBXL_HAVE_PVUSB check
  * address Jim's comments

 src/libxl/libxl_conf.c   | 74 
 src/libxl/libxl_conf.h   |  5 
 src/libxl/libxl_domain.c | 16 +--
 src/libxl/libxl_driver.c |  8 +-
 4 files changed, 100 insertions(+), 3 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index c399f5c..c6c76c4 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1861,6 +1861,75 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
 
 }
 
+#ifdef LIBXL_HAVE_PVUSB
+int
+libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev)
+{
+virDomainHostdevSubsysUSBPtr usbsrc = >source.subsys.u.usb;
+
+if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+return -1;
+if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
+return -1;
+
+if (usbsrc->bus <= 0 || usbsrc->device <= 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("libxenlight supports only USB device "
+ "specified by busnum:devnum"));
+return -1;
+}
+
+usbdev->u.hostdev.hostbus = usbsrc->bus;
+usbdev->u.hostdev.hostaddr = usbsrc->device;
+
+return 0;
+}
+
+static int
+libxlMakeUSBList(virDomainDefPtr def, libxl_domain_config *d_config)
+{
+virDomainHostdevDefPtr *l_hostdevs = def->hostdevs;
+size_t nhostdevs = def->nhostdevs;
+size_t nusbdevs = 0;
+libxl_device_usbdev *x_usbdevs;
+size_t i, j;
+
+if (nhostdevs == 0)
+return 0;
+
+if (VIR_ALLOC_N(x_usbdevs, nhostdevs) < 0)
+return -1;
+
+for (i = 0, j = 0; i < nhostdevs; i++) {
+if (l_hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+continue;
+if (l_hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
+continue;
+
+libxl_device_usbdev_init(_usbdevs[j]);
+
+if (libxlMakeUSB(l_hostdevs[i], _usbdevs[j]) < 0)
+goto error;
+
+nusbdevs++;
+j++;
+}
+
+VIR_SHRINK_N(x_usbdevs, nhostdevs, nhostdevs - nusbdevs);
+d_config->usbdevs = x_usbdevs;
+d_config->num_usbdevs = nusbdevs;
+
+return 0;
+
+ error:
+for (i = 0; i < nusbdevs; i++)
+libxl_device_usbdev_dispose(_usbdevs[i]);
+
+VIR_FREE(x_usbdevs);
+return -1;
+}
+#endif
+
 int
 libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev)
 {
@@ -2092,6 +2161,11 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
 if (libxlMakePCIList(def, d_config) < 0)
 return -1;
 
+#ifdef LIBXL_HAVE_PVUSB
+if (libxlMakeUSBList(def, d_config) < 0)
+return -1;
+#endif
+
 /*
  * Now that any potential VFBs are defined, update the build info with
  * the data of the primary display. Some day libxl might implicitely do
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index c5b9429..df318f4 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -196,6 +196,11 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports,
 int
 libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev);
 
+#ifdef LIBXL_HAVE_PVUSB
+int
+libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev);
+#endif
+
 virDomainXMLOptionPtr
 libxlCreateXMLConf(void);
 
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 5fa1bd9..3dda34d 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -726,9 +726,15 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
 int vnc_port;
 char *file;
 virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+unsigned int hostdev_flags;
+
+hostdev_flags = VIR_HOSTDEV_SP_PCI;
+#ifdef LIBXL_HAVE_PVUSB
+hostdev_flags |= VIR_HOSTDEV_SP_USB;
+#endif
 
 virHostdevReAttachDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
-vm->def, VIR_HOSTDEV_SP_PCI, NULL);
+vm->def, hostdev_flags, NULL);
 
 VIR_FREE(priv->lockState);
 if (virDomainLockProcessPause(driver->lockManager, vm, >lockState) < 
0)
@@ -1038,6 +1044,12 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
 virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
 libxl_asyncprogress_how aop_console_how;
 libxl_domain_restore_params params;
+unsigned int hostdev_flags;
+
+hostdev_flags = VIR_HOSTDEV_SP_PCI;
+#ifdef LIBXL_HAVE_PVUSB
+hostdev_flags |= VIR_HOSTDEV_SP_USB;
+#endif
 
 libxl_domain_config_init(_config);
 
@@ -1114

[libvirt] [PATCH V2 1/3] extract XEN_CONFIG_FORMAT_XM/XL to xen_common.h

2016-05-17 Thread Chunyan Liu
Unify XEN_CONFIG_FORMAT_x and LIBXL_CONFIG_FORMAT_x to
XEN_CONFIG_FORMAT_x, and move to xen_common.h.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c   | 14 +-
 src/xen/xen_driver.h   |  3 ---
 src/xenconfig/xen_common.h |  4 
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 062d6f8..2c19ddb 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -70,10 +70,6 @@ VIR_LOG_INIT("libxl.libxl_driver");
 #define LIBXL_DOM_REQ_CRASH3
 #define LIBXL_DOM_REQ_HALT 4
 
-#define LIBXL_CONFIG_FORMAT_XL "xen-xl"
-#define LIBXL_CONFIG_FORMAT_XM "xen-xm"
-#define LIBXL_CONFIG_FORMAT_SEXPR "xen-sxpr"
-
 #define LIBXL_NB_TOTAL_CPU_STAT_PARAM 1
 
 #define HYPERVISOR_CAPABILITIES "/proc/xen/capabilities"
@@ -2534,14 +2530,14 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
 if (virConnectDomainXMLFromNativeEnsureACL(conn) < 0)
 goto cleanup;
 
-if (STREQ(nativeFormat, LIBXL_CONFIG_FORMAT_XL)) {
+if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) {
 if (!(conf = virConfReadMem(nativeConfig, strlen(nativeConfig), 0)))
 goto cleanup;
 if (!(def = xenParseXL(conf,
cfg->caps,
driver->xmlopt)))
 goto cleanup;
-} else if (STREQ(nativeFormat, LIBXL_CONFIG_FORMAT_XM)) {
+} else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
 if (!(conf = virConfReadMem(nativeConfig, strlen(nativeConfig), 0)))
 goto cleanup;
 
@@ -2549,7 +2545,7 @@ libxlConnectDomainXMLFromNative(virConnectPtr conn,
cfg->caps,
driver->xmlopt)))
 goto cleanup;
-} else if (STREQ(nativeFormat, LIBXL_CONFIG_FORMAT_SEXPR)) {
+} else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_SEXPR)) {
 /* only support latest xend config format */
 if (!(def = xenParseSxprString(nativeConfig,
NULL,
@@ -2599,10 +2595,10 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const 
char * nativeFormat,
 VIR_DOMAIN_DEF_PARSE_INACTIVE)))
 goto cleanup;
 
-if (STREQ(nativeFormat, LIBXL_CONFIG_FORMAT_XL)) {
+if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) {
 if (!(conf = xenFormatXL(def, conn)))
 goto cleanup;
-} else if (STREQ(nativeFormat, LIBXL_CONFIG_FORMAT_XM)) {
+} else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
 if (!(conf = xenFormatXM(conn, def)))
 goto cleanup;
 } else {
diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h
index 8578324..5015b31 100644
--- a/src/xen/xen_driver.h
+++ b/src/xen/xen_driver.h
@@ -67,9 +67,6 @@ int xenRegister (void);
 
 # define MIN_XEN_GUEST_SIZE 64  /* 64 megabytes */
 
-# define XEN_CONFIG_FORMAT_XM"xen-xm"
-# define XEN_CONFIG_FORMAT_SEXPR "xen-sxpr"
-
 # define XEND_DOMAINS_DIR "/var/lib/xend/domains"
 
 # define XEN_SCHED_SEDF_NPARAM   6
diff --git a/src/xenconfig/xen_common.h b/src/xenconfig/xen_common.h
index 9ddf210..d96063c 100644
--- a/src/xenconfig/xen_common.h
+++ b/src/xenconfig/xen_common.h
@@ -27,6 +27,10 @@
 # include "virconf.h"
 # include "domain_conf.h"
 
+#define XEN_CONFIG_FORMAT_XL "xen-xl"
+#define XEN_CONFIG_FORMAT_XM "xen-xm"
+#define XEN_CONFIG_FORMAT_SEXPR "xen-sxpr"
+
 int xenConfigGetString(virConfPtr conf,
const char *name,
const char **value,
-- 
2.1.4

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


[libvirt] [PATCH V2 3/3] xlconfigtest: add test case for type=vif in xl format

2016-05-17 Thread Chunyan Liu
Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 tests/xlconfigdata/test-vif-typename.cfg | 25 ++
 tests/xlconfigdata/test-vif-typename.xml | 45 
 tests/xlconfigtest.c |  1 +
 3 files changed, 71 insertions(+)
 create mode 100644 tests/xlconfigdata/test-vif-typename.cfg
 create mode 100644 tests/xlconfigdata/test-vif-typename.xml

diff --git a/tests/xlconfigdata/test-vif-typename.cfg 
b/tests/xlconfigdata/test-vif-typename.cfg
new file mode 100644
index 000..2e30777
--- /dev/null
+++ b/tests/xlconfigdata/test-vif-typename.cfg
@@ -0,0 +1,25 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+pae = 1
+acpi = 1
+apic = 1
+viridian = 0
+rtc_timeoffset = 0
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+device_model = "/usr/lib/xen/bin/qemu-dm"
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = "127.0.0.1"
+vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,type=vif" ]
+parallel = "none"
+serial = "none"
+builder = "hvm"
+boot = "d"
+disk = [ 
"format=raw,vdev=hda,access=rw,backendtype=phy,target=/dev/HostVG/XenGuest2" ]
diff --git a/tests/xlconfigdata/test-vif-typename.xml 
b/tests/xlconfigdata/test-vif-typename.xml
new file mode 100644
index 000..76e98e3
--- /dev/null
+++ b/tests/xlconfigdata/test-vif-typename.xml
@@ -0,0 +1,45 @@
+
+  XenGuest2
+  c7a5fdb2-cdaf-9455-926a-d65c16db1809
+  592896
+  403456
+  1
+  
+hvm
+/usr/lib/xen/boot/hvmloader
+
+  
+  
+
+
+
+  
+  
+  destroy
+  restart
+  restart
+  
+/usr/lib/xen/bin/qemu-dm
+
+  
+  
+  
+  
+
+
+
+  
+  
+  
+  
+
+
+
+
+  
+
+
+  
+
+  
+
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index ba1bed0..6819bad 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -228,6 +228,7 @@ mymain(void)
 DO_TEST_FORMAT("fullvirt-direct-kernel-boot-extra");
 DO_TEST_FORMAT("fullvirt-direct-kernel-boot-bogus-extra");
 #endif
+DO_TEST("vif-typename");
 
 virObjectUnref(caps);
 virObjectUnref(xmlopt);
-- 
2.1.4

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


[libvirt] [PATCH V2 0/3] correct libxl config file convert

2016-05-17 Thread Chunyan Liu
Correct libxl config file type=vif handling.

---
Changes in v2:
  * update xen{Parse,Format}ConfigCommon parameter vif_typename to
nativeFomat. To reuse XEN_CONFIG_FORMAT_{XM,XL}, first extract
XEN_CONFIG_FORMAT_{XM,XL} to xen_common.h

Chunyan Liu (3):
  extract XEN_CONFIG_FORMAT_XM/XL to xen_common.h
  xenFormatNet: correct `type=netfront' to 'type=vif' to match libxl
  xlconfigtest: add test case for type=vif in xl format

 src/libxl/libxl_driver.c | 14 --
 src/xen/xen_driver.h |  3 ---
 src/xenconfig/xen_common.c   | 43 ++
 src/xenconfig/xen_common.h   | 10 +--
 src/xenconfig/xen_xl.c   |  4 +--
 src/xenconfig/xen_xm.c   |  4 +--
 tests/xlconfigdata/test-vif-typename.cfg | 25 ++
 tests/xlconfigdata/test-vif-typename.xml | 45 
 tests/xlconfigtest.c |  1 +
 9 files changed, 120 insertions(+), 29 deletions(-)
 create mode 100644 tests/xlconfigdata/test-vif-typename.cfg
 create mode 100644 tests/xlconfigdata/test-vif-typename.xml

-- 
2.1.4

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


[libvirt] [PATCH V2 2/3] xenFormatNet: correct `type=netfront' to 'type=vif' to match libxl

2016-05-17 Thread Chunyan Liu
According to current xl.cfg docs and xl codes, it uses type=vif
instead of type=netfront.

Currently after domxml-to-native, libvirt xml model=netfront will be
converted to xl type=netfront. This has no problem before, xen codes
for a long time just check type=ioemu, if not, set type to _VIF.

Since libxl uses parse_nic_config to avoid duplicate codes, it
compares 'type=vif' and 'type=ioemu' for valid parameters, others
are considered as invalid, thus we have problem with type=netfront
in xl config file.
 #xl create sles12gm-hvm.orig
 Parsing config from sles12gm-hvm.orig
 Invalid parameter `type'.

Correct the convertion in libvirt, so that it matchs libxl codes
and also xl.cfg.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/xenconfig/xen_common.c | 43 ---
 src/xenconfig/xen_common.h |  6 --
 src/xenconfig/xen_xl.c |  4 ++--
 src/xenconfig/xen_xm.c |  4 ++--
 4 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index c6aee69..3e57601 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -801,9 +801,8 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def)
 return -1;
 }
 
-
 static int
-xenParseVif(virConfPtr conf, virDomainDefPtr def)
+xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
 {
 char *script = NULL;
 virDomainNetDefPtr net = NULL;
@@ -942,7 +941,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def)
 VIR_STRDUP(net->model, model) < 0)
 goto cleanup;
 
-if (!model[0] && type[0] && STREQ(type, "netfront") &&
+if (!model[0] && type[0] && STREQ(type, vif_typename) &&
 VIR_STRDUP(net->model, "netfront") < 0)
 goto cleanup;
 
@@ -1046,7 +1045,8 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, 
virCapsPtr caps)
 int
 xenParseConfigCommon(virConfPtr conf,
  virDomainDefPtr def,
- virCapsPtr caps)
+ virCapsPtr caps,
+ const char *nativeFormat)
 {
 if (xenParseGeneralMeta(conf, def, caps) < 0)
 return -1;
@@ -1066,8 +1066,17 @@ xenParseConfigCommon(virConfPtr conf,
 if (xenConfigCopyStringOpt(conf, "device_model", >emulator) < 0)
 return -1;
 
-if (xenParseVif(conf, def) < 0)
+if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XL)) {
+if (xenParseVif(conf, def, "vif") < 0)
+return -1;
+} else if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
+if (xenParseVif(conf, def, "netfront") < 0)
+return -1;
+} else {
+virReportError(VIR_ERR_INVALID_ARG,
+   _("unsupported config type %s"), nativeFormat);
 return -1;
+}
 
 if (xenParsePCI(conf, def) < 0)
 return -1;
@@ -1127,7 +1136,8 @@ static int
 xenFormatNet(virConnectPtr conn,
  virConfValuePtr list,
  virDomainNetDefPtr net,
- int hvm)
+ int hvm,
+ const char *vif_typename)
 {
 virBuffer buf = VIR_BUFFER_INITIALIZER;
 virConfValuePtr val, tmp;
@@ -1199,7 +1209,7 @@ xenFormatNet(virConnectPtr conn,
 virBufferAsprintf(, ",model=%s", net->model);
 } else {
 if (net->model != NULL && STREQ(net->model, "netfront")) {
-virBufferAddLit(, ",type=netfront");
+virBufferAsprintf(, ",type=%s", vif_typename);
 } else {
 if (net->model != NULL)
 virBufferAsprintf(, ",model=%s", net->model);
@@ -1749,7 +1759,8 @@ xenFormatSound(virConfPtr conf, virDomainDefPtr def)
 static int
 xenFormatVif(virConfPtr conf,
  virConnectPtr conn,
- virDomainDefPtr def)
+ virDomainDefPtr def,
+ const char *vif_typename)
 {
virConfValuePtr netVal = NULL;
size_t i;
@@ -1762,7 +1773,7 @@ xenFormatVif(virConfPtr conf,
 
 for (i = 0; i < def->nnets; i++) {
 if (xenFormatNet(conn, netVal, def->nets[i],
- hvm) < 0)
+ hvm, vif_typename) < 0)
goto cleanup;
 }
 
@@ -1788,7 +1799,8 @@ xenFormatVif(virConfPtr conf,
 int
 xenFormatConfigCommon(virConfPtr conf,
   virDomainDefPtr def,
-  virConnectPtr conn)
+  virConnectPtr conn,
+  const char * nativeFormat)
 {
 if (xenFormatGeneralMeta(conf, def) < 0)
 return -1;
@@ -1814,8 +1826,17 @@ xenFormatConfigCommon(virConfPtr conf,
 if (xenFormatVfb(conf, def) < 0)
 return -1;
 
-if (xenFormatVif(conf, conn, def) < 0)
+if (STREQ(nativeFormat, XEN

[libvirt] [PATCH] libxl: add .domainInterfaceAddresses

2016-05-13 Thread Chunyan Liu
Add .domainInterfaceAddresses so that user can have a way to
get domain interface address by 'virsh domifaddr'. Currently
it only supports '--source lease'.

Signed-off: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 140 +++
 1 file changed, 140 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 062d6f8..f2bd6fa 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5425,6 +5425,145 @@ static int libxlNodeGetSecurityModel(virConnectPtr conn,
 return 0;
 }
 
+static int
+libxlGetDHCPInterfaces(virDomainPtr dom,
+   virDomainObjPtr vm,
+   virDomainInterfacePtr **ifaces)
+{
+int rv = -1;
+int n_leases = 0;
+size_t i, j;
+size_t ifaces_count = 0;
+virNetworkPtr network = NULL;
+char macaddr[VIR_MAC_STRING_BUFLEN];
+virDomainInterfacePtr iface = NULL;
+virNetworkDHCPLeasePtr *leases = NULL;
+virDomainInterfacePtr *ifaces_ret = NULL;
+
+if (!dom->conn->networkDriver ||
+!dom->conn->networkDriver->networkGetDHCPLeases) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("Network driver does not support DHCP lease query"));
+return -1;
+}
+
+for (i = 0; i < vm->def->nnets; i++) {
+if (vm->def->nets[i]->type != VIR_DOMAIN_NET_TYPE_NETWORK)
+continue;
+
+virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr);
+virObjectUnref(network);
+network = virNetworkLookupByName(dom->conn,
+ vm->def->nets[i]->data.network.name);
+
+if ((n_leases = virNetworkGetDHCPLeases(network, macaddr,
+, 0)) < 0)
+goto error;
+
+if (n_leases) {
+if (VIR_EXPAND_N(ifaces_ret, ifaces_count, 1) < 0)
+goto error;
+
+if (VIR_ALLOC(ifaces_ret[ifaces_count - 1]) < 0)
+goto error;
+
+iface = ifaces_ret[ifaces_count - 1];
+/* Assuming each lease corresponds to a separate IP */
+iface->naddrs = n_leases;
+
+if (VIR_ALLOC_N(iface->addrs, iface->naddrs) < 0)
+goto error;
+
+if (VIR_STRDUP(iface->name, vm->def->nets[i]->ifname) < 0)
+goto cleanup;
+
+if (VIR_STRDUP(iface->hwaddr, macaddr) < 0)
+goto cleanup;
+}
+
+for (j = 0; j < n_leases; j++) {
+virNetworkDHCPLeasePtr lease = leases[j];
+virDomainIPAddressPtr ip_addr = >addrs[j];
+
+if (VIR_STRDUP(ip_addr->addr, lease->ipaddr) < 0)
+goto cleanup;
+
+ip_addr->type = lease->type;
+ip_addr->prefix = lease->prefix;
+}
+
+for (j = 0; j < n_leases; j++)
+virNetworkDHCPLeaseFree(leases[j]);
+
+VIR_FREE(leases);
+}
+
+*ifaces = ifaces_ret;
+ifaces_ret = NULL;
+rv = ifaces_count;
+
+ cleanup:
+virObjectUnref(network);
+if (leases) {
+for (i = 0; i < n_leases; i++)
+virNetworkDHCPLeaseFree(leases[i]);
+}
+VIR_FREE(leases);
+
+return rv;
+
+ error:
+if (ifaces_ret) {
+for (i = 0; i < ifaces_count; i++)
+virDomainInterfaceFree(ifaces_ret[i]);
+}
+VIR_FREE(ifaces_ret);
+
+goto cleanup;
+}
+
+
+static int
+libxlDomainInterfaceAddresses(virDomainPtr dom,
+  virDomainInterfacePtr **ifaces,
+  unsigned int source,
+  unsigned int flags)
+{
+virDomainObjPtr vm = NULL;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+if (!(vm = libxlDomObjFromDomain(dom)))
+goto cleanup;
+
+if (virDomainInterfaceAddressesEnsureACL(dom->conn, vm->def) < 0)
+goto cleanup;
+
+if (!virDomainObjIsActive(vm)) {
+virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+   _("domain is not running"));
+goto cleanup;
+}
+
+switch (source) {
+case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE:
+ret = libxlGetDHCPInterfaces(dom, vm, ifaces);
+break;
+
+default:
+virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
+   _("Unsupported IP address data source %d"),
+   source);
+break;
+}
+
+ cleanup:
+virDomainObjEndAPI();
+return ret;
+}
+
+
 static virHypervisorDriver libxlHypervisorDriver = {
 .name = LIBXL_DRIVER_NAME,
 .connectOpen = libxlConnectOpen, /* 0.9.0 */
@@ -5525,6 +5664,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
 .domainMigrateFinish3Params = libxlDomainMigrateFinish3P

[libvirt] [PATCH 2/2] xlconfigtest: add test case for type=vif in xl format

2016-04-21 Thread Chunyan Liu
Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 tests/xlconfigdata/test-vif-typename.cfg | 25 +++
 tests/xlconfigdata/test-vif-typename.xml | 42 
 tests/xlconfigtest.c |  1 +
 3 files changed, 68 insertions(+)
 create mode 100644 tests/xlconfigdata/test-vif-typename.cfg
 create mode 100644 tests/xlconfigdata/test-vif-typename.xml

diff --git a/tests/xlconfigdata/test-vif-typename.cfg 
b/tests/xlconfigdata/test-vif-typename.cfg
new file mode 100644
index 000..2e30777
--- /dev/null
+++ b/tests/xlconfigdata/test-vif-typename.cfg
@@ -0,0 +1,25 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+pae = 1
+acpi = 1
+apic = 1
+viridian = 0
+rtc_timeoffset = 0
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+device_model = "/usr/lib/xen/bin/qemu-dm"
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = "127.0.0.1"
+vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,type=vif" ]
+parallel = "none"
+serial = "none"
+builder = "hvm"
+boot = "d"
+disk = [ 
"format=raw,vdev=hda,access=rw,backendtype=phy,target=/dev/HostVG/XenGuest2" ]
diff --git a/tests/xlconfigdata/test-vif-typename.xml 
b/tests/xlconfigdata/test-vif-typename.xml
new file mode 100644
index 000..1e99377
--- /dev/null
+++ b/tests/xlconfigdata/test-vif-typename.xml
@@ -0,0 +1,42 @@
+
+  XenGuest2
+  c7a5fdb2-cdaf-9455-926a-d65c16db1809
+  592896
+  403456
+  1
+  
+hvm
+/usr/lib/xen/boot/hvmloader
+
+  
+  
+
+
+
+  
+  
+  destroy
+  restart
+  restart
+  
+/usr/lib/xen/bin/qemu-dm
+
+  
+  
+  
+  
+
+
+
+  
+  
+  
+  
+
+
+
+
+  
+
+  
+
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
index ba1bed0..6819bad 100644
--- a/tests/xlconfigtest.c
+++ b/tests/xlconfigtest.c
@@ -228,6 +228,7 @@ mymain(void)
 DO_TEST_FORMAT("fullvirt-direct-kernel-boot-extra");
 DO_TEST_FORMAT("fullvirt-direct-kernel-boot-bogus-extra");
 #endif
+DO_TEST("vif-typename");
 
 virObjectUnref(caps);
 virObjectUnref(xmlopt);
-- 
2.1.4

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


[libvirt] [PATCH 1/2] xenFormatNet: correct `type=netfront' to 'type=vif' to match libxl

2016-04-21 Thread Chunyan Liu
According to current xl.cfg docs and xl codes, it uses type=vif
instead of type=netfront.

Currently after domxml-to-native, libvirt xml model=netfront will be
converted to xl type=netfront. This has no problem before, xen codes
for a long time just check type=ioemu, if not, set type to _VIF.

Since libxl uses parse_nic_config to avoid duplicate codes, it
compares 'type=vif' and 'type=ioemu' for valid parameters, others
are considered as invalid, thus we have problem with type=netfront
in xl config file.
 #xl create sles12gm-hvm.orig
 Parsing config from sles12gm-hvm.orig
 Invalid parameter `type'.

Correct the convertion in libvirt, so that it matchs libxl codes
and also xl.cfg.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/xenconfig/xen_common.c | 38 --
 src/xenconfig/xen_common.h |  7 ---
 src/xenconfig/xen_xl.c |  4 ++--
 src/xenconfig/xen_xm.c |  8 
 4 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index e1d9cf6..f54d6b6 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -801,9 +801,8 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def)
 return -1;
 }
 
-
 static int
-xenParseVif(virConfPtr conf, virDomainDefPtr def)
+xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename)
 {
 char *script = NULL;
 virDomainNetDefPtr net = NULL;
@@ -942,7 +941,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def)
 VIR_STRDUP(net->model, model) < 0)
 goto cleanup;
 
-if (!model[0] && type[0] && STREQ(type, "netfront") &&
+if (!model[0] && type[0] && STREQ(type, vif_typename) &&
 VIR_STRDUP(net->model, "netfront") < 0)
 goto cleanup;
 
@@ -1042,11 +1041,17 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr 
def, virCapsPtr caps)
 
 /*
  * A convenience function for parsing all config common to both XM and XL
+ *
+ * vif_typename: type name for a paravirtualized network could
+ * be different for xm and xl. For xm, it uses type=netfront;
+ * for xl, it uses type=vif. So, for xm, should pass "netfront";
+ * for xl, should pass "vif".
  */
 int
 xenParseConfigCommon(virConfPtr conf,
  virDomainDefPtr def,
- virCapsPtr caps)
+ virCapsPtr caps,
+ const char *vif_typename)
 {
 if (xenParseGeneralMeta(conf, def, caps) < 0)
 return -1;
@@ -1066,7 +1071,7 @@ xenParseConfigCommon(virConfPtr conf,
 if (xenConfigCopyStringOpt(conf, "device_model", >emulator) < 0)
 return -1;
 
-if (xenParseVif(conf, def) < 0)
+if (xenParseVif(conf, def, vif_typename) < 0)
 return -1;
 
 if (xenParsePCI(conf, def) < 0)
@@ -1122,12 +1127,12 @@ xenFormatSerial(virConfValuePtr list, 
virDomainChrDefPtr serial)
 return -1;
 }
 
-
 static int
 xenFormatNet(virConnectPtr conn,
  virConfValuePtr list,
  virDomainNetDefPtr net,
- int hvm)
+ int hvm,
+ const char *vif_typename)
 {
 virBuffer buf = VIR_BUFFER_INITIALIZER;
 virConfValuePtr val, tmp;
@@ -1199,7 +1204,7 @@ xenFormatNet(virConnectPtr conn,
 virBufferAsprintf(, ",model=%s", net->model);
 } else {
 if (net->model != NULL && STREQ(net->model, "netfront")) {
-virBufferAddLit(, ",type=netfront");
+virBufferAsprintf(, ",type=%s", vif_typename);
 } else {
 if (net->model != NULL)
 virBufferAsprintf(, ",model=%s", net->model);
@@ -1744,12 +1749,11 @@ xenFormatSound(virConfPtr conf, virDomainDefPtr def)
 return 0;
 }
 
-
-
 static int
 xenFormatVif(virConfPtr conf,
  virConnectPtr conn,
- virDomainDefPtr def)
+ virDomainDefPtr def,
+ const char *vif_typename)
 {
virConfValuePtr netVal = NULL;
size_t i;
@@ -1762,7 +1766,7 @@ xenFormatVif(virConfPtr conf,
 
 for (i = 0; i < def->nnets; i++) {
 if (xenFormatNet(conn, netVal, def->nets[i],
- hvm) < 0)
+ hvm, vif_typename) < 0)
goto cleanup;
 }
 
@@ -1784,11 +1788,17 @@ xenFormatVif(virConfPtr conf,
 
 /*
  * A convenience function for formatting all config common to both XM and XL
+ *
+ * vif_typename: type name for a paravirtualized network could
+ * be different for xm and xl. For xm, it uses type=netfront;
+ * for xl, it uses type=vif. So, for xm, should pass "netfront";
+ * for xl, should pass "vif".
  */
 int
 xenFormatConfigCommon(virConfPtr conf,
   virDomainDefPtr def,
-

[libvirt] [PATCH 0/2] correct libxl config file convert

2016-04-21 Thread Chunyan Liu
Correct libxl config file type=vif handling.

Chunyan Liu (2):
  xenFormatNet: correct `type=netfront' to 'type=vif' to match libxl
  xlconfigtest: add test case for type=vif in xl format

 src/xenconfig/xen_common.c   | 38 ++---
 src/xenconfig/xen_common.h   |  7 +++---
 src/xenconfig/xen_xl.c   |  4 +--
 src/xenconfig/xen_xm.c   |  8 +++---
 tests/xlconfigdata/test-vif-typename.cfg | 25 +++
 tests/xlconfigdata/test-vif-typename.xml | 42 
 tests/xlconfigtest.c |  1 +
 7 files changed, 102 insertions(+), 23 deletions(-)
 create mode 100644 tests/xlconfigdata/test-vif-typename.cfg
 create mode 100644 tests/xlconfigdata/test-vif-typename.xml

-- 
2.1.4

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


[libvirt] [PATCH 1/2] libxl: support creating guest with USB hostdev

2016-04-21 Thread Chunyan Liu
Support creating guest with USB host device in config file.
Currently libxl only supports xen PV guest, and only supports
specifying USB host device by 'bus number' and 'device number'.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_conf.c   | 71 
 src/libxl/libxl_conf.h   |  3 ++
 src/libxl/libxl_domain.c |  4 +--
 src/libxl/libxl_driver.c |  2 +-
 4 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 30f2ce9..3b69cbf 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1848,6 +1848,74 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
 }
 
 int
+libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev)
+{
+virDomainHostdevSubsysUSBPtr usbsrc = >source.subsys.u.usb;
+
+if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+return -1;
+if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
+return -1;
+
+if (usbsrc->bus <= 0 || usbsrc->device <= 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("libxenlight supports only USB device "
+ "specified by busnum:devnum"));
+return -1;
+}
+
+usbdev->u.hostdev.hostbus = usbsrc->bus;
+usbdev->u.hostdev.hostaddr = usbsrc->device;
+
+return 0;
+}
+
+static int
+libxlMakeUSBList(virDomainDefPtr def, libxl_domain_config *d_config)
+{
+virDomainHostdevDefPtr *l_hostdevs = def->hostdevs;
+size_t nhostdevs = def->nhostdevs;
+size_t nusbdevs = 0;
+libxl_device_usbdev *x_usbdevs;
+size_t i, j;
+
+if (nhostdevs == 0)
+return 0;
+
+if (VIR_ALLOC_N(x_usbdevs, nhostdevs) < 0)
+return -1;
+
+for (i = 0, j = 0; i < nhostdevs; i++) {
+if (l_hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+continue;
+if (l_hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
+continue;
+
+libxl_device_usbdev_init(_usbdevs[j]);
+
+if (libxlMakeUSB(l_hostdevs[i], _usbdevs[j]) < 0)
+goto error;
+
+nusbdevs++;
+j++;
+}
+
+VIR_SHRINK_N(x_usbdevs, nhostdevs, nhostdevs - nusbdevs);
+d_config->usbdevs = x_usbdevs;
+d_config->num_usbdevs = nusbdevs;
+
+return 0;
+
+ error:
+for (i = 0; i < nhostdevs; i++)
+libxl_device_usbdev_dispose(_usbdevs[i]);
+
+VIR_FREE(x_usbdevs);
+return -1;
+}
+
+
+int
 libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev)
 {
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
@@ -2078,6 +2146,9 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
 if (libxlMakePCIList(def, d_config) < 0)
 return -1;
 
+if (libxlMakeUSBList(def, d_config) < 0)
+return -1;
+
 /*
  * Now that any potential VFBs are defined, update the build info with
  * the data of the primary display. Some day libxl might implicitely do
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index 24e2911..e3ccca1 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -192,6 +192,9 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports,
 int
 libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev);
 
+int
+libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev);
+
 virDomainXMLOptionPtr
 libxlCreateXMLConf(void);
 
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 14a900c..4272dda 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -728,7 +728,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
 virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
 
 virHostdevReAttachDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
-vm->def, VIR_HOSTDEV_SP_PCI, NULL);
+vm->def, VIR_HOSTDEV_SP_PCI | 
VIR_HOSTDEV_SP_USB, NULL);
 
 VIR_FREE(priv->lockState);
 if (virDomainLockProcessPause(driver->lockManager, vm, >lockState) < 
0)
@@ -1103,7 +1103,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, 
virDomainObjPtr vm,
 goto cleanup_dom;
 
 if (virHostdevPrepareDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
-   vm->def, VIR_HOSTDEV_SP_PCI) < 0)
+   vm->def, VIR_HOSTDEV_SP_PCI | 
VIR_HOSTDEV_SP_USB) < 0)
 goto cleanup_dom;
 
 /* Unlock virDomainObj while creating the domain */
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index bf97c9c..18a0891 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -383,7 +383,7 @@ libxlReconnectDomain(virDomainObjPtr vm,
 
 /* Update hostdev state */
 if (virHostdevUpdateActiveDomainDev

[libvirt] [PATCH 0/2] libxl: support pvusb

2016-04-21 Thread Chunyan Liu
This patch series is to support pvusb in libxl driver.

Chunyan Liu (2):
  libxl: support creating guest with USB hostdev
  libxl: support hotplug USB host device

 src/libxl/libxl_conf.c   |  71 +
 src/libxl/libxl_conf.h   |   3 ++
 src/libxl/libxl_domain.c |   4 +-
 src/libxl/libxl_driver.c | 132 ++-
 4 files changed, 206 insertions(+), 4 deletions(-)

-- 
2.1.4

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


[libvirt] [PATCH 2/2] libxl: support hotplug USB host device

2016-04-21 Thread Chunyan Liu
Support hot attach/detach a USB host device to guest.
Curretnly libxl only supports xen PV guest, and only
supports specifying USB host device by 'bus number'
and 'device number'.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 130 ++-
 1 file changed, 129 insertions(+), 1 deletion(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 18a0891..8900644 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3024,6 +3024,55 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 }
 
 static int
+libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr driver,
+   virDomainObjPtr vm,
+   virDomainHostdevDefPtr hostdev)
+{
+libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+libxl_device_usbdev usbdev;
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+int ret = -1;
+
+libxl_device_usbdev_init();
+
+if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
+return ret;
+
+if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
+goto cleanup;
+
+if (virHostdevPrepareUSBDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
+vm->def->name, , 1, 0) < 0)
+goto cleanup;
+
+if (libxlMakeUSB(hostdev, ) < 0)
+goto error;
+
+if (libxl_device_usbdev_add(cfg->ctx, vm->def->id, , 0) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("libxenlight failed to attach usb device Busnum:%3x, 
Devnum:%3x"),
+   hostdev->source.subsys.u.usb.bus,
+   hostdev->source.subsys.u.usb.device);
+goto error;
+}
+
+vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
+ret = 0;
+goto cleanup;
+
+ error:
+virHostdevReAttachUSBDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
+ vm->def->name, , 1);
+
+ cleanup:
+virObjectUnref(cfg);
+libxl_device_usbdev_dispose();
+return ret;
+}
+
+
+static int
 libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver,
 virDomainObjPtr vm,
 virDomainHostdevDefPtr hostdev)
@@ -3041,6 +3090,11 @@ libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver,
 return -1;
 break;
 
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
+if (libxlDomainAttachHostUSBDevice(driver, vm, hostdev) < 0)
+return -1;
+break;
+
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("hostdev subsys type '%s' not supported"),
@@ -3266,7 +3320,8 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
 case VIR_DOMAIN_DEVICE_HOSTDEV:
 hostdev = dev->data.hostdev;
 
-if (hostdev->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+if (hostdev->source.subsys.type !=
+(VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB || 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI))
 return -1;
 
 if (virDomainHostdevFind(vmdef, hostdev, ) >= 0) {
@@ -3385,6 +3440,76 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 }
 
 static int
+libxlDomainDetachHostUSBDevice(libxlDriverPrivatePtr driver,
+   virDomainObjPtr vm,
+   virDomainHostdevDefPtr hostdev)
+{
+libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+virDomainHostdevSubsysPtr subsys = >source.subsys;
+virDomainHostdevSubsysUSBPtr usbsrc = >u.usb;
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+libxl_device_usbdev usbdev;
+libxl_device_usbdev *usbdevs = NULL;
+int num = 0;
+virDomainHostdevDefPtr detach;
+int idx;
+size_t i;
+bool found = false;
+int ret = -1;
+
+libxl_device_usbdev_init();
+
+idx = virDomainHostdevFind(vm->def, hostdev, );
+if (idx < 0) {
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("host USB device Busnum: %3x, Devnum:%3x not found"),
+   usbsrc->bus, usbsrc->device);
+goto cleanup;
+}
+
+usbdevs = libxl_device_usbdev_list(cfg->ctx, vm->def->id, );
+for (i = 0; i < num; i++) {
+if (usbdevs[i].u.hostdev.hostbus == usbsrc->bus &&
+usbdevs[i].u.hostdev.hostaddr == usbsrc->device) {
+libxl_device_usbdev_copy(cfg->ctx, , [i]);
+found = true;
+break;
+}
+}
+libxl_device_usbdev_list_free(usbdevs, num);
+
+if (!found) {
+virReportError(VIR_ERR_OPERATION_FAILED,
+   _("host USB devic

[libvirt] [PATCH] libxl config file convertion: correct `type=netfront' to 'type=vif'

2016-04-08 Thread Chunyan Liu
According to current xl.cfg docs and xl codes, it uses type=vif
instead of type=netfront.

Currently after domxml-to-native, libvirt xml model=netfront will be
converted to xl type=netfront. This has no problem before, xen codes
for a long time just check type=ioemu, if not, set type to _VIF.

Since libxl uses parse_nic_config to avoid duplicate codes, it
compares 'type=vif' and 'type=ioemu' for valid parameters, others
are considered as invalid, thus we have problem with type=netfront
in xl config file.
 #xl create sles12gm-hvm.orig
 Parsing config from sles12gm-hvm.orig
 Invalid parameter `type'.

Correct the convertion in libvirt, so that it matchs libxl codes
and also xl.cfg.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
Since type=netfront config has been used for a very long time, at
lease for xm/xend, it has no problem. I'm not sure if we need to
split into xenParseXLVif vs xenParseXMVif, and xenFormatXLVif vs
xenFormatXMVif for this change?

 src/xenconfig/xen_common.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 4dcd484..ae81635 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -944,7 +944,8 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def)
 VIR_STRDUP(net->model, model) < 0)
 goto cleanup;
 
-if (!model[0] && type[0] && STREQ(type, "netfront") &&
+if (!model[0] && type[0] &&
+(STREQ(type, "netfront") || STREQ(type, "vif")) &&
 VIR_STRDUP(net->model, "netfront") < 0)
 goto cleanup;
 
@@ -1201,7 +1202,7 @@ xenFormatNet(virConnectPtr conn,
 virBufferAsprintf(, ",model=%s", net->model);
 } else {
 if (net->model != NULL && STREQ(net->model, "netfront")) {
-virBufferAddLit(, ",type=netfront");
+virBufferAddLit(, ",type=vif");
 } else {
 if (net->model != NULL)
 virBufferAsprintf(, ",model=%s", net->model);
-- 
2.1.4

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


[libvirt] [PATCH V5] libxl: support creating domain with VF assignment from a pool

2016-04-07 Thread Chunyan Liu
Add codes to support creating domain with network defition of assigning
SRIOV VF from a pool.

Signed-off-by: Chunyan Liu <cy...@suse.com>
Signed-off-by: Jim Fehlig <jfeh...@suse.com>
---
Rebase and send a new version.

 src/libxl/libxl_domain.c | 48 
 tests/Makefile.am|  3 +++
 2 files changed, 51 insertions(+)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 04962a0..bd5deaa 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -36,6 +36,7 @@
 #include "virtime.h"
 #include "locking/domain_lock.h"
 #include "xen_common.h"
+#include "network/bridge_driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
 
@@ -764,6 +765,10 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
 if (net->ifname &&
 STRPREFIX(net->ifname, LIBXL_GENERATED_PREFIX_XEN))
 VIR_FREE(net->ifname);
+
+/* cleanup actual device */
+virDomainNetRemoveHostdev(vm->def, net);
+networkReleaseActualDevice(vm->def, net);
 }
 }
 
@@ -900,6 +905,46 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config 
*d_config)
 return -1;
 }
 
+static int
+libxlNetworkPrepareDevices(virDomainDefPtr def)
+{
+size_t i;
+
+for (i = 0; i < def->nnets; i++) {
+virDomainNetDefPtr net = def->nets[i];
+int actualType;
+
+/* If appropriate, grab a physical device from the configured
+ * network's pool of devices, or resolve bridge device name
+ * to the one defined in the network definition.
+ */
+if (networkAllocateActualDevice(def, net) < 0)
+return -1;
+
+actualType = virDomainNetGetActualType(net);
+if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
+/* Each type='hostdev' network device must also have a
+ * corresponding entry in the hostdevs array. For netdevs
+ * that are hardcoded as type='hostdev', this is already
+ * done by the parser, but for those allocated from a
+ * network / determined at runtime, we need to do it
+ * separately.
+ */
+virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
+virDomainHostdevSubsysPCIPtr pcisrc = 
>source.subsys.u.pci;
+
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+hostdev->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
+if (virDomainHostdevInsert(def, hostdev) < 0)
+return -1;
+}
+}
+return 0;
+}
+
 static void
 libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void *for_callback)
 {
@@ -1050,6 +1095,9 @@ libxlDomainStart(libxlDriverPrivatePtr driver, 
virDomainObjPtr vm,
 goto cleanup;
 VIR_FREE(priv->lockState);
 
+if (libxlNetworkPrepareDevices(vm->def) < 0)
+goto cleanup_dom;
+
 if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def,
cfg->ctx, _config) < 0)
 goto cleanup_dom;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b3f1144..db4f88b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -534,6 +534,9 @@ endif ! WITH_XEN
 
 if WITH_LIBXL
 libxl_LDADDS = ../src/libvirt_driver_libxl_impl.la
+if WITH_NETWORK
+libxl_LDADDS += ../src/libvirt_driver_network_impl.la
+endif WITH_NETWORK
 libxl_LDADDS += $(LDADDS)
 
 xlconfigtest_SOURCES = \
-- 
1.8.5.6

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


[libvirt] [PATCH V4 0/6] libxl: support assign VF to guest from SRIOV pool

2016-03-21 Thread Chunyan Liu
This patch series is to support assign VF to guest from SRIOV pool,
including fixes to network attach/detach and fix to libxlDomainstart.

Chunyan Liu (6):
  libxlDomainAttachNetDevice: release actual deivce and remove hostdev
when fail
  libxlDomainDetachNetDevice: cleanup codes
  libxlDomainDetachDeviceLive: handle hostdev parent is network device
  libxl: support creating domain with VF assignment from a pool
  libxl: fix hot add/remove VF from a pool
  libxlDomainStart: correct cleanup after failure

 src/libxl/libxl_domain.c | 85 +++-
 src/libxl/libxl_driver.c | 52 -
 tests/Makefile.am|  3 ++
 3 files changed, 108 insertions(+), 32 deletions(-)

-- 
2.1.4

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


[libvirt] [PATCH V4 2/6] libxlDomainDetachNetDevice: cleanup codes

2016-03-21 Thread Chunyan Liu
Adjust codes to make it cleaner.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 05ebe29..74ebea4 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3413,8 +3413,10 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
 char mac[VIR_MAC_STRING_BUFLEN];
 int ret = -1;
 
+libxl_device_nic_init();
+
 if ((detachidx = virDomainNetFindIdx(vm->def, net)) < 0)
-goto out;
+goto cleanup;
 
 detach = vm->def->nets[detachidx];
 
@@ -3424,10 +3426,9 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
  */
 ret = libxlDomainDetachHostDevice(driver, vm,
   
virDomainNetGetActualHostdev(detach));
-goto out;
+goto cleanup;
 }
 
-libxl_device_nic_init();
 if (libxl_mac_to_device_nic(cfg->ctx, vm->def->id,
 virMacAddrFormat(>mac, mac), ))
 goto cleanup;
@@ -3442,7 +3443,6 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
 
  cleanup:
 libxl_device_nic_dispose();
- out:
 if (!ret)
 virDomainNetRemove(vm->def, detachidx);
 virObjectUnref(cfg);
-- 
2.1.4

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


[libvirt] [PATCH V4 4/6] libxl: support creating domain with VF assignment from a pool

2016-03-21 Thread Chunyan Liu
Add codes to support creating domain with network defition of assigning
SRIOV VF from a pool.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_domain.c | 50 
 tests/Makefile.am|  3 +++
 2 files changed, 53 insertions(+)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index c8d09b1..d11bf3a 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -36,6 +36,7 @@
 #include "virtime.h"
 #include "locking/domain_lock.h"
 #include "xen_common.h"
+#include "network/bridge_driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
 
@@ -764,6 +765,10 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
 if (net->ifname &&
 STRPREFIX(net->ifname, LIBXL_GENERATED_PREFIX_XEN))
 VIR_FREE(net->ifname);
+
+/* cleanup actual device */
+virDomainNetRemoveHostdev(vm->def, net);
+networkReleaseActualDevice(vm->def, net);
 }
 }
 
@@ -960,6 +965,48 @@ libxlDomainCreateIfaceNames(virDomainDefPtr def, 
libxl_domain_config *d_config)
 }
 }
 
+static int
+libxlNetworkPrepareDevices(virDomainDefPtr def)
+{
+int ret = -1;
+size_t i;
+
+for (i = 0; i < def->nnets; i++) {
+virDomainNetDefPtr net = def->nets[i];
+int actualType;
+
+/* If appropriate, grab a physical device from the configured
+ * network's pool of devices, or resolve bridge device name
+ * to the one defined in the network definition.
+ */
+if (networkAllocateActualDevice(def, net) < 0)
+goto cleanup;
+
+actualType = virDomainNetGetActualType(net);
+if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
+/* Each type='hostdev' network device must also have a
+ * corresponding entry in the hostdevs array. For netdevs
+ * that are hardcoded as type='hostdev', this is already
+ * done by the parser, but for those allocated from a
+ * network / determined at runtime, we need to do it
+ * separately.
+ */
+virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
+virDomainHostdevSubsysPCIPtr pcisrc = 
>source.subsys.u.pci;
+
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+hostdev->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
+if (virDomainHostdevInsert(def, hostdev) < 0)
+goto cleanup;
+}
+}
+ret = 0;
+ cleanup:
+return ret;
+}
 
 /*
  * Start a domain through libxenlight.
@@ -1036,6 +1083,9 @@ libxlDomainStart(libxlDriverPrivatePtr driver, 
virDomainObjPtr vm,
 vm, true) < 0)
 goto cleanup;
 
+if (libxlNetworkPrepareDevices(vm->def) < 0)
+goto cleanup;
+
 if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def,
cfg->ctx, _config) < 0)
 goto cleanup;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b3f1144..db4f88b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -534,6 +534,9 @@ endif ! WITH_XEN
 
 if WITH_LIBXL
 libxl_LDADDS = ../src/libvirt_driver_libxl_impl.la
+if WITH_NETWORK
+libxl_LDADDS += ../src/libvirt_driver_network_impl.la
+endif WITH_NETWORK
 libxl_LDADDS += $(LDADDS)
 
 xlconfigtest_SOURCES = \
-- 
2.1.4

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


[libvirt] [PATCH V4 6/6] libxlDomainStart: correct cleanup after failure

2016-03-21 Thread Chunyan Liu
Functions like libxlNetworkPrepareDevices, libxlBuildDomainConfig,
virHostdevPrepareDomainDevices will allocate and reserve some
resources. In libxlDomainStart, after calling these functions,
in case of failure, we need to call libxlDomainCleanup to check
and release resoureces.
Besides, since libxlDomainCleanup will call virDomainLockProcessPause,
so we move virDomainLockProcessStart/Resume to earlier stage.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_domain.c | 41 ++---
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index d11bf3a..6855ce4 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -1083,20 +1083,13 @@ libxlDomainStart(libxlDriverPrivatePtr driver, 
virDomainObjPtr vm,
 vm, true) < 0)
 goto cleanup;
 
-if (libxlNetworkPrepareDevices(vm->def) < 0)
-goto cleanup;
-
-if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def,
-   cfg->ctx, _config) < 0)
-goto cleanup;
-
-if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, _config) < 0)
-goto cleanup;
-
-if (virHostdevPrepareDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
-   vm->def, VIR_HOSTDEV_SP_PCI) < 0)
-goto cleanup;
-
+/* libxlNetworkPrepareDevices, libxlBuildDomainConfig,
+ * virHostdevPrepareDomainDevices will allocate and reserve
+ * some resources. In case of failure, need to release
+ * resoureces. This can be done by calling libxlDomainCleanup.
+ * Since libxlDomainCleanup will call virDomainLockProcessPause,
+ * so we move virDomainLockProcessStart/Resume to here.
+ */
 if (virDomainLockProcessStart(driver->lockManager,
   "xen:///system",
   vm,
@@ -,6 +1104,20 @@ libxlDomainStart(libxlDriverPrivatePtr driver, 
virDomainObjPtr vm,
 goto cleanup;
 VIR_FREE(priv->lockState);
 
+if (libxlNetworkPrepareDevices(vm->def) < 0)
+goto release_dom;
+
+if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def,
+   cfg->ctx, _config) < 0)
+goto release_dom;
+
+if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, _config) < 0)
+goto release_dom;
+
+if (virHostdevPrepareDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
+   vm->def, VIR_HOSTDEV_SP_PCI) < 0)
+goto release_dom;
+
 /* Unlock virDomainObj while creating the domain */
 virObjectUnlock(vm);
 
@@ -1194,16 +1201,12 @@ libxlDomainStart(libxlDriverPrivatePtr driver, 
virDomainObjPtr vm,
 
  cleanup_dom:
 ret = -1;
-if (priv->deathW) {
-libxl_evdisable_domain_death(cfg->ctx, priv->deathW);
-priv->deathW = NULL;
-}
 libxlDomainDestroyInternal(driver, vm);
 vm->def->id = -1;
 virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_FAILED);
 
  release_dom:
-virDomainLockProcessPause(driver->lockManager, vm, >lockState);
+libxlDomainCleanup(driver, vm);
 
  cleanup:
 libxl_domain_config_dispose(_config);
-- 
2.1.4

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


[libvirt] [PATCH V4 5/6] libxl: fix hot add/remove VF from a pool

2016-03-21 Thread Chunyan Liu
For those VF allocated from a network pool, we need to set its backend
to be VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN so that later work can be
correct.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 328dac8..d7004fd 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3145,13 +3145,23 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
 }
 
 if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
+virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
+
+/* For those just allocated from a network pool whose backend is
+ * still VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT, we need to set
+ * backend correctly.
+ */
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
 /* This is really a "smart hostdev", so it should be attached
  * as a hostdev (the hostdev code will reach over into the
  * netdev-specific code as appropriate), then also added to
  * the nets list (see out:) if successful.
  */
-ret = libxlDomainAttachHostDevice(driver, vm,
-  virDomainNetGetActualHostdev(net));
+ret = libxlDomainAttachHostDevice(driver, vm, hostdev);
 goto cleanup;
 }
 
-- 
2.1.4

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


[libvirt] [PATCH V4 1/6] libxlDomainAttachNetDevice: release actual deivce and remove hostdev when fail

2016-03-21 Thread Chunyan Liu
When AttachNetDevice failed, should call networkReleaseActualDevice
to release actual device, and if actual device is hostdev, should
remove the hostdev from vm->def->hostdevs.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 87ec5a5..05ebe29 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3122,16 +3122,18 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
 int ret = -1;
 char mac[VIR_MAC_STRING_BUFLEN];
 
+libxl_device_nic_init();
+
 /* preallocate new slot for device */
 if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1) < 0)
-goto out;
+goto cleanup;
 
 /* If appropriate, grab a physical device from the configured
  * network's pool of devices, or resolve bridge device name
  * to the one defined in the network definition.
  */
 if (networkAllocateActualDevice(vm->def, net) < 0)
-goto out;
+goto cleanup;
 
 actualType = virDomainNetGetActualType(net);
 
@@ -3139,7 +3141,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
 virReportError(VIR_ERR_INVALID_ARG,
_("network device with mac %s already exists"),
virMacAddrFormat(>mac, mac));
-return -1;
+goto cleanup;
 }
 
 if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
@@ -3150,10 +3152,9 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
  */
 ret = libxlDomainAttachHostDevice(driver, vm,
   virDomainNetGetActualHostdev(net));
-goto out;
+goto cleanup;
 }
 
-libxl_device_nic_init();
 if (libxlMakeNic(vm->def, net, ) < 0)
 goto cleanup;
 
@@ -3167,9 +3168,12 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
 
  cleanup:
 libxl_device_nic_dispose();
- out:
-if (!ret)
+if (!ret) {
 vm->def->nets[vm->def->nnets++] = net;
+} else {
+virDomainNetRemoveHostdev(vm->def, net);
+networkReleaseActualDevice(vm->def, net);
+}
 virObjectUnref(cfg);
 return ret;
 }
-- 
2.1.4

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


[libvirt] [PATCH V4 3/6] libxlDomainDetachDeviceLive: handle hostdev parent is network device

2016-03-21 Thread Chunyan Liu
When hostdev parent is network device, should call
libxlDomainDetachNetDevice to detach the device from a higher level.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 74ebea4..328dac8 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3443,8 +3443,10 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
 
  cleanup:
 libxl_device_nic_dispose();
-if (!ret)
+if (!ret) {
+networkReleaseActualDevice(vm->def, detach);
 virDomainNetRemove(vm->def, detachidx);
+}
 virObjectUnref(cfg);
 return ret;
 }
@@ -3467,8 +3469,12 @@ libxlDomainDetachDeviceLive(libxlDriverPrivatePtr driver,
 break;
 
 case VIR_DOMAIN_DEVICE_HOSTDEV:
-ret = libxlDomainDetachHostDevice(driver, vm,
-  dev->data.hostdev);
+if (dev->data.hostdev->parent.type == VIR_DOMAIN_DEVICE_NET)
+ret = libxlDomainDetachNetDevice(driver, vm,
+  dev->data.hostdev->parent.data.net);
+else
+ret = libxlDomainDetachHostDevice(driver, vm,
+  dev->data.hostdev);
 break;
 
 default:
-- 
2.1.4

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


[libvirt] [PATCH V3 0/2] libxl: support assignment VF to guest from a pool of SRIOV VFs

2016-03-09 Thread Chunyan Liu
This patch series is to support assigning VF to guest from a pool of SRIOV VFs
in libxl driver, detailed usage can be referred to:
http://wiki.libvirt.org/page/Networking#Assignment_from_a_pool_of_SRIOV_VFs_in_a_libvirt_.3Cnetwork.3E_definition

Chunyan Liu (2):
  libxl_conf: reuse virDomainNetGetActualtype in libxlMakeNicList
  libxl: support assignment from a pool of SRIOV VFs

 src/libxl/libxl_conf.c   |  3 ++-
 src/libxl/libxl_domain.c | 46 ++
 src/libxl/libxl_driver.c | 12 
 tests/Makefile.am|  3 +++
 4 files changed, 63 insertions(+), 1 deletion(-)

-- 
2.1.4

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


[libvirt] [PATCH V3 2/2] libxl: support assignment from a pool of SRIOV VFs

2016-03-09 Thread Chunyan Liu
Add codes to support creating domain with network defition of assigning
SRIOV VF from a pool. And fix hot plug and unplug SRIOV VF under this
kind of network defition.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
Changes:
  * move a common change in libxl_conf.c into separate patch

 src/libxl/libxl_domain.c | 46 ++
 src/libxl/libxl_driver.c | 12 
 tests/Makefile.am|  3 +++
 3 files changed, 61 insertions(+)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index c8d09b1..8191911 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -36,6 +36,7 @@
 #include "virtime.h"
 #include "locking/domain_lock.h"
 #include "xen_common.h"
+#include "network/bridge_driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
 
@@ -960,6 +961,48 @@ libxlDomainCreateIfaceNames(virDomainDefPtr def, 
libxl_domain_config *d_config)
 }
 }
 
+static int
+libxlNetworkPrepareDevices(virDomainDefPtr def)
+{
+int ret = -1;
+size_t i;
+
+for (i = 0; i < def->nnets; i++) {
+virDomainNetDefPtr net = def->nets[i];
+int actualType;
+
+/* If appropriate, grab a physical device from the configured
+ * network's pool of devices, or resolve bridge device name
+ * to the one defined in the network definition.
+ */
+if (networkAllocateActualDevice(def, net) < 0)
+goto cleanup;
+
+actualType = virDomainNetGetActualType(net);
+if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
+/* Each type='hostdev' network device must also have a
+ * corresponding entry in the hostdevs array. For netdevs
+ * that are hardcoded as type='hostdev', this is already
+ * done by the parser, but for those allocated from a
+ * network / determined at runtime, we need to do it
+ * separately.
+ */
+virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
+virDomainHostdevSubsysPCIPtr pcisrc = 
>source.subsys.u.pci;
+
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+hostdev->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
+if (virDomainHostdevInsert(def, hostdev) < 0)
+goto cleanup;
+}
+}
+ret = 0;
+ cleanup:
+return ret;
+}
 
 /*
  * Start a domain through libxenlight.
@@ -1036,6 +1079,9 @@ libxlDomainStart(libxlDriverPrivatePtr driver, 
virDomainObjPtr vm,
 vm, true) < 0)
 goto cleanup;
 
+if (libxlNetworkPrepareDevices(vm->def) < 0)
+goto cleanup;
+
 if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def,
cfg->ctx, _config) < 0)
 goto cleanup;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 87ec5a5..a0b157b 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2982,6 +2982,12 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 
 libxl_device_pci_init();
 
+/* For those allocated from a network pool/ determined at runtime, it's
+ * not handled by libxlDomainDeviceDefPostParse as hostdev, we need to
+ * set backend correctly.
+ */
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
 if (virDomainHostdevFind(vm->def, hostdev, ) >= 0) {
 virReportError(VIR_ERR_OPERATION_FAILED,
_("target pci device %.4x:%.2x:%.2x.%.1x already 
exists"),
@@ -3323,6 +3329,12 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 
 libxl_device_pci_init();
 
+/* For those allocated from a network pool/ determined at runtime, it's
+ * not handled by libxlDomainDeviceDefPostParse as hostdev, we need to
+ * set backend correctly.
+ */
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
 idx = virDomainHostdevFind(vm->def, hostdev, );
 if (idx < 0) {
 virReportError(VIR_ERR_OPERATION_FAILED,
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 90981dc..b08cc7a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -530,6 +530,9 @@ endif ! WITH_XEN
 
 if WITH_LIBXL
 libxl_LDADDS = ../src/libvirt_driver_libxl_impl.la
+if WITH_NETWORK
+libxl_LDADDS += ../src/libvirt_driver_network_impl.la
+endif WITH_NETWORK
 libxl_LDADDS += $(LDADDS)
 
 xlconfigtest_SOURCES = \
-- 
2.1.4

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


[libvirt] [PATCH V3 1/2] libxl_conf: reuse virDomainNetGetActualtype in libxlMakeNicList

2016-03-09 Thread Chunyan Liu
Reuse existing helper function virDomainNetGetActualtype.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_conf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 93c943b..2b77c59 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1445,7 +1445,8 @@ libxlMakeNicList(virDomainDefPtr def,  
libxl_domain_config *d_config)
 return -1;
 
 for (i = 0; i < nnics; i++) {
-if (l_nics[i]->type == VIR_DOMAIN_NET_TYPE_HOSTDEV)
+if (virDomainNetGetActualType(l_nics[i])
+== VIR_DOMAIN_NET_TYPE_HOSTDEV)
 continue;
 
 if (libxlMakeNic(def, l_nics[i], _nics[nvnics]))
-- 
2.1.4

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


[libvirt] [PATCH V2] libxl: support assignment from a pool of SRIOV VFs

2016-02-23 Thread Chunyan Liu
Add codes to support creating domain with network defition of assigning
SRIOV VF from a pool. And fix hot plug and unplug SRIOV VF under this
kind of network defition.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
Changes:
* move bug fix to another patch
* use virDomainNetGetActualType instead of multiple times checking
---
 src/libxl/libxl_conf.c   |  3 ++-
 src/libxl/libxl_domain.c | 46 ++
 src/libxl/libxl_driver.c | 12 
 tests/Makefile.am|  3 +++
 4 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 48b8826..3cefbaa 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1453,7 +1453,8 @@ libxlMakeNicList(virDomainDefPtr def,  
libxl_domain_config *d_config)
 return -1;
 
 for (i = 0; i < nnics; i++) {
-if (l_nics[i]->type == VIR_DOMAIN_NET_TYPE_HOSTDEV)
+if (virDomainNetGetActualType(l_nics[i])
+== VIR_DOMAIN_NET_TYPE_HOSTDEV)
 continue;
 
 if (libxlMakeNic(def, l_nics[i], _nics[nvnics]))
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 50f7eed..88d1399 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -36,6 +36,7 @@
 #include "virtime.h"
 #include "locking/domain_lock.h"
 #include "xen_common.h"
+#include "network/bridge_driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
 
@@ -929,6 +930,48 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void 
*for_callback)
 libxl_event_free(ctx, ev);
 }
 
+static int
+libxlNetworkPrepareDevices(virDomainDefPtr def)
+{
+int ret = -1;
+size_t i;
+
+for (i = 0; i < def->nnets; i++) {
+virDomainNetDefPtr net = def->nets[i];
+int actualType;
+
+/* If appropriate, grab a physical device from the configured
+ * network's pool of devices, or resolve bridge device name
+ * to the one defined in the network definition.
+ */
+if (networkAllocateActualDevice(def, net) < 0)
+goto cleanup;
+
+actualType = virDomainNetGetActualType(net);
+if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
+/* Each type='hostdev' network device must also have a
+ * corresponding entry in the hostdevs array. For netdevs
+ * that are hardcoded as type='hostdev', this is already
+ * done by the parser, but for those allocated from a
+ * network / determined at runtime, we need to do it
+ * separately.
+ */
+virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
+virDomainHostdevSubsysPCIPtr pcisrc = 
>source.subsys.u.pci;
+
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+hostdev->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
+if (virDomainHostdevInsert(def, hostdev) < 0)
+goto cleanup;
+}
+}
+ret = 0;
+ cleanup:
+return ret;
+}
 
 /*
  * Start a domain through libxenlight.
@@ -1005,6 +1048,9 @@ libxlDomainStart(libxlDriverPrivatePtr driver, 
virDomainObjPtr vm,
 vm, true) < 0)
 goto cleanup;
 
+if (libxlNetworkPrepareDevices(vm->def) < 0)
+goto cleanup;
+
 if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def,
cfg->ctx, _config) < 0)
 goto cleanup;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 404016e..eef6651 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3049,6 +3049,12 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 
 libxl_device_pci_init();
 
+/* For those allocated from a network pool/ determined at runtime, it's
+ * not handled by libxlDomainDeviceDefPostParse as hostdev, we need to
+ * set backend correctly.
+ */
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
 if (virDomainHostdevFind(vm->def, hostdev, ) >= 0) {
 virReportError(VIR_ERR_OPERATION_FAILED,
_("target pci device %.4x:%.2x:%.2x.%.1x already 
exists"),
@@ -3390,6 +3396,12 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 
 libxl_device_pci_init();
 
+/* For those allocated from a network pool/ determined at runtime, it's
+ * not handled by libxlDomainDeviceDefPostParse as hostdev, we need to
+ * set backend correctly.
+ */
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
 idx = virDomainHostdevFind(vm->def, hostdev, );
 if (idx < 0) {
 virReportError(VIR_ERR_OPERATION_FAILED,
diff --

[libvirt] [PATCH] libxl: small fix in parsing network

2016-02-23 Thread Chunyan Liu
Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_conf.c   | 2 +-
 src/libxl/libxl_domain.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 5133299..48b8826 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1471,7 +1471,7 @@ libxlMakeNicList(virDomainDefPtr def,  
libxl_domain_config *d_config)
 
 VIR_SHRINK_N(x_nics, nnics, nnics - nvnics);
 d_config->nics = x_nics;
-d_config->num_nics = nnics;
+d_config->num_nics = nvnics;
 
 return 0;
 
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 632acfd..50f7eed 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -315,7 +315,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 virDomainHostdevSubsysPCIPtr pcisrc;
 
 if (dev->type == VIR_DOMAIN_DEVICE_NET)
-hostdev = &(dev->data.net)->data.hostdev.def;
+hostdev = >data.net->data.hostdev.def;
 else
 hostdev = dev->data.hostdev;
 pcisrc = >source.subsys.u.pci;
-- 
2.1.4

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


[libvirt] [PATCH] libxl: support assignment from a pool of SRIOV VFs

2016-01-25 Thread Chunyan Liu
Add codes to support creating domain with network defition of assigning
SRIOV VF from a pool. And fix hot plug and unplug SRIOV VF under this
kind of network defition.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_conf.c   |  5 +++--
 src/libxl/libxl_domain.c | 48 +++-
 src/libxl/libxl_driver.c | 12 
 tests/Makefile.am|  3 +++
 4 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 6320421..f50c68a 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1260,7 +1260,8 @@ libxlMakeNicList(virDomainDefPtr def,  
libxl_domain_config *d_config)
 return -1;
 
 for (i = 0; i < nnics; i++) {
-if (l_nics[i]->type == VIR_DOMAIN_NET_TYPE_HOSTDEV)
+if (l_nics[i]->type == VIR_DOMAIN_NET_TYPE_HOSTDEV ||
+l_nics[i]->data.network.actual->type == 
VIR_DOMAIN_NET_TYPE_HOSTDEV)
 continue;
 
 if (libxlMakeNic(def, l_nics[i], _nics[nvnics]))
@@ -1278,7 +1279,7 @@ libxlMakeNicList(virDomainDefPtr def,  
libxl_domain_config *d_config)
 
 VIR_SHRINK_N(x_nics, nnics, nnics - nvnics);
 d_config->nics = x_nics;
-d_config->num_nics = nnics;
+d_config->num_nics = nvnics;
 
 return 0;
 
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index cf5c9f6..9bf7a5a 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -35,6 +35,7 @@
 #include "virstring.h"
 #include "virtime.h"
 #include "locking/domain_lock.h"
+#include "network/bridge_driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
 
@@ -314,7 +315,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 virDomainHostdevSubsysPCIPtr pcisrc;
 
 if (dev->type == VIR_DOMAIN_DEVICE_NET)
-hostdev = &(dev->data.net)->data.hostdev.def;
+hostdev = >data.net->data.hostdev.def;
 else
 hostdev = dev->data.hostdev;
 pcisrc = >source.subsys.u.pci;
@@ -916,6 +917,48 @@ libxlConsoleCallback(libxl_ctx *ctx, libxl_event *ev, void 
*for_callback)
 libxl_event_free(ctx, ev);
 }
 
+static int
+libxlNetworkPrepareDevices(virDomainDefPtr def)
+{
+int ret = -1;
+size_t i;
+
+for (i = 0; i < def->nnets; i++) {
+virDomainNetDefPtr net = def->nets[i];
+int actualType;
+
+/* If appropriate, grab a physical device from the configured
+ * network's pool of devices, or resolve bridge device name
+ * to the one defined in the network definition.
+ */
+if (networkAllocateActualDevice(def, net) < 0)
+goto cleanup;
+
+actualType = virDomainNetGetActualType(net);
+if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
+net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
+/* Each type='hostdev' network device must also have a
+ * corresponding entry in the hostdevs array. For netdevs
+ * that are hardcoded as type='hostdev', this is already
+ * done by the parser, but for those allocated from a
+ * network / determined at runtime, we need to do it
+ * separately.
+ */
+virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
+virDomainHostdevSubsysPCIPtr pcisrc = 
>source.subsys.u.pci;
+
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+hostdev->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
+if (virDomainHostdevInsert(def, hostdev) < 0)
+goto cleanup;
+}
+}
+ret = 0;
+ cleanup:
+return ret;
+}
 
 /*
  * Start a domain through libxenlight.
@@ -992,6 +1035,9 @@ libxlDomainStart(libxlDriverPrivatePtr driver, 
virDomainObjPtr vm,
 vm, true) < 0)
 goto cleanup;
 
+if (libxlNetworkPrepareDevices(vm->def) < 0)
+goto cleanup;
+
 if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def,
cfg->ctx, _config) < 0)
 goto cleanup;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 4a9134e..6aca042 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3047,6 +3047,12 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 
 libxl_device_pci_init();
 
+/* For those allocated from a network pool/ determined at runtime, it's
+ * not handled by libxlDomainDeviceDefPostParse as hostdev, we need to
+ * set backend correctly.
+ */
+pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
+
 if (virDomainHostdevFind(vm->def, hostdev, ) >= 0) {
 virRepo

[libvirt] [PATCH] libxl: fix AttachDeviceConfig on hostdev type

2015-09-16 Thread Chunyan Liu
After attach-device a  with --config, new device doesn't
show up in dumpxml and in guest.

To fix that, set dev->data.hostdev = NULL after work so that the
pointer is not freed, since vmdef has the pointer and still need it.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index e2797d5..8087c27 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3312,6 +3312,7 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
 
 if (virDomainHostdevInsert(vmdef, hostdev) < 0)
 return -1;
+dev->data.hostdev = NULL;
 break;
 
 default:
-- 
1.8.5.6

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


[libvirt] [PATCH] libxl: fix AttachDeviceConfig on hostdev type

2015-09-16 Thread Chunyan Liu
After attach-device a  with --config, new device doesn't
show up in dumpxml and in guest.

To fix that, set dev->data.hostdev = NULL after work so that the
pointer is not freed, since vmdef has the pointer and still need it.

Signed-off-by: Chunyan Liu <cy...@suse.com>
---
 src/libxl/libxl_driver.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index e2797d5..8087c27 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3312,6 +3312,7 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
 
 if (virDomainHostdevInsert(vmdef, hostdev) < 0)
 return -1;
+dev->data.hostdev = NULL;
 break;
 
 default:
-- 
1.8.5.6

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


[libvirt] [PATCH] fix vol-create when target allocation=0

2015-08-23 Thread Chunyan Liu
Regression is introduced by commit e30297b0. After that, it will
report Cannot fill file error with following xml file:
volume
  namevirtinst-vmlinuz-xen.tP1NHh/name
  capacity4343792/capacity
  allocation0/allocation
  target
format type=raw/
nocow/
  /target
/volume
Because of this, installing xen pv guest with virt-manager fails.

Reason is: posix_fallocate(int fd, off_t offset, off_t len) will
return EINVAL when len is equal to 0. So, this patch adds a check
before calling safezero().

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/storage/storage_backend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index db49739..2a265af 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -455,7 +455,7 @@ createRawFile(int fd, virStorageVolDefPtr vol,
 pos = inputvol-target.capacity - remain;
 }
 
-if (need_alloc) {
+if (need_alloc  (vol-target.allocation  pos)) {
 if (safezero(fd, pos, vol-target.allocation - pos)  0) {
 ret = -errno;
 virReportSystemError(errno, _(cannot fill file '%s'),
-- 
2.1.4

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


[libvirt] [PATCH V4 0/5] support sending sysrq key

2015-01-11 Thread Chunyan Liu
xend/libxl support sending sysrq key to guest kernel but not support
sending any key sequence as virDomainSendKey is expected to do. To
add equivalant sysrq functionality in libvirt for xen/libxl, add a new
virDomainSendSysrq API and add related codes to virsh, remote driver,
xen/libxl driver.


Changes to V3:
  * fix some memory leak

Not change:
  virDomainSendSysrq parameter still keeps char key rather than enum
  key, main reason to keep it because: sysrq key is different to different
  kinds of guests, xen hypervisor doesn't know the correct enum - letter
  mapping towards different guests, it just sends the key blindly to guests.
  See:
  http://www.redhat.com/archives/libvir-list/2015-January/msg00132.html

V3 is here:
  http://www.redhat.com/archives/libvir-list/2014-December/msg00882.html

Chunyan Liu (5):
  Add public API virDomainSendSysrq
  implement remote protocol for domainSendSysrq
  virsh: add 'sysrq' command
  libxl: implement .domainSendSysrq method
  xen: add .domainSendSysrq method

 include/libvirt/libvirt-domain.h |  3 +++
 src/driver-hypervisor.h  |  4 +++
 src/libvirt-domain.c | 39 +++
 src/libvirt_public.syms  |  5 
 src/libxl/libxl_driver.c | 25 ++
 src/remote/remote_driver.c   |  1 +
 src/remote/remote_protocol.x | 14 +-
 src/remote_protocol-structs  |  6 +
 src/rpc/gendispatch.pl   | 12 +
 src/xen/xen_driver.c | 21 +++
 src/xen/xend_internal.c  | 30 +
 src/xen/xend_internal.h  |  1 +
 tools/virsh-domain.c | 57 
 13 files changed, 217 insertions(+), 1 deletion(-)

-- 
1.8.4.5

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


[libvirt] [PATCH V4 1/5] Add public API virDomainSendSysrq

2015-01-11 Thread Chunyan Liu
Add public API virDomainSendSysrq for sending SysRequest key.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 include/libvirt/libvirt-domain.h |  3 +++
 src/driver-hypervisor.h  |  4 
 src/libvirt-domain.c | 39 +++
 src/libvirt_public.syms  |  5 +
 4 files changed, 51 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 0b1a2d6..a762034 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -3527,6 +3527,9 @@ int virDomainGetFSInfo(virDomainPtr dom,
virDomainFSInfoPtr **info,
unsigned int flags);
 
+/* virDomainSendSysrq */
+int virDomainSendSysrq(virDomainPtr dom, char key, unsigned int flags);
+
 int virDomainGetTime(virDomainPtr dom,
  long long *seconds,
  unsigned int *nseconds,
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 9f26b13..d260d29 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -1170,6 +1170,9 @@ typedef int
 unsigned int cellCount,
 unsigned int flags);
 
+typedef int
+(*virDrvDomainSendSysrq)(virDomainPtr dom, char key, unsigned int flags);
+
 
 typedef struct _virHypervisorDriver virHypervisorDriver;
 typedef virHypervisorDriver *virHypervisorDriverPtr;
@@ -1396,6 +1399,7 @@ struct _virHypervisorDriver {
 virDrvConnectGetAllDomainStats connectGetAllDomainStats;
 virDrvNodeAllocPages nodeAllocPages;
 virDrvDomainGetFSInfo domainGetFSInfo;
+virDrvDomainSendSysrq domainSendSysrq;
 };
 
 
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 6ec68aa..83ece45 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -11201,3 +11201,42 @@ virDomainFSInfoFree(virDomainFSInfoPtr info)
 VIR_FREE(info-devAlias[i]);
 VIR_FREE(info-devAlias);
 }
+
+
+/**
+ * virDomainSendSysrq:
+ * @domain:pointer to domain object, or NULL for Domain0
+ * @key:SysRq key, like h, c, ...
+ * @flags:  extra flags; not used yet, so callers should always pass 0
+ *
+ * Send SysRq key to the guest.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+int
+virDomainSendSysrq(virDomainPtr domain, char key, unsigned int flags)
+{
+virConnectPtr conn;
+VIR_DOMAIN_DEBUG(domain, key=%c, flags=%x, key, flags);
+
+virResetLastError();
+
+virCheckDomainReturn(domain, -1);
+conn = domain-conn;
+
+virCheckReadOnlyGoto(conn-flags, error);
+
+if (conn-driver-domainSendSysrq) {
+int ret;
+ret = conn-driver-domainSendSysrq(domain, key, flags);
+if (ret  0)
+goto error;
+return ret;
+}
+
+virReportUnsupportedError();
+
+ error:
+virDispatchError(domain-conn);
+return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index e4c2df1..5d4999a 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -690,4 +690,9 @@ LIBVIRT_1.2.11 {
 virDomainGetFSInfo;
 } LIBVIRT_1.2.9;
 
+LIBVIRT_1.2.12 {
+global:
+virDomainSendSysrq;
+} LIBVIRT_1.2.11;
+
 #  define new API here using predicted next version number 
-- 
1.8.4.5

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


[libvirt] [PATCH V4 5/5] xen: add .domainSendSysrq method

2015-01-11 Thread Chunyan Liu
Support sending sysrq key to guest.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/xen/xen_driver.c| 21 +
 src/xen/xend_internal.c | 30 ++
 src/xen/xend_internal.h |  1 +
 3 files changed, 52 insertions(+)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index c9f4159..4a56b69 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2738,6 +2738,26 @@ xenUnifiedNodeSuspendForDuration(virConnectPtr conn,
 return nodeSuspendForDuration(target, duration, flags);
 }
 
+static int
+xenUnifiedDomainSendSysrq(virDomainPtr dom, char key, unsigned int flags)
+{
+int ret = -1;
+virDomainDefPtr def = NULL;
+
+virCheckFlags(0, -1);
+
+if (!(def = xenGetDomainDefForDom(dom)))
+goto cleanup;
+
+if (virDomainSendSysrqEnsureACL(dom-conn, def)  0)
+goto cleanup;
+
+ret = xenDaemonDomainSysrq(dom-conn, def, key);
+
+ cleanup:
+virDomainDefFree(def);
+return ret;
+}
 
 /*- Register with libvirt.c, and initialize Xen drivers. -*/
 
@@ -2836,6 +2856,7 @@ static virHypervisorDriver xenUnifiedDriver = {
 .nodeSuspendForDuration = xenUnifiedNodeSuspendForDuration, /* 0.9.8 */
 .nodeGetMemoryParameters = xenUnifiedNodeGetMemoryParameters, /* 0.10.2 */
 .nodeSetMemoryParameters = xenUnifiedNodeSetMemoryParameters, /* 0.10.2 */
+.domainSendSysrq = xenUnifiedDomainSendSysrq, /* 1.2.12 */
 };
 
 /**
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index b233b6b..77af8a0 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -3300,6 +3300,36 @@ xenDaemonDomainBlockPeek(virConnectPtr conn,
 return ret;
 }
 
+/*
+ * xenDaemonDomainSysrq:
+ *  at conn: the connection object
+ *  at def: the domain to destroy
+ *  at key: SysRq key
+ *
+ * Send a sysrq to a domain.
+ *
+ * Returns 0 in case of success, -1 (with errno) in case of error.
+ */
+int
+xenDaemonDomainSysrq(virConnectPtr conn, virDomainDefPtr def, char key)
+{
+char *buf;
+int ret;
+
+if (def-id  0) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _(Domain %s isn't running.), def-name);
+return -1;
+}
+
+if (virAsprintf(buf, %c, key)  0)
+return -1;
+
+ret = xend_op(conn, def-name, op, sysrq, key, buf, NULL);
+
+VIR_FREE(buf);
+return ret;
+}
 
 /**
  * virDomainXMLDevID:
diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h
index 814330d..02f9d9b 100644
--- a/src/xen/xend_internal.h
+++ b/src/xen/xend_internal.h
@@ -213,5 +213,6 @@ int xenDaemonSetSchedulerParameters(virConnectPtr conn,
 virDomainDefPtr def,
 virTypedParameterPtr params,
 int nparams);
+int xenDaemonDomainSysrq(virConnectPtr conn, virDomainDefPtr def, char key);
 
 #endif /* __XEND_INTERNAL_H_ */
-- 
1.8.4.5

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


[libvirt] [PATCH V4 4/5] libxl: implement .domainSendSysrq method

2015-01-11 Thread Chunyan Liu
Support .domainSendSysrq in libxl driver.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libxl/libxl_driver.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 4135670..5ae565e 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -4745,6 +4745,30 @@ libxlDomainMigrateConfirm3Params(virDomainPtr domain,
 return libxlDomainMigrationConfirm(driver, vm, flags, cancelled);
 }
 
+static int
+libxlDomainSendSysrq(virDomainPtr dom, char key, unsigned int flags)
+{
+virDomainObjPtr vm;
+libxlDomainObjPrivatePtr priv;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+if (!(vm = libxlDomObjFromDomain(dom)))
+goto cleanup;
+
+priv = vm-privateData;
+
+if (virDomainSendSysrqEnsureACL(dom-conn, vm-def)  0)
+goto cleanup;
+
+ret = libxl_send_sysrq(priv-ctx, vm-def-id, key);
+
+ cleanup:
+if (vm)
+virObjectUnlock(vm);
+return ret;
+}
 
 static virHypervisorDriver libxlDriver = {
 .no = VIR_DRV_LIBXL,
@@ -4840,6 +4864,7 @@ static virHypervisorDriver libxlDriver = {
 .domainMigratePerform3Params = libxlDomainMigratePerform3Params, /* 1.2.6 
*/
 .domainMigrateFinish3Params = libxlDomainMigrateFinish3Params, /* 1.2.6 */
 .domainMigrateConfirm3Params = libxlDomainMigrateConfirm3Params, /* 1.2.6 
*/
+.domainSendSysrq = libxlDomainSendSysrq, /* 1.2.12 */
 };
 
 static virStateDriver libxlStateDriver = {
-- 
1.8.4.5

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


[libvirt] [PATCH V4 3/5] virsh: add 'sysrq' command

2015-01-11 Thread Chunyan Liu
All domainSendSysrq related API should be manageable from
the virsh command line. So, expose 'virsh sysrq' command.

Signed-off-by: Chunyan Liu cy...@suse.com
---
Changes:
  * adjust code to follow general format and fix a memory leak

 tools/virsh-domain.c | 57 
 1 file changed, 57 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 750411b..43fa1d8 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -12289,6 +12289,57 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
 return ret = 0;
 }
 
+/*
+ * sysrq command
+ */
+static const vshCmdInfo info_sysrq[] = {
+{.name = help,
+ .data = N_(Send SysRq key to the guest)
+},
+{.name = desc,
+ .data = N_(Send SysRq key to the guest)
+},
+{.name = NULL}
+};
+
+static const vshCmdOptDef opts_sysrq[] = {
+{.name = domain,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_(domain name, id or uuid)
+},
+{.name = key,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_(the SysRq key)
+},
+{.name = NULL}
+};
+
+static bool
+cmdSysrq(vshControl *ctl, const vshCmd *cmd)
+{
+virDomainPtr dom;
+bool ret = false;
+const char *key = NULL;
+
+if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+return false;
+
+if (vshCommandOptStringReq(ctl, cmd, key, key)  0)
+goto cleanup;
+
+if (virDomainSendSysrq(dom, key[0], 0)  0)
+goto cleanup;
+
+ret = true;
+
+ cleanup:
+virDomainFree(dom);
+return ret;
+}
+
+
 const vshCmdDef domManagementCmds[] = {
 {.name = attach-device,
  .handler = cmdAttachDevice,
@@ -12808,5 +12859,11 @@ const vshCmdDef domManagementCmds[] = {
  .info = info_vncdisplay,
  .flags = 0
 },
+{.name = sysrq,
+ .handler = cmdSysrq,
+ .opts = opts_sysrq,
+ .info = info_sysrq,
+ .flags = 0
+},
 {.name = NULL}
 };
-- 
1.8.4.5

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


[libvirt] [PATCH V4 2/5] implement remote protocol for domainSendSysrq

2015-01-11 Thread Chunyan Liu
Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/remote/remote_driver.c   |  1 +
 src/remote/remote_protocol.x | 14 +-
 src/remote_protocol-structs  |  6 ++
 src/rpc/gendispatch.pl   | 12 
 4 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 999f16d..b24de5c 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8285,6 +8285,7 @@ static virHypervisorDriver hypervisor_driver = {
 .connectGetAllDomainStats = remoteConnectGetAllDomainStats, /* 1.2.8 */
 .nodeAllocPages = remoteNodeAllocPages, /* 1.2.9 */
 .domainGetFSInfo = remoteDomainGetFSInfo, /* 1.2.11 */
+.domainSendSysrq = remoteDomainSendSysrq, /* 1.2.12 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index cbd3ec7..708983c 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1084,6 +1084,12 @@ struct remote_domain_send_key_args {
 unsigned int flags;
 };
 
+struct remote_domain_send_sysrq_args {
+remote_nonnull_domain dom;
+char key;
+unsigned int flags;
+};
+
 struct remote_domain_send_process_signal_args {
 remote_nonnull_domain dom;
 hyper pid_value;
@@ -5550,5 +5556,11 @@ enum remote_procedure {
  * @generate: none
  * @acl: domain:fs_freeze
  */
-REMOTE_PROC_DOMAIN_GET_FSINFO = 349
+REMOTE_PROC_DOMAIN_GET_FSINFO = 349,
+
+/**
+ * @generate: both
+ * @acl: domain:send_input
+ */
+REMOTE_PROC_DOMAIN_SEND_SYSRQ = 350
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 2907fd5..afd9a8d 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2605,6 +2605,11 @@ struct remote_domain_get_fsinfo_ret {
 } info;
 u_int  ret;
 };
+struct remote_domain_send_sysrq_args {
+remote_nonnull_domain dom;
+char key;
+unsigned int flags;
+};
 enum remote_procedure {
 REMOTE_PROC_CONNECT_OPEN = 1,
 REMOTE_PROC_CONNECT_CLOSE = 2,
@@ -2955,4 +2960,5 @@ enum remote_procedure {
 REMOTE_PROC_NODE_ALLOC_PAGES = 347,
 REMOTE_PROC_DOMAIN_EVENT_CALLBACK_AGENT_LIFECYCLE = 348,
 REMOTE_PROC_DOMAIN_GET_FSINFO = 349,
+REMOTE_PROC_DOMAIN_SEND_SYSRQ = 350,
 };
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 0dc167a..cafe5ab 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -592,6 +592,12 @@ elsif ($mode eq server) {
 } else {
 push(@args_list, args-$arg_name);
 }
+} elsif ($args_member =~ m/^(unsigned )?char (\S+);/) {
+if (! @args_list) {
+push(@args_list, priv-conn);
+}
+
+push(@args_list, args-$2);
 } elsif ($args_member =~ m/^(\/)?\*/) {
 # ignore comments
 } else {
@@ -1228,6 +1234,12 @@ elsif ($mode eq client) {
 
 push(@args_list, $type_name $arg_name);
 push(@setters_list, args.$arg_name = $arg_name;);
+} elsif ($args_member =~ m/^((?:unsigned )?char) (\S+);/) {
+my $type_name = $1;
+my $arg_name = $2;
+
+push(@args_list, $type_name $arg_name);
+push(@setters_list, args.$arg_name = $arg_name;);
 } elsif ($args_member =~ m/^(\/)?\*/) {
 # ignore comments
 } else {
-- 
1.8.4.5

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


[libvirt] [PATCH V2 2/2] Add tests to xmconfigtest

2014-12-22 Thread Chunyan Liu
Add tests to testing HVM default features (pae, acpi, apic)
conversion from xm config to libvirt xml. If no pae|acpi|apic
specified in xm config, after conversion, libvirt xml should
by default include:
 features
   pae/
   apic/
   acpi/
 /features

Signed-off-by: Chunyan Liu cy...@suse.com
---
Changes to v1:
  * add testcase to test HVM default features conversion from
xm config to xml.
  * introduce DO_TEST_PARSE and DO_TEST_FORMAT to allow test
one direction only.

 .../xmconfigdata/test-fullvirt-default-feature.cfg | 23 +++
 .../xmconfigdata/test-fullvirt-default-feature.xml | 48 ++
 tests/xmconfigtest.c   | 20 -
 3 files changed, 89 insertions(+), 2 deletions(-)
 create mode 100644 tests/xmconfigdata/test-fullvirt-default-feature.cfg
 create mode 100644 tests/xmconfigdata/test-fullvirt-default-feature.xml

diff --git a/tests/xmconfigdata/test-fullvirt-default-feature.cfg 
b/tests/xmconfigdata/test-fullvirt-default-feature.cfg
new file mode 100644
index 000..5ce234f
--- /dev/null
+++ b/tests/xmconfigdata/test-fullvirt-default-feature.cfg
@@ -0,0 +1,23 @@
+name = XenGuest2
+uuid = c7a5fdb2-cdaf-9455-926a-d65c16db1809
+maxmem = 579
+memory = 394
+vcpus = 1
+builder = hvm
+kernel = /usr/lib/xen/boot/hvmloader
+boot = d
+hpet = 1
+localtime = 0
+on_poweroff = destroy
+on_reboot = restart
+on_crash = restart
+device_model = /usr/lib/xen/bin/qemu-dm
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = 127.0.0.1
+vncpasswd = 123poi
+vif = [ 
mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu ]
+parallel = none
+serial = none
+disk = [ phy:/dev/HostVG/XenGuest2,hda,w, file:/root/boot.iso,hdc:cdrom,r ]
diff --git a/tests/xmconfigdata/test-fullvirt-default-feature.xml 
b/tests/xmconfigdata/test-fullvirt-default-feature.xml
new file mode 100644
index 000..57a6531
--- /dev/null
+++ b/tests/xmconfigdata/test-fullvirt-default-feature.xml
@@ -0,0 +1,48 @@
+domain type='xen'
+  nameXenGuest2/name
+  uuidc7a5fdb2-cdaf-9455-926a-d65c16db1809/uuid
+  memory unit='KiB'592896/memory
+  currentMemory unit='KiB'403456/currentMemory
+  vcpu placement='static'1/vcpu
+  os
+type arch='i686' machine='xenfv'hvm/type
+loader type='rom'/usr/lib/xen/boot/hvmloader/loader
+boot dev='cdrom'/
+  /os
+  features
+acpi/
+apic/
+pae/
+  /features
+  clock offset='utc' adjustment='reset'
+timer name='hpet' present='yes'/
+  /clock
+  on_poweroffdestroy/on_poweroff
+  on_rebootrestart/on_reboot
+  on_crashrestart/on_crash
+  devices
+emulator/usr/lib/xen/bin/qemu-dm/emulator
+disk type='block' device='disk'
+  driver name='phy'/
+  source dev='/dev/HostVG/XenGuest2'/
+  target dev='hda' bus='ide'/
+/disk
+disk type='file' device='cdrom'
+  driver name='file'/
+  source file='/root/boot.iso'/
+  target dev='hdc' bus='ide'/
+  readonly/
+/disk
+interface type='bridge'
+  mac address='00:16:3e:66:92:9c'/
+  source bridge='xenbr1'/
+  script path='vif-bridge'/
+  model type='e1000'/
+/interface
+input type='mouse' bus='ps2'/
+input type='keyboard' bus='ps2'/
+graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' 
passwd='123poi'
+  listen type='address' address='127.0.0.1'/
+/graphics
+  /devices
+/domain
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index 0c6f803..8a49eb5 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -176,6 +176,7 @@ testCompareHelper(const void *data)
 const struct testInfo *info = data;
 char *xml = NULL;
 char *cfg = NULL;
+char *cfgout = NULL;
 
 if (virAsprintf(xml, %s/xmconfigdata/test-%s.xml,
 abs_srcdir, info-name)  0 ||
@@ -191,6 +192,7 @@ testCompareHelper(const void *data)
  cleanup:
 VIR_FREE(xml);
 VIR_FREE(cfg);
+VIR_FREE(cfgout);
 
 return result;
 }
@@ -207,18 +209,30 @@ mymain(void)
 if (!(xmlopt = xenDomainXMLConfInit()))
 return EXIT_FAILURE;
 
-#define DO_TEST(name, version)  \
+#define DO_TEST_PARSE(name, version)\
 do {\
 struct testInfo info0 = { name, version, 0 };   \
-struct testInfo info1 = { name, version, 1 };   \
 if (virtTestRun(Xen XM-2-XML Parse   name,\
 testCompareHelper, info0)  0) \
 ret = -1;   \
+} while (0)
+
+
+#define DO_TEST_FORMAT(name, version)   \
+do {\
+struct testInfo info1 = { name, version, 1 };   \
 if (virtTestRun(Xen XM-2-XML Format  name,\
 testCompareHelper

[libvirt] [PATCH V2 0/2] fix xen HVM pae|apic|acpi features parser

2014-12-22 Thread Chunyan Liu
According to xm.config manual, HVM pae|apic|acpi feature default
is 1 (enabled). But in conversion from xm config to libvirt xml,
if xm config doesn't contain pae|apic|acpi, it sets default value
to 0, this causes some problems in HVM guest.

Update parser codes to set HVM pae|apic|acpi default value to 1
to match xm config convension.

Add tests data to test it.

---
Changes to v1:
   * update xmconfigtest

Chunyan Liu (2):
  xenconfig: set HVM pae/apic/acpi/ default to 1
  Add tests to xmconfigtest

 src/xenconfig/xen_common.c |  6 +--
 .../xmconfigdata/test-fullvirt-default-feature.cfg | 23 +++
 .../xmconfigdata/test-fullvirt-default-feature.xml | 48 ++
 tests/xmconfigtest.c   | 20 -
 4 files changed, 92 insertions(+), 5 deletions(-)
 create mode 100644 tests/xmconfigdata/test-fullvirt-default-feature.cfg
 create mode 100644 tests/xmconfigdata/test-fullvirt-default-feature.xml

-- 
1.8.4.5

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


[libvirt] [PATCH V2 1/2] xenconfig: set HVM pae/apic/acpi/ default to 1

2014-12-22 Thread Chunyan Liu
According to xm.config manual, HVM pae|apic|acpi feature default
is 1 (enabled). But in conversion from xm config to libvirt xml,
if xm config doesn't contain pae|apic|acpi, it sets default value
to 0, this causes some problems in HVM guest.

Update parser codes to set HVM pae|apic|acpi default value to 1
to match xm config convension.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/xenconfig/xen_common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 25bdf26..221509a 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -512,17 +512,17 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
 return -1;
 
 if (STREQ(def-os.type, hvm)) {
-if (xenConfigGetBool(conf, pae, val, 0)  0)
+if (xenConfigGetBool(conf, pae, val, 1)  0)
 return -1;
 
 else if (val)
 def-features[VIR_DOMAIN_FEATURE_PAE] = VIR_TRISTATE_SWITCH_ON;
-if (xenConfigGetBool(conf, acpi, val, 0)  0)
+if (xenConfigGetBool(conf, acpi, val, 1)  0)
 return -1;
 
 else if (val)
 def-features[VIR_DOMAIN_FEATURE_ACPI] = VIR_TRISTATE_SWITCH_ON;
-if (xenConfigGetBool(conf, apic, val, 0)  0)
+if (xenConfigGetBool(conf, apic, val, 1)  0)
 return -1;
 
 else if (val)
-- 
1.8.4.5

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


[libvirt] [PATCH 0/2] fix xen HVM pae|apic|acpi features parser

2014-12-18 Thread Chunyan Liu
According to xm.config manual, HVM pae|apic|acpi feature default
is 1 (enabled). But in conversion from xm config to libvirt xml,
if xm config doesn't contain pae|apic|acpi, it sets default value
to 0, this causes some problems in HVM guest.

Update parser codes to set HVM pae|apic|acpi default value to 1
to match xm config convension.

Add tests data to test it.

Chunyan Liu (2):
  xenconfig: set HVM pae/apic/acpi/ default to 1
  Add tests to xmconfigtest

 src/xenconfig/xen_common.c |  6 +--
 .../xmconfigdata/test-fullvirt-default-feature.cfg | 23 +++
 .../test-fullvirt-default-feature.cfg.out  | 26 
 .../xmconfigdata/test-fullvirt-default-feature.xml | 48 ++
 tests/xmconfigtest.c   |  9 +++-
 5 files changed, 108 insertions(+), 4 deletions(-)
 create mode 100644 tests/xmconfigdata/test-fullvirt-default-feature.cfg
 create mode 100644 tests/xmconfigdata/test-fullvirt-default-feature.cfg.out
 create mode 100644 tests/xmconfigdata/test-fullvirt-default-feature.xml

-- 
1.8.4.5

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


[libvirt] [PATCH 2/2] Add tests to xmconfigtest

2014-12-18 Thread Chunyan Liu
Add tests to testing HVM default features (pae, acpi, apic)
conversion from xm config to libvirt xml and from libvirt
xml to xm config.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 .../xmconfigdata/test-fullvirt-default-feature.cfg | 23 +++
 .../test-fullvirt-default-feature.cfg.out  | 26 
 .../xmconfigdata/test-fullvirt-default-feature.xml | 48 ++
 tests/xmconfigtest.c   |  9 +++-
 4 files changed, 105 insertions(+), 1 deletion(-)
 create mode 100644 tests/xmconfigdata/test-fullvirt-default-feature.cfg
 create mode 100644 tests/xmconfigdata/test-fullvirt-default-feature.cfg.out
 create mode 100644 tests/xmconfigdata/test-fullvirt-default-feature.xml

diff --git a/tests/xmconfigdata/test-fullvirt-default-feature.cfg 
b/tests/xmconfigdata/test-fullvirt-default-feature.cfg
new file mode 100644
index 000..5ce234f
--- /dev/null
+++ b/tests/xmconfigdata/test-fullvirt-default-feature.cfg
@@ -0,0 +1,23 @@
+name = XenGuest2
+uuid = c7a5fdb2-cdaf-9455-926a-d65c16db1809
+maxmem = 579
+memory = 394
+vcpus = 1
+builder = hvm
+kernel = /usr/lib/xen/boot/hvmloader
+boot = d
+hpet = 1
+localtime = 0
+on_poweroff = destroy
+on_reboot = restart
+on_crash = restart
+device_model = /usr/lib/xen/bin/qemu-dm
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = 127.0.0.1
+vncpasswd = 123poi
+vif = [ 
mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu ]
+parallel = none
+serial = none
+disk = [ phy:/dev/HostVG/XenGuest2,hda,w, file:/root/boot.iso,hdc:cdrom,r ]
diff --git a/tests/xmconfigdata/test-fullvirt-default-feature.cfg.out 
b/tests/xmconfigdata/test-fullvirt-default-feature.cfg.out
new file mode 100644
index 000..97a9827
--- /dev/null
+++ b/tests/xmconfigdata/test-fullvirt-default-feature.cfg.out
@@ -0,0 +1,26 @@
+name = XenGuest2
+uuid = c7a5fdb2-cdaf-9455-926a-d65c16db1809
+maxmem = 579
+memory = 394
+vcpus = 1
+builder = hvm
+kernel = /usr/lib/xen/boot/hvmloader
+boot = d
+pae = 1
+acpi = 1
+apic = 1
+hpet = 1
+localtime = 0
+on_poweroff = destroy
+on_reboot = restart
+on_crash = restart
+device_model = /usr/lib/xen/bin/qemu-dm
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = 127.0.0.1
+vncpasswd = 123poi
+vif = [ 
mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu ]
+parallel = none
+serial = none
+disk = [ phy:/dev/HostVG/XenGuest2,hda,w, file:/root/boot.iso,hdc:cdrom,r ]
diff --git a/tests/xmconfigdata/test-fullvirt-default-feature.xml 
b/tests/xmconfigdata/test-fullvirt-default-feature.xml
new file mode 100644
index 000..57a6531
--- /dev/null
+++ b/tests/xmconfigdata/test-fullvirt-default-feature.xml
@@ -0,0 +1,48 @@
+domain type='xen'
+  nameXenGuest2/name
+  uuidc7a5fdb2-cdaf-9455-926a-d65c16db1809/uuid
+  memory unit='KiB'592896/memory
+  currentMemory unit='KiB'403456/currentMemory
+  vcpu placement='static'1/vcpu
+  os
+type arch='i686' machine='xenfv'hvm/type
+loader type='rom'/usr/lib/xen/boot/hvmloader/loader
+boot dev='cdrom'/
+  /os
+  features
+acpi/
+apic/
+pae/
+  /features
+  clock offset='utc' adjustment='reset'
+timer name='hpet' present='yes'/
+  /clock
+  on_poweroffdestroy/on_poweroff
+  on_rebootrestart/on_reboot
+  on_crashrestart/on_crash
+  devices
+emulator/usr/lib/xen/bin/qemu-dm/emulator
+disk type='block' device='disk'
+  driver name='phy'/
+  source dev='/dev/HostVG/XenGuest2'/
+  target dev='hda' bus='ide'/
+/disk
+disk type='file' device='cdrom'
+  driver name='file'/
+  source file='/root/boot.iso'/
+  target dev='hdc' bus='ide'/
+  readonly/
+/disk
+interface type='bridge'
+  mac address='00:16:3e:66:92:9c'/
+  source bridge='xenbr1'/
+  script path='vif-bridge'/
+  model type='e1000'/
+/interface
+input type='mouse' bus='ps2'/
+input type='keyboard' bus='ps2'/
+graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' 
passwd='123poi'
+  listen type='address' address='127.0.0.1'/
+/graphics
+  /devices
+/domain
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index 0c6f803..b0b7b30 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -176,21 +176,26 @@ testCompareHelper(const void *data)
 const struct testInfo *info = data;
 char *xml = NULL;
 char *cfg = NULL;
+char *cfgout = NULL;
 
 if (virAsprintf(xml, %s/xmconfigdata/test-%s.xml,
 abs_srcdir, info-name)  0 ||
 virAsprintf(cfg, %s/xmconfigdata/test-%s.cfg,
+abs_srcdir, info-name)  0 ||
+virAsprintf(cfgout, %s/xmconfigdata/test-%s.cfg.out,
 abs_srcdir, info-name)  0)
 goto cleanup;
 
 if (info-mode == 0)
-result = testCompareParseXML(cfg, xml, info-version);
+result = testCompareParseXML(virFileExists(cfgout) ? cfgout : cfg,
+ xml, info-version);
 else
 result = testCompareFormatXML(cfg

[libvirt] [PATCH 1/2] xenconfig: set HVM pae/apic/acpi/ default to 1

2014-12-18 Thread Chunyan Liu
According to xm.config manual, HVM pae|apic|acpi feature default
is 1 (enabled). But in conversion from xm config to libvirt xml,
if xm config doesn't contain pae|apic|acpi, it sets default value
to 0, this causes some problems in HVM guest.

Update parser codes to set HVM pae|apic|acpi default value to 1
to match xm config convension.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/xenconfig/xen_common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 25bdf26..221509a 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -512,17 +512,17 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
 return -1;
 
 if (STREQ(def-os.type, hvm)) {
-if (xenConfigGetBool(conf, pae, val, 0)  0)
+if (xenConfigGetBool(conf, pae, val, 1)  0)
 return -1;
 
 else if (val)
 def-features[VIR_DOMAIN_FEATURE_PAE] = VIR_TRISTATE_SWITCH_ON;
-if (xenConfigGetBool(conf, acpi, val, 0)  0)
+if (xenConfigGetBool(conf, acpi, val, 1)  0)
 return -1;
 
 else if (val)
 def-features[VIR_DOMAIN_FEATURE_ACPI] = VIR_TRISTATE_SWITCH_ON;
-if (xenConfigGetBool(conf, apic, val, 0)  0)
+if (xenConfigGetBool(conf, apic, val, 1)  0)
 return -1;
 
 else if (val)
-- 
1.8.4.5

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


[libvirt] [PATCH V3 1/5] Add public API virDomainSendSysrq

2014-12-17 Thread Chunyan Liu
Add public API virDomainSendSysrq for sending SysRequest key.

Signed-off-by: Chunyan Liu cy...@suse.com
---
changes:
  * add 'flags' to the new API
  * change parameter from 'const char *key' to 'char key'
  * change version number from 1.2.11 to 1.2.12

 include/libvirt/libvirt-domain.h |  3 +++
 src/driver-hypervisor.h  |  4 
 src/libvirt-domain.c | 39 +++
 src/libvirt_public.syms  |  5 +
 4 files changed, 51 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index baef32d..5f72850 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -3526,6 +3526,9 @@ int virDomainGetFSInfo(virDomainPtr dom,
virDomainFSInfoPtr **info,
unsigned int flags);
 
+/* virDomainSendSysrq */
+int virDomainSendSysrq(virDomainPtr dom, char key, unsigned int flags);
+
 int virDomainGetTime(virDomainPtr dom,
  long long *seconds,
  unsigned int *nseconds,
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 9f26b13..d260d29 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -1170,6 +1170,9 @@ typedef int
 unsigned int cellCount,
 unsigned int flags);
 
+typedef int
+(*virDrvDomainSendSysrq)(virDomainPtr dom, char key, unsigned int flags);
+
 
 typedef struct _virHypervisorDriver virHypervisorDriver;
 typedef virHypervisorDriver *virHypervisorDriverPtr;
@@ -1396,6 +1399,7 @@ struct _virHypervisorDriver {
 virDrvConnectGetAllDomainStats connectGetAllDomainStats;
 virDrvNodeAllocPages nodeAllocPages;
 virDrvDomainGetFSInfo domainGetFSInfo;
+virDrvDomainSendSysrq domainSendSysrq;
 };
 
 
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index cb76d8c..d58ec87 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -11192,3 +11192,42 @@ virDomainFSInfoFree(virDomainFSInfoPtr info)
 VIR_FREE(info-devAlias[i]);
 VIR_FREE(info-devAlias);
 }
+
+
+/**
+ * virDomainSendSysrq:
+ * @domain:pointer to domain object, or NULL for Domain0
+ * @key:SysRq key, like h, c, ...
+ * @flags:  extra flags; not used yet, so callers should always pass 0
+ *
+ * Send SysRq key to the guest.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+int
+virDomainSendSysrq(virDomainPtr domain, char key, unsigned int flags)
+{
+virConnectPtr conn;
+VIR_DOMAIN_DEBUG(domain, key=%c, flags=%x, key, flags);
+
+virResetLastError();
+
+virCheckDomainReturn(domain, -1);
+conn = domain-conn;
+
+virCheckReadOnlyGoto(conn-flags, error);
+
+if (conn-driver-domainSendSysrq) {
+int ret;
+ret = conn-driver-domainSendSysrq(domain, key, flags);
+if (ret  0)
+goto error;
+return ret;
+}
+
+virReportUnsupportedError();
+
+ error:
+virDispatchError(domain-conn);
+return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index e4c2df1..5d4999a 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -690,4 +690,9 @@ LIBVIRT_1.2.11 {
 virDomainGetFSInfo;
 } LIBVIRT_1.2.9;
 
+LIBVIRT_1.2.12 {
+global:
+virDomainSendSysrq;
+} LIBVIRT_1.2.11;
+
 #  define new API here using predicted next version number 
-- 
1.8.4.5

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


[libvirt] [PATCH V3 5/5] xen: add .domainSendSysrq method

2014-12-17 Thread Chunyan Liu
Support sending sysrq key to guest.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/xen/xen_driver.c| 21 +
 src/xen/xend_internal.c | 26 ++
 src/xen/xend_internal.h |  1 +
 3 files changed, 48 insertions(+)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index c9f4159..4a56b69 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2738,6 +2738,26 @@ xenUnifiedNodeSuspendForDuration(virConnectPtr conn,
 return nodeSuspendForDuration(target, duration, flags);
 }
 
+static int
+xenUnifiedDomainSendSysrq(virDomainPtr dom, char key, unsigned int flags)
+{
+int ret = -1;
+virDomainDefPtr def = NULL;
+
+virCheckFlags(0, -1);
+
+if (!(def = xenGetDomainDefForDom(dom)))
+goto cleanup;
+
+if (virDomainSendSysrqEnsureACL(dom-conn, def)  0)
+goto cleanup;
+
+ret = xenDaemonDomainSysrq(dom-conn, def, key);
+
+ cleanup:
+virDomainDefFree(def);
+return ret;
+}
 
 /*- Register with libvirt.c, and initialize Xen drivers. -*/
 
@@ -2836,6 +2856,7 @@ static virHypervisorDriver xenUnifiedDriver = {
 .nodeSuspendForDuration = xenUnifiedNodeSuspendForDuration, /* 0.9.8 */
 .nodeGetMemoryParameters = xenUnifiedNodeGetMemoryParameters, /* 0.10.2 */
 .nodeSetMemoryParameters = xenUnifiedNodeSetMemoryParameters, /* 0.10.2 */
+.domainSendSysrq = xenUnifiedDomainSendSysrq, /* 1.2.12 */
 };
 
 /**
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index b233b6b..16532ad 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -3300,6 +3300,32 @@ xenDaemonDomainBlockPeek(virConnectPtr conn,
 return ret;
 }
 
+/*
+ * xenDaemonDomainSysrq:
+ *  at conn: the connection object
+ *  at def: the domain to destroy
+ *  at key: SysRq key
+ *
+ * Send a sysrq to a domain.
+ *
+ * Returns 0 in case of success, -1 (with errno) in case of error.
+ */
+int
+xenDaemonDomainSysrq(virConnectPtr conn, virDomainDefPtr def, char key)
+{
+char *buf;
+
+if (def-id  0) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _(Domain %s isn't running.), def-name);
+return -1;
+}
+
+if (virAsprintf(buf, %c, key)  0)
+return -1;
+
+return xend_op(conn, def-name, op, sysrq, key, buf, NULL);
+}
 
 /**
  * virDomainXMLDevID:
diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h
index 814330d..02f9d9b 100644
--- a/src/xen/xend_internal.h
+++ b/src/xen/xend_internal.h
@@ -213,5 +213,6 @@ int xenDaemonSetSchedulerParameters(virConnectPtr conn,
 virDomainDefPtr def,
 virTypedParameterPtr params,
 int nparams);
+int xenDaemonDomainSysrq(virConnectPtr conn, virDomainDefPtr def, char key);
 
 #endif /* __XEND_INTERNAL_H_ */
-- 
1.8.4.5

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


[libvirt] [PATCH V3 2/5] implement remote protocol for domainSendSysrq

2014-12-17 Thread Chunyan Liu
Signed-off-by: Chunyan Liu cy...@suse.com
---
Changes:
  * change args 'key' from 'remote_nonnull_string' to 'char'
  * add code to gendispatch.pl to handle 'char|unsigned char' type
  * update remote_protocol-strcuts

 src/remote/remote_driver.c   |  1 +
 src/remote/remote_protocol.x | 14 +-
 src/remote_protocol-structs  |  6 ++
 src/rpc/gendispatch.pl   | 12 
 4 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 999f16d..b24de5c 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8285,6 +8285,7 @@ static virHypervisorDriver hypervisor_driver = {
 .connectGetAllDomainStats = remoteConnectGetAllDomainStats, /* 1.2.8 */
 .nodeAllocPages = remoteNodeAllocPages, /* 1.2.9 */
 .domainGetFSInfo = remoteDomainGetFSInfo, /* 1.2.11 */
+.domainSendSysrq = remoteDomainSendSysrq, /* 1.2.12 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index cbd3ec7..708983c 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1084,6 +1084,12 @@ struct remote_domain_send_key_args {
 unsigned int flags;
 };
 
+struct remote_domain_send_sysrq_args {
+remote_nonnull_domain dom;
+char key;
+unsigned int flags;
+};
+
 struct remote_domain_send_process_signal_args {
 remote_nonnull_domain dom;
 hyper pid_value;
@@ -5550,5 +5556,11 @@ enum remote_procedure {
  * @generate: none
  * @acl: domain:fs_freeze
  */
-REMOTE_PROC_DOMAIN_GET_FSINFO = 349
+REMOTE_PROC_DOMAIN_GET_FSINFO = 349,
+
+/**
+ * @generate: both
+ * @acl: domain:send_input
+ */
+REMOTE_PROC_DOMAIN_SEND_SYSRQ = 350
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 2907fd5..afd9a8d 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2605,6 +2605,11 @@ struct remote_domain_get_fsinfo_ret {
 } info;
 u_int  ret;
 };
+struct remote_domain_send_sysrq_args {
+remote_nonnull_domain dom;
+char key;
+unsigned int flags;
+};
 enum remote_procedure {
 REMOTE_PROC_CONNECT_OPEN = 1,
 REMOTE_PROC_CONNECT_CLOSE = 2,
@@ -2955,4 +2960,5 @@ enum remote_procedure {
 REMOTE_PROC_NODE_ALLOC_PAGES = 347,
 REMOTE_PROC_DOMAIN_EVENT_CALLBACK_AGENT_LIFECYCLE = 348,
 REMOTE_PROC_DOMAIN_GET_FSINFO = 349,
+REMOTE_PROC_DOMAIN_SEND_SYSRQ = 350,
 };
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 0dc167a..cafe5ab 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -592,6 +592,12 @@ elsif ($mode eq server) {
 } else {
 push(@args_list, args-$arg_name);
 }
+} elsif ($args_member =~ m/^(unsigned )?char (\S+);/) {
+if (! @args_list) {
+push(@args_list, priv-conn);
+}
+
+push(@args_list, args-$2);
 } elsif ($args_member =~ m/^(\/)?\*/) {
 # ignore comments
 } else {
@@ -1228,6 +1234,12 @@ elsif ($mode eq client) {
 
 push(@args_list, $type_name $arg_name);
 push(@setters_list, args.$arg_name = $arg_name;);
+} elsif ($args_member =~ m/^((?:unsigned )?char) (\S+);/) {
+my $type_name = $1;
+my $arg_name = $2;
+
+push(@args_list, $type_name $arg_name);
+push(@setters_list, args.$arg_name = $arg_name;);
 } elsif ($args_member =~ m/^(\/)?\*/) {
 # ignore comments
 } else {
-- 
1.8.4.5

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


[libvirt] [PATCH V3 4/5] libxl: implement .domainSendSysrq method

2014-12-17 Thread Chunyan Liu
Support .domainSendSysrq in libxl driver.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libxl/libxl_driver.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 53c87ce..7c96bab 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -4729,6 +4729,30 @@ libxlDomainMigrateConfirm3Params(virDomainPtr domain,
 return libxlDomainMigrationConfirm(driver, vm, flags, cancelled);
 }
 
+static int
+libxlDomainSendSysrq(virDomainPtr dom, char key, unsigned int flags)
+{
+virDomainObjPtr vm;
+libxlDomainObjPrivatePtr priv;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+if (!(vm = libxlDomObjFromDomain(dom)))
+goto cleanup;
+
+priv = vm-privateData;
+
+if (virDomainSendSysrqEnsureACL(dom-conn, vm-def)  0)
+goto cleanup;
+
+ret = libxl_send_sysrq(priv-ctx, vm-def-id, key);
+
+ cleanup:
+if (vm)
+virObjectUnlock(vm);
+return ret;
+}
 
 static virHypervisorDriver libxlDriver = {
 .no = VIR_DRV_LIBXL,
@@ -4824,6 +4848,7 @@ static virHypervisorDriver libxlDriver = {
 .domainMigratePerform3Params = libxlDomainMigratePerform3Params, /* 1.2.6 
*/
 .domainMigrateFinish3Params = libxlDomainMigrateFinish3Params, /* 1.2.6 */
 .domainMigrateConfirm3Params = libxlDomainMigrateConfirm3Params, /* 1.2.6 
*/
+.domainSendSysrq = libxlDomainSendSysrq, /* 1.2.12 */
 };
 
 static virStateDriver libxlStateDriver = {
-- 
1.8.4.5

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


[libvirt] [PATCH V3 0/5] support sending sysrq key

2014-12-17 Thread Chunyan Liu
xend/libxl support sending sysrq key to guest kernel but not support
sending any key sequence as virDomainSendKey is expected to do. To
add equivalant sysrq functionality in libvirt for xen/libxl, add a new
virDomainSendSysrq API and add related codes to virsh, remote driver,
xen/libxl driver.


Changes to V2:
  * change parameter from 'const char *key' to 'char key'.
  * add 'flags' parameter to virDomainSendSysrq API.
  * update codes to fit for above changes.

  V2 is here:
  http://www.mail-archive.com/libvir-list@redhat.com/msg106106.html

Chunyan Liu (5):
  Add public API virDomainSendSysrq
  implement remote protocol for domainSendSysrq
  virsh: add 'sysrq' command
  libxl: implement .domainSendSysrq method
  xen: add .domainSendSysrq method

 include/libvirt/libvirt-domain.h |  3 +++
 src/driver-hypervisor.h  |  4 +++
 src/libvirt-domain.c | 39 +
 src/libvirt_public.syms  |  5 
 src/libxl/libxl_driver.c | 25 +++
 src/remote/remote_driver.c   |  1 +
 src/remote/remote_protocol.x | 14 ++-
 src/remote_protocol-structs  |  6 +
 src/rpc/gendispatch.pl   | 12 +
 src/xen/xen_driver.c | 21 
 src/xen/xend_internal.c  | 21 
 src/xen/xend_internal.h  |  1 +
 tools/virsh-domain.c | 54 
 13 files changed, 205 insertions(+), 1 deletion(-)

-- 
1.8.4.5

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


[libvirt] [PATCH V3 3/5] virsh: add 'sysrq' command

2014-12-17 Thread Chunyan Liu
All domainSendSysrq related API should be manageable from
the virsh command line. So, expose 'virsh sysrq' command.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 tools/virsh-domain.c | 54 
 1 file changed, 54 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 750411b..bffcc8e 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -12289,6 +12289,54 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
 return ret = 0;
 }
 
+/*
+ * sysrq command
+ */
+static const vshCmdInfo info_sysrq[] = {
+{.name = help,
+ .data = N_(Send SysRq key to the guest)
+},
+{.name = desc,
+ .data = N_(Send SysRq key to the guest)
+},
+{.name = NULL}
+};
+
+static const vshCmdOptDef opts_sysrq[] = {
+{.name = domain,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_(domain name, id or uuid)
+},
+{.name = key,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_(the SysRq key)
+},
+{.name = NULL}
+};
+
+static bool
+cmdSysrq(vshControl *ctl, const vshCmd *cmd)
+{
+virDomainPtr dom;
+bool ret = false;
+const char *key = NULL;
+
+if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+return false;
+
+if (vshCommandOptStringReq(ctl, cmd, key, key)  0)
+return false;
+
+if (!(virDomainSendSysrq(dom, key[0], 0)  0))
+ret = true;
+
+virDomainFree(dom);
+return ret;
+}
+
+
 const vshCmdDef domManagementCmds[] = {
 {.name = attach-device,
  .handler = cmdAttachDevice,
@@ -12808,5 +12856,11 @@ const vshCmdDef domManagementCmds[] = {
  .info = info_vncdisplay,
  .flags = 0
 },
+{.name = sysrq,
+ .handler = cmdSysrq,
+ .opts = opts_sysrq,
+ .info = info_sysrq,
+ .flags = 0
+},
 {.name = NULL}
 };
-- 
1.8.4.5

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


[libvirt] [PATCH V2 1/5] Add public API virDomainSendSysrq

2014-12-12 Thread Chunyan Liu
Add public API virDomainSendSysrq for sending SysRequest key.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 include/libvirt/libvirt-domain.h |  3 +++
 src/driver-hypervisor.h  |  4 
 src/libvirt-domain.c | 38 ++
 src/libvirt_public.syms  |  1 +
 4 files changed, 46 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index ae2c49c..73ef6c8 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -3519,6 +3519,9 @@ int virDomainGetFSInfo(virDomainPtr dom,
virDomainFSInfoPtr **info,
unsigned int flags);
 
+/* virDomainSendSysrq */
+int virDomainSendSysrq(virDomainPtr dom, const char *key);
+
 int virDomainGetTime(virDomainPtr dom,
  long long *seconds,
  unsigned int *nseconds,
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 9f26b13..79558c3 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -1170,6 +1170,9 @@ typedef int
 unsigned int cellCount,
 unsigned int flags);
 
+typedef int
+(*virDrvDomainSendSysrq)(virDomainPtr dom, const char *key);
+
 
 typedef struct _virHypervisorDriver virHypervisorDriver;
 typedef virHypervisorDriver *virHypervisorDriverPtr;
@@ -1396,6 +1399,7 @@ struct _virHypervisorDriver {
 virDrvConnectGetAllDomainStats connectGetAllDomainStats;
 virDrvNodeAllocPages nodeAllocPages;
 virDrvDomainGetFSInfo domainGetFSInfo;
+virDrvDomainSendSysrq domainSendSysrq;
 };
 
 
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index cb76d8c..4658fd7 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -11192,3 +11192,41 @@ virDomainFSInfoFree(virDomainFSInfoPtr info)
 VIR_FREE(info-devAlias[i]);
 VIR_FREE(info-devAlias);
 }
+
+
+/**
+ * virDomainSendSysrq:
+ * @domain:pointer to domain object, or NULL for Domain0
+ * @key:SysRq key, like h, c, ...
+ *
+ * Send SysRq key to the guest.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+int
+virDomainSendSysrq(virDomainPtr domain, const char *key)
+{
+virConnectPtr conn;
+VIR_DOMAIN_DEBUG(domain, key=%s, key);
+
+virResetLastError();
+
+virCheckDomainReturn(domain, -1);
+conn = domain-conn;
+
+virCheckReadOnlyGoto(conn-flags, error);
+
+if (conn-driver-domainSendSysrq) {
+int ret;
+ret = conn-driver-domainSendSysrq(domain, key);
+if (ret  0)
+goto error;
+return ret;
+}
+
+virReportUnsupportedError();
+
+ error:
+virDispatchError(domain-conn);
+return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index e4c2df1..80d1dd2 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -688,6 +688,7 @@ LIBVIRT_1.2.11 {
 global:
 virDomainFSInfoFree;
 virDomainGetFSInfo;
+virDomainSendSysrq;
 } LIBVIRT_1.2.9;
 
 #  define new API here using predicted next version number 
-- 
1.8.4.5

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


[libvirt] [PATCH V2 3/5] virsh: add 'sysrq' command

2014-12-12 Thread Chunyan Liu
All domainSendSysrq related API should be manageable from
the virsh command line. So, expose 'virsh sysrq' command.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 tools/virsh-domain.c | 54 
 1 file changed, 54 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 750411b..6a1e4fd 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -12289,6 +12289,54 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
 return ret = 0;
 }
 
+/*
+ * sysrq command
+ */
+static const vshCmdInfo info_sysrq[] = {
+{.name = help,
+ .data = N_(Send SysRq key to the guest)
+},
+{.name = desc,
+ .data = N_(Send SysRq key to the guest)
+},
+{.name = NULL}
+};
+
+static const vshCmdOptDef opts_sysrq[] = {
+{.name = domain,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_(domain name, id or uuid)
+},
+{.name = key,
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_(the SysRq key)
+},
+{.name = NULL}
+};
+
+static bool
+cmdSysrq(vshControl *ctl, const vshCmd *cmd)
+{
+virDomainPtr dom;
+bool ret = false;
+const char *key = NULL;
+
+if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+return false;
+
+if (vshCommandOptStringReq(ctl, cmd, key, key)  0)
+return false;
+
+if (!(virDomainSendSysrq(dom, key)  0))
+ret = true;
+
+virDomainFree(dom);
+return ret;
+}
+
+
 const vshCmdDef domManagementCmds[] = {
 {.name = attach-device,
  .handler = cmdAttachDevice,
@@ -12808,5 +12856,11 @@ const vshCmdDef domManagementCmds[] = {
  .info = info_vncdisplay,
  .flags = 0
 },
+{.name = sysrq,
+ .handler = cmdSysrq,
+ .opts = opts_sysrq,
+ .info = info_sysrq,
+ .flags = 0
+},
 {.name = NULL}
 };
-- 
1.8.4.5

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


[libvirt] [PATCH V2 5/5] xen: add .domainSendSysrq method

2014-12-12 Thread Chunyan Liu
Support .domainSendSysrq in xen driver.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/xen/xen_driver.c| 19 +++
 src/xen/xend_internal.c | 20 
 src/xen/xend_internal.h |  2 ++
 3 files changed, 41 insertions(+)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index c9f4159..e2b01cf 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2738,6 +2738,24 @@ xenUnifiedNodeSuspendForDuration(virConnectPtr conn,
 return nodeSuspendForDuration(target, duration, flags);
 }
 
+static int
+xenUnifiedDomainSendSysrq(virDomainPtr dom, const char *key)
+{
+int ret = -1;
+virDomainDefPtr def = NULL;
+
+if (!(def = xenGetDomainDefForDom(dom)))
+goto cleanup;
+
+if (virDomainSendSysrqEnsureACL(dom-conn, def)  0)
+goto cleanup;
+
+ret = xenDaemonDomainSysrq(dom-conn, def, key);
+
+ cleanup:
+virDomainDefFree(def);
+return ret;
+}
 
 /*- Register with libvirt.c, and initialize Xen drivers. -*/
 
@@ -2836,6 +2854,7 @@ static virHypervisorDriver xenUnifiedDriver = {
 .nodeSuspendForDuration = xenUnifiedNodeSuspendForDuration, /* 0.9.8 */
 .nodeGetMemoryParameters = xenUnifiedNodeGetMemoryParameters, /* 0.10.2 */
 .nodeSetMemoryParameters = xenUnifiedNodeSetMemoryParameters, /* 0.10.2 */
+.domainSendSysrq = xenUnifiedDomainSendSysrq, /* 1.2.11 */
 };
 
 /**
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index b233b6b..62b6e31 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -3300,6 +3300,26 @@ xenDaemonDomainBlockPeek(virConnectPtr conn,
 return ret;
 }
 
+/*
+ * xenDaemonDomainSysrq:
+ *  at conn: the connection object
+ *  at def: the domain to destroy
+ *
+ * Send a sysrq to a domain.
+ *
+ * Returns 0 in case of success, -1 (with errno) in case of error.
+ */
+int
+xenDaemonDomainSysrq(virConnectPtr conn, virDomainDefPtr def, const char *key)
+{
+if (def-id  0) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _(Domain %s isn't running.), def-name);
+return -1;
+}
+
+return xend_op(conn, def-name, op, sysrq, key, key, NULL);
+}
 
 /**
  * virDomainXMLDevID:
diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h
index 814330d..26ab5e3 100644
--- a/src/xen/xend_internal.h
+++ b/src/xen/xend_internal.h
@@ -213,5 +213,7 @@ int xenDaemonSetSchedulerParameters(virConnectPtr conn,
 virDomainDefPtr def,
 virTypedParameterPtr params,
 int nparams);
+int xenDaemonDomainSysrq(virConnectPtr conn, virDomainDefPtr def,
+ const char *key);
 
 #endif /* __XEND_INTERNAL_H_ */
-- 
1.8.4.5

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


[libvirt] [PATCH V2 2/5] implement remote protocol for domainSendSysrq

2014-12-12 Thread Chunyan Liu
Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/remote/remote_driver.c   |  2 +-
 src/remote/remote_protocol.x | 13 -
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 999f16d..97ea64b 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -7941,7 +7941,6 @@ remoteDomainGetFSInfo(virDomainPtr dom,
 return rv;
 }
 
-
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
  * (name, uuid) pair into virDomainPtr or virNetworkPtr object.
  * These can return NULL if underlying memory allocations fail,
@@ -8285,6 +8284,7 @@ static virHypervisorDriver hypervisor_driver = {
 .connectGetAllDomainStats = remoteConnectGetAllDomainStats, /* 1.2.8 */
 .nodeAllocPages = remoteNodeAllocPages, /* 1.2.9 */
 .domainGetFSInfo = remoteDomainGetFSInfo, /* 1.2.11 */
+.domainSendSysrq = remoteDomainSendSysrq, /* 1.2.11 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index cbd3ec7..d988182 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1084,6 +1084,11 @@ struct remote_domain_send_key_args {
 unsigned int flags;
 };
 
+struct remote_domain_send_sysrq_args {
+remote_nonnull_domain dom;
+remote_nonnull_string key;
+};
+
 struct remote_domain_send_process_signal_args {
 remote_nonnull_domain dom;
 hyper pid_value;
@@ -5550,5 +,11 @@ enum remote_procedure {
  * @generate: none
  * @acl: domain:fs_freeze
  */
-REMOTE_PROC_DOMAIN_GET_FSINFO = 349
+REMOTE_PROC_DOMAIN_GET_FSINFO = 349,
+
+/**
+ * @generate: both
+ * @acl: domain:send_input
+ */
+REMOTE_PROC_DOMAIN_SEND_SYSRQ = 350
 };
-- 
1.8.4.5

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


[libvirt] [PATCH V2 4/5] libxl: implement .domainSendSysrq method

2014-12-12 Thread Chunyan Liu
Support .domainSendSysrq in libxl driver.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libxl/libxl_driver.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 53c87ce..0830d68 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -4729,6 +4729,28 @@ libxlDomainMigrateConfirm3Params(virDomainPtr domain,
 return libxlDomainMigrationConfirm(driver, vm, flags, cancelled);
 }
 
+static int
+libxlDomainSendSysrq(virDomainPtr dom, const char *key)
+{
+virDomainObjPtr vm;
+libxlDomainObjPrivatePtr priv;
+int ret = -1;
+
+if (!(vm = libxlDomObjFromDomain(dom)))
+goto cleanup;
+
+priv = vm-privateData;
+
+if (virDomainSendSysrqEnsureACL(dom-conn, vm-def)  0)
+goto cleanup;
+
+ret = libxl_send_sysrq(priv-ctx, vm-def-id, key[0]);
+
+ cleanup:
+if (vm)
+virObjectUnlock(vm);
+return ret;
+}
 
 static virHypervisorDriver libxlDriver = {
 .no = VIR_DRV_LIBXL,
@@ -4824,6 +4846,7 @@ static virHypervisorDriver libxlDriver = {
 .domainMigratePerform3Params = libxlDomainMigratePerform3Params, /* 1.2.6 
*/
 .domainMigrateFinish3Params = libxlDomainMigrateFinish3Params, /* 1.2.6 */
 .domainMigrateConfirm3Params = libxlDomainMigrateConfirm3Params, /* 1.2.6 
*/
+.domainSendSysrq = libxlDomainSendSysrq, /* 1.2.11 */
 };
 
 static virStateDriver libxlStateDriver = {
-- 
1.8.4.5

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


[libvirt] [PATCH V2 0/5] support sending sysrq key

2014-12-12 Thread Chunyan Liu
xend/libxl support sending sysrq key to guest kernel but not support
sending any key sequence as virDomainSendKey is expected to do. To
add equivalant sysrq functionality in libvirt for xen/libxl, add a new
virDomainSendSysrq API and add related codes to virsh, remote driver,
xen/libxl driver.

Changes:
  * add new API virDomainSendSysrq instead of hacking virDomainSendKey.
  * add related changes according to new API, including libvirt API,
remote protocol, virsh and libxl/xen driver.

  v1 is here:
  https://www.redhat.com/archives/libvir-list/2014-December/msg00480.html

Chunyan Liu (5):
  Add public API virDomainSendSysrq
  implement remote protocol for domainSendSysrq
  virsh: add 'sysrq' command
  libxl: implement .domainSendSysrq method
  xen: add .domainSendSysrq method

 include/libvirt/libvirt-domain.h |  3 +++
 src/driver-hypervisor.h  |  4 +++
 src/libvirt-domain.c | 38 
 src/libvirt_public.syms  |  1 +
 src/libxl/libxl_driver.c | 23 +
 src/remote/remote_driver.c   |  2 +-
 src/remote/remote_protocol.x | 13 +-
 src/xen/xen_driver.c | 19 ++
 src/xen/xend_internal.c  | 20 +++
 src/xen/xend_internal.h  |  2 ++
 tools/virsh-domain.c | 54 
 11 files changed, 177 insertions(+), 2 deletions(-)

-- 
1.8.4.5

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


[libvirt] [PATCH 3/3] libxl: add .domainSendKey

2014-12-08 Thread Chunyan Liu
libxl supports sysrq. Add .domainSendKey function to support
sending sysrq key.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libxl/libxl_driver.c | 89 
 1 file changed, 89 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 53c87ce..6cc5fe6 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -56,6 +56,7 @@
 #include viratomic.h
 #include virhostdev.h
 #include network/bridge_driver.h
+#include virkeycode.h
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
 
@@ -4729,6 +4730,93 @@ libxlDomainMigrateConfirm3Params(virDomainPtr domain,
 return libxlDomainMigrationConfirm(driver, vm, flags, cancelled);
 }
 
+typedef struct keyname_to_letter {
+   const char *keyname;
+   const char *letter;
+} keyname_to_letter;
+
+static const keyname_to_letter sysrq_keymap[] = {
+{KEY_0, 0}, {KEY_1, 1}, {KEY_2, 2}, {KEY_3, 3},
+{KEY_4, 4}, {KEY_5, 5}, {KEY_6, 6}, {KEY_7, 7},
+{KEY_8, 8}, {KEY_9, 9}, {KEY_A, a}, {KEY_B, b},
+{KEY_C, c}, {KEY_D, d}, {KEY_E, e}, {KEY_F, f},
+{KEY_G, g}, {KEY_H, h}, {KEY_I, i}, {KEY_J, j},
+{KEY_K, k}, {KEY_L, l}, {KEY_M, m}, {KEY_N, n},
+{KEY_O, o}, {KEY_P, p}, {KEY_Q, q}, {KEY_R, r},
+{KEY_S, s}, {KEY_T, t}, {KEY_U, u}, {KEY_V, v},
+{KEY_W, w}, {KEY_X, x}, {KEY_Y, y}, {KEY_Z, z},
+{NULL, NULL}
+};
+
+static int
+libxlDomainSendKey(virDomainPtr dom,
+   unsigned int codeset,
+   unsigned int holdtime ATTRIBUTE_UNUSED,
+   unsigned int *keycodes,
+   int nkeycodes,
+   unsigned int flags)
+{
+virDomainObjPtr vm;
+libxlDomainObjPrivatePtr priv;
+const char *keyname0, *keyname1;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+if (!(vm = libxlDomObjFromDomain(dom)))
+goto cleanup;
+
+priv = vm-privateData;
+
+if (virDomainSendKeyEnsureACL(dom-conn, vm-def)  0)
+goto cleanup;
+
+/* check key, only support sending magic sysrq. Like:
+ * #virsh send-key guest1 KEY_LEFTALT KEY_SYSRQ KEY_H
+ */
+if (nkeycodes  3)
+goto non_sysrq;
+
+keyname0 = virKeynameFromKeycode(codeset, keycodes[0]);
+keyname1 = virKeynameFromKeycode(codeset, keycodes[1]);
+if (!keyname0 || !keyname1)
+goto non_sysrq;
+
+if ((STREQ(keyname0, KEY_LEFTALT)  STREQ(keyname1, KEY_SYSRQ)) ||
+(STREQ(keyname1, KEY_LEFTALT)  STREQ(keyname0, KEY_SYSRQ))) {
+const keyname_to_letter *item = sysrq_keymap;
+char *key = NULL;
+const char *keyname = virKeynameFromKeycode(codeset, keycodes[2]);
+
+while (item  item-keyname) {
+if (keyname  STREQ(item-keyname, keyname)) {
+if (VIR_STRDUP(key, item-letter)  0)
+goto cleanup;
+break;
+}
+item++;
+}
+
+if (!key)
+goto non_sysrq;
+
+ret = libxl_send_sysrq(priv-ctx, vm-def-id, key[0]);
+VIR_FREE(key);
+goto cleanup;
+
+} else {
+goto non_sysrq;
+}
+
+ non_sysrq:
+virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
+   %s, _(Sending non-sysrq keys is not supported));
+
+ cleanup:
+if (vm)
+virObjectUnlock(vm);
+return ret;
+}
 
 static virHypervisorDriver libxlDriver = {
 .no = VIR_DRV_LIBXL,
@@ -4824,6 +4912,7 @@ static virHypervisorDriver libxlDriver = {
 .domainMigratePerform3Params = libxlDomainMigratePerform3Params, /* 1.2.6 
*/
 .domainMigrateFinish3Params = libxlDomainMigrateFinish3Params, /* 1.2.6 */
 .domainMigrateConfirm3Params = libxlDomainMigrateConfirm3Params, /* 1.2.6 
*/
+.domainSendKey = libxlDomainSendKey, /* 1.2.11 */
 };
 
 static virStateDriver libxlStateDriver = {
-- 
1.8.4.5

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


[libvirt] [PATCH 0/3] support sysrq in xen/libxl driver

2014-12-08 Thread Chunyan Liu
xm/xend and libxl already support sending sysrq key. Adding the
equivalant to libvirt.

Chunyan Liu (3):
  virkeycode: add virKeynameFromKeycode function
  xen: add .domainSendKey
  libxl: add .domainSendKey

 src/libvirt_private.syms |  1 +
 src/libxl/libxl_driver.c | 89 
 src/util/virkeycode.c| 17 +
 src/util/virkeycode.h|  1 +
 src/xen/xen_driver.c | 85 +
 src/xen/xend_internal.c  | 21 
 src/xen/xend_internal.h  |  1 +
 7 files changed, 215 insertions(+)

-- 
1.8.4.5

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


[libvirt] [PATCH 2/3] xen: add .domainSendKey

2014-12-08 Thread Chunyan Liu
xm/xend supports sysrq command. Add .domainSendKey function to support
sending sysrq key.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/xen/xen_driver.c| 85 +
 src/xen/xend_internal.c | 21 
 src/xen/xend_internal.h |  1 +
 3 files changed, 107 insertions(+)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index c9f4159..434236e 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -67,6 +67,7 @@
 #include configmake.h
 #include virstring.h
 #include viraccessapicheck.h
+#include virkeycode.h
 
 #define VIR_FROM_THIS VIR_FROM_XEN
 
@@ -2738,6 +2739,89 @@ xenUnifiedNodeSuspendForDuration(virConnectPtr conn,
 return nodeSuspendForDuration(target, duration, flags);
 }
 
+typedef struct keyname_to_letter {
+   const char *keyname;
+   const char *letter;
+} keyname_to_letter;
+
+static const keyname_to_letter sysrq_keymap[] = {
+{KEY_0, 0}, {KEY_1, 1}, {KEY_2, 2}, {KEY_3, 3},
+{KEY_4, 4}, {KEY_5, 5}, {KEY_6, 6}, {KEY_7, 7},
+{KEY_8, 8}, {KEY_9, 9}, {KEY_A, a}, {KEY_B, b},
+{KEY_C, c}, {KEY_D, d}, {KEY_E, e}, {KEY_F, f},
+{KEY_G, g}, {KEY_H, h}, {KEY_I, i}, {KEY_J, j},
+{KEY_K, k}, {KEY_L, l}, {KEY_M, m}, {KEY_N, n},
+{KEY_O, o}, {KEY_P, p}, {KEY_Q, q}, {KEY_R, r},
+{KEY_S, s}, {KEY_T, t}, {KEY_U, u}, {KEY_V, v},
+{KEY_W, w}, {KEY_X, x}, {KEY_Y, y}, {KEY_Z, z},
+{NULL, NULL}
+};
+
+static int
+xenUnifiedDomainSendKey(virDomainPtr dom,
+unsigned int codeset,
+unsigned int holdtime ATTRIBUTE_UNUSED,
+unsigned int *keycodes,
+int nkeycodes,
+unsigned int flags)
+{
+int ret = -1;
+virDomainDefPtr def;
+const char *keyname0, *keyname1;
+
+virCheckFlags(0, -1);
+
+if (!(def = xenGetDomainDefForDom(dom)))
+goto cleanup;
+
+if (virDomainSendKeyEnsureACL(dom-conn, def)  0)
+goto cleanup;
+
+/* check key, only support sending magic sysrq. Like:
+ * #virsh send-key guest1 KEY_LEFTALT KEY_SYSRQ KEY_H
+ */
+if (nkeycodes  3)
+goto non_sysrq;
+
+keyname0 = virKeynameFromKeycode(codeset, keycodes[0]);
+keyname1 = virKeynameFromKeycode(codeset, keycodes[1]);
+if (!keyname0 || !keyname1)
+goto non_sysrq;
+
+if ((STREQ(keyname0, KEY_LEFTALT)  STREQ(keyname1, KEY_SYSRQ)) ||
+(STREQ(keyname1, KEY_LEFTALT)  STREQ(keyname0, KEY_SYSRQ))) {
+const keyname_to_letter *item = sysrq_keymap;
+char *key = NULL;
+const char *keyname = virKeynameFromKeycode(codeset, keycodes[2]);
+
+while (item  item-keyname) {
+if (keyname  STREQ(item-keyname, keyname)) {
+if (VIR_STRDUP(key, item-letter)  0)
+goto cleanup;
+break;
+}
+item++;
+}
+
+if (!key)
+goto non_sysrq;
+
+ret = xenDaemonDomainSysrq(dom-conn, def, key);
+VIR_FREE(key);
+goto cleanup;
+
+} else {
+goto non_sysrq;
+}
+
+ non_sysrq:
+virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
+   %s, _(Sending non-sysrq keys is not supported));
+
+ cleanup:
+virDomainDefFree(def);
+return ret;
+}
 
 /*- Register with libvirt.c, and initialize Xen drivers. -*/
 
@@ -2836,6 +2920,7 @@ static virHypervisorDriver xenUnifiedDriver = {
 .nodeSuspendForDuration = xenUnifiedNodeSuspendForDuration, /* 0.9.8 */
 .nodeGetMemoryParameters = xenUnifiedNodeGetMemoryParameters, /* 0.10.2 */
 .nodeSetMemoryParameters = xenUnifiedNodeSetMemoryParameters, /* 0.10.2 */
+.domainSendKey = xenUnifiedDomainSendKey, /* 1.2.11 */
 };
 
 /**
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index b233b6b..eabb6ed 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -1349,6 +1349,27 @@ xenDaemonDomainReboot(virConnectPtr conn, 
virDomainDefPtr def)
 }
 
 /**
+ * xenDaemonDomainSysrq:
+ * @conn: the connection object
+ * @def: the domain to destroy
+ *
+ * Send a sysrq to a domain.
+ *
+ * Returns 0 in case of success, -1 (with errno) in case of error.
+ */
+int
+xenDaemonDomainSysrq(virConnectPtr conn, virDomainDefPtr def, char *key)
+{
+if (def-id  0) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _(Domain %s isn't running.), def-name);
+return -1;
+}
+
+return xend_op(conn, def-name, op, sysrq, key, key, NULL);
+}
+
+/**
  * xenDaemonDomainDestroy:
  * @conn: the connection object
  * @def: the domain to destroy
diff --git a/src/xen/xend_internal.h b/src/xen/xend_internal.h
index 814330d..6706394 100644
--- a/src/xen/xend_internal.h
+++ b/src/xen/xend_internal.h
@@ -213,5 +213,6 @@ int xenDaemonSetSchedulerParameters(virConnectPtr conn,
 virDomainDefPtr def,
 virTypedParameterPtr params

[libvirt] [PATCH 1/3] virkeycode: add virKeynameFromKeycode function

2014-12-08 Thread Chunyan Liu
Add virKeynameFromKeycode for later xen/libxl sendkey usage.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libvirt_private.syms |  1 +
 src/util/virkeycode.c| 17 +
 src/util/virkeycode.h|  1 +
 3 files changed, 19 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6df2784..087b75f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1540,6 +1540,7 @@ virKeycodeSetTypeFromString;
 virKeycodeSetTypeToString;
 virKeycodeValueFromString;
 virKeycodeValueTranslate;
+virKeynameFromKeycode;
 
 
 # util/virkeyfile.h
diff --git a/src/util/virkeycode.c b/src/util/virkeycode.c
index 7880a0a..c6b3b36 100644
--- a/src/util/virkeycode.c
+++ b/src/util/virkeycode.c
@@ -124,3 +124,20 @@ int virKeycodeValueTranslate(virKeycodeSet from_codeset,
 
 return -1;
 }
+
+const char *
+virKeynameFromKeycode(virKeycodeSet codeset, int keycode)
+{
+size_t i;
+
+for (i = 0; i  VIR_KEYMAP_ENTRY_MAX; i++) {
+if (!virKeymapNames[codeset] ||
+!virKeymapValues[codeset])
+continue;
+
+if (virKeymapValues[codeset][i] == keycode)
+return virKeymapNames[codeset][i];
+}
+
+return NULL;
+}
diff --git a/src/util/virkeycode.h b/src/util/virkeycode.h
index 6947cfe..aefb1c9 100644
--- a/src/util/virkeycode.h
+++ b/src/util/virkeycode.h
@@ -29,5 +29,6 @@ int virKeycodeValueFromString(virKeycodeSet codeset, const 
char *keyname);
 int virKeycodeValueTranslate(virKeycodeSet from_codeset,
 virKeycodeSet to_offset,
 int key_value);
+const char *virKeynameFromKeycode(virKeycodeSet codeset, int keycode);
 
 #endif
-- 
1.8.4.5

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


[libvirt] [PATCH V2] libxl: support hvm direct kernel boot

2014-09-16 Thread Chunyan Liu
Xen libxl can support Xen HVM direct kernel boot now. To support
Xen HVM direct kernel boot in libvirt, it still needs some changes
to libvirt code: accept HVM direct kernel boot related configuration
in xml, parse those info into virDomainDefPtr, and fill in related
parts of libxl_domain_build_info, so that libxl can handle. This
patch is just to do this.

Signed-off-by: Chunyan Liu cy...@suse.com
---
Changes:
  - fix Jim's comments

 src/libxl/libxl_conf.c | 18 +++
 src/xenconfig/xen_common.c | 57 ++
 2 files changed, 60 insertions(+), 15 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index acba69c..a5bda64 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -704,6 +704,15 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
 if (VIR_STRDUP(b_info-u.hvm.boot, bootorder)  0)
 goto error;
 
+#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
+if (VIR_STRDUP(b_info-cmdline, def-os.cmdline)  0)
+goto error;
+if (VIR_STRDUP(b_info-kernel, def-os.kernel)  0)
+goto error;
+if (VIR_STRDUP(b_info-ramdisk, def-os.initrd)  0)
+goto error;
+#endif
+
 if (def-nserials) {
 if (def-nserials  1) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -748,6 +757,14 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
   virStringSplit(def-os.bootloaderArgs,  \t\n, 0)))
 goto error;
 }
+#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
+if (VIR_STRDUP(b_info-cmdline, def-os.cmdline)  0)
+goto error;
+if (VIR_STRDUP(b_info-kernel, def-os.kernel)  0)
+goto error;
+if (VIR_STRDUP(b_info-ramdisk, def-os.initrd)  0)
+goto error;
+#else
 if (VIR_STRDUP(b_info-u.pv.cmdline, def-os.cmdline)  0)
 goto error;
 if (def-os.kernel) {
@@ -758,6 +775,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
 }
 if (VIR_STRDUP(b_info-u.pv.ramdisk, def-os.initrd)  0)
 goto error;
+#endif
 }
 
 return 0;
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 32954f3..3cf7553 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -39,6 +39,9 @@
 #include virstring.h
 #include xen_common.h
 
+#if WITH_LIBXL
+# include libxl.h
+#endif
 
 /*
  * Convenience method to grab a long int from the config file object
@@ -1053,6 +1056,27 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr 
def, virCapsPtr caps)
 return 0;
 }
 
+static int
+xenParseCmdline(virConfPtr conf, virDomainDefPtr def)
+{
+const char *extra, *root;
+
+if (xenConfigGetString(conf, extra, extra, NULL)  0)
+return -1;
+
+if (xenConfigGetString(conf, root, root, NULL)  0)
+return -1;
+
+if (root) {
+if (virAsprintf(def-os.cmdline, root=%s %s, root, extra)  0)
+return -1;
+} else {
+if (VIR_STRDUP(def-os.cmdline, extra)  0)
+return -1;
+}
+
+return 0;
+}
 
 static int
 xenParseOS(virConfPtr conf, virDomainDefPtr def)
@@ -1065,9 +1089,25 @@ xenParseOS(virConfPtr conf, virDomainDefPtr def)
 if (STREQ(def-os.type, hvm)) {
 const char *boot;
 
+#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
+if (xenConfigCopyStringOpt(conf, kernel, def-os.kernel)  0)
+return -1;
+
+if (def-os.kernel  strstr(def-os.kernel, hvmloader)) {
+/* 'kernel' set to 'hvmloader' will be ignored in libxl */
+VIR_FREE(def-os.kernel);
+}
+
+if (xenConfigCopyStringOpt(conf, ramdisk, def-os.initrd)  0)
+return -1;
+
+if (xenParseCmdline(conf, def)  0)
+return -1;
+#else
 if (VIR_ALLOC(def-os.loader)  0 ||
-xenConfigCopyString(conf, kernel, def-os.loader-path)  0)
+xenConfigCopyStringOpt(conf, kernel, def-os.loader-path)  0)
 return -1;
+#endif
 
 if (xenConfigGetString(conf, boot, boot, c)  0)
 return -1;
@@ -1091,8 +1131,6 @@ xenParseOS(virConfPtr conf, virDomainDefPtr def)
 def-os.nBootDevs++;
 }
 } else {
-const char *extra, *root;
-
 if (xenConfigCopyStringOpt(conf, bootloader, def-os.bootloader)  
0)
 return -1;
 if (xenConfigCopyStringOpt(conf, bootargs, def-os.bootloaderArgs) 
 0)
@@ -1104,19 +1142,8 @@ xenParseOS(virConfPtr conf, virDomainDefPtr def)
 if (xenConfigCopyStringOpt(conf, ramdisk, def-os.initrd)  0)
 return -1;
 
-if (xenConfigGetString(conf, extra, extra, NULL)  0)
+if (xenParseCmdline(conf, def)  0)
 return -1;
-
-if (xenConfigGetString(conf, root, root, NULL)  0)
-return -1;
-
-if (root) {
-if (virAsprintf(def-os.cmdline, root=%s %s, root, extra)  0)
-return -1;
-} else {
-if (VIR_STRDUP(def-os.cmdline

[libvirt] [PATCH] libxl: support hvm direct kernel boot

2014-09-14 Thread Chunyan Liu
Xen libxl can support Xen HVM direct kernel boot now. To support
Xen HVM direct kernel boot in libvirt, it still needs some changes
to libvirt code: accept HVM direct kernel boot related configuration
in xml, parse those info into virDomainDefPtr, and fill in related
parts of libxl_domain_build_info, so that libxl can handle. This
patch is just to do this.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libxl/libxl_conf.c | 18 
 src/xenconfig/xen_common.c | 51 +-
 2 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index acba69c..a5bda64 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -704,6 +704,15 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
 if (VIR_STRDUP(b_info-u.hvm.boot, bootorder)  0)
 goto error;
 
+#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
+if (VIR_STRDUP(b_info-cmdline, def-os.cmdline)  0)
+goto error;
+if (VIR_STRDUP(b_info-kernel, def-os.kernel)  0)
+goto error;
+if (VIR_STRDUP(b_info-ramdisk, def-os.initrd)  0)
+goto error;
+#endif
+
 if (def-nserials) {
 if (def-nserials  1) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -748,6 +757,14 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
   virStringSplit(def-os.bootloaderArgs,  \t\n, 0)))
 goto error;
 }
+#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
+if (VIR_STRDUP(b_info-cmdline, def-os.cmdline)  0)
+goto error;
+if (VIR_STRDUP(b_info-kernel, def-os.kernel)  0)
+goto error;
+if (VIR_STRDUP(b_info-ramdisk, def-os.initrd)  0)
+goto error;
+#else
 if (VIR_STRDUP(b_info-u.pv.cmdline, def-os.cmdline)  0)
 goto error;
 if (def-os.kernel) {
@@ -758,6 +775,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
 }
 if (VIR_STRDUP(b_info-u.pv.ramdisk, def-os.initrd)  0)
 goto error;
+#endif
 }
 
 return 0;
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 32954f3..290ba3d 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -1053,6 +1053,26 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr 
def, virCapsPtr caps)
 return 0;
 }
 
+static int xenParseCmdline(virConfPtr conf, virDomainDefPtr def)
+{
+const char *extra, *root;
+
+if (xenConfigGetString(conf, extra, extra, NULL)  0)
+return -1;
+
+if (xenConfigGetString(conf, root, root, NULL)  0)
+return -1;
+
+if (root) {
+if (virAsprintf(def-os.cmdline, root=%s %s, root, extra)  0)
+return -1;
+} else {
+if (VIR_STRDUP(def-os.cmdline, extra)  0)
+return -1;
+}
+
+return 0;
+}
 
 static int
 xenParseOS(virConfPtr conf, virDomainDefPtr def)
@@ -1065,9 +1085,25 @@ xenParseOS(virConfPtr conf, virDomainDefPtr def)
 if (STREQ(def-os.type, hvm)) {
 const char *boot;
 
+#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
+if (xenConfigCopyStringOpt(conf, kernel, def-os.kernel)  0)
+return -1;
+
+if (strstr(def-os.kernel, hvmloader)) {
+/* 'kernel' set to 'hvmloader' will be ignored in libxl */
+virFree(def-os.kernel);
+}
+
+if (xenConfigCopyStringOpt(conf, ramdisk, def-os.initrd)  0)
+return -1;
+
+if (xenParseCmdline(conf, def)  0)
+   return -1;
+#else
 if (VIR_ALLOC(def-os.loader)  0 ||
 xenConfigCopyString(conf, kernel, def-os.loader-path)  0)
 return -1;
+#endif
 
 if (xenConfigGetString(conf, boot, boot, c)  0)
 return -1;
@@ -1091,8 +1127,6 @@ xenParseOS(virConfPtr conf, virDomainDefPtr def)
 def-os.nBootDevs++;
 }
 } else {
-const char *extra, *root;
-
 if (xenConfigCopyStringOpt(conf, bootloader, def-os.bootloader)  
0)
 return -1;
 if (xenConfigCopyStringOpt(conf, bootargs, def-os.bootloaderArgs) 
 0)
@@ -1104,19 +1138,8 @@ xenParseOS(virConfPtr conf, virDomainDefPtr def)
 if (xenConfigCopyStringOpt(conf, ramdisk, def-os.initrd)  0)
 return -1;
 
-if (xenConfigGetString(conf, extra, extra, NULL)  0)
+if (xenParseCmdline(conf, def)  0)
 return -1;
-
-if (xenConfigGetString(conf, root, root, NULL)  0)
-return -1;
-
-if (root) {
-if (virAsprintf(def-os.cmdline, root=%s %s, root, extra)  0)
-return -1;
-} else {
-if (VIR_STRDUP(def-os.cmdline, extra)  0)
-return -1;
-}
 }
 
 return 0;
-- 
1.8.4.5

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


[libvirt] [PATCH V2] fix: unix sockets created for virtio-serail has insufficient permissions

2014-09-03 Thread Chunyan Liu
Add umask to _virCommand, allow user to set umask to command.
Set umask(002) to qemu process to overwrite default umask(022) so
that unix sockets created for virtio-serial has expected permissions.

Fix problem reported here:
https://sourceware.org/bugzilla/show_bug.cgi?id=13078#c11
https://bugzilla.novell.com/show_bug.cgi?id=888166

To use virtio-serial device, unix socket created for chardev with
default umask(022) has insufficient permissions.
e.g.:
-device virtio-serial \
-chardev socket,path=/tmp/foo,server,nowait,id=foo \
-device virtserialport,chardev=foo,name=org.fedoraproject.port.0

srwxr-xr-x 1 qemu qemu 0 21. Jul 14:19 /tmp/somefile.sock

Other users in the same group (like real user, test engines, etc)
cannot write to this socket.

Signed-off-by: Chunyan Liu cy...@suse.com
---
Changes:
  * set umask(002) to the whole qemu process instead of calling
umask in qemu unix_listen_opts.

  V1 is here:
  http://www.mail-archive.com/libvir-list@redhat.com/msg101513.html

 src/libvirt_private.syms |  1 +
 src/qemu/qemu_process.c  |  1 +
 src/util/vircommand.c| 11 +++
 src/util/vircommand.h|  1 +
 4 files changed, 14 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 71fc063..f136d24 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1171,6 +1171,7 @@ virCommandSetPidFile;
 virCommandSetPreExecHook;
 virCommandSetSELinuxLabel;
 virCommandSetUID;
+virCommandSetUmask;
 virCommandSetWorkingDirectory;
 virCommandToString;
 virCommandWait;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f68dfbe..f76aa5a 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4141,6 +4141,7 @@ int qemuProcessStart(virConnectPtr conn,
 virCommandSetPreExecHook(cmd, qemuProcessHook, hookData);
 virCommandSetMaxProcesses(cmd, cfg-maxProcesses);
 virCommandSetMaxFiles(cmd, cfg-maxFiles);
+virCommandSetUmask(cmd, 0x002);
 
 VIR_DEBUG(Setting up security labelling);
 if (virSecurityManagerSetChildProcessLabel(driver-securityManager,
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 1d6dbd9..efb5f69 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -133,6 +133,7 @@ struct _virCommand {
 #if defined(WITH_SECDRIVER_APPARMOR)
 char *appArmorProfile;
 #endif
+int umask;
 };
 
 /* See virCommandSetDryRun for description for this variable */
@@ -582,6 +583,8 @@ virExec(virCommandPtr cmd)
 
 /* child */
 
+if (cmd-umask)
+umask(cmd-umask);
 ret = EXIT_CANCELED;
 openmax = sysconf(_SC_OPEN_MAX);
 if (openmax  0) {
@@ -1082,6 +1085,14 @@ virCommandSetMaxFiles(virCommandPtr cmd, unsigned int 
files)
 cmd-maxFiles = files;
 }
 
+void virCommandSetUmask(virCommandPtr cmd, int umask)
+{
+if (!cmd || cmd-has_error)
+return;
+
+cmd-umask = umask;
+}
+
 /**
  * virCommandClearCaps:
  * @cmd: the command to modify
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
index d3b286d..bf65de4 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -72,6 +72,7 @@ void virCommandSetUID(virCommandPtr cmd, uid_t uid);
 void virCommandSetMaxMemLock(virCommandPtr cmd, unsigned long long bytes);
 void virCommandSetMaxProcesses(virCommandPtr cmd, unsigned int procs);
 void virCommandSetMaxFiles(virCommandPtr cmd, unsigned int files);
+void virCommandSetUmask(virCommandPtr cmd, int umask);
 
 void virCommandClearCaps(virCommandPtr cmd);
 
-- 
1.8.4.5

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


[libvirt] [PATCH 0/2] fix: unix sockets created for virtio-serail has insufficient permissions

2014-09-02 Thread Chunyan Liu
https://sourceware.org/bugzilla/show_bug.cgi?id=13078#c11
https://bugzilla.novell.com/show_bug.cgi?id=888166

To use virtio-serial device, unix socket created for chardev with
default umask(022) has insufficient permissions.
e.g.:
-device virtio-serial \
-chardev socket,path=/tmp/foo,server,nowait,id=foo \
-device virtserialport,chardev=foo,name=org.fedoraproject.port.0

#ls -l /tmp/somefile.sock
srwxr-xr-x 1 qemu qemu 0 21. Jul 14:19 /tmp/somefile.sock

Other users in the same group (like real user, test engines, etc)
cannot write to this socket.

These patch series contains a qemu patch and a libvirt patch:
qemu patch: adds a new 'umask' option to -chardev, so that user can
change the umask.
libvirt patch: pass 'umask=0x002' paramter to qemu command line
for virtio-serial device

Chunyan Liu (2):
  qemu side: add 'umask' option to chardev
  libvirt side: qemu: add umask(002) to virtio-serial chardev commandline

-- 
1.8.4.5

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


[libvirt] [PATCH 2/2] qemu: add umask(002) to virtio-serial chardev commandline

2014-09-02 Thread Chunyan Liu
To use virtio-serial device, unix socket created for communication with
default umask(022) has insufficient permissions.
e.g.
1. Setup a virtual machine with a virtio-serial device:
# virsh edit myvm
(...)
channel type='unix'
  source mode='bind' path='/tmp/somefile.sock'/
  target type='virtio' name='com.suse.sometest'/
  address type='virtio-serial' controller='0' bus='0' port='1'/
/channel
(...)
controller type='virtio-serial' index='0'
  address type='pci' domain='0x' bus='0x00' slot='0x06'
function='0x0'/
/controller

2. Start this virtual machine:
# virsh start myvm

3. Check permissions for the socket file that has been created in the
host to enable communication through virtual serial ports in the guest:
# ls -l /tmp/somefile.sock
srwxr-xr-x 1 qemu qemu 0 21. Jul 14:19 /tmp/somefile.sock

Other users in the qemu group (like real user, test engines, etc) cannot
write to this socket.

Problem reported here:
https://sourceware.org/bugzilla/show_bug.cgi?id=13078#c11
https://bugzilla.novell.com/show_bug.cgi?id=888166

This patch tries to pass a 'umask' option to '-chardev' when
building qemu command line in above configuration case. In
qemu side, there is another patch to handle the 'umask' option
to overwrite default umask(022). With these changes, unix
socket created for virtio-serial device can have expected
permissions.

Signed-off-by: Chunyan Liu cy...@suse.com 
---
This is patch for libvirt.

 src/qemu/qemu_command.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index beb8ca8..11eee44 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8509,6 +8509,18 @@ qemuBuildCommandLine(virConnectPtr conn,
   channel-info.alias,
   qemuCaps)))
 goto error;
+/* use umask(002) instead of default umask(022) to create
+ * a unix socket, so that virtio-serial device has sufficient
+ * permissions for correct usage.
+ */
+if (channel-source.type == VIR_DOMAIN_CHR_TYPE_UNIX) {
+char *tmpstr = NULL;
+if (virAsprintf(tmpstr, %s,umask=0x002, devstr)  0)
+goto error;
+VIR_FREE(devstr);
+devstr = tmpstr;
+}
+
 virCommandAddArg(cmd, devstr);
 VIR_FREE(devstr);
 }
-- 
1.8.4.5

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


[libvirt] [PATCH 1/2] add 'umask' option to -chardev

2014-09-02 Thread Chunyan Liu
To use virtio-serial device, unix socket created for chardev with
default umask(022) has insufficient permissions.

e.g. start kvm guest with:
-device virtio-serial \
-chardev socket,path=/tmp/foo,server,nowait,id=foo \
-device virtserialport,chardev=foo,name=org.fedoraproject.port.0

Check permissions for the socket file that has been created in the host
to enable communication through virtual serial ports in the guest:
#ls -l /tmp/somefile.sock
srwxr-xr-x 1 qemu qemu 0 21. Jul 14:19 /tmp/somefile.sock

Other users in the qemu group (like real user, test engines, etc) cannot
write to this socket.

Problem reported here:
https://sourceware.org/bugzilla/show_bug.cgi?id=13078#c11
https://bugzilla.novell.com/show_bug.cgi?id=888166

This patch tries to add a 'umask' option to 'chardev', so that user
can have chance to indicate a umask overwritting the default one (default
is 022), then create unix sockets with expected permissions.

Signed-off-by: Chunyan Liu cy...@suse.com
---
This is patch for qemu.

 qemu-char.c |  3 +++
 qemu-options.hx |  9 +++--
 util/qemu-sockets.c | 12 +++-
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index d4f327a..a39a5e4 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3856,6 +3856,9 @@ QemuOptsList qemu_chardev_opts = {
 },{
 .name = chardev,
 .type = QEMU_OPT_STRING,
+},{
+.name = umask,
+.type = QEMU_OPT_NUMBER,
 },
 { /* end of list */ }
 },
diff --git a/qemu-options.hx b/qemu-options.hx
index ecd0e34..078e9db 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1929,7 +1929,7 @@ DEF(chardev, HAS_ARG, QEMU_OPTION_chardev,
 -chardev null,id=id[,mux=on|off]\n
 -chardev 
socket,id=id[,host=host],port=port[,to=to][,ipv4][,ipv6][,nodelay]\n
  [,server][,nowait][,telnet][,mux=on|off] (tcp)\n
--chardev socket,id=id,path=path[,server][,nowait][,telnet],[mux=on|off] 
(unix)\n
+-chardev 
socket,id=id,path=path[,umask][,server][,nowait][,telnet],[mux=on|off] (unix)\n
 -chardev udp,id=id[,host=host],port=port[,localaddr=localaddr]\n
  [,localport=localport][,ipv4][,ipv6][,mux=on|off]\n
 -chardev msmouse,id=id[,mux=on|off]\n
@@ -2001,12 +2001,17 @@ Options to each backend are described below.
 A void device. This device will not emit any data, and will drop any data it
 receives. The null backend does not take any options.
 
-@item -chardev socket ,id=@var{id} [@var{TCP options} or @var{unix options}] 
[,server] [,nowait] [,telnet]
+@item -chardev socket ,id=@var{id} [@var{TCP options} or @var{unix options}] 
[,umask][,server] [,nowait] [,telnet]
 
 Create a two-way stream socket, which can be either a TCP or a unix socket. A
 unix socket will be created if @option{path} is specified. Behaviour is
 undefined if TCP options are specified for a unix socket.
 
+@option{umask} specifies the umask used for creating a unix socket. Without
+this option, default umask(022) will be used, permission is not sufficient
+for virtio-serial device. One can indicate umask=0x002 for virtio-serial
+device for correct usage.
+
 @option{server} specifies that the socket shall be a listening socket.
 
 @option{nowait} specifies that QEMU should not block waiting for a client to
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 5d38395..facf2c6 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -680,7 +680,8 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
 {
 struct sockaddr_un un;
 const char *path = qemu_opt_get(opts, path);
-int sock, fd;
+int newmask = qemu_opt_get_number(opts, umask, 0);
+int sock, fd, oldmask;
 
 sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
 if (sock  0) {
@@ -708,10 +709,19 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
 }
 
 unlink(un.sun_path);
+if (newmask) {
+oldmask = umask(newmask);
+}
 if (bind(sock, (struct sockaddr*) un, sizeof(un))  0) {
+if (newmask) {
+umask(oldmask);
+}
 error_set_errno(errp, errno, QERR_SOCKET_BIND_FAILED);
 goto err;
 }
+if (newmask) {
+umask(oldmask);
+}
 if (listen(sock, 1)  0) {
 error_set_errno(errp, errno, QERR_SOCKET_LISTEN_FAILED);
 goto err;
-- 
1.8.5.2

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


[libvirt] [PATCH] cmdMigrate: move vshConnect before vshWatchJob

2014-08-08 Thread Chunyan Liu
A possible fix to issue:
http://www.redhat.com/archives/libvir-list/2014-August/thread.html#00227

While doing migration on KVM host, found problem sometimes:
VM is already running on the target host and disappears from source
host, but 'virsh migrate' command line hangs, cannot exit normally.
If pressing ENTER key, it will exit.

The code hangs at tools/virsh-domain.c: cmdMigrate
-vshWatchJob-poll():
poll() is trying to select pipe_fd, which is used to receive message
from doMigrate thread. In debugging, found that doMigrate finishes
and at the end it does call safewrite() to write the retval ('0' or
'1') to pipe_fd, and the write is completed. But cmdMigrate poll()
cannot get the event. If pressing ENTER key, poll() can get the
event and select pipe_fd, then command line can exit.

In current code, authentication thread which is called by vshConnect
will use stdin, and at the same time, in cmdMigrate main process,
poll() is listening to stdin, that probably affect poll() to get
pipe_fd event. Better to move authentication before vshWatchJob. With
this change, above problem does not exist.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 tools/virsh-domain.c | 26 --
 tools/virsh.h|  1 +
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f7193cb..2562326 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -8965,6 +8965,7 @@ doMigrate(void *opaque)
 virTypedParameterPtr params = NULL;
 int nparams = 0;
 int maxparams = 0;
+virConnectPtr dconn = data-dconn;
 
 sigemptyset(sigmask);
 sigaddset(sigmask, SIGINT);
@@ -9079,18 +9080,12 @@ doMigrate(void *opaque)
 ret = '0';
 } else {
 /* For traditional live migration, connect to the destination host 
directly. */
-virConnectPtr dconn = NULL;
 virDomainPtr ddom = NULL;
 
-dconn = vshConnect(ctl, desturi, false);
-if (!dconn)
-goto out;
-
 if ((ddom = virDomainMigrate3(dom, dconn, params, nparams, flags))) {
 virDomainFree(ddom);
 ret = '0';
 }
-virConnectClose(dconn);
 }
 
  out:
@@ -9152,6 +9147,23 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
 data.cmd = cmd;
 data.writefd = p[1];
 
+if (vshCommandOptBool(cmd, p2p) || vshCommandOptBool(cmd, direct)) {
+data.dconn = NULL;
+} else {
+/* For traditional live migration, connect to the destination host. */
+virConnectPtr dconn = NULL;
+const char *desturi = NULL;
+
+if (vshCommandOptStringReq(ctl, cmd, desturi, desturi)  0)
+goto cleanup;
+
+dconn = vshConnect(ctl, desturi, false);
+if (!dconn)
+goto cleanup;
+
+data.dconn = dconn;
+}
+
 if (virThreadCreate(workerThread,
 true,
 doMigrate,
@@ -9163,6 +9175,8 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
 virThreadJoin(workerThread);
 
  cleanup:
+if (data.dconn)
+virConnectClose(data.dconn);
 virDomainFree(dom);
 VIR_FORCE_CLOSE(p[0]);
 VIR_FORCE_CLOSE(p[1]);
diff --git a/tools/virsh.h b/tools/virsh.h
index 7656407..b4df24b 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -371,6 +371,7 @@ struct _vshCtrlData {
 vshControl *ctl;
 const vshCmd *cmd;
 int writefd;
+virConnectPtr dconn;
 };
 
 /* error handling */
-- 
1.8.4.5

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


[libvirt] [PATCH] blockcopy: check dst = identical device

2014-07-29 Thread Chunyan Liu
Check whether dst is the same device as source, if yes, report
error and exit.

Currently if dst is the same device as source, blockcopy is still
going and qemu 'drive-mirror' is executed. Considering that:
a). blockcopy to the same device is meaningless. b.) result is
unexpected. (tested with block device whose source path is /dev/sdaX,
after blockcopy, shutdown VM and then create VM from xml again, the
VM cannot be started.) This case should not be allowed.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/qemu/qemu_driver.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 704ba39..87a3790 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15309,6 +15309,13 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
 }
 
 /* Prepare the destination file.  */
+if (STREQ(disk-src-path, dest)) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _(destination '%s' is the same as disk '%s' source),
+   dest, path);
+goto endjob;
+}
+
 if (stat(dest, st)  0) {
 if (errno != ENOENT) {
 virReportSystemError(errno, _(unable to stat for disk %s: %s),
-- 
1.8.4.5

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


[libvirt] [PATCH V3 2/2] add nocow test case

2014-07-15 Thread Chunyan Liu
Add file in storagevolxml2xmlin and storagevolxml2xmlout, let
storagevolxml2xmltest and storagevolschematest cover 'nocow'.
Add test case to storagevolxml2argvtest to cover 'nocow'.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 .../storagevolxml2argvdata/qcow2-nocow-compat.argv |  3 ++
 tests/storagevolxml2argvdata/qcow2-nocow.argv  |  3 ++
 tests/storagevolxml2argvtest.c |  6 
 tests/storagevolxml2xmlin/vol-qcow2-nocow.xml  | 32 ++
 tests/storagevolxml2xmlout/vol-qcow2-nocow.xml | 31 +
 5 files changed, 75 insertions(+)
 create mode 100644 tests/storagevolxml2argvdata/qcow2-nocow-compat.argv
 create mode 100644 tests/storagevolxml2argvdata/qcow2-nocow.argv
 create mode 100644 tests/storagevolxml2xmlin/vol-qcow2-nocow.xml
 create mode 100644 tests/storagevolxml2xmlout/vol-qcow2-nocow.xml

diff --git a/tests/storagevolxml2argvdata/qcow2-nocow-compat.argv 
b/tests/storagevolxml2argvdata/qcow2-nocow-compat.argv
new file mode 100644
index 000..d5a7547
--- /dev/null
+++ b/tests/storagevolxml2argvdata/qcow2-nocow-compat.argv
@@ -0,0 +1,3 @@
+qemu-img create -f qcow2 -b /dev/null \
+-o backing_fmt=raw,encryption=on,nocow=on,compat=0.10 \
+/var/lib/libvirt/images/OtherDemo.img 5242880K
diff --git a/tests/storagevolxml2argvdata/qcow2-nocow.argv 
b/tests/storagevolxml2argvdata/qcow2-nocow.argv
new file mode 100644
index 000..e54801c
--- /dev/null
+++ b/tests/storagevolxml2argvdata/qcow2-nocow.argv
@@ -0,0 +1,3 @@
+qemu-img create -f qcow2 -b /dev/null \
+-o backing_fmt=raw,encryption=on,nocow=on \
+/var/lib/libvirt/images/OtherDemo.img 5242880K
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
index 11d70e1..2a45f6f 100644
--- a/tests/storagevolxml2argvtest.c
+++ b/tests/storagevolxml2argvtest.c
@@ -296,6 +296,12 @@ mymain(void)
 DO_TEST(pool-logical, vol-logical,
 pool-dir, vol-qcow2-nobacking,
 logical-from-qcow2, 0, FMT_COMPAT);
+DO_TEST(pool-dir, vol-qcow2-nocow,
+NULL, NULL,
+qcow2-nocow, 0, FMT_OPTIONS);
+DO_TEST(pool-dir, vol-qcow2-nocow,
+NULL, NULL,
+qcow2-nocow-compat, 0, FMT_COMPAT);
 
 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/storagevolxml2xmlin/vol-qcow2-nocow.xml 
b/tests/storagevolxml2xmlin/vol-qcow2-nocow.xml
new file mode 100644
index 000..661475b
--- /dev/null
+++ b/tests/storagevolxml2xmlin/vol-qcow2-nocow.xml
@@ -0,0 +1,32 @@
+volume
+  nameOtherDemo.img/name
+  key/var/lib/libvirt/images/OtherDemo.img/key
+  source
+  /source
+  capacity unit=G5/capacity
+  allocation294912/allocation
+  target
+path/var/lib/libvirt/images/OtherDemo.img/path
+format type='qcow2'/
+permissions
+  mode0644/mode
+  owner0/owner
+  group0/group
+  labelunconfined_u:object_r:virt_image_t:s0/label
+/permissions
+encryption format='qcow'
+  secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/
+/encryption
+nocow/
+  /target
+  backingStore
+path/dev/null/path
+format type='raw'/
+permissions
+  mode0644/mode
+  owner0/owner
+  group0/group
+  labelunconfined_u:object_r:virt_image_t:s0/label
+/permissions
+  /backingStore
+/volume
diff --git a/tests/storagevolxml2xmlout/vol-qcow2-nocow.xml 
b/tests/storagevolxml2xmlout/vol-qcow2-nocow.xml
new file mode 100644
index 000..31dc578
--- /dev/null
+++ b/tests/storagevolxml2xmlout/vol-qcow2-nocow.xml
@@ -0,0 +1,31 @@
+volume type='file'
+  nameOtherDemo.img/name
+  key/var/lib/libvirt/images/OtherDemo.img/key
+  source
+  /source
+  capacity unit='bytes'5368709120/capacity
+  allocation unit='bytes'294912/allocation
+  target
+path/var/lib/libvirt/images/OtherDemo.img/path
+format type='qcow2'/
+permissions
+  mode0644/mode
+  owner0/owner
+  group0/group
+  labelunconfined_u:object_r:virt_image_t:s0/label
+/permissions
+encryption format='qcow'
+  secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/
+/encryption
+  /target
+  backingStore
+path/dev/null/path
+format type='raw'/
+permissions
+  mode0644/mode
+  owner0/owner
+  group0/group
+  labelunconfined_u:object_r:virt_image_t:s0/label
+/permissions
+  /backingStore
+/volume
-- 
1.8.4.5

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


[libvirt] [PATCH V3 0/2] storagevol: add 'nocow' option to vol xml

2014-07-15 Thread Chunyan Liu
Add 'nocow' option to vol xml, so that user can have a chance to create
a volume with NOCOW flag set on btrfs. It improves performance when the
volume is a file image on btrfs and is used in VM environment.

---
Changes:
  * fix typo in V2
  * add test case for 'nocow', in separate patch 

V2 is here:
  http://www.redhat.com/archives/libvir-list/2014-July/msg00361.html

Chunyan Liu (2):
  storagevol: add nocow to vol xml
  add nocow test case

 docs/formatstorage.html.in |  7 +
 docs/schemas/storagevol.rng|  5 
 src/conf/storage_conf.c|  3 ++
 src/storage/storage_backend.c  | 22 +++
 src/util/virstoragefile.h  |  1 +
 .../storagevolxml2argvdata/qcow2-nocow-compat.argv |  3 ++
 tests/storagevolxml2argvdata/qcow2-nocow.argv  |  3 ++
 tests/storagevolxml2argvtest.c |  6 
 tests/storagevolxml2xmlin/vol-qcow2-nocow.xml  | 32 ++
 tests/storagevolxml2xmlout/vol-qcow2-nocow.xml | 31 +
 10 files changed, 113 insertions(+)
 create mode 100644 tests/storagevolxml2argvdata/qcow2-nocow-compat.argv
 create mode 100644 tests/storagevolxml2argvdata/qcow2-nocow.argv
 create mode 100644 tests/storagevolxml2xmlin/vol-qcow2-nocow.xml
 create mode 100644 tests/storagevolxml2xmlout/vol-qcow2-nocow.xml

-- 
1.8.4.5

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


[libvirt] [PATCH V3 1/2] storagevol: add nocow to vol xml

2014-07-15 Thread Chunyan Liu
Add 'nocow' to storage volume xml so that user can have an option
to set NOCOW flag to the newly created volume. It's useful on btrfs
file system to enhance performance.

Btrfs has low performance when hosting VM images, even more when the guest
in those VM are also using btrfs as file system. One way to mitigate this
bad performance is to turn off COW attributes on VM files. Generally, there
are two ways to turn off COW on btrfs: a) by mounting fs with nodatacow,
then all newly created files will be NOCOW. b) per file. Add the NOCOW file
attribute. It could only be done to empty or new files.

This patch tries the second way, according to 'nocow' option, it could set
NOCOW flag per file:
for raw file images, handle 'nocow' in libvirt code; for non-raw file images,
pass 'nocow=on' option to qemu-img, and let qemu-img to handle that (requires
qemu-img version = 2.1).

Signed-off-by: Chunyan Liu cy...@suse.com
---
Changes:
  * fix typo

 docs/formatstorage.html.in|  7 +++
 docs/schemas/storagevol.rng   |  5 +
 src/conf/storage_conf.c   |  3 +++
 src/storage/storage_backend.c | 22 ++
 src/util/virstoragefile.h |  1 +
 5 files changed, 38 insertions(+)

diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index 1cd82b4..8d51402 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -385,6 +385,7 @@
 lt;labelgt;virt_image_tlt;/labelgt;
   lt;/permissionsgt;
   lt;compatgt;1.1lt;/compatgt;
+  lt;nocow/gt;
   lt;featuresgt;
 lt;lazy_refcounts/gt;
   lt;/featuresgt;
@@ -424,6 +425,12 @@
 1.1 is used. If omitted, qemu-img default is used.
 span class=sinceSince 1.1.0/span
   /dd
+  dtcodenocow/code/dt
+  ddTurn off COW of the newly created volume. So far, this is only valid
+for a file image in btrfs file system. It will improve performance when
+the file image is used in VM. To create non-raw file images, it
+requires QEMU version since 2.1. span class=sinceSince 1.2.6/span
+  /dd
   dtcodefeatures/code/dt
   ddFormat-specific features. Only used for codeqcow2/code now.
 Valid sub-elements are:
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 3798476..1b2d4cc 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -138,6 +138,11 @@
   ref name='compat'/
 /optional
 optional
+  element name='nocow'
+empty/
+  /element
+/optional
+optional
   ref name='fileFormatFeatures'/
 /optional
   /interleave
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index aa29658..f28a314 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1285,6 +1285,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 virStringFreeList(version);
 }
 
+if (virXPathNode(./target/nocow, ctxt))
+ret-target.nocow = true;
+
 if (options-featureFromString  virXPathNode(./target/features, ctxt)) 
{
 if ((n = virXPathNodeSet(./target/features/*, ctxt, nodes))  0)
 goto error;
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 7b17ca4..5f2dc5d 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -37,6 +37,9 @@
 #ifdef __linux__
 # include sys/ioctl.h
 # include linux/fs.h
+# ifndef FS_NOCOW_FL
+#  define FS_NOCOW_FL 0x0080 /* Do not cow file */
+# endif
 #endif
 
 #if WITH_SELINUX
@@ -453,6 +456,21 @@ virStorageBackendCreateRaw(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 goto cleanup;
 }
 
+if (vol-target.nocow) {
+#ifdef __linux__
+int attr;
+
+/* Set NOCOW flag. This is an optimisation for btrfs.
+ * The FS_IOC_SETFLAGS ioctl return value will be ignored since any
+ * failure of this operation should not block the left work.
+ */
+if (ioctl(fd, FS_IOC_GETFLAGS, attr) == 0) {
+attr |= FS_NOCOW_FL;
+ioctl(fd, FS_IOC_SETFLAGS, attr);
+}
+#endif
+}
+
 if ((ret = createRawFile(fd, vol, inputvol))  0)
 /* createRawFile already reported the exact error. */
 ret = -1;
@@ -718,6 +736,7 @@ virStorageBackendCreateQemuImgOpts(char **opts,
bool preallocate,
int format,
const char *compat,
+   bool nocow,
virBitmapPtr features)
 {
 virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -730,6 +749,8 @@ virStorageBackendCreateQemuImgOpts(char **opts,
 virBufferAddLit(buf, encryption=on,);
 if (preallocate)
 virBufferAddLit(buf, preallocation=metadata,);
+if (nocow)
+virBufferAddLit(buf, nocow=on,);
 
 if (compat)
 virBufferAsprintf(buf

[libvirt] [PATCH 0/3] libxl: support hotplug of interface device

2014-07-14 Thread Chunyan Liu
This patch series is to add support for attach/detaching an interface
device. At the same time, add two fixes (1/3 and 3/3)

Chunyan Liu (3):
  libxl: add HOSTDEV type in libxlDomainDetachDeviceConfig
  libxl: support hotplug of interface
  libxl: fix return value error Attach|DetachDeviceFlags

 .gnulib  |   2 +-
 src/libxl/libxl_domain.c |  12 ++-
 src/libxl/libxl_driver.c | 193 +--
 3 files changed, 180 insertions(+), 27 deletions(-)

-- 
1.8.4.5

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


[libvirt] [PATCH 1/3] libxl: add HOSTDEV type in libxlDomainDetachDeviceConfig

2014-07-14 Thread Chunyan Liu
Missing HOSTDEV type in libxlDomainDetachDeviceConfig. Add it.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libxl/libxl_driver.c | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index b27581e..5e08bba 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2985,7 +2985,8 @@ static int
 libxlDomainDetachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
 {
 virDomainDiskDefPtr disk, detach;
-int ret = -1;
+virDomainHostdevDefPtr hostdev, det_hostdev;
+int idx;
 
 switch (dev-type) {
 case VIR_DOMAIN_DEVICE_DISK:
@@ -2993,18 +2994,30 @@ libxlDomainDetachDeviceConfig(virDomainDefPtr vmdef, 
virDomainDeviceDefPtr dev)
 if (!(detach = virDomainDiskRemoveByName(vmdef, disk-dst))) {
 virReportError(VIR_ERR_INVALID_ARG,
_(no target device %s), disk-dst);
-break;
+return -1;
 }
 virDomainDiskDefFree(detach);
-ret = 0;
 break;
+
+case VIR_DOMAIN_DEVICE_HOSTDEV: {
+hostdev = dev-data.hostdev;
+if ((idx = virDomainHostdevFind(vmdef, hostdev, det_hostdev))  
0) {
+virReportError(VIR_ERR_INVALID_ARG, %s,
+   _(device not present in domain 
configuration));
+return -1;
+}
+virDomainHostdevRemove(vmdef, idx);
+virDomainHostdevDefFree(det_hostdev);
+break;
+}
+
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
_(persistent detach of device is not supported));
-break;
+return -1;
 }
 
-return ret;
+return 0;
 }
 
 static int
-- 
1.8.4.5

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


[libvirt] [PATCH 2/3] libxl: support hotplug of interface

2014-07-14 Thread Chunyan Liu
Add code to support attach/detaching a network device.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libxl/libxl_domain.c |  12 +++-
 src/libxl/libxl_driver.c | 146 ---
 2 files changed, 149 insertions(+), 9 deletions(-)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 0c86601..6780e34 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -482,8 +482,16 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 STRNEQ(def-os.type, hvm))
 dev-data.chr-targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
 
-if (dev-type == VIR_DOMAIN_DEVICE_HOSTDEV) {
-virDomainHostdevDefPtr hostdev = dev-data.hostdev;
+if (dev-type == VIR_DOMAIN_DEVICE_HOSTDEV ||
+(dev-type == VIR_DOMAIN_DEVICE_NET 
+ dev-data.net-type == VIR_DOMAIN_NET_TYPE_HOSTDEV)) {
+
+virDomainHostdevDefPtr hostdev;
+
+if (dev-type == VIR_DOMAIN_DEVICE_NET)
+hostdev = (dev-data.net)-data.hostdev.def;
+else
+hostdev = dev-data.hostdev;
 
 /* forbid capabilities mode hostdev in this kind of hypervisor */
 if (hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 5e08bba..9cd56b5 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -55,6 +55,7 @@
 #include viraccessapicheck.h
 #include viratomic.h
 #include virhostdev.h
+#include network/bridge_driver.h
 
 #define VIR_FROM_THIS VIR_FROM_LIBXL
 
@@ -2674,10 +2675,8 @@ static int
 libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver,
 libxlDomainObjPrivatePtr priv,
 virDomainObjPtr vm,
-virDomainDeviceDefPtr dev)
+virDomainHostdevDefPtr hostdev)
 {
-virDomainHostdevDefPtr hostdev = dev-data.hostdev;
-
 if (hostdev-mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_(hostdev mode '%s' not supported),
@@ -2756,6 +2755,60 @@ libxlDomainDetachDeviceDiskLive(libxlDomainObjPrivatePtr 
priv,
 }
 
 static int
+libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
+   libxlDomainObjPrivatePtr priv,
+   virDomainObjPtr vm,
+   virDomainNetDefPtr net)
+{
+int actualType;
+libxl_device_nic nic;
+int ret = -1;
+
+/* preallocate new slot for device */
+if (VIR_REALLOC_N(vm-def-nets, vm-def-nnets + 1)  0)
+return -1;
+
+/* If appropriate, grab a physical device from the configured
+ * network's pool of devices, or resolve bridge device name
+ * to the one defined in the network definition.
+ */
+if (networkAllocateActualDevice(vm-def, net)  0)
+return -1;
+
+actualType = virDomainNetGetActualType(net);
+
+if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+/* This is really a smart hostdev, so it should be attached
+ * as a hostdev (the hostdev code will reach over into the
+ * netdev-specific code as appropriate), then also added to
+ * the nets list (see out:) if successful.
+ */
+ret = libxlDomainAttachHostDevice(driver, priv, vm,
+  virDomainNetGetActualHostdev(net));
+goto out;
+}
+
+libxl_device_nic_init(nic);
+if (libxlMakeNic(vm-def, net, nic)  0)
+goto cleanup;
+
+if (libxl_device_nic_add(priv-ctx, vm-def-id, nic, 0)) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(libxenlight failed to attach network device));
+goto cleanup;
+}
+
+ret = 0;
+
+ cleanup:
+libxl_device_nic_dispose(nic);
+ out:
+if (!ret)
+vm-def-nets[vm-def-nnets++] = net;
+return ret;
+}
+
+static int
 libxlDomainAttachDeviceLive(libxlDriverPrivatePtr driver,
 libxlDomainObjPrivatePtr priv,
 virDomainObjPtr vm,
@@ -2770,8 +2823,16 @@ libxlDomainAttachDeviceLive(libxlDriverPrivatePtr driver,
 dev-data.disk = NULL;
 break;
 
+case VIR_DOMAIN_DEVICE_NET:
+ret = libxlDomainAttachNetDevice(driver, priv, vm,
+ dev-data.net);
+if (!ret)
+dev-data.net = NULL;
+break;
+
 case VIR_DOMAIN_DEVICE_HOSTDEV:
-ret = libxlDomainAttachHostDevice(driver, priv, vm, dev);
+ret = libxlDomainAttachHostDevice(driver, priv, vm,
+  dev-data.hostdev);
 if (!ret)
 dev-data.hostdev = NULL;
 break;
@@ -2790,6 +2851,7 @@ static int
 libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
 {
 virDomainDiskDefPtr disk;
+virDomainNetDefPtr net

[libvirt] [PATCH 3/3] libxl: fix return value error Attach|DetachDeviceFlags

2014-07-14 Thread Chunyan Liu
Code logic in libxlDomainAttachDeviceFlags and libxlDomainDetachDeviceFlags
is wrong with return value in error cases.

'ret' was being set to 0 if 'flags  VIR_DOMAIN_DEVICE_MODIFY_CONFIG' was
false. Then if something like virDomainDeviceDefParse() failed in the
VIR_DOMAIN_DEVICE_MODIFY_LIVE logic, the error would be reported but the
function would return success.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libxl/libxl_driver.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 9cd56b5..5fbff1c 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3285,10 +3285,8 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const 
char *xml,
 driver-xmlopt)))
 goto endjob;
 
-if ((ret = libxlDomainAttachDeviceConfig(vmdef, dev))  0)
+if (libxlDomainAttachDeviceConfig(vmdef, dev)  0)
 goto endjob;
-} else {
-ret = 0;
 }
 
 if (flags  VIR_DOMAIN_DEVICE_MODIFY_LIVE) {
@@ -3299,7 +3297,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char 
*xml,
 VIR_DOMAIN_XML_INACTIVE)))
 goto endjob;
 
-if ((ret = libxlDomainAttachDeviceLive(driver, priv, vm, dev))  0)
+if (libxlDomainAttachDeviceLive(driver, priv, vm, dev)  0)
 goto endjob;
 
 /*
@@ -3307,11 +3305,13 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const 
char *xml,
  * changed even if we attach the device failed.
  */
 if (virDomainSaveStatus(driver-xmlopt, cfg-stateDir, vm)  0)
-ret = -1;
+goto endjob;
 }
 
+ret = 0;
+
 /* Finally, if no error until here, we can save config. */
-if (!ret  (flags  VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) {
+if (flags  VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
 ret = virDomainSaveConfig(cfg-configDir, vmdef);
 if (!ret) {
 virDomainObjAssignDef(vm, vmdef, false, NULL);
@@ -3396,10 +3396,8 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const 
char *xml,
 driver-xmlopt)))
 goto endjob;
 
-if ((ret = libxlDomainDetachDeviceConfig(vmdef, dev))  0)
+if (libxlDomainDetachDeviceConfig(vmdef, dev)  0)
 goto endjob;
-} else {
-ret = 0;
 }
 
 if (flags  VIR_DOMAIN_DEVICE_MODIFY_LIVE) {
@@ -3410,7 +3408,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char 
*xml,
 VIR_DOMAIN_XML_INACTIVE)))
 goto endjob;
 
-if ((ret = libxlDomainDetachDeviceLive(driver, priv, vm, dev))  0)
+if (libxlDomainDetachDeviceLive(driver, priv, vm, dev)  0)
 goto endjob;
 
 /*
@@ -3418,11 +3416,13 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const 
char *xml,
  * changed even if we attach the device failed.
  */
 if (virDomainSaveStatus(driver-xmlopt, cfg-stateDir, vm)  0)
-ret = -1;
+goto endjob;
 }
 
+ret = 0;
+
 /* Finally, if no error until here, we can save config. */
-if (!ret  (flags  VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) {
+if (flags  VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
 ret = virDomainSaveConfig(cfg-configDir, vmdef);
 if (!ret) {
 virDomainObjAssignDef(vm, vmdef, false, NULL);
-- 
1.8.4.5

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


[libvirt] [PATCH V2] storagevol: add nocow to vol xml

2014-07-08 Thread Chunyan Liu
Add 'nocow' to storage volume xml so that user can have an option
to set NOCOW flag to the newly created volume. It's useful on btrfs
file system to enhance performance.

Btrfs has low performance when hosting VM images, even more when the guest
in those VM are also using btrfs as file system. One way to mitigate this
bad performance is to turn off COW attributes on VM files. Generally, there
are two ways to turn off NOCOW on btrfs: a) by mounting fs with nodatacow,
then all newly created files will be NOCOW. b) per file. Add the NOCOW file
attribute. It could only be done to empty or new files.

This patch tries the second way, according to 'nocow' option, it could set
NOCOW flag per file:
for raw file images, handle 'nocow' in libvirt code; for non-raw file images,
pass 'nocow=on' option to qemu-img, and let qemu-img to handle that (requires
qemu-img version = 2.1).

Signed-off-by: Chunyan Liu cy...@suse.com
---
Changes:
  - now qemu-img can handle 'nocow=on' option, just pass 'nocow=on' to
qemu-img for non-raw file images. No need to handle all file type
in libvirt code.

Pervious version is here:
  http://www.redhat.com/archives/libvir-list/2013-December/msg01257.html

---
 docs/formatstorage.html.in|  7 +++
 docs/schemas/storagevol.rng   |  5 +
 src/conf/storage_conf.c   |  3 +++
 src/storage/storage_backend.c | 22 ++
 src/util/virstoragefile.h |  1 +
 5 files changed, 38 insertions(+)

diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index 1cd82b4..e8862bf 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -385,6 +385,7 @@
 lt;labelgt;virt_image_tlt;/labelgt;
   lt;/permissionsgt;
   lt;compatgt;1.1lt;/compatgt;
+  lt;nocow/gt;
   lt;featuresgt;
 lt;lazy_refcounts/gt;
   lt;/featuresgt;
@@ -424,6 +425,12 @@
 1.1 is used. If omitted, qemu-img default is used.
 span class=sinceSince 1.1.0/span
   /dd
+  dtcodenocow/code/dt
+  ddTurn off COW of the newly created volume. So far, this is only valid
+to a file image in btrfs file system. It will improve performance when
+the file image is used in VM. To create non-raw file images, it
+requires QEMU version since 2.1. span class=sinceSince 1.2.6/span
+  /dd
   dtcodefeatures/code/dt
   ddFormat-specific features. Only used for codeqcow2/code now.
 Valid sub-elements are:
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 3798476..1b2d4cc 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -138,6 +138,11 @@
   ref name='compat'/
 /optional
 optional
+  element name='nocow'
+empty/
+  /element
+/optional
+optional
   ref name='fileFormatFeatures'/
 /optional
   /interleave
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 9ac5975..77ea23e 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1285,6 +1285,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
 virStringFreeList(version);
 }
 
+if (virXPathNode(./target/nocow, ctxt))
+ret-target.nocow = true;
+
 if (options-featureFromString  virXPathNode(./target/features, ctxt)) 
{
 if ((n = virXPathNodeSet(./target/features/*, ctxt, nodes))  0)
 goto error;
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index e83a108..80347de 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -37,6 +37,9 @@
 #ifdef __linux__
 # include sys/ioctl.h
 # include linux/fs.h
+# ifndef FS_NOCOW_FL
+#  define FS_NOCOW_FL 0x0080 /* Do not cow file */
+# endif
 #endif
 
 #if WITH_SELINUX
@@ -452,6 +455,21 @@ virStorageBackendCreateRaw(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 goto cleanup;
 }
 
+if (vol-target.nocow) {
+#ifdef __linux__
+int attr;
+
+/* Set NOCOW flag. This is an optimisation for btrfs.
+ * The FS_IOC_SETFLAGS ioctl return value will be ignored since any
+ * failure of this operation should not block the left work.
+ */
+if (ioctl(fd, FS_IOC_GETFLAGS, attr) == 0) {
+attr |= FS_NOCOW_FL;
+ioctl(fd, FS_IOC_SETFLAGS, attr);
+}
+#endif
+}
+
 if ((ret = createRawFile(fd, vol, inputvol))  0)
 /* createRawFile already reported the exact error. */
 ret = -1;
@@ -717,6 +735,7 @@ virStorageBackendCreateQemuImgOpts(char **opts,
bool preallocate,
int format,
const char *compat,
+   bool nocow,
virBitmapPtr features)
 {
 virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -729,6 +748,8

[libvirt] [PATCH 1/2] libxl: support syntax interface type=hostdev

2014-05-08 Thread Chunyan Liu
Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libxl/libxl_conf.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 298c8a1..b7fed7f 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -921,25 +921,31 @@ static int
 libxlMakeNicList(virDomainDefPtr def,  libxl_domain_config *d_config)
 {
 virDomainNetDefPtr *l_nics = def-nets;
-int nnics = def-nnets;
+size_t nnics = def-nnets;
 libxl_device_nic *x_nics;
-size_t i;
+size_t i, nvnics = 0;
 
 if (VIR_ALLOC_N(x_nics, nnics)  0)
 return -1;
 
 for (i = 0; i  nnics; i++) {
-if (libxlMakeNic(def, l_nics[i], x_nics[i]))
+if (l_nics[i]-type == VIR_DOMAIN_NET_TYPE_HOSTDEV)
+continue;
+
+if (libxlMakeNic(def, l_nics[i], x_nics[nvnics]))
 goto error;
 /*
  * The devid (at least right now) will not get initialized by
  * libxl in the setup case but is required for starting the
  * device-model.
  */
-if (x_nics[i].devid  0)
-x_nics[i].devid = i;
+if (x_nics[nvnics].devid  0)
+x_nics[nvnics].devid = nvnics;
+
+nvnics++;
 }
 
+VIR_SHRINK_N(x_nics, nnics, nnics - nvnics);
 d_config-nics = x_nics;
 d_config-num_nics = nnics;
 
-- 
1.8.4.5

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


[libvirt] [PATCH 2/2] update documentation of interface type='hostdev'

2014-05-08 Thread Chunyan Liu
interface type='hostdev' managed='yes' is supported, but
nowhere mentions 'managed' in interface type='hostdev' syntax.
Update documentation to cover it.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 docs/formatdomain.html.in | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 4f19473..c3b9f5b 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3510,7 +3510,7 @@
 pre
   ...
   lt;devicesgt;
-lt;interface type='hostdev'gt;
+lt;interface type='hostdev' managed='yes'gt;
   lt;driver name='vfio'/gt;
   lt;sourcegt;
 lt;address type='pci' domain='0x' bus='0x00' slot='0x07' 
function='0x0'/gt;
@@ -3523,6 +3523,18 @@
   lt;/devicesgt;
   .../pre
 
+p
+  Similar to the functionality of a standard lt;hostdevgt; device,
+  when codemanaged/code is yes, it is detached from the host
+  before being passed on to the guest, and reattached to the host
+  after the guest exits. If codemanaged/code is omitted or no,
+  the user is responsible to call codevirNodeDeviceDettach/code
+  (or codevirsh nodedev-dettach/code) before starting the guest
+  or hot-plugging the device, and codevirNodeDeviceReAttach/code
+  (or codevirsh nodedev-reattach/code) after hot-unplug or
+  stopping the guest.
+/p
+
 
 h5a name=elementsNICSMulticastMulticast tunnel/a/h5
 
-- 
1.8.4.5

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


[libvirt] [PATCH] libxl_driver.c: cleanup code

2014-03-18 Thread Chunyan Liu
Following Jim's comments about add pci passthrough to libxl patch:
https://www.redhat.com/archives/libvir-list/2014-March/msg00170.html

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/libxl/libxl_driver.c | 47 +++
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index a6ba10a..4d22fb7 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3357,10 +3357,10 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 if (virHostdevPreparePCIDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
 vm-def-name, vm-def-uuid,
 hostdev, 1, 0)  0)
-goto cleanup;
+return -1;
 
 if (libxlMakePci(hostdev, pcidev)  0)
-goto reattach_hostdev;
+goto error;
 
 if (libxl_device_pci_add(priv-ctx, vm-def-id, pcidev, 0)  0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3369,17 +3369,15 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr 
driver,
hostdev-source.subsys.u.pci.addr.bus,
hostdev-source.subsys.u.pci.addr.slot,
hostdev-source.subsys.u.pci.addr.function);
-goto reattach_hostdev;
+goto error;
 }
 
 vm-def-hostdevs[vm-def-nhostdevs++] = hostdev;
 return 0;
 
-reattach_hostdev:
+error:
 virHostdevReAttachPCIDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
  vm-def-name, hostdev, 1, NULL);
-
-cleanup:
 return -1;
 }
 
@@ -3401,20 +3399,17 @@ libxlDomainAttachHostDevice(libxlDriverPrivatePtr 
driver,
 switch (hostdev-source.subsys.type) {
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
 if (libxlDomainAttachHostPCIDevice(driver, priv, vm, hostdev)  0)
-goto error;
+return -1;
 break;
 
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_(hostdev subsys type '%s' not supported),

virDomainHostdevSubsysTypeToString(hostdev-source.subsys.type));
-goto error;
+return -1;
 }
 
 return 0;
-
-error:
-return -1;
 }
 
 static int
@@ -3608,14 +3603,14 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr 
driver,
_(cannot hot unplug multifunction PCI device: 
%.4x:%.2x:%.2x.%.1x),
subsys-u.pci.addr.domain, subsys-u.pci.addr.bus,
subsys-u.pci.addr.slot, subsys-u.pci.addr.function);
-goto cleanup;
+goto error;
 }
 
 
 libxl_device_pci_init(pcidev);
 
 if (libxlMakePci(detach, pcidev)  0)
-goto cleanup;
+goto error;
 
 if (libxl_device_pci_remove(priv-ctx, vm-def-id, pcidev, 0)  0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3623,7 +3618,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr 
driver,
   %.4x:%.2x:%.2x.%.1x),
subsys-u.pci.addr.domain, subsys-u.pci.addr.bus,
subsys-u.pci.addr.slot, subsys-u.pci.addr.function);
-goto cleanup;
+goto error;
 }
 
 libxl_device_pci_dispose(pcidev);
@@ -3635,7 +3630,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr 
driver,
 
 return 0;
 
-cleanup:
+error:
 virDomainHostdevDefFree(detach);
 return -1;
 }
@@ -4897,7 +4892,6 @@ libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
   unsigned *function)
 {
 virNodeDevCapsDefPtr cap;
-int ret = -1;
 
 cap = def-caps;
 while (cap) {
@@ -4915,12 +4909,10 @@ libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
 if (!cap) {
 virReportError(VIR_ERR_INVALID_ARG,
_(device %s is not a PCI device), def-name);
-goto out;
+return -1;
 }
 
-ret = 0;
-out:
-return ret;
+return 0;
 }
 
 static int
@@ -5012,12 +5004,12 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev)
 goto cleanup;
 
 if (virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci)  0)
-goto out;
+goto cleanup;
 
 ret = 0;
-out:
-virPCIDeviceFree(pci);
+
 cleanup:
+virPCIDeviceFree(pci);
 virNodeDeviceDefFree(def);
 VIR_FREE(xml);
 return ret;
@@ -5026,7 +5018,7 @@ cleanup:
 static int
 libxlNodeDeviceReset(virNodeDevicePtr dev)
 {
-virPCIDevicePtr pci;
+virPCIDevicePtr pci = NULL;
 unsigned domain = 0, bus = 0, slot = 0, function = 0;
 int ret = -1;
 virNodeDeviceDefPtr def = NULL;
@@ -5053,18 +5045,17 @@ libxlNodeDeviceReset(virNodeDevicePtr dev)
 goto cleanup;
 
 if (virHostdevPCINodeDeviceReset(hostdev_mgr, pci)  0)
-goto out;
+goto cleanup;
 
 ret = 0;
-out:
-virPCIDeviceFree(pci);
+
 cleanup:
+virPCIDeviceFree(pci);
 virNodeDeviceDefFree(def);
 VIR_FREE(xml);
 return ret;
 }
 
-
 static virDriver libxlDriver

[libvirt] [PATCH] virhostdev.h: remove ATTRIBUTE_NONNULL to oldStateDir

2014-03-18 Thread Chunyan Liu
For libxl driver usage, it didn't support hostdev passthrough before,
oldStateDir is NULL when calling virHostdevReAttachDomainHostdevs.
That is allowed. Remove ATTRIBUTE_NONNULL setting to oldStateDir.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/util/virhostdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index a56a2b5..2036430 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -142,7 +142,7 @@ virHostdevReAttachDomainDevices(virHostdevManagerPtr mgr,
 virDomainDefPtr def,
 unsigned int flags,
 const char *oldStateDir)
-ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) 
ATTRIBUTE_NONNULL(5);
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
 
 /* functions used by NodeDevDetach/Reattach/Reset */
 int virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr,
-- 
1.7.12.4

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


Re: [libvirt] [PATCH v14 42/49] rename some function names to keep consistency

2014-03-12 Thread Chunyan Liu
2014-03-12 23:12 GMT+08:00 Daniel P. Berrange berra...@redhat.com:

 On Fri, Mar 07, 2014 at 06:53:09PM +0800, Chunyan Liu wrote:
  Signed-off-by: Chunyan Liu cy...@suse.com
  ---
   src/libvirt_private.syms |  8 
   src/qemu/qemu_hostdev.c  | 16 +++
   src/util/virhostdev.c| 52
 
   src/util/virhostdev.h| 40 ++---
   4 files changed, 58 insertions(+), 58 deletions(-)
 
  diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
  index 5bb529c..e7d9d56 100644
  --- a/src/libvirt_private.syms
  +++ b/src/libvirt_private.syms
  @@ -1297,10 +1297,10 @@ virHostdevManagerGetDefault;
   virHostdevPciNodeDeviceDetach;
   virHostdevPciNodeDeviceReAttach;
   virHostdevPciNodeDeviceReset;
  -virHostdevPreparePCIDevices;
  -virHostdevPrepareSCSIDevices;
  -virHostdevPrepareUSBDevices;
  -virHostdevReAttachPCIDevices;
  +virHostdevPreparePciHostdevs;
  +virHostdevPrepareScsiHostdevs;
  +virHostdevPrepareUsbHostdevs;
  +virHostdevReAttachPciHostdevs;
   virHostdevReAttachScsiHostdevs;
   virHostdevReAttachUsbHostdevs;
   virHostdevUpdateActivePciHostdevs;

 IMHO this is fixing the wrong side of the inconsistency.

 PCI, USB and SCSI are all abbreviations, so using capitalization
 is correct. We should instead fix the Pci, Usb and Scsi names.


Thanks. I'll update.



 Regards,
 Daniel
 --
 |: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/:|
 |: http://libvirt.org  -o- http://virt-manager.org:|
 |: http://autobuild.org   -o- http://search.cpan.org/~danberr/:|
 |: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc:|


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

Re: [libvirt] [PATCH v14 45/49] add parameter checks to common interfaces

2014-03-12 Thread Chunyan Liu
2014-03-12 23:11 GMT+08:00 Daniel P. Berrange berra...@redhat.com:

 On Fri, Mar 07, 2014 at 06:53:12PM +0800, Chunyan Liu wrote:
  Check NULL parameter inputs
 
  Signed-off-by: Chunyan Liu cy...@suse.com
  ---
   src/util/virhostdev.c | 57
 +++
   1 file changed, 57 insertions(+)
 
  diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
  index 577de48..5f61bfc 100644
  --- a/src/util/virhostdev.c
  +++ b/src/util/virhostdev.c
  @@ -468,6 +468,11 @@ virHostdevPreparePciHostdevs(virHostdevManagerPtr
 hostdev_mgr,
   size_t i;
   int ret = -1;
 
  +if (!nhostdevs)
  +return 0;

 This is reasonable because it is an expected case.

  +if (hostdev_mgr == NULL)
  +return -1;

 This is something that should never happen except by programmer
 error, since this is allocated right at libvirtd startup and
 then never changed thereafter.

 It is preferrable to use ATTRIBUTE_NONNULL() in the header
 file for these kind of things.


Will update.




 Regards,
 Daniel
 --
 |: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/:|
 |: http://libvirt.org  -o- http://virt-manager.org:|
 |: http://autobuild.org   -o- http://search.cpan.org/~danberr/:|
 |: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc:|


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

[libvirt] [PATCH v14 03/49] update qemuPrepareHostUSBDevices parameters to keep consistency

2014-03-07 Thread Chunyan Liu
Update parameters from vm-def to specific name, hostdevs, nhostdevs to keep
consistentcy with PreparePCIDevices and PrepareSCSIDevices. And, at the same
time, make it reusable in later patch.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 src/qemu/qemu_hostdev.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index e4f6b1b..47c7f96 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -993,15 +993,15 @@ out:
 
 static int
 qemuPrepareHostUSBDevices(virQEMUDriverPtr driver,
-  virDomainDefPtr def,
+  const char *name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs,
   bool coldBoot)
 {
 size_t i;
 int ret = -1;
 virUSBDeviceListPtr list;
 virUSBDevicePtr tmp;
-virDomainHostdevDefPtr *hostdevs = def-hostdevs;
-int nhostdevs = def-nhostdevs;
 
 /* To prevent situation where USB device is assigned to two domains
  * we need to keep a list of currently assigned USB devices.
@@ -1041,7 +1041,7 @@ qemuPrepareHostUSBDevices(virQEMUDriverPtr driver,
  * and add them do driver list. However, if something goes
  * wrong, perform rollback.
  */
-if (qemuPrepareHostdevUSBDevices(driver, def-name, list)  0)
+if (qemuPrepareHostdevUSBDevices(driver, name, list)  0)
 goto cleanup;
 
 /* Loop 2: Temporary list was successfully merged with
@@ -1201,7 +1201,8 @@ qemuPrepareHostDevices(virQEMUDriverPtr driver,
  qemuCaps)  0)
 return -1;
 
-if (qemuPrepareHostUSBDevices(driver, def, coldBoot)  0)
+if (qemuPrepareHostUSBDevices(driver, def-name,
+  def-hostdevs, def-nhostdevs, coldBoot)  0)
 return -1;
 
 if (qemuPrepareHostdevSCSIDevices(driver, def-name,
-- 
1.9.0

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


  1   2   3   >