[lxc-devel] [lxc/master] lxccontainer: fix F_OFD_GETLK checks

brauner on Github lxc-bot at linuxcontainers.org
Tue Aug 14 11:05:36 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 733 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180814/119e0121/attachment.bin>
-------------- next part --------------
From ec74f3f859dbe04a62e7dcb169ce6a5baf81841b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 14 Aug 2018 13:00:29 +0200
Subject: [PATCH] lxccontainer: fix F_OFD_GETLK checks

When we check whether an open file description lock has been taken on a file we
need to set the l_pid field to 0 otherwise the kernel will send back EINVAL.
Additionally, the kernel will not do pid translation and simply set the l_pid
value to -1.

Fixes https://discuss.linuxcontainers.org/t/container-deleted-or-stopped-when-lxc-ls-executed-concurrently/2439

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/lxccontainer.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 2e8674723..04c2f672b 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -164,7 +164,10 @@ static int ongoing_create(struct lxc_container *c)
 
 	lk.l_type = F_WRLCK;
 	lk.l_whence = SEEK_SET;
-	lk.l_pid = -1;
+	/* F_OFD_GETLK requires that l_pid be set to 0 otherwise the kernel
+	 * will EINVAL us.
+	 */
+	lk.l_pid = 0;
 
 	ret = fcntl(fd, F_OFD_GETLK, &lk);
 	if (ret < 0 && errno == EINVAL)
@@ -172,8 +175,9 @@ static int ongoing_create(struct lxc_container *c)
 
 	close(fd);
 
-	if (ret == 0 && lk.l_pid != -1)
-		/* create is still ongoing */
+	/* F_OFD_GETLK will not send us back a pid so don't check it. */
+	if (ret == 0)
+		/* Create is still ongoing. */
 		return 1;
 
 	/* Create completed but partial is still there. */


More information about the lxc-devel mailing list