From patchwork Tue Mar 4 17:31:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Adamson X-Patchwork-Id: 3764291 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 ED8BE9F35F for ; Tue, 4 Mar 2014 17:31:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C837A20220 for ; Tue, 4 Mar 2014 17:31:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D506320382 for ; Tue, 4 Mar 2014 17:31:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753402AbaCDRbU (ORCPT ); Tue, 4 Mar 2014 12:31:20 -0500 Received: from mx11.netapp.com ([216.240.18.76]:39593 "EHLO mx11.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752007AbaCDRbT (ORCPT ); Tue, 4 Mar 2014 12:31:19 -0500 X-IronPort-AV: E=Sophos;i="4.97,586,1389772800"; d="scan'208";a="106535024" Received: from vmwexceht04-prd.hq.netapp.com ([10.106.77.34]) by mx11-out.netapp.com with ESMTP; 04 Mar 2014 09:31:19 -0800 Received: from smtp2.corp.netapp.com (10.57.159.114) by VMWEXCEHT04-PRD.hq.netapp.com (10.106.77.34) with Microsoft SMTP Server id 14.3.123.3; Tue, 4 Mar 2014 09:31:19 -0800 Received: from netapp42.cthon.org (vpn2ntap-29457.vpn.netapp.com [10.55.72.152]) by smtp2.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id s24HVEFI017405; Tue, 4 Mar 2014 09:31:17 -0800 (PST) From: To: CC: , Andy Adamson Subject: [PATCH 2/4] NFSv4 Check errors on stateid changed functions in I/O path Date: Tue, 4 Mar 2014 12:31:07 -0500 Message-ID: <1393954269-3974-3-git-send-email-andros@netapp.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1393954269-3974-1-git-send-email-andros@netapp.com> References: <1393954269-3974-1-git-send-email-andros@netapp.com> MIME-Version: 1.0 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.9 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 From: Andy Adamson Retry I/O from the call prepare state (with the new stateid) if the stateid has changed on an stateid expired error Fail the I/O if the statied represents a lost lock. Otherwise, let the error handler decide what to do. Without this change, I/O with a stateid expired error such as NFS4ERR_BAD_STATEID can be retried without recovery and loop forever. Signed-off-by: Andy Adamson --- fs/nfs/nfs4proc.c | 77 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 2f1997d..de8e7f5 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -4107,29 +4107,49 @@ static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data) return 0; } -static bool nfs4_read_stateid_changed(struct rpc_task *task, +static int nfs4_read_stateid_changed(struct rpc_task *task, struct nfs_readargs *args) { + int ret; - if (!nfs4_error_stateid_expired(task->tk_status) || - nfs4_stateid_is_current(&args->stateid, + ret = nfs4_stateid_is_current(&args->stateid, args->context, args->lock_context, - FMODE_READ)) - return false; - rpc_restart_call_prepare(task); - return true; + FMODE_READ); + switch (ret) { + case 0: /* stateid changed */ + if (nfs4_error_stateid_expired(task->tk_status)) { + /* stateid expired error, retry with changed stateid */ + rpc_restart_call_prepare(task); + return -EAGAIN; + } + return 0; /* let error handler proceed */ + + case -EIO: /* -EIO means lock stateid was lost: fail the I/O */ + task->tk_status = -EIO; + return -EIO; + + case -EWOULDBLOCK: /* stateid change in progress */ + default:/* stateid has not changed, let error handler proceed.*/ + return 0; + + } } static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) { + int ret; dprintk("--> %s\n", __func__); if (!nfs4_sequence_done(task, &data->res.seq_res)) return -EAGAIN; - if (nfs4_read_stateid_changed(task, &data->args)) - return -EAGAIN; + ret = nfs4_read_stateid_changed(task, &data->args); + switch (ret) { + case -EAGAIN: + case -EIO: + return ret; + } return data->read_done_cb ? data->read_done_cb(task, data) : nfs4_read_done_cb(task, data); } @@ -4176,23 +4196,46 @@ static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data static bool nfs4_write_stateid_changed(struct rpc_task *task, struct nfs_writeargs *args) { + int ret; - if (!nfs4_error_stateid_expired(task->tk_status) || - nfs4_stateid_is_current(&args->stateid, + ret = nfs4_stateid_is_current(&args->stateid, args->context, args->lock_context, - FMODE_WRITE)) - return false; - rpc_restart_call_prepare(task); - return true; + FMODE_WRITE); + + switch (ret) { + case 0: /* stateid changed */ + if (nfs4_error_stateid_expired(task->tk_status)) { + /* stateid expired error, retry with changed stateid */ + rpc_restart_call_prepare(task); + return -EAGAIN; + } + return 0; /* let error handler proceed */ + + case -EIO: /* -EIO means lock stateid was lost: fail the I/O */ + task->tk_status = -EIO; + return -EIO; + + case -EWOULDBLOCK: /* stateid change in progress */ + default:/* stateid has not changed, let error handler proceed.*/ + return 0; + + } } static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) { + int ret; + if (!nfs4_sequence_done(task, &data->res.seq_res)) return -EAGAIN; - if (nfs4_write_stateid_changed(task, &data->args)) - return -EAGAIN; + + ret = nfs4_write_stateid_changed(task, &data->args); + switch (ret) { + case -EAGAIN: + case -EIO: + return ret; + } return data->write_done_cb ? data->write_done_cb(task, data) : nfs4_write_done_cb(task, data); }