From nobody Wed Oct 29 20:26:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525442446171620.7915429992789; Fri, 4 May 2018 07:00:46 -0700 (PDT) Received: from localhost ([::1]:34554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEbGP-0000iC-DH for importer@patchew.org; Fri, 04 May 2018 10:00:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEbBo-000502-Ey for qemu-devel@nongnu.org; Fri, 04 May 2018 09:56:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEbBm-0003Xr-G8 for qemu-devel@nongnu.org; Fri, 04 May 2018 09:56:00 -0400 Received: from smtp03.citrix.com ([162.221.156.55]:24303) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fEbBg-0003QE-O4; Fri, 04 May 2018 09:55:52 -0400 X-IronPort-AV: E=Sophos;i="5.49,362,1520899200"; d="scan'208";a="53691033" From: Paul Durrant To: , , Date: Fri, 4 May 2018 14:55:28 +0100 Message-ID: <1525442134-20488-3-git-send-email-paul.durrant@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1525442134-20488-1-git-send-email-paul.durrant@citrix.com> References: <1525442134-20488-1-git-send-email-paul.durrant@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PATCH v2 2/8] xen_disk: remove open-coded use of libxengnttab X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony Perard , Kevin Wolf , Paul Durrant , Stefano Stabellini , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that helpers are present in xen_backend, this patch removes open-coded calls to libxengnttab from the xen_disk code. This patch also fixes one whitspace error in the assignment of the XenDevOps initialise method. Signed-off-by: Paul Durrant --- Cc: Stefano Stabellini Cc: Anthony Perard Cc: Kevin Wolf Cc: Max Reitz v2: - New in v2 --- hw/block/xen_disk.c | 122 ++++++++++++++----------------------------------= ---- 1 file changed, 32 insertions(+), 90 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index f74fcd4..66ed2b7 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -68,7 +68,6 @@ struct ioreq { uint8_t mapped; =20 /* grant mapping */ - uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST]; uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; int prot; void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST]; @@ -142,7 +141,6 @@ static void ioreq_reset(struct ioreq *ioreq) ioreq->presync =3D 0; ioreq->mapped =3D 0; =20 - memset(ioreq->domids, 0, sizeof(ioreq->domids)); memset(ioreq->refs, 0, sizeof(ioreq->refs)); ioreq->prot =3D 0; memset(ioreq->page, 0, sizeof(ioreq->page)); @@ -168,16 +166,12 @@ static gint int_cmp(gconstpointer a, gconstpointer b,= gpointer user_data) static void destroy_grant(gpointer pgnt) { PersistentGrant *grant =3D pgnt; - xengnttab_handle *gnt =3D grant->blkdev->xendev.gnttabdev; + struct XenBlkDev *blkdev =3D grant->blkdev; + struct XenDevice *xendev =3D &blkdev->xendev; =20 - if (xengnttab_unmap(gnt, grant->page, 1) !=3D 0) { - xen_pv_printf(&grant->blkdev->xendev, 0, - "xengnttab_unmap failed: %s\n", - strerror(errno)); - } + xen_be_unmap_grant_ref(xendev, grant->page); grant->blkdev->persistent_gnt_count--; - xen_pv_printf(&grant->blkdev->xendev, 3, - "unmapped grant %p\n", grant->page); + xen_pv_printf(xendev, 3, "unmapped grant %p\n", grant->page); g_free(grant); } =20 @@ -185,15 +179,10 @@ static void remove_persistent_region(gpointer data, g= pointer dev) { PersistentRegion *region =3D data; struct XenBlkDev *blkdev =3D dev; - xengnttab_handle *gnt =3D blkdev->xendev.gnttabdev; + struct XenDevice *xendev =3D &blkdev->xendev; =20 - if (xengnttab_unmap(gnt, region->addr, region->num) !=3D 0) { - xen_pv_printf(&blkdev->xendev, 0, - "xengnttab_unmap region %p failed: %s\n", - region->addr, strerror(errno)); - } - xen_pv_printf(&blkdev->xendev, 3, - "unmapped grant region %p with %d pages\n", + xen_be_unmap_grant_refs(xendev, region->addr, region->num); + xen_pv_printf(xendev, 3, "unmapped grant region %p with %d pages\n", region->addr, region->num); g_free(region); } @@ -304,7 +293,6 @@ static int ioreq_parse(struct ioreq *ioreq) goto err; } =20 - ioreq->domids[i] =3D blkdev->xendev.dom; ioreq->refs[i] =3D ioreq->req.seg[i].gref; =20 mem =3D ioreq->req.seg[i].first_sect * blkdev->file_blk; @@ -324,7 +312,8 @@ err: =20 static void ioreq_unmap(struct ioreq *ioreq) { - xengnttab_handle *gnt =3D ioreq->blkdev->xendev.gnttabdev; + struct XenBlkDev *blkdev =3D ioreq->blkdev; + struct XenDevice *xendev =3D &blkdev->xendev; int i; =20 if (ioreq->num_unmap =3D=3D 0 || ioreq->mapped =3D=3D 0) { @@ -334,11 +323,7 @@ static void ioreq_unmap(struct ioreq *ioreq) if (!ioreq->pages) { return; } - if (xengnttab_unmap(gnt, ioreq->pages, ioreq->num_unmap) !=3D 0) { - xen_pv_printf(&ioreq->blkdev->xendev, 0, - "xengnttab_unmap failed: %s\n", - strerror(errno)); - } + xen_be_unmap_grant_refs(xendev, ioreq->pages, ioreq->num_unmap); ioreq->blkdev->cnt_map -=3D ioreq->num_unmap; ioreq->pages =3D NULL; } else { @@ -346,11 +331,7 @@ static void ioreq_unmap(struct ioreq *ioreq) if (!ioreq->page[i]) { continue; } - if (xengnttab_unmap(gnt, ioreq->page[i], 1) !=3D 0) { - xen_pv_printf(&ioreq->blkdev->xendev, 0, - "xengnttab_unmap failed: %s\n", - strerror(errno)); - } + xen_be_unmap_grant_ref(xendev, ioreq->page[i]); ioreq->blkdev->cnt_map--; ioreq->page[i] =3D NULL; } @@ -360,14 +341,14 @@ static void ioreq_unmap(struct ioreq *ioreq) =20 static int ioreq_map(struct ioreq *ioreq) { - xengnttab_handle *gnt =3D ioreq->blkdev->xendev.gnttabdev; - uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST]; + struct XenBlkDev *blkdev =3D ioreq->blkdev; + struct XenDevice *xendev =3D &blkdev->xendev; uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST]; int i, j, new_maps =3D 0; PersistentGrant *grant; PersistentRegion *region; - /* domids and refs variables will contain the information necessary + /* refs variable will contain the information necessary * to map the grants that are needed to fulfill this request. * * After mapping the needed grants, the page array will contain the @@ -392,7 +373,6 @@ static int ioreq_map(struct ioreq *ioreq) /* Add the grant to the list of grants that * should be mapped */ - domids[new_maps] =3D ioreq->domids[i]; refs[new_maps] =3D ioreq->refs[i]; page[i] =3D NULL; new_maps++; @@ -405,14 +385,13 @@ static int ioreq_map(struct ioreq *ioreq) } else { /* All grants in the request should be mapped */ memcpy(refs, ioreq->refs, sizeof(refs)); - memcpy(domids, ioreq->domids, sizeof(domids)); memset(page, 0, sizeof(page)); new_maps =3D ioreq->v.niov; } =20 if (batch_maps && new_maps) { - ioreq->pages =3D xengnttab_map_grant_refs - (gnt, new_maps, domids, refs, ioreq->prot); + ioreq->pages =3D xen_be_map_grant_refs(xendev, refs, new_maps, + ioreq->prot); if (ioreq->pages =3D=3D NULL) { xen_pv_printf(&ioreq->blkdev->xendev, 0, "can't map %d grant refs (%s, %d maps)\n", @@ -427,8 +406,8 @@ static int ioreq_map(struct ioreq *ioreq) ioreq->blkdev->cnt_map +=3D new_maps; } else if (new_maps) { for (i =3D 0; i < new_maps; i++) { - ioreq->page[i] =3D xengnttab_map_grant_ref - (gnt, domids[i], refs[i], ioreq->prot); + ioreq->page[i] =3D xen_be_map_grant_ref(xendev, refs[i], + ioreq->prot); if (ioreq->page[i] =3D=3D NULL) { xen_pv_printf(&ioreq->blkdev->xendev, 0, "can't map grant ref %d (%s, %d maps)\n", @@ -529,10 +508,12 @@ static int ioreq_init_copy_buffers(struct ioreq *iore= q) =20 static int ioreq_grant_copy(struct ioreq *ioreq) { - xengnttab_handle *gnt =3D ioreq->blkdev->xendev.gnttabdev; - xengnttab_grant_copy_segment_t segs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; + struct XenBlkDev *blkdev =3D ioreq->blkdev; + struct XenDevice *xendev =3D &blkdev->xendev; + XenGrantCopySegment segs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; int i, count, rc; int64_t file_blk =3D ioreq->blkdev->file_blk; + bool to_domain =3D (ioreq->req.operation =3D=3D BLKIF_OP_READ); =20 if (ioreq->v.niov =3D=3D 0) { return 0; @@ -541,16 +522,12 @@ static int ioreq_grant_copy(struct ioreq *ioreq) count =3D ioreq->v.niov; =20 for (i =3D 0; i < count; i++) { - if (ioreq->req.operation =3D=3D BLKIF_OP_READ) { - segs[i].flags =3D GNTCOPY_dest_gref; + if (to_domain) { segs[i].dest.foreign.ref =3D ioreq->refs[i]; - segs[i].dest.foreign.domid =3D ioreq->domids[i]; segs[i].dest.foreign.offset =3D ioreq->req.seg[i].first_sect *= file_blk; segs[i].source.virt =3D ioreq->v.iov[i].iov_base; } else { - segs[i].flags =3D GNTCOPY_source_gref; segs[i].source.foreign.ref =3D ioreq->refs[i]; - segs[i].source.foreign.domid =3D ioreq->domids[i]; segs[i].source.foreign.offset =3D ioreq->req.seg[i].first_sect= * file_blk; segs[i].dest.virt =3D ioreq->v.iov[i].iov_base; } @@ -558,7 +535,7 @@ static int ioreq_grant_copy(struct ioreq *ioreq) - ioreq->req.seg[i].first_sect + 1) * file_blk; } =20 - rc =3D xengnttab_grant_copy(gnt, count, segs); + rc =3D xen_be_copy_grant_refs(xendev, to_domain, segs, count); =20 if (rc) { xen_pv_printf(&ioreq->blkdev->xendev, 0, @@ -567,16 +544,6 @@ static int ioreq_grant_copy(struct ioreq *ioreq) return -1; } =20 - for (i =3D 0; i < count; i++) { - if (segs[i].status !=3D GNTST_okay) { - xen_pv_printf(&ioreq->blkdev->xendev, 3, - "failed to copy data %d for gref %d, domid %d\n", - segs[i].status, ioreq->refs[i], ioreq->domids[i]= ); - ioreq->aio_errors++; - rc =3D -1; - } - } - return rc; } #else @@ -1085,7 +1052,6 @@ static int blk_connect(struct XenDevice *xendev) int order, ring_ref; unsigned int ring_size, max_grants; unsigned int i; - uint32_t *domids; =20 trace_xen_disk_connect(xendev->name); =20 @@ -1247,31 +1213,11 @@ static int blk_connect(struct XenDevice *xendev) /* Add on the number needed for the ring pages */ max_grants +=3D blkdev->nr_ring_ref; =20 - blkdev->xendev.gnttabdev =3D xengnttab_open(NULL, 0); - if (blkdev->xendev.gnttabdev =3D=3D NULL) { - xen_pv_printf(xendev, 0, "xengnttab_open failed: %s\n", - strerror(errno)); - return -1; - } - if (xengnttab_set_max_grants(blkdev->xendev.gnttabdev, max_grants)) { - xen_pv_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n", - strerror(errno)); - return -1; - } - - domids =3D g_new0(uint32_t, blkdev->nr_ring_ref); - for (i =3D 0; i < blkdev->nr_ring_ref; i++) { - domids[i] =3D blkdev->xendev.dom; - } - - blkdev->sring =3D xengnttab_map_grant_refs(blkdev->xendev.gnttabdev, - blkdev->nr_ring_ref, - domids, - blkdev->ring_ref, - PROT_READ | PROT_WRITE); - - g_free(domids); + xen_be_set_max_grant_refs(xendev, max_grants); =20 + blkdev->sring =3D xen_be_map_grant_refs(xendev, blkdev->ring_ref, + blkdev->nr_ring_ref, + PROT_READ | PROT_WRITE); if (!blkdev->sring) { return -1; } @@ -1344,8 +1290,8 @@ static void blk_disconnect(struct XenDevice *xendev) aio_context_release(blkdev->ctx); =20 if (blkdev->sring) { - xengnttab_unmap(blkdev->xendev.gnttabdev, blkdev->sring, - blkdev->nr_ring_ref); + xen_be_unmap_grant_refs(xendev, blkdev->sring, + blkdev->nr_ring_ref); blkdev->cnt_map--; blkdev->sring =3D NULL; } @@ -1369,11 +1315,6 @@ static void blk_disconnect(struct XenDevice *xendev) } blkdev->feature_persistent =3D false; } - - if (blkdev->xendev.gnttabdev) { - xengnttab_close(blkdev->xendev.gnttabdev); - blkdev->xendev.gnttabdev =3D NULL; - } } =20 static int blk_free(struct XenDevice *xendev) @@ -1410,10 +1351,11 @@ static void blk_event(struct XenDevice *xendev) } =20 struct XenDevOps xen_blkdev_ops =3D { + .flags =3D DEVOPS_FLAG_NEED_GNTDEV, .size =3D sizeof(struct XenBlkDev), .alloc =3D blk_alloc, .init =3D blk_init, - .initialise =3D blk_connect, + .initialise =3D blk_connect, .disconnect =3D blk_disconnect, .event =3D blk_event, .free =3D blk_free, --=20 2.1.4