Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7581304rwd; Tue, 20 Jun 2023 03:24:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6EJwi3lq9d4wI6RPWa3FBKYhL8WVjsHwG6vglW4vgfc5rgXlUbzVT4/R9/F/OexTF219vM X-Received: by 2002:a05:6a20:a10c:b0:11f:c1a1:8c with SMTP id q12-20020a056a20a10c00b0011fc1a1008cmr9283491pzk.54.1687256682524; Tue, 20 Jun 2023 03:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687256682; cv=none; d=google.com; s=arc-20160816; b=AvY7WHlAbHHW71c2vmFSRZOIbxaJpwcmunfdIsAoomzlxgkGUYAu2IE00NcVD1ZGCw scisq/YGpXlH7kXDU7kce6ny8KlbDYMLWA6scvc8gHKVnppmlsFcXituhspRKJiEbnaL URBrwIcWyANJxO+LUWfS1/8iVkbUs2xT10EzpJ93ilTeozj+yO6bGUvKD2KS6ZvL8ZBA nSyUVxotukKdVg8AKxHCD3qymHu/zzSOxHgdaGi9793XUzpCl5jMe85vLOg7kfL7q0dV bzvgsckHyHqdBU4+rHNy2+wU0284M817Vd/AhovVhGFNgw6MwVwPjAD/TjZP2dqonmzI HOCQ== 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=sUfHCacVyDt7Kg3HyQ2KiMmhLhRyXxIZpN8hmjW6jXw=; b=1EEPDjWh/ojjkV+s8HP3B6PdgkLznQpotNbtqTxUrWq/ScK1PLg0mOieVMssMu9OY4 1933/yMjg5JPoFfBY6xX6FUKntBE1Rc1tJaOmeyKqaTlHFh42RWtd3Y78dp/3buSRnX0 +b7nTu8KqD2cc3MkzpuoQ60aGJzIJbNrqf3vFlZwAa9h4fOIzZXEbmwspP3C7zpmn33h iXtqUeTN5mLkBuXFcQ2jf4pRpQdkQMa3euVWEVUIHhiLhOGYUfE0ulrQaftn+evQ7Akt e087fN2AeOLudI9oX0c+H4b/sA2B9YHhuk5R7lnDsZvmoTjiPTJkcbtXcj/0IW+dpK4h hqvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=ceuQ+TxZ; 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 z2-20020aa79f82000000b0064f735aef04si1404062pfr.209.2023.06.20.03.24.27; Tue, 20 Jun 2023 03:24:42 -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=ceuQ+TxZ; 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 S230451AbjFTKIC (ORCPT + 99 others); Tue, 20 Jun 2023 06:08:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231733AbjFTKHe (ORCPT ); Tue, 20 Jun 2023 06:07:34 -0400 Received: from forward204a.mail.yandex.net (forward204a.mail.yandex.net [178.154.239.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AA41172B; Tue, 20 Jun 2023 03:07:19 -0700 (PDT) Received: from forward103a.mail.yandex.net (forward103a.mail.yandex.net [IPv6:2a02:6b8:c0e:500:1:45:d181:d103]) by forward204a.mail.yandex.net (Yandex) with ESMTP id 13770497AF; Tue, 20 Jun 2023 12:55:51 +0300 (MSK) Received: from mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net [IPv6:2a02:6b8:c1f:5e51:0:640:23ee:0]) by forward103a.mail.yandex.net (Yandex) with ESMTP id 28811463BB; Tue, 20 Jun 2023 12:55:44 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-51.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id Utd7jIuDca60-Htt71yOI; Tue, 20 Jun 2023 12:55:43 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1687254943; bh=sUfHCacVyDt7Kg3HyQ2KiMmhLhRyXxIZpN8hmjW6jXw=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=ceuQ+TxZ2P+d+L+jTkyDGA54u/cllL0gz+lX6yj7P9w6wz/m2WNtjsLtnH5kiKyLl G0BFqq4UGx/D20fJUH1w3ehXFfQROT2L5XWvgmxREKmLIT5EN/VEfHf68rydRZz/xW MJLXWtUocgpoqlfk9HxgeD6vK3xu9D6/z0o11nzo= Authentication-Results: mail-nwsmtp-smtp-production-main-51.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 Subject: [PATCH 1/3] fs/locks: F_UNLCK extension for F_OFD_GETLK Date: Tue, 20 Jun 2023 14:55:05 +0500 Message-Id: <20230620095507.2677463-2-stsp2@yandex.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620095507.2677463-1-stsp2@yandex.ru> References: <20230620095507.2677463-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 --- 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