[libvirt] [PATCH] remove a static limit on max domains in python bindings

* python/libvirt-override.c: remove the predefined array in the virConnectListDomainsID binding and call virConnectNumOfDomains to do a proper allocation diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 8a643a3..2dea16b 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -1616,7 +1616,7 @@ static PyObject * libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; - int ids[500], c_retval, i; + int *ids = NULL, c_retval, i; virConnectPtr conn; PyObject *pyobj_conn; @@ -1626,14 +1626,34 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); LIBVIRT_BEGIN_ALLOW_THREADS; - c_retval = virConnectListDomains(conn, &ids[0], 500); + c_retval = virConnectNumOfDomains(conn); LIBVIRT_END_ALLOW_THREADS; if (c_retval < 0) return VIR_PY_NONE; + + if (c_retval) { + ids = malloc(sizeof(*ids) * c_retval); + if (!ids) + return VIR_PY_NONE; + + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virConnectListDomains(conn, ids, c_retval); + LIBVIRT_END_ALLOW_THREADS; + if (c_retval < 0) { + free(ids); + return VIR_PY_NONE; + } + } py_retval = PyList_New(c_retval); - for (i = 0;i < c_retval;i++) { - PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i])); + + if (ids) { + for (i = 0;i < c_retval;i++) { + PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i])); + } + free(ids); } + return(py_retval); } Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On 2011年12月29日 09:56, Daniel Veillard wrote:
* python/libvirt-override.c: remove the predefined array in the virConnectListDomainsID binding and call virConnectNumOfDomains to do a proper allocation
diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 8a643a3..2dea16b 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -1616,7 +1616,7 @@ static PyObject * libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; - int ids[500], c_retval, i; + int *ids = NULL, c_retval, i; virConnectPtr conn; PyObject *pyobj_conn;
@@ -1626,14 +1626,34 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
LIBVIRT_BEGIN_ALLOW_THREADS; - c_retval = virConnectListDomains(conn,&ids[0], 500); + c_retval = virConnectNumOfDomains(conn); LIBVIRT_END_ALLOW_THREADS; if (c_retval< 0) return VIR_PY_NONE; + + if (c_retval) { + ids = malloc(sizeof(*ids) * c_retval); + if (!ids)
Intention problems, should be caused by TAB use.
+ return VIR_PY_NONE; + + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virConnectListDomains(conn, ids, c_retval); + LIBVIRT_END_ALLOW_THREADS; + if (c_retval< 0) { + free(ids); + return VIR_PY_NONE; + } + } py_retval = PyList_New(c_retval); - for (i = 0;i< c_retval;i++) { - PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i])); + + if (ids) { + for (i = 0;i< c_retval;i++) { + PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i])); + } + free(ids); } + return(py_retval); }
Daniel
ACK with the TAB use replaced by 4 white spaces.

On Thu, Dec 29, 2011 at 12:36:14PM +0800, Osier Yang wrote:
On 2011年12月29日 09:56, Daniel Veillard wrote:
* python/libvirt-override.c: remove the predefined array in the virConnectListDomainsID binding and call virConnectNumOfDomains to do a proper allocation
diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 8a643a3..2dea16b 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -1616,7 +1616,7 @@ static PyObject * libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { PyObject *py_retval; - int ids[500], c_retval, i; + int *ids = NULL, c_retval, i; virConnectPtr conn; PyObject *pyobj_conn;
@@ -1626,14 +1626,34 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED, conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
LIBVIRT_BEGIN_ALLOW_THREADS; - c_retval = virConnectListDomains(conn,&ids[0], 500); + c_retval = virConnectNumOfDomains(conn); LIBVIRT_END_ALLOW_THREADS; if (c_retval< 0) return VIR_PY_NONE; + + if (c_retval) { + ids = malloc(sizeof(*ids) * c_retval); + if (!ids)
Intention problems, should be caused by TAB use.
yeah, apparently I forgot to copy my .vimrc to the laptop :)
+ return VIR_PY_NONE; + + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virConnectListDomains(conn, ids, c_retval); + LIBVIRT_END_ALLOW_THREADS; + if (c_retval< 0) { + free(ids); + return VIR_PY_NONE; + } + } py_retval = PyList_New(c_retval); - for (i = 0;i< c_retval;i++) { - PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i])); + + if (ids) { + for (i = 0;i< c_retval;i++) { + PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i])); + } + free(ids); } + return(py_retval); }
Daniel
ACK with the TAB use replaced by 4 white spaces.
Thanks, fixed and commited, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

I want to change the default path of qemu emulator in libvirt By default the path is /usr/libexec/qemu-kvm Which is defined in every guest xml <emulator> tag I want to change this default path. Can any one help ??? I want to specify path before the virt-install is used and editing every guest xml to change emulator path is of no use to me. Please help how I can change the path permanently . DISCLAIMER: ----------------------------------------------------------------------------------------------------------------------- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or NECHCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of NECHCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. . -----------------------------------------------------------------------------------------------------------------------

On 2011年12月29日 19:12, Pankaj Rawat wrote:
I want to change the default path of qemu emulator in libvirt
By default the path is /usr/libexec/qemu-kvm Which is defined in every guest xml<emulator> tag
I want to change this default path. Can any one help ???
If no emulator is specified in the XML, libvirt will probe a proper emulator from the driver's capabilities (See virsh capabilities) by the requested OS, arch, and domain type. The problem is virt-install doesn't has an option for you to specify the emulator path. And thus libvirt will always probe the emulator. So you might want to request virt-install to add an option for the emulator in virt-tools list. Regards, Osier

Is'nt there is any shortcut for the problem then to request virt-install because that is a very long procedure and might take weeks or months -----Original Message----- From: Osier Yang [mailto:jyang@redhat.com] Sent: Thursday, December 29, 2011 5:35 PM To: Pankaj Rawat Cc: libvir-list@redhat.com Subject: Re: [libvirt] Changing the default qemu path in libvirt On 2011年12月29日 19:12, Pankaj Rawat wrote:
I want to change the default path of qemu emulator in libvirt
By default the path is /usr/libexec/qemu-kvm Which is defined in every guest xml<emulator> tag
I want to change this default path. Can any one help ???
If no emulator is specified in the XML, libvirt will probe a proper emulator from the driver's capabilities (See virsh capabilities) by the requested OS, arch, and domain type. The problem is virt-install doesn't has an option for you to specify the emulator path. And thus libvirt will always probe the emulator. So you might want to request virt-install to add an option for the emulator in virt-tools list. Regards, Osier DISCLAIMER: ----------------------------------------------------------------------------------------------------------------------- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or NECHCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of NECHCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. . -----------------------------------------------------------------------------------------------------------------------

On 2011年12月29日 21:49, Pankaj Rawat wrote:
Is'nt there is any shortcut for the problem then to request virt-install because that is a very long procedure and might take weeks or months
As far as I known, no. :-)
-----Original Message----- From: Osier Yang [mailto:jyang@redhat.com] Sent: Thursday, December 29, 2011 5:35 PM To: Pankaj Rawat Cc: libvir-list@redhat.com Subject: Re: [libvirt] Changing the default qemu path in libvirt
On 2011年12月29日 19:12, Pankaj Rawat wrote:
I want to change the default path of qemu emulator in libvirt
By default the path is /usr/libexec/qemu-kvm Which is defined in every guest xml<emulator> tag
I want to change this default path. Can any one help ???
If no emulator is specified in the XML, libvirt will probe a proper emulator from the driver's capabilities (See virsh capabilities) by the requested OS, arch, and domain type.
The problem is virt-install doesn't has an option for you to specify the emulator path. And thus libvirt will always probe the emulator. So you might want to request virt-install to add an option for the emulator in virt-tools list.
Regards, Osier
DISCLAIMER: ----------------------------------------------------------------------------------------------------------------------- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. It shall not attach any liability on the originator or NECHCL or its affiliates. Any views or opinions presented in this email are solely those of the author and may not necessarily reflect the opinions of NECHCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. . -----------------------------------------------------------------------------------------------------------------------
participants (3)
-
Daniel Veillard
-
Osier Yang
-
Pankaj Rawat