From patchwork Mon Jul 30 04:28:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10548405 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 E8E8E13B8 for ; Mon, 30 Jul 2018 04:29:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D370529997 for ; Mon, 30 Jul 2018 04:29:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7F58299A0; Mon, 30 Jul 2018 04:29:07 +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.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 52F4E29997 for ; Mon, 30 Jul 2018 04:29:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726094AbeG3GCI (ORCPT ); Mon, 30 Jul 2018 02:02:08 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:38847 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726093AbeG3GCI (ORCPT ); Mon, 30 Jul 2018 02:02:08 -0400 Received: by mail-it0-f68.google.com with SMTP id v71-v6so15038927itb.3 for ; Sun, 29 Jul 2018 21:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cWc1iLQWMIgtEjH1h41rrRZOuQcLwozX+h2rURo+ILk=; b=SQyu4Qnns8M50XhpsS5C7AdkuB1AGY5z3R2ZDpip8AkdzVuR+0762asm3iIC0z+2OE rRi/ajXyheEdHSPSWOI5R1sPcLjID3DNIS2DNrIrO8jRYdXxR0xHi7V6j8YyI2Vtn5E9 1LjgfpQMYFQ+Kd3srqntZekRKYaY+hJ/eYc4JjXx1QgL4dNMDJfi3kN1LXdC6lQeKbTw n+3m2n9YJ+MjBBzx7WP8yICe2ff64RU2j5VAsNzDzgR6VfqCZZcxzJhWPEh+kHveUBrc EK5hfvnPUiyFfGQpjG6DhhUS6tgwFNylutWAxtbQe6xLRjT/ag5UFQaoJhXQIbqB9B/W F6KQ== 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:mime-version :content-transfer-encoding; bh=cWc1iLQWMIgtEjH1h41rrRZOuQcLwozX+h2rURo+ILk=; b=RT+Y+EaZKa2Uqkkitk9GtykwLHe2xDYb95Wx6YbQrA6NAA1wDQGWMo969aRenXqfOq gBuI1YGkPkYUeN5gsYNFr8kuKHnuAzh85nmfeSVhHStaqySbQqtWS/qegndM0Zq9OxDC eWRMxMl8uiI9+i8zyZm23Fc2aL083DCKAdrtXF5Nnvh5AG1R7tAvTLUQTlUSzr8K8h0c mSzQVk2epn6XtyHnYd6YpHgI4sA72BvSGaSH8jxXY9GiNTw9glC3aMcky+DRW6WWgP2I ycH6iCSzbcIPHhg6y+n5GWGtTctp9dhn7KUSvR2xL0mNXtfbwapaQbWpzqge8RwDQFQo lcYg== X-Gm-Message-State: AOUpUlGxW3n9IWVoqqkgqCzE7rf6ct0kksVKH2TaVYGNRNl0s6dKA9U+ ffKgNHujarRxz9oZ7tTTMtCV5Oo= X-Google-Smtp-Source: AAOMgpeG9ATe3KQJjYFFrE40ihunIDYZZjmbpwY3gMCIJy19KIcMzCJjJCZFvHj3KgGVa2zv+D+Ngg== X-Received: by 2002:a24:14d8:: with SMTP id 207-v6mr13661882itg.41.1532924944032; Sun, 29 Jul 2018 21:29:04 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (50-36-89-147.alma.mi.frontiernet.net. [50.36.89.147]) by smtp.gmail.com with ESMTPSA id z2-v6sm5643732iti.3.2018.07.29.21.29.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Jul 2018 21:29:03 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2] NFSv4: bump/drop the nlink count on the parent dir when we mkdir/rmdir Date: Mon, 30 Jul 2018 00:28:41 -0400 Message-Id: <20180730042841.32485-1-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Ensure that we always bump or drop the nlink count on the parent directory when we do a mkdir or a rmdir(). This needs to be done by hand as we don't have pre/post op attributes. Signed-off-by: Trond Myklebust --- v2: Fix a typo in nfs4_dec_nlink_locked() fs/nfs/nfs4proc.c | 50 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 5a8190ec31a2..0d56d3662005 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1071,12 +1071,26 @@ int nfs4_call_sync(struct rpc_clnt *clnt, return nfs4_call_sync_sequence(clnt, server, msg, args, res); } -static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, +static void +nfs4_inc_nlink_locked(struct inode *inode) +{ + NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; + inc_nlink(inode); +} + +static void +nfs4_dec_nlink_locked(struct inode *inode) +{ + NFS_I(inode)->cache_validity |= NFS_INO_INVALID_OTHER; + dec_nlink(inode); +} + +static void +update_changeattr_locked(struct inode *dir, struct nfs4_change_info *cinfo, unsigned long timestamp) { struct nfs_inode *nfsi = NFS_I(dir); - spin_lock(&dir->i_lock); nfsi->cache_validity |= NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME | NFS_INO_INVALID_DATA; @@ -1093,6 +1107,14 @@ static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, nfsi->read_cache_jiffies = timestamp; nfsi->attr_gencount = nfs_inc_attr_generation_counter(); nfs_fscache_invalidate(dir); +} + +static void +update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo, + unsigned long timestamp) +{ + spin_lock(&dir->i_lock); + update_changeattr_locked(dir, cinfo, timestamp); spin_unlock(&dir->i_lock); } @@ -4237,7 +4259,8 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, return status; } -static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) +static int +_nfs4_proc_remove(struct inode *dir, const struct qstr *name, u32 ftype) { struct nfs_server *server = NFS_SERVER(dir); struct nfs_removeargs args = { @@ -4256,8 +4279,14 @@ static int _nfs4_proc_remove(struct inode *dir, const struct qstr *name) int status; status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); - if (status == 0) - update_changeattr(dir, &res.cinfo, timestamp); + if (status == 0) { + spin_lock(&dir->i_lock); + update_changeattr_locked(dir, &res.cinfo, timestamp); + /* Removing a directory decrements nlink in the parent */ + if (ftype == NF4DIR && dir->i_nlink > 2) + nfs4_dec_nlink_locked(dir); + spin_unlock(&dir->i_lock); + } return status; } @@ -4274,7 +4303,7 @@ static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) nfs4_inode_make_writeable(inode); } do { - err = _nfs4_proc_remove(dir, &dentry->d_name); + err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG); trace_nfs4_remove(dir, &dentry->d_name, err); err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); @@ -4288,7 +4317,7 @@ static int nfs4_proc_rmdir(struct inode *dir, const struct qstr *name) int err; do { - err = _nfs4_proc_remove(dir, name); + err = _nfs4_proc_remove(dir, name, NF4DIR); trace_nfs4_remove(dir, name, err); err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); @@ -4492,8 +4521,13 @@ static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_ int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg, &data->arg.seq_args, &data->res.seq_res, 1); if (status == 0) { - update_changeattr(dir, &data->res.dir_cinfo, + spin_lock(&dir->i_lock); + update_changeattr_locked(dir, &data->res.dir_cinfo, data->res.fattr->time_start); + /* Creating a directory bumps nlink in the parent */ + if (data->arg.ftype == NF4DIR) + nfs4_inc_nlink_locked(dir); + spin_unlock(&dir->i_lock); status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, data->res.label); } return status;