public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: "Juergen Gross" <jgross@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Boris Ostrovsky" <boris.ostrovsky@oracle.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Jens Axboe" <axboe@kernel.dk>
Subject: [PATCH v3 13/21] xen/blkfront: use xenbus_setup_ring() and xenbus_teardown_ring()
Date: Thu,  5 May 2022 10:16:32 +0200	[thread overview]
Message-ID: <20220505081640.17425-14-jgross@suse.com> (raw)
In-Reply-To: <20220505081640.17425-1-jgross@suse.com>

Simplify blkfront's ring creation and removal via xenbus_setup_ring()
and xenbus_teardown_ring().

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 drivers/block/xen-blkfront.c | 37 ++++++++----------------------------
 1 file changed, 8 insertions(+), 29 deletions(-)

diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 7f35e30e626a..bd7b34f29193 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -1280,15 +1280,8 @@ static void blkif_free_ring(struct blkfront_ring_info *rinfo)
 	flush_work(&rinfo->work);
 
 	/* Free resources associated with old device channel. */
-	for (i = 0; i < info->nr_ring_pages; i++) {
-		if (rinfo->ring_ref[i] != INVALID_GRANT_REF) {
-			gnttab_end_foreign_access(rinfo->ring_ref[i], 0);
-			rinfo->ring_ref[i] = INVALID_GRANT_REF;
-		}
-	}
-	free_pages_exact(rinfo->ring.sring,
-			 info->nr_ring_pages * XEN_PAGE_SIZE);
-	rinfo->ring.sring = NULL;
+	xenbus_teardown_ring((void **)&rinfo->ring.sring, info->nr_ring_pages,
+			     rinfo->ring_ref);
 
 	if (rinfo->irq)
 		unbind_from_irqhandler(rinfo->irq, rinfo);
@@ -1679,30 +1672,16 @@ static int setup_blkring(struct xenbus_device *dev,
 			 struct blkfront_ring_info *rinfo)
 {
 	struct blkif_sring *sring;
-	int err, i;
+	int err;
 	struct blkfront_info *info = rinfo->dev_info;
 	unsigned long ring_size = info->nr_ring_pages * XEN_PAGE_SIZE;
-	grant_ref_t gref[XENBUS_MAX_RING_GRANTS];
-
-	for (i = 0; i < info->nr_ring_pages; i++)
-		rinfo->ring_ref[i] = INVALID_GRANT_REF;
 
-	sring = alloc_pages_exact(ring_size, GFP_NOIO);
-	if (!sring) {
-		xenbus_dev_fatal(dev, -ENOMEM, "allocating shared ring");
-		return -ENOMEM;
-	}
-	SHARED_RING_INIT(sring);
-	FRONT_RING_INIT(&rinfo->ring, sring, ring_size);
-
-	err = xenbus_grant_ring(dev, rinfo->ring.sring, info->nr_ring_pages, gref);
-	if (err < 0) {
-		free_pages_exact(sring, ring_size);
-		rinfo->ring.sring = NULL;
+	err = xenbus_setup_ring(dev, GFP_NOIO, (void **)&sring,
+				info->nr_ring_pages, rinfo->ring_ref);
+	if (err)
 		goto fail;
-	}
-	for (i = 0; i < info->nr_ring_pages; i++)
-		rinfo->ring_ref[i] = gref[i];
+
+	XEN_FRONT_RING_INIT(&rinfo->ring, sring, ring_size);
 
 	err = xenbus_alloc_evtchn(dev, &rinfo->evtchn);
 	if (err)
-- 
2.35.3


  parent reply	other threads:[~2022-05-05  8:18 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05  8:16 [PATCH v3 00/21] xen: simplify frontend side ring setup Juergen Gross
2022-05-05  8:16 ` [PATCH v3 01/21] xen: update grant_table.h Juergen Gross
2022-05-05  8:16 ` [PATCH v3 02/21] xen/grant-table: never put a reserved grant on the free list Juergen Gross
2022-05-05  8:16 ` [PATCH v3 03/21] xen/blkfront: switch blkfront to use INVALID_GRANT_REF Juergen Gross
2022-05-09  8:20   ` Roger Pau Monné
2022-05-05  8:16 ` [PATCH v3 04/21] xen/netfront: switch netfront " Juergen Gross
2022-05-05  8:16 ` [PATCH v3 05/21] xen/scsifront: remove unused GRANT_INVALID_REF definition Juergen Gross
2022-05-05  8:16 ` [PATCH v3 06/21] xen/usb: switch xen-hcd to use INVALID_GRANT_REF Juergen Gross
2022-05-05  8:16 ` [PATCH v3 07/21] xen/drm: switch xen_drm_front " Juergen Gross
2022-05-05  8:16 ` [PATCH v3 08/21] xen/sound: switch xen_snd_front " Juergen Gross
2022-05-05  8:16 ` [PATCH v3 09/21] xen/dmabuf: switch gntdev-dmabuf " Juergen Gross
2022-05-05  8:16 ` [PATCH v3 10/21] xen/shbuf: switch xen-front-pgdir-shbuf " Juergen Gross
2022-05-09  8:47   ` Oleksandr
2022-05-05  8:16 ` [PATCH v3 11/21] xen: update ring.h Juergen Gross
2022-05-05  8:16 ` [PATCH v3 12/21] xen/xenbus: add xenbus_setup_ring() service function Juergen Gross
2022-05-05  8:16 ` Juergen Gross [this message]
2022-05-09  8:42   ` [PATCH v3 13/21] xen/blkfront: use xenbus_setup_ring() and xenbus_teardown_ring() Roger Pau Monné
2022-05-05  8:16 ` [PATCH v3 14/21] xen/netfront: " Juergen Gross
2022-05-05  8:16 ` [PATCH v3 15/21] xen/tpmfront: " Juergen Gross
2022-05-06 22:32   ` Jarkko Sakkinen
2022-05-18  9:41     ` Juergen Gross
2022-05-18 14:57       ` Jarkko Sakkinen
2022-05-05  8:16 ` [PATCH v3 16/21] xen/drmfront: " Juergen Gross
2022-05-05  8:16 ` [PATCH v3 17/21] xen/pcifront: " Juergen Gross
2022-05-05  8:16 ` [PATCH v3 18/21] xen/scsifront: " Juergen Gross
2022-05-05  8:16 ` [PATCH v3 19/21] xen/usbfront: " Juergen Gross
2022-05-05  8:16 ` [PATCH v3 20/21] xen/sndfront: " Juergen Gross
2022-05-05  8:16 ` [PATCH v3 21/21] xen/xenbus: eliminate xenbus_grant_ring() Juergen Gross
2022-05-06  0:12 ` [PATCH v3 00/21] xen: simplify frontend side ring setup Boris Ostrovsky
2022-05-09 13:23 ` Oleksandr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220505081640.17425-14-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=axboe@kernel.dk \
    --cc=boris.ostrovsky@oracle.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox