[libvirt] [PATCH] maint: Kill usage of atoi()
by Peter Krempa
Also fix a typo in variable name holding the cylinders count of a disk
pool (apparently unused).
---
cfg.mk | 10 ++++++++++
src/conf/storage_conf.h | 2 +-
src/qemu/qemu_command.c | 8 ++++++--
src/storage/storage_backend_disk.c | 16 +++++++++++-----
src/xen/xend_internal.c | 17 +++++++++++++----
5 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index befd231..4df81d2 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -869,6 +869,13 @@ sc_prohibit_getenv:
halt='Use virGetEnv{Allow,Block}SUID instead of getenv' \
$(_sc_search_regexp)
+sc_prohibit_atoi:
+ @prohibit='\batoi *\(' \
+ exclude='exempt from syntax-check' \
+ halt='Use virStrToLong* instead of atoi' \
+ $(_sc_search_regexp)
+
+
# We don't use this feature of maint.mk.
prev_version_file = /dev/null
@@ -1040,3 +1047,6 @@ exclude_file_name_regexp--sc_prohibit_int_ijk = \
exclude_file_name_regexp--sc_prohibit_getenv = \
^tests/.*\.[ch]$$
+
+exclude_file_name_regexp--sc_prohibit_atoi= \
+ ^examples/.*\.[ch]$$
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index f062bd8..05c291e 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -227,7 +227,7 @@ struct _virStoragePoolSourceDevice {
* the geometry data is needed
*/
struct _geometry {
- int cyliders;
+ int cylinders;
int heads;
int sectors;
} geometry;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 966aa0d..25beedf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3663,8 +3663,12 @@ qemuBuildDriveURIString(virConnectPtr conn,
if (disk->src && virAsprintf(&volimg, "/%s", disk->src) < 0)
goto cleanup;
- if (disk->hosts->port) {
- port = atoi(disk->hosts->port);
+ if (disk->hosts->port &&
+ virStrToLong_i(disk->hosts->port, NULL, 0, &port) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("failed to parse network port '%s'"),
+ disk->hosts->port);
+ goto cleanup;
}
if (disk->hosts->socket &&
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 4e53ec5..1f30b06 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -280,12 +280,18 @@ virStorageBackendDiskMakePoolGeometry(virStoragePoolObjPtr pool,
char **const groups,
void *data ATTRIBUTE_UNUSED)
{
+ pool = pool;
+ groups = groups;
+ virStoragePoolSourceDevicePtr device = &(pool->def->source.devices[0]);
+ if (virStrToLong_i(groups[0], NULL, 0, &device->geometry.cylinders) < 0 ||
+ virStrToLong_i(groups[1], NULL, 0, &device->geometry.heads) < 0 ||
+ virStrToLong_i(groups[2], NULL, 0, &device->geometry.sectors) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Failed to create disk pool geometry"));
+ return -1;
+ }
- pool->def->source.devices[0].geometry.cyliders = atoi(groups[0]);
- pool->def->source.devices[0].geometry.heads = atoi(groups[1]);
- pool->def->source.devices[0].geometry.sectors = atoi(groups[2]);
-
- return 0;
+ return 0;
}
static int
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index dc57350..771288c 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -290,10 +290,19 @@ xend_req(int fd, char **content)
if (STREQ(buffer, "\r\n"))
break;
- if (istartswith(buffer, "Content-Length: "))
- content_length = atoi(buffer + 16);
- else if (istartswith(buffer, "HTTP/1.1 "))
- retcode = atoi(buffer + 9);
+ if (istartswith(buffer, "Content-Length: ")) {
+ if (virStrToLong_i(buffer + 16, NULL, 10, &content_length) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to parse Xend response content length"));
+ return -1;
+ }
+ } else if (istartswith(buffer, "HTTP/1.1 ")) {
+ if (virStrToLong_i(buffer + 9, NULL, 10, &retcode) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to parse Xend response return code"));
+ return -1;
+ }
+ }
}
VIR_FREE(buffer);
--
1.8.4.3
11 years
[libvirt] [PATCH] LXC: make sure fuse thread start to run before we do clone
by Gao feng
I met a problem that container blocked by seteuid/setegid
which is call in lxcContainerSetID on UP system and libvirt
compiled with --with-fuse=yes.
I looked into the glibc's codes, and found setxid in glibc
calls futex() to wait for other threads to change their
setxid_futex to 0(see setxid_mark_thread in glibc).
since the process created by clone system call will not
share the memory with the other threads and the context
of memory doesn't changed until we call execl.(COW)
So if the process which created by clone is called before
fuse thread being stated, the new setxid_futex of fuse
thread will not be saw in this process, it will be blocked
forever.
Maybe this problem should be fixed in glibc, but I send
this patch as a quick fix.
Signed-off-by: Gao feng <gaofeng(a)cn.fujitsu.com>
---
src/lxc/lxc_controller.c | 13 ++++++++++++-
src/lxc/lxc_fuse.c | 6 +++++-
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index c8f68c0..ed83bb3 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1977,7 +1977,18 @@ cleanup:
static int
virLXCControllerSetupFuse(virLXCControllerPtr ctrl)
{
- return lxcSetupFuse(&ctrl->fuse, ctrl->def);
+ int ret = lxcSetupFuse(&ctrl->fuse, ctrl->def);
+
+ if (!ret) {
+ /* Wait for fuse thread starting run, so we
+ * can make sure the setxid_futex of fuse thread
+ * is 0(see start_thread of glibc), otherwise
+ * the lxcContainerChild will block at setxid. */
+ virMutexLock(&ctrl->fuse->lock);
+ virMutexUnlock(&ctrl->fuse->lock);
+ }
+
+ return ret;
}
static int
diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c
index 9d12832..8cddfa8 100644
--- a/src/lxc/lxc_fuse.c
+++ b/src/lxc/lxc_fuse.c
@@ -272,6 +272,8 @@ static void lxcFuseDestroy(virLXCFusePtr fuse)
static void lxcFuseRun(void *opaque)
{
virLXCFusePtr fuse = opaque;
+ /* Let libvirt_lxc continue. */
+ virMutexUnlock(&fuse->lock);
if (fuse_loop(fuse->fuse) < 0)
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -321,7 +323,9 @@ int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr def)
fuse_unmount(fuse->mountpoint, fuse->ch);
goto cleanup1;
}
-
+ /* Get mutex lock, lxcFuseRun will unlock it. this will
+ * cause libvirt_lxc wait for the fuse thread starting. */
+ virMutexLock(&fuse->lock);
if (virThreadCreate(&fuse->thread, false, lxcFuseRun,
(void *)fuse) < 0) {
lxcFuseDestroy(fuse);
--
1.8.3.1
11 years
[libvirt] [PATCH v2]virsh: track alias option and improve error message when option duplicates its alias
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
commit 2b172a8effa712aee97a21a64d2d02060958f9b2 allow
alias to expand to opt=value pair.
That means alias may not look alike since then.
With this patch we will also track alias.
If we type command with one option and another marked
as its alias, we will get an error message like:
error: option '--AA' duplicates its alias '--AAA'
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
v2: do not depend on orders of options in array.
Alias could be anywhere except after the default one.
tools/virsh.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/tools/virsh.c b/tools/virsh.c
index bad78c9..ffead84 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1071,6 +1071,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name,
size_t i;
const vshCmdOptDef *ret = NULL;
char *alias = NULL;
+ char *tmp_name = NULL;
if (STREQ(name, helpopt.name)) {
return &helpopt;
@@ -1101,6 +1102,13 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name,
if (VIR_STRDUP(*optstr, value + 1) < 0)
goto cleanup;
}
+ tmp_name = vshMalloc(NULL, strlen(name) + 3);
+ snprintf(tmp_name, strlen(name) + 3, "--%s", name);
+ if (strstr(rl_line_buffer, tmp_name)) {
+ vshError(ctl, _("option '--%s' duplicates its alias '--%s'"),
+ cmd->opts[i].name, name);
+ goto cleanup;
+ }
continue;
}
if ((*opts_seen & (1 << i)) && opt->type != VSH_OT_ARGV) {
@@ -1119,6 +1127,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name,
cmd->name, name);
}
cleanup:
+ VIR_FREE(tmp_name);
VIR_FREE(alias);
return ret;
}
--
1.8.2.1
11 years
[libvirt] [PATCH libvirt-python 00/14] Split the python binding out
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
This patch series is a followup to
https://www.redhat.com/archives/libvir-list/2013-September/msg00413.html
to split the python binding out into a separate GIT repository.
These patches do not apply to current GIT. Instead you have to first
create a new git repo, initializing based on the history of the
python/ subdirectory.
Assuming your current checkout of libvirt is in a directory 'libvirt',
then
$ git clone libvirt libvirt-python
$ cd libvirt-python
$ git filter-branch --subdirectory-filter python --tag-name-filter cat -- --all
$ git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
$ git reflog expire --expire=now --all
$ git gc --prune=now
You should now have a repo that's a couple of MB in size, showing only the
files from python/ dir, in the root.
The tags have been re-written to show content from the python/ directory.
All the GPG signatures from tags are removed, since they are invalid
after rewriting history. This was previously agreed to be the right
way to handle this.
Anyway, with the repo as above, you can now apply the 17 patches from
this series onto that
The build system uses python distutils instead of autoconf/automake.
It still uses the code generator as before though, pulling the XML
files from /usr/share/libvirt/api (or whever you installed libvirt,
as indicated by pkg-config)
I created a simple autobuild.sh to do an end-to-end build, including
the RPM generation. Or you can just do
python setup.py build ('make' equiv)
python setup.py test ('make check' equiv)
python setup.py rpm ('make rpm' equiv)
python setup.py clean ('make clean' equiv)
Historically libvirt python only worked with the exact matching libvirt
binary. Before releasing this, I think we need to make it possible to
compile libvirt-python against any recent-ish libvirt version.
This shouldn't actually be too hard - the generator will take care of
most of it. All we need do is fix up the -override.c files to make
use of version checks to hide APIs not present in older libvirt.
The RPM is designed to be drop in compatible/identical to/with the
existing libvirt-python RPM, so users should notice no difference
in any way when upgrading.
If you don't want to try the filter-branch steps yourself, you can
clone this complete series + repo from
http://fedorapeople.org/cgit/berrange/public_git/libvirt-python-v6.git/
(May take upto 1 hour to appear from the time I sent this message)
Notice how the history is intact right back to the first commit of the
python bindings.
Daniel P. Berrange (14):
Remove obsolete Makefile.am
Update generator for new code layout
Update header file includes
Import STREQ macro from libvirt
Add decl of MIN macro
Import gnulib's xalloc_oversized macro
Import gnulib's ignore_value macro
Import code annotation macros from libvirt
Import VIR_ALLOC / VIR_ALLOC_N / VIR_REALLOC_N functions
Remove use of virStrcpyStatic
Import VIR_FORCE_CLOSE macro from libvirt
Add build/ to python module path for sanitytest.py
Add execute permission for sanitytest.py
Setup distutils buld system
.gitignore | 4 +
AUTHORS.in | 12 ++
COPYING | 339 ++++++++++++++++++++++++++++++++
COPYING.LESSER | 502 ++++++++++++++++++++++++++++++++++++++++++++++++
MANIFEST.in | 27 +++
Makefile.am | 173 -----------------
NEWS | 9 +
autobuild.sh | 25 +++
generator.py | 69 +++----
libvirt-lxc-override.c | 9 +-
libvirt-override.c | 122 ++++++------
libvirt-python.spec.in | 34 ++++
libvirt-qemu-override.c | 8 +-
libvirt-utils.c | 136 +++++++++++++
libvirt-utils.h | 193 +++++++++++++++++++
sanitytest.py | 4 +
setup.py | 262 +++++++++++++++++++++++++
typewrappers.c | 5 +-
18 files changed, 1638 insertions(+), 295 deletions(-)
create mode 100644 .gitignore
create mode 100644 AUTHORS.in
create mode 100644 COPYING
create mode 100644 COPYING.LESSER
create mode 100644 MANIFEST.in
delete mode 100644 Makefile.am
create mode 100644 NEWS
create mode 100755 autobuild.sh
create mode 100644 libvirt-python.spec.in
create mode 100644 libvirt-utils.c
create mode 100644 libvirt-utils.h
mode change 100644 => 100755 sanitytest.py
create mode 100644 setup.py
--
1.8.3.1
11 years
[libvirt] [PATCHv2] Macro for testing the version you are compiling with
by Doug Goldstein
Added a macro similar to the GLib's GLIB_CHECK_VERSION so that one can
simplydo something like:
#if LIBVIRT_CHECK_VERSION(1,1,3)
/* Call function here that appeared in 1.1.3 and newer */
virSomeNewFunction();
#endif
---
include/libvirt/libvirt.h.in | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 80b2d78..65f98c6 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1466,6 +1466,20 @@ VIR_EXPORT_VAR virConnectAuthPtr virConnectAuthPtrDefault;
#define LIBVIR_VERSION_NUMBER @LIBVIRT_VERSION_NUMBER@
+/**
+ * LIBVIRT_CHECK_VERSION:
+ *
+ * Macro for developers to easily check what version of the library
+ * their code is compiling against.
+ * e.g.
+ * #if LIBVIR_CHECK_VERSION(1,1,3)
+ * // some code that only works in 1.1.3 and newer
+ * #endif
+ */
+#define LIBVIRT_CHECK_VERSION(major,minor,micro) \
+ ((((major) * 1000000) + ((minor) * 1000) + (micro)) <= \
+ LIBVIR_VERSION_NUMBER)
+
int virGetVersion (unsigned long *libVer,
const char *type,
unsigned long *typeVer);
--
1.8.1.5
11 years
[libvirt] [PATCH] storage: fix RNG validation of gluster via netfs
by Eric Blake
While trying to compare netfs against my new gluster pool, I
discovered two things:
virt-xml-validate chokes on valid xml produced by 'virsh pool-dumpxml'
[yet another reason that ALL patches that add new xml should be adding
corresponding tests]
When using glusterfs FUSE mounts, you cannot access a subdirectory
of a gluster volume. The recommended workaround in the gluster
community is to mount the volume to an intermediate location, then
bind-mount the desired subdirectory to the final location. Maybe
we should teach libvirt to do bind-mounting, but for now I chose to
just document the limitation.
* docs/storage.html.in: Improve documentation.
* docs/schemas/storagepool.rng (sourcefmtnetfs): Allow all
formats, and drop redundant info-vendor.
* tests/storagepoolxml2xmltest.c (mymain): New test.
* tests/storagepoolxml2xmlin/pool-netfs-gluster.xml: New file.
* tests/storagepoolxml2xmlout/pool-netfs-gluster.xml: Likewise.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
We added glusterfs support to netfs pools in 2009 (commit 2562303);
it's been broken for quite some time :(
docs/schemas/storagepool.rng | 5 ++---
docs/storage.html.in | 11 ++++++++---
tests/storagepoolxml2xmlin/pool-netfs-gluster.xml | 12 ++++++++++++
tests/storagepoolxml2xmlout/pool-netfs-gluster.xml | 20 ++++++++++++++++++++
tests/storagepoolxml2xmltest.c | 1 +
5 files changed, 43 insertions(+), 6 deletions(-)
create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-gluster.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-gluster.xml
diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
index 66d3c22..61fa7a3 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -381,11 +381,10 @@
<choice>
<value>auto</value>
<value>nfs</value>
+ <value>cifs</value>
+ <value>glusterfs</value>
</choice>
</attribute>
- <optional>
- <ref name='sourceinfovendor'/>
- </optional>
</element>
</optional>
</define>
diff --git a/docs/storage.html.in b/docs/storage.html.in
index 1181444..0464565 100644
--- a/docs/storage.html.in
+++ b/docs/storage.html.in
@@ -249,7 +249,8 @@
a local block device as the source, it requires the name of a
host and path of an exported directory. It will mount this network
filesystem and manage files within the directory of its mount
- point. It will default to using NFS as the protocol.
+ point. It will default to using <code>auto</code> as the
+ protocol, which generally tries a mount via NFS first.
</p>
<h3>Example pool input</h3>
@@ -259,6 +260,7 @@
<source>
<host name="nfs.example.com"/>
<dir path="/var/lib/virt/images"/>
+ <format type='nfs'/>
</source>
<target>
<path>/var/lib/virt/images</path>
@@ -275,10 +277,13 @@
<code>nfs</code>
</li>
<li>
- <code>glusterfs</code>
+ <code>glusterfs</code> - use the glusterfs FUSE file system.
+ For now, the <code>dir</code> specified as the source can only
+ be a gluster volume name, as gluster does not provide a way to
+ directly mount subdirectories within a volume.
</li>
<li>
- <code>cifs</code>
+ <code>cifs</code> - use the SMB (samba) or CIFS file system
</li>
</ul>
diff --git a/tests/storagepoolxml2xmlin/pool-netfs-gluster.xml b/tests/storagepoolxml2xmlin/pool-netfs-gluster.xml
new file mode 100644
index 0000000..9b39e87
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-netfs-gluster.xml
@@ -0,0 +1,12 @@
+<pool type='netfs'>
+ <source>
+ <host name='example.com'/>
+ <format type='glusterfs'/>
+ <dir path='/volume'/>
+ </source>
+ <name>netfs-gluster</name>
+ <uuid>d5609ced-94b1-489e-b218-eff35c30336a</uuid>
+ <target>
+ <path>/mnt/gluster</path>
+ </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-netfs-gluster.xml b/tests/storagepoolxml2xmlout/pool-netfs-gluster.xml
new file mode 100644
index 0000000..bab2a15
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-netfs-gluster.xml
@@ -0,0 +1,20 @@
+<pool type='netfs'>
+ <name>netfs-gluster</name>
+ <uuid>d5609ced-94b1-489e-b218-eff35c30336a</uuid>
+ <capacity unit='bytes'>0</capacity>
+ <allocation unit='bytes'>0</allocation>
+ <available unit='bytes'>0</available>
+ <source>
+ <host name='example.com'/>
+ <dir path='/volume'/>
+ <format type='glusterfs'/>
+ </source>
+ <target>
+ <path>/mnt/gluster</path>
+ <permissions>
+ <mode>0755</mode>
+ <owner>-1</owner>
+ <group>-1</group>
+ </permissions>
+ </target>
+</pool>
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index 0ae9b29..743e1cb 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -93,6 +93,7 @@ mymain(void)
DO_TEST("pool-iscsi");
DO_TEST("pool-iscsi-auth");
DO_TEST("pool-netfs");
+ DO_TEST("pool-netfs-gluster");
DO_TEST("pool-scsi");
DO_TEST("pool-scsi-type-scsi-host");
DO_TEST("pool-scsi-type-fc-host");
--
1.8.3.1
11 years
[libvirt] [PATCH] Macro for testing the version you are compiling with
by Doug Goldstein
Added a macro similar to the Linux kernel's KERNEL_VERSION so that you
can simply do something like:
#if LIBVIR_VERSION(1,1,3) <= LIBVIR_VERSION_NUMBER
/* Call function here that appeared in 1.1.3 and newer */
virSomeNewFunction();
#endif
---
include/libvirt/libvirt.h.in | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 80b2d78..41a8c69 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1466,6 +1466,16 @@ VIR_EXPORT_VAR virConnectAuthPtr virConnectAuthPtrDefault;
#define LIBVIR_VERSION_NUMBER @LIBVIRT_VERSION_NUMBER@
+/**
+ * LIBVIR_VERSION:
+ *
+ * Macro for developers to easily check what version of the library
+ * their code is compiling against. Similar in behavior to KERNEL_VERSION
+ * e.g.
+ * #if LIBVIR_VERSION(1,1,3) < LIBVIR_VERSION_NUMBER
+ */
+#define LIBVIR_VERSION(a,b,c) (((a) * 1000000) + ((b) * 1000) + (c))
+
int virGetVersion (unsigned long *libVer,
const char *type,
unsigned long *typeVer);
--
1.8.1.5
11 years
[libvirt] [PATCH 0/4] Fix up rest of the list APIs to correct format
by Peter Krempa
Peter Krempa (4):
virsh-pool: Unify spacing of listing function
virsh-nwfilter: Unify list command column alignment
virsh-interface: Unify list column alignment
virsh-secret: Unify list column alignment
tools/virsh-interface.c | 6 +++---
tools/virsh-nwfilter.c | 8 ++++----
tools/virsh-pool.c | 10 +++++-----
tools/virsh-secret.c | 9 +++++----
4 files changed, 17 insertions(+), 16 deletions(-)
--
1.8.4.3
11 years
[libvirt] [PATCH] snapshot: conf: Fix NULL dereference when <driver> element is empty
by Peter Krempa
Consider the following valid snapshot XML as the <driver> element is
allowed to be empty in the domainsnapshot.rng schema:
$ cat snap.xml
<domainsnapshot>
<disks>
<disk name='vda' snapshot='external'>
<source file='/tmp/foo'/>
<driver/>
</disk>
</disks>
</domainsnapshot>
produces the following error:
$ virsh snapshot-create domain snap.xml
error: internal error: unknown disk snapshot driver '(null)'
The driver type is parsed as NULL from the XML as the attribute is not
present and then directly used to produce the error message.
With this patch the attempt to parse the driver type is skipped if not
present to avoid changing the schema to forbid the empty driver element.
---
src/conf/snapshot_conf.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index d8910c9..418987b 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -175,15 +175,17 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
} else if (!def->format &&
xmlStrEqual(cur->name, BAD_CAST "driver")) {
char *driver = virXMLPropString(cur, "type");
- def->format = virStorageFileFormatTypeFromString(driver);
- if (def->format <= 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown disk snapshot driver '%s'"),
- driver);
+ if (driver) {
+ def->format = virStorageFileFormatTypeFromString(driver);
+ if (def->format <= 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unknown disk snapshot driver '%s'"),
+ driver);
+ VIR_FREE(driver);
+ goto cleanup;
+ }
VIR_FREE(driver);
- goto cleanup;
}
- VIR_FREE(driver);
}
}
--
1.8.4.3
11 years