Re: [libvirt] [Openstack] [RFC PATCH] lxc: don't return error on GetInfo when cgroups not yet set up

2011-10-02 Thread Serge E. Hallyn
Haven't tested this, but I think the following patch should fix the
race, by forcing lxc_driver to hang on lxcMonitorClient() until
after the lxc_controller has set up the cgroups, ensuring that that
happens before the driver is unlocked.

(I'll test tomorrow)

Index: libvirt-0.9.2/src/lxc/lxc_controller.c
===
--- libvirt-0.9.2.orig/src/lxc/lxc_controller.c 2011-10-02 20:30:23.988539174 
-0500
+++ libvirt-0.9.2/src/lxc/lxc_controller.c  2011-10-02 20:30:34.392538998 
-0500
@@ -611,7 +611,6 @@
  unsigned int nveths,
  char **veths,
  int monitor,
- int client,
  int appPty)
 {
 int rc = -1;
@@ -622,6 +621,7 @@
 virDomainFSDefPtr root;
 char *devpts = NULL;
 char *devptmx = NULL;
+int client;
 
 if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) {
 virReportSystemError(errno, "%s",
@@ -634,6 +634,13 @@
 if (lxcSetContainerResources(def) < 0)
 goto cleanup;
 
+/* Accept initial client which is the libvirtd daemon */
+if ((client = accept(monitor, NULL, 0)) < 0) {
+virReportSystemError(errno, "%s",
+ _("Failed to accept a connection from driver"));
+goto cleanup;
+}
+
 /*
  * If doing a chroot style setup, we need to prepare
  * a private /dev/pts for the child now, which they
@@ -922,14 +929,7 @@
 /* Initialize logging */
 virLogSetFromEnv();
 
-/* Accept initial client which is the libvirtd daemon */
-if ((client = accept(monitor, NULL, 0)) < 0) {
-virReportSystemError(errno, "%s",
- _("Failed to accept a connection from driver"));
-goto cleanup;
-}
-
-rc = lxcControllerRun(def, nveths, veths, monitor, client, appPty);
+rc = lxcControllerRun(def, nveths, veths, monitor, appPty);
 
 
 cleanup:

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


[libvirt] [libvirt-glib] [PATCH] Explicitly link conn-test example against libgobject

2011-10-02 Thread Guido Günther
Otherwise the build fails with:

/usr/bin/ld: conn_test-conn-test.o: undefined reference to symbol 
'g_type_check_instance_cast'
/usr/bin/ld: note: 'g_type_check_instance_cast' is defined in DSO 
/usr/lib/libgobject-2.0.so.0 so try adding it to the linker command line
/usr/lib/libgobject-2.0.so.0: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
---
 examples/Makefile.am |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/examples/Makefile.am b/examples/Makefile.am
index 10ce32d..0964597 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -25,5 +25,5 @@ conn_test_SOURCES = \
 conn_test_LDADD = \
../libvirt-gobject/libvirt-gobject-1.0.la \
$(LIBVIRT_LIBS) \
-   $(GLIB2_LIBS)
-
+   $(GLIB2_LIBS) \
+   $(GOBJECT2_LIBS)
-- 
1.7.6.3

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


Re: [libvirt] [PATCH 1/2] snapshot: implement getparent for esx

2011-10-02 Thread Matthias Bolte
2011/9/29 Eric Blake :
> Pretty easy to paste together compared to existing functions.
>
> * src/esx/esx_driver.c (esxDomainSnapshotGetParent): New function.
> ---
>
> I can only compile-test this; I'm relying on someone with an actual
> esx setup to actually test it.  Also, I didn't see anything in
> existing code that would efficiently implement
> virDomainSnapshotNumChildren; there may an API that I'm not aware of,
> but someone else will have to implement that API (Matthias?)

This will have to be done by esxVI_GetNumberOfSnapshotTrees that just
counts the snapshots in the driver. This is one of things where
vSphere API doesn't translate efficiently to libvirt API.

>  src/esx/esx_driver.c |   41 +
>  1 files changed, 41 insertions(+), 0 deletions(-)
>

Looks good, tested, works, ACK :)

-- 
Matthias Bolte
http://photron.blogspot.com

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

Re: [libvirt] [PATCH 2/2] snapshot: implement getparent for vbox

2011-10-02 Thread Matthias Bolte
2011/9/29 Eric Blake :
> Again, built by copying from existing functions.
>
> * src/vbox/vbox_tmpl.c (vboxDomainSnapshotGetParent): New function.
> ---
>
> I can only compile-test this; I'm relying on someone with an actual
> vbox setup to actually test it.

This patch needs some fixes, see below.

> Also, I didn't see anything in
> existing code that would efficiently implement
> virDomainSnapshotNumChildren; there may an API that I'm not aware of,
> but someone else will have to implement that API (Matthias?)

Is virDomainSnapshotNumChildren supposed to only return the number of
direct children, or all children (direct children, grandchildren, etc)
of a snapshot? In the later case they'll have to be counted
recursively, unfortunately.

>  src/vbox/vbox_tmpl.c |   71 
> ++
>  1 files changed, 71 insertions(+), 0 deletions(-)
>
> diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
> index b483d0f..3d5f4ae 100644
> --- a/src/vbox/vbox_tmpl.c
> +++ b/src/vbox/vbox_tmpl.c
> @@ -6046,6 +6046,76 @@ cleanup:
>  }
>
>  static virDomainSnapshotPtr
> +vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
> +                            unsigned int flags)
> +{
> +    virDomainPtr dom = snapshot->domain;
> +    VBOX_OBJECT_CHECK(dom->conn, virDomainSnapshotPtr, NULL);
> +    vboxIID iid = VBOX_IID_INITIALIZER;
> +    IMachine *machine = NULL;
> +    ISnapshot *snap = NULL;
> +    ISnapshot *parent = NULL;
> +    PRUnichar *nameUtf16 = NULL;
> +    char *name = NULL;
> +    nsresult rc;
> +
> +    virCheckFlags(0, NULL);
> +
> +    vboxIIDFromUUID(&iid, dom->uuid);
> +    rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
> +    if (NS_FAILED(rc)) {
> +        vboxError(VIR_ERR_NO_DOMAIN, "%s",
> +                  _("no domain with matching UUID"));
> +        goto cleanup;
> +    }
> +
> +    if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name)))
> +        goto cleanup;

At this point you already have the snapshot you want.

> +    rc = machine->vtbl->GetCurrentSnapshot(machine, &snap);
> +    if (NS_FAILED(rc)) {
> +        vboxError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                  _("could not get current snapshot"));
> +        goto cleanup;
> +    }

This block here gives you the current snapshot, that's not what you want.

> +    rc = snap->vtbl->GetParent(snap, &parent);
> +    if (NS_FAILED(rc)) {
> +        vboxError(VIR_ERR_INTERNAL_ERROR,
> +                  _("could not get parent of snapshot %s"),
> +                  snapshot->name);
> +        goto cleanup;
> +    }
> +    if (!parent) {
> +        vboxError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
> +                  _("snapshot '%s' does not have a parent"),
> +                  snapshot->name);
> +        goto cleanup;
> +    }
> +
> +    rc = parent->vtbl->GetName(parent, &nameUtf16);
> +    if (NS_FAILED(rc) || !nameUtf16) {
> +        vboxError(VIR_ERR_INTERNAL_ERROR,
> +                  _("could not get name of parent of snapshot %s"),
> +                  snapshot->name);
> +        goto cleanup;
> +    }
> +    VBOX_UTF16_TO_UTF8(nameUtf16, &name);
> +    VBOX_UTF16_FREE(nameUtf16);

Because VBOX_UTF16_FREE doesn't set the pointer to NULL, calling it
twice on the same pointer isn't safe.

> +
> +    ret = virGetDomainSnapshot(dom, name);
> +
> +cleanup:
> +    VBOX_UTF8_FREE(name);
> +    VBOX_UTF16_FREE(nameUtf16);

And this second call segfaults in the success path.

> +    VBOX_RELEASE(snap);
> +    VBOX_RELEASE(parent);
> +    VBOX_RELEASE(machine);
> +    vboxIIDUnalloc(&iid);
> +    return ret;
> +}

ACK with this diff applied:

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 3d5f4ae..2eb23fb 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -6072,13 +6072,6 @@
vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
 if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name)))
 goto cleanup;

-rc = machine->vtbl->GetCurrentSnapshot(machine, &snap);
-if (NS_FAILED(rc)) {
-vboxError(VIR_ERR_INTERNAL_ERROR, "%s",
-  _("could not get current snapshot"));
-goto cleanup;
-}
-
 rc = snap->vtbl->GetParent(snap, &parent);
 if (NS_FAILED(rc)) {
 vboxError(VIR_ERR_INTERNAL_ERROR,
@@ -6101,7 +6094,10 @@
vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
 goto cleanup;
 }
 VBOX_UTF16_TO_UTF8(nameUtf16, &name);
-VBOX_UTF16_FREE(nameUtf16);
+if (!name) {
+virReportOOMError();
+goto cleanup;
+}

 ret = virGetDomainSnapshot(dom, name);


-- 
Matthias Bolte
http://photron.blogspot.com

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