[lxc-devel] Patch: rootfs pinning: make file hidden, don't delete it (but not encode pid)

Christian Brauner christian.brauner at mailbox.org
Fri Mar 23 10:04:30 UTC 2018


On Thu, Mar 22, 2018 at 03:39:57PM +0000, Jäkel, Guido wrote:
> Dear Serge and others
> 
> I suggest the following patch:

Guido,

Could you please sign-off the patch otherwise we won't be able to even
look at it. :)

Thanks!
Christian

> 
> --- lxc/conf.c.20180315-160849  2018-03-15 16:08:49.283081271 +0100
> +++ lxc/conf.c  2018-03-22 16:36:13.282864098 +0100
> @@ -546,10 +546,11 @@
>  
>  /*
>   * pin_rootfs
> - * if rootfs is a directory, then open ${rootfs}/lxc.hold for writing for
> + * if rootfs is a directory, then open ${rootfs}/.lxc-keep for writing for
>   * the duration of the container run, to prevent the container from marking
>   * the underlying fs readonly on shutdown. unlink the file immediately so
>   * no name pollution is happens
> + * don't unlink on NFS to avoid random named stale handles
>   * return -1 on error.
>   * return -2 if nothing needed to be pinned.
>   * return an open fd (>=0) if we pinned it.
> @@ -559,6 +560,7 @@
>         char absrootfs[MAXPATHLEN];
>         char absrootfspin[MAXPATHLEN];
>         struct stat s;
> +       struct statfs sfs;
>         int ret, fd;
>  
>         if (rootfs == NULL || strlen(rootfs) == 0)
> @@ -576,13 +578,23 @@
>         if (!S_ISDIR(s.st_mode))
>                 return -2;
>  
> -       ret = snprintf(absrootfspin, MAXPATHLEN, "%s/lxc.hold", absrootfs);
> +       ret = snprintf(absrootfspin, MAXPATHLEN, "%s/.lxc-keep", absrootfs);
>         if (ret >= MAXPATHLEN)
>                 return -1;
>  
>         fd = open(absrootfspin, O_CREAT | O_RDWR, S_IWUSR|S_IRUSR);
>         if (fd < 0)
>                 return fd;
> +
> +       if (fstatfs (fd, &sfs)) {
> +               return -1;
> +       }
> +
> +       if (sfs.f_type == NFS_SUPER_MAGIC) {
> +               DEBUG("rootfs on NFS, not unlinking pin file \"%s\".", absrootfspin);
> +               return fd;
> +       }
> +
>         (void)unlink(absrootfspin);
>         return fd;
>  }                                   
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list