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@ubuntu.com>
This commit is contained in:
Christian Brauner 2018-08-14 13:00:29 +02:00
parent 375121e4e0
commit ec74f3f859
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D

View File

@ -164,7 +164,10 @@ static int ongoing_create(struct lxc_container *c)
lk.l_type = F_WRLCK; lk.l_type = F_WRLCK;
lk.l_whence = SEEK_SET; 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); ret = fcntl(fd, F_OFD_GETLK, &lk);
if (ret < 0 && errno == EINVAL) if (ret < 0 && errno == EINVAL)
@ -172,8 +175,9 @@ static int ongoing_create(struct lxc_container *c)
close(fd); close(fd);
if (ret == 0 && lk.l_pid != -1) /* F_OFD_GETLK will not send us back a pid so don't check it. */
/* create is still ongoing */ if (ret == 0)
/* Create is still ongoing. */
return 1; return 1;
/* Create completed but partial is still there. */ /* Create completed but partial is still there. */