Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9595306rwd; Wed, 21 Jun 2023 09:16:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4hGRn6SEBV9VplkAEx+LX/LRfX0mmYo4yvn7vEXInnpiN5k6uClQy5jn4yzYRyiaLp1uJS X-Received: by 2002:a05:6808:628f:b0:39d:adbe:fa29 with SMTP id du15-20020a056808628f00b0039dadbefa29mr7232765oib.4.1687364173259; Wed, 21 Jun 2023 09:16:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687364173; cv=none; d=google.com; s=arc-20160816; b=BXoL33DXrRpFfKU5ygfH4pC6veHQPCFr+m/3rUwBcr08K/ddYlq84NQ1kbVPi0I11T NfLbtsHAZIeHRPtEQGi9aOSTXdgHmCjSc/JqvOLfy7TxJ3J6Ip9SwKxdqsMqrNwFscp6 1AsR3Z/m6S6bNkyw7Vgm2cNvbtbG/NnMc5rzHr8Uscs34ds2xCG8RlXKOb/8mbSaxUBo +cQBlorG7O9K4TV+lBrsMIIEG5tycHbI1B1DoKhS/J0LAZrQ2j8YN08/n4OxN32d3nr4 nUAA4fFdOvzdUwegIrt4UUPx+3sihaYTET4IviZc7Hga5q4PCqqCPLAAUad7EeWjI0Cq 2yxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lDc4QgnEZC8KLbodk8+haNOeCOpk4ZEgKr8+epbYZ8s=; b=BeFllrKJs9ZbfJrErNdB8AXTfSxQUYBe3aDsecmcQosJvEskcnFe/1QQevM06B+ye2 bpaq0F0tyUyefbps3YKVRL2vtSCUIhkzfZkg2kNv/8+TpsErcOwPtFphIo5a86TMHt62 u7bjh8+nbfHbDh1HeC0Bjph4ID3QEiZWM9TDCNXOrbgvfXfaOKVe+57Jlsj0GtKJJVFK h3VA0KOxp5GlFWTu3/m7u2F8PdhEXR8tDAQBtnKgo5opIwJDwll+mNHoYWsjGbg+Q4da nF5hvBHH0ZJ20WyZ0t711wXbUrlP2Nk4l+GyY2Bdp4XwMtbGxxmMYbpM9acgYtpLr6z7 E5zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b="eIQxgQ/K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k126-20020a633d84000000b005401008809bsi4325346pga.752.2023.06.21.09.15.59; Wed, 21 Jun 2023 09:16:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b="eIQxgQ/K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233487AbjFUPbo (ORCPT + 99 others); Wed, 21 Jun 2023 11:31:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233462AbjFUPba (ORCPT ); Wed, 21 Jun 2023 11:31:30 -0400 Received: from forward206a.mail.yandex.net (forward206a.mail.yandex.net [178.154.239.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBADDCC; Wed, 21 Jun 2023 08:30:57 -0700 (PDT) Received: from forward103a.mail.yandex.net (forward103a.mail.yandex.net [IPv6:2a02:6b8:c0e:500:1:45:d181:d103]) by forward206a.mail.yandex.net (Yandex) with ESMTP id E496247332; Wed, 21 Jun 2023 18:22:46 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-31.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-31.vla.yp-c.yandex.net [IPv6:2a02:6b8:c18:58f:0:640:3768:0]) by forward103a.mail.yandex.net (Yandex) with ESMTP id 7231846C65; Wed, 21 Jun 2023 18:22:42 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-31.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id UMkSjYADYGk0-AkLoIPpV; Wed, 21 Jun 2023 18:22:41 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1687360962; bh=lDc4QgnEZC8KLbodk8+haNOeCOpk4ZEgKr8+epbYZ8s=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=eIQxgQ/KENbUZ2x3qrqriO4S0ZYhAkXI/90UF2KUSj/TTbA+veewMIsiEPhYnRdqt 0V0P/wgTHNei1+XAV7yCi7yD4HZ3Ll1e4DBnlsO+NONxMTp0e/uNDn6HZVSqkGE1/J BP3N5YBMk6d5ek3PfEddmifedtt1aTG0h2dxqna4= Authentication-Results: mail-nwsmtp-smtp-production-main-31.vla.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Stas Sergeev To: linux-kernel@vger.kernel.org Cc: Stas Sergeev , Jeff Layton , Chuck Lever , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, Shuah Khan , linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH 1/2] fs/locks: F_UNLCK extension for F_OFD_GETLK Date: Wed, 21 Jun 2023 20:22:12 +0500 Message-Id: <20230621152214.2720319-2-stsp2@yandex.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230621152214.2720319-1-stsp2@yandex.ru> References: <20230621152214.2720319-1-stsp2@yandex.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_VALIDITY_RPBL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently F_UNLCK with F_OFD_GETLK returns -EINVAL. The proposed extension allows to use it for getting the lock information from the particular fd. Signed-off-by: Stas Sergeev CC: Jeff Layton CC: Chuck Lever CC: Alexander Viro CC: Christian Brauner CC: linux-fsdevel@vger.kernel.org CC: linux-kernel@vger.kernel.org CC: Shuah Khan CC: linux-kselftest@vger.kernel.org CC: linux-api@vger.kernel.org --- fs/locks.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index df8b26a42524..210766007e63 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -868,6 +868,21 @@ static bool posix_locks_conflict(struct file_lock *caller_fl, return locks_conflict(caller_fl, sys_fl); } +/* Determine if lock sys_fl blocks lock caller_fl. Used on xx_GETLK + * path so checks for additional GETLK-specific things like F_UNLCK. + */ +static bool posix_test_locks_conflict(struct file_lock *caller_fl, + struct file_lock *sys_fl) +{ + /* F_UNLCK checks any locks on the same fd. */ + if (caller_fl->fl_type == F_UNLCK) { + if (!posix_same_owner(caller_fl, sys_fl)) + return false; + return locks_overlap(caller_fl, sys_fl); + } + return posix_locks_conflict(caller_fl, sys_fl); +} + /* Determine if lock sys_fl blocks lock caller_fl. FLOCK specific * checking before calling the locks_conflict(). */ @@ -901,7 +916,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl) retry: spin_lock(&ctx->flc_lock); list_for_each_entry(cfl, &ctx->flc_posix, fl_list) { - if (!posix_locks_conflict(fl, cfl)) + if (!posix_test_locks_conflict(fl, cfl)) continue; if (cfl->fl_lmops && cfl->fl_lmops->lm_lock_expirable && (*cfl->fl_lmops->lm_lock_expirable)(cfl)) { @@ -2207,7 +2222,8 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock *flock) if (fl == NULL) return -ENOMEM; error = -EINVAL; - if (flock->l_type != F_RDLCK && flock->l_type != F_WRLCK) + if (cmd != F_OFD_GETLK && flock->l_type != F_RDLCK + && flock->l_type != F_WRLCK) goto out; error = flock_to_posix_lock(filp, fl, flock); @@ -2414,7 +2430,8 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 *flock) return -ENOMEM; error = -EINVAL; - if (flock->l_type != F_RDLCK && flock->l_type != F_WRLCK) + if (cmd != F_OFD_GETLK && flock->l_type != F_RDLCK + && flock->l_type != F_WRLCK) goto out; error = flock64_to_posix_lock(filp, fl, flock); -- 2.39.2