Received: by 2002:a05:7412:8d1c:b0:fa:4c10:6cad with SMTP id bj28csp50633rdb; Tue, 16 Jan 2024 14:44:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFB7OzZYliICdU4QykIEptZ47xXdpf6jEdobDv9Tk6K5ZdaCM4rwnX9dGmQbLrfxVJqMI3f X-Received: by 2002:a17:902:efcc:b0:1d5:ac6:7123 with SMTP id ja12-20020a170902efcc00b001d50ac67123mr4221116plb.19.1705445089991; Tue, 16 Jan 2024 14:44:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705445089; cv=pass; d=google.com; s=arc-20160816; b=LPBsF9i7lD3UZWWIHcFvyBgAW9I6ICbJ39fT7VxtY4w7VT+XkAla1X05WOeaAI7INc JEF7pbPJ13/AKXdIGQBN5T6O+cTXgzY+Ro6fn6lqbj7ZFnmCqg4Rx8iQ3Y37rzDH1bQB TlDSTOZH/1KeuFRqOlGF5Ltr4AdXwHDaVfbaOF898NUvn9gm7zh94uyWHElVV7BUGCqR xMBFthHP6CnTacZVv1QR8Wl7yR5wdmU1qZXwCPYJNLMSvAt8gsU38AVXux/dMCEjn9Ad 2x8dnXoG2oqanluIWsoUuGzMEbxLLLXXEeNoWZxycejKAmfHK08hRhQ8MZ6LdULqloq6 /Pqg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:references:in-reply-to:subject:cc:to:from :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding; bh=Jsk6qYBnoqRiqs1Dsy/OWEyiCfLZPRL0iOpzVL5tMPk=; fh=mAq26R6urpe+KOcIReX0RRLqFRiZaH7bEHzigtUdAdU=; b=O1nEjNnhHiih8Xl/rbjR8+uHEWkNcWnPoOavbPms6qmlAJt3SArZB1dn0RQS7fon3U 8oZU7v5Pni4jBt90M2cQqtKgutRI2RMJdB+V+EuiiGW+MKpJCEdOFCI7rPftsyxEEni0 kmsL65GkwS2MtPMrB0VrCUEMKNgBsXXhNMEdVwAmszl5Svo3kcwpAcJa+aoW22oIKeKS mSHgSorE9g7LBr4Z41tekrV9pqAgWniDLzGcsyR6M0qDDNayWTCFfv55OUWSanRmdJrJ aiDlwa15o92Hy5AhDtUz0hW1MdkR08ELyfthdQYV+aCFgTKQMJH5HGHEQmC21CPgSyjb lmTg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-28338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i2-20020a170902c94200b001d0187da0a0si12990887pla.292.2024.01.16.14.44.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 14:44:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-28338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-kernel+bounces-28338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-28338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6BEB5291D01 for ; Tue, 16 Jan 2024 22:40:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BC213219F6; Tue, 16 Jan 2024 22:17:21 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FD1F1EB53; Tue, 16 Jan 2024 22:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705443441; cv=none; b=E7UVpWekq3f8aXurlkm/A671T+7ViRBkTCrpQLi3Wjsbeqa1G6OQSTmbZ5KM6AsFl8Ihd3tR3vrt1KK+TyVCKmMozOYukUWgZLSKnlBBvvI/dWDV/e1MMy5aOor3MNZnqB2oFX5cLcYxvOAkRWttRZXGX+GdwiHf7PZ+9nbJzJU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705443441; c=relaxed/simple; bh=c9fNxQOO0OpCqCDvyOc4cQBH2+/Y/B7I7wB7BdxBEPg=; h=Received:Received:Received:Content-Type:Content-Transfer-Encoding: MIME-Version:From:To:Cc:Subject:In-reply-to:References:Date: Message-id:X-Spam-Level:X-Rspamd-Server:X-Spamd-Result: X-Spam-Score:X-Rspamd-Queue-Id:X-Spam-Flag; b=X8ZUwfICVWMg9BB0Z7YrkygIq7QWPW7+nTskNWT9JqEeaNHkult29MaoMT2n+SDDMINWLTElLlMkMWMFQUJfwtFwv0uGa85QLga0TXTizINUW6JqFDxmMmjigbFX+BXAd8oxY+8xezaLO/ozb/9+xznoaGfSDconcTn7Y3kIbEY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5484A221D7; Tue, 16 Jan 2024 22:17:17 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C4DE713751; Tue, 16 Jan 2024 22:17:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id 3eSDHl8Ap2XCegAAD6G6ig (envelope-from ); Tue, 16 Jan 2024 22:17:03 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "NeilBrown" To: "Jeff Layton" Cc: "Christian Brauner" , "Alexander Viro" , "Eric Van Hensbergen" , "Latchesar Ionkov" , "Dominique Martinet" , "Christian Schoenebeck" , "David Howells" , "Marc Dionne" , "Xiubo Li" , "Ilya Dryomov" , "Alexander Aring" , "David Teigland" , "Miklos Szeredi" , "Andreas Gruenbacher" , "Trond Myklebust" , "Anna Schumaker" , "Chuck Lever" , "Olga Kornievskaia" , "Dai Ngo" , "Tom Talpey" , "Jan Kara" , "Mark Fasheh" , "Joel Becker" , "Joseph Qi" , "Steve French" , "Paulo Alcantara" , "Ronnie Sahlberg" , "Shyam Prasad N" , "Namjae Jeon" , "Sergey Senozhatsky" , "Steven Rostedt" , "Masami Hiramatsu" , "Mathieu Desnoyers" , linux-kernel@vger.kernel.org, v9fs@lists.linux.dev, linux-afs@lists.infradead.org, ceph-devel@vger.kernel.org, gfs2@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, ocfs2-devel@lists.linux.dev, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-trace-kernel@vger.kernel.org, "Jeff Layton" Subject: Re: [PATCH 11/20] filelock: convert the IS_* macros to take file_lock_core In-reply-to: <20240116-flsplit-v1-11-c9d0f4370a5d@kernel.org> References: <20240116-flsplit-v1-0-c9d0f4370a5d@kernel.org>, <20240116-flsplit-v1-11-c9d0f4370a5d@kernel.org> Date: Wed, 17 Jan 2024 09:16:56 +1100 Message-id: <170544341684.23031.11038222640477022046@noble.neil.brown.name> X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: 5484A221D7 X-Spam-Flag: NO On Wed, 17 Jan 2024, Jeff Layton wrote: > I couldn't get them to work properly as macros, so convert them > to static inlines instead (which is probably better for the type safety > anyway). >=20 > Signed-off-by: Jeff Layton > --- > fs/locks.c | 46 +++++++++++++++++++++++++++++++++------------- > 1 file changed, 33 insertions(+), 13 deletions(-) >=20 > diff --git a/fs/locks.c b/fs/locks.c > index 770aaa5809ba..eddf4d767d5d 100644 > --- a/fs/locks.c > +++ b/fs/locks.c > @@ -70,10 +70,26 @@ > =20 > #include > =20 > -#define IS_POSIX(fl) (fl->fl_core.fl_flags & FL_POSIX) Used 3 times... once as if (IS_POSIX(blocker) && !IS_OFDLCK(blocker)) Can an IS_POSIX lock also be IS_OFDLCK ?? > -#define IS_FLOCK(fl) (fl->fl_core.fl_flags & FL_FLOCK) Used once. > -#define IS_LEASE(fl) (fl->fl_core.fl_flags & (FL_LEASE|FL_DELEG|FL_LAYOUT)) Used twice. Either "IS_LEASE" approves things that aren't leases, or FL_LEASE is not set on all leases.... Names could be improved. > -#define IS_OFDLCK(fl) (fl->fl_core.fl_flags & FL_OFDLCK) used 4 times - a clear winner :-) If it would me, I would simply discard these macros and open-code the tests. I don't think IS_FLOCK() is easier to read for someone who knows the code, and I think IS_LEASE() is actually harder to read for someone who doesn't know the code, as that it does it not really obvious. But this is just a suggestion, I won't push it. Thanks, NeilBrown > +static inline bool IS_POSIX(struct file_lock_core *flc) > +{ > + return flc->fl_flags & FL_POSIX; > +} > + > +static inline bool IS_FLOCK(struct file_lock_core *flc) > +{ > + return flc->fl_flags & FL_FLOCK; > +} > + > +static inline bool IS_OFDLCK(struct file_lock_core *flc) > +{ > + return flc->fl_flags & FL_OFDLCK; > +} > + > +static inline bool IS_LEASE(struct file_lock_core *flc) > +{ > + return flc->fl_flags & (FL_LEASE|FL_DELEG|FL_LAYOUT); > +} > + > #define IS_REMOTELCK(fl) (fl->fl_core.fl_pid <=3D 0) > =20 > static bool lease_breaking(struct file_lock *fl) > @@ -761,6 +777,7 @@ static void __locks_insert_block(struct file_lock *bloc= ker, > struct file_lock *)) > { > struct file_lock *fl; > + struct file_lock_core *bflc; > BUG_ON(!list_empty(&waiter->fl_core.fl_blocked_member)); > =20 > new_blocker: > @@ -773,7 +790,9 @@ static void __locks_insert_block(struct file_lock *bloc= ker, > waiter->fl_core.fl_blocker =3D blocker; > list_add_tail(&waiter->fl_core.fl_blocked_member, > &blocker->fl_core.fl_blocked_requests); > - if (IS_POSIX(blocker) && !IS_OFDLCK(blocker)) > + > + bflc =3D &blocker->fl_core; > + if (IS_POSIX(bflc) && !IS_OFDLCK(bflc)) > locks_insert_global_blocked(&waiter->fl_core); > =20 > /* The requests in waiter->fl_blocked are known to conflict with > @@ -998,6 +1017,7 @@ static int posix_locks_deadlock(struct file_lock *call= er_fl, > struct file_lock *block_fl) > { > int i =3D 0; > + struct file_lock_core *flc =3D &caller_fl->fl_core; > =20 > lockdep_assert_held(&blocked_lock_lock); > =20 > @@ -1005,7 +1025,7 @@ static int posix_locks_deadlock(struct file_lock *cal= ler_fl, > * This deadlock detector can't reasonably detect deadlocks with > * FL_OFDLCK locks, since they aren't owned by a process, per-se. > */ > - if (IS_OFDLCK(caller_fl)) > + if (IS_OFDLCK(flc)) > return 0; > =20 > while ((block_fl =3D what_owner_is_waiting_for(block_fl))) { > @@ -2157,7 +2177,7 @@ static pid_t locks_translate_pid(struct file_lock *fl= , struct pid_namespace *ns) > pid_t vnr; > struct pid *pid; > =20 > - if (IS_OFDLCK(fl)) > + if (IS_OFDLCK(&fl->fl_core)) > return -1; > if (IS_REMOTELCK(fl)) > return fl->fl_core.fl_pid; > @@ -2721,19 +2741,19 @@ static void lock_get_status(struct seq_file *f, str= uct file_lock *fl, > if (repeat) > seq_printf(f, "%*s", repeat - 1 + (int)strlen(pfx), pfx); > =20 > - if (IS_POSIX(fl)) { > + if (IS_POSIX(&fl->fl_core)) { > if (fl->fl_core.fl_flags & FL_ACCESS) > seq_puts(f, "ACCESS"); > - else if (IS_OFDLCK(fl)) > + else if (IS_OFDLCK(&fl->fl_core)) > seq_puts(f, "OFDLCK"); > else > seq_puts(f, "POSIX "); > =20 > seq_printf(f, " %s ", > (inode =3D=3D NULL) ? "*NOINODE*" : "ADVISORY "); > - } else if (IS_FLOCK(fl)) { > + } else if (IS_FLOCK(&fl->fl_core)) { > seq_puts(f, "FLOCK ADVISORY "); > - } else if (IS_LEASE(fl)) { > + } else if (IS_LEASE(&fl->fl_core)) { > if (fl->fl_core.fl_flags & FL_DELEG) > seq_puts(f, "DELEG "); > else > @@ -2748,7 +2768,7 @@ static void lock_get_status(struct seq_file *f, struc= t file_lock *fl, > } else { > seq_puts(f, "UNKNOWN UNKNOWN "); > } > - type =3D IS_LEASE(fl) ? target_leasetype(fl) : fl->fl_core.fl_type; > + type =3D IS_LEASE(&fl->fl_core) ? target_leasetype(fl) : fl->fl_core.fl_t= ype; > =20 > seq_printf(f, "%s ", (type =3D=3D F_WRLCK) ? "WRITE" : > (type =3D=3D F_RDLCK) ? "READ" : "UNLCK"); > @@ -2760,7 +2780,7 @@ static void lock_get_status(struct seq_file *f, struc= t file_lock *fl, > } else { > seq_printf(f, "%d :0 ", fl_pid); > } > - if (IS_POSIX(fl)) { > + if (IS_POSIX(&fl->fl_core)) { > if (fl->fl_end =3D=3D OFFSET_MAX) > seq_printf(f, "%Ld EOF\n", fl->fl_start); > else >=20 > --=20 > 2.43.0 >=20 >=20