pin_rootfs: be quiet and don't fail container start

It's a legitimate use case to use read-only $lxcpath.  If we can't
create the pin file, then we're not worried about marking the fs
readonly on exit.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Serge Hallyn 2013-09-10 23:17:46 -05:00
parent 9431aa65a4
commit 00ec333b2e
2 changed files with 6 additions and 17 deletions

View File

@ -687,32 +687,23 @@ int pin_rootfs(const char *rootfs)
if (rootfs == NULL || strlen(rootfs) == 0) if (rootfs == NULL || strlen(rootfs) == 0)
return -2; return -2;
if (!realpath(rootfs, absrootfs)) { if (!realpath(rootfs, absrootfs))
INFO("failed to get real path for '%s', not pinning", rootfs);
return -2; return -2;
}
if (access(absrootfs, F_OK)) { if (access(absrootfs, F_OK))
SYSERROR("'%s' is not accessible", absrootfs);
return -1; return -1;
}
if (stat(absrootfs, &s)) { if (stat(absrootfs, &s))
SYSERROR("failed to stat '%s'", absrootfs);
return -1; return -1;
}
if (!S_ISDIR(s.st_mode)) if (!S_ISDIR(s.st_mode))
return -2; return -2;
ret = snprintf(absrootfspin, MAXPATHLEN, "%s%s", absrootfs, ".hold"); ret = snprintf(absrootfspin, MAXPATHLEN, "%s%s", absrootfs, ".hold");
if (ret >= MAXPATHLEN) { if (ret >= MAXPATHLEN)
SYSERROR("pathname too long for rootfs hold file");
return -1; return -1;
}
fd = open(absrootfspin, O_CREAT | O_RDWR, S_IWUSR|S_IRUSR); fd = open(absrootfspin, O_CREAT | O_RDWR, S_IWUSR|S_IRUSR);
INFO("opened %s as fd %d\n", absrootfspin, fd);
return fd; return fd;
} }

View File

@ -669,10 +669,8 @@ int lxc_spawn(struct lxc_handler *handler)
*/ */
handler->pinfd = pin_rootfs(handler->conf->rootfs.path); handler->pinfd = pin_rootfs(handler->conf->rootfs.path);
if (handler->pinfd == -1) { if (handler->pinfd == -1)
ERROR("failed to pin the container's rootfs"); INFO("failed to pin the container's rootfs");
goto out_delete_net;
}
/* Create a process in a new set of namespaces */ /* Create a process in a new set of namespaces */
handler->pid = lxc_clone(do_start, handler, handler->clone_flags); handler->pid = lxc_clone(do_start, handler, handler->clone_flags);