Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1905515imm; Thu, 9 Aug 2018 04:10:51 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxINWXfmx6pAkf88ly0Q0gdTvgsbnOqFvoggpsJDscSwL5IPKkOcDjLfyMAHh3GX4X6xfAH X-Received: by 2002:aa7:824d:: with SMTP id e13-v6mr1899761pfn.97.1533813051446; Thu, 09 Aug 2018 04:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533813051; cv=none; d=google.com; s=arc-20160816; b=rdL3kr3GA5daYFaE8WDCSAG1F32gUd813L69we8eR8tyFcCCRh1J0ihd8YVonkb0Yl +6NriGSO2fhJXOl3/cZDJdZBRifl6o3E5/mWacXfcdUv9m2gQwn2hyVL/2OXf7n209VX eFU8DFB4WcdhrETQ72X+y+yyIcExq9Z1R8wIr96QdRPkfcsHtdQTuE3MC3Ykc9De+oBu s08htzuvcV0M5ICZwTB50rpM29DVpXFXVXBgfjPeLJAhhyA8LnDYYIXhyXyy8Xs9e3lW pb1bFmPbL3wI9R2q7E/vLAjHqRYlxwmTEGLhZB3S5JBskoCL6cLrc7ZtXnCZCN9YO/3X c3Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature:arc-authentication-results; bh=vVloH3Q9YWrq0UoogqAENDpv7mm51desRL8mgUvjO8g=; b=H4QbD5KFdSE1Xn0I+MS6RzunnWo0Cm6XvG5KKxMPu6iYG8NP+9sGHw9Ku+brm4kep2 7jyKgvduwLWXgnYNoUZnCnKUMuNwg3YIV5MdVFPJPelAnJDyKok8w8ovF9/hzc9wCvse XVNGafiAGNmvQHwllVl8y5tBGNFAREZzg4E6lHkJUbe8OmTGecCcnGy2wGiu1fG+64iP AixtlV8p9J2ex0hVRFjpJXrXvuCrbhR1PIBLh8m56rbfSLh+mlj1n7ctFZg7e9amWm1x HG766AKAbHHfLKK/t0SnpogTts9lzT4+FrX73kcRQs+JqecINB2arQTDwOZF23IwjPFI W0ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g5zhFnSN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20-v6si5337920pls.78.2018.08.09.04.10.37; Thu, 09 Aug 2018 04:10:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g5zhFnSN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1730905AbeHINeB (ORCPT + 99 others); Thu, 9 Aug 2018 09:34:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:49268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730758AbeHINeA (ORCPT ); Thu, 9 Aug 2018 09:34:00 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 83BD02177D; Thu, 9 Aug 2018 11:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1533812978; bh=JKRgVp2jltUbxQUvzjm2xEUIkPkBZH+8rxRaf5dZl/I=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=g5zhFnSNb/TvID6s/Xs7gwqCOfR9KpDx23G81/Nw/5ZlyXBwfvv46EZypmozXeUE8 cr+Q5rcSwF/90bkWhX2lt9CO5j5IeGTu/Mv/zgEKnZRs1jsP4aTQ8y5zVrjE/oTNNK +4Lhg4vLKoWI1VSjcb+G8YwF3v6rqtEB5bd0O5AQ= Message-ID: <4c852081f72a8ed00cc216090030756b0a042f7c.camel@kernel.org> Subject: Re: [PATCH 3/5] fs/locks: change all *_conflict() functions to return a new enum. From: Jeff Layton To: NeilBrown , Alexander Viro Cc: "J. Bruce Fields" , Martin Wilck , linux-fsdevel@vger.kernel.org, Frank Filz , linux-kernel@vger.kernel.org Date: Thu, 09 Aug 2018 07:09:35 -0400 In-Reply-To: <153378028114.1220.3708291796442871726.stgit@noble> References: <153378012255.1220.6754153662007899557.stgit@noble> <153378028114.1220.3708291796442871726.stgit@noble> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-1.fc28) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2018-08-09 at 12:04 +1000, NeilBrown wrote: > In a future patch we will need to differentiate between conflicts that > are "transitive" and those that aren't. > A "transitive" conflict is defined as one where any lock that > conflicts with the first (newly requested) lock would conflict with > the existing lock. > > So change posix_locks_conflict(), flock_locks_conflict() (both > currently returning int) and leases_conflict() (currently returning > bool) to return "enum conflict". > Add locks_transitive_overlap() to make it possible to compute the > correct conflict for posix locks. > > The FL_NO_CONFLICT value is zero, so current code which only tests the > truth value of these functions will still work the same way. > > And convert some > return (foo); > to > return foo; > > Signed-off-by: NeilBrown > --- > fs/locks.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++-------------- > 1 file changed, 49 insertions(+), 15 deletions(-) > > diff --git a/fs/locks.c b/fs/locks.c > index b4812da2a374..d06658b2dc7a 100644 > --- a/fs/locks.c > +++ b/fs/locks.c > @@ -139,6 +139,16 @@ > #define IS_OFDLCK(fl) (fl->fl_flags & FL_OFDLCK) > #define IS_REMOTELCK(fl) (fl->fl_pid <= 0) > > +/* A transitive conflict is one where the first lock conflicts with > + * the second lock, and any other lock that conflicts with the > + * first lock, also conflicts with the second lock. > + */ > +enum conflict { > + FL_NO_CONFLICT = 0, > + FL_CONFLICT, > + FL_TRANSITIVE_CONFLICT, > +}; > + > static inline bool is_remote_lock(struct file *filp) > { > return likely(!(filp->f_path.dentry->d_sb->s_flags & SB_NOREMOTELOCK)); > @@ -612,6 +622,15 @@ static inline int locks_overlap(struct file_lock *fl1, struct file_lock *fl2) > (fl2->fl_end >= fl1->fl_start)); > } > > +/* Check for transitive-overlap - true if any lock that overlaps > + * the first lock must overlap the seconds > + */ > +static inline bool locks_transitive_overlap(struct file_lock *fl1, > + struct file_lock *fl2) > +{ > + return (fl1->fl_start >= fl2->fl_start) && > + (fl1->fl_end <= fl2->fl_end); > +} > /* > * Check whether two locks have the same owner. > */ > @@ -793,47 +812,61 @@ locks_delete_lock_ctx(struct file_lock *fl, struct list_head *dispose) > /* Determine if lock sys_fl blocks lock caller_fl. Common functionality > * checks for shared/exclusive status of overlapping locks. > */ > -static int locks_conflict(struct file_lock *caller_fl, struct file_lock *sys_fl) > +static enum conflict locks_conflict(struct file_lock *caller_fl, > + struct file_lock *sys_fl) > { > if (sys_fl->fl_type == F_WRLCK) > - return 1; > + return FL_TRANSITIVE_CONFLICT; > if (caller_fl->fl_type == F_WRLCK) > - return 1; > - return 0; > + return FL_CONFLICT; > + return FL_NO_CONFLICT; > } > > /* Determine if lock sys_fl blocks lock caller_fl. POSIX specific > * checking before calling the locks_conflict(). > */ > -static int posix_locks_conflict(struct file_lock *caller_fl, struct file_lock *sys_fl) > +static enum conflict posix_locks_conflict(struct file_lock *caller_fl, > + struct file_lock *sys_fl) > { > /* POSIX locks owned by the same process do not conflict with > * each other. > */ > if (posix_same_owner(caller_fl, sys_fl)) > - return (0); > + return FL_NO_CONFLICT; > > /* Check whether they overlap */ > if (!locks_overlap(caller_fl, sys_fl)) > - return 0; > + return FL_NO_CONFLICT; > > - return (locks_conflict(caller_fl, sys_fl)); > + switch (locks_conflict(caller_fl, sys_fl)) { > + default: Maybe BUG or WARN here or something? locks_conflict should never return values that aren't in the enum. > + case FL_NO_CONFLICT: > + return FL_NO_CONFLICT; > + case FL_CONFLICT: > + return FL_CONFLICT; > + case FL_TRANSITIVE_CONFLICT: > + if (locks_transitive_overlap(caller_fl, sys_fl)) > + return FL_TRANSITIVE_CONFLICT; > + else > + return FL_CONFLICT; > + } > } > > /* Determine if lock sys_fl blocks lock caller_fl. FLOCK specific > * checking before calling the locks_conflict(). > */ > -static int flock_locks_conflict(struct file_lock *caller_fl, struct file_lock *sys_fl) > +static enum conflict flock_locks_conflict(struct file_lock *caller_fl, > + struct file_lock *sys_fl) > { > /* FLOCK locks referring to the same filp do not conflict with > * each other. > */ > if (caller_fl->fl_file == sys_fl->fl_file) > - return (0); > + return FL_NO_CONFLICT; > if ((caller_fl->fl_type & LOCK_MAND) || (sys_fl->fl_type & LOCK_MAND)) > - return 0; > + return FL_NO_CONFLICT; > > - return (locks_conflict(caller_fl, sys_fl)); > + return locks_conflict(caller_fl, sys_fl); > } > > void > @@ -1435,12 +1468,13 @@ static void time_out_leases(struct inode *inode, struct list_head *dispose) > } > } > > -static bool leases_conflict(struct file_lock *lease, struct file_lock *breaker) > +static enum conflict leases_conflict(struct file_lock *lease, > + struct file_lock *breaker) > { > if ((breaker->fl_flags & FL_LAYOUT) != (lease->fl_flags & FL_LAYOUT)) > - return false; > + return FL_NO_CONFLICT; > if ((breaker->fl_flags & FL_DELEG) && (lease->fl_flags & FL_LEASE)) > - return false; > + return FL_NO_CONFLICT; > return locks_conflict(breaker, lease); > } > > > -- Jeff Layton