Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3503681pxb; Mon, 24 Jan 2022 10:56:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyG3s+49wdonoofQ/9ZCKua8ouauvSzKZtl/7Mpgf8A+3x38EfoqpEoLqS07Be9u0mxLPla X-Received: by 2002:a62:5211:0:b0:4bc:c949:ae8d with SMTP id g17-20020a625211000000b004bcc949ae8dmr15391051pfb.26.1643050579356; Mon, 24 Jan 2022 10:56:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643050579; cv=none; d=google.com; s=arc-20160816; b=sSRtPNgwMQQqCZqrT6bgvI6eDUQ8JmBawf4eR0Dk7K9WcBmCcB5Dng7KtE0yMV0H4H fPBltqo3M2J+/0h/aQsArgHUzwK3TFr4ZF5ewL7OYeRwOkcPNILYNUH5/UfyHPQGoFCu GcarGX+iajIappfh5Kw5WA/BVwBFi+j1l8Xu1js3rUpZ9v9uC6PdPKICVTnSN7BT9Fnh jpENL4s62XfJ0PNRYz008dYQKIxAWt2uMSP6Yo5gCGZIS1Un9y66jsY45lFemhdwGrpr PWdd6z9jeAYUcSwlx0cVCKblKOjfw6Knllr17cyKGYu+WAPtvJSzmsDGte/m0h3W3EQS /X1A== 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=zTiOqFQyhHqguPQ678Zaf9btDaCC9p/oqBHpvCY61VM=; b=Y4NWhQeyp6QjdW6oQUUUTvlZsswhlwgAVjMTKyFcbmhHVyZiUEFe4BQqtjb+kM654V DIhgoXD4uZ53bVCTMQVIiSJKnVxl9MkoVM+03U5mjUMrskH0od4CuhfsIvbMOXSBiGdp k0KKmHJsVy2jVHaSK/Hhpx5mKBfp03EwzgO/BfNJx8J+1D875NzA3QMIZtOJ/OkPyVE/ omwAxG2xqXfjHHOzPJWqwgCXud5Fd4iXAUq5gMyF54l82Fvj9FnsTGlI18FpHL9ox0rq DdHKONVKUPrAFBJzB6OpShx6D3oLCcoQJn6oT0YFa1N+LJG5J2EmPBUR2OxsciTnD+bq Mgmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=DLsazqu1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z3si11560162pla.559.2022.01.24.10.56.06; Mon, 24 Jan 2022 10:56:19 -0800 (PST) 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=@infradead.org header.s=bombadil.20210309 header.b=DLsazqu1; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236647AbiAXJLw (ORCPT + 99 others); Mon, 24 Jan 2022 04:11:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236514AbiAXJLo (ORCPT ); Mon, 24 Jan 2022 04:11:44 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B8D9C061401; Mon, 24 Jan 2022 01:11:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=zTiOqFQyhHqguPQ678Zaf9btDaCC9p/oqBHpvCY61VM=; b=DLsazqu1zmz3g/ZUEQDTQ2VMur poc51f3+HV2y+P4Uu24nVRS8tSMYoAm0DDJM1GqOyqbQ5OvqtD5jzYX6TWeohojJ31J+PhTLBj7kP I7ExgXt+TwpSuiufrxi3XK8FXJJ31LbbT1wxYW6K/RQKAHhscZtCiiUF3X5E5yG0uS4sim2kDFkqQ VkaOcFhxuEUDFEkQCQn3jyAq5xJJUq9RvpI7XdVgDOAJfonm1JdXofbZEOPPThlerJSHMD3vBAu7N MXEwm4MA3sSOZ7xheQb489RCslkMFty7jdqqkSilh68MAG/wk6sJ+lDEjFLtZ9lIgY/ock1JVgfVf 9uGID8dg==; Received: from [2001:4bb8:184:72a4:a337:a75f:a24e:7e39] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nBvNx-002kCs-4t; Mon, 24 Jan 2022 09:11:37 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Pavel Begunkov , Mike Snitzer , Ryusuke Konishi , Konstantin Komarov , Andrew Morton , "Md . Haris Iqbal " , Jack Wang , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Philipp Reisner , Lars Ellenberg , linux-block@vger.kernel.org, dm-devel@redhat.com, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-nilfs@vger.kernel.org, ntfs3@lists.linux.dev, xen-devel@lists.xenproject.org, drbd-dev@lists.linbit.com, Jack Wang Subject: [PATCH 10/19] rnbd-srv: simplify bio mapping in process_rdma Date: Mon, 24 Jan 2022 10:10:58 +0100 Message-Id: <20220124091107.642561-11-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124091107.642561-1-hch@lst.de> References: <20220124091107.642561-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The memory mapped in process_rdma is contiguous, so there is no need to loop over bio_add_page. Remove rnbd_bio_map_kern and just open code the bio allocation and mapping in the caller. Signed-off-by: Christoph Hellwig Reviewed-by: Jack Wang Tested-by: Jack Wang --- drivers/block/rnbd/rnbd-srv-dev.c | 57 ------------------------------- drivers/block/rnbd/rnbd-srv-dev.h | 5 --- drivers/block/rnbd/rnbd-srv.c | 23 +++++++++---- 3 files changed, 16 insertions(+), 69 deletions(-) diff --git a/drivers/block/rnbd/rnbd-srv-dev.c b/drivers/block/rnbd/rnbd-srv-dev.c index b241a099aeae2..98d3e591a0885 100644 --- a/drivers/block/rnbd/rnbd-srv-dev.c +++ b/drivers/block/rnbd/rnbd-srv-dev.c @@ -44,60 +44,3 @@ void rnbd_dev_close(struct rnbd_dev *dev) blkdev_put(dev->bdev, dev->blk_open_flags); kfree(dev); } - -void rnbd_dev_bi_end_io(struct bio *bio) -{ - struct rnbd_dev_blk_io *io = bio->bi_private; - - rnbd_endio(io->priv, blk_status_to_errno(bio->bi_status)); - bio_put(bio); -} - -/** - * rnbd_bio_map_kern - map kernel address into bio - * @data: pointer to buffer to map - * @bs: bio_set to use. - * @len: length in bytes - * @gfp_mask: allocation flags for bio allocation - * - * Map the kernel address into a bio suitable for io to a block - * device. Returns an error pointer in case of error. - */ -struct bio *rnbd_bio_map_kern(void *data, struct bio_set *bs, - unsigned int len, gfp_t gfp_mask) -{ - unsigned long kaddr = (unsigned long)data; - unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT; - unsigned long start = kaddr >> PAGE_SHIFT; - const int nr_pages = end - start; - int offset, i; - struct bio *bio; - - bio = bio_alloc_bioset(gfp_mask, nr_pages, bs); - if (!bio) - return ERR_PTR(-ENOMEM); - - offset = offset_in_page(kaddr); - for (i = 0; i < nr_pages; i++) { - unsigned int bytes = PAGE_SIZE - offset; - - if (len <= 0) - break; - - if (bytes > len) - bytes = len; - - if (bio_add_page(bio, virt_to_page(data), bytes, - offset) < bytes) { - /* we don't support partial mappings */ - bio_put(bio); - return ERR_PTR(-EINVAL); - } - - data += bytes; - len -= bytes; - offset = 0; - } - - return bio; -} diff --git a/drivers/block/rnbd/rnbd-srv-dev.h b/drivers/block/rnbd/rnbd-srv-dev.h index 0eb23850afb95..1a14ece0be726 100644 --- a/drivers/block/rnbd/rnbd-srv-dev.h +++ b/drivers/block/rnbd/rnbd-srv-dev.h @@ -41,11 +41,6 @@ void rnbd_dev_close(struct rnbd_dev *dev); void rnbd_endio(void *priv, int error); -void rnbd_dev_bi_end_io(struct bio *bio); - -struct bio *rnbd_bio_map_kern(void *data, struct bio_set *bs, - unsigned int len, gfp_t gfp_mask); - static inline int rnbd_dev_get_max_segs(const struct rnbd_dev *dev) { return queue_max_segments(bdev_get_queue(dev->bdev)); diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index 1ee808fc600cf..6d228af1dcc35 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -114,6 +114,14 @@ rnbd_get_sess_dev(int dev_id, struct rnbd_srv_session *srv_sess) return sess_dev; } +static void rnbd_dev_bi_end_io(struct bio *bio) +{ + struct rnbd_dev_blk_io *io = bio->bi_private; + + rnbd_endio(io->priv, blk_status_to_errno(bio->bi_status)); + bio_put(bio); +} + static int process_rdma(struct rnbd_srv_session *srv_sess, struct rtrs_srv_op *id, void *data, u32 datalen, const void *usr, size_t usrlen) @@ -144,12 +152,12 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, priv->sess_dev = sess_dev; priv->id = id; - /* Generate bio with pages pointing to the rdma buffer */ - bio = rnbd_bio_map_kern(data, sess_dev->rnbd_dev->ibd_bio_set, datalen, GFP_KERNEL); - if (IS_ERR(bio)) { - err = PTR_ERR(bio); - rnbd_srv_err(sess_dev, "Failed to generate bio, err: %d\n", err); - goto sess_dev_put; + bio = bio_alloc_bioset(GFP_KERNEL, 1, sess_dev->rnbd_dev->ibd_bio_set); + if (bio_add_page(bio, virt_to_page(data), datalen, + offset_in_page(data)) != datalen) { + rnbd_srv_err(sess_dev, "Failed to map data to bio\n"); + err = -EINVAL; + goto bio_put; } io = container_of(bio, struct rnbd_dev_blk_io, bio); @@ -170,7 +178,8 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, return 0; -sess_dev_put: +bio_put: + bio_put(bio); rnbd_put_sess_dev(sess_dev); err: kfree(priv); -- 2.30.2