Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3177865pxk; Mon, 28 Sep 2020 10:11:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqodOcyMZRPAG/n226m5KN+/gYM++R/uyhvsK2D9zh0pNJNEKlRVBiVCWMUg/ia8Nl4n8q X-Received: by 2002:a50:d987:: with SMTP id w7mr2886055edj.113.1601313076004; Mon, 28 Sep 2020 10:11:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601313075; cv=none; d=google.com; s=arc-20160816; b=U0rDpS812GSG70RYh7U5vsij1U+p9yfY3Ro/AEQKfJOXnfMsJKHYq7IKWGwVrofvo1 Ujto2jjYELJa0IjVwVyJoU91PPpuVIizbg6l3BATwnG0H5fEK90zfhM9Um56Vy+QLbIP UVhP2r6PTStnEgBnljSSmD9/tpBycfT8nCMuO5ExZtVBWsn5xltQMi9wybdvxtO+PuPV vRp5RfkbOE81NqwXNeFZKzaWLG2aipRPKxendlWiJDTzQG0PHOMcyUbzdK0p0mTsLSjO wDTL5YOfrz3tXNb65YDDXq67kfbJ/KRCDOtoiHNKsRKsPovbjSdQTIECtCU53rTYB6qx E7Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=igtPl6C6Gfbp4gxTezXs9k9ZWoIUbuf9BiavER35twk=; b=ErjW/qQ59WkZVe6kRZmQEnOIjBP93r4nCFbKSXGVh0Lt1mctSgibEDFkd+TGPN4Vsu vc+Sv6ewdQckD1hXMCrE/m0GyAeKI3ATTzqltuy/34oZs9N5kqBAQ9qkHSxfeqK40LH4 BwG1M4JAOF++uyEizS6V5Oc6NFON3OgZCdbqj3m559+Fmt11mb9afR+NQdQQMrdJpWyx rUCaJ/CF2A3rs5f0DE7wkfcUjS7enqfe2sJ5JDiRT248gEfmPYq5Y7Qc07yWp2RaWjHr 3L78roZeLhcXba3LWDzRlx/KujLlL19CQncIjnaigtsrQZVAicPh/7fHGuKdIJloovMi u2yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h8FzGESx; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id f23si1043450edm.413.2020.09.28.10.10.52; Mon, 28 Sep 2020 10:11:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h8FzGESx; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 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 S1726607AbgI1RJ3 (ORCPT + 99 others); Mon, 28 Sep 2020 13:09:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726596AbgI1RJ3 (ORCPT ); Mon, 28 Sep 2020 13:09:29 -0400 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA77BC061755 for ; Mon, 28 Sep 2020 10:09:28 -0700 (PDT) Received: by mail-qv1-xf41.google.com with SMTP id f11so826878qvw.3 for ; Mon, 28 Sep 2020 10:09:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=igtPl6C6Gfbp4gxTezXs9k9ZWoIUbuf9BiavER35twk=; b=h8FzGESx18UfpAGrmm6E5iD3H2nQ6XEnfHNfMYQFwQRZlaDND6Jektvv93VeNdZyNJ N3lTanuhJYOed1X9UpIKfY4heAMT+Ec1u5LW3OABb3pAHnvLy2M6+hXAJUO0AMipP50Y DaSHpj6/9XNEQt9ar28Uk+AyLN9QrcUItM5zmY9YtQBhWSTdO59Dqs0BSAZ9nYT5w5eP CTDPr48OhzYxHDY3kZZQv2ckCLXcFrkmfGABB9zOWDN1eL0MdekwpZlnW5scgaEtCHvv levlYmjRt7wVzRzGkgxz/5248tLfdTGjiKf2QbHoxAnOLGwSc9ms+9UaMBJOrscu6CPD KIcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=igtPl6C6Gfbp4gxTezXs9k9ZWoIUbuf9BiavER35twk=; b=Xzt/j8CcgmKq+yI08senczxZen9j2VyWTAY5ar9TgaBo8LDXyr+O+dJIcRwskpYA/7 E5F6+ujqrcYNk9rb5Cm9oJzqSvE0UkZG7p7xKnfIQl55kBZT2usNyBUYconds6oZl2An xlz0GM51CaXmVak+FERbSp+B1u0t8YSvPFv07gCJZWYVI+buceQssxZwiIB4St6yyupO DlIxUKTNDPlGfWsI0h+UvlroXkSJ4wWEGIrjOUMaC5yQdmRDDFsrFI5piJ0c0LaNqYXL +R8yfwxMR64w7jUsbXwP69awOYBomzI42XuWg1KtxXxWZ3CNus9aqHeDhVck1zEo8LPp atuw== X-Gm-Message-State: AOAM532Z3F/KXPyOb//x8EHzbHEUUfemP7Mw4tvpSgqKw7iIzs/eEZ4P bCsCior9LlgEoY8x3dpGu+G0q5FcsZk= X-Received: by 2002:a0c:c709:: with SMTP id w9mr558168qvi.26.1601312967648; Mon, 28 Sep 2020 10:09:27 -0700 (PDT) Received: from gouda.nowheycreamery.com (c-68-32-74-190.hsd1.mi.comcast.net. [68.32.74.190]) by smtp.gmail.com with ESMTPSA id 201sm1556862qkf.103.2020.09.28.10.09.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 10:09:27 -0700 (PDT) Sender: Anna Schumaker From: schumaker.anna@gmail.com X-Google-Original-From: Anna.Schumaker@Netapp.com To: linux-nfs@vger.kernel.org Cc: Anna.Schumaker@Netapp.com Subject: [PATCH v6 06/10] SUNRPC: Split out _shift_data_right_tail() Date: Mon, 28 Sep 2020 13:09:15 -0400 Message-Id: <20200928170919.707641-7-Anna.Schumaker@Netapp.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200928170919.707641-1-Anna.Schumaker@Netapp.com> References: <20200928170919.707641-1-Anna.Schumaker@Netapp.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Anna Schumaker xdr_shrink_pagelen() is very similar to what we need for hole expansion, so split out the common code into its own function that can be used by both functions. Signed-off-by: Anna Schumaker --- net/sunrpc/xdr.c | 68 +++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c index 70efb35c119e..d8c9555c6f2b 100644 --- a/net/sunrpc/xdr.c +++ b/net/sunrpc/xdr.c @@ -266,6 +266,46 @@ _shift_data_right_pages(struct page **pages, size_t pgto_base, } while ((len -= copy) != 0); } +static unsigned int +_shift_data_right_tail(struct xdr_buf *buf, unsigned int pgfrom, size_t len) +{ + struct kvec *tail = buf->tail; + unsigned int tailbuf_len; + unsigned int result = 0; + size_t copy; + + tailbuf_len = buf->buflen - buf->head->iov_len - buf->page_len; + + /* Shift the tail first */ + if (tailbuf_len != 0) { + unsigned int free_space = tailbuf_len - tail->iov_len; + + if (len < free_space) + free_space = len; + if (len > free_space) + len = free_space; + + tail->iov_len += free_space; + copy = len; + + if (tail->iov_len > len) { + char *p = (char *)tail->iov_base + len; + memmove(p, tail->iov_base, tail->iov_len - free_space); + result += tail->iov_len - free_space; + } else + copy = tail->iov_len; + + /* Copy from the inlined pages into the tail */ + _copy_from_pages((char *)tail->iov_base, + buf->pages, + buf->page_base + pgfrom, + copy); + result += copy; + } + + return result; +} + /** * _copy_to_pages * @pages: array of pages @@ -446,39 +486,13 @@ xdr_shrink_bufhead(struct xdr_buf *buf, size_t len) static unsigned int xdr_shrink_pagelen(struct xdr_buf *buf, size_t len) { - struct kvec *tail; - size_t copy; unsigned int pglen = buf->page_len; - unsigned int tailbuf_len; unsigned int result; - result = 0; - tail = buf->tail; if (len > buf->page_len) len = buf-> page_len; - tailbuf_len = buf->buflen - buf->head->iov_len - buf->page_len; - /* Shift the tail first */ - if (tailbuf_len != 0) { - unsigned int free_space = tailbuf_len - tail->iov_len; - - if (len < free_space) - free_space = len; - tail->iov_len += free_space; - - copy = len; - if (tail->iov_len > len) { - char *p = (char *)tail->iov_base + len; - memmove(p, tail->iov_base, tail->iov_len - len); - result += tail->iov_len - len; - } else - copy = tail->iov_len; - /* Copy from the inlined pages into the tail */ - _copy_from_pages((char *)tail->iov_base, - buf->pages, buf->page_base + pglen - len, - copy); - result += copy; - } + result = _shift_data_right_tail(buf, pglen - len, len); buf->page_len -= len; buf->buflen -= len; /* Have we truncated the message? */ -- 2.28.0