From patchwork Wed Oct 30 00:29:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 1186438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-106440-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="oBWoGWd0"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 472q8h62bPz9sPc for ; Wed, 30 Oct 2019 11:29:39 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; q=dns; s=default; b=wa+ PIPqXyXkurpIMVbqK8YRnozzecZfHdVSODUe3iL10dnKlfg3V7ntdqvixPBNyIPn AiSIYHC8uT/i36XPnndmmGJBnis2hso6IkfFpt/HVEiTf+Qa67eDYRC2elPdovrR dhDh0HNklccU/6hQblWyfDAHpSoqZq7+0b3hT6SY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=default; bh=q4UrFZbYi VeUkF2TiWhX4PEs5Ds=; b=oBWoGWd0HC4V7xJJmxZ/ADhfyH5a/6MpKY4htpXYe 8O9L9uQYczm5AYgXye5bMz1Xp5U/H+vJbKHSR30XNZAUgNED7kRjoHh2c2vL5Fs7 POguQthAdyus1ATHSHc15XD+NSFQNSSDRMHYKozrGuFvp+THJaZgbOP9ZEXxNYlx yI= Received: (qmail 13850 invoked by alias); 30 Oct 2019 00:29:32 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 13841 invoked by uid 89); 30 Oct 2019 00:29:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.1 spammy=H*r:4.92.3, HContent-Transfer-Encoding:8bit X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Svante Signell , commit-hurd@gnu.org Subject: [hurd,commited] hurd: Support for file record locking Date: Wed, 30 Oct 2019 01:29:24 +0100 Message-Id: <20191030002924.5548-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 From: Svante Signell * sysdeps/mach/hurd/fcntl.c: Add support for file-record-lock RPC fixing posix file locking using the flock64 version of struct flock. --- sysdeps/mach/hurd/fcntl.c | 111 +++++++++++++++++++++++++++++--------- 1 file changed, 87 insertions(+), 24 deletions(-) diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c index 26243682ca..0e3f0adbd9 100644 --- a/sysdeps/mach/hurd/fcntl.c +++ b/sysdeps/mach/hurd/fcntl.c @@ -130,23 +130,75 @@ __libc_fcntl (int fd, int cmd, ...) case F_SETLKW: { struct flock *fl = va_arg (ap, struct flock *); - int wait = 0; - va_end (ap); + switch (cmd) { case F_GETLK: - errno = ENOSYS; - return -1; - case F_SETLKW: - wait = 1; - /* FALLTHROUGH */ + cmd = F_GETLK64; + break; case F_SETLK: - return __f_setlk (fd, fl->l_type, fl->l_whence, - fl->l_start, fl->l_len, wait); + cmd = F_SETLK64; + break; + case F_SETLKW: + cmd = F_SETLKW64; + break; default: errno = EINVAL; return -1; } + + struct flock64 fl64 = { + .l_type = fl->l_type, + .l_whence = fl->l_whence, + .l_start = fl->l_start, + .l_len = fl->l_len, + .l_pid = fl->l_pid + }; + + err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, &fl64, + MACH_PORT_NULL, MACH_MSG_TYPE_MAKE_SEND)); + + /* XXX: To remove once file_record_lock RPC is settled. */ + if (err == EMIG_BAD_ID || err == EOPNOTSUPP) + { + int wait = 0; + va_end (ap); + switch (cmd) + { + case F_GETLK64: + errno = ENOSYS; + return -1; + case F_SETLKW64: + wait = 1; + /* FALLTHROUGH */ + case F_SETLK64: + return __f_setlk (fd, fl->l_type, fl->l_whence, + fl->l_start, fl->l_len, wait); + default: + errno = EINVAL; + return -1; + } + } + else if (cmd == F_GETLK64) + { + fl->l_type = fl64.l_type; + fl->l_whence = fl64.l_whence; + fl->l_start = fl64.l_start; + fl->l_len = fl64.l_len; + fl->l_pid = fl64.l_pid; + + if ((sizeof fl->l_start != sizeof fl64.l_start + && fl->l_start != fl64.l_start) + || (sizeof fl->l_len != sizeof fl64.l_len + && fl->l_len != fl64.l_len)) + { + errno = EOVERFLOW; + return -1; + } + } + + result = err ? __hurd_dfail (fd, err) : 0; + break; } case F_GETLK64: @@ -154,23 +206,34 @@ __libc_fcntl (int fd, int cmd, ...) case F_SETLKW64: { struct flock64 *fl = va_arg (ap, struct flock64 *); - int wait = 0; - va_end (ap); - switch (cmd) + + err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, fl, + MACH_PORT_NULL, MACH_MSG_TYPE_MAKE_SEND)); + + /* XXX: To remove once file_record_lock RPC is settled. */ + if (err == EMIG_BAD_ID || err == EOPNOTSUPP) { - case F_GETLK64: - errno = ENOSYS; - return -1; - case F_SETLKW64: - wait = 1; - /* FALLTHROUGH */ - case F_SETLK64: - return __f_setlk (fd, fl->l_type, fl->l_whence, - fl->l_start, fl->l_len, wait); - default: - errno = EINVAL; - return -1; + int wait = 0; + va_end (ap); + switch (cmd) + { + case F_GETLK64: + errno = ENOSYS; + return -1; + case F_SETLKW64: + wait = 1; + /* FALLTHROUGH */ + case F_SETLK64: + return __f_setlk (fd, fl->l_type, fl->l_whence, + fl->l_start, fl->l_len, wait); + default: + errno = EINVAL; + return -1; + } } + + result = err ? __hurd_dfail (fd, err) : 0; + break; } case F_GETFL: /* Get per-open flags. */