From patchwork Wed May 30 18:05:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10439533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6FBA8602CC for ; Wed, 30 May 2018 18:06:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CA92290F0 for ; Wed, 30 May 2018 18:06:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50CA6291B0; Wed, 30 May 2018 18:06:34 +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 CF891290F0 for ; Wed, 30 May 2018 18:06:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932130AbeE3SGc (ORCPT ); Wed, 30 May 2018 14:06:32 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:36075 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753659AbeE3SG1 (ORCPT ); Wed, 30 May 2018 14:06:27 -0400 Received: by mail-it0-f66.google.com with SMTP id e20-v6so24660018itc.1 for ; Wed, 30 May 2018 11:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=IIC1FUpVgKnR13S9Aam4viiMnYl+Ah6eTGM4QLoFjUQ=; b=H72y2mfsLtnPYOREMLaWbx8B7OkPnZuJ01JFxSJSlATYDbqUZjV3O3KoYd6ZsPMYbW pn4eSt6MdL5FPjEYIJ9lfdQtzRyw8oTd4+qheP6zbTEeA+o/Bpl1jYBGWXo7OLuO82/w xnSQt8uY4BMqwSUPWA4+EGS61z5yhBQnWFHeSq77Y+X52rntrmCujUAzhLZqPqjcs8Ns 4gGsVRH/Jco5E2DFGUIxgNt5ss7qiAmpY2kfFfEu8lKEeAIoPoTYexG6DuSmuuj2z08B WQOmzUpTscfR/s7Ezw8sew3TmZt4JteUJNSkF3Y7oQ4zl5b0lB+eewU9PujJWOjqKcaL zqWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IIC1FUpVgKnR13S9Aam4viiMnYl+Ah6eTGM4QLoFjUQ=; b=R7lcicAPxr/AGh5QM4qysdWhdWESk3M4epoD7AdR0VL0aiUpUTj2jBiGD6eMo04Qj/ ZgdZEYGyLjVxuRbxeqjCNRbh4yjGXm309IwiDFhTqtKLMwapRgFmsPB1oKYuLfYA5j+W sayC6ggKMgFKx8bllSu/KI8zw4x748atn+ZMqX1loDDM2iRMeBAH7hm7Lyo3uK4RO36U aPshIcVGD5Da+Ya/CQX7npNwc6m/ILVzuyNFjRHJOIy5x4RM2FEhLw2PiVUTsuz5u6dy WuVu6gg+0v5vCurahBIzhMdqsEyIrNqiA8VRj19KrPHW6FzbjYMmMk9/ZZRA1ypBUNqx INBA== X-Gm-Message-State: APt69E2FG1DBmV9b+SoimiLBmSzgmNoY38JsacxVOe6UrOmWsHUP+quF /h0QwjIA2DyyJGUNECQderDNY7w= X-Google-Smtp-Source: ADUXVKIIs7FgC4uER/uzcB2p5uBRpP8Wmxf5WuOyqdLCcNao+RiXB89lv2aK8oroj2+EsfQ796gocQ== X-Received: by 2002:a24:4981:: with SMTP id e1-v6mr2557423itd.86.1527703586127; Wed, 30 May 2018 11:06:26 -0700 (PDT) Received: from leira.trondhjem.org.localdomain (c-68-49-162-121.hsd1.mi.comcast.net. [68.49.162.121]) by smtp.gmail.com with ESMTPSA id i201-v6sm8589368ite.33.2018.05.30.11.06.25 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 May 2018 11:06:25 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 11/19] pnfs: Add LAYOUTGET to OPEN of an existing file Date: Wed, 30 May 2018 14:05:45 -0400 Message-Id: <20180530180553.38769-12-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180530180553.38769-11-trond.myklebust@hammerspace.com> References: <20180530180553.38769-1-trond.myklebust@hammerspace.com> <20180530180553.38769-2-trond.myklebust@hammerspace.com> <20180530180553.38769-3-trond.myklebust@hammerspace.com> <20180530180553.38769-4-trond.myklebust@hammerspace.com> <20180530180553.38769-5-trond.myklebust@hammerspace.com> <20180530180553.38769-6-trond.myklebust@hammerspace.com> <20180530180553.38769-7-trond.myklebust@hammerspace.com> <20180530180553.38769-8-trond.myklebust@hammerspace.com> <20180530180553.38769-9-trond.myklebust@hammerspace.com> <20180530180553.38769-10-trond.myklebust@hammerspace.com> <20180530180553.38769-11-trond.myklebust@hammerspace.com> 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 From: Fred Isaman Signed-off-by: Fred Isaman Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 90 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 17 deletions(-) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index a0a2484c3aed..258b68110277 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -921,9 +921,9 @@ pnfs_find_server(struct inode *inode, struct nfs_open_context *ctx) { struct nfs_server *server; - if (inode) + if (inode) { server = NFS_SERVER(inode); - else { + } else { struct dentry *parent_dir = dget_parent(ctx->dentry); server = NFS_SERVER(parent_dir->d_inode); dput(parent_dir); @@ -1686,6 +1686,22 @@ static void pnfs_clear_first_layoutget(struct pnfs_layout_hdr *lo) wake_up_bit(bitlock, NFS_LAYOUT_FIRST_LAYOUTGET); } +static void _add_to_server_list(struct pnfs_layout_hdr *lo, + struct nfs_server *server) +{ + if (list_empty(&lo->plh_layouts)) { + struct nfs_client *clp = server->nfs_client; + + /* The lo must be on the clp list if there is any + * chance of a CB_LAYOUTRECALL(FILE) coming in. + */ + spin_lock(&clp->cl_lock); + if (list_empty(&lo->plh_layouts)) + list_add_tail(&lo->plh_layouts, &server->layouts); + spin_unlock(&clp->cl_lock); + } +} + /* * Layout segment is retreived from the server if not cached. * The appropriate layout segment is referenced and returned to the caller. @@ -1836,15 +1852,7 @@ pnfs_update_layout(struct inode *ino, atomic_inc(&lo->plh_outstanding); spin_unlock(&ino->i_lock); - if (list_empty(&lo->plh_layouts)) { - /* The lo must be on the clp list if there is any - * chance of a CB_LAYOUTRECALL(FILE) coming in. - */ - spin_lock(&clp->cl_lock); - if (list_empty(&lo->plh_layouts)) - list_add_tail(&lo->plh_layouts, &server->layouts); - spin_unlock(&clp->cl_lock); - } + _add_to_server_list(lo, server); pg_offset = arg.offset & ~PAGE_MASK; if (pg_offset) { @@ -1943,12 +1951,62 @@ pnfs_sanity_check_layout_range(struct pnfs_layout_range *range) return true; } +static struct pnfs_layout_hdr * +_pnfs_grab_empty_layout(struct inode *ino, struct nfs_open_context *ctx) +{ + struct pnfs_layout_hdr *lo; + + spin_lock(&ino->i_lock); + lo = pnfs_find_alloc_layout(ino, ctx, GFP_KERNEL); + if (!lo) + goto out_unlock; + if (!test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags)) + goto out_unlock; + if (test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) + goto out_unlock; + if (pnfs_layoutgets_blocked(lo)) + goto out_unlock; + if (test_and_set_bit(NFS_LAYOUT_FIRST_LAYOUTGET, &lo->plh_flags)) + goto out_unlock; + atomic_inc(&lo->plh_outstanding); + spin_unlock(&ino->i_lock); + _add_to_server_list(lo, NFS_SERVER(ino)); + return lo; + +out_unlock: + spin_unlock(&ino->i_lock); + pnfs_put_layout_hdr(lo); + return NULL; +} + extern const nfs4_stateid current_stateid; static void _lgopen_prepare_attached(struct nfs4_opendata *data, struct nfs_open_context *ctx) { - /* STUB */ + struct inode *ino = data->dentry->d_inode; + struct pnfs_layout_range rng = { + .iomode = (data->o_arg.fmode & FMODE_WRITE) ? + IOMODE_RW: IOMODE_READ, + .offset = 0, + .length = NFS4_MAX_UINT64, + }; + struct nfs4_layoutget *lgp; + struct pnfs_layout_hdr *lo; + + lo = _pnfs_grab_empty_layout(ino, ctx); + if (!lo) + return; + lgp = pnfs_alloc_init_layoutget_args(ino, ctx, ¤t_stateid, + &rng, GFP_KERNEL); + if (!lgp) { + pnfs_clear_first_layoutget(lo); + pnfs_put_layout_hdr(lo); + return; + } + data->lgp = lgp; + data->o_arg.lg_args = &lgp->args; + data->o_res.lg_res = &lgp->res; } static void _lgopen_prepare_floating(struct nfs4_opendata *data, @@ -1996,11 +2054,9 @@ void pnfs_parse_lgopen(struct inode *ino, struct nfs4_layoutget *lgp, if (!lgp || lgp->res.layoutp->len == 0) return; if (!lgp->args.inode) { - /* Need to grab lo */ - spin_lock(&ino->i_lock); - lo = pnfs_find_alloc_layout(ino, ctx, GFP_KERNEL); - atomic_inc(&lo->plh_outstanding); - spin_unlock(&ino->i_lock); + lo = _pnfs_grab_empty_layout(ino, ctx); + if (!lo) + return; lgp->args.inode = ino; } else lo = NFS_I(lgp->args.inode)->layout;