From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A77BEC4332F for ; Tue, 15 Nov 2022 08:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232642AbiKOIzS (ORCPT ); Tue, 15 Nov 2022 03:55:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232993AbiKOIyw (ORCPT ); Tue, 15 Nov 2022 03:54:52 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBD0B20F72; Tue, 15 Nov 2022 00:54:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=XnEj26lKZcJ/I4VuOEUSvvYB44Q9hvJF20imshWtvMA=; b=kNSPfSHEg2HxqQCdQLWh+G4Esm 2qwuSXBJtSwRoDUdcuxQTX0483lMMKT6LxtmOaL13kbTQeKCgWFaHkVXMoWEAG+YFY3/PpsMkhuxX Z5r00F7BzautJ8h5usb/hnqhT12GoyfnpWiIUj4SOf48FL+rxcqTXj4Vpl3ps459ZwROQ0YzQROfh BRsffR0Ua0x4d8osnPMu82FUwXiL5TrTHWgFLoP/XZcXgD2NE5SLJTKhbZ1eHrxU1s2vSfiA98TDN V1BZls0UhxcVS60l4qcUhohpUpalSC708FlHlLQykqbkt4EAm5yakbMKDi9c739Czg5cKIZOiVNGB qQdIutSg==; Received: from hch by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1ouriB-0094M7-LE; Tue, 15 Nov 2022 08:54:31 +0000 Date: Tue, 15 Nov 2022 00:54:31 -0800 From: Christoph Hellwig To: Jeff Layton Cc: chuck.lever@oracle.com, xiubli@redhat.com, linux-fsdevel@vger.kernel.org, ceph-devel@vger.kernel.org Subject: Re: [RFC PATCH] filelock: new helper: vfs_file_has_locks Message-ID: References: <20221114140747.134928-1-jlayton@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221114140747.134928-1-jlayton@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Mon, Nov 14, 2022 at 09:07:47AM -0500, Jeff Layton wrote: > +bool vfs_file_has_locks(struct file *filp) > +{ > + struct file_lock_context *ctx; > + struct file_lock *fl; > + bool ret = false; > + > + ctx = smp_load_acquire(&locks_inode(filp)->i_flctx); > + if (!ctx) > + return false; > + > + spin_lock(&ctx->flc_lock); > + list_for_each_entry(fl, &ctx->flc_posix, fl_list) { > + if (fl->fl_file == filp) { > + ret = true; > + goto out; > + } > + } > + list_for_each_entry(fl, &ctx->flc_flock, fl_list) { > + if (fl->fl_file == filp) { > + ret = true; > + break; > + } > + } Maybe a little helper for the list lookup would be nice here: static inline bool __vfs_file_has_locks(struct file *file) { struct file_lock *fl; list_for_each_entry(fl, &ctx->flc_flock, fl_list) if (fl->fl_file == filp) return true; return false; } simplifying the check in the caller to: ret = __vfs_file_has_locks(&ctx->flc_posix) || __vfs_file_has_locks(&ctx->flc_flock); > +EXPORT_SYMBOL(vfs_file_has_locks); EXPORT_SYMBOL_GPL for any new network-fsy functionality would be nice.