From patchwork Fri Sep 22 12:07:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 9965901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B70ED600C5 for ; Fri, 22 Sep 2017 12:09:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 966322988C for ; Fri, 22 Sep 2017 12:09:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87C662988E; Fri, 22 Sep 2017 12:09:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 096132988C for ; Fri, 22 Sep 2017 12:09:55 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvMk2-00061W-QE; Fri, 22 Sep 2017 12:07:34 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dvMk1-00060z-8t for xen-devel@lists.xenproject.org; Fri, 22 Sep 2017 12:07:33 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id F7/72-03093-40DF4C95; Fri, 22 Sep 2017 12:07:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMLMWRWlGSWpSXmKPExsVyuP0Ovy7D3yO RBntW21h83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBlT99YWdApX3Lq3lLGB8R9fFyMnh4SAkcTb if+Yuhi5OIQEFjJKLPm5hBEkwSagKrHh+ilWEFtEwEpie8t2sDizQI7E56Nf2EFsYQF3icOT9 zOD2CxA9feXzgGzeQVMJBqnHGSFWCAv0XFgMguIzSlgKtE1eTdYjRBQze8nj9kmMHIvYGRYxa hRnFpUllqka2igl1SUmZ5RkpuYmQPkmenlphYXJ6an5iQmFesl5+duYgR6lwEIdjAefx93iFG Sg0lJlFfw55FIIb6k/JTKjMTijPii0pzU4kOMGhwcAn1rVl9glGLJy89LVZLgffcbqE6wKDU9 tSItMwcYfjClEhw8SiK8k38BpXmLCxJzizPTIVKnGI05jm26/IeJo+Pm3T9MQmCTpMR5m0EmC YCUZpTmwQ2CxcUlRlkpYV5GoDOFeApSi3IzS1DlXzGKczAqCfMK/gGawpOZVwK37xXQKUxAp5 SvBjulJBEhJdXA2Ceb+v/VVt1a330LN7o0hOopTjKLa9Hq5ryivF2+/7ptReJLiyuPJiaeaJZ udTV48l7ixMzyhyJu8Y/3RL+yWOHw/b6ZuefsHzuOny7Oaqn47dlRtDJE1I717lvLicssD5sZ asVJ/tQwqO1n0Ch4Fv+zek/Szffh1/wS5h9fzHHQU35q7rcWJZbijERDLeai4kQA0sYqcoYCA AA= X-Env-Sender: jgross@suse.com X-Msg-Ref: server-16.tower-27.messagelabs.com!1506082048!117723677!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37729 invoked from network); 22 Sep 2017 12:07:28 -0000 Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by server-16.tower-27.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 22 Sep 2017 12:07:28 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 92B59ACC3; Fri, 22 Sep 2017 12:07:28 +0000 (UTC) From: Juergen Gross To: qemu-devel@nongnu.org, xen-devel@lists.xenproject.org Date: Fri, 22 Sep 2017 14:07:25 +0200 Message-Id: <20170922120725.10910-3-jgross@suse.com> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20170922120725.10910-1-jgross@suse.com> References: <20170922120725.10910-1-jgross@suse.com> Cc: anthony.perard@citrix.com, Juergen Gross , sstabellini@kernel.org, kraxel@redhat.com Subject: [Xen-devel] [PATCH v2 2/2] xen: dont try setting max grants multiple times X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Trying to call xengnttab_set_max_grants() with the same file handle might fail on some kernels, as this operation is allowed only once. This is a problem for the qdisk backend as blk_connect() can be called multiple times for a domain, e.g. in case grub-xen is being used to boot it. So instead of letting the generic backend code open the gnttab device do it in blk_connect() and close it again in blk_disconnect. Signed-off-by: Juergen Gross Acked-by: Anthony PERARD --- V2: - always call blk_disconnect() from blk_free() in order to have the gnttab device node closed (Anthony Perard) --- hw/block/xen_disk.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 62506e3167..e431bd89e8 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1220,6 +1220,12 @@ static int blk_connect(struct XenDevice *xendev) /* Add on the number needed for the ring pages */ max_grants += blkdev->nr_ring_ref; + blkdev->xendev.gnttabdev = xengnttab_open(NULL, 0); + if (blkdev->xendev.gnttabdev == 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)); @@ -1327,6 +1333,11 @@ static void blk_disconnect(struct XenDevice *xendev) } blkdev->feature_persistent = false; } + + if (blkdev->xendev.gnttabdev) { + xengnttab_close(blkdev->xendev.gnttabdev); + blkdev->xendev.gnttabdev = NULL; + } } static int blk_free(struct XenDevice *xendev) @@ -1334,9 +1345,7 @@ static int blk_free(struct XenDevice *xendev) struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev); struct ioreq *ioreq; - if (blkdev->blk || blkdev->sring) { - blk_disconnect(xendev); - } + blk_disconnect(xendev); while (!QLIST_EMPTY(&blkdev->freelist)) { ioreq = QLIST_FIRST(&blkdev->freelist); @@ -1363,7 +1372,6 @@ static void blk_event(struct XenDevice *xendev) struct XenDevOps xen_blkdev_ops = { .size = sizeof(struct XenBlkDev), - .flags = DEVOPS_FLAG_NEED_GNTDEV, .alloc = blk_alloc, .init = blk_init, .initialise = blk_connect,