From patchwork Mon Oct 7 15:45:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benny Halevy X-Patchwork-Id: 2997501 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DBB919F1E1 for ; Mon, 7 Oct 2013 15:45:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 24E10201EA for ; Mon, 7 Oct 2013 15:45:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6EA9320154 for ; Mon, 7 Oct 2013 15:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754457Ab3JGPp2 (ORCPT ); Mon, 7 Oct 2013 11:45:28 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:48052 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751234Ab3JGPp1 (ORCPT ); Mon, 7 Oct 2013 11:45:27 -0400 Received: by mail-wi0-f179.google.com with SMTP id hm2so5073476wib.12 for ; Mon, 07 Oct 2013 08:45:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=e23AMw2tHq3W4r5uvjW+2DG7CIRLBWIEcaIW4ZJIq9M=; b=AA1uxfW1TPDAiepGyrX2bcuBfe3+/6L7GbCnNgFHSyOetZPmiukOkaS/0D1tpy38Jw APDmWm9SK+qyNYo0+ZtIGsqcj8i01XF4FtbKnPZc60AnQrq8ZHO5BWzcj7Gc0fzvlE6h gJ0rDPSLfnv4i54v8iuhMti2zRS5iX2GFoiBmCK4uB8/SwouheqBD0Cah1xJ2hk3q52U sL38cCFYQ98QflJ1+ffjAMUKxdpM1/rNy15HDfv76W3XPqaTQrc//WCCY4VGv9iH7cGL idLly4sZdnUCbQrD5BBqa5Dqnok7YvNqpnIU/pG0vzBvVPlVOiqcv9/zlqHX+IVjhUwS 9fgQ== X-Gm-Message-State: ALoCoQnZetTybyPHjLTIA9K+05azy3WPjIlxW0kN7gWqlGjzHf82xQwa2AjpFukNE7zxX9n1GZ3r X-Received: by 10.194.2.108 with SMTP id 12mr2104127wjt.64.1381160726461; Mon, 07 Oct 2013 08:45:26 -0700 (PDT) Received: from bhalevy-lt.il.tonian.com (bzq-80-49-130.static.bezeqint.net. [82.80.49.130]) by mx.google.com with ESMTPSA id ma3sm40455365wic.1.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 07 Oct 2013 08:45:25 -0700 (PDT) Message-ID: <5252D713.7000004@primarydata.com> Date: Mon, 07 Oct 2013 18:45:23 +0300 From: Benny Halevy User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8 MIME-Version: 1.0 To: linux-nfs@vger.kernel.org CC: Christoph Hellwig , Nadav Shemer Subject: [PATCH v2 2/4] SQUASHME: pnfsd: nfs4_find_create_layout_stateid References: <5251140B.4000203@primarydata.com> <1381045468-30670-1-git-send-email-bhalevy@primarydata.com> In-Reply-To: <1381045468-30670-1-git-send-email-bhalevy@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Split off nfs4_process_layout_stateid functionality for layout get. layout commit and return never allocate a new layout stateid. Signed-off-by: Benny Halevy --- fs/nfsd/nfs4pnfsd.c | 77 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/fs/nfsd/nfs4pnfsd.c b/fs/nfsd/nfs4pnfsd.c index 2b421e0..84f0283 100644 --- a/fs/nfsd/nfs4pnfsd.c +++ b/fs/nfsd/nfs4pnfsd.c @@ -193,23 +193,20 @@ struct sbid_tracker { } /* - * We have looked up the nfs4_file corresponding to the current_fh, and - * confirmed the clientid. Pull the few tests from nfs4_preprocess_stateid_op() - * that make sense with a layout stateid. - * * If the layout state was found in cache, grab a reference count on it; - * otherwise, allocate a new layout state if "do_alloc" is set. + * otherwise, allocate a new layout state if the client provided a open/ + * lock/deleg stateid. * * Called with the state_lock held - * Returns zero and stateid is updated, or error. + * Returns zero and the layout state in *lsp, or error. */ static __be32 -nfs4_process_layout_stateid(struct nfs4_client *clp, struct nfs4_file *fp, - stateid_t *stateid, unsigned char typemask, - struct nfs4_layout_state **lsp) +nfs4_find_create_layout_stateid(struct nfs4_client *clp, struct nfs4_file *fp, + stateid_t *stateid, unsigned char typemask, + struct nfs4_layout_state **lsp) { struct nfs4_layout_state *ls = NULL; - __be32 status = 0; + __be32 status; struct nfs4_stid *stid; dprintk("--> %s clp %p fp %p operation stateid=" STATEID_FMT "\n", @@ -233,13 +230,61 @@ struct sbid_tracker { /* BAD STATEID */ if (stateid->si_generation > ls->ls_stid.sc_stateid.si_generation) { - dprintk("%s bad stateid 1\n", __func__); status = nfserr_bad_stateid; goto out; } get_layout_state(ls); } - status = 0; + + dprintk("%s: layout stateid=" STATEID_FMT " ref=%d\n", __func__, + STATEID_VAL(&ls->ls_stid.sc_stateid), atomic_read(&ls->ls_ref.refcount)); + + *lsp = ls; +out: + dprintk("<-- %s status %d\n", __func__, htonl(status)); + + return status; +} + +/* + * If the layout state was found in cache, grab a reference count on it. + * + * Called with the state_lock held + * Returns zero and the layout state in *lsp, or error. + */ +static __be32 +nfs4_process_layout_stateid(struct nfs4_client *clp, struct nfs4_file *fp, + stateid_t *stateid, unsigned char typemask, + struct nfs4_layout_state **lsp) +{ + struct nfs4_layout_state *ls = NULL; + __be32 status; + struct nfs4_stid *stid; + + dprintk("--> %s clp %p fp %p operation stateid=" STATEID_FMT "\n", + __func__, clp, fp, STATEID_VAL(stateid)); + + nfs4_assert_state_locked(); + status = nfsd4_lookup_stateid(stateid, typemask, &stid, true, + net_generic(clp->net, nfsd_net_id)); + if (status) + goto out; + + /* Is this the first use of this layout ? */ + if (stid->sc_type != NFS4_LAYOUT_STID) { + status = nfserr_bad_stateid; + goto out; + } + + ls = container_of(stid, struct nfs4_layout_state, ls_stid); + + /* BAD STATEID */ + if (stateid->si_generation > ls->ls_stid.sc_stateid.si_generation) { + dprintk("%s bad stateid 1\n", __func__); + status = nfserr_bad_stateid; + goto out; + } + get_layout_state(ls); *lsp = ls; dprintk("%s: layout stateid=" STATEID_FMT " ref=%d\n", __func__, @@ -576,10 +621,10 @@ struct super_block * } /* Check decoded layout stateid */ - nfserr = nfs4_process_layout_stateid(clp, fp, &lgp->lg_sid, - (NFS4_OPEN_STID | NFS4_LOCK_STID | - NFS4_DELEG_STID | NFS4_LAYOUT_STID), - &ls); + nfserr = nfs4_find_create_layout_stateid(clp, fp, &lgp->lg_sid, + (NFS4_OPEN_STID | NFS4_LOCK_STID | + NFS4_DELEG_STID | NFS4_LAYOUT_STID), + &ls); if (nfserr) goto out_unlock;