From patchwork Mon Sep 17 20:10:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Brandenburg X-Patchwork-Id: 10603355 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B378517D5 for ; Mon, 17 Sep 2018 20:12:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A60CA2A319 for ; Mon, 17 Sep 2018 20:12:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A0FC2A512; Mon, 17 Sep 2018 20:12:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 304B72A319 for ; Mon, 17 Sep 2018 20:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728555AbeIRBkJ (ORCPT ); Mon, 17 Sep 2018 21:40:09 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:42706 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727329AbeIRBkI (ORCPT ); Mon, 17 Sep 2018 21:40:08 -0400 Received: by mail-qt0-f194.google.com with SMTP id z8-v6so16538500qto.9 for ; Mon, 17 Sep 2018 13:11:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=omnibond-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SirJKoIx7jx+/pssoW2lLhRdFGwvChtL7wsaf8VCkus=; b=HA5PeBZHtni39+dG2TBUaxi6cZ6ue/ghbULDJLdX2d5F0XKrG+0bYBe2HXNT1VEqla RfoVi/pY+wKuXNmgu4mQtzmF2ABOJeAzmKRJpIjMCD5n2x32Hd+s9IutrJJ/saqyWOMF MAETIze9Kfx3Kt9B07jMPX514J1YmtcO+uGmzuMoaYu2TlNn2fTPr8lbeULDSXEE4VqA YuxiTPu4JXRuuKkFCl0J/YMzQCqTrz7iLoz5trUPuf0+ou1STdU+zM/CbWN2tYL7ZW7k 5Rf2PkM8JOaq1GE7KY3IOUpu0emqiOqMXw+k4S+M5H+EbiMDbelTmxipG2RqI8fKFtJP dzfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SirJKoIx7jx+/pssoW2lLhRdFGwvChtL7wsaf8VCkus=; b=teF4N5PwZVEeTefvV/zChRE5xs+nB8wCpMkliYHyPpu+hkUQM+BhHFJn6uMYh18dMQ O8jJN7NBaOhHOSAdpbsO+wzYKvkNcShjud3HlTtn+RryoP/5ySPXOQnJBotFQ1Hmyr5S KK5Wit9ay4Y97zAC0KYsDqnxBEEIDPKB2BfjBU1zjolO5MI4bDuZf/u21swYKZiusaGw BhtVvL5Ag3X/g/mSqrzFCOY7e58ZmHffnUZsfvHerBu7jOZZ50YCDSdKty/T2+1L8cFN Z8OrEA2BswkJDVgQr8n67n5675/Ir8wfn8PV48J8Q9JXoH0zd7CxxLgrnndsHmxpbxf3 NZxw== X-Gm-Message-State: APzg51AIQbcfF8l4/AYqIPYi0hDmAOSEjS+1CWlTC7Hww4RnsZx2Hudh 5X3ybx4AColcKI2ze6JijqPSWm4BuO83+3Ov X-Google-Smtp-Source: ANB0Vdb8PxFBZA7BjGXqFjlSF/ei101OAq3oXPlT+RDhY73bkfbnk8gVhhUmomyggj9bcb/Ln4Utcg== X-Received: by 2002:aed:21ac:: with SMTP id l41-v6mr18389455qtc.293.1537215076397; Mon, 17 Sep 2018 13:11:16 -0700 (PDT) Received: from ip-172-31-22-34.ec2.internal (ec2-18-215-252-133.compute-1.amazonaws.com. [18.215.252.133]) by smtp.gmail.com with ESMTPSA id n8-v6sm11053480qtk.38.2018.09.17.13.11.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Sep 2018 13:11:15 -0700 (PDT) From: Martin Brandenburg To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, devel@lists.orangefs.org Cc: Martin Brandenburg Subject: [PATCH 05/17] orangefs: hold i_lock during inode_getattr Date: Mon, 17 Sep 2018 20:10:42 +0000 Message-Id: <20180917201054.3530-6-martin@omnibond.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180917201054.3530-1-martin@omnibond.com> References: <20180917201054.3530-1-martin@omnibond.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This should be a no-op now. When inode writeback works, this will prevent a getattr from overwriting inode data while an inode is transitioning to dirty. Signed-off-by: Martin Brandenburg --- fs/orangefs/inode.c | 4 ++-- fs/orangefs/orangefs-utils.c | 33 +++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c index 067fd7111103..ec3996a61f92 100644 --- a/fs/orangefs/inode.c +++ b/fs/orangefs/inode.c @@ -253,8 +253,8 @@ int orangefs_getattr(const struct path *path, struct kstat *stat, struct inode *inode = path->dentry->d_inode; gossip_debug(GOSSIP_INODE_DEBUG, - "orangefs_getattr: called on %pd\n", - path->dentry); + "orangefs_getattr: called on %pd mask %u\n", + path->dentry, request_mask); ret = orangefs_inode_getattr(inode, request_mask & STATX_SIZE ? ORANGEFS_GETATTR_SIZE : 0); diff --git a/fs/orangefs/orangefs-utils.c b/fs/orangefs/orangefs-utils.c index 76f18a3494c7..d44cbe96719a 100644 --- a/fs/orangefs/orangefs-utils.c +++ b/fs/orangefs/orangefs-utils.c @@ -280,12 +280,17 @@ int orangefs_inode_getattr(struct inode *inode, int flags) loff_t inode_size; int ret, type; - gossip_debug(GOSSIP_UTILS_DEBUG, "%s: called on inode %pU\n", __func__, - get_khandle_from_ino(inode)); + gossip_debug(GOSSIP_UTILS_DEBUG, "%s: called on inode %pU flags %d\n", + __func__, get_khandle_from_ino(inode), flags); + spin_lock(&inode->i_lock); /* Must have all the attributes in the mask and be within cache time. */ - if (!flags && time_before(jiffies, orangefs_inode->getattr_time)) + if ((!flags && time_before(jiffies, orangefs_inode->getattr_time)) || + inode->i_state & I_DIRTY) { + spin_unlock(&inode->i_lock); return 0; + } + spin_unlock(&inode->i_lock); new_op = op_alloc(ORANGEFS_VFS_OP_GETATTR); if (!new_op) @@ -306,13 +311,23 @@ int orangefs_inode_getattr(struct inode *inode, int flags) if (ret != 0) goto out; + spin_lock(&inode->i_lock); + /* Must have all the attributes in the mask and be within cache time. */ + if ((!flags && time_before(jiffies, orangefs_inode->getattr_time)) || + inode->i_state & I_DIRTY) { + gossip_debug(GOSSIP_UTILS_DEBUG, "%s: in cache or dirty\n", + __func__); + ret = 0; + goto out_unlock; + } + if (!(flags & ORANGEFS_GETATTR_NEW)) { ret = orangefs_inode_is_stale(inode, &new_op->downcall.resp.getattr.attributes, new_op->downcall.resp.getattr.link_target); if (ret) { ret = -ESTALE; - goto out; + goto out_unlock; } } @@ -328,19 +343,15 @@ int orangefs_inode_getattr(struct inode *inode, int flags) inode->i_size = inode_size; inode->i_blkbits = ffs(new_op->downcall.resp.getattr. attributes.blksize); - spin_lock(&inode->i_lock); inode->i_bytes = inode_size; inode->i_blocks = (inode_size + 512 - inode_size % 512)/512; - spin_unlock(&inode->i_lock); } break; case S_IFDIR: if (flags) { inode->i_size = PAGE_SIZE; - spin_lock(&inode->i_lock); inode_set_bytes(inode, inode->i_size); - spin_unlock(&inode->i_lock); } set_nlink(inode, 1); break; @@ -353,7 +364,7 @@ int orangefs_inode_getattr(struct inode *inode, int flags) ORANGEFS_NAME_MAX); if (ret == -E2BIG) { ret = -EIO; - goto out; + goto out_unlock; } inode->i_link = orangefs_inode->link_target; } @@ -363,7 +374,7 @@ int orangefs_inode_getattr(struct inode *inode, int flags) /* XXX: ESTALE? This is what is done if it is not new. */ orangefs_make_bad_inode(inode); ret = -ESTALE; - goto out; + goto out_unlock; } inode->i_uid = make_kuid(&init_user_ns, new_op-> @@ -387,6 +398,8 @@ int orangefs_inode_getattr(struct inode *inode, int flags) orangefs_inode->getattr_time = jiffies + orangefs_getattr_timeout_msecs*HZ/1000; ret = 0; +out_unlock: + spin_unlock(&inode->i_lock); out: op_release(new_op); return ret;