From patchwork Fri Oct 19 15:29:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10649653 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 6A9BF13A4 for ; Fri, 19 Oct 2018 15:29:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A1C627F92 for ; Fri, 19 Oct 2018 15:29:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E96D27F93; Fri, 19 Oct 2018 15:29:27 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 C307527F94 for ; Fri, 19 Oct 2018 15:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726860AbeJSXf6 (ORCPT ); Fri, 19 Oct 2018 19:35:58 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:39200 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbeJSXf6 (ORCPT ); Fri, 19 Oct 2018 19:35:58 -0400 Received: by mail-qt1-f195.google.com with SMTP id e21-v6so2520742qtp.6 for ; Fri, 19 Oct 2018 08:29:23 -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:in-reply-to:references; bh=KKq+uFwhLrZI0Vi9YIIJCW9jp1FWEeolO2gwCwk2llc=; b=dOIwMSR0gD0yPACyt30nlGAMyZarSXr7eUpbwuRwkoXBhJBR4IKaU0iBqWvwYYtchL OtylGjc1GVA8u2e+og8ahB7QkRpewfA0gMEdlyb+VRTUE3ZRauK0fSeC9kc66LkdwbR6 iwI0I00aFf59F9F7I83iCyk0nYcBJU/B4NJ/ogk6hsDUrK7fjQqVRH7tp/5AzP7paRjW WVukm7JpshJXlFcV8WQlbXOLHyt/HRutarce46/PDIVAzz6UOq7VoWv0FuCuP0cZ0h1i tUN7DXw3BT/epJQ4fN5lAR+b0cWPTvJACu6J5m3+7G8/7e23FzIXtSEzskL4Avv5phzE Yf3A== 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; bh=KKq+uFwhLrZI0Vi9YIIJCW9jp1FWEeolO2gwCwk2llc=; b=ZRZysgFy900wGXNQzlbxrxlp0DEobEdpUtNj/DFOfCYex/2nAgUIsT26zIREzDwxxx inqt6YdUc5NjiKpcYhFPFaQykFahbuDGrbyw2KaOXaQ6vgY8GzR+ziqOn77GL9CeW9E5 NpZ9dhckwc9ZpLRsUNYTSp0iuZxW/8efM/65N7vPL8llP3EmzmNx6Xb6SZiuynJMHDf4 m+rKgtErTqY8sP4BHj0gxvxN37NUVUGJxD7sf7EIrMCqJ1hmpc2TAWYmSv3tGhT4c73t jWf52Pn/jd/ss0gr1iQRDkkuLd1BW69QKkikUZYAuc39VqVRHigIhJzKIUErcc3v/jcu IKBg== X-Gm-Message-State: ABuFfoikvX9uWqWaza7i9Rmp+xd+yy4hqlpKNCaRHoRsaumFMCcm32+j qkO1EaTLpJD/9P17n+RqXTY= X-Google-Smtp-Source: ACcGV62xSfXV0ASCpZ5uQcV7iEd7jcUiuYRPMw0ouML1UX5kX0/2Q9WGKZ3xX+cIBi3UX1Fcd6S3RQ== X-Received: by 2002:aed:25d1:: with SMTP id y17-v6mr33198369qtc.217.1539962962728; Fri, 19 Oct 2018 08:29:22 -0700 (PDT) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id s17-v6sm18126231qtj.31.2018.10.19.08.29.21 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Oct 2018 08:29:21 -0700 (PDT) From: Olga Kornievskaia To: bfields@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v1 10/13] NFSD check stateids against copy stateids Date: Fri, 19 Oct 2018 11:29:02 -0400 Message-Id: <20181019152905.32418-11-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20181019152905.32418-1-olga.kornievskaia@gmail.com> References: <20181019152905.32418-1-olga.kornievskaia@gmail.com> 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: Olga Kornievskaia Incoming stateid (used by a READ) could be a saved copy stateid. On first use make it active and check that the copy has started within the allowable lease time. Signed-off-by: Olga Kornievskaia --- fs/nfsd/nfs4state.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 7764a8b..16359de 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -5206,6 +5206,47 @@ static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) return 0; } +/* + * A READ from an inter server to server COPY will have a + * copy stateid. Return the parent nfs4_stid. + */ +static __be32 _find_cpntf_state(struct nfsd_net *nn, stateid_t *st, + struct nfs4_cpntf_state **cps) +{ + struct nfs4_cpntf_state *state = NULL; + + if (st->si_opaque.so_clid.cl_id != nn->s2s_cp_cl_id) + return nfserr_bad_stateid; + spin_lock(&nn->s2s_cp_lock); + state = idr_find(&nn->s2s_cp_stateids, st->si_opaque.so_id); + spin_unlock(&nn->s2s_cp_lock); + if (!state) + return nfserr_bad_stateid; + *cps = state; + return 0; +} + +static __be32 find_cpntf_state(struct nfsd_net *nn, stateid_t *st, + struct nfs4_stid **stid) +{ + __be32 status; + struct nfs4_cpntf_state *cps = NULL; + + status = _find_cpntf_state(nn, st, &cps); + if (status) + return status; + + /* Did the inter server to server copy start in time? */ + if (cps->cp_active == false && !time_after(cps->cp_timeout, jiffies)) + return nfserr_partner_no_auth; + else + cps->cp_active = true; + + *stid = cps->cp_p_stid; + refcount_inc(&cps->cp_p_stid->sc_count); + + return nfs_ok; +} /* * Checks for stateid operations @@ -5238,6 +5279,8 @@ static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid) status = nfsd4_lookup_stateid(cstate, stateid, NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID, &s, nn); + if (status == nfserr_bad_stateid) + status = find_cpntf_state(nn, stateid, &s); if (status) return status; status = nfsd4_stid_check_stateid_generation(stateid, s,