Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4566469rwl; Tue, 28 Mar 2023 08:28:51 -0700 (PDT) X-Google-Smtp-Source: AKy350aEFuQqX1LmFl519J1Ev1GTag4W9X7GoRVR4XeBKH1Wex0gAOWqC9klJ/fKVTKpv/clkkPb X-Received: by 2002:aa7:c790:0:b0:4fc:d837:2c44 with SMTP id n16-20020aa7c790000000b004fcd8372c44mr15657404eds.35.1680017330805; Tue, 28 Mar 2023 08:28:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680017330; cv=none; d=google.com; s=arc-20160816; b=CznGOyTTCrbqu7siPeEJIJ1erEP1Ke51ob0N7UCR2JlZ8mMiiLJDX1Nkb3ZIRMSDKv GuAZjfENluk4tP/YII0a1Zi2czkB/wptmMc58wmBHmogmYUWGH6ymy5QMfL3atpmN7xy t13LiFzkqsx62ujXTzDE13iI9ZPAwLkQOJKsV988gw0s1RO+i51hzLoVw3sf4qupF2AB 6She4k3g6pPtJAZ9IcqTczz+e+XRfQVtR4+wBKn/siuokTJNgCDtaeTsqF1cd38LJ7VM +2H/ELPteQSQrdb85BfPiu6akfYNw25PfXfjq02De18NS4I5XaNzozIB1ARo9yyCIwLr UOfg== 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=litTAfSrcuMc4HupIpacq5wCRTNFJAvtr6mPltpyGGw=; b=swFDgvWmZoA6tQgKc2dLAfRHML7OiDcioXC8/x54spGdSGI6Kfj2HcZsAIWdr1IBhS U1Fz1PFqEuLJ5uUUfumBjDjMD881WYTP0WTigNsI0DYL32eW8sKlpQKNnZtCcD947omM WQM4HY27FT7SgH0eRz1nmHKWrhNXRqYpo9Y9uL4cFySAxwEpreOWIoWphnV43G1jfN6D V+4s3X86+NfumO8Le3BF3jkaC9lbzbtrUW5on8Llw5VSBavG1pKeUwk8tPMeRgEYXI2U ZnypJ9YXgS3vmkzCZM5IeGCivIFTzFCU5Y2+9OLNCdt02jFSADIxPI/o3qUoSGAgPN3j hLEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UcP1YHm0; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r8-20020aa7d148000000b004c12b7f5a48si28452892edo.177.2023.03.28.08.28.24; Tue, 28 Mar 2023 08:28:50 -0700 (PDT) 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=UcP1YHm0; 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 S233304AbjC1PVb (ORCPT + 99 others); Tue, 28 Mar 2023 11:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233344AbjC1PVP (ORCPT ); Tue, 28 Mar 2023 11:21:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2929311678 for ; Tue, 28 Mar 2023 08:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680016681; 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=litTAfSrcuMc4HupIpacq5wCRTNFJAvtr6mPltpyGGw=; b=UcP1YHm0UEPIZRO1Fpb1sDRNUJxNuC0Y6ZMHr5Y+b0k3Lw8Q7ktfM5p81sEJlJLgmbB79c igEJw1kZee9mYQ0+OQgoQbIdcogcR/LMiK7Hc1Z3rsxSOEU9rxaBHAT/RvH/E9EkFRYX4W oEhoeJx6dDeuB8clcctl5sHGHLsXTcM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-akZKb0QuMtm2nodnVwiDcw-1; Tue, 28 Mar 2023 11:11:30 -0400 X-MC-Unique: akZKb0QuMtm2nodnVwiDcw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C7BB185A7A9; Tue, 28 Mar 2023 15:11:29 +0000 (UTC) Received: from localhost (ovpn-8-20.pek2.redhat.com [10.72.8.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7679E40B3EDA; Tue, 28 Mar 2023 15:11:28 +0000 (UTC) From: Ming Lei To: Jens Axboe , io-uring@vger.kernel.org, linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Miklos Szeredi , ZiyangZhang , Xiaoguang Wang , Bernd Schubert , Pavel Begunkov , Stefan Hajnoczi , Dan Williams , Ming Lei Subject: [PATCH V5 08/16] block: ublk_drv: add two helpers to clean up map/unmap request Date: Tue, 28 Mar 2023 23:09:50 +0800 Message-Id: <20230328150958.1253547-9-ming.lei@redhat.com> In-Reply-To: <20230328150958.1253547-1-ming.lei@redhat.com> References: <20230328150958.1253547-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-0.2 required=5.0 tests=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=unavailable 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 Add two helpers for checking if map/unmap is needed, since we may have passthrough request which needs map or unmap in future, such as for supporting report zones. Meantime don't mark ublk_copy_user_pages as inline since this function is a bit fat now. Reviewed-by: Ziyang Zhang Signed-off-by: Ming Lei --- drivers/block/ublk_drv.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index c73b2dba25ce..f87597a7d679 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -488,8 +488,7 @@ static inline unsigned ublk_copy_io_pages(struct ublk_io_iter *data, return done; } -static inline int ublk_copy_user_pages(struct ublk_map_data *data, - bool to_vm) +static int ublk_copy_user_pages(struct ublk_map_data *data, bool to_vm) { const unsigned int gup_flags = to_vm ? FOLL_WRITE : 0; const unsigned long start_vm = data->io->addr; @@ -525,6 +524,16 @@ static inline int ublk_copy_user_pages(struct ublk_map_data *data, return done; } +static inline bool ublk_need_map_req(const struct request *req) +{ + return ublk_rq_has_data(req) && req_op(req) == REQ_OP_WRITE; +} + +static inline bool ublk_need_unmap_req(const struct request *req) +{ + return ublk_rq_has_data(req) && req_op(req) == REQ_OP_READ; +} + static int ublk_map_io(const struct ublk_queue *ubq, const struct request *req, struct ublk_io *io) { @@ -535,7 +544,7 @@ static int ublk_map_io(const struct ublk_queue *ubq, const struct request *req, * context and the big benefit is that pinning pages in current * context is pretty fast, see ublk_pin_user_pages */ - if (ublk_rq_has_data(req) && req_op(req) == REQ_OP_WRITE) { + if (ublk_need_map_req(req)) { struct ublk_map_data data = { .ubq = ubq, .rq = req, @@ -556,7 +565,7 @@ static int ublk_unmap_io(const struct ublk_queue *ubq, { const unsigned int rq_bytes = blk_rq_bytes(req); - if (req_op(req) == REQ_OP_READ && ublk_rq_has_data(req)) { + if (ublk_need_unmap_req(req)) { struct ublk_map_data data = { .ubq = ubq, .rq = req, @@ -772,7 +781,7 @@ static inline void __ublk_rq_task_work(struct request *req, return; } - if (ublk_need_get_data(ubq) && (req_op(req) == REQ_OP_WRITE)) { + if (ublk_need_get_data(ubq) && ublk_need_map_req(req)) { /* * We have not handled UBLK_IO_NEED_GET_DATA command yet, * so immepdately pass UBLK_IO_RES_NEED_GET_DATA to ublksrv -- 2.39.2