Update absolute paths for overlay and aufs mounts
Update absolute paths for overlay and aufs mounts

When using overlay and aufs mounts with lxc.mount.entry users have to specify
absolute paths for upperdir and workdir which will then get created
automatically by mount_entry_create_overlay_dirs() and
mount_entry_create_aufs_dirs() in conf.c. When we clone a container with
overlay or aufs lxc.mount.entry entries we need to update these absolute paths.
In order to do this we add the function update_ovl_paths() in
lxccontainer.c. The function updates the mounts in two locations:

        1) lxc_conf->mount_list

and

        2) lxc_conf->unexpanded_config (by calling clone_update_unexp_ovl_dir())

If we were to only update 2) we would end up with wrong upperdir and workdir
mounts as the absolute paths would still point to the container that serves as
the base for the clone. If we were to only update 1) we would end up with wrong
upperdir and workdir lxc.mount.entry entries in the clone's config as the
absolute paths in upperdir and workdir would still point to the container that
serves as the base for the clone. Updating both will get the job done.

NOTE: This function does not sanitize paths apart from removing trailing
slashes. (So when a user specifies //home//someone/// it will be cleaned to
//home//someone. This is the minimal path cleansing which is also done by
lxc_container_new().) But the mount_entry_create_overlay_dirs() and
mount_entry_create_aufs_dirs() functions both try to be extremely strict about
when to create upperdirs and workdirs. They will only accept sanitized paths,
i.e. they require /home/someone. I think this is a (safety) virtue and we
should consider sanitizing paths in general. In short: update_ovl_paths() does
update all absolute paths to the new container but
mount_entry_create_overlay_dirs() and mount_entry_create_aufs_dirs() will still
refuse to create upperdir and workdir when the updated path is unclean. This
happens easily when e.g. a user calls lxc-clone -o OLD -n NEW -P
//home//chb///.

Signed-off-by: Christian Brauner <94aca18939fc64aa4df96ea8cb026da8a2e1541a@gmail.com>
Acked-by: Serge E. Hallyn <3df611b026e4639bee8aef7a4beb2e39fcebb313@ubuntu.com>

hallyn/lxc,QingweiPeterLan/cs188-lxc,ysbnim/lxc,federicobriata/lxc,LynxChaus/lxc,ysbnim/lxc,ss1h2a3tw/lxc,ksperis/lxc,terceiro/lxc,Distrotech/lxc,aeris/lxc,hallyn/lxc,terceiro/lxc,ss1h2a3tw/lxc,QingweiPeterLan/cs188-lxc,hfuCN/lxc,cjwatson/lxc,caglar10ur/lxc,QingweiPeterLan/cs188-lxc,armcc/lxc,fwilson42/lxc,GreatFruitOmsk/lxc,hallyn/lxc,ysbnim/lxc,thmo/lxc,hfuCN/lxc,fwilson42/lxc,federicobriata/lxc,bostjan/lxc,caglar10ur/lxc,bostjan/lxc,thmo/lxc,armcc/lxc,akshaykarle/lxc,akshaykarle/lxc,terceiro/lxc,aeris/lxc,GreatFruitOmsk/lxc,hfuCN/lxc,LynxChaus/lxc,fwilson42/lxc,thmo/lxc,ksperis/lxc,tych0/lxc,Distrotech/lxc,aeris/lxc,Distrotech/lxc,ss1h2a3tw/lxc,ksperis/lxc,akshaykarle/lxc,GreatFruitOmsk/lxc,LynxChaus/lxc,cjwatson/lxc,caglar10ur/lxc,armcc/lxc,federicobriata/lxc,tych0/lxc,bostjan/lxc,cjwatson/lxc,tych0/lxc