From patchwork Fri Sep 20 11:23:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11154243 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEBE117E6 for ; Fri, 20 Sep 2019 11:25:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CD8AC205F4 for ; Fri, 20 Sep 2019 11:25:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MEIPtDdA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438178AbfITLZ7 (ORCPT ); Fri, 20 Sep 2019 07:25:59 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:35193 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438173AbfITLZ7 (ORCPT ); Fri, 20 Sep 2019 07:25:59 -0400 Received: by mail-io1-f66.google.com with SMTP id q10so15380273iop.2 for ; Fri, 20 Sep 2019 04:25:58 -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 :mime-version:content-transfer-encoding; bh=u+xAWTrh/Lsv4sQba0rlaTvUNAip8h2KHmmPmv3mJ88=; b=MEIPtDdAe69WuPjgv8mb5KS2Nj91HiHM7X/fNwxDpzOl2yVJnmopDhGCfIdaqH1ods 0zqq3V1dJYVz+jQcuEA00Jo0GoSVYu1RseEF1q1OrwH+fFati7IcM+woA3i0HPHz68P+ vXqoIw2yz4mwsMR5ns+0e4LbgQASlreSwdnfEP9HoHRdB2GW3IoDV9CFcqaA/sFFDzrO PMKu00F4Php/b2WSHMc/3e0RzC0NqECFQ4a8aetc/bV8ARFQLN4Km5z+VI/TwK1YVfGC eo7y2MTlnd3sGUTJyqNcRMqbVYjRndQijRonLh89ZMynxNCJ7WEgLBagIG+wpFXcSxJW zdKg== 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:mime-version:content-transfer-encoding; bh=u+xAWTrh/Lsv4sQba0rlaTvUNAip8h2KHmmPmv3mJ88=; b=uUE/0R5QsfuM/CtfGdvfyKLm+hgFnyL2eLq/2LFlnmWkPodb7Lxv+Jq0C1HHzFTdgq ztsA/qvfpRT/1pqwY7jykN2aYqtw3nKgXj/NKezXEewFBs8sgk1WuE8qbB+WmgeeF4zP HuV7jzG+PgggBqQSY6R/kRPrCdLlH7YmhP9ZjhK7W7tB89KQJtBiGj2N3Im7QXpPxBye KmVoV/MAOBqCL/MUL0e7V27BGjM3ic7laoLdbdRlaeW74GXT8h0enjZ55x0ZHGafXCnY jUIkNlj6543hUyHz7gR4ByCLMjEs6ppVqRrHZpDTZviOtD86w/uNY2++q67qNfDYngl7 6Niw== X-Gm-Message-State: APjAAAVKvFhroHHNhoK1GiGb54RpeYUlOolRR1JFF8FH6vTlUtJfpR0u aFqZBsDahzTIaGY8emb4Qw== X-Google-Smtp-Source: APXvYqy60NN9T4al6mcSVmrGPUUn1jbaxNJmyfs4sWpX/Ay69eg+v9LejHvFRrKdkcM4d/+6JhXx2A== X-Received: by 2002:a02:c787:: with SMTP id n7mr19292465jao.91.1568978758189; Fri, 20 Sep 2019 04:25:58 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id q74sm1308736iod.72.2019.09.20.04.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 04:25:57 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v3 1/9] pNFS: Ensure we do clear the return-on-close layout stateid on fatal errors Date: Fri, 20 Sep 2019 07:23:40 -0400 Message-Id: <20190920112348.69496-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190920112348.69496-1-trond.myklebust@hammerspace.com> References: <20190920112348.69496-1-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 IF the server rejected our layout return with a state error such as NFS4ERR_BAD_STATEID, or even a stale inode error, then we do want to clear out all the remaining layout segments and mark that stateid as invalid. Fixes: 1c5bd76d17cca ("pNFS: Enable layoutreturn operation for...") Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 4525d5acae38..0418b198edd3 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1449,10 +1449,15 @@ void pnfs_roc_release(struct nfs4_layoutreturn_args *args, const nfs4_stateid *res_stateid = NULL; struct nfs4_xdr_opaque_data *ld_private = args->ld_private; - if (ret == 0) { - arg_stateid = &args->stateid; + switch (ret) { + case -NFS4ERR_NOMATCHING_LAYOUT: + break; + case 0: if (res->lrs_present) res_stateid = &res->stateid; + /* Fallthrough */ + default: + arg_stateid = &args->stateid; } pnfs_layoutreturn_free_lsegs(lo, arg_stateid, &args->range, res_stateid); From patchwork Fri Sep 20 11:23:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11154247 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B48217E6 for ; Fri, 20 Sep 2019 11:26:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 49F22208C0 for ; Fri, 20 Sep 2019 11:26:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Yh3Qt4iC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438182AbfITL0H (ORCPT ); Fri, 20 Sep 2019 07:26:07 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:35918 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438173AbfITL0H (ORCPT ); Fri, 20 Sep 2019 07:26:07 -0400 Received: by mail-io1-f67.google.com with SMTP id b136so15345300iof.3 for ; Fri, 20 Sep 2019 04:26:06 -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 :mime-version:content-transfer-encoding; bh=NYN5Bd9Dd0vS7p9p+LtozvKO/VbaMtj9Dt0A4GBDoyM=; b=Yh3Qt4iC4zFQvXnJpNf/DmG6PuYMkGE30iHAQUbPfkYbyTvWwH/ZY1qxQdtrLLY4b0 +vd8Um3hbhXCxPtkIsl7tmRDbIGTA88T7w2Iq4dGH1VI/rC9eSINAAL6p7ckiGUL8eYv /6Q3GA2VYOIG4Yew/SxoJl+W54x5jMe9OUeTidnVrmAyiZqjBd+U778WZOVZKBUKVzka xq2h9jZNzzRRFXKsY3J9sHRC5j3c4TvXWKtZWfnAQ2O8xL/DmxcqiY8J0gbvLkUf/shc 1SuzwexcA4Tq4krigR5C6pJ8G1j4Cmon2VrkfTK66oDFWYGmsd0nM3T/h1R5pXjHuLqN /glw== 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:mime-version:content-transfer-encoding; bh=NYN5Bd9Dd0vS7p9p+LtozvKO/VbaMtj9Dt0A4GBDoyM=; b=AJoZ2T3GvoZO3PY1XRenfM4SiI9SmVUii8mW2OYBqXMIn4/e9vzHCRcgyMOYhyHFps izxoIROKblapofJ5cdqqwAKx7MBMd4gA4l7LHXLEW3mx0Yp7JBhgd+YXsBqsT8kdcqaS lnKxOACDZzD5QEiG03PUMC33M1raGU5H0fsALO0ioZAGy/JqLi1K3NBnFKOCxWCvqt9o aoWo584bX/CxxR2OD2UX38fPy4LnEMZRIFb2UzEsvoYxhiFH+nRy8zRXzQUtSvHCzTFI Ug9jppXEWDYgLkRJyLsONxBgQ21+zlKlxT7UvElWQWqiYnh1xEbNDB5wvqwDA+WaPFCb dnxg== X-Gm-Message-State: APjAAAWNivsIVzw29YDRSJCvllyUY0Q9TadOChWc9oGcbfjUFxSp056k hrp4G+1KbC8HVmSK9lGMug== X-Google-Smtp-Source: APXvYqz7bWHJsbeVCOcGjStlMHyAEEc/gsOb60BLIAf1OYdVkqYjm1L7V4mLDadzb4SpOFCsQS6Xhw== X-Received: by 2002:a6b:8d90:: with SMTP id p138mr19836391iod.176.1568978759188; Fri, 20 Sep 2019 04:25:59 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id q74sm1308736iod.72.2019.09.20.04.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 04:25:58 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v3 2/9] NFSv4: Clean up pNFS return-on-close error handling Date: Fri, 20 Sep 2019 07:23:41 -0400 Message-Id: <20190920112348.69496-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190920112348.69496-2-trond.myklebust@hammerspace.com> References: <20190920112348.69496-1-trond.myklebust@hammerspace.com> <20190920112348.69496-2-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 Both close and delegreturn have identical code to handle pNFS return-on-close. This patch refactors that code and places it in pnfs.c Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 66 +++++++---------------------------------------- fs/nfs/pnfs.c | 27 +++++++++++++++++++ fs/nfs/pnfs.h | 13 ++++++++++ 3 files changed, 50 insertions(+), 56 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 1406858bae6c..fcdfddfd3ab4 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -3358,32 +3358,11 @@ static void nfs4_close_done(struct rpc_task *task, void *data) trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status); /* Handle Layoutreturn errors */ - if (calldata->arg.lr_args && task->tk_status != 0) { - switch (calldata->res.lr_ret) { - default: - calldata->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; - break; - case 0: - calldata->arg.lr_args = NULL; - calldata->res.lr_res = NULL; - break; - case -NFS4ERR_OLD_STATEID: - if (nfs4_layoutreturn_refresh_stateid(&calldata->arg.lr_args->stateid, - &calldata->arg.lr_args->range, - calldata->inode)) - goto lr_restart; - /* Fallthrough */ - case -NFS4ERR_ADMIN_REVOKED: - case -NFS4ERR_DELEG_REVOKED: - case -NFS4ERR_EXPIRED: - case -NFS4ERR_BAD_STATEID: - case -NFS4ERR_UNKNOWN_LAYOUTTYPE: - case -NFS4ERR_WRONG_CRED: - calldata->arg.lr_args = NULL; - calldata->res.lr_res = NULL; - goto lr_restart; - } - } + if (pnfs_roc_done(task, calldata->inode, + &calldata->arg.lr_args, + &calldata->res.lr_res, + &calldata->res.lr_ret) == -EAGAIN) + goto out_restart; /* hmm. we are done with the inode, and in the process of freeing * the state_owner. we keep this around to process errors @@ -3430,8 +3409,6 @@ static void nfs4_close_done(struct rpc_task *task, void *data) nfs_refresh_inode(calldata->inode, &calldata->fattr); dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); return; -lr_restart: - calldata->res.lr_ret = 0; out_restart: task->tk_status = 0; rpc_restart_call_prepare(task); @@ -6129,32 +6106,11 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status); /* Handle Layoutreturn errors */ - if (data->args.lr_args && task->tk_status != 0) { - switch(data->res.lr_ret) { - default: - data->res.lr_ret = -NFS4ERR_NOMATCHING_LAYOUT; - break; - case 0: - data->args.lr_args = NULL; - data->res.lr_res = NULL; - break; - case -NFS4ERR_OLD_STATEID: - if (nfs4_layoutreturn_refresh_stateid(&data->args.lr_args->stateid, - &data->args.lr_args->range, - data->inode)) - goto lr_restart; - /* Fallthrough */ - case -NFS4ERR_ADMIN_REVOKED: - case -NFS4ERR_DELEG_REVOKED: - case -NFS4ERR_EXPIRED: - case -NFS4ERR_BAD_STATEID: - case -NFS4ERR_UNKNOWN_LAYOUTTYPE: - case -NFS4ERR_WRONG_CRED: - data->args.lr_args = NULL; - data->res.lr_res = NULL; - goto lr_restart; - } - } + if (pnfs_roc_done(task, data->inode, + &data->args.lr_args, + &data->res.lr_res, + &data->res.lr_ret) == -EAGAIN) + goto out_restart; switch (task->tk_status) { case 0: @@ -6192,8 +6148,6 @@ static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) } data->rpc_status = task->tk_status; return; -lr_restart: - data->res.lr_ret = 0; out_restart: task->tk_status = 0; rpc_restart_call_prepare(task); diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 0418b198edd3..8769422a12f5 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1440,6 +1440,33 @@ bool pnfs_roc(struct inode *ino, return false; } +int pnfs_roc_done(struct rpc_task *task, struct inode *inode, + struct nfs4_layoutreturn_args **argpp, + struct nfs4_layoutreturn_res **respp, + int *ret) +{ + struct nfs4_layoutreturn_args *arg = *argpp; + int retval = -EAGAIN; + + if (!arg) + return 0; + /* Handle Layoutreturn errors */ + switch (*ret) { + case 0: + retval = 0; + break; + case -NFS4ERR_OLD_STATEID: + if (!nfs4_layoutreturn_refresh_stateid(&arg->stateid, + &arg->range, inode)) + break; + *ret = -NFS4ERR_NOMATCHING_LAYOUT; + return -EAGAIN; + } + *argpp = NULL; + *respp = NULL; + return retval; +} + void pnfs_roc_release(struct nfs4_layoutreturn_args *args, struct nfs4_layoutreturn_res *res, int ret) diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h index f15609c003d8..3ef3756d437c 100644 --- a/fs/nfs/pnfs.h +++ b/fs/nfs/pnfs.h @@ -282,6 +282,10 @@ bool pnfs_roc(struct inode *ino, struct nfs4_layoutreturn_args *args, struct nfs4_layoutreturn_res *res, const struct cred *cred); +int pnfs_roc_done(struct rpc_task *task, struct inode *inode, + struct nfs4_layoutreturn_args **argpp, + struct nfs4_layoutreturn_res **respp, + int *ret); void pnfs_roc_release(struct nfs4_layoutreturn_args *args, struct nfs4_layoutreturn_res *res, int ret); @@ -701,6 +705,15 @@ pnfs_roc(struct inode *ino, return false; } +static inline int +pnfs_roc_done(struct rpc_task *task, struct inode *inode, + struct nfs4_layoutreturn_args **argpp, + struct nfs4_layoutreturn_res **respp, + int *ret) +{ + return 0; +} + static inline void pnfs_roc_release(struct nfs4_layoutreturn_args *args, struct nfs4_layoutreturn_res *res, From patchwork Fri Sep 20 11:23:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11154245 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A64A14ED for ; Fri, 20 Sep 2019 11:26:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 18EA6208C0 for ; Fri, 20 Sep 2019 11:26:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sYjAxxLp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438180AbfITL0H (ORCPT ); Fri, 20 Sep 2019 07:26:07 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:40436 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438179AbfITL0H (ORCPT ); Fri, 20 Sep 2019 07:26:07 -0400 Received: by mail-io1-f65.google.com with SMTP id h144so15276858iof.7 for ; Fri, 20 Sep 2019 04:26:07 -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 :mime-version:content-transfer-encoding; bh=J/GVnqkPBoCv5U4dJF5GCvANtn9QnHDChOd9TrjN6yM=; b=sYjAxxLpC/LlUJ+bj3BSCbHLMivh+PBEPoG59tTC+BZIdR+GLdv1QHKTYFbri8sWlD hGqzitV0A6NXGLgL+gDuVy+VB1EoWvaMgPMiqt/Mxmz4ERT51bRp3jH/P5S10cnqSvkZ f50QazNDGpccN6izCkUaoo6SmfJ4bWmMHkEC0uEkkno37oDxWwI5XJUtuTRrgBC4heIs Vf0pdTZ4e6ukVqm7AAsBQjCAWav3vp5tIIh3QWP5CFsFJqwALea/XAsXgJQTDKzSxMAa pcYl+flUnLr2OF2o4I+IHvel8Wjpuo9+GbjvvkalwMZr3W38MP2Q8WDQDYYfwLbP4+NU kGaA== 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:mime-version:content-transfer-encoding; bh=J/GVnqkPBoCv5U4dJF5GCvANtn9QnHDChOd9TrjN6yM=; b=QKHuvYzNbllEmPPtI61AxQVMfPsRA3ssktWEGhOGThxQqMgdeYLFDCvlEC7Mpcw+mo fceRNbGSe9S9LuMNKkRgVPcnCxDe7+xVTRqR+ndg+9kcWh1118RUVzi+2iaYgAeQmyQG R9ddNU+B6u1V0ceqOGyu+oa+Nal6ZpF/kzVGZvICZbPYVW01YHVz/6kOHTuud/+rHw4v tCeQTAT608pYgi5UY6UKuOdKrfavY7nUpzceRzhW080dr3go1CHon0liQSD7nuixoOT0 H4aJkf9zv4YJlkPMlD/bxjMZ5pfNQ3INskQZmqhqqISLhig2rmpMGWPRBnCCio16fOp2 gvyQ== X-Gm-Message-State: APjAAAWL9Xaihe69GbJobIR+eDG7SjgbmJ8ly0tteHDio3l9hFN/AZ4S cQlMxPw9d3YVWBGKibw8QA== X-Google-Smtp-Source: APXvYqyaRoi/XdiVjra3MX6cYTtq/I70T7eOCUTG3advkWgwJSGMyfoDhHR0JwMNRN+gLZ1wzi7emg== X-Received: by 2002:a6b:1606:: with SMTP id 6mr20043034iow.108.1568978766426; Fri, 20 Sep 2019 04:26:06 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id q74sm1308736iod.72.2019.09.20.04.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 04:26:05 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v3 3/9] NFSv4: Handle NFS4ERR_DELAY correctly in return-on-close Date: Fri, 20 Sep 2019 07:23:42 -0400 Message-Id: <20190920112348.69496-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190920112348.69496-3-trond.myklebust@hammerspace.com> References: <20190920112348.69496-1-trond.myklebust@hammerspace.com> <20190920112348.69496-2-trond.myklebust@hammerspace.com> <20190920112348.69496-3-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 If the server sends a NFS4ERR_DELAY, then allow the caller to retry. Signed-off-by: Trond Myklebust --- fs/nfs/pnfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 8769422a12f5..6436047dc999 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1455,6 +1455,10 @@ int pnfs_roc_done(struct rpc_task *task, struct inode *inode, case 0: retval = 0; break; + case -NFS4ERR_DELAY: + /* Let the caller handle the retry */ + *ret = -NFS4ERR_NOMATCHING_LAYOUT; + return 0; case -NFS4ERR_OLD_STATEID: if (!nfs4_layoutreturn_refresh_stateid(&arg->stateid, &arg->range, inode)) From patchwork Fri Sep 20 11:23:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11154249 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3E6D14ED for ; Fri, 20 Sep 2019 11:26:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1DE2205F4 for ; Fri, 20 Sep 2019 11:26:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L0hcTQax" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438173AbfITL0I (ORCPT ); Fri, 20 Sep 2019 07:26:08 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:38073 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438179AbfITL0I (ORCPT ); Fri, 20 Sep 2019 07:26:08 -0400 Received: by mail-io1-f67.google.com with SMTP id k5so15323192iol.5 for ; Fri, 20 Sep 2019 04:26:07 -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 :mime-version:content-transfer-encoding; bh=mT/Rzj/K1U6LEdiuCQ0lI11+dkVn7b9E0XXmRpME0Iw=; b=L0hcTQaxV8tWoYW+YxfWvV652jMyLbKAjaRxV1Yn1a2PNN0bAn+CrM6haVrz1rrB7C NkIiFUUATU+H6s0Ro70G/R0HD6mLM2ddrLlznOOj1mqwRdP+ZMtsH1bDQiSYdDFkJGPG 5qCDctlZ+lNvaR9/WTuScAyhT8aVOGkE+F8jH6OfDMa9SOrdOC2liBQ7K0z38ZWk07tg GEsHDIrc3z4O9r8ZxxrvPy4nzSt6hMwSb090QCCX1vHGIKIpZtB4KkBbdY2ZyX6SgTvt /+u6hqWTdq4wjLUjIpusCTNPsex280T7OvCJtm3bdUvGnEblS2HzXS09bko+rKbp+EcD /UaQ== 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:mime-version:content-transfer-encoding; bh=mT/Rzj/K1U6LEdiuCQ0lI11+dkVn7b9E0XXmRpME0Iw=; b=FGFAnuPTKwM0hVZSQuLAS/PE1R1VBdgujpV5cexHToGcZWiNpjzFfyuxb7Azab4/MJ I6UqRyUVXcfsBlFuNGyeHDiejO0QvpVCM6xko+reCtWNY+RpH1tH98bxxyxPAGRzToVz DpNYALFS5OYayz4nvzrpcgisEBrJO8C+jnzQfSRSFrlgzM6qrRv9eMo3beSqyrMnIqzX ZeLDC2D8jj++f9DWlqn/H4iDWq876Z+izzl4Oa5eQAAR0TaYyWpDQSm68OzEgafrGuts GuyKxPBNYlo0umWafb3vzfBoeQsE1fYAOt2P44UbvRglio0u4XqxZyyQqk/c7DMCKSds igrQ== X-Gm-Message-State: APjAAAUAy1oD1CYa6FU2sEWNKkhQm3dlYaLjU9qaZnJbifcvFVgNi5tO RypVos+jQ7+IUsgR4iVQNFomPpfTtw== X-Google-Smtp-Source: APXvYqz4dbuW1lrZ0hrHtY6UP7e0JWsA8yXBOVTpveDWwkgIPtFfYB0lUNRsjJmK2WLDcFnNJck/Ow== X-Received: by 2002:a5e:9319:: with SMTP id k25mr19119010iom.290.1568978767125; Fri, 20 Sep 2019 04:26:07 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id q74sm1308736iod.72.2019.09.20.04.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 04:26:06 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v3 4/9] NFSv4: Handle RPC level errors in LAYOUTRETURN Date: Fri, 20 Sep 2019 07:23:43 -0400 Message-Id: <20190920112348.69496-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190920112348.69496-4-trond.myklebust@hammerspace.com> References: <20190920112348.69496-1-trond.myklebust@hammerspace.com> <20190920112348.69496-2-trond.myklebust@hammerspace.com> <20190920112348.69496-3-trond.myklebust@hammerspace.com> <20190920112348.69496-4-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 Handle RPC level errors by assuming that the RPC call was successful. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 9 +++++++++ fs/nfs/pnfs.c | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index fcdfddfd3ab4..a5deb00b5ad1 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -9057,6 +9057,15 @@ static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) if (!nfs41_sequence_process(task, &lrp->res.seq_res)) return; + /* + * Was there an RPC level error? Assume the call succeeded, + * and that we need to release the layout + */ + if (task->tk_rpc_status != 0 && RPC_WAS_SENT(task)) { + lrp->res.lrs_present = 0; + return; + } + server = NFS_SERVER(lrp->args.inode); switch (task->tk_status) { case -NFS4ERR_OLD_STATEID: diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 6436047dc999..abc7188f1853 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1455,6 +1455,21 @@ int pnfs_roc_done(struct rpc_task *task, struct inode *inode, case 0: retval = 0; break; + case -NFS4ERR_NOMATCHING_LAYOUT: + /* Was there an RPC level error? If not, retry */ + if (task->tk_rpc_status == 0) + break; + /* If the call was not sent, let caller handle it */ + if (!RPC_WAS_SENT(task)) + return 0; + /* + * Otherwise, assume the call succeeded and + * that we need to release the layout + */ + *ret = 0; + (*respp)->lrs_present = 0; + retval = 0; + break; case -NFS4ERR_DELAY: /* Let the caller handle the retry */ *ret = -NFS4ERR_NOMATCHING_LAYOUT; From patchwork Fri Sep 20 11:23:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11154251 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 102AF14ED for ; Fri, 20 Sep 2019 11:26:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2FC1208C0 for ; Fri, 20 Sep 2019 11:26:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PjKwDKm+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438183AbfITL0J (ORCPT ); Fri, 20 Sep 2019 07:26:09 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:38078 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438179AbfITL0J (ORCPT ); Fri, 20 Sep 2019 07:26:09 -0400 Received: by mail-io1-f66.google.com with SMTP id k5so15323324iol.5 for ; Fri, 20 Sep 2019 04:26:08 -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 :mime-version:content-transfer-encoding; bh=owbPNNcxjT5XKu6v3G4mEstWx8051g6tPkh8ytztNTM=; b=PjKwDKm+lJ+INL5UyfnAazw67cMh9yPkm/RdguHN9f4rM1zpgowAlaVB6je9g2PRoR 8Ea4t36qjhqrTpY2od8aESP6+/CeYEmzpZkK1wsM1ttTW+2SL6yix8m+5kWGgXyYBbrJ 7P/Xxi+jaSckQmYS9rOugQULhjKVh5gMnGQmIeV4bb9EtkUM6rFlvbgRHCobmGEpPndN lPGHQCbapzT6Z36OBx8b6jboMvjeVtpwqWCoooByeFQNGAhHTCWRwh7mbU57xkGtzaQa va/Cu1229qZH3TPpI/Qy4SUxKAZE3ZYtMboS6fNh5A+Jhxvc04L0FVD+Uw9i8TXRKC12 sGIQ== 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:mime-version:content-transfer-encoding; bh=owbPNNcxjT5XKu6v3G4mEstWx8051g6tPkh8ytztNTM=; b=WZokM3t276JvM8Zng4ATVajpsZ8W8zuJjezzHcUQy0eb9nsxElFVPrKOj+rk+HqZLD 0wT0awQDIHxcQhhjAeaa1VxfKyBzybtObLkT/rdPiLV2EZblhOnPQE+vh2J31nWNbj63 s048SQGn7aMkCZDEoryo722NL9DqpgUy0RoTN0vUGJC3Izuy8lmhvma9HaUMlR36N/HR StiNfjm/h7Y0CpsCgKlEkgKulR9cajCrKQ4nJtKACgW8SU2/DmSPfxXGNxlSmWE7wXYU kM4ek9oEexEs8q3fTXXKQ6y4c5q3byB4tyl6/Zl6rMpsalSJCdOln3eeFI7FRXTSV6Fj WlKw== X-Gm-Message-State: APjAAAUMBhaAZDGo4JRHman0F3UvWYH0W04w9/zXqCM0aGYI4DKjnPvr 5D3axMrJDgZpSfQSuJtTvDkjiziTVw== X-Google-Smtp-Source: APXvYqyJFLFTxlbVd25afJJ7UL2daRSlLy1DBgGpbvRkQsQHLZDaIFtTseWjSeLHQCreEklp49YCzA== X-Received: by 2002:a6b:c9d7:: with SMTP id z206mr11007377iof.172.1568978768110; Fri, 20 Sep 2019 04:26:08 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id q74sm1308736iod.72.2019.09.20.04.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 04:26:07 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v3 5/9] NFSv4: Add a helper to increment stateid seqids Date: Fri, 20 Sep 2019 07:23:44 -0400 Message-Id: <20190920112348.69496-6-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190920112348.69496-5-trond.myklebust@hammerspace.com> References: <20190920112348.69496-1-trond.myklebust@hammerspace.com> <20190920112348.69496-2-trond.myklebust@hammerspace.com> <20190920112348.69496-3-trond.myklebust@hammerspace.com> <20190920112348.69496-4-trond.myklebust@hammerspace.com> <20190920112348.69496-5-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 Add a helper function to increment stateid seqids according to the rules specified in RFC5661 Section 8.2.2. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4_fs.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index 3564da1ba8a1..e8f74ed98e42 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -574,6 +574,15 @@ static inline bool nfs4_stateid_is_newer(const nfs4_stateid *s1, const nfs4_stat return (s32)(be32_to_cpu(s1->seqid) - be32_to_cpu(s2->seqid)) > 0; } +static inline void nfs4_stateid_seqid_inc(nfs4_stateid *s1) +{ + u32 seqid = be32_to_cpu(s1->seqid); + + if (++seqid == 0) + ++seqid; + s1->seqid = cpu_to_be32(seqid); +} + static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state) { return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0; From patchwork Fri Sep 20 11:23:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11154253 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A0E3914ED for ; Fri, 20 Sep 2019 11:26:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E79F205F4 for ; Fri, 20 Sep 2019 11:26:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fykzTfTB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438185AbfITL0L (ORCPT ); Fri, 20 Sep 2019 07:26:11 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:35940 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438179AbfITL0K (ORCPT ); Fri, 20 Sep 2019 07:26:10 -0400 Received: by mail-io1-f66.google.com with SMTP id b136so15345663iof.3 for ; Fri, 20 Sep 2019 04:26:09 -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 :mime-version:content-transfer-encoding; bh=yyGDQpMVH1rTLSPHW8HYSc7W3EA/zyjV2dF3PYsHi3Q=; b=fykzTfTBwzW0DpPmM96O/2thXkpM/se4o/onSzRCCJwaboA9Yf76Rzuag5hwT51BJo +jKsTbsUaPnJOxVkP+orhbkgcyM9n6S6WsKkIyXIENNGhdiwTRipk92fVmOS6Qz08M0j Mv64YCbEC8hKBhbYYu71RApH8peACTNRWanc3CQ2aa1etQB5aacZPi3mhgoO9nah03hZ ikFBVC66PvjSZzNX2zvQglqqVQDe9/4QuJMPrIpoFMHRA/BApcEK3Gdam035MK8+ETuH vcZnHXYAVgMj1ZII9cG+2AGb8m9G5E552O2SKMlhDwLK7RcM1hqCdSXB51ZGzn2KklfT RuDQ== 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:mime-version:content-transfer-encoding; bh=yyGDQpMVH1rTLSPHW8HYSc7W3EA/zyjV2dF3PYsHi3Q=; b=uglINGAU+42xS+573Ad/SyosQlxHqlKghhXZ0PS9a54ZKjlfPjBuaulsA0Z6FYGOpN IuSU01edbf3UzqWGyRD0+wv81G19a2mAo1Ocmw0flG9rAiHChYdqulJliAFR7hkawqjJ aLy+BsS4BYd7qCFw2c0MxWZBrukC7xxXCLKltbpft9hpSTKGxAgPtS/OhuQAui7AQlIa QExNvhMSV5YgJ6157Wtqe3StmcLgl5W3u19bnKAu8dxhf4Rw7FmLMyQ9T3FAWsdRWD6f kQQL+S1WJ9nIQ3Yn2V+heCqfXvGVQ6z75ZuqiBU3mQ34i9UJLRNzZC6y1YiqDo7gRT8Y /lfQ== X-Gm-Message-State: APjAAAW/yx+iNi9ASLcAdQgz+58Vzyd2Lc3Wmk1ji5H8MOcMZDkI0Pm4 W0jY+1Eyt0GAezPuC94rPA== X-Google-Smtp-Source: APXvYqybyROkKS23j6MnSgBivnuTOcBOaFIQUqQs6GsXD49JmRnkhp3UJK9BJYAYxAPKut9iOoEDIw== X-Received: by 2002:a02:b782:: with SMTP id f2mr19267984jam.48.1568978769264; Fri, 20 Sep 2019 04:26:09 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id q74sm1308736iod.72.2019.09.20.04.26.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 04:26:08 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v3 6/9] pNFS: Handle NFS4ERR_OLD_STATEID on layoutreturn by bumping the state seqid Date: Fri, 20 Sep 2019 07:23:45 -0400 Message-Id: <20190920112348.69496-7-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190920112348.69496-6-trond.myklebust@hammerspace.com> References: <20190920112348.69496-1-trond.myklebust@hammerspace.com> <20190920112348.69496-2-trond.myklebust@hammerspace.com> <20190920112348.69496-3-trond.myklebust@hammerspace.com> <20190920112348.69496-4-trond.myklebust@hammerspace.com> <20190920112348.69496-5-trond.myklebust@hammerspace.com> <20190920112348.69496-6-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 If a LAYOUTRETURN receives a reply of NFS4ERR_OLD_STATEID then assume we've missed an update, and just bump the stateid. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 2 +- fs/nfs/pnfs.c | 18 ++++++++++++++---- fs/nfs/pnfs.h | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index a5deb00b5ad1..cbaf6b7ac128 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -9069,7 +9069,7 @@ static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) server = NFS_SERVER(lrp->args.inode); switch (task->tk_status) { case -NFS4ERR_OLD_STATEID: - if (nfs4_layoutreturn_refresh_stateid(&lrp->args.stateid, + if (nfs4_layout_refresh_old_stateid(&lrp->args.stateid, &lrp->args.range, lrp->args.inode)) goto out_restart; diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index abc7188f1853..bb80034a7661 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -359,9 +359,10 @@ pnfs_clear_lseg_state(struct pnfs_layout_segment *lseg, } /* - * Update the seqid of a layout stateid + * Update the seqid of a layout stateid after receiving + * NFS4ERR_OLD_STATEID */ -bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst, +bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst, struct pnfs_layout_range *dst_range, struct inode *inode) { @@ -377,7 +378,15 @@ bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst, spin_lock(&inode->i_lock); lo = NFS_I(inode)->layout; - if (lo && nfs4_stateid_match_other(dst, &lo->plh_stateid)) { + if (lo && pnfs_layout_is_valid(lo) && + nfs4_stateid_match_other(dst, &lo->plh_stateid)) { + /* Is our call using the most recent seqid? If so, bump it */ + if (!nfs4_stateid_is_newer(&lo->plh_stateid, dst)) { + nfs4_stateid_seqid_inc(dst); + ret = true; + goto out; + } + /* Try to update the seqid to the most recent */ err = pnfs_mark_matching_lsegs_return(lo, &head, &range, 0); if (err != -EBUSY) { dst->seqid = lo->plh_stateid.seqid; @@ -385,6 +394,7 @@ bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst, ret = true; } } +out: spin_unlock(&inode->i_lock); pnfs_free_lseg_list(&head); return ret; @@ -1475,7 +1485,7 @@ int pnfs_roc_done(struct rpc_task *task, struct inode *inode, *ret = -NFS4ERR_NOMATCHING_LAYOUT; return 0; case -NFS4ERR_OLD_STATEID: - if (!nfs4_layoutreturn_refresh_stateid(&arg->stateid, + if (!nfs4_layout_refresh_old_stateid(&arg->stateid, &arg->range, inode)) break; *ret = -NFS4ERR_NOMATCHING_LAYOUT; diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h index 3ef3756d437c..f8a38065c7e4 100644 --- a/fs/nfs/pnfs.h +++ b/fs/nfs/pnfs.h @@ -261,7 +261,7 @@ int pnfs_destroy_layouts_byfsid(struct nfs_client *clp, bool is_recall); int pnfs_destroy_layouts_byclid(struct nfs_client *clp, bool is_recall); -bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst, +bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst, struct pnfs_layout_range *dst_range, struct inode *inode); void pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo); @@ -798,7 +798,7 @@ static inline void nfs4_pnfs_v3_ds_connect_unload(void) { } -static inline bool nfs4_layoutreturn_refresh_stateid(nfs4_stateid *dst, +static inline bool nfs4_layout_refresh_old_stateid(nfs4_stateid *dst, struct pnfs_layout_range *dst_range, struct inode *inode) { From patchwork Fri Sep 20 11:23:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11154255 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B18417E6 for ; Fri, 20 Sep 2019 11:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DDB44208C0 for ; Fri, 20 Sep 2019 11:26:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DouOPYI0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438179AbfITL0L (ORCPT ); Fri, 20 Sep 2019 07:26:11 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:32927 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438184AbfITL0L (ORCPT ); Fri, 20 Sep 2019 07:26:11 -0400 Received: by mail-io1-f68.google.com with SMTP id m11so15407969ioo.0 for ; Fri, 20 Sep 2019 04:26:10 -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 :mime-version:content-transfer-encoding; bh=tm3Z204lhcQueHhZs5vFp/leKoUofNIJTGBebGTHcyI=; b=DouOPYI0AeVNZ9nYPuPDBOTnNEy+FK3Wp6GlEVjzxmQRRX++jM2bRECxE2w/JW4Ub2 0Dp9FoK9qFr7JNBMsuoLgIXJGS0qnevkonC8alfPBeJqrZn2UmN+z31+ZYHox9WsN0Fk E5YGuQWzvp2J4LDz5Sz+cWztVBAIuL5aXLt59Kxuiml8g8ZalvSk48qH9Ya564yLKMGh 6nE1GP9yyVRHxt9H1i4MTVFgS82YRyGRb+eBw6GpuQBQUTxJ+9nyY2QWK63px5JJidoH pjfTRVN3iHLXmV3IiRAmHeI9595JKZOr9dqR9T98ZCzplMyOHR/6jeh3e558sVuag5Cl YwGg== 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:mime-version:content-transfer-encoding; bh=tm3Z204lhcQueHhZs5vFp/leKoUofNIJTGBebGTHcyI=; b=AOVgfyerQSROdLVdEwboivIqiOxXXEq9UyYfk6lKsp0kckBz3zMQHocc1M3PMhtw2V cjkI8fbudCrxyqCz85j1ZhmXObrH2Mt5QRPUD/fUTxN2hI4HcXTa8+DRthTUPuLNAa08 mybGdr6hU7JBqNcx7gk4pLnXDMMV3mJhRdgItT560O57S5ADWoWGQFcMTxx39QkPOZNI i0buRHNuOsy17/1kIAtDajWqGOc/Ao6g7BacHGx8N+sMJQwl+0pj2LYKMHvz28uZ6HMa kO8PSq42tMkx6eGaz7YmpzOoUfS6OOjncF5fJJpdTvq0aBlXS9EbjN233gNclRYCjKt3 NSmw== X-Gm-Message-State: APjAAAXOCjtyolzRl3eN3l5ynggNct6MMmj4H/753S/mdviKUEf2svmZ UK1IwCXdLbQMXmMnEGnTEQ== X-Google-Smtp-Source: APXvYqxkyb8PQz7rti0W5pGgdJOgo20Rv7KxfMmfxyQ61kc06u/5IePRLExq7BS/gR66Ti9PCMp6dg== X-Received: by 2002:a5d:97cf:: with SMTP id k15mr4253011ios.151.1568978770042; Fri, 20 Sep 2019 04:26:10 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id q74sm1308736iod.72.2019.09.20.04.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 04:26:09 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v3 7/9] NFSv4: Fix OPEN_DOWNGRADE error handling Date: Fri, 20 Sep 2019 07:23:46 -0400 Message-Id: <20190920112348.69496-8-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190920112348.69496-7-trond.myklebust@hammerspace.com> References: <20190920112348.69496-1-trond.myklebust@hammerspace.com> <20190920112348.69496-2-trond.myklebust@hammerspace.com> <20190920112348.69496-3-trond.myklebust@hammerspace.com> <20190920112348.69496-4-trond.myklebust@hammerspace.com> <20190920112348.69496-5-trond.myklebust@hammerspace.com> <20190920112348.69496-6-trond.myklebust@hammerspace.com> <20190920112348.69496-7-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 If OPEN_DOWNGRADE returns a state error, then we want to initiate state recovery in addition to marking the stateid as closed. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index cbaf6b7ac128..025dd5efbf34 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -3394,7 +3394,9 @@ static void nfs4_close_done(struct rpc_task *task, void *data) task->tk_msg.rpc_cred); /* Fallthrough */ case -NFS4ERR_BAD_STATEID: - break; + if (calldata->arg.fmode == 0) + break; + /* Fallthrough */ default: task->tk_status = nfs4_async_handle_exception(task, server, task->tk_status, &exception); From patchwork Fri Sep 20 11:23:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11154257 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4FFA514ED for ; Fri, 20 Sep 2019 11:26:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 26691208C0 for ; Fri, 20 Sep 2019 11:26:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kX+PQVfz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438187AbfITL0M (ORCPT ); Fri, 20 Sep 2019 07:26:12 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:42059 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438184AbfITL0M (ORCPT ); Fri, 20 Sep 2019 07:26:12 -0400 Received: by mail-io1-f66.google.com with SMTP id n197so15269936iod.9 for ; Fri, 20 Sep 2019 04:26:11 -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 :mime-version:content-transfer-encoding; bh=dKBtfXBDb2I4SIWkL8RbGSdtWIaBiUXWBZYasSgkTuM=; b=kX+PQVfzY3z1NkQMDKaRAAkI61WmJfj7k279HXOWC7fQE29f0g+aFogda1BU4xtcFN A/4zmqHZe14/PjellTKQT4fw1Hi/0emAWOgRDaOx3fC8WPfPMEUbmkMir9RewwqY2Ocx uv9rZyz86it2jnd3fAuXJm2LJiXSzdNSoI1mVCeoZimBLmU8aqwCXYl0epS1t6ZfG8MN Epui648jjUPOk+Zfx4Lp39y5Ym37LJOtjjn64YFF7MWGbkcweq9lwsyHNBFiDGM4FEoj rZYyMnkBQgwuagaQ6HNMi4B2YtDS5jk/5GD5tpjyxowgAJ8Lt8yEjAHXa1RkwrUv/vRE X+GQ== 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:mime-version:content-transfer-encoding; bh=dKBtfXBDb2I4SIWkL8RbGSdtWIaBiUXWBZYasSgkTuM=; b=iW8Of2ZnklSVXbr0n9bNxp+yy9QfVcaoieFhW0TYhLXax1tWxwq+hva87V8Fs8Rcwa eCxCpWCVHO3RF1Q872WMIXHIdiByOpNnJvog+9lGmHRJHCV/7ma1CLWvejytZ567IPIh eqYf3v7xM9UzRoVummoMYKtjN838jnGUknJbhCBirV/+4QBlxnSx8iJYlKjD9yqxRJpY Q9dyx0sXswZ8PkeCpHBifvT84mV8Ew3ULLsyGfWtJXbDfecdHbUrPsjrdyb4pSsAjIIx aNfAevp5XeBgYAS6kDjL3r0f/C5Rx0p3PI/k+KZPKccIcXZLVDDTJMFqWg7RolJaEDJ4 aJkw== X-Gm-Message-State: APjAAAUB1auHYfxXT8h2VH12iDgj26sVQkkGGiJ3FKN/mHGIrOvjjfDE fWoH1tQhN94blR1RSmVUcw== X-Google-Smtp-Source: APXvYqxeccqgqZbpN+cCz0VyKJ+wdf0kNJhx2/4y+uy2B19D82kvDlfkpRSYVVjQmkMMH6FK4l7/gg== X-Received: by 2002:a6b:8d84:: with SMTP id p126mr18188497iod.111.1568978771137; Fri, 20 Sep 2019 04:26:11 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id q74sm1308736iod.72.2019.09.20.04.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 04:26:10 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v3 8/9] NFSv4: Handle NFS4ERR_OLD_STATEID in CLOSE/OPEN_DOWNGRADE Date: Fri, 20 Sep 2019 07:23:47 -0400 Message-Id: <20190920112348.69496-9-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190920112348.69496-8-trond.myklebust@hammerspace.com> References: <20190920112348.69496-1-trond.myklebust@hammerspace.com> <20190920112348.69496-2-trond.myklebust@hammerspace.com> <20190920112348.69496-3-trond.myklebust@hammerspace.com> <20190920112348.69496-4-trond.myklebust@hammerspace.com> <20190920112348.69496-5-trond.myklebust@hammerspace.com> <20190920112348.69496-6-trond.myklebust@hammerspace.com> <20190920112348.69496-7-trond.myklebust@hammerspace.com> <20190920112348.69496-8-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 If a CLOSE or OPEN_DOWNGRADE operation receives a NFS4ERR_OLD_STATEID then bump the seqid before resending. Ensure we only bump the seqid by 1. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4_fs.h | 2 -- fs/nfs/nfs4proc.c | 75 ++++++++++++++++++++++++++++++++++++++++++++-- fs/nfs/nfs4state.c | 16 ---------- 3 files changed, 72 insertions(+), 21 deletions(-) diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index e8f74ed98e42..16b2e5cc3e94 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h @@ -491,8 +491,6 @@ extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t, const struct nfs_lock_context *, nfs4_stateid *, const struct cred **); -extern bool nfs4_refresh_open_stateid(nfs4_stateid *dst, - struct nfs4_state *state); extern bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state); diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 025dd5efbf34..c14af2c1c6b6 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -3308,6 +3308,75 @@ nfs4_wait_on_layoutreturn(struct inode *inode, struct rpc_task *task) return pnfs_wait_on_layoutreturn(inode, task); } +/* + * Update the seqid of an open stateid + */ +static void nfs4_sync_open_stateid(nfs4_stateid *dst, + struct nfs4_state *state) +{ + __be32 seqid_open; + u32 dst_seqid; + int seq; + + for (;;) { + if (!nfs4_valid_open_stateid(state)) + break; + seq = read_seqbegin(&state->seqlock); + if (!nfs4_state_match_open_stateid_other(state, dst)) { + nfs4_stateid_copy(dst, &state->open_stateid); + if (read_seqretry(&state->seqlock, seq)) + continue; + break; + } + seqid_open = state->open_stateid.seqid; + if (read_seqretry(&state->seqlock, seq)) + continue; + + dst_seqid = be32_to_cpu(dst->seqid); + if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) < 0) + dst->seqid = seqid_open; + break; + } +} + +/* + * Update the seqid of an open stateid after receiving + * NFS4ERR_OLD_STATEID + */ +static bool nfs4_refresh_open_old_stateid(nfs4_stateid *dst, + struct nfs4_state *state) +{ + __be32 seqid_open; + u32 dst_seqid; + bool ret; + int seq; + + for (;;) { + ret = false; + if (!nfs4_valid_open_stateid(state)) + break; + seq = read_seqbegin(&state->seqlock); + if (!nfs4_state_match_open_stateid_other(state, dst)) { + if (read_seqretry(&state->seqlock, seq)) + continue; + break; + } + seqid_open = state->open_stateid.seqid; + if (read_seqretry(&state->seqlock, seq)) + continue; + + dst_seqid = be32_to_cpu(dst->seqid); + if ((s32)(dst_seqid - be32_to_cpu(seqid_open)) >= 0) + dst->seqid = cpu_to_be32(dst_seqid + 1); + else + dst->seqid = seqid_open; + ret = true; + break; + } + + return ret; +} + struct nfs4_closedata { struct inode *inode; struct nfs4_state *state; @@ -3382,7 +3451,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data) break; case -NFS4ERR_OLD_STATEID: /* Did we race with OPEN? */ - if (nfs4_refresh_open_stateid(&calldata->arg.stateid, + if (nfs4_refresh_open_old_stateid(&calldata->arg.stateid, state)) goto out_restart; goto out_release; @@ -3451,8 +3520,8 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) } else if (is_rdwr) calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; - if (!nfs4_valid_open_stateid(state) || - !nfs4_refresh_open_stateid(&calldata->arg.stateid, state)) + nfs4_sync_open_stateid(&calldata->arg.stateid, state); + if (!nfs4_valid_open_stateid(state)) call_close = 0; spin_unlock(&state->owner->so_lock); diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index cad4e064b328..e23945174da4 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -1015,22 +1015,6 @@ static int nfs4_copy_lock_stateid(nfs4_stateid *dst, return ret; } -bool nfs4_refresh_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) -{ - bool ret; - int seq; - - do { - ret = false; - seq = read_seqbegin(&state->seqlock); - if (nfs4_state_match_open_stateid_other(state, dst)) { - dst->seqid = state->open_stateid.seqid; - ret = true; - } - } while (read_seqretry(&state->seqlock, seq)); - return ret; -} - bool nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state) { bool ret; From patchwork Fri Sep 20 11:23:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 11154259 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3271314ED for ; Fri, 20 Sep 2019 11:26:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 10CB7208C0 for ; Fri, 20 Sep 2019 11:26:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DyyhfbaK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438184AbfITL0N (ORCPT ); Fri, 20 Sep 2019 07:26:13 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:46661 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438186AbfITL0N (ORCPT ); Fri, 20 Sep 2019 07:26:13 -0400 Received: by mail-io1-f65.google.com with SMTP id c6so2125995ioo.13 for ; Fri, 20 Sep 2019 04:26:12 -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 :mime-version:content-transfer-encoding; bh=isIuY52YMigDpv+ec/V/dH0sTr/uAIcEnxiREMN/WIA=; b=DyyhfbaKOiziy+dizHrQ3Nb1WW7GnJqmmJ0BIv2HBLaXTQZGNDkRfQxcfom1/TaQqa /5X667auj5jDIRn+RFCtDAeM8QaMyXoDo1M5pcV8SPNzOhuntRTUj8nf9zJeUQ11scau JB+Wlu+bEDpHT7ryLZX5/MUMszUy9S+E3z/jGXX/BfHf2o3QbyCAr4Nup/4ZM/aj1eRc iKLxizx6vaEQOgilW5XcBupm6cJ6kOsbYPSyqZ5Ph+HNM9g8n+92RScY5j+vlt+ulrIk UXCZ/joyK8mGWbea4RCyMCjqwxg6P30Eyt8G883gLWin9i3UnCVhUWrDvk5Uyai9E1fV IGUA== 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:mime-version:content-transfer-encoding; bh=isIuY52YMigDpv+ec/V/dH0sTr/uAIcEnxiREMN/WIA=; b=rQbVFecGTgmNpiQDUE6k/YnSMS73NUDqzdBS7CpCPJY7ri9XXMbpQYQDNrsS8DyAT3 MH+SKQn7YsRwOl8IEv8FijR4HUjLN2rQk3xBT5tKQ2ck3wa6ZUOnSoYwkwdiNTmv79hf 75SFpatU88vLrRYRykmcKNTEM81Lr0mlBI8ZRUdsq9Lh4ohYsmqogkLZG/weQ1RaiFrx v5VACQO72Tj2m32ti/Np2biGQpkBDDzV19X0SRuzu8BUDtuOkH9D9jHkKVcXK6GOjNka GdbsjW9DRmc1z+WMQMX8c7d8jN3hUMyQtLls26V6OAPyRj6uhAXw2/QXrIxaCdNUOuiY a7Gg== X-Gm-Message-State: APjAAAWBTMZhkefnQdrQWuHHKNeVUQw98WykMZQ+5jmc2eok6AMkil2W RU6jxp9dFg7kwYGVLvdFuw== X-Google-Smtp-Source: APXvYqwRNNiDMtPbAIgkJoTDmNYOHY/mSzMCkxWPLmi2biky0uImXb9meuaox3AB49pWgZo7k04XSg== X-Received: by 2002:a6b:9308:: with SMTP id v8mr1170362iod.221.1568978771937; Fri, 20 Sep 2019 04:26:11 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id q74sm1308736iod.72.2019.09.20.04.26.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 04:26:11 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: Olga Kornievskaia , linux-nfs@vger.kernel.org Subject: [PATCH v3 9/9] NFSv4: Handle NFS4ERR_OLD_STATEID in LOCKU Date: Fri, 20 Sep 2019 07:23:48 -0400 Message-Id: <20190920112348.69496-10-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190920112348.69496-9-trond.myklebust@hammerspace.com> References: <20190920112348.69496-1-trond.myklebust@hammerspace.com> <20190920112348.69496-2-trond.myklebust@hammerspace.com> <20190920112348.69496-3-trond.myklebust@hammerspace.com> <20190920112348.69496-4-trond.myklebust@hammerspace.com> <20190920112348.69496-5-trond.myklebust@hammerspace.com> <20190920112348.69496-6-trond.myklebust@hammerspace.com> <20190920112348.69496-7-trond.myklebust@hammerspace.com> <20190920112348.69496-8-trond.myklebust@hammerspace.com> <20190920112348.69496-9-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 If a LOCKU request receives a NFS4ERR_OLD_STATEID, then bump the seqid before resending. Ensure we only bump the seqid by 1. Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 53 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index c14af2c1c6b6..415480b7e43e 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -6411,6 +6411,42 @@ static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock * return err; } +/* + * Update the seqid of a lock stateid after receiving + * NFS4ERR_OLD_STATEID + */ +static bool nfs4_refresh_lock_old_stateid(nfs4_stateid *dst, + struct nfs4_lock_state *lsp) +{ + struct nfs4_state *state = lsp->ls_state; + bool ret = false; + + spin_lock(&state->state_lock); + if (!nfs4_stateid_match_other(dst, &lsp->ls_stateid)) + goto out; + if (!nfs4_stateid_is_newer(&lsp->ls_stateid, dst)) + nfs4_stateid_seqid_inc(dst); + else + dst->seqid = lsp->ls_stateid.seqid; + ret = true; +out: + spin_unlock(&state->state_lock); + return ret; +} + +static bool nfs4_sync_lock_stateid(nfs4_stateid *dst, + struct nfs4_lock_state *lsp) +{ + struct nfs4_state *state = lsp->ls_state; + bool ret; + + spin_lock(&state->state_lock); + ret = !nfs4_stateid_match_other(dst, &lsp->ls_stateid); + nfs4_stateid_copy(dst, &lsp->ls_stateid); + spin_unlock(&state->state_lock); + return ret; +} + struct nfs4_unlockdata { struct nfs_locku_args arg; struct nfs_locku_res res; @@ -6428,7 +6464,8 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, struct nfs_seqid *seqid) { struct nfs4_unlockdata *p; - struct inode *inode = lsp->ls_state->inode; + struct nfs4_state *state = lsp->ls_state; + struct inode *inode = state->inode; p = kzalloc(sizeof(*p), GFP_NOFS); if (p == NULL) @@ -6444,6 +6481,9 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, locks_init_lock(&p->fl); locks_copy_lock(&p->fl, fl); p->server = NFS_SERVER(inode); + spin_lock(&state->state_lock); + nfs4_stateid_copy(&p->arg.stateid, &lsp->ls_stateid); + spin_unlock(&state->state_lock); return p; } @@ -6482,10 +6522,14 @@ static void nfs4_locku_done(struct rpc_task *task, void *data) task->tk_msg.rpc_cred); /* Fall through */ case -NFS4ERR_BAD_STATEID: - case -NFS4ERR_OLD_STATEID: case -NFS4ERR_STALE_STATEID: - if (!nfs4_stateid_match(&calldata->arg.stateid, - &calldata->lsp->ls_stateid)) + if (nfs4_sync_lock_stateid(&calldata->arg.stateid, + calldata->lsp)) + rpc_restart_call_prepare(task); + break; + case -NFS4ERR_OLD_STATEID: + if (nfs4_refresh_lock_old_stateid(&calldata->arg.stateid, + calldata->lsp)) rpc_restart_call_prepare(task); break; default: @@ -6508,7 +6552,6 @@ static void nfs4_locku_prepare(struct rpc_task *task, void *data) if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) goto out_wait; - nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid); if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { /* Note: exit _without_ running nfs4_locku_done */ goto out_no_action;