From patchwork Sun Oct 6 07:44:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benny Halevy X-Patchwork-Id: 2992531 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 39E749F2B8 for ; Sun, 6 Oct 2013 07:44:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6725D201FA for ; Sun, 6 Oct 2013 07:44:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93328201EC for ; Sun, 6 Oct 2013 07:44:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751404Ab3JFHoc (ORCPT ); Sun, 6 Oct 2013 03:44:32 -0400 Received: from mail-ee0-f47.google.com ([74.125.83.47]:40520 "EHLO mail-ee0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751373Ab3JFHoc (ORCPT ); Sun, 6 Oct 2013 03:44:32 -0400 Received: by mail-ee0-f47.google.com with SMTP id d49so2551108eek.6 for ; Sun, 06 Oct 2013 00:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=K9MNmEO5C2huWZSNM1nw8O3BGUg5F6nCfBOCZajqz9o=; b=e1c5cgwuzAw76rWkGvSviN7BlZYlCtu6EgjZqUG+kpjZttrObd8gCUykC+R21wO8s1 lCUW6hxzbdh2EwwMTqJKkcKqL5wOr5kyO5nlJ87QepeNTjyywDTkDxX7vPvb1ixsupsO Z70KNJhE/q4iK7sY8CefLCo93zsgAX8xCKUjuXFlTC/sjbMDX8ac2oqHa6+CAx9uLJNY F+uJosKFVAL5gaZfJUZkLODiZ9ssCfrW6em5k6EVoENKrGBWN/wJLrV2yLuTO5jzZ5cd 1Q6JdcWEW9e2naVDzQdyjxtRyArlt+ETViuWGvx0Ggy0yCIFDNRLCMlIQgS9X8/Wb73z +0MA== X-Received: by 10.14.194.131 with SMTP id m3mr1450145een.45.1381045471280; Sun, 06 Oct 2013 00:44:31 -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 a6sm48371606eei.10.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 06 Oct 2013 00:44:30 -0700 (PDT) From: Benny Halevy To: linux-nfs@vger.kernel.org Subject: [PATCH 2/4] SQUASHME: pnfsd: nfs4_find_create_layout_stateid Date: Sun, 6 Oct 2013 10:44:28 +0300 Message-Id: <1381045468-30670-1-git-send-email-bhalevy@primarydata.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <5251140B.4000203@primarydata.com> References: <5251140B.4000203@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=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 | 62 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4pnfsd.c b/fs/nfsd/nfs4pnfsd.c index a9e535f..c00eb03 100644 --- a/fs/nfsd/nfs4pnfsd.c +++ b/fs/nfsd/nfs4pnfsd.c @@ -199,6 +199,60 @@ struct sbid_tracker { } /* + * 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. + * + * Called with the state_lock held + * Returns zero and the layout state in *lsp, or error. + */ +static __be32 +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; + 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) { + ls = alloc_init_layout_state(clp, fp, stateid); + if (!ls) { + status = nfserr_jukebox; + goto out; + } + } else { + ls = container_of(stid, struct nfs4_layout_state, ls_stid); + + /* BAD STATEID */ + if (stateid->si_generation > ls->ls_stid.sc_stateid.si_generation) { + 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; +} + +/* * 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. @@ -776,10 +830,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;