Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7760334ybi; Mon, 22 Jul 2019 20:11:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6JhxMWUf+YQ++WoyZ1vE4FB1yVVgcdgnHo5oCMrfiIJuuaFLr4PTrRFXIu3PfIMqp4YAk X-Received: by 2002:aa7:9210:: with SMTP id 16mr3541492pfo.11.1563851469275; Mon, 22 Jul 2019 20:11:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563851469; cv=none; d=google.com; s=arc-20160816; b=NpQIx/VBiy7GwZyAeGRSRF/08E4fepqxXgjOdwbkoy3MUFndNEH4MnRNn1tg8xUrtw 8nlonF5Yt29OQ0k1vQ54+hPdEqGmkOsLxWSZkd+ju3nS3d7ZR/QSgZZPk0c0aujTK/6N R9oZvAZhXKjSbgA9b2lb3F/I5JVwTa/LjNHuy9/bs+fzyPmGboQe7iW8mj3bIXkzBSOR roZUoUFABTswo/+ro33jEl6Vz95i6Nsxo+6Vadd2MtrE8TQuIV3ZCCS6QlnmqapZjzTD Txw5yB9lBtdiX0aP0wF9l0U1xxSJXQL3retQiaxywY7lMZ8OZExAQssWIA3Fyfn92a8j u+6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=OyLY8vZGbNtKNzk8EZ6eo74FGjMtzBY30Su26WbZ/H4=; b=s/9ywkaXqFAlPwAmb/AWxAo74bkcoyf85YXuN753ZFjGaMxjBzevlN3refCrR3ao9F ILcDqWCbwrSRcfgo0dXuBHLm2iS/PcB0WqEjYqY0v2ZumZAa5qBeYNtzZNtd3npxUqgW EDWlfPIVXHf7KYhHASNcv8Mp+EXiMLR3QXchvXDPAOdaa+JwdxtSRigXoquWqN8cW6x4 UeMGr5FVjAIi6u+W8hwr5vMAK7alsjhxBLCxYTuq0bYJcXxacffvewmRP0GC8RFvIiXS 80TTGb9kwFBI+4r0GKNdeJkO6L7vR95pIDSJWjwnov3iDnShijDECwfJ7X5f9Mq3OCwn SEFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="odKgsY/Q"; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r145si10180992pgr.553.2019.07.22.20.10.55; Mon, 22 Jul 2019 20:11:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="odKgsY/Q"; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729899AbfGVUYU (ORCPT + 99 others); Mon, 22 Jul 2019 16:24:20 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:33497 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729621AbfGVUYU (ORCPT ); Mon, 22 Jul 2019 16:24:20 -0400 Received: by mail-vs1-f66.google.com with SMTP id m8so27313137vsj.0 for ; Mon, 22 Jul 2019 13:24:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OyLY8vZGbNtKNzk8EZ6eo74FGjMtzBY30Su26WbZ/H4=; b=odKgsY/QIZDZ5z3Y0eRLl+oZ2H4jEjjtvXQtxfEuNd6oPqPQEN8kY1gSaMaAuiUwqs Wk46znlogXhsoV2FCet4Xz3WmM3vcerYzoTzFYP3M3p9i2kSmFKsD7QKU6VBKGOviXD1 NeJBBsokUvTZRCFC2szqlHEhmGSWfYpzoJlPncUlsSTLSX3O53dHgUFhqC66yu+kKIOp Ue3jqTJa5A2/ehjk6ytxJV5ETxIfEGKRioSydOVmiFB+ZLBKC0U/vrS2JocgiXJS83h0 EmZAaqz08K/dcGTQjnlama+KCnnDqQZV0hLLOdT2YmyT+/xC7H9tF7gb+SW4KpwQfhJy 16rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OyLY8vZGbNtKNzk8EZ6eo74FGjMtzBY30Su26WbZ/H4=; b=k+A0z4N0hbbbmbTYiEfGnivB9d7EW/wwUz9ufGw86KVDV3AxlJ7xkiSgLKKfTaNJYk hjQd3avCp5nxBqEz7YpSp/ngPYtXNTPe7h0yhKp8b+jbTG3zKTmNqtd5TWF+Bwb30vf3 yKhCKnTcSHsT2p1G1ZbhsACk2x38JoAEj49XTOFxDgqRvr8lMR06H1O6PpAVsx03hQqS fUH/zx9HeBJymnWBQofwnzVcXAzT/S7JrxDdrkrqDvDdJtLfsaVf9Mz9Endh2SQAegD0 pdeNk9Sx5X7A7oQOJX4dnP2zYSK8ZSPA5UaTOFlwDLNes7FDoV8/EXc4p/k77hqR+Vit TiDw== X-Gm-Message-State: APjAAAWAkvATeZodd2d16S+oSiysR0/IwnUqr7C99qKWvVLu1A9eKPdb RCjw+CknvKVa7XCFLkHFK0WatTTx/L6+iQXvSS4= X-Received: by 2002:a67:79d4:: with SMTP id u203mr43895414vsc.85.1563827059016; Mon, 22 Jul 2019 13:24:19 -0700 (PDT) MIME-Version: 1.0 References: <20190708192352.12614-1-olga.kornievskaia@gmail.com> <20190708192352.12614-6-olga.kornievskaia@gmail.com> <20190719220116.GA24373@fieldses.org> In-Reply-To: <20190719220116.GA24373@fieldses.org> From: Olga Kornievskaia Date: Mon, 22 Jul 2019 16:24:08 -0400 Message-ID: Subject: Re: [PATCH v4 5/8] NFSD check stateids against copy stateids To: "J. Bruce Fields" Cc: "J. Bruce Fields" , linux-nfs Content-Type: text/plain; charset="UTF-8" Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Fri, Jul 19, 2019 at 6:01 PM J. Bruce Fields wrote: > > On Mon, Jul 08, 2019 at 03:23:49PM -0400, Olga Kornievskaia wrote: > > 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 | 45 +++++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 45 insertions(+) > > > > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c > > index 2555eb9..b786625 100644 > > --- a/fs/nfsd/nfs4state.c > > +++ b/fs/nfsd/nfs4state.c > > @@ -5232,6 +5232,49 @@ 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); > > + if (state) > > + refcount_inc(&state->cp_p_stid->sc_count); > > + 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)) { > > + nfs4_put_stid(cps->cp_p_stid); > > + return nfserr_partner_no_auth; > > I wonder whether instead of checking the time we should instead be > destroying copy stateid's as they expire, so the fact that you were > still able to look up the stateid suggests that it's good. Or would > that result in returning the wrong error here? Just curious. In order to destroy copy stateid as they expire we need some thread monitoring the copies and then remove the expired one. That seems like a lot more work than what's currently there. The spec says that the use of the copy has to start without a certain timeout and that's what this is suppose to enforce. If the client took too long start the copy, it'll get an error. I don't think it matters what error code is returned BAD_STATEID or PARTNER_NO_AUTH both imply the stateid is bad. > > > + } else > > + cps->cp_active = true; > > + > > + *stid = cps->cp_p_stid; > > What guarantees that cp_p_stid still points to a valid stateid? (E.g. > if this is an open stateid that has since been closed.) A copy (or copy_notify) stateid takes a reference on the parent, thus we guaranteed that pointer is still a valid stateid. > > --b. > > > + > > + return nfs_ok; > > +} > > > > /* > > * Checks for stateid operations > > @@ -5264,6 +5307,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, > > -- > > 1.8.3.1