Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3166113imu; Wed, 7 Nov 2018 06:13:01 -0800 (PST) X-Google-Smtp-Source: AJdET5eboCqrwobDx+cBZisF+iw/xiSgqWKT1nC0thHq2rYIsQiUX8hZ7GuVmw72Ifvolsx6ivtI X-Received: by 2002:a62:1cc6:: with SMTP id c189-v6mr365905pfc.49.1541599981550; Wed, 07 Nov 2018 06:13:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541599981; cv=none; d=google.com; s=arc-20160816; b=UnAopIIbuHg9awl7REHyyU7nvaHW92SaoF58V+X7qvCYlOexhpFInNmxIIOb0CL7xN 7fDnBETKUyrTg/PIMJzFvflQwTCvvh8T63RJ/WT9NW9atElyoUfeBS/f26p6cARz62In quY6f4C1i/bVR9XVPR1BmSl9nD4TLJCqcdyyQoQnOQjvWuA2kN+RBCJpBOTEzV2DsiAy ZkcVR7g7YnPoaFd5guAbLPEfdldlnITrfSSRfu51BFNT5oUUuPsMVhg1xv9SCUt1GUfg B0MR4HGNF9xT66ZBOSietB9m8jVYPfcU5PR+h/qw74GDrdDAsAa8RnAHzWrs39Uv4934 aAVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=TZGnFEmQgoGsHsuz6vt5dn/fNUdlCN38NGGqmcyYGNI=; b=uQuaGcKXboPFoYGjiOwAIMNgF5dsY73s7Jm6mkTggyV+Fe41WQiWTA8m5+Wla9x/PV sdHyEhE8nk4EDinnRaSlcXwyhI3Na0yy7wqoPzqf0n/1VbYtpc/NhkHoGyNtX4y5YdV4 igUQqfH6rn569eAmTiJu1N+/+pIouZEizQmZfSv3oRTd3Iq3thaeL5e4sDYMDm9iN39D 8TipFxveshwFMsZ8Fb8Orvc/VB2Ho+N53nNKV22PO3PwhMXcz08svc2pGCY0j5EbQOdm RVTdFZuv0ZUtP7QEb5gxj1hvS+7iTDxzcgeHkDFa8QQ3VnC3xzOYDDJ/ShSi0JyGrwUP JqCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=hWIZfDVZ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j19-v6si696940pfh.63.2018.11.07.06.12.46; Wed, 07 Nov 2018 06:13:01 -0800 (PST) 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=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=hWIZfDVZ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727775AbeKGXmt (ORCPT + 99 others); Wed, 7 Nov 2018 18:42:49 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:40430 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726752AbeKGXmt (ORCPT ); Wed, 7 Nov 2018 18:42:49 -0500 Received: by mail-it1-f194.google.com with SMTP id e11so19562492itl.5 for ; Wed, 07 Nov 2018 06:12:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=TZGnFEmQgoGsHsuz6vt5dn/fNUdlCN38NGGqmcyYGNI=; b=hWIZfDVZq4sKtKt18Xd4PXWr88elFVcTyxXJWNzQUlUltnSnxK0uKTZYsKJAM9u1a4 w6fsLzCyS9CYCK6AXZ+HOqjMmTsYFAso0QT1GCv36/lLuBJBYXw+Jase1OQgKbIxRm9O PGClADHhTgZvRiHeo7o/F+nKE77k1R67LE+C4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=TZGnFEmQgoGsHsuz6vt5dn/fNUdlCN38NGGqmcyYGNI=; b=HgZYqXpTcYTD0tfmTdaSFoy8gcA63xdOJTN4suhMK8tmdQ5+Q/aKuofBSZ8QGHYA7W C+wXLKo2mQD3nk7K0I0AsSAhbkjqkyvgZ+eWFZ9v6+mgV7PUHyJDhPd+oNz5xytlmXDC sfOA6AAu30wTKgqmpY6DGaM9oqf/9NR9abcpgiU4ZIeFvZVIsGF3O3jMGxVqtJ+NBtEr YdZ4k7nbCnIXApoxfmWb7QP5C8u3AgS177yWfIHbuqn1a7x8oiD6FPZFnaedUHb9dHp9 1h1PqOfh9Ehk5C+nF1Q7250qBAMTVQOFLuJKs1dudXOVkzduidaNPLtsoeBnRiI+og86 AfZQ== X-Gm-Message-State: AGRZ1gK1Eqeqt/64zUFcXUHv2NfVwUCAi4dVoW1zui5XPq9Yx6dmxnje h3IHe+i5yZEMGqbfC8tFCmpM82vS5fUOVDFstNfclQ== X-Received: by 2002:a24:fe88:: with SMTP id w130-v6mr291140ith.69.1541599936200; Wed, 07 Nov 2018 06:12:16 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a6b:ac42:0:0:0:0:0 with HTTP; Wed, 7 Nov 2018 06:12:15 -0800 (PST) X-Originating-IP: [212.96.48.140] In-Reply-To: <154149743811.18189.2448546280541143340.stgit@localhost.localdomain> References: <154149673368.18189.14752124997476502777.stgit@localhost.localdomain> <154149743811.18189.2448546280541143340.stgit@localhost.localdomain> From: Miklos Szeredi Date: Wed, 7 Nov 2018 15:12:15 +0100 Message-ID: Subject: Re: [PATCH 4/6] fuse: Implement fuse_attr_version_inc() To: Kirill Tkhai Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 6, 2018 at 10:43 AM, Kirill Tkhai wrote: > For cleanup purpose archive repeating pattern: > > spin_lock(&fc->lock); > fi->attr_version = ++fc->attr_version; > spin_unlock(&fc->lock); > > into separate function. > > Signed-off-by: Kirill Tkhai > --- > fs/fuse/dir.c | 8 ++------ > fs/fuse/file.c | 16 ++++------------ > fs/fuse/fuse_i.h | 11 +++++++++++ > fs/fuse/inode.c | 4 +--- > 4 files changed, 18 insertions(+), 21 deletions(-) > > diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c > index 794b9f48fb8e..35f3b3d1e044 100644 > --- a/fs/fuse/dir.c > +++ b/fs/fuse/dir.c > @@ -674,9 +674,7 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry) > struct fuse_inode *fi = get_fuse_inode(inode); > > spin_lock(&fi->lock); > - spin_lock(&fc->lock); > - fi->attr_version = ++fc->attr_version; > - spin_unlock(&fc->lock); > + fi->attr_version = fuse_attr_version_inc_return(fc); > /* > * If i_nlink == 0 then unlink doesn't make sense, yet this can > * happen if userspace filesystem is careless. It would be > @@ -830,9 +828,7 @@ static int fuse_link(struct dentry *entry, struct inode *newdir, > struct fuse_inode *fi = get_fuse_inode(inode); > > spin_lock(&fi->lock); > - spin_lock(&fc->lock); > - fi->attr_version = ++fc->attr_version; > - spin_unlock(&fc->lock); > + fi->attr_version = fuse_attr_version_inc_return(fc); > inc_nlink(inode); > spin_unlock(&fi->lock); > fuse_invalidate_attr(inode); > diff --git a/fs/fuse/file.c b/fs/fuse/file.c > index 48e2889ba6a6..1164d3580c62 100644 > --- a/fs/fuse/file.c > +++ b/fs/fuse/file.c > @@ -186,9 +186,7 @@ void fuse_finish_open(struct inode *inode, struct file *file) > struct fuse_inode *fi = get_fuse_inode(inode); > > spin_lock(&fi->lock); > - spin_lock(&fc->lock); > - fi->attr_version = ++fc->attr_version; > - spin_unlock(&fc->lock); > + fi->attr_version = fuse_attr_version_inc_return(fc); > i_size_write(inode, 0); > spin_unlock(&fi->lock); > fuse_invalidate_attr(inode); > @@ -604,9 +602,7 @@ static void fuse_aio_complete(struct fuse_io_priv *io, int err, ssize_t pos) > struct fuse_inode *fi = get_fuse_inode(inode); > > spin_lock(&fi->lock); > - spin_lock(&fc->lock); > - fi->attr_version = ++fc->attr_version; > - spin_unlock(&fc->lock); > + fi->attr_version = fuse_attr_version_inc_return(fc); > spin_unlock(&fi->lock); > } > > @@ -685,9 +681,7 @@ static void fuse_read_update_size(struct inode *inode, loff_t size, > spin_lock(&fi->lock); > if (attr_ver == fi->attr_version && size < inode->i_size && > !test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) { > - spin_lock(&fc->lock); > - fi->attr_version = ++fc->attr_version; > - spin_unlock(&fc->lock); > + fi->attr_version = fuse_attr_version_inc_return(fc); > i_size_write(inode, size); > } > spin_unlock(&fi->lock); > @@ -1006,9 +1000,7 @@ bool fuse_write_update_size(struct inode *inode, loff_t pos) > bool ret = false; > > spin_lock(&fi->lock); > - spin_lock(&fc->lock); > - fi->attr_version = ++fc->attr_version; > - spin_unlock(&fc->lock); > + fi->attr_version = fuse_attr_version_inc_return(fc); > if (pos > inode->i_size) { > i_size_write(inode, pos); > ret = true; > diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h > index 075da40499b8..f7442bcecbb0 100644 > --- a/fs/fuse/fuse_i.h > +++ b/fs/fuse/fuse_i.h > @@ -775,6 +775,17 @@ static inline int invalid_nodeid(u64 nodeid) > return !nodeid || nodeid == FUSE_ROOT_ID; > } > > +static inline u64 fuse_attr_version_inc_return(struct fuse_conn *fc) > +{ > + u64 attr_version; > + > + spin_lock(&fc->lock); > + attr_version = ++fc->attr_version; > + spin_unlock(&fc->lock); > + > + return attr_version; > +} atomic64_t? And move this patch one up, 3/6 is complicated as is without having to add extra locking around fc->attr_version. > + > /** Device operations */ > extern const struct file_operations fuse_dev_operations; > > diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c > index f62d45686b42..5f488b019cd9 100644 > --- a/fs/fuse/inode.c > +++ b/fs/fuse/inode.c > @@ -167,9 +167,7 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, > > lockdep_assert_held(&fi->lock); > > - spin_lock(&fc->lock); > - fi->attr_version = ++fc->attr_version; > - spin_unlock(&fc->lock); > + fi->attr_version = fuse_attr_version_inc_return(fc); > > fi->i_time = attr_valid; > WRITE_ONCE(fi->inval_mask, 0); >