Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2023936pxb; Sat, 21 Nov 2020 06:18:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzcv87FPUdfRRApYHhNkohHTqBddLIMw2zyJZkKbcu6u+tZJ3q9uGo4JSJNWvuLFdBZbKi X-Received: by 2002:a05:6402:1cb8:: with SMTP id cz24mr16072372edb.34.1605968322161; Sat, 21 Nov 2020 06:18:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605968322; cv=none; d=google.com; s=arc-20160816; b=SZMQxBUnNkUmdU9A2VI5cufIK/BBpKSfHfu5iDFCRjxWwNwpDRiOfsZkPtQGX1g5LD l1oS6lONgxW6tbcC7kuq0Ea75EzzHULgZJJq+7CF7bt4LGqMO3rSKXJ8chtFnz0INP/h yX1kNSayVx0f8Uq4Tt/Hv+OL4l4vmr8ySS0Kz9eKB8Flc2+bxwOYBX3q76IS4h/VNieG ctvbMTmgFVtFwZVYVsbIe2iPlvMROl4NhHvlASSW3ivMTs2tc8nQ7Z3OAyb3qVZ/faV/ Um0r0Z63ivaCcQA/Iry9ZBq1gcCGr1ICm0EAT6OIjgtJSZG/oD4WfvMZuBcSn8xqqofH 13lg== 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 :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=XP3mnUJc4mxTb6vHs3+R4NsGbX5N4I46o5CgY2C0v48=; b=ew0S6YecAtp3OGrC+FuxMZb2/6I8i6RcKuu3RQT5sstrgZ5hr0HG/aCVnz3Bg2SX67 CaqdFMACKz8WAEHKO3A3IhN/3WELAAFmhnGE9Wl2fekevbCTKKwP7aZnFfKBY10tExmC n9PIWfieJ0WMV9ksIa0odryY3sArbMMYh1UiCgjyHFkHEGKCvuyJwKMa3ZtRsOu/evtz UQzmKh5WWtYLOdafuLdoyWmWn3ifij+Iff/3WGTIngtA3cIAA2KmzKLU/QTHlN1xpoat gJ/mHI04yZJsVl4VfF+zZQ3ZzqJ23ZD7F6i0RIRBM9Hv8t3zoqmOQsmt9HDuJInQSQsp nYfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Ch+8c9/g"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si2522611edv.147.2020.11.21.06.18.20; Sat, 21 Nov 2020 06:18:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@redhat.com header.s=mimecast20190719 header.b="Ch+8c9/g"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728268AbgKUOPx (ORCPT + 99 others); Sat, 21 Nov 2020 09:15:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48379 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728225AbgKUOPw (ORCPT ); Sat, 21 Nov 2020 09:15:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605968151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XP3mnUJc4mxTb6vHs3+R4NsGbX5N4I46o5CgY2C0v48=; b=Ch+8c9/g6nk1ASmSVQfE8lw8k8EwV6GCSBLBSgzVYMebJ8ZMsWftEtUAf6kjO88K/hE7gv Np3lVw+cyRWDEl6ZMLeIYIJeshxQSkgnayyHUtc9EI6u2apHKvVsUA5yhF8cwIkvMz6e7a HMPF0+ZwDZaTOecIx2cNnjTSPoxUkpE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-253-W_XtH6zlM8uyYu3poeiBQw-1; Sat, 21 Nov 2020 09:15:46 -0500 X-MC-Unique: W_XtH6zlM8uyYu3poeiBQw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 469471DDE8; Sat, 21 Nov 2020 14:15:45 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-112-246.rdu2.redhat.com [10.10.112.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70A4C5D6CF; Sat, 21 Nov 2020 14:15:43 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 18/29] iov_iter: Split iov_iter_single_seg_count() From: David Howells To: Pavel Begunkov , Matthew Wilcox , Jens Axboe , Alexander Viro Cc: dhowells@redhat.com, Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sat, 21 Nov 2020 14:15:42 +0000 Message-ID: <160596814260.154728.8650477861968611110.stgit@warthog.procyon.org.uk> In-Reply-To: <160596800145.154728.7192318545120181269.stgit@warthog.procyon.org.uk> References: <160596800145.154728.7192318545120181269.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split iov_iter_single_seg_count() by type. Signed-off-by: David Howells --- lib/iov_iter.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index b8e3da20547e..90291188ace5 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1415,18 +1415,23 @@ static void discard_revert(struct iov_iter *i, size_t unroll) /* * Return the count of just the current iov_iter segment. */ -static size_t xxx_single_seg_count(const struct iov_iter *i) +static size_t iovec_kvec_single_seg_count(const struct iov_iter *i) { - if (unlikely(iov_iter_is_pipe(i))) - return i->count; // it is a silly place, anyway if (i->nr_segs == 1) return i->count; - if (unlikely(iov_iter_is_discard(i))) + return min(i->count, i->iov->iov_len - i->iov_offset); +} + +static size_t bvec_single_seg_count(const struct iov_iter *i) +{ + if (i->nr_segs == 1) return i->count; - else if (iov_iter_is_bvec(i)) - return min(i->count, i->bvec->bv_len - i->iov_offset); - else - return min(i->count, i->iov->iov_len - i->iov_offset); + return min(i->count, i->bvec->bv_len - i->iov_offset); +} + +static size_t simple_single_seg_count(const struct iov_iter *i) +{ + return i->count; } void iov_iter_kvec(struct iov_iter *i, unsigned int direction, @@ -2110,7 +2115,7 @@ static const struct iov_iter_ops iovec_iter_ops = { .advance = iovec_advance, .revert = iovec_kvec_revert, .fault_in_readable = iovec_fault_in_readable, - .single_seg_count = xxx_single_seg_count, + .single_seg_count = iovec_kvec_single_seg_count, .copy_page_to_iter = iovec_copy_page_to_iter, .copy_page_from_iter = iovec_copy_page_from_iter, .copy_to_iter = iovec_copy_to_iter, @@ -2144,7 +2149,7 @@ static const struct iov_iter_ops kvec_iter_ops = { .advance = kvec_advance, .revert = iovec_kvec_revert, .fault_in_readable = no_fault_in_readable, - .single_seg_count = xxx_single_seg_count, + .single_seg_count = iovec_kvec_single_seg_count, .copy_page_to_iter = bkvec_copy_page_to_iter, .copy_page_from_iter = bkvec_copy_page_from_iter, .copy_to_iter = kvec_copy_to_iter, @@ -2178,7 +2183,7 @@ static const struct iov_iter_ops bvec_iter_ops = { .advance = bvec_iov_advance, .revert = bvec_revert, .fault_in_readable = no_fault_in_readable, - .single_seg_count = xxx_single_seg_count, + .single_seg_count = bvec_single_seg_count, .copy_page_to_iter = bkvec_copy_page_to_iter, .copy_page_from_iter = bkvec_copy_page_from_iter, .copy_to_iter = bvec_copy_to_iter, @@ -2212,7 +2217,7 @@ static const struct iov_iter_ops pipe_iter_ops = { .advance = pipe_advance, .revert = pipe_revert, .fault_in_readable = no_fault_in_readable, - .single_seg_count = xxx_single_seg_count, + .single_seg_count = simple_single_seg_count, .copy_page_to_iter = pipe_copy_page_to_iter, .copy_page_from_iter = no_copy_page_from_iter, .copy_to_iter = pipe_copy_to_iter, @@ -2246,7 +2251,7 @@ static const struct iov_iter_ops discard_iter_ops = { .advance = discard_advance, .revert = discard_revert, .fault_in_readable = no_fault_in_readable, - .single_seg_count = xxx_single_seg_count, + .single_seg_count = simple_single_seg_count, .copy_page_to_iter = discard_copy_page_to_iter, .copy_page_from_iter = no_copy_page_from_iter, .copy_to_iter = discard_copy_to_iter,