The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2259

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
On NFS, avoid random names of the root pin file due to "NFS silly renaming" but use a fixed hidden name instead.

IMHO this is a better solution because one is able to relate the anyway vislble file to a purpose.
From 63fc76c3e0d90bc6a3d9ea82a91b3fbc8a3552ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guido=20J=C3=A4kel?= <g.jae...@dnb.de>
Date: Fri, 6 Apr 2018 09:35:21 +0200
Subject: [PATCH] rootfs pinning: On NFS, make file hidden but don't delete it

On NFS, avoid random names of the root pin file due to "NFS silly renaming" but 
use a fixed hidden name instead.
---
 src/lxc/conf.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 745584308..6e0b06a00 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -539,10 +539,11 @@ int run_script(const char *name, const char *section, 
const char *script, ...)
 }
 
 /* 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
+ * 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.
@@ -552,6 +553,7 @@ int pin_rootfs(const char *rootfs)
        int fd, ret;
        char absrootfs[MAXPATHLEN], absrootfspin[MAXPATHLEN];
        struct stat s;
+       struct statfs sfs;
 
        if (rootfs == NULL || strlen(rootfs) == 0)
                return -2;
@@ -570,7 +572,7 @@ int pin_rootfs(const char *rootfs)
        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;
 
@@ -578,6 +580,15 @@ int pin_rootfs(const char *rootfs)
        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@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to