[lxc-devel] [PATCH 1/1] userns: clear and save id_map
Serge Hallyn
serge.hallyn at ubuntu.com
Mon Jul 15 21:22:38 UTC 2013
Quoting Dwight Engen (dwight.engen at oracle.com):
> On Mon, 15 Jul 2013 13:47:40 -0500
> Serge Hallyn <serge.hallyn at ubuntu.com> wrote:
>
> >
> > Otherwise (a) there is a memory leak when using user namespaces and
> > clearing a config, and (b) saving a container configuration file
> > doesn't maintain the userns mapping. For instance, if container c1
> > has lxc.id_map configuration entries, then
> >
> > python3
> > import lxc
> > c=lxc.Container("c1")
> > c.save_config("/tmp/config1")
> >
> > should show 'lxc.id_map =' entries in /tmp/config1.
> >
> > Reported-by: Dwight Engen <dwight.engen at oracle.com>
> > Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
> > ---
> > src/lxc/conf.c | 13 +++++++++++++
> > src/lxc/confile.c | 6 ++++++
> > 2 files changed, 19 insertions(+)
> >
> > diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> > index dc521b5..21614d9 100644
> > --- a/src/lxc/conf.c
> > +++ b/src/lxc/conf.c
> > @@ -3123,6 +3123,18 @@ int lxc_clear_config_caps(struct lxc_conf *c)
> > return 0;
> > }
> >
> > +int lxc_clear_idmaps(struct lxc_conf *c)
> > +{
> > + struct lxc_list *it, *next;
> > +
> > + lxc_list_for_each_safe(it, &c->id_map, next) {
> > + lxc_list_del(it);
> > + free(it->elem);
> > + free(it);
> > + }
> > + return 0;
> > +}
> > +
> > int lxc_clear_cgroups(struct lxc_conf *c, const char *key)
> > {
> > struct lxc_list *it,*next;
> > @@ -3226,5 +3238,6 @@ void lxc_conf_free(struct lxc_conf *conf)
> > lxc_clear_hooks(conf, "lxc.hook");
> > lxc_clear_mount_entries(conf);
> > lxc_clear_saved_nics(conf);
> > + lxc_clear_idmaps(conf);
> > free(conf);
> > }
> > diff --git a/src/lxc/confile.c b/src/lxc/confile.c
> > index a7db117..05370f0 100644
> > --- a/src/lxc/confile.c
> > +++ b/src/lxc/confile.c
> > @@ -1945,6 +1945,12 @@ void write_config(FILE *fout, struct lxc_conf
> > *c) }
> > lxc_list_for_each(it, &c->caps)
> > fprintf(fout, "lxc.cap.drop = %s\n", (char
> > *)it->elem);
> > + lxc_list_for_each(it, &c->id_map) {
> > + struct id_map *idmap = it->elem;
> > + fprintf(fout, "lxc.id_map = %c %lu %lu %lu\n",
> > + idmap->type == ID_TYPE_UID ? 'u' : 'c',
> > idmap->nsid,
> > + idmap->hostid, idmap->range);
>
> Hi Serge, I'm getting:
>
> confile.c:1951:9: error: ‘struct id_map’ has no member named ‘type’
>
> I think you wanted idmap->idtype :) With that change, it builds but I'm
Gah, I failed to scp before mailing.
> getting a segfault when doing a lxc-clone -s -o ol64-01 -n ol64-02 (and
> ol64-01 has lxc.id_map entries). Here is the gdb backtrace, I'll look
> into it if you don't have time.
That's because I needed 'g' instead of 'c' above.
With both of those fixed (which is what I'm running here) things seem
all right.
Sorry about all the goofs.
thanks,
-serge
More information about the lxc-devel
mailing list