From patchwork Fri Sep 4 19:07:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schumaker, Anna" X-Patchwork-Id: 7125481 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 937749F36E for ; Fri, 4 Sep 2015 19:07:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 792822069D for ; Fri, 4 Sep 2015 19:07:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6AB33208B8 for ; Fri, 4 Sep 2015 19:07:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933074AbbIDTHz (ORCPT ); Fri, 4 Sep 2015 15:07:55 -0400 Received: from mx143.netapp.com ([216.240.21.24]:52782 "EHLO mx143.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932596AbbIDTHz (ORCPT ); Fri, 4 Sep 2015 15:07:55 -0400 X-IronPort-AV: E=Sophos;i="5.17,470,1437462000"; d="scan'208";a="64788735" Received: from vmwexchts02-prd.hq.netapp.com ([10.122.105.23]) by mx143-out.netapp.com with ESMTP; 04 Sep 2015 12:07:54 -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.1076.9; Fri, 4 Sep 2015 12:07:54 -0700 Received: from davros.com ([10.63.224.137]) by smtp2.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id t84J7pLq011473; Fri, 4 Sep 2015 12:07:53 -0700 (PDT) From: Anna Schumaker To: , CC: Subject: [PATCH v1 2/5] SUNRPC: Add the ability to expand holes in data pages Date: Fri, 4 Sep 2015 15:07:46 -0400 Message-ID: <1441393669-30280-3-git-send-email-Anna.Schumaker@Netapp.com> X-Mailer: git-send-email 2.5.1 In-Reply-To: <1441393669-30280-1-git-send-email-Anna.Schumaker@Netapp.com> References: <1441393669-30280-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=-6.9 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 This patch adds the ability to "read a hole" into a set of XDR data pages by taking the following steps: 1) Shift all data after the current xdr->p to the right, possibly into the tail, 2) Zero the specified range, and 3) Update xdr->p to point beyond the hole. Signed-off-by: Anna Schumaker --- include/linux/sunrpc/xdr.h | 1 + net/sunrpc/xdr.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h index 70c6b92..81c5a3f 100644 --- a/include/linux/sunrpc/xdr.h +++ b/include/linux/sunrpc/xdr.h @@ -229,6 +229,7 @@ extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes); extern unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len); extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len); extern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data); +extern size_t xdr_expand_hole(struct xdr_stream *, size_t, size_t); #endif /* __KERNEL__ */ diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c index b1c4ffb..be154e7 100644 --- a/net/sunrpc/xdr.c +++ b/net/sunrpc/xdr.c @@ -219,6 +219,40 @@ _shift_data_right_pages(struct page **pages, size_t pgto_base, } while ((len -= copy) != 0); } +static void +_shift_data_right_tail(struct xdr_buf *buf, size_t pgfrom_base, size_t len) +{ + struct kvec *tail = buf->tail; + + /* Make room for new data. */ + if (tail->iov_len > 0) + memmove((char *)tail->iov_base + len, tail->iov_base, len); + + _copy_from_pages((char *)tail->iov_base, + buf->pages, + buf->page_base + pgfrom_base, + len); + + tail->iov_len += len; +} + +static void +_shift_data_right(struct xdr_buf *buf, size_t to, size_t from, size_t len) +{ + size_t shift = len; + + if ((to + len) > buf->page_len) { + shift = (to + len) - buf->page_len; + _shift_data_right_tail(buf, (from + len) - shift, shift); + shift = len - shift; + } + + _shift_data_right_pages(buf->pages, + buf->page_base + to, + buf->page_base + from, + shift); +} + /** * _copy_to_pages * @pages: array of pages @@ -304,6 +338,33 @@ _copy_from_pages(char *p, struct page **pages, size_t pgbase, size_t len) EXPORT_SYMBOL_GPL(_copy_from_pages); /** + * _zero_data_pages + * @pages: array of pages + * @pgbase: beginning page vector address + * @len: length + */ +static void +_zero_data_pages(struct page **pages, size_t pgbase, size_t len) +{ + struct page **page; + size_t zero; + + page = pages + (pgbase >> PAGE_CACHE_SHIFT); + pgbase &= ~PAGE_CACHE_MASK; + + do { + zero = len; + if (pgbase + zero > PAGE_SIZE) + zero = PAGE_SIZE - pgbase; + + zero_user_segment(*page, pgbase, pgbase + zero); + page++; + pgbase = 0; + + } while ((len -= zero) != 0); +} + +/** * xdr_shrink_bufhead * @buf: xdr_buf * @len: bytes to remove from buf->head[0] @@ -445,6 +506,24 @@ unsigned int xdr_stream_pos(const struct xdr_stream *xdr) EXPORT_SYMBOL_GPL(xdr_stream_pos); /** + * xdr_page_pos - Return the current offset from the start of the xdr->buf->pages + * @xdr: pointer to struct xdr_stream + */ +static size_t xdr_page_pos(const struct xdr_stream *xdr) +{ + unsigned int offset; + unsigned int base = xdr->buf->page_len; + void *kaddr = xdr->buf->tail->iov_base;; + + if (xdr->page_ptr) { + base = (xdr->page_ptr - xdr->buf->pages) * PAGE_SIZE; + kaddr = page_address(*xdr->page_ptr); + } + offset = xdr->p - (__be32 *)kaddr; + return base + (offset * sizeof(__be32)); +} + +/** * xdr_init_encode - Initialize a struct xdr_stream for sending data. * @xdr: pointer to xdr_stream struct * @buf: pointer to XDR buffer in which to encode data @@ -976,6 +1055,26 @@ unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len) } EXPORT_SYMBOL_GPL(xdr_read_pages); +size_t xdr_expand_hole(struct xdr_stream *xdr, size_t offset, size_t length) +{ + struct xdr_buf *buf = xdr->buf; + size_t from = 0; + + if ((offset + length) > buf->page_len) + length = buf->page_len - offset; + + if (offset == 0) + xdr_align_pages(xdr, xdr->nwords << 2); + else + from = xdr_page_pos(xdr); + + _shift_data_right(buf, offset + length, from, xdr->nwords << 2); + _zero_data_pages(buf->pages, buf->page_base + offset, length); + xdr_set_page(xdr, offset + length); + return length; +} +EXPORT_SYMBOL_GPL(xdr_expand_hole); + /** * xdr_enter_page - decode data from the XDR page * @xdr: pointer to xdr_stream struct