Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2478902pxa; Mon, 17 Aug 2020 10:34:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6jAQSBoOJJqI0Sk91OnOe2tVGBnf1ocrvwNNKt7V9/OePw4RlICOzJQJtBumQkB2wGhH3 X-Received: by 2002:a17:906:386:: with SMTP id b6mr15903399eja.538.1597685662812; Mon, 17 Aug 2020 10:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597685662; cv=none; d=google.com; s=arc-20160816; b=ZJ4pSDRQnQ2dnPTSGJFycXCiKQvaSqiSBVbYlxgiQdzEOv0brUkpRhP0W/9KkGbL0I IbuAeGEoYg3HW38R8izHKsXSkhPqjQOB8gD3pqe8bMmzfryJm1PV0SJrklLk8vY0WA45 22JyCij9OwEFrq3G89PnXKDNxUnm3zhogAvil2rdfL4J/74uEZ5OrNTEJAoPmiD+1I2D zZjW2bEioF0VGtAKoGsr0P4S5ZzkztIgQiASNPtxxZh6uwRrS0+LQtFE1+Q+rl7ILmzE inPe6Cdc3JOlhaKEl4oUUl+bpJJVLbBeC95lNehIsm7zmogdWDQcZ7rWagHiD7iVPM0y No+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=igtPl6C6Gfbp4gxTezXs9k9ZWoIUbuf9BiavER35twk=; b=0AGGqTQehVPhREVdaPR1CfvhkLBJs81kCiSYV4JVOYkYgdtRAjghrYtrT3RAr2dh9R xMZWZX9qq/HA6jdj1ePD2lmHgqPclne8k9HM8LH7lZ0s5mVu6x8yFivlGHPytG4w7hJa 4AFN3BwWpPCAiGGl7mwMwQsrvh0zQVcuNlRoWwZZQOOjb8gWwzeWM7E2HZz/+mLAwHHk 7u4D/LvT9LjqYx3lHVlHoatSnKd1QDbYBeKREYqX2FHRJsjvy2zFnLvjTqpHX6R3Rf8o DXyZ7gZS3CQmii+ybqcAYwQrHCD8BA9omHuXFpn+7h1FT2zzuQ9roDMtqHSekOdBjoWx 257Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=l6tJiV94; 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=fail (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 dc6si10386624ejb.271.2020.08.17.10.33.58; Mon, 17 Aug 2020 10:34:22 -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=fail header.i=@gmail.com header.s=20161025 header.b=l6tJiV94; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389111AbgHQRdT (ORCPT + 99 others); Mon, 17 Aug 2020 13:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389031AbgHQQx7 (ORCPT ); Mon, 17 Aug 2020 12:53:59 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0405BC061350 for ; Mon, 17 Aug 2020 09:53:36 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id s189so18342886iod.2 for ; Mon, 17 Aug 2020 09:53:35 -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=l6tJiV94mBsIvprRfO5B9/2n2RdWmhvF/tW70Z8gHF/htpDCDydIKo9MxYmAeumGAW ziCAnHKVorsee0OpROsctkVp2Y3J5NH+yhkXTenvQKWRXO2oPLu4zO48c5inZAZMfxtC OujirCLAbXOo9D+tEbuStlebnJ9RqjPgL8gjJmNblUwkUG9rs1oAwmctW4aWWd6WKjXr KgNdDeF6TT7GoAMSvYlUs7QcXFrAqkoi5mpSRgF0VgWXL8ufvr9fJ9Qzf+hIeoWHZOhH J7Hk9m67qMDLryDg2aNJJQpXC6lJtYI2IS7ShOQYBNba5MTRaneZS8sYxTSES/HTVAt3 qnqA== 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=l06RNM5NShdMBRodeaZSDZBgc+DakMGxWLvkGK6jRbWZMCETptm41hgjuhrliQ5KF3 2v+B6KB85YFLCg3n7fQQ0xJrTcECTNmoFNIOE1klEzjwJ5ua2RpH5UL/UIwfYpU0ErTr Z83ZvLGt/g22rNnQfuJRMRiV4JQbE7/RkPeVObHyUGzIxGmPQbldfA7eqq3OBM7YK9qR OT67eST+5j35HY9dYT33SPODPIVw3BWUoPO3Z03YizRHhAnrPiyi3nDKpR9fx6DEWqTG nUJPoi25EOK4AyuzmfszW8cb8WeDqq8Q8JmTiKKBZR3Q0LjPUPrV8c+hRSq0OdNW9X5x k0Xw== X-Gm-Message-State: AOAM53221pLzkkyfDTgEkmaygQkZKwzCGXRs3PbqujSKhcqmFc0zPXGM URsH/829m72Z9RUZXIG9KhrBIwrxMuk= X-Received: by 2002:a05:6638:1a7:: with SMTP id b7mr15156618jaq.1.1597683215032; Mon, 17 Aug 2020 09:53:35 -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 a16sm7413106ilc.7.2020.08.17.09.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 09:53:34 -0700 (PDT) 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 v4 06/10] SUNRPC: Split out _shift_data_right_tail() Date: Mon, 17 Aug 2020 12:53:23 -0400 Message-Id: <20200817165327.354181-7-Anna.Schumaker@Netapp.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817165327.354181-1-Anna.Schumaker@Netapp.com> References: <20200817165327.354181-1-Anna.Schumaker@Netapp.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-nfs-owner@vger.kernel.org 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