From patchwork Tue Feb 14 08:37:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 56767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2846634wrn; Tue, 14 Feb 2023 00:46:27 -0800 (PST) X-Google-Smtp-Source: AK7set9UbDxHt5zixBErbU5zkIYBRaOnM070bowqQtfv0LZ/QIz/a4kXVYyMMMPhaS6jHsJpAeUq X-Received: by 2002:a50:d494:0:b0:4ac:d30d:c3a3 with SMTP id s20-20020a50d494000000b004acd30dc3a3mr1495050edi.32.1676364387728; Tue, 14 Feb 2023 00:46:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676364387; cv=none; d=google.com; s=arc-20160816; b=qTGf/5BffoNWI3ZupRSXJRjDFOM/Y0mkqGqCuMkUJoG6Zywut3M7ZclxSaqz81JHca 6XFlFNrPGDO6nPbRacR/Fm01y1RUq82n4W5mtPhFNTf5HgU2UqX/iTky5/q7tG8yXhbL T08/1Joa0UbC0A/nreWcl/GO1Ro+a4w8XSdAD/3pgeMu1OMmDuBN7LopNGWId2mu0iaj 5oUDgFUs+zETxz9PA1zxpuJ3vrCU6VMH4sIMimqw3tIwSrEwGkpUOZQJrFDBPat/JKf+ kYEFEg5ThNPiHw4nwrdVrwgz2VyGi6usl+/UYuTUy2w/7zXOVMScxb3mZ6UgHOxOVnK3 N8EQ== 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 :dkim-signature; bh=+b2VMeGpZTyrheqYPKTaHyxDIQ3yZeSE4YqjD4ZyLaI=; b=CJwIIbMcN9h2kKK8krDJFHj/71HfCyriR7O3cgFLbs4Vv0Ml97xJ5K5umAqSrwOEat trgAzcE/tRDK6SolibR96IQakkUDIJah8+Arfw0AcP+tk/vBbPQP6n4obY9TRkdypfAE ZvLBUv3q11CztfcF6nUr9D05B5v3KFQDQtEe/pqb5WHBHzMWkhhfxlHKSsTmzhPQjyD4 /+OR6SZdFG4Sa1mueJKZeMFHp905T9t5IBwFe6do/VM980scaicfrBuZutiupVjGpN/f b42ETRa76YHiDO/3/4avOWJJgDAFeT9v7bFSjSFO2yDPNQWGYynEI+oVEDz4pRuWvwV5 Bx4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B42Yq0mS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020aa7dc14000000b004aac4b55319si15896241edu.480.2023.02.14.00.46.04; Tue, 14 Feb 2023 00:46:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B42Yq0mS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232059AbjBNIiw (ORCPT + 99 others); Tue, 14 Feb 2023 03:38:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232045AbjBNIir (ORCPT ); Tue, 14 Feb 2023 03:38:47 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6194CDBE8 for ; Tue, 14 Feb 2023 00:37:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676363847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+b2VMeGpZTyrheqYPKTaHyxDIQ3yZeSE4YqjD4ZyLaI=; b=B42Yq0mS1jT2+5yCTMZ9rNQMBeM+wEBBt38IY7prjxI6UEAlX0OZNSvX0wbGyLlkxqscSs 6PdRQ7hXUqxui/Stgdc3aGGYz0Szc7ZAyiFnJpdzUrQpqxpguNsv2BAtnWfWpJtyI6dOQ6 NS4EHg+3qbv/BJQHiFM7x4vxOUns+RM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-225-1sNGJShAP3avneZS4IyFGA-1; Tue, 14 Feb 2023 03:37:26 -0500 X-MC-Unique: 1sNGJShAP3avneZS4IyFGA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8859E3811F2C; Tue, 14 Feb 2023 08:37:25 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B3BFC15BA0; Tue, 14 Feb 2023 08:37:23 +0000 (UTC) From: David Howells To: Jens Axboe , Al Viro , Christoph Hellwig Cc: David Howells , Matthew Wilcox , Jan Kara , Jeff Layton , David Hildenbrand , Jason Gunthorpe , Logan Gunthorpe , Hillf Danton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig , John Hubbard Subject: [PATCH v3 2/5] splice: Provide pipe_head_buf() helper Date: Tue, 14 Feb 2023 08:37:07 +0000 Message-Id: <20230214083710.2547248-3-dhowells@redhat.com> In-Reply-To: <20230214083710.2547248-1-dhowells@redhat.com> References: <20230214083710.2547248-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757795464132267415?= X-GMAIL-MSGID: =?utf-8?q?1757795464132267415?= Provide a helper, pipe_head_buf(), to get the current head buffer from a pipe. Implement this as a wrapper around a more general function, pipe_buf(), that gets a specified buffer. Requested-by: Christoph Hellwig Signed-off-by: David Howells Reviewed-by: Christoph Hellwig cc: Jens Axboe cc: Al Viro cc: John Hubbard cc: David Hildenbrand cc: Matthew Wilcox cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/splice.c | 9 +++------ include/linux/pipe_fs_i.h | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 91b9e2cb9e03..7c0ff187f87a 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -295,7 +295,6 @@ static ssize_t direct_splice_read(struct file *in, loff_t *ppos, struct bio_vec *bv; struct kiocb kiocb; struct page **pages; - unsigned int head; ssize_t ret; size_t used, npages, chunk, remain, reclaim; int i; @@ -358,9 +357,8 @@ static ssize_t direct_splice_read(struct file *in, loff_t *ppos, } /* Push the remaining pages into the pipe. */ - head = pipe->head; for (i = 0; i < npages; i++) { - struct pipe_buffer *buf = &pipe->bufs[head & (pipe->ring_size - 1)]; + struct pipe_buffer *buf = pipe_head_buf(pipe); chunk = min_t(size_t, remain, PAGE_SIZE); *buf = (struct pipe_buffer) { @@ -369,10 +367,9 @@ static ssize_t direct_splice_read(struct file *in, loff_t *ppos, .offset = 0, .len = chunk, }; - head++; + pipe->head++; remain -= chunk; } - pipe->head = head; kfree(bv); return ret; @@ -394,7 +391,7 @@ static size_t splice_folio_into_pipe(struct pipe_inode_info *pipe, while (spliced < size && !pipe_full(pipe->head, pipe->tail, pipe->max_usage)) { - struct pipe_buffer *buf = &pipe->bufs[pipe->head & (pipe->ring_size - 1)]; + struct pipe_buffer *buf = pipe_head_buf(pipe); size_t part = min_t(size_t, PAGE_SIZE - offset, size - spliced); *buf = (struct pipe_buffer) { diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index 6cb65df3e3ba..d2c3f16cf6b1 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -156,6 +156,26 @@ static inline bool pipe_full(unsigned int head, unsigned int tail, return pipe_occupancy(head, tail) >= limit; } +/** + * pipe_buf - Return the pipe buffer for the specified slot in the pipe ring + * @pipe: The pipe to access + * @slot: The slot of interest + */ +static inline struct pipe_buffer *pipe_buf(const struct pipe_inode_info *pipe, + unsigned int slot) +{ + return &pipe->bufs[slot & (pipe->ring_size - 1)]; +} + +/** + * pipe_head_buf - Return the pipe buffer at the head of the pipe ring + * @pipe: The pipe to access + */ +static inline struct pipe_buffer *pipe_head_buf(const struct pipe_inode_info *pipe) +{ + return pipe_buf(pipe, pipe->head); +} + /** * pipe_buf_get - get a reference to a pipe_buffer * @pipe: the pipe that the buffer belongs to