Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17988011rwd; Tue, 27 Jun 2023 10:01:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4QyQgokU4h1owWSWLpu2o9Lu2XQGlBi/wpQVKdDUDDiSyMR+yqUnbkPq+PTNje5L6fXi0n X-Received: by 2002:a19:4316:0:b0:4f8:5940:5c6a with SMTP id q22-20020a194316000000b004f859405c6amr19729297lfa.31.1687885314110; Tue, 27 Jun 2023 10:01:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687885314; cv=none; d=google.com; s=arc-20160816; b=VK8FhqrxnpEMXZKRQFYaMPJsl4kWJt7af2YpPluGUdsRhVQPPV4l88hA1taxk+Cbgn koXL5m5q1QhR98VZMU3jHsI8AMkllyBaFVZeXzk4hnhToUgshqro/JKJRrbkb0DEwhIG qZBzBTyGjpLukubKFe4Qq9Inqder5jKI4B+Sawu8RuL1zG4u8PulRahUyAdveVO2Lwu6 T8f98h5PlkuYFXwaU2V8BZFQ4DNZMzuyskY6TZG6XkOR7hY5BLFpK4XZT9j19nJeZZ48 yep9E6noqkJkJuKl2dNojsRWW0+Kvcjq+g/UcpCaY9Y7M2MFcpgAo3KuEXE+jrh5l+AJ VOvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=brOWiX3CBTB8FmMN7G8wuwVQlaholFGuvrnHuiFquL8=; fh=YkEQYIMdgPEFFf8dweS85wV8qbAJN4Feuv6InugO3vk=; b=YET+O9JgrzSWzebdhQgY/KUNftijb5Ql4ZZLiyrsIaL2tQ8xZBti0e8MOJu86f/pep ds5vAmm7MevNo2tzWGu0mKujkY27j2QGcVHw3iFxRjLk4YorbB+0ogsVYocDXIo2ZVIh oSvK6bIz5qBDrhNsFyBt18VQL4CJqIaQp2CRzmvGOV3LNRUEvWoIEmJsEhQ/+PhqrSI9 U16JVqp1O28Awb2DoLSp/WNoOB2/8fUU+qUvP7dU9niy8izLP7xn/8aJJuOFvKUBhZZj hW/F6E800J/vvAxT/VVZOYOewh+0KF0bL4rbWzUwDCTHzVzy72ah7KRaOpwN/8bkkW2H 7QzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bMs4+nSR; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020a1709067e5200b0098df1cbe2aesi4172185ejr.1008.2023.06.27.10.01.29; Tue, 27 Jun 2023 10:01:54 -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=@kernel.org header.s=k20201202 header.b=bMs4+nSR; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231648AbjF0QXw (ORCPT + 99 others); Tue, 27 Jun 2023 12:23:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231200AbjF0QXo (ORCPT ); Tue, 27 Jun 2023 12:23:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EDBC1FF0; Tue, 27 Jun 2023 09:23:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C83EA611D8; Tue, 27 Jun 2023 16:23:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58BEFC433C9; Tue, 27 Jun 2023 16:23:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687883022; bh=DSpyRxprW3MPfkhjPF5yXCDbAEFb7zNN+CnoAFHKHDI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=bMs4+nSR1W39m4QCMlBeLxy90os9T7tM9/ADdF1aARQ78hSxdCbmkJ9PNaQYK19Ju zT5Km1Rls5PK5FwBcnCRm2u8vhBzSgBJE5pybKa7pHa31ysYrrbUPq7/32BtO9VW/e R+cvLIVm21mnF9w4lni7NkFqS4JFMdRnADZPQ0Y8FYR6qPIZ9BDRgOZkYqv7VDfx0p 5yOrxdfxFqXR1PCK0T3PIpSQtr5bItmHVnua3DOpngwk60cVGSFIi4tMAW8hwf7URl TqF+XYGeZN0QcUZ1dc5VHIP4tDsuwIlUCUmOZh44BSKeWuSWDJkLyb3wRycnRhv69Y vZfR6LZL4Tnaw== Message-ID: Subject: Re: [PATCH 0/2] v3: F_OFD_GETLK extension to read lock info From: Jeff Layton To: Stas Sergeev , linux-kernel@vger.kernel.org Cc: Chuck Lever , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, Shuah Khan , linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org Date: Tue, 27 Jun 2023 12:23:40 -0400 In-Reply-To: <20230622165225.2772076-1-stsp2@yandex.ru> References: <20230622165225.2772076-1-stsp2@yandex.ru> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.3 (3.48.3-1.fc38) MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 On Thu, 2023-06-22 at 21:52 +0500, Stas Sergeev wrote: > This extension allows to use F_UNLCK on query, which currently returns > EINVAL. Instead it can be used to query the locks on a particular fd - > something that is not currently possible. The basic idea is that on > F_OFD_GETLK, F_UNLCK would "conflict" with (or query) any types of the > lock on the same fd, and ignore any locks on other fds. >=20 > Use-cases: >=20 > 1. CRIU-alike scenario when you want to read the locking info from an > fd for the later reconstruction. This can now be done by setting > l_start and l_len to 0 to cover entire file range, and do F_OFD_GETLK. > In the loop you need to advance l_start past the returned lock ranges, > to eventually collect all locked ranges. >=20 > 2. Implementing the lock checking/enforcing policy. > Say you want to implement an "auditor" module in your program, > that checks that the I/O is done only after the proper locking is > applied on a file region. In this case you need to know if the > particular region is locked on that fd, and if so - with what type > of the lock. If you would do that currently (without this extension) > then you can only check for the write locks, and for that you need to > probe the lock on your fd and then open the same file via another fd and > probe there. That way you can identify the write lock on a particular > fd, but such trick is non-atomic and complex. As for finding out the > read lock on a particular fd - impossible. > This extension allows to do such queries without any extra efforts. >=20 > 3. Implementing the mandatory locking policy. > Suppose you want to make a policy where the write lock inhibits any > unlocked readers and writers. Currently you need to check if the > write lock is present on some other fd, and if it is not there - allow > the I/O operation. But because the write lock can appear at any moment, > you need to do that under some global lock, which can be released only > when the I/O operation is finished. > With the proposed extension you can instead just check the write lock > on your own fd first, and if it is there - allow the I/O operation on > that fd without using any global lock. Only if there is no write lock > on this fd, then you need to take global lock and check for a write > lock on other fds. >=20 >=20 > The second patch adds a test-case for OFD locks. > It tests both the generic things and the proposed extension. >=20 >=20 > The third patch is a proposed man page update for fcntl(2) > (not for the linux source tree) >=20 >=20 > Changes in v3: > - Move selftest to selftests/filelock >=20 > Changes in v2: > - Dropped the l_pid extension patch and updated test-case accordingly. >=20 > Stas Sergeev (2): > fs/locks: F_UNLCK extension for F_OFD_GETLK > selftests: add OFD lock tests >=20 > fs/locks.c | 23 +++- > tools/testing/selftests/filelock/Makefile | 5 + > tools/testing/selftests/filelock/ofdlocks.c | 132 ++++++++++++++++++++ > 3 files changed, 157 insertions(+), 3 deletions(-) > create mode 100644 tools/testing/selftests/filelock/Makefile > create mode 100644 tools/testing/selftests/filelock/ofdlocks.c >=20 > 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 >=20 I've taken the first two patches into my locks-next branch, so they should end up in linux-next soon. Adding support for testing this to fstests is a hard requirement before this will be merged into mainline. Thanks, --=20 Jeff Layton