[libvirt] Fix compilation failure if yajl is not available
by Daniel Veillard
I commited the following as it was a compile breaker for most people I
assume and it's trivial
commit a4e09c1ed81f7361ff03d95ad42eac49d4d60812
Author: Daniel Veillard <veillard(a)redhat.com>
Date: Tue Dec 8 11:08:17 2009 +0100
Fix a compilation failure if yajl not avail
configure: yajl: no
CC libvirt_util_la-json.lo
util/json.c:32:27: error: yajl/yajl_gen.h: No such file or directory
util/json.c:33:29: error: yajl/yajl_parse.h: No such file or directory
* src/util/json.c: remove the includes if yajl not configured in
diff --git a/src/util/json.c b/src/util/json.c
index 93b8186..35f6e52 100644
--- a/src/util/json.c
+++ b/src/util/json.c
@@ -29,8 +29,10 @@
#include "logging.h"
#include "util.h"
+#if HAVE_YAJL
#include <yajl/yajl_gen.h>
#include <yajl/yajl_parse.h>
+#endif
/* XXX fixme */
#define VIR_FROM_THIS VIR_FROM_NONE
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel(a)veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
15 years, 5 months
[libvirt] fc12 virsh tap device problem
by Chiradeep Vittal
Hi,
On a fresh FC12 system, I am able to create and run KVM-based vms with tap networking using the qemu-kvm command line but not using virsh.
I have user and group set to "root" in /etc/libvirt/qemu.conf. "user mode networking" works with virsh, but not tap!
I have this xml:
<domain type='kvm'>
<name>centos</name>
<uuid>22d9d573-d82c-c18d-36c0-d3ffef057468</uuid>
<memory>131072</memory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64'>hvm</type>
</os>
<features>
<acpi/>
<pae/>
</features>
<clock offset='utc'/>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
<disk type='file' device='disk'>
<source file='/var/lib/images/centos.5-4.x86-64/centos-small.img'/>
<target dev='hda' bus='ide'/>
</disk>
<interface type='user'>
<mac address='52:54:00:7e:5b:58'/>
</interface>
<interface type='ethernet'>
<mac address='52:54:00:2e:33:c8'/>
<script path='/var/lib/images/centos.5-4.x86-64/qemu-ifup'/>
</interface>
<graphics type='vnc' port='5910' autoport='no' listen=''/>
</devices>
</domain>
This won't start even when I execute virsh as root:
[root@fc12 centos.5-4.x86-64]# virsh -c qemu+unix:///system create domr.xml
error: Failed to create domain from domr.xml
error: monitor socket did not show up.: No such file or directory
[root@fc12 centos.5-4.x86-64]# tail -3 /var/log/libvirt/qemu/centos.log
LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin QEMU_AUDIO_DRV=none /usr/bin/qemu-kvm -S -M pc-0.11 -m 128 -smp 1 -name centos -uuid 22d9d573-d82c-c18d-36c0-d3ffef057468 -monitor unix:/var/lib/libvirt/qemu/centos.monitor,server,nowait -boot c -drive file=/var/lib/images/centos.5-4.x86-64/centos-small.img,if=ide,index=0,boot=on -net nic,macaddr=52:54:00:7e:5b:58,vlan=0,name=nic.0 -net user,vlan=0,name=user.0 -net nic,macaddr=52:54:00:2e:33:c8,vlan=1,name=nic.1 -net tap,script=/var/lib/images/centos.5-4.x86-64/qemu-ifup,vlan=1,name=tap.0 -serial none -parallel none -usb -vnc :10 -vga cirrus
warning: could not configure /dev/net/tun: no virtual network emulation
qemu: Could not initialize device 'tap'
'***** But I can execute the same command line and it works!!********
[root@fc12 centos.5-4.x86-64]# LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin QEMU_AUDIO_DRV=none /usr/bin/qemu-kvm -S -M pc-0.11 -m 128 -smp 1 -name centos -uuid 22d9d573-d82c-c18d-36c0-d3ffef057468 -monitor unix:/var/lib/libvirt/qemu/centos.monitor,server,nowait -boot c -drive file=/var/lib/images/centos.5-4.x86-64/centos-small.img,if=ide,index=0,boot=on -net nic,macaddr=52:54:00:7e:5b:58,vlan=0,name=nic.0 -net user,vlan=0,name=user.0 -net nic,macaddr=52:54:00:2e:33:c8,vlan=1,name=nic.1 -net tap,script=/var/lib/images/centos.5-4.x86-64/qemu-ifup,vlan=1,name=tap.0 -serial none -parallel none -usb -vnc :10 -vga cirrus &
[2] 4543
[root@fc12 centos.5-4.x86-64]# ps -ef | grep qemu
root 4543 3449 0 19:02 pts/12 00:00:00 /usr/bin/qemu-kvm -S -M pc-0.11 -m 128 -smp 1 -name centos -uuid 22d9d573-d82c-c18d-36c0-d3ffef057468 -monitor unix:/var/lib/libvirt/qemu/centos.monitor,server,nowait -boot c -drive file=/var/lib/images/centos.5-4.x86-64/centos-small.img,if=ide,index=0,boot=on -net nic,macaddr=52:54:00:7e:5b:58,vlan=0,name=nic.0 -net user,vlan=0,name=user.0 -net nic,macaddr=52:54:00:2e:33:c8,vlan=1,name=nic.1 -net tap,script=/var/lib/images/centos.5-4.x86-64/qemu-ifup,vlan=1,name=tap.0 -serial none -parallel none -usb -vnc :10 -vga cirrus
15 years, 5 months
[libvirt] qemu smbios options in domain xml format
by Phillip Balli
Hello,
I could not find any explicit mention of support for the -smbios
options which are present in qemu 0.10.5+ in the domain xml format or
the qemu/kvm hypervisor driver pages. Is there some way to specify
commands and options which are not described in the xml config by
adjusting something in the way libvirt processes the xml? Or is
providing smbios options just not supported currently?
15 years, 5 months
[libvirt] RE: [virt-tools-list] Questions about virt-manager running on Arch of Itanium 64
by Dustin Xiong
> >>.......<<<
> >> > I downloaded and compiled the latest version of virtinst:
> > virtinst-0.500.0.tar.gz.
> >> > then compile the virt-manager-0.8.0, error changed as below:
> >> >
> >> > [root@kvm virt-manager-0.8.0]# make check
> >> > Making check in src
> >> > make[1]: Entering directory
> > `/home/dustin/virt-manager/virt-manager-0.8.0/src'
> >> > Making check in virtManager
> >> > make[2]: Entering directory
> > `/home/dustin/virt-manager/virt-manager-0.8.0/src/virtManager'
> >> > make ch! eck-local
> >> > make[3]: Entering directory `/home/dust! in/virt-
> > manager/virt-manager-0.8.0/src/virtManager'
> >> > PYTHONPATH=./..:../graphWidgets/.libs python about.py && touch
> > .tstamp.about.py
> >> > PYTHONPATH=./..:../graphWidgets/.libs python addhardware.py && touch
> > .tstamp.addhardware.py
> >> > Traceback (most recent call last):
> >> > File "addhardware.py", line 35, in ?
> >> > from virtManager.asyncjob import vmmAsyncJob
> >> > File
> > "/home/dustin/virt-manager/virt-manager-0.8.0/src/virtManager/asyncjob.py",
> > line 30, in ?
> >> > class vmmAsyncJob(gobject.GObject):
> >> > File
> > "/home/dustin/virt-manager/virt-manager-0.8.0/src/virtManager/asyncjob.py",
> > line 40, in vmmAsyncJob
> >> > def __init__(self, config, callback, args=None,
> >> > NameError: name '_' is not defined
> >> >
> >> > Thanks for help.If you need any further infos please dont't hesitate
> > to tell me.
> >> >
> >>
> >> Ah, didn't notice the make check! in the first mail. 'make check' doesn't
> >> work in the virt-manager code base, never taken the time to fix it. You
> >> should just be able to 'make && make install', or 'make' and python
> >> src/virt-manager.py to run from the source dir. If running virt-manager
> >> then throws an error, report here and Ill try to help.
> >>
> >
> > After make install, when i run virt-manager, the error is:
> >
> > starting the virt-manager error: 'gtk.TreeView' object has no attribute
> > 'set_level_indentation'
> >
> > Details:
> > raceback (most recent call last):
> > File "/usr/local/share/virt-manager/virt-manager.py", line 377, in ?
> > main()
> > File "/usr/local/share/virt-manager/virt-manager.py", line 364, in main
> > options.no_conn_auto)
> > File "/usr/local/share/virt-manager/virt-manager.py", line 237, in
> > show_engine
> > engine.show_manager()
> > File "/usr/local/share/virt-man! ager/virtManager/engine.py", line
> > 365, in show_manager
> > &nbs! p; self.get_manager().show()
> > File "/usr/local/share/virt-manager/virtManager/engine.py", line 342,
> > in get_manager
> > self.windowManager = vmmManager(self.get_config(), self)
> > File "/usr/local/share/virt-manager/virtManager/manager.py", line 167,
> > in __init__
> > self.prepare_vmlist()
> > File "/usr/local/share/virt-manager/virtManager/manager.py", line 826,
> > in prepare_vmlist
> > vmlist.set_level_indentation(-15)
> > AttributeError: 'gtk.TreeView' object has no attribute
> > 'set_level_indentation'
> >
> > thanks a lot
> >
> > - dustin
> >
>
> I recently tested upstream virt-manager on older RHEL 5.3 and fixed several
> back compat issues, including the one above. I'd recommend giving virt-manager
> 0.8.1 a shot, and report back here if you still hit virt-manager errors.
>
I installed the virt-manager-0.8.1 and virtinst-0.500.1.
And the error was fixed. The virt-manager gui can works. Thank you!
At the same time, i still can't create vm with the virt-manager-0.8.1
the error as below:
Unable to complete install 'libvirt.libvirtError internal error Domain as didn't show up
Traceback (most recent call last):
File "/usr/local/dvirt/share/virt-manager/virtManager/create.py", line 1429, in do_install
dom = guest.start_install(False, meter = meter)
File "/usr/lib/python2.4/site-packages/virtinst/Guest.py", line 660, in start_install
return self._do_install(consolecb, meter, removeOld, wait)
File "/usr/lib/python2.4/site-packages/virtinst/Guest.py", line 758, in _do_install
self.domain = self.conn.createLinux(install_xml, 0)
File "/usr/lib/python2.4/site-packages/libvirt.py", line 974, in createLinux
if ret is None:raise libvirtError('virDomainCreateLinux() failed', conn=self)
libvirtError: internal error Domain as didn't show up
And the reason is as Daniel P. Berrange said, "'ia64' is not listed as a valid architecture
in qemu_conf.c, RHEL-5 KVM only supports x86_64".
In other words, the libvirt didn't support KVM emulator running on ia64 architecture.
Thank you for your work on virt-manager.
-dustin
_________________________________________________________________
Keep your friends updated―even when you’re not signed in.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/...
15 years, 5 months
[libvirt] [PATCH] Add virBufferFreeAndReset() and replace free()
by Matthias Bolte
Replace free(virBufferContentAndReset()) with virBufferFreeAndReset().
Update documentation and replace all remaining calls to free() with
calls to VIR_FREE(). Also add missing calls to virBufferFreeAndReset()
and virReportOOMError() in OOM error cases.
---
HACKING | 5 ++-
daemon/libvirtd.c | 6 ++--
docs/hacking.html.in | 7 ++--
src/conf/capabilities.c | 4 ++-
src/conf/domain_conf.c | 11 +++---
src/conf/interface_conf.c | 5 +--
src/conf/network_conf.c | 4 +--
src/conf/node_device_conf.c | 4 +--
src/conf/secret_conf.c | 4 +--
src/conf/storage_conf.c | 8 ++---
src/esx/esx_driver.c | 3 ++
src/esx/esx_vi.c | 10 ++---
src/esx/esx_vi_methods.c | 68 +++++++++---------------------------
src/esx/esx_vmx.c | 11 +-----
src/libvirt_private.syms | 1 +
src/node_device/node_device_udev.c | 1 +
src/opennebula/one_conf.c | 3 +-
src/openvz/openvz_conf.c | 8 +++--
src/openvz/openvz_driver.c | 3 +-
src/phyp/phyp_driver.c | 5 +--
src/qemu/qemu_conf.c | 39 ++++++++++++++-------
src/qemu/qemu_driver.c | 5 ++-
src/security/virt-aa-helper.c | 9 +++--
src/storage/storage_backend.c | 3 +-
src/uml/uml_conf.c | 4 +--
src/util/buf.c | 13 +++++++
src/util/buf.h | 1 +
src/util/conf.c | 5 ++-
src/util/logging.c | 8 +++-
src/util/qparams.c | 1 +
src/xen/xend_internal.c | 14 +++++---
src/xen/xm_internal.c | 19 +++++-----
tools/virsh.c | 4 +-
33 files changed, 146 insertions(+), 150 deletions(-)
diff --git a/HACKING b/HACKING
index 548e2a0..3fb1113 100644
--- a/HACKING
+++ b/HACKING
@@ -293,10 +293,11 @@ eg typical usage is as follows:
...
virBufferAddLit(&buf, "</domain>\n");
- ....
+ ...
if (virBufferError(&buf)) {
- __virRaiseError(...);
+ virBufferFreeAndReset(&buf);
+ virReportOOMError(...);
return NULL;
}
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 1caa4ce..806970c 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -582,7 +582,7 @@ static int qemudListenUnix(struct qemud_server *server,
cleanup:
if (sock->fd)
close(sock->fd);
- free(sock);
+ VIR_FREE(sock);
return -1;
}
@@ -803,8 +803,8 @@ static int qemudInitPaths(struct qemud_server *server,
_("Resulting path too long for buffer in qemudInitPaths()"));
cleanup:
- free (dir_prefix);
- free (sock_dir_prefix);
+ VIR_FREE(dir_prefix);
+ VIR_FREE(sock_dir_prefix);
return ret;
}
diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index 94b7238..af63411 100644
--- a/docs/hacking.html.in
+++ b/docs/hacking.html.in
@@ -306,14 +306,15 @@
...
virBufferAddLit(&buf, "<domain>\n");
- virBufferVSprint(&buf, " <memory>%d</memory>\n", memory);
+ virBufferVSprint(&buf, " <memory>%d</memory>\n", memory);
...
virBufferAddLit(&buf, "</domain>\n");
- ....
+ ...
if (virBufferError(&buf)) {
- __virRaiseError(...);
+ virBufferFreeAndReset(&buf);
+ virReportOOMError(...);
return NULL;
}
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 6ebddf5..476bba6 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -769,8 +769,10 @@ virCapabilitiesFormatXML(virCapsPtr caps)
virBufferAddLit(&xml, "</capabilities>\n");
- if (virBufferError(&xml))
+ if (virBufferError(&xml)) {
+ virBufferFreeAndReset(&xml);
return NULL;
+ }
return virBufferContentAndReset(&xml);
}
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0a7eef7..355004b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3775,6 +3775,7 @@ virDomainCpuSetFormat(virConnectPtr conn, char *cpuset, int maxcpu)
}
if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
virReportOOMError(conn);
return NULL;
}
@@ -4570,7 +4571,7 @@ char *virDomainDefFormat(virConnectPtr conn,
virBuffer buf = VIR_BUFFER_INITIALIZER;
unsigned char *uuid;
char uuidstr[VIR_UUID_STRING_BUFLEN];
- const char *type = NULL, *tmp;
+ const char *type = NULL;
int n, allones = 1;
if (!(type = virDomainVirtTypeToString(def->virtType))) {
@@ -4826,8 +4827,7 @@ char *virDomainDefFormat(virConnectPtr conn,
no_memory:
virReportOOMError(conn);
cleanup:
- tmp = virBufferContentAndReset(&buf);
- VIR_FREE(tmp);
+ virBufferFreeAndReset(&buf);
return NULL;
}
@@ -4835,7 +4835,7 @@ char *virDomainObjFormat(virConnectPtr conn,
virDomainObjPtr obj,
int flags)
{
- char *config_xml = NULL, *xml = NULL;
+ char *config_xml = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
const char *monitorpath;
@@ -4887,8 +4887,7 @@ char *virDomainObjFormat(virConnectPtr conn,
no_memory:
virReportOOMError(conn);
error:
- xml = virBufferContentAndReset(&buf);
- VIR_FREE(xml);
+ virBufferFreeAndReset(&buf);
return NULL;
}
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index 31abf12..3c99027 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -1208,7 +1208,7 @@ char *virInterfaceDefFormat(virConnectPtr conn,
const virInterfaceDefPtr def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
- const char *type = NULL, *tmp;
+ const char *type = NULL;
if ((def == NULL) ||
((def->name == NULL) && (def->type != VIR_INTERFACE_TYPE_VLAN))) {
@@ -1271,8 +1271,7 @@ char *virInterfaceDefFormat(virConnectPtr conn,
no_memory:
virReportOOMError(conn);
cleanup:
- tmp = virBufferContentAndReset(&buf);
- VIR_FREE(tmp);
+ virBufferFreeAndReset(&buf);
return NULL;
}
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 62b3007..ab76f21 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -642,7 +642,6 @@ char *virNetworkDefFormat(virConnectPtr conn,
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
unsigned char *uuid;
- char *tmp;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virBufferAddLit(&buf, "<network>\n");
@@ -731,8 +730,7 @@ char *virNetworkDefFormat(virConnectPtr conn,
no_memory:
virReportOOMError(conn);
- tmp = virBufferContentAndReset(&buf);
- VIR_FREE(tmp);
+ virBufferFreeAndReset(&buf);
return NULL;
}
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 6003ab1..4bf71da 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -246,7 +246,6 @@ char *virNodeDeviceDefFormat(virConnectPtr conn,
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
virNodeDevCapsDefPtr caps;
- char *tmp;
virBufferAddLit(&buf, "<device>\n");
virBufferEscapeString(&buf, " <name>%s</name>\n", def->name);
@@ -464,8 +463,7 @@ char *virNodeDeviceDefFormat(virConnectPtr conn,
no_memory:
virReportOOMError(conn);
- tmp = virBufferContentAndReset(&buf);
- VIR_FREE(tmp);
+ virBufferFreeAndReset(&buf);
return NULL;
}
diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index 21215b2..538fa91 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -303,7 +303,6 @@ virSecretDefFormat(virConnectPtr conn, const virSecretDefPtr def)
virBuffer buf = VIR_BUFFER_INITIALIZER;
unsigned char *uuid;
char uuidstr[VIR_UUID_STRING_BUFLEN];
- char *tmp;
virBufferVSprintf(&buf, "<secret ephemeral='%s' private='%s'>\n",
def->ephemeral ? "yes" : "no",
@@ -328,7 +327,6 @@ virSecretDefFormat(virConnectPtr conn, const virSecretDefPtr def)
no_memory:
virReportOOMError(conn);
error:
- tmp = virBufferContentAndReset(&buf);
- VIR_FREE(tmp);
+ virBufferFreeAndReset(&buf);
return NULL;
}
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 065cd04..0aefa06 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -954,7 +954,7 @@ virStoragePoolDefFormat(virConnectPtr conn,
no_memory:
virReportOOMError(conn);
cleanup:
- free(virBufferContentAndReset(&buf));
+ virBufferFreeAndReset(&buf);
return NULL;
}
@@ -1292,7 +1292,6 @@ virStorageVolDefFormat(virConnectPtr conn,
virStorageVolDefPtr def) {
virStorageVolOptionsPtr options;
virBuffer buf = VIR_BUFFER_INITIALIZER;
- char *tmp;
options = virStorageVolOptionsForPoolType(pool->type);
if (options == NULL)
@@ -1351,8 +1350,7 @@ virStorageVolDefFormat(virConnectPtr conn,
no_memory:
virReportOOMError(conn);
cleanup:
- tmp = virBufferContentAndReset(&buf);
- VIR_FREE(tmp);
+ virBufferFreeAndReset(&buf);
return NULL;
}
@@ -1742,7 +1740,7 @@ char *virStoragePoolSourceListFormat(virConnectPtr conn,
no_memory:
virReportOOMError(conn);
cleanup:
- free(virBufferContentAndReset(&buf));
+ virBufferFreeAndReset(&buf);
return NULL;
}
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 5737fe9..ea464a3 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -2293,6 +2293,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
return xml;
failure:
+ virBufferFreeAndReset(&buffer);
VIR_FREE(xml);
goto cleanup;
@@ -2723,6 +2724,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
return domain;
failure:
+ virBufferFreeAndReset(&buffer);
+
domain = NULL;
goto cleanup;
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 04860e2..5725b2f 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -532,7 +532,7 @@ esxVI_Context_DownloadFile(virConnectPtr conn, esxVI_Context *ctx,
return 0;
failure:
- free(virBufferContentAndReset(&buffer));
+ virBufferFreeAndReset(&buffer);
return -1;
}
@@ -708,7 +708,7 @@ esxVI_Context_Execute(virConnectPtr conn, esxVI_Context *ctx,
return 0;
failure:
- free(virBufferContentAndReset(&buffer));
+ virBufferFreeAndReset(&buffer);
esxVI_Response_Free(response);
esxVI_Fault_Free(&fault);
@@ -2065,7 +2065,7 @@ esxVI_StartSimpleVirtualMachineTask
return result;
failure:
- free(virBufferContentAndReset(&buffer));
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -2124,9 +2124,7 @@ esxVI_SimpleVirtualMachineMethod(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
diff --git a/src/esx/esx_vi_methods.c b/src/esx/esx_vi_methods.c
index a80d1bf..06b5fd4 100644
--- a/src/esx/esx_vi_methods.c
+++ b/src/esx/esx_vi_methods.c
@@ -158,9 +158,7 @@ esxVI_Login(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -214,9 +212,7 @@ esxVI_Logout(virConnectPtr conn, esxVI_Context *ctx)
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -283,9 +279,7 @@ esxVI_SessionIsActive(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -352,9 +346,7 @@ esxVI_RetrieveProperties(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -451,9 +443,7 @@ esxVI_MigrateVM_Task(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -509,9 +499,7 @@ esxVI_ReconfigVM_Task(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -579,9 +567,7 @@ esxVI_RegisterVM_Task(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -630,9 +616,7 @@ esxVI_UnregisterVM(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -702,9 +686,7 @@ esxVI_CreateFilter(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -758,9 +740,7 @@ esxVI_DestroyPropertyFilter(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -824,9 +804,7 @@ esxVI_WaitForUpdates(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -928,9 +906,7 @@ esxVI_ValidateMigration(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -1003,9 +979,7 @@ esxVI_FindByIp(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -1089,9 +1063,7 @@ esxVI_FindByUuid(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -1165,9 +1137,7 @@ esxVI_QueryAvailablePerfMetric(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -1232,9 +1202,7 @@ esxVI_QueryPerfCounter(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
@@ -1299,9 +1267,7 @@ esxVI_QueryPerf(virConnectPtr conn, esxVI_Context *ctx,
return result;
failure:
- if (request == NULL) {
- request = virBufferContentAndReset(&buffer);
- }
+ virBufferFreeAndReset(&buffer);
result = -1;
diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c
index 9a9fe0a..ff08fdb 100644
--- a/src/esx/esx_vmx.c
+++ b/src/esx/esx_vmx.c
@@ -2150,7 +2150,6 @@ esxVMX_FormatConfig(virConnectPtr conn, esxVI_Context *ctx,
int sched_cpu_affinity_length;
unsigned char zero[VIR_UUID_BUFLEN];
virBuffer buffer = VIR_BUFFER_INITIALIZER;
- char *vmx = NULL;
memset(zero, 0, VIR_UUID_BUFLEN);
@@ -2373,16 +2372,10 @@ esxVMX_FormatConfig(virConnectPtr conn, esxVI_Context *ctx,
goto failure;
}
- vmx = virBufferContentAndReset(&buffer);
-
- return vmx;
+ return virBufferContentAndReset(&buffer);
failure:
- if (vmx == NULL) {
- vmx = virBufferContentAndReset(&buffer);
- }
-
- VIR_FREE(vmx);
+ virBufferFreeAndReset(&buffer);
return NULL;
}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c473d49..f182630 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -11,6 +11,7 @@ virBufferAddChar;
virBufferContentAndReset;
virBufferError;
virBufferURIEncodeString;
+virBufferFreeAndReset;
# caps.h
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 9b48052..10b4416 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -323,6 +323,7 @@ static int udevGenerateDeviceName(struct udev_device *device,
}
if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
VIR_ERROR("Buffer error when generating device name for device "
"with sysname '%s'\n", udev_device_get_sysname(device));
ret = -1;
diff --git a/src/opennebula/one_conf.c b/src/opennebula/one_conf.c
index 415f832..a4768b1 100644
--- a/src/opennebula/one_conf.c
+++ b/src/opennebula/one_conf.c
@@ -278,7 +278,6 @@ char* xmlOneTemplate(virConnectPtr conn,virDomainDefPtr def)
no_memory:
virReportOOMError(conn);
- char* tmp = virBufferContentAndReset(&buf);
- VIR_FREE(tmp);
+ virBufferFreeAndReset(&buf);
return NULL;
};
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 33c2fd3..930f841 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -345,10 +345,12 @@ openvz_replace(const char* str,
str_start = offset + from_len;
}
- virBufferAdd(&buf, str_start, strlen(str_start));
+ virBufferAdd(&buf, str_start, strlen(str_start));
- if(virBufferError(&buf))
- return NULL;
+ if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
+ return NULL;
+ }
return virBufferContentAndReset(&buf);
}
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index aac2eb8..1c0fccc 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -792,8 +792,7 @@ openvzDomainSetNetworkConfig(virConnectPtr conn,
return 0;
exit:
- param = virBufferContentAndReset(&buf);
- VIR_FREE(param);
+ virBufferFreeAndReset(&buf);
return -1;
}
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index ea9555a..c21d99d 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -486,13 +486,12 @@ phypExec(LIBSSH2_SESSION * session, char *cmd, int *exit_status,
err:
(*exit_status) = SSH_CMD_ERR;
- char *cleanup_buf = virBufferContentAndReset(&tex_ret);
-
- VIR_FREE(cleanup_buf);
+ virBufferFreeAndReset(&tex_ret);
return NULL;
exit:
if (virBufferError(&tex_ret)) {
+ virBufferFreeAndReset(&tex_ret);
virReportOOMError(conn);
return NULL;
}
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index f26e94d..09a298b 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1376,6 +1376,7 @@ qemuBuildHostNetStr(virConnectPtr conn,
type_sep = ','; /* dead-store, but leave it, in case... */
}
if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
virReportOOMError(conn);
return -1;
}
@@ -1859,8 +1860,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
virBuffer buf = VIR_BUFFER_INITIALIZER;
qemudBuildCommandLineChrDevStr(monitor_chr, &buf);
- if (virBufferError(&buf))
- goto error;
+ if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
+ goto no_memory;
+ }
ADD_ARG_LIT("-monitor");
ADD_ARG(virBufferContentAndReset(&buf));
@@ -2024,8 +2027,8 @@ int qemudBuildCommandLine(virConnectPtr conn,
}
if (virBufferError(&opt)) {
- virReportOOMError(conn);
- goto error;
+ virBufferFreeAndReset(&opt);
+ goto no_memory;
}
optstr = virBufferContentAndReset(&opt);
@@ -2147,8 +2150,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
virDomainChrDefPtr serial = def->serials[i];
qemudBuildCommandLineChrDevStr(serial, &buf);
- if (virBufferError(&buf))
- goto error;
+ if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
+ goto no_memory;
+ }
ADD_ARG_LIT("-serial");
ADD_ARG(virBufferContentAndReset(&buf));
@@ -2164,8 +2169,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
virDomainChrDefPtr parallel = def->parallels[i];
qemudBuildCommandLineChrDevStr(parallel, &buf);
- if (virBufferError(&buf))
- goto error;
+ if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
+ goto no_memory;
+ }
ADD_ARG_LIT("-parallel");
ADD_ARG(virBufferContentAndReset(&buf));
@@ -2190,8 +2197,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
}
qemudBuildCommandLineChrDevChardevStr(channel, id, &buf);
- if (virBufferError(&buf))
- goto error;
+ if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
+ goto no_memory;
+ }
ADD_ARG_LIT("-chardev");
ADD_ARG(virBufferContentAndReset(&buf));
@@ -2204,8 +2213,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
VIR_FREE(addr);
- if (virBufferError(&buf))
- goto error;
+ if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
+ goto no_memory;
+ }
ADD_ARG_LIT("-net");
ADD_ARG(virBufferContentAndReset(&buf));
@@ -2263,8 +2274,10 @@ int qemudBuildCommandLine(virConnectPtr conn,
virBufferVSprintf(&opt, "%d",
def->graphics[0]->data.vnc.port - 5900);
}
- if (virBufferError(&opt))
+ if (virBufferError(&opt)) {
+ virBufferFreeAndReset(&opt);
goto no_memory;
+ }
optstr = virBufferContentAndReset(&opt);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a4a87ac..d449669 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4308,8 +4308,11 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
tmp++;
}
- if (virBufferError(&buf))
+ if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
+ virReportOOMError(conn);
goto cleanup;
+ }
ret = virBufferContentAndReset(&buf);
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 62f0977..e1e141b 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -883,8 +883,9 @@ get_files(vahControl * ctl)
goto clean;
if (virBufferError(&buf)) {
- vah_error(NULL, 0, "failed to allocate file buffer");
- goto clean;
+ virBufferFreeAndReset(&buf);
+ vah_error(NULL, 0, "failed to allocate file buffer");
+ goto clean;
}
rc = 0;
@@ -1048,8 +1049,10 @@ main(int argc, char **argv)
if (ctl->files)
virBufferVSprintf(&buf, "%s", ctl->files);
- if (virBufferError(&buf))
+ if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
vah_error(ctl, 1, "failed to allocate buffer");
+ }
included_files = virBufferContentAndReset(&buf);
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index bb926cd..dd977f4 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -445,8 +445,7 @@ cleanup:
conn->secretDriver->undefine(secret);
virSecretFree(secret);
}
- xml = virBufferContentAndReset(&buf);
- VIR_FREE(xml);
+ virBufferFreeAndReset(&buf);
virSecretDefFree(def);
VIR_FREE(enc_secret);
return ret;
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c
index 0ace58f..895a94d 100644
--- a/src/uml/uml_conf.c
+++ b/src/uml/uml_conf.c
@@ -163,7 +163,6 @@ umlBuildCommandLineNet(virConnectPtr conn,
virDomainNetDefPtr def,
int idx)
{
- char *ret;
virBuffer buf = VIR_BUFFER_INITIALIZER;
/* General format: ethNN=type,options */
@@ -265,8 +264,7 @@ umlBuildCommandLineNet(virConnectPtr conn,
return virBufferContentAndReset(&buf);
error:
- ret = virBufferContentAndReset(&buf);
- VIR_FREE(ret);
+ virBufferFreeAndReset(&buf);
return NULL;
}
diff --git a/src/util/buf.c b/src/util/buf.c
index 9681635..e683928 100644
--- a/src/util/buf.c
+++ b/src/util/buf.c
@@ -167,6 +167,19 @@ virBufferContentAndReset(const virBufferPtr buf)
}
/**
+ * virBufferFreeAndReset:
+ * @buf: the buffer to free and reset
+ *
+ * Frees the buffer content and resets the buffer structure.
+ */
+void virBufferFreeAndReset(const virBufferPtr buf)
+{
+ char *str = virBufferContentAndReset(buf);
+
+ VIR_FREE(str);
+}
+
+/**
* virBufferError:
* @buf: the buffer
*
diff --git a/src/util/buf.h b/src/util/buf.h
index 94ee8a3..d9a1708 100644
--- a/src/util/buf.h
+++ b/src/util/buf.h
@@ -35,6 +35,7 @@ struct _virBuffer {
#endif
char *virBufferContentAndReset(const virBufferPtr buf);
+void virBufferFreeAndReset(const virBufferPtr buf);
int virBufferError(const virBufferPtr buf);
unsigned int virBufferUse(const virBufferPtr buf);
void virBufferAdd(const virBufferPtr buf, const char *str, int len);
diff --git a/src/util/conf.c b/src/util/conf.c
index 8126f69..0c7e556 100644
--- a/src/util/conf.c
+++ b/src/util/conf.c
@@ -927,15 +927,15 @@ virConfWriteFile(const char *filename, virConfPtr conf)
}
if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
virReportOOMError(NULL);
return -1;
}
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR );
if (fd < 0) {
- char *tmp = virBufferContentAndReset(&buf);
+ virBufferFreeAndReset(&buf);
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to open file"));
- VIR_FREE(tmp);
return -1;
}
@@ -983,6 +983,7 @@ virConfWriteMem(char *memory, int *len, virConfPtr conf)
}
if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
virReportOOMError(NULL);
return -1;
}
diff --git a/src/util/logging.c b/src/util/logging.c
index 757f78c..6bd8469 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -867,8 +867,10 @@ char *virLogGetFilters(void) {
}
virLogUnlock();
- if (virBufferError(&filterbuf))
+ if (virBufferError(&filterbuf)) {
+ virBufferFreeAndReset(&filterbuf);
return NULL;
+ }
return virBufferContentAndReset(&filterbuf);
}
@@ -905,8 +907,10 @@ char *virLogGetOutputs(void) {
}
virLogUnlock();
- if (virBufferError(&outputbuf))
+ if (virBufferError(&outputbuf)) {
+ virBufferFreeAndReset(&outputbuf);
return NULL;
+ }
return virBufferContentAndReset(&outputbuf);
}
diff --git a/src/util/qparams.c b/src/util/qparams.c
index d0a84b3..9b96c2a 100644
--- a/src/util/qparams.c
+++ b/src/util/qparams.c
@@ -154,6 +154,7 @@ qparam_get_query (const struct qparam_set *ps)
}
if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
virReportOOMError(NULL);
return NULL;
}
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index d61e9e6..db21940 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -525,6 +525,7 @@ xend_op_ext(virConnectPtr xend, const char *path, char *error,
}
if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
virReportOOMError(NULL);
return -1;
}
@@ -5279,8 +5280,10 @@ xenDaemonFormatSxprChr(virConnectPtr conn,
break;
}
- if (virBufferError(buf))
+ if (virBufferError(buf)) {
+ virReportOOMError(conn);
return -1;
+ }
return 0;
}
@@ -5605,8 +5608,10 @@ xenDaemonFormatSxprSound(virConnectPtr conn,
virBufferVSprintf(buf, "%s%s", i ? "," : "", str);
}
- if (virBufferError(buf))
+ if (virBufferError(buf)) {
+ virReportOOMError(conn);
return -1;
+ }
return 0;
}
@@ -5878,14 +5883,13 @@ xenDaemonFormatSxpr(virConnectPtr conn,
if (virBufferError(&buf)) {
virReportOOMError(conn);
- return NULL;
+ goto error;
}
return virBufferContentAndReset(&buf);
error:
- tmp = virBufferContentAndReset(&buf);
- VIR_FREE(tmp);
+ virBufferFreeAndReset(&buf);
return NULL;
}
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 2ee321f..7f43784 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -1735,6 +1735,7 @@ int xenXMDomainPinVcpu(virDomainPtr domain,
}
if (virBufferError(&mapbuf)) {
+ virBufferFreeAndReset(&mapbuf);
virReportOOMError(domain->conn);
goto cleanup;
}
@@ -1965,7 +1966,6 @@ static int xenXMDomainConfigFormatDisk(virConnectPtr conn,
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
virConfValuePtr val, tmp;
- char *str;
if(disk->src) {
if (disk->driverName) {
@@ -1996,7 +1996,7 @@ static int xenXMDomainConfigFormatDisk(virConnectPtr conn,
if (virBufferError(&buf)) {
virReportOOMError(conn);
- return -1;
+ goto cleanup;
}
if (VIR_ALLOC(val) < 0) {
@@ -2017,8 +2017,7 @@ static int xenXMDomainConfigFormatDisk(virConnectPtr conn,
return 0;
cleanup:
- str = virBufferContentAndReset(&buf);
- VIR_FREE(str);
+ virBufferFreeAndReset(&buf);
return -1;
}
@@ -2029,7 +2028,6 @@ static int xenXMDomainConfigFormatNet(virConnectPtr conn,
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
virConfValuePtr val, tmp;
- char *str;
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
virBufferVSprintf(&buf, "mac=%02x:%02x:%02x:%02x:%02x:%02x",
@@ -2093,8 +2091,10 @@ static int xenXMDomainConfigFormatNet(virConnectPtr conn,
virBufferVSprintf(&buf, ",vifname=%s",
net->ifname);
- if (virBufferError(&buf))
+ if (virBufferError(&buf)) {
+ virReportOOMError(conn);
goto cleanup;
+ }
if (VIR_ALLOC(val) < 0) {
virReportOOMError(conn);
@@ -2114,8 +2114,7 @@ static int xenXMDomainConfigFormatNet(virConnectPtr conn,
return 0;
cleanup:
- str = virBufferContentAndReset(&buf);
- VIR_FREE(str);
+ virBufferFreeAndReset(&buf);
return -1;
}
@@ -2444,8 +2443,10 @@ virConfPtr xenXMDomainConfigFormat(virConnectPtr conn,
virBufferVSprintf(&buf, ",keymap=%s",
def->graphics[0]->data.vnc.keymap);
}
- if (virBufferError(&buf))
+ if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
goto no_memory;
+ }
vfbstr = virBufferContentAndReset(&buf);
diff --git a/tools/virsh.c b/tools/virsh.c
index 9faac35..94a99e9 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -3800,7 +3800,7 @@ static int buildPoolXML(const vshCmd *cmd, char **retname, char **xml) {
return TRUE;
cleanup:
- free(virBufferContentAndReset(&buf));
+ virBufferFreeAndReset(&buf);
return FALSE;
}
@@ -4663,7 +4663,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
}
cleanup:
- free(virBufferContentAndReset(&buf));
+ virBufferFreeAndReset(&buf);
virStoragePoolFree(pool);
return FALSE;
}
--
1.6.0.4
15 years, 5 months
[libvirt] [RFC] virDomain{Attach,Detach}Device
by Jim Fehlig
History
I found that virDomainDetachDevice did not work with inactive domains
and submitted a patch [1] to fix this. As it turns out, some drivers do
not support attaching/detaching devices on inactive domains and it was
preferred that virDomain{Attach,Detach}Device only be permitted on
active domains.
I posted a follow-up patch [2] that restricted
virDomain{Attach,Detach}Device to active domains only, although as
Daniel Veillard pointed out this restriction should have been enforced
in the libvirt front-end. Cole Robinson suggested improving virsh [3]
to handle the case of inactive vs. active by redefining the domain with
new device (or removed device) when domain is inactive. While
implementing this improvement I asked some questions on IRC that
resulted in another approach suggested by Dan Berrange as outlined below.
Introduce two new APIs
virDomainAttachDeviceFlags(virDomainPtr dom, const char *xml, unsigned
flags)
virDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, unsigned
flags)
with flags being one or more from VIR_DOMAIN_DEVICE_ATTACH_CURRENT,
VIR_DOMAIN_DEVICE_ATTACH_LIVE, VIR_DOMAIN_DEVICE_ATTACH_CONFIG.
(I'm not sure about the ATTACH in these names. Perhaps CHANGE or MODIFY
would be more appropriate.)
If caller specifies CURRENT (default), add or remove the device
depending on the current state of domain. E.g. if domain is active add
or remove the device to/from live domain, if it is inactive change the
persistent config. If caller specifies LIVE, only change the active
domain. If caller specifies CONFIG, only change persistent config -
even if the domain is active. If caller specifies both LIVE and CONFIG,
then change both.
If a driver could not satisfy the exact requested flags it must return
an error. E.g if user specified LIVE but the driver can only change
live and persisted config, the driver must fail the request.
The existing virDomain{Attach,Detach}Device would be declared to be
equivalent to virDomain{Attach,Detach}DeviceFlags(LIVE).
Finally, virsh {attach,detach}-{disk,interface,device} would be modified
to add a --persistent flag in order to set the appropriate flags when
calling the new APIs.
Regards,
Jim
[1] https://www.redhat.com/archives/libvir-list/2009-November/msg00489.html
[2] https://www.redhat.com/archives/libvir-list/2009-November/msg00571.html
[3] https://www.redhat.com/archives/libvir-list/2009-November/msg00676.html
15 years, 5 months
[libvirt] [PATCH] Fix bug in storage driver accessing wrong private data
by Daniel P. Berrange
* src/storage/storage_driver.c: Fix IsPersistent() and IsActivE()
methods on storage pools to use 'storagePrivateData' instead
of 'privateData'. Also fix naming convention of objects
---
src/storage/storage_driver.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index fadba57..4a49089 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -466,17 +466,17 @@ cleanup:
}
-static int storagePoolIsActive(virStoragePoolPtr net)
+static int storagePoolIsActive(virStoragePoolPtr pool)
{
- virStorageDriverStatePtr driver = net->conn->privateData;
+ virStorageDriverStatePtr driver = pool->conn->storagePrivateData;
virStoragePoolObjPtr obj;
int ret = -1;
storageDriverLock(driver);
- obj = virStoragePoolObjFindByUUID(&driver->pools, net->uuid);
+ obj = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid);
storageDriverUnlock(driver);
if (!obj) {
- virStorageReportError(net->conn, VIR_ERR_NO_STORAGE_POOL, NULL);
+ virStorageReportError(pool->conn, VIR_ERR_NO_STORAGE_POOL, NULL);
goto cleanup;
}
ret = virStoragePoolObjIsActive(obj);
@@ -487,17 +487,17 @@ cleanup:
return ret;
}
-static int storagePoolIsPersistent(virStoragePoolPtr net)
+static int storagePoolIsPersistent(virStoragePoolPtr pool)
{
- virStorageDriverStatePtr driver = net->conn->privateData;
+ virStorageDriverStatePtr driver = pool->conn->storagePrivateData;
virStoragePoolObjPtr obj;
int ret = -1;
storageDriverLock(driver);
- obj = virStoragePoolObjFindByUUID(&driver->pools, net->uuid);
+ obj = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid);
storageDriverUnlock(driver);
if (!obj) {
- virStorageReportError(net->conn, VIR_ERR_NO_STORAGE_POOL, NULL);
+ virStorageReportError(pool->conn, VIR_ERR_NO_STORAGE_POOL, NULL);
goto cleanup;
}
ret = obj->configFile ? 1 : 0;
--
1.6.5.2
15 years, 5 months