[libvirt] [PATCH go-xml] support virtualport for interface and add test code
by ZhenweiPi
---
domain.go | 29 +++++++++++++++++------------
domain_test.go | 4 ++++
2 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/domain.go b/domain.go
index eb7ff9e..ecb8550 100644
--- a/domain.go
+++ b/domain.go
@@ -185,19 +185,24 @@ type DomainInterfaceDriver struct {
Queues uint `xml:"queues,attr,omitempty"`
}
+type DomainInterfaceVirtualport struct {
+ Type string `xml:"type,attr"`
+}
+
type DomainInterface struct {
- XMLName xml.Name `xml:"interface"`
- Type string `xml:"type,attr"`
- MAC *DomainInterfaceMAC `xml:"mac"`
- Model *DomainInterfaceModel `xml:"model"`
- Source *DomainInterfaceSource `xml:"source"`
- Target *DomainInterfaceTarget `xml:"target"`
- Alias *DomainInterfaceAlias `xml:"alias"`
- Link *DomainInterfaceLink `xml:"link"`
- Boot *DomainDeviceBoot `xml:"boot"`
- Script *DomainInterfaceScript `xml:"script"`
- Driver *DomainInterfaceDriver `xml:"driver"`
- Address *DomainAddress `xml:"address"`
+ XMLName xml.Name `xml:"interface"`
+ Type string `xml:"type,attr"`
+ MAC *DomainInterfaceMAC `xml:"mac"`
+ Model *DomainInterfaceModel `xml:"model"`
+ Source *DomainInterfaceSource `xml:"source"`
+ Target *DomainInterfaceTarget `xml:"target"`
+ Alias *DomainInterfaceAlias `xml:"alias"`
+ Link *DomainInterfaceLink `xml:"link"`
+ Boot *DomainDeviceBoot `xml:"boot"`
+ Script *DomainInterfaceScript `xml:"script"`
+ Driver *DomainInterfaceDriver `xml:"driver"`
+ Virtualport *DomainInterfaceVirtualport `xml:"virtualport"`
+ Address *DomainAddress `xml:"address"`
}
type DomainChardevSource struct {
diff --git a/domain_test.go b/domain_test.go
index 6b37719..9de725c 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -565,6 +565,9 @@ var domainTestData = []struct {
Model: &DomainInterfaceModel{
Type: "virtio",
},
+ Virtualport: &DomainInterfaceVirtualport{
+ Type: "openvswitch",
+ },
},
},
},
@@ -577,6 +580,7 @@ var domainTestData = []struct {
` <interface type="network">`,
` <mac address="00:11:22:33:44:55"></mac>`,
` <model type="virtio"></model>`,
+ ` <virtualport type="openvswitch"></virtualport>`,
` </interface>`,
` </devices>`,
`</domain>`,
--
2.7.4
7 years, 6 months
[libvirt] [PATCH go-xml] add append attr for chardev
by zhenwei.pi
---
domain.go | 5 +++--
domain_test.go | 14 ++++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/domain.go b/domain.go
index 82bf728..00231b2 100644
--- a/domain.go
+++ b/domain.go
@@ -227,8 +227,9 @@ type DomainInterface struct {
}
type DomainChardevSource struct {
- Mode string `xml:"mode,attr"`
- Path string `xml:"path,attr"`
+ Mode string `xml:"mode,attr,omitempty"`
+ Path string `xml:"path,attr"`
+ Append string `xml:"append,attr,omitempty"`
}
type DomainChardevTarget struct {
diff --git a/domain_test.go b/domain_test.go
index 122aada..f50f1fd 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -297,6 +297,16 @@ var domainTestData = []struct {
Port: &serialPort,
},
},
+ DomainSerial{
+ Type: "file",
+ Source: &DomainChardevSource{
+ Path: "/tmp/serial.log",
+ Append: "off",
+ },
+ Target: &DomainSerialTarget{
+ Port: &serialPort,
+ },
+ },
},
Channels: []DomainChannel{
DomainChannel{
@@ -332,6 +342,10 @@ var domainTestData = []struct {
` <serial type="pty">`,
` <target type="isa" port="0"></target>`,
` </serial>`,
+ ` <serial type="file">`,
+ ` <source path="/tmp/serial.log" append="off"></source>`,
+ ` <target port="0"></target>`,
+ ` </serial>`,
` <console type="pty">`,
` <target type="virtio" port="0"></target>`,
` </console>`,
--
2.7.4
7 years, 6 months
[libvirt] [PATCH] qemu: Avoid fd leak on incoming tunneled migration
by Jiri Denemark
While qemuProcessIncomingDefNew takes an fd argument and stores it in
qemuProcessIncomingDef structure, the caller is still responsible for
closing the file descriptor.
Introduced by commit v1.2.21-140-ge7c6f4575.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_migration.c | 1 -
src/qemu/qemu_process.c | 3 +++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 8129dcd40..c23fffef2 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2690,7 +2690,6 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
listenAddress, port,
dataFD[0])))
goto stopjob;
- dataFD[0] = -1; /* the FD is now owned by incoming */
if (qemuProcessPrepareDomain(dconn, driver, vm,
VIR_QEMU_PROCESS_START_AUTODESTROY) < 0)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index fa9990e5d..443ec88fe 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4169,6 +4169,9 @@ qemuProcessIncomingDefFree(qemuProcessIncomingDefPtr inc)
* This function does not copy @path, the caller is responsible for keeping
* the @path pointer valid during the lifetime of the allocated
* qemuProcessIncomingDef structure.
+ *
+ * The caller is responsible for closing @fd, calling
+ * qemuProcessIncomingDefFree will NOT close it.
*/
qemuProcessIncomingDefPtr
qemuProcessIncomingDefNew(virQEMUCapsPtr qemuCaps,
--
2.13.1
7 years, 6 months
[libvirt] [PATCH] README: Remove unnecessary empty line
by Andrea Bolognani
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
Pushed as trivial.
README.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/README.md b/README.md
index 1035bcf..d0ce149 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,6 @@ $ make
$ make install
```
-
The libvirt code relies on a large number of 3rd party libraries. These will
be detected during execution of the configure script and a summary printed
which lists any missing (optional) dependencies.
--
2.7.5
7 years, 6 months
[libvirt] [PATCH v2] util: Extract locale-related fixes into separate functions
by Peter Krempa
From: Martin Kletzander <mkletzan(a)redhat.com>
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/util/virstring.c | 114 +++++++++++++++++++++++++++++++++------------------
1 file changed, 75 insertions(+), 39 deletions(-)
v2:
- fixed Martin's laziness ... oh wait.
diff --git a/src/util/virstring.c b/src/util/virstring.c
index feea5be05..9b54bd6fb 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -521,19 +521,81 @@ virStrToLong_ullp(char const *s, char **end_ptr, int base,
/* In case thread-safe locales are available */
#if HAVE_NEWLOCALE
-static locale_t virLocale;
+typedef locale_t virLocale;
+static virLocale virLocaleRaw;
static int
virLocaleOnceInit(void)
{
- virLocale = newlocale(LC_ALL_MASK, "C", (locale_t)0);
- if (!virLocale)
+ virLocaleRaw = newlocale(LC_ALL_MASK, "C", (locale_t)0);
+ if (!virLocaleRaw)
return -1;
return 0;
}
VIR_ONCE_GLOBAL_INIT(virLocale);
-#endif
+
+/**
+ * virLocaleSetRaw:
+ *
+ * @oldlocale: set to old locale pointer
+ *
+ * Sets the locale to 'C' to allow operating on non-localized objects.
+ * Returns 0 on success -1 on error.
+ */
+static int
+virLocaleSetRaw(virLocale *oldlocale)
+{
+ if (virLocaleInitialize() < 0)
+ return -1;
+ *oldlocale = uselocale(virLocaleRaw);
+ return 0;
+}
+
+static void
+virLocaleRevert(virLocale *oldlocale)
+{
+ uselocale(*oldlocale);
+}
+
+static void
+virLocaleFixupRadix(char **strp ATTRIBUTE_UNUSED)
+{
+}
+
+#else /* !HAVE_NEWLOCALE */
+
+typedef int virLocale;
+
+static int
+virLocaleSetRaw(virLocale *oldlocale ATTRIBUTE_UNUSED)
+{
+ return 0;
+}
+
+static void
+virLocaleRevert(virLocale *oldlocale ATTRIBUTE_UNUSED)
+{
+}
+
+static void
+virLocaleFixupRadix(char **strp)
+{
+ char *radix, *tmp;
+ struct lconv *lc;
+
+ lc = localeconv();
+ radix = lc->decimal_point;
+ tmp = strstr(*strp, radix);
+ if (tmp) {
+ *tmp = '.';
+ if (strlen(radix) > 1)
+ memmove(tmp + 1, tmp + strlen(radix), strlen(*strp) - (tmp - *strp));
+ }
+}
+
+#endif /* !HAVE_NEWLOCALE */
+
/**
* virStrToDouble
@@ -547,22 +609,17 @@ virStrToDouble(char const *s,
char **end_ptr,
double *result)
{
+ virLocale oldlocale;
double val;
char *p;
int err;
errno = 0;
-#if HAVE_NEWLOCALE
- locale_t old_loc;
- if (virLocaleInitialize() < 0)
+ if (virLocaleSetRaw(&oldlocale) < 0)
return -1;
-
- old_loc = uselocale(virLocale);
-#endif
val = strtod(s, &p); /* exempt from syntax-check */
-#if HAVE_NEWLOCALE
- uselocale(old_loc);
-#endif
+ virLocaleRevert(&oldlocale);
+
err = (errno || (!end_ptr && *p) || p == s);
if (end_ptr)
*end_ptr = p;
@@ -582,38 +639,17 @@ virStrToDouble(char const *s,
int
virDoubleToStr(char **strp, double number)
{
+ virLocale oldlocale;
int ret = -1;
-#if HAVE_NEWLOCALE
-
- locale_t old_loc;
-
- if (virLocaleInitialize() < 0)
- goto error;
+ if (virLocaleSetRaw(&oldlocale) < 0)
+ return -1;
- old_loc = uselocale(virLocale);
ret = virAsprintf(strp, "%lf", number);
- uselocale(old_loc);
-
-#else
- char *radix, *tmp;
- struct lconv *lc;
+ virLocaleRevert(&oldlocale);
+ virLocaleFixupRadix(strp);
- if ((ret = virAsprintf(strp, "%lf", number) < 0))
- goto error;
-
- lc = localeconv();
- radix = lc->decimal_point;
- tmp = strstr(*strp, radix);
- if (tmp) {
- *tmp = '.';
- if (strlen(radix) > 1)
- memmove(tmp + 1, tmp + strlen(radix), strlen(*strp) - (tmp - *strp));
- }
-
-#endif /* HAVE_NEWLOCALE */
- error:
return ret;
}
--
2.12.2
7 years, 6 months
[libvirt] [PATCH] HACKING: Refresh after changes to source file
by Andrea Bolognani
Commit 79c1900fc1eb changed docs/hacking.html.in, but *of
course* I forgot once again to update the text-only version
of the file at the same time.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
Pushed as trivial.
HACKING | 54 ++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 38 insertions(+), 16 deletions(-)
diff --git a/HACKING b/HACKING
index b78a9ae..1d9f3f1 100644
--- a/HACKING
+++ b/HACKING
@@ -43,27 +43,49 @@ post your patches:
git pull --rebase
(fix any conflicts)
git send-email --cover-letter --no-chain-reply-to --annotate \
- --to=libvir-list(a)redhat.com master
+ --confirm=always --to=libvir-list(a)redhat.com master
-(Note that the "git send-email" subcommand may not be in the main git package
+For a single patch you can omit "--cover-letter", but a series of two or more
+patches needs a cover letter.
+
+Note that the "git send-email" subcommand may not be in the main git package
and using it may require installation of a separate package, for example the
-"git-email" package in Fedora.) For a single patch you can omit
-"--cover-letter", but a series of two or more patches needs a cover letter. If
-you get tired of typing "--to=libvir-list(a)redhat.com" designation you can set
-it in git config:
+"git-email" package in Fedora and Debian. If this is your first time using
+"git send-email", you might need to configure it to point it to your SMTP
+server with something like:
+
+ git config --global sendemail.smtpServer stmp.youremailprovider.net
+
+If you get tired of typing "--to=libvir-list(a)redhat.com" all the time, you can
+configure that to be automatically handled as well:
git config sendemail.to libvir-list(a)redhat.com
-Please follow this as close as you can, especially the rebase and git
-send-email part, as it makes life easier for other developers to review your
-patch set. One should avoid sending patches as attachments, but rather send
-them in email body along with commit message. If a developer is sending
-another version of the patch (e.g. to address review comments), they are
-advised to note differences to previous versions after the "---" line in the
-patch so that it helps reviewers but doesn't become part of git history.
-Moreover, such patch needs to be prefixed correctly with
-"--subject-prefix=PATCHv2" appended to "git send-email" (substitute "v2" with
-the correct version if needed though).
+As a rule, patches should be sent to the mailing list only: all developers are
+subscribed to libvir-list and read it regularly, so please don't CC individual
+developers unless they've explicitly asked you to.
+
+Avoid using mail clients for sending patches, as most of them will mangle the
+messages in some way, making them unusable for our purposes. Gmail and other
+Web-based mail clients are particularly bad at this.
+
+If everything went well, your patch should show up on the libvir-list archives
+<https://www.redhat.com/archives/libvir-list/> in a matter of minutes; if you
+still can't find it on there after an hour or so, you should double-check your
+setup. Note that your very first post to the mailing list will be subject to
+moderation, and it's not uncommon for that to take around a day.
+
+Please follow this as close as you can, especially the rebase and "git
+send-email" part, as it makes life easier for other developers to review your
+patch set.
+
+One should avoid sending patches as attachments, but rather send them in email
+body along with commit message. If a developer is sending another version of
+the patch (e.g. to address review comments), they are advised to note
+differences to previous versions after the "---" line in the patch so that it
+helps reviewers but doesn't become part of git history. Moreover, such patch
+needs to be prefixed correctly with "--subject-prefix=PATCHv2" appended to
+"git send-email" (substitute "v2" with the correct version if needed though).
(5) In your commit message, make the summary line reasonably short (60 characters
is typical), followed by a blank line, followed by any longer description of
--
2.7.5
7 years, 6 months
[libvirt] [PATCH] qemuMonitorTextAddDrive: Fail on unrecognized disk format
by Michal Privoznik
Since qemu commit 3ef6c40ad0b it can fail if trying to hotplug a
disk that is not qcow2 despite us saying it is. We need to error
out in that case.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_monitor_text.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 66c94fbcd..737e8389b 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -1963,6 +1963,12 @@ int qemuMonitorTextAddDrive(qemuMonitorPtr mon,
goto cleanup;
}
+ if (strstr(reply, "Image is not in")) {
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("Incorrect disk format"));
+ goto cleanup;
+ }
+
ret = 0;
cleanup:
--
2.13.0
7 years, 6 months
[libvirt] [PATCH] docs: Add callback-related info to virStream{Abort, Finish}
by Martin Kletzander
When one has a non-blocking stream and aborts or finishes it without
removing the callback, any event loop invocation will trigger that
callback, but it cannot be removed any more. We cannot remove the
callback automatically from virStream{Abort,Finish} functions due to
forward-compatibility. So let's at least document this behaviour,
because it is not easy to find out the reason for.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
Notes:
The discussion about the reasons:
https://www.redhat.com/archives/libvir-list/2017-June/msg00038.html
src/libvirt-stream.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c
index d7a8f581608f..c49f20264fd7 100644
--- a/src/libvirt-stream.c
+++ b/src/libvirt-stream.c
@@ -1131,6 +1131,9 @@ virStreamEventRemoveCallback(virStreamPtr stream)
* errors, so if this returns a success code the application can
* be sure that all data has been successfully processed.
*
+ * If the stream is non-blocking, any callback must be removed
+ * beforehand.
+ *
* Returns 0 on success, -1 upon error
*/
int
@@ -1170,6 +1173,9 @@ virStreamFinish(virStreamPtr stream)
* streams this can be used to inform the driver that it
* should stop sending data.
*
+ * If the stream is non-blocking, any callback must be removed
+ * beforehand.
+ *
* Returns 0 on success, -1 upon error
*/
int
--
2.13.1
7 years, 6 months
[libvirt] [PATCH v2] hacking: Improve 'git send-email' documentation
by Andrea Bolognani
For the benefit of first time contributors, we point out that 'git
send-email' might have to be installed separately; however, we omit
the fact that some configuration will likely be needed before it
can successfully deliver patches to the mailing list.
Some minor tweaks to the existing contents are included as well.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
docs/hacking.html.in | 46 ++++++++++++++++++++++++++++++++++------------
1 file changed, 34 insertions(+), 12 deletions(-)
diff --git a/docs/hacking.html.in b/docs/hacking.html.in
index d6a574c..975ee69 100644
--- a/docs/hacking.html.in
+++ b/docs/hacking.html.in
@@ -29,8 +29,8 @@
file from zanata.</p>
</li>
- <li><p>Post patches using "git send-email", with git rename
- detection enabled. You need a one-time setup of:</p>
+ <li><p>Post patches using <code>git send-email</code>, with git
+ rename detection enabled. You need a one-time setup of:</p>
<pre>
git config diff.renames true
</pre>
@@ -50,22 +50,44 @@
git pull --rebase
(fix any conflicts)
git send-email --cover-letter --no-chain-reply-to --annotate \
- --to=libvir-list(a)redhat.com master
+ --confirm=always --to=libvir-list(a)redhat.com master
</pre>
- <p>(Note that the "git send-email" subcommand may not be in
- the main git package and using it may require installation of a
- separate package, for example the "git-email" package in
- Fedora.) For a single patch you can omit
+ <p>For a single patch you can omit
<code>--cover-letter</code>, but a series of two or more
- patches needs a cover letter. If you get tired of typing
- <code>--to=libvir-list(a)redhat.com</code> designation you can
- set it in git config:</p>
+ patches needs a cover letter.</p>
+ <p>Note that the <code>git send-email</code> subcommand may not
+ be in the main git package and using it may require installation
+ of a separate package, for example the "git-email" package in
+ Fedora and Debian. If this is your first time using
+ <code>git send-email</code>, you might need to configure it to
+ point it to your SMTP server with something like:</p>
+<pre>
+ git config --global sendemail.smtpServer stmp.youremailprovider.net
+</pre>
+ <p>If you get tired of typing
+ <code>--to=libvir-list(a)redhat.com</code> all the time, you can
+ configure that to be automatically handled as well:</p>
<pre>
git config sendemail.to libvir-list(a)redhat.com
</pre>
+ <p>As a rule, patches should be sent to the mailing list only: all
+ developers are subscribed to libvir-list and read it regularly, so
+ please don't CC individual developers unless they've explicitly
+ asked you to.</p>
+ <p>Avoid using mail clients for sending patches, as most of them
+ will mangle the messages in some way, making them unusable for our
+ purposes. Gmail and other Web-based mail clients are particularly
+ bad at this.</p>
+ <p>If everything went well, your patch should show up on the
+ <a href="https://www.redhat.com/archives/libvir-list/">libvir-list
+ archives</a> in a matter of minutes; if you still can't find it on
+ there after an hour or so, you should double-check your setup. Note
+ that your very first post to the mailing list will be subject to
+ moderation, and it's not uncommon for that to take around a day.</p>
<p>Please follow this as close as you can, especially the rebase and
- git send-email part, as it makes life easier for other developers to
- review your patch set. One should avoid sending patches as attachments,
+ <code>git send-email</code> part, as it makes life easier for other
+ developers to review your patch set.</p>
+ <p>One should avoid sending patches as attachments,
but rather send them in email body along with commit message. If a
developer is sending another version of the patch (e.g. to address
review comments), they are advised to note differences to previous
--
2.7.5
7 years, 6 months
[libvirt] [PATCH] events: Avoid double free possibility on remote call failure
by John Ferlan
If a remote call fails during event registration (more than likely from
a network failure or remote libvirtd restart timed just right), then when
calling the virObjectEventStateDeregisterID we don't want to call the
registered @freecb function because that breaks our contract that we
would only call it after succesfully returning. If the @freecb routine
were called, it could result in a double free from properly coded
applications that free their opaque data on failure to register, as seen
in the following details:
Program terminated with signal 6, Aborted.
#0 0x00007fc45cba15d7 in raise
#1 0x00007fc45cba2cc8 in abort
#2 0x00007fc45cbe12f7 in __libc_message
#3 0x00007fc45cbe86d3 in _int_free
#4 0x00007fc45d8d292c in PyDict_Fini
#5 0x00007fc45d94f46a in Py_Finalize
#6 0x00007fc45d960735 in Py_Main
#7 0x00007fc45cb8daf5 in __libc_start_main
#8 0x0000000000400721 in _start
The double dereference of 'pyobj_cbData' is triggered in the following way:
(1) libvirt_virConnectDomainEventRegisterAny is invoked.
(2) the event is successfully added to the event callback list
(virDomainEventStateRegisterClient in
remoteConnectDomainEventRegisterAny returns 1 which means ok).
(3) when function remoteConnectDomainEventRegisterAny is hit,
network connection disconnected coincidently (or libvirtd is
restarted) in the context of function 'call' then the connection
is lost and the function 'call' failed, the branch
virObjectEventStateDeregisterID is therefore taken.
(4) 'pyobj_conn' is dereferenced the 1st time in
libvirt_virConnectDomainEventFreeFunc.
(5) 'pyobj_cbData' (refered to pyobj_conn) is dereferenced the
2nd time in libvirt_virConnectDomainEventRegisterAny.
(6) the double free error is triggered.
Resolve this by adding an @inhibitFreeCb boolean in order to avoid calling
freecb in virObjectEventStateDeregisterID for any remote call failure in
a remoteConnect*EventRegister* API. For remoteConnect*EventDeregister* calls,
the passed value would be false indicating they should run the freecb if it
exists.
Patch based on the investigation and initial patch posted by:
fangying <fangying1(a)huawei.com>.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
Initial patch found at:
https://www.redhat.com/archives/libvir-list/2017-June/msg00039.html
based on feedback from Daniel Berrange to a previous posting:
https://www.redhat.com/archives/libvir-list/2017-May/msg01089.html
Since no new patch was posted, I posted my idea from review for
consideration.
src/bhyve/bhyve_driver.c | 2 +-
src/conf/domain_event.c | 2 +-
src/conf/object_event.c | 23 +++++++++++++++++------
src/conf/object_event.h | 3 ++-
src/libxl/libxl_driver.c | 2 +-
src/lxc/lxc_driver.c | 2 +-
src/network/bridge_driver.c | 2 +-
src/node_device/node_device_driver.c | 2 +-
src/qemu/qemu_driver.c | 4 ++--
src/remote/remote_driver.c | 32 ++++++++++++++++----------------
src/secret/secret_driver.c | 2 +-
src/storage/storage_driver.c | 2 +-
src/test/test_driver.c | 8 ++++----
src/uml/uml_driver.c | 2 +-
src/vz/vz_driver.c | 2 +-
src/xen/xen_driver.c | 2 +-
16 files changed, 52 insertions(+), 40 deletions(-)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index ed2221a..6722dc4 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1503,7 +1503,7 @@ bhyveConnectDomainEventDeregisterAny(virConnectPtr conn,
if (virObjectEventStateDeregisterID(conn,
privconn->domainEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
return -1;
return 0;
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 6e471d7..ff4c602 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -2301,7 +2301,7 @@ virDomainEventStateDeregister(virConnectPtr conn,
NULL);
if (callbackID < 0)
return -1;
- return virObjectEventStateDeregisterID(conn, state, callbackID);
+ return virObjectEventStateDeregisterID(conn, state, callbackID, false);
}
diff --git a/src/conf/object_event.c b/src/conf/object_event.c
index e5f942f..5e944af 100644
--- a/src/conf/object_event.c
+++ b/src/conf/object_event.c
@@ -234,13 +234,15 @@ virObjectEventCallbackListCount(virConnectPtr conn,
* @conn: pointer to the connection
* @cbList: the list
* @callback: the callback to remove
+ * @inhibitFreeCb: Inhibit calling the freecb
*
* Internal function to remove a callback from a virObjectEventCallbackListPtr
*/
static int
virObjectEventCallbackListRemoveID(virConnectPtr conn,
virObjectEventCallbackListPtr cbList,
- int callbackID)
+ int callbackID,
+ bool inhibitFreeCb)
{
size_t i;
@@ -256,7 +258,10 @@ virObjectEventCallbackListRemoveID(virConnectPtr conn,
cb->key_filter ? cb->key : NULL,
cb->remoteID >= 0) - 1);
- if (cb->freecb)
+ /* inhibiting calling @freecb from error paths in register
+ * functions ensures the caller of the register function won't
+ * end up with a double free error */
+ if (!inhibitFreeCb && cb->freecb)
(*cb->freecb)(cb->opaque);
virObjectEventCallbackFree(cb);
VIR_DELETE_ELEMENT(cbList->callbacks, i, cbList->count);
@@ -927,16 +932,22 @@ virObjectEventStateRegisterID(virConnectPtr conn,
* @conn: connection to associate with callback
* @state: object event state
* @callbackID: ID of the function to remove from event
+ * @inhibitFreeCb: Inhibit the calling of a freecb
*
* Unregister the function @callbackID with connection @conn,
- * from @state, for events.
+ * from @state, for events. If @inhibitFreeCb is true, then we
+ * are being called from a remote call failure path for the
+ * Event registration indicating a -1 return to the caller. The
+ * caller wouldn't expect us to run their freecb function if it
+ * exists, so we cannot do so.
*
* Returns: the number of callbacks still registered, or -1 on error
*/
int
virObjectEventStateDeregisterID(virConnectPtr conn,
virObjectEventStatePtr state,
- int callbackID)
+ int callbackID,
+ bool inhibitFreeCb)
{
int ret;
@@ -946,8 +957,8 @@ virObjectEventStateDeregisterID(virConnectPtr conn,
state->callbacks,
callbackID);
else
- ret = virObjectEventCallbackListRemoveID(conn,
- state->callbacks, callbackID);
+ ret = virObjectEventCallbackListRemoveID(conn, state->callbacks,
+ callbackID, inhibitFreeCb);
virObjectEventStateCleanupTimer(state, true);
diff --git a/src/conf/object_event.h b/src/conf/object_event.h
index 7a9995e..b36fcc9 100644
--- a/src/conf/object_event.h
+++ b/src/conf/object_event.h
@@ -73,7 +73,8 @@ virObjectEventStateQueueRemote(virObjectEventStatePtr state,
int
virObjectEventStateDeregisterID(virConnectPtr conn,
virObjectEventStatePtr state,
- int callbackID)
+ int callbackID,
+ bool inhibitFreeCb)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 0d65342..2995324 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5652,7 +5652,7 @@ libxlConnectDomainEventDeregisterAny(virConnectPtr conn, int callbackID)
if (virObjectEventStateDeregisterID(conn,
driver->domainEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
return -1;
return 0;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 22c8b58..ec357c6 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1479,7 +1479,7 @@ lxcConnectDomainEventDeregisterAny(virConnectPtr conn,
if (virObjectEventStateDeregisterID(conn,
driver->domainEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
return -1;
return 0;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 3ba7018..e9ad77e 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -3001,7 +3001,7 @@ networkConnectNetworkEventDeregisterAny(virConnectPtr conn,
if (virObjectEventStateDeregisterID(conn,
driver->networkEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
goto cleanup;
ret = 0;
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index 760d73a..37e4e19 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -690,7 +690,7 @@ nodeConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
if (virObjectEventStateDeregisterID(conn,
driver->nodeDeviceEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
goto cleanup;
ret = 0;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e91663c..8c10599 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11826,7 +11826,7 @@ qemuConnectDomainEventDeregisterAny(virConnectPtr conn,
if (virObjectEventStateDeregisterID(conn,
driver->domainEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
goto cleanup;
ret = 0;
@@ -18472,7 +18472,7 @@ qemuConnectDomainQemuMonitorEventDeregister(virConnectPtr conn,
goto cleanup;
if (virObjectEventStateDeregisterID(conn, driver->domainEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
goto cleanup;
ret = 0;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index b452e8b..6ebf910 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3066,7 +3066,7 @@ remoteConnectNetworkEventRegisterAny(virConnectPtr conn,
(xdrproc_t) xdr_remote_connect_network_event_register_any_args, (char *) &args,
(xdrproc_t) xdr_remote_connect_network_event_register_any_ret, (char *) &ret) == -1) {
virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID);
+ callbackID, true);
goto done;
}
virObjectEventStateSetRemote(conn, priv->eventState, callbackID,
@@ -3099,7 +3099,7 @@ remoteConnectNetworkEventDeregisterAny(virConnectPtr conn,
goto done;
if ((count = virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID)) < 0)
+ callbackID, false)) < 0)
goto done;
/* If that was the last callback for this eventID, we need to disable
@@ -3160,7 +3160,7 @@ remoteConnectStoragePoolEventRegisterAny(virConnectPtr conn,
(xdrproc_t) xdr_remote_connect_storage_pool_event_register_any_args, (char *) &args,
(xdrproc_t) xdr_remote_connect_storage_pool_event_register_any_ret, (char *) &ret) == -1) {
virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID);
+ callbackID, true);
goto done;
}
@@ -3193,7 +3193,7 @@ remoteConnectStoragePoolEventDeregisterAny(virConnectPtr conn,
goto done;
if ((count = virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID)) < 0)
+ callbackID, false)) < 0)
goto done;
/* If that was the last callback for this eventID, we need to disable
@@ -3256,7 +3256,7 @@ remoteConnectNodeDeviceEventRegisterAny(virConnectPtr conn,
(xdrproc_t) xdr_remote_connect_node_device_event_register_any_args, (char *) &args,
(xdrproc_t) xdr_remote_connect_node_device_event_register_any_ret, (char *) &ret) == -1) {
virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID);
+ callbackID, true);
goto done;
}
@@ -3290,7 +3290,7 @@ remoteConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
goto done;
if ((count = virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID)) < 0)
+ callbackID, false)) < 0)
goto done;
/* If that was the last callback for this eventID, we need to disable
@@ -3353,7 +3353,7 @@ remoteConnectSecretEventRegisterAny(virConnectPtr conn,
(xdrproc_t) xdr_remote_connect_secret_event_register_any_args, (char *) &args,
(xdrproc_t) xdr_remote_connect_secret_event_register_any_ret, (char *) &ret) == -1) {
virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID);
+ callbackID, true);
goto done;
}
@@ -3387,7 +3387,7 @@ remoteConnectSecretEventDeregisterAny(virConnectPtr conn,
goto done;
if ((count = virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID)) < 0)
+ callbackID, false)) < 0)
goto done;
/* If that was the last callback for this eventID, we need to disable
@@ -3453,7 +3453,7 @@ remoteConnectDomainQemuMonitorEventRegister(virConnectPtr conn,
(xdrproc_t) xdr_qemu_connect_domain_monitor_event_register_args, (char *) &args,
(xdrproc_t) xdr_qemu_connect_domain_monitor_event_register_ret, (char *) &ret) == -1) {
virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID);
+ callbackID, true);
goto done;
}
virObjectEventStateSetRemote(conn, priv->eventState, callbackID,
@@ -3485,7 +3485,7 @@ remoteConnectDomainQemuMonitorEventDeregister(virConnectPtr conn,
goto done;
if ((count = virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID)) < 0)
+ callbackID, false)) < 0)
goto done;
/* If that was the last callback for this event, we need to disable
@@ -4409,7 +4409,7 @@ remoteConnectDomainEventRegister(virConnectPtr conn,
(xdrproc_t) xdr_remote_connect_domain_event_callback_register_any_args, (char *) &args,
(xdrproc_t) xdr_remote_connect_domain_event_callback_register_any_ret, (char *) &ret) == -1) {
virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID);
+ callbackID, true);
goto done;
}
virObjectEventStateSetRemote(conn, priv->eventState, callbackID,
@@ -4419,7 +4419,7 @@ remoteConnectDomainEventRegister(virConnectPtr conn,
(xdrproc_t) xdr_void, (char *) NULL,
(xdrproc_t) xdr_void, (char *) NULL) == -1) {
virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID);
+ callbackID, true);
goto done;
}
}
@@ -4452,7 +4452,7 @@ remoteConnectDomainEventDeregister(virConnectPtr conn,
goto done;
if ((count = virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID)) < 0)
+ callbackID, false)) < 0)
goto done;
if (count == 0) {
@@ -5951,7 +5951,7 @@ remoteConnectDomainEventRegisterAny(virConnectPtr conn,
(xdrproc_t) xdr_remote_connect_domain_event_callback_register_any_args, (char *) &args,
(xdrproc_t) xdr_remote_connect_domain_event_callback_register_any_ret, (char *) &ret) == -1) {
virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID);
+ callbackID, true);
goto done;
}
virObjectEventStateSetRemote(conn, priv->eventState, callbackID,
@@ -5965,7 +5965,7 @@ remoteConnectDomainEventRegisterAny(virConnectPtr conn,
(xdrproc_t) xdr_remote_connect_domain_event_register_any_args, (char *) &args,
(xdrproc_t) xdr_void, (char *)NULL) == -1) {
virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID);
+ callbackID, true);
goto done;
}
}
@@ -5996,7 +5996,7 @@ remoteConnectDomainEventDeregisterAny(virConnectPtr conn,
goto done;
if ((count = virObjectEventStateDeregisterID(conn, priv->eventState,
- callbackID)) < 0)
+ callbackID, false)) < 0)
goto done;
/* If that was the last callback for this eventID, we need to disable
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index fc01e6d..7d7ded8 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -532,7 +532,7 @@ secretConnectSecretEventDeregisterAny(virConnectPtr conn,
if (virObjectEventStateDeregisterID(conn,
driver->secretEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
goto cleanup;
ret = 0;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index ab1dc8f..698654c 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2662,7 +2662,7 @@ storageConnectStoragePoolEventDeregisterAny(virConnectPtr conn,
if (virObjectEventStateDeregisterID(conn,
driver->storageEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
goto cleanup;
ret = 0;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 11e7fd8..fec4d83 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5697,7 +5697,7 @@ testConnectDomainEventDeregisterAny(virConnectPtr conn,
int ret = 0;
if (virObjectEventStateDeregisterID(conn, driver->eventState,
- callbackID) < 0)
+ callbackID, false) < 0)
ret = -1;
return ret;
@@ -5731,7 +5731,7 @@ testConnectNetworkEventDeregisterAny(virConnectPtr conn,
int ret = 0;
if (virObjectEventStateDeregisterID(conn, driver->eventState,
- callbackID) < 0)
+ callbackID, false) < 0)
ret = -1;
return ret;
@@ -5764,7 +5764,7 @@ testConnectStoragePoolEventDeregisterAny(virConnectPtr conn,
int ret = 0;
if (virObjectEventStateDeregisterID(conn, driver->eventState,
- callbackID) < 0)
+ callbackID, false) < 0)
ret = -1;
return ret;
@@ -5797,7 +5797,7 @@ testConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
int ret = 0;
if (virObjectEventStateDeregisterID(conn, driver->eventState,
- callbackID) < 0)
+ callbackID, false) < 0)
ret = -1;
return ret;
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 080fea4..c3dc9d2 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -2721,7 +2721,7 @@ umlConnectDomainEventDeregisterAny(virConnectPtr conn,
umlDriverLock(driver);
if (virObjectEventStateDeregisterID(conn,
driver->domainEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
ret = -1;
umlDriverUnlock(driver);
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 7aa0c4c..1fa2e2f 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -1053,7 +1053,7 @@ vzConnectDomainEventDeregisterAny(virConnectPtr conn,
if (virObjectEventStateDeregisterID(conn,
privconn->driver->domainEventState,
- callbackID) < 0)
+ callbackID, false) < 0)
return -1;
return 0;
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 8e7bc35..f6d7fdc 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2284,7 +2284,7 @@ xenUnifiedConnectDomainEventDeregisterAny(virConnectPtr conn,
if (virObjectEventStateDeregisterID(conn,
priv->domainEvents,
- callbackID) < 0)
+ callbackID, false) < 0)
ret = -1;
xenUnifiedUnlock(priv);
--
2.9.4
7 years, 6 months