From patchwork Tue May 20 18:08:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schumaker, Anna" X-Patchwork-Id: 4212411 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 2E5559F32A for ; Tue, 20 May 2014 18:08:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7BB12201DE for ; Tue, 20 May 2014 18:08:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F04842017E for ; Tue, 20 May 2014 18:08:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751457AbaETSId (ORCPT ); Tue, 20 May 2014 14:08:33 -0400 Received: from mx12.netapp.com ([216.240.18.77]:16546 "EHLO mx12.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751244AbaETSIc (ORCPT ); Tue, 20 May 2014 14:08:32 -0400 X-IronPort-AV: E=Sophos;i="4.98,875,1392192000"; d="scan'208";a="165539426" Received: from vmwexceht01-prd.hq.netapp.com ([10.106.76.239]) by mx12-out.netapp.com with ESMTP; 20 May 2014 11:08:32 -0700 Received: from VMWEXCHTS02-PRD.hq.netapp.com (10.122.105.23) by vmwexceht01-prd.hq.netapp.com (10.106.76.239) with Microsoft SMTP Server (TLS) id 14.3.123.3; Tue, 20 May 2014 11:08:32 -0700 Received: from smtp2.corp.netapp.com (10.57.159.114) by VMWEXCHTS02-PRD.hq.netapp.com (10.122.105.23) with Microsoft SMTP Server id 15.0.847.32; Tue, 20 May 2014 11:08:31 -0700 Received: from davros.com (davros.ocarinaproject.vpn.netapp.com [10.63.224.110]) by smtp2.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id s4KI8LYo029501; Tue, 20 May 2014 11:08:30 -0700 (PDT) From: Anna Schumaker To: , CC: , Subject: [RFC 08/12] nfs: create a common pnfs_do_rw() function Date: Tue, 20 May 2014 14:08:15 -0400 Message-ID: <1400609299-32558-9-git-send-email-Anna.Schumaker@Netapp.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1400609299-32558-1-git-send-email-Anna.Schumaker@Netapp.com> References: <1400609299-32558-1-git-send-email-Anna.Schumaker@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=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 The read and write code looks almost identical, so use a simple function pointer to decide between read_pagelist() and write_pagelist(). Signed-off-by: Anna Schumaker --- fs/nfs/pnfs.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index 293e970..69751d4 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c @@ -1481,6 +1481,24 @@ pnfs_through_mds(struct nfs_pageio_descriptor *desc, nfs_generic_pgio_reset(hdr); } +static bool +pnfs_do_rw(struct nfs_pageio_descriptor *desc, struct nfs_pgio_header *hdr, + enum pnfs_try_status (*try_rw)(struct nfs_pgio_header *, int)) +{ + struct pnfs_layout_segment *lseg = desc->pg_lseg; + bool ret = true; + + hdr->mds_ops = desc->pg_rpc_callops; + desc->pg_lseg = NULL; + + if (try_rw(hdr, desc->pg_ioflags) == PNFS_NOT_ATTEMPTED) { + pnfs_through_mds(desc, hdr); + ret = false; + } + pnfs_put_lseg(lseg); + return ret; +} + void pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req, u64 wb_size) @@ -1517,19 +1535,10 @@ pnfs_try_to_write_data(struct nfs_pgio_header *hdr, int how) } static void -pnfs_do_write(struct nfs_pageio_descriptor *desc, - struct nfs_pgio_header *hdr, int how) +pnfs_do_write(struct nfs_pageio_descriptor *desc, struct nfs_pgio_header *hdr) { - struct pnfs_layout_segment *lseg = desc->pg_lseg; - - hdr->mds_ops = desc->pg_rpc_callops; - desc->pg_lseg = NULL; - - if (pnfs_try_to_write_data(hdr, how) == PNFS_NOT_ATTEMPTED) - pnfs_through_mds(desc, hdr); - else + if (pnfs_do_rw(desc, hdr, pnfs_try_to_write_data)) nfs_inc_stats(hdr->inode, NFSIOS_PNFS_WRITE); - pnfs_put_lseg(lseg); } static void pnfs_writehdr_free(struct nfs_pgio_header *hdr) @@ -1559,7 +1568,7 @@ pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc) pnfs_put_lseg(desc->pg_lseg); desc->pg_lseg = NULL; } else - pnfs_do_write(desc, hdr, desc->pg_ioflags); + pnfs_do_write(desc, hdr); return ret; } EXPORT_SYMBOL_GPL(pnfs_generic_pg_writepages); @@ -1602,7 +1611,7 @@ EXPORT_SYMBOL_GPL(pnfs_ld_read_done); * Call the appropriate parallel I/O subsystem read function. */ static enum pnfs_try_status -pnfs_try_to_read_data(struct nfs_pgio_header *hdr) +pnfs_try_to_read_data(struct nfs_pgio_header *hdr, int how) { return NFS_SERVER(hdr->inode)->pnfs_curr_ld->read_pagelist(hdr); } @@ -1610,16 +1619,8 @@ pnfs_try_to_read_data(struct nfs_pgio_header *hdr) static void pnfs_do_read(struct nfs_pageio_descriptor *desc, struct nfs_pgio_header *hdr) { - struct pnfs_layout_segment *lseg = desc->pg_lseg; - - hdr->mds_ops = desc->pg_rpc_callops; - desc->pg_lseg = NULL; - - if (pnfs_try_to_read_data(hdr) == PNFS_NOT_ATTEMPTED) - pnfs_through_mds(desc, hdr); - else + if (pnfs_do_rw(desc, hdr, pnfs_try_to_read_data)) nfs_inc_stats(hdr->inode, NFSIOS_PNFS_READ); - pnfs_put_lseg(lseg); } static void pnfs_readhdr_free(struct nfs_pgio_header *hdr)