[libvirt] [PATCH] Inherit namespace feature

Imran Khan ik.nitk at gmail.com
Sat Aug 8 18:43:56 UTC 2015


Thanks Daniel and Michal,

I have made the changes suggested by both of you. Mainly avoid creating new
connection to lxc. Sending another version of diffs named "[PATCH] Inherit
namespace feature 2"

one point to mention is that reason for adding libxml in driver_la_la is
because of error i got
/usr/bin/ld:
../src/.libs/libvirt_driver_lxc_impl.a(libvirt_driver_lxc_impl_la-lxc_domain.o):
undefined reference to symbol 'xmlXPathRegisterNs@@LIBXML2_2.4.30'

and  reason to add libvirt-lxc is because of the below error. Other wise
lot of code would be duplicated to call virProcessGetNamespace. i.e inorder
to get the pid of domain before getting namespace. instead just use
virDomainLxcOpenNamespace.

 8) Test driver "lxc"                                                 ...
2015-08-08 17:14:45.434+0000: 19513: info : libvirt version: 1.2.17
2015-08-08 17:14:45.434+0000: 19513: error : virDriverLoadModule:73 :
failed to load module
/home/imran/programming/libvirt/src/.libs/libvirt_driver_lxc.so
/home/imran/programming/libvirt/src/.libs/libvirt_driver_lxc.so: undefined
symbol: virDomainLxcOpenNamespace
FAILED


Thanks a lot for your valuable time and experienced comments,
-imran

On Mon, Aug 3, 2015 at 10:08 PM, Daniel P. Berrange <berrange at redhat.com>
wrote:

> On Mon, Aug 03, 2015 at 10:00:29PM +0530, Imran Khan wrote:
> > Thanks Daniel and Michal again for your valuable inputs.  Please check my
> > reply with text <imran> for some of your comments.  And request you to
> help
> > on those.
> >
> > BTW:  should i reply with rework in the new patch. or i should reply to
> > this thread itself?  Sorry i am new to the community so yet to get
> familiar
> > with etiquette.
>
> Different communities often have different rules on this. For libvirt
> reply to the comments in the thread, but when posting a new version of
> a patch post the patch as a new top level thread.
>
> ie do *not* use '--in-reply-to' with git send-email
>
>
>
>
> > > > +        ns_fd[VIR_DOMAIN_NAMESPACE_SHARENET] = open(path, O_RDONLY);
> > > > +        VIR_FREE(path);
> > > > +        if (ns_fd[VIR_DOMAIN_NAMESPACE_SHARENET] < 0) {
> > > > +            virReportSystemError(errno,
> > > > +                      _("failed to open netns %s"),
> > > lxcDef->ns_val[VIR_DOMAIN_NAMESPACE_SHARENET]);
> > > > +            return -1;
> > > > +        }
> > > > +    }
> > > > +    for (i = 0; i < VIR_DOMAIN_NAMESPACE_LAST; i++) {
> > > > +        /* If not yet intialized by above: netns*/
> > > > +        if (lxcDef->ns_type[i] && ns_fd[i] == -1) {
> > > > +            pid = strtol(lxcDef->ns_val[i], &eptr, 10);
> > > > +            if (*eptr != '\0' || pid < 1) {
> > > > +                /* check if the domain is running, then set the
> > > namespaces
> > > > +                 * to that container
> > > > +                 */
> > > > +                const char *ns[] = { "user", "ipc", "uts", "net",
> > > "pid", "mnt" };
> > > > +                conn = virConnectOpen("lxc:///");
> > > > +                if (!conn) {
> > > > +                    virReportError(virGetLastError()->code,
> > > > +                      _("unable to get connect to lxc %s"),
> > > lxcDef->ns_val[i]);
> > > > +                    rc = -1;
> > > > +                    goto cleanup;
> > > > +                }
> > > > +                dom = virDomainLookupByName(conn,
> lxcDef->ns_val[i]);
> > > > +                if (!dom) {
> > > > +                    virReportError(virGetLastError()->code,
> > > > +                                   _("Unable to lookup peer
> containeri
> > > %s"),
> > > > +                                   lxcDef->ns_val[i]);
> > > > +                    rc = -1;
> > > > +                    goto cleanup;
> > > > +                }
> > > > +                if ((nfdlist = virDomainLxcOpenNamespace(dom,
> &fdlist,
> > > 0)) < 0) {
> > > > +                    virReportError(virGetLastError()->code,
> > > > +                                   _("Unable to open %s"),
> > > lxcDef->ns_val[i]);
> > > > +                    rc = -1;
> > > > +                    goto cleanup;
> > > > +                }
> > >
> > > I really hate the idea of the libvirt_lxc program opening a connection
> > > back to libvirtd using virConnectOpen, as that creates a circular
> > > dependancy. It also risks deadlock, because libvirtd will be holding
> > > locks while starting up the container, and you're calling back into
> > > the driver which may then end up acquiring the same lock.
> > >
> > > <imran>:  This is where i am finding problem to code.  All the driver
> > functions are static and to access them i might have to change the static
> > to non-static.which will not be inline with current design. i don't see
> > circular dependency with this approach as the internal connection is just
> > used to get the fd's. please share any approach to handle this or hope i
> > can keep the current code.
>
>
> The code you are interested in for virDomainLxcOpenNamespace is in
> lxc_driver.c, which is static. This though, simply calls the global
> virProcessGetNamespaces() method which is non-static. So when you
> put the code in lxc_process.c you can directly call virProcssGetNamespaces
>
> > > I think a better approach in general is for libvirtd  lxc_process.c
> > > code to be responsible for getting access to all the namespace
> > > file descriptors. We can then pass those pre-opened file descrpitors
> > > down into libvirt_lxc using command line args, in the sme way that
> > > we pass down file descriptors for pre-opened TAP devices.
> > >
> > > eg so we end up running
> > >
> > >  libvirt_lxc --netns 23 --pidns 24 --utsns 25
> > >
> > > or something like that.
> > >
> >
> > <imran>: And useability wise its easier to provide names instead of fds.
> as
> > if the shared container goes down. the fds wont be valid.
> >  with name a simple restart and again get the new fds with names
> > automatically.
>
> The libvirt_lxc program is not something that eend users ever run. It
> is launched by libvirtd itself, so we don't need to care about usability
> in this particular place. The users still use XML which allows names
> as you have in your patch already.
>
>
> Regards,
> Daniel
> --
> |: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/
> :|
> |: http://libvirt.org              -o-             http://virt-manager.org
> :|
> |: http://autobuild.org       -o-         http://search.cpan.org/~danberr/
> :|
> |: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc
> :|
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150809/510949ce/attachment-0001.htm>


More information about the libvir-list mailing list