From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548896550230850.1799720495139; Wed, 30 Jan 2019 17:02:30 -0800 (PST) Received: from localhost ([127.0.0.1]:46844 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0kJ-0000vN-Gk for importer@patchew.org; Wed, 30 Jan 2019 20:02:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0hw-0007sW-Hb for qemu-devel@nongnu.org; Wed, 30 Jan 2019 19:59:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0hv-0007bC-2u for qemu-devel@nongnu.org; Wed, 30 Jan 2019 19:59:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0hr-0007Yn-RF; Wed, 30 Jan 2019 19:59:52 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B5DEA402E; Thu, 31 Jan 2019 00:59:51 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27D706266C; Thu, 31 Jan 2019 00:59:49 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:33 +0100 Message-Id: <20190131005945.20149-2-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 31 Jan 2019 00:59:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 01/13] qapi: add x-debug-query-block-graph 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Add a new command, returning block nodes (and their users) graph. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-id: 20181221170909.25584-2-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- qapi/block-core.json | 108 ++++++++++++++++++++++++ include/block/block.h | 1 + include/sysemu/block-backend.h | 2 + block.c | 148 +++++++++++++++++++++++++++++++++ block/block-backend.c | 5 ++ blockdev.c | 5 ++ 6 files changed, 269 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index 91685be6c2..cde1b53708 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1665,6 +1665,114 @@ ## { 'command': 'query-named-block-nodes', 'returns': [ 'BlockDeviceInfo' ] } =20 +## +# @XDbgBlockGraphNodeType: +# +# @block-backend: corresponds to BlockBackend +# +# @block-job: corresonds to BlockJob +# +# @block-driver: corresponds to BlockDriverState +# +# Since: 4.0 +## +{ 'enum': 'XDbgBlockGraphNodeType', + 'data': [ 'block-backend', 'block-job', 'block-driver' ] } + +## +# @XDbgBlockGraphNode: +# +# @id: Block graph node identifier. This @id is generated only for +# x-debug-query-block-graph and does not relate to any other identifi= ers in +# Qemu. +# +# @type: Type of graph node. Can be one of block-backend, block-job or +# block-driver-state. +# +# @name: Human readable name of the node. Corresponds to node-name for +# block-driver-state nodes; is not guaranteed to be unique in the w= hole +# graph (with block-jobs and block-backends). +# +# Since: 4.0 +## +{ 'struct': 'XDbgBlockGraphNode', + 'data': { 'id': 'uint64', 'type': 'XDbgBlockGraphNodeType', 'name': 'str= ' } } + +## +# @BlockPermission: +# +# Enum of base block permissions. +# +# @consistent-read: A user that has the "permission" of consistent reads is +# guaranteed that their view of the contents of the block +# device is complete and self-consistent, representing t= he +# contents of a disk at a specific point. +# For most block devices (including their backing files)= this +# is true, but the property cannot be maintained in a few +# situations like for intermediate nodes of a commit blo= ck +# job. +# +# @write: This permission is required to change the visible disk contents. +# +# @write-unchanged: This permission (which is weaker than BLK_PERM_WRITE) = is +# both enough and required for writes to the block node = when +# the caller promises that the visible disk content does= n't +# change. +# As the BLK_PERM_WRITE permission is strictly stronger, +# either is sufficient to perform an unchanging write. +# +# @resize: This permission is required to change the size of a block node. +# +# @graph-mod: This permission is required to change the node that this +# BdrvChild points to. +# +# Since: 4.0 +## + { 'enum': 'BlockPermission', + 'data': [ 'consistent-read', 'write', 'write-unchanged', 'resize', + 'graph-mod' ] } +## +# @XDbgBlockGraphEdge: +# +# Block Graph edge description for x-debug-query-block-graph. +# +# @parent: parent id +# +# @child: child id +# +# @name: name of the relation (examples are 'file' and 'backing') +# +# @perm: granted permissions for the parent operating on the child +# +# @shared-perm: permissions that can still be granted to other users of the +# child while it is still attached to this parent +# +# Since: 4.0 +## +{ 'struct': 'XDbgBlockGraphEdge', + 'data': { 'parent': 'uint64', 'child': 'uint64', + 'name': 'str', 'perm': [ 'BlockPermission' ], + 'shared-perm': [ 'BlockPermission' ] } } + +## +# @XDbgBlockGraph: +# +# Block Graph - list of nodes and list of edges. +# +# Since: 4.0 +## +{ 'struct': 'XDbgBlockGraph', + 'data': { 'nodes': ['XDbgBlockGraphNode'], 'edges': ['XDbgBlockGraphEdge= '] } } + +## +# @x-debug-query-block-graph: +# +# Get the block graph. +# +# Since: 4.0 +## +{ 'command': 'x-debug-query-block-graph', 'returns': 'XDbgBlockGraph' } + ## # @drive-mirror: # diff --git a/include/block/block.h b/include/block/block.h index f70a843b72..57233cf2c0 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -448,6 +448,7 @@ void bdrv_eject(BlockDriverState *bs, bool eject_flag); const char *bdrv_get_format_name(BlockDriverState *bs); BlockDriverState *bdrv_find_node(const char *node_name); BlockDeviceInfoList *bdrv_named_nodes_list(Error **errp); +XDbgBlockGraph *bdrv_get_xdbg_block_graph(Error **errp); BlockDriverState *bdrv_lookup_bs(const char *device, const char *node_name, Error **errp); diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index c96bcdee14..c8f816a200 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -237,4 +237,6 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in= , int64_t off_in, int bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); =20 +const BdrvChild *blk_root(BlockBackend *blk); + #endif diff --git a/block.c b/block.c index 4f5ff2cc12..e795a7c5de 100644 --- a/block.c +++ b/block.c @@ -4119,6 +4119,154 @@ BlockDeviceInfoList *bdrv_named_nodes_list(Error **= errp) return list; } =20 +#define QAPI_LIST_ADD(list, element) do { \ + typeof(list) _tmp =3D g_new(typeof(*(list)), 1); \ + _tmp->value =3D (element); \ + _tmp->next =3D (list); \ + (list) =3D _tmp; \ +} while (0) + +typedef struct XDbgBlockGraphConstructor { + XDbgBlockGraph *graph; + GHashTable *graph_nodes; +} XDbgBlockGraphConstructor; + +static XDbgBlockGraphConstructor *xdbg_graph_new(void) +{ + XDbgBlockGraphConstructor *gr =3D g_new(XDbgBlockGraphConstructor, 1); + + gr->graph =3D g_new0(XDbgBlockGraph, 1); + gr->graph_nodes =3D g_hash_table_new(NULL, NULL); + + return gr; +} + +static XDbgBlockGraph *xdbg_graph_finalize(XDbgBlockGraphConstructor *gr) +{ + XDbgBlockGraph *graph =3D gr->graph; + + g_hash_table_destroy(gr->graph_nodes); + g_free(gr); + + return graph; +} + +static uintptr_t xdbg_graph_node_num(XDbgBlockGraphConstructor *gr, void *= node) +{ + uintptr_t ret =3D (uintptr_t)g_hash_table_lookup(gr->graph_nodes, node= ); + + if (ret !=3D 0) { + return ret; + } + + /* + * Start counting from 1, not 0, because 0 interferes with not-found (= NULL) + * answer of g_hash_table_lookup. + */ + ret =3D g_hash_table_size(gr->graph_nodes) + 1; + g_hash_table_insert(gr->graph_nodes, node, (void *)ret); + + return ret; +} + +static void xdbg_graph_add_node(XDbgBlockGraphConstructor *gr, void *node, + XDbgBlockGraphNodeType type, const char *n= ame) +{ + XDbgBlockGraphNode *n; + + n =3D g_new0(XDbgBlockGraphNode, 1); + + n->id =3D xdbg_graph_node_num(gr, node); + n->type =3D type; + n->name =3D g_strdup(name); + + QAPI_LIST_ADD(gr->graph->nodes, n); +} + +static void xdbg_graph_add_edge(XDbgBlockGraphConstructor *gr, void *paren= t, + const BdrvChild *child) +{ + typedef struct { + unsigned int flag; + BlockPermission num; + } PermissionMap; + + static const PermissionMap permissions[] =3D { + { BLK_PERM_CONSISTENT_READ, BLOCK_PERMISSION_CONSISTENT_READ }, + { BLK_PERM_WRITE, BLOCK_PERMISSION_WRITE }, + { BLK_PERM_WRITE_UNCHANGED, BLOCK_PERMISSION_WRITE_UNCHANGED }, + { BLK_PERM_RESIZE, BLOCK_PERMISSION_RESIZE }, + { BLK_PERM_GRAPH_MOD, BLOCK_PERMISSION_GRAPH_MOD }, + { 0, 0 } + }; + const PermissionMap *p; + XDbgBlockGraphEdge *edge; + + QEMU_BUILD_BUG_ON(1UL << (ARRAY_SIZE(permissions) - 1) !=3D BLK_PERM_A= LL + 1); + + edge =3D g_new0(XDbgBlockGraphEdge, 1); + + edge->parent =3D xdbg_graph_node_num(gr, parent); + edge->child =3D xdbg_graph_node_num(gr, child->bs); + edge->name =3D g_strdup(child->name); + + for (p =3D permissions; p->flag; p++) { + if (p->flag & child->perm) { + QAPI_LIST_ADD(edge->perm, p->num); + } + if (p->flag & child->shared_perm) { + QAPI_LIST_ADD(edge->shared_perm, p->num); + } + } + + QAPI_LIST_ADD(gr->graph->edges, edge); +} + + +XDbgBlockGraph *bdrv_get_xdbg_block_graph(Error **errp) +{ + BlockBackend *blk; + BlockJob *job; + BlockDriverState *bs; + BdrvChild *child; + XDbgBlockGraphConstructor *gr =3D xdbg_graph_new(); + + for (blk =3D blk_all_next(NULL); blk; blk =3D blk_all_next(blk)) { + char *allocated_name =3D NULL; + const char *name =3D blk_name(blk); + + if (!*name) { + name =3D allocated_name =3D blk_get_attached_dev_id(blk); + } + xdbg_graph_add_node(gr, blk, X_DBG_BLOCK_GRAPH_NODE_TYPE_BLOCK_BAC= KEND, + name); + g_free(allocated_name); + if (blk_root(blk)) { + xdbg_graph_add_edge(gr, blk, blk_root(blk)); + } + } + + for (job =3D block_job_next(NULL); job; job =3D block_job_next(job)) { + GSList *el; + + xdbg_graph_add_node(gr, job, X_DBG_BLOCK_GRAPH_NODE_TYPE_BLOCK_JOB, + job->job.id); + for (el =3D job->nodes; el; el =3D el->next) { + xdbg_graph_add_edge(gr, job, (BdrvChild *)el->data); + } + } + + QTAILQ_FOREACH(bs, &graph_bdrv_states, node_list) { + xdbg_graph_add_node(gr, bs, X_DBG_BLOCK_GRAPH_NODE_TYPE_BLOCK_DRIV= ER, + bs->node_name); + QLIST_FOREACH(child, &bs->children, next) { + xdbg_graph_add_edge(gr, bs, child); + } + } + + return xdbg_graph_finalize(gr); +} + BlockDriverState *bdrv_lookup_bs(const char *device, const char *node_name, Error **errp) diff --git a/block/block-backend.c b/block/block-backend.c index 60d37a0c3d..cf05abd89d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2249,3 +2249,8 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_= in, int64_t off_in, blk_out->root, off_out, bytes, read_flags, write_flags); } + +const BdrvChild *blk_root(BlockBackend *blk) +{ + return blk->root; +} diff --git a/blockdev.c b/blockdev.c index a8fa8748a9..fb18e9c975 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3582,6 +3582,11 @@ BlockDeviceInfoList *qmp_query_named_block_nodes(Err= or **errp) return bdrv_named_nodes_list(errp); } =20 +XDbgBlockGraph *qmp_x_debug_query_block_graph(Error **errp) +{ + return bdrv_get_xdbg_block_graph(errp); +} + BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn, Error **errp) { --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548896551586557.4247202430076; Wed, 30 Jan 2019 17:02:31 -0800 (PST) Received: from localhost ([127.0.0.1]:46846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0kL-0000wu-7q for importer@patchew.org; Wed, 30 Jan 2019 20:02:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0hy-0007uQ-N3 for qemu-devel@nongnu.org; Wed, 30 Jan 2019 19:59:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0hx-0007ca-E9 for qemu-devel@nongnu.org; Wed, 30 Jan 2019 19:59:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43100) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0hu-0007aY-JD; Wed, 30 Jan 2019 19:59:54 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9768356D2; Thu, 31 Jan 2019 00:59:53 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EC5D1001F59; Thu, 31 Jan 2019 00:59:53 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:34 +0100 Message-Id: <20190131005945.20149-3-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 31 Jan 2019 00:59:53 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/13] scripts: add render_block_graph function for QEMUMachine 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Render block nodes graph with help of graphviz. This new function is for debugging, so there is no sense to put it into qemu.py as a method of QEMUMachine. Let's instead put it separately. Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Eduardo Habkost Reviewed-by: Max Reitz Message-id: 20181221170909.25584-3-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- scripts/render_block_graph.py | 120 ++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100755 scripts/render_block_graph.py diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py new file mode 100755 index 0000000000..ed7e581b4f --- /dev/null +++ b/scripts/render_block_graph.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +# +# Render Qemu Block Graph +# +# Copyright (c) 2018 Virtuozzo International GmbH. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import sys +import subprocess +import json +from graphviz import Digraph +from qemu import MonitorResponseError + + +def perm(arr): + s =3D 'w' if 'write' in arr else '_' + s +=3D 'r' if 'consistent-read' in arr else '_' + s +=3D 'u' if 'write-unchanged' in arr else '_' + s +=3D 'g' if 'graph-mod' in arr else '_' + s +=3D 's' if 'resize' in arr else '_' + return s + + +def render_block_graph(qmp, filename, format=3D'png'): + ''' + Render graph in text (dot) representation into "@filename" and + representation in @format into "@filename.@format" + ''' + + bds_nodes =3D qmp.command('query-named-block-nodes') + bds_nodes =3D {n['node-name']: n for n in bds_nodes} + + job_nodes =3D qmp.command('query-block-jobs') + job_nodes =3D {n['device']: n for n in job_nodes} + + block_graph =3D qmp.command('x-debug-query-block-graph') + + graph =3D Digraph(comment=3D'Block Nodes Graph') + graph.format =3D format + graph.node('permission symbols:\l' + ' w - Write\l' + ' r - consistent-Read\l' + ' u - write - Unchanged\l' + ' g - Graph-mod\l' + ' s - reSize\l' + 'edge label scheme:\l' + ' \l' + ' \l' + ' \l', shape=3D'none') + + for n in block_graph['nodes']: + if n['type'] =3D=3D 'block-driver': + info =3D bds_nodes[n['name']] + label =3D n['name'] + ' [' + info['drv'] + ']' + if info['drv'] =3D=3D 'file': + label +=3D '\n' + os.path.basename(info['file']) + shape =3D 'ellipse' + elif n['type'] =3D=3D 'block-job': + info =3D job_nodes[n['name']] + label =3D info['type'] + ' job (' + n['name'] + ')' + shape =3D 'box' + else: + assert n['type'] =3D=3D 'block-backend' + label =3D n['name'] if n['name'] else 'unnamed blk' + shape =3D 'box' + + graph.node(str(n['id']), label, shape=3Dshape) + + for e in block_graph['edges']: + label =3D '%s\l%s\l%s\l' % (e['name'], perm(e['perm']), + perm(e['shared-perm'])) + graph.edge(str(e['parent']), str(e['child']), label=3Dlabel) + + graph.render(filename) + + +class LibvirtGuest(): + def __init__(self, name): + self.name =3D name + + def command(self, cmd): + # only supports qmp commands without parameters + m =3D {'execute': cmd} + ar =3D ['virsh', 'qemu-monitor-command', self.name, json.dumps(m)] + + reply =3D json.loads(subprocess.check_output(ar)) + + if 'error' in reply: + raise MonitorResponseError(reply) + + return reply['return'] + + +if __name__ =3D=3D '__main__': + obj =3D sys.argv[1] + out =3D sys.argv[2] + + if os.path.exists(obj): + # assume unix socket + qmp =3D QEMUMonitorProtocol(obj) + qmp.connect() + else: + # assume libvirt guest name + qmp =3D LibvirtGuest(obj) + + render_block_graph(qmp, out) --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 154889675210849.16777459123148; Wed, 30 Jan 2019 17:05:52 -0800 (PST) Received: from localhost ([127.0.0.1]:46896 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0na-0003ZC-1f for importer@patchew.org; Wed, 30 Jan 2019 20:05:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0i2-0007yR-7S for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0i0-0007ed-LR for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43126) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0hx-0007cH-FQ; Wed, 30 Jan 2019 19:59:57 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CCA64356E7; Thu, 31 Jan 2019 00:59:56 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2FFCD608C6; Thu, 31 Jan 2019 00:59:55 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:35 +0100 Message-Id: <20190131005945.20149-4-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 31 Jan 2019 00:59:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/13] block/ssh: Convert from DPRINTF() macro to trace events 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Laurent Vivier Signed-off-by: Laurent Vivier Reviewed-by: Richard W.M. Jones Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20181213162727.17438-2-lvivier@redhat.com [mreitz: Fixed type of ssh_{read,write}_return's parameter to be ssize_t instead of size_t] Signed-off-by: Max Reitz --- block/ssh.c | 46 +++++++++++++++++----------------------------- block/trace-events | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 7fbc27abdf..bbc513e095 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -41,27 +41,17 @@ #include "qapi/qmp/qstring.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" +#include "trace.h" =20 -/* DEBUG_SSH=3D1 enables the DPRINTF (debugging printf) statements in - * this block driver code. - * +/* * TRACE_LIBSSH2=3D enables tracing in libssh2 itself. Note * that this requires that libssh2 was specially compiled with the * `./configure --enable-debug' option, so most likely you will have * to compile it yourself. The meaning of is described * here: http://www.libssh2.org/libssh2_trace.html */ -#define DEBUG_SSH 0 #define TRACE_LIBSSH2 0 /* or try: LIBSSH2_TRACE_SFTP */ =20 -#define DPRINTF(fmt, ...) \ - do { \ - if (DEBUG_SSH) { \ - fprintf(stderr, "ssh: %-15s " fmt "\n", \ - __func__, ##__VA_ARGS__); \ - } \ - } while (0) - typedef struct BDRVSSHState { /* Coroutine. */ CoMutex lock; @@ -336,7 +326,7 @@ static int check_host_key_knownhosts(BDRVSSHState *s, switch (r) { case LIBSSH2_KNOWNHOST_CHECK_MATCH: /* OK */ - DPRINTF("host key OK: %s", found->key); + trace_ssh_check_host_key_knownhosts(found->key); break; case LIBSSH2_KNOWNHOST_CHECK_MISMATCH: ret =3D -EINVAL; @@ -721,8 +711,7 @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOpti= onsSsh *opts, } =20 /* Open the remote file. */ - DPRINTF("opening file %s flags=3D0x%x creat_mode=3D0%o", - opts->path, ssh_flags, creat_mode); + trace_ssh_connect_to_ssh(opts->path, ssh_flags, creat_mode); s->sftp_handle =3D libssh2_sftp_open(s->sftp, opts->path, ssh_flags, creat_mode); if (!s->sftp_handle) { @@ -890,7 +879,7 @@ static int coroutine_fn ssh_co_create_opts(const char *= filename, QemuOpts *opts, /* Get desired file size. */ ssh_opts->size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE= , 0), BDRV_SECTOR_SIZE); - DPRINTF("total_size=3D%" PRIi64, ssh_opts->size); + trace_ssh_co_create_opts(ssh_opts->size); =20 uri_options =3D qdict_new(); ret =3D parse_uri(filename, uri_options, errp); @@ -946,7 +935,7 @@ static void restart_coroutine(void *opaque) BDRVSSHState *s =3D bs->opaque; AioContext *ctx =3D bdrv_get_aio_context(bs); =20 - DPRINTF("co=3D%p", restart->co); + trace_ssh_restart_coroutine(restart->co); aio_set_fd_handler(ctx, s->sock, false, NULL, NULL, NULL, NULL); =20 aio_co_wake(restart->co); @@ -974,13 +963,12 @@ static coroutine_fn void co_yield(BDRVSSHState *s, Bl= ockDriverState *bs) wr_handler =3D restart_coroutine; } =20 - DPRINTF("s->sock=3D%d rd_handler=3D%p wr_handler=3D%p", s->sock, - rd_handler, wr_handler); + trace_ssh_co_yield(s->sock, rd_handler, wr_handler); =20 aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, false, rd_handler, wr_handler, NULL, &restart); qemu_coroutine_yield(); - DPRINTF("s->sock=3D%d - back", s->sock); + trace_ssh_co_yield_back(s->sock); } =20 /* SFTP has a function `libssh2_sftp_seek64' which seeks to a position @@ -1003,7 +991,7 @@ static void ssh_seek(BDRVSSHState *s, int64_t offset, = int flags) bool force =3D (flags & SSH_SEEK_FORCE) !=3D 0; =20 if (force || op_read !=3D s->offset_op_read || offset !=3D s->offset) { - DPRINTF("seeking to offset=3D%" PRIi64, offset); + trace_ssh_seek(offset); libssh2_sftp_seek64(s->sftp_handle, offset); s->offset =3D offset; s->offset_op_read =3D op_read; @@ -1019,7 +1007,7 @@ static coroutine_fn int ssh_read(BDRVSSHState *s, Blo= ckDriverState *bs, char *buf, *end_of_vec; struct iovec *i; =20 - DPRINTF("offset=3D%" PRIi64 " size=3D%zu", offset, size); + trace_ssh_read(offset, size); =20 ssh_seek(s, offset, SSH_SEEK_READ); =20 @@ -1038,9 +1026,9 @@ static coroutine_fn int ssh_read(BDRVSSHState *s, Blo= ckDriverState *bs, */ for (got =3D 0; got < size; ) { again: - DPRINTF("sftp_read buf=3D%p size=3D%zu", buf, end_of_vec - buf); + trace_ssh_read_buf(buf, end_of_vec - buf); r =3D libssh2_sftp_read(s->sftp_handle, buf, end_of_vec - buf); - DPRINTF("sftp_read returned %zd", r); + trace_ssh_read_return(r); =20 if (r =3D=3D LIBSSH2_ERROR_EAGAIN || r =3D=3D LIBSSH2_ERROR_TIMEOU= T) { co_yield(s, bs); @@ -1094,7 +1082,7 @@ static int ssh_write(BDRVSSHState *s, BlockDriverStat= e *bs, char *buf, *end_of_vec; struct iovec *i; =20 - DPRINTF("offset=3D%" PRIi64 " size=3D%zu", offset, size); + trace_ssh_write(offset, size); =20 ssh_seek(s, offset, SSH_SEEK_WRITE); =20 @@ -1108,9 +1096,9 @@ static int ssh_write(BDRVSSHState *s, BlockDriverStat= e *bs, =20 for (written =3D 0; written < size; ) { again: - DPRINTF("sftp_write buf=3D%p size=3D%zu", buf, end_of_vec - buf); + trace_ssh_write_buf(buf, end_of_vec - buf); r =3D libssh2_sftp_write(s->sftp_handle, buf, end_of_vec - buf); - DPRINTF("sftp_write returned %zd", r); + trace_ssh_write_return(r); =20 if (r =3D=3D LIBSSH2_ERROR_EAGAIN || r =3D=3D LIBSSH2_ERROR_TIMEOU= T) { co_yield(s, bs); @@ -1187,7 +1175,7 @@ static coroutine_fn int ssh_flush(BDRVSSHState *s, Bl= ockDriverState *bs) { int r; =20 - DPRINTF("fsync"); + trace_ssh_flush(); again: r =3D libssh2_sftp_fsync(s->sftp_handle); if (r =3D=3D LIBSSH2_ERROR_EAGAIN || r =3D=3D LIBSSH2_ERROR_TIMEOUT) { @@ -1238,7 +1226,7 @@ static int64_t ssh_getlength(BlockDriverState *bs) =20 /* Note we cannot make a libssh2 call here. */ length =3D (int64_t) s->attrs.filesize; - DPRINTF("length=3D%" PRIi64, length); + trace_ssh_getlength(length); =20 return length; } diff --git a/block/trace-events b/block/trace-events index 693c14c443..bdd58f6226 100644 --- a/block/trace-events +++ b/block/trace-events @@ -160,3 +160,20 @@ iscsi_xcopy(void *src_lun, uint64_t src_off, void *dst= _lun, uint64_t dst_off, ui # block/nbd-client.c nbd_read_reply_entry_fail(int ret, const char *err) "ret =3D %d, err: %s" nbd_co_request_fail(uint64_t from, uint32_t len, uint64_t handle, uint16_t= flags, uint16_t type, const char *name, int ret, const char *err) "Request= failed { .from =3D %" PRIu64", .len =3D %" PRIu32 ", .handle =3D %" PRIu64= ", .flags =3D 0x%" PRIx16 ", .type =3D %" PRIu16 " (%s) } ret =3D %d, err:= %s" + +# block/ssh.c +ssh_restart_coroutine(void *co) "co=3D%p" +ssh_flush(void) "fsync" +ssh_check_host_key_knownhosts(const char *key) "host key OK: %s" +ssh_connect_to_ssh(char *path, int flags, int mode) "opening file %s flags= =3D0x%x creat_mode=3D0%o" +ssh_co_yield(int sock, void *rd_handler, void *wr_handler) "s->sock=3D%d r= d_handler=3D%p wr_handler=3D%p" +ssh_co_yield_back(int sock) "s->sock=3D%d - back" +ssh_getlength(int64_t length) "length=3D%" PRIi64 +ssh_co_create_opts(uint64_t size) "total_size=3D%" PRIu64 +ssh_read(int64_t offset, size_t size) "offset=3D%" PRIi64 " size=3D%zu" +ssh_read_buf(void *buf, size_t size) "sftp_read buf=3D%p size=3D%zu" +ssh_read_return(ssize_t ret) "sftp_read returned %zd" +ssh_write(int64_t offset, size_t size) "offset=3D%" PRIi64 " size=3D%zu" +ssh_write_buf(void *buf, size_t size) "sftp_write buf=3D%p size=3D%zu" +ssh_write_return(ssize_t ret) "sftp_write returned %zd" +ssh_seek(int64_t offset) "seeking to offset=3D%" PRIi64 --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548896578909822.0227975991447; Wed, 30 Jan 2019 17:02:58 -0800 (PST) Received: from localhost ([127.0.0.1]:46848 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0kk-0001Cq-UK for importer@patchew.org; Wed, 30 Jan 2019 20:02:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37538) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0i3-0007zw-Po for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0i2-0007hA-OC for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57334) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0i0-0007e5-Cr; Wed, 30 Jan 2019 20:00:00 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B263219D381; Thu, 31 Jan 2019 00:59:59 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 429E55D96F; Thu, 31 Jan 2019 00:59:59 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:36 +0100 Message-Id: <20190131005945.20149-5-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 31 Jan 2019 00:59:59 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 04/13] block/curl: Convert from DPRINTF() macro to trace events 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Laurent Vivier Signed-off-by: Laurent Vivier Reviewed-by: Richard W.M. Jones Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20181213162727.17438-3-lvivier@redhat.com Signed-off-by: Max Reitz --- block/curl.c | 29 ++++++++--------------------- block/trace-events | 9 +++++++++ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/block/curl.c b/block/curl.c index db5d2bd8ef..b7ac265d3a 100644 --- a/block/curl.c +++ b/block/curl.c @@ -32,22 +32,10 @@ #include "crypto/secret.h" #include #include "qemu/cutils.h" +#include "trace.h" =20 -// #define DEBUG_CURL // #define DEBUG_VERBOSE =20 -#ifdef DEBUG_CURL -#define DEBUG_CURL_PRINT 1 -#else -#define DEBUG_CURL_PRINT 0 -#endif -#define DPRINTF(fmt, ...) \ - do { \ - if (DEBUG_CURL_PRINT) { \ - fprintf(stderr, fmt, ## __VA_ARGS__); \ - } \ - } while (0) - #if LIBCURL_VERSION_NUM >=3D 0x071000 /* The multi interface timer callback was introduced in 7.16.0 */ #define NEED_CURL_TIMER_CALLBACK @@ -154,7 +142,7 @@ static int curl_timer_cb(CURLM *multi, long timeout_ms,= void *opaque) { BDRVCURLState *s =3D opaque; =20 - DPRINTF("CURL: timer callback timeout_ms %ld\n", timeout_ms); + trace_curl_timer_cb(timeout_ms); if (timeout_ms =3D=3D -1) { timer_del(&s->timer); } else { @@ -193,7 +181,7 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, i= nt action, } socket =3D NULL; =20 - DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, (int)fd); + trace_curl_sock_cb(action, (int)fd); switch (action) { case CURL_POLL_IN: aio_set_fd_handler(s->aio_context, fd, false, @@ -238,7 +226,7 @@ static size_t curl_read_cb(void *ptr, size_t size, size= _t nmemb, void *opaque) size_t realsize =3D size * nmemb; int i; =20 - DPRINTF("CURL: Just reading %zd bytes\n", realsize); + trace_curl_read_cb(realsize); =20 if (!s || !s->orig_buf) { goto read_end; @@ -777,7 +765,7 @@ static int curl_open(BlockDriverState *bs, QDict *optio= ns, int flags, } } =20 - DPRINTF("CURL: Opening %s\n", file); + trace_curl_open(file); qemu_co_queue_init(&s->free_state_waitq); s->aio_context =3D bdrv_get_aio_context(bs); s->url =3D g_strdup(file); @@ -830,7 +818,7 @@ static int curl_open(BlockDriverState *bs, QDict *optio= ns, int flags, "Server does not support 'range' (byte ranges)."); goto out; } - DPRINTF("CURL: Size =3D %" PRIu64 "\n", s->len); + trace_curl_open_size(s->len); =20 qemu_mutex_lock(&s->mutex); curl_clean_state(state); @@ -908,8 +896,7 @@ static void curl_setup_preadv(BlockDriverState *bs, CUR= LAIOCB *acb) state->acb[0] =3D acb; =20 snprintf(state->range, 127, "%" PRIu64 "-%" PRIu64, start, end); - DPRINTF("CURL (AIO): Reading %" PRIu64 " at %" PRIu64 " (%s)\n", - acb->bytes, start, state->range); + trace_curl_setup_preadv(acb->bytes, start, state->range); curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range); =20 curl_multi_add_handle(s->multi, state->curl); @@ -943,7 +930,7 @@ static void curl_close(BlockDriverState *bs) { BDRVCURLState *s =3D bs->opaque; =20 - DPRINTF("CURL: Close\n"); + trace_curl_close(); curl_detach_aio_context(bs); qemu_mutex_destroy(&s->mutex); =20 diff --git a/block/trace-events b/block/trace-events index bdd58f6226..8ea8d1eaeb 100644 --- a/block/trace-events +++ b/block/trace-events @@ -177,3 +177,12 @@ ssh_write(int64_t offset, size_t size) "offset=3D%" PR= Ii64 " size=3D%zu" ssh_write_buf(void *buf, size_t size) "sftp_write buf=3D%p size=3D%zu" ssh_write_return(ssize_t ret) "sftp_write returned %zd" ssh_seek(int64_t offset) "seeking to offset=3D%" PRIi64 + +# block/curl.c +curl_timer_cb(long timeout_ms) "timer callback timeout_ms %ld" +curl_sock_cb(int action, int fd) "sock action %d on fd %d" +curl_read_cb(size_t realsize) "just reading %zu bytes" +curl_open(const char *file) "opening %s" +curl_open_size(uint64_t size) "size =3D %" PRIu64 +curl_setup_preadv(uint64_t bytes, uint64_t start, const char *range) "read= ing %" PRIu64 " at %" PRIu64 " (%s)" +curl_close(void) "close" --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548896926060208.30725422920523; Wed, 30 Jan 2019 17:08:46 -0800 (PST) Received: from localhost ([127.0.0.1]:46939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0qN-000624-8G for importer@patchew.org; Wed, 30 Jan 2019 20:08:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0i8-00083E-7w for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0i5-0007kL-UD for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35294) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0i3-0007h5-82; Wed, 30 Jan 2019 20:00:03 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7047C88317; Thu, 31 Jan 2019 01:00:02 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCAF15D717; Thu, 31 Jan 2019 01:00:01 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:37 +0100 Message-Id: <20190131005945.20149-6-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 31 Jan 2019 01:00:02 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 05/13] block/file-posix: Convert from DPRINTF() macro to trace events 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Laurent Vivier Signed-off-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20181213162727.17438-4-lvivier@redhat.com Signed-off-by: Max Reitz --- block/file-posix.c | 25 ++++++------------------- block/trace-events | 7 +++++++ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 8aee7a3fb8..ba6ab62a38 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -102,19 +102,7 @@ #include #endif =20 -//#define DEBUG_BLOCK - -#ifdef DEBUG_BLOCK -# define DEBUG_BLOCK_PRINT 1 -#else -# define DEBUG_BLOCK_PRINT 0 -#endif -#define DPRINTF(fmt, ...) \ -do { \ - if (DEBUG_BLOCK_PRINT) { \ - printf(fmt, ## __VA_ARGS__); \ - } \ -} while (0) +#include "trace.h" =20 /* OS X does not have O_DSYNC */ #ifndef O_DSYNC @@ -1411,7 +1399,7 @@ static int xfs_write_zeroes(BDRVRawState *s, int64_t = offset, uint64_t bytes) =20 if (xfsctl(NULL, s->fd, XFS_IOC_ZERO_RANGE, &fl) < 0) { err =3D errno; - DPRINTF("cannot write zero range (%s)\n", strerror(errno)); + trace_file_xfs_write_zeroes(strerror(errno)); return -err; } =20 @@ -1430,7 +1418,7 @@ static int xfs_discard(BDRVRawState *s, int64_t offse= t, uint64_t bytes) =20 if (xfsctl(NULL, s->fd, XFS_IOC_UNRESVSP64, &fl) < 0) { err =3D errno; - DPRINTF("cannot punch hole (%s)\n", strerror(errno)); + trace_file_xfs_discard(strerror(errno)); return -err; } =20 @@ -2819,7 +2807,7 @@ static char *FindEjectableOpticalMedia(io_iterator_t = *mediaIterator) =20 /* If a match was found, leave the loop */ if (*mediaIterator !=3D 0) { - DPRINTF("Matching using %s\n", matching_array[index]); + trace_file_FindEjectableOpticalMedia(matching_array[index]); mediaType =3D g_strdup(matching_array[index]); break; } @@ -2879,7 +2867,7 @@ static bool setup_cdrom(char *bsd_path, Error **errp) if (partition_found =3D=3D false) { error_setg(errp, "Failed to find a working partition on disc"); } else { - DPRINTF("Using %s as optical disc\n", test_partition); + trace_file_setup_cdrom(test_partition); pstrcpy(bsd_path, MAXPATHLEN, test_partition); } return partition_found; @@ -2974,8 +2962,7 @@ static bool hdev_is_sg(BlockDriverState *bs) =20 ret =3D ioctl(s->fd, SG_GET_SCSI_ID, &scsiid); if (ret >=3D 0) { - DPRINTF("SG device found: type=3D%d, version=3D%d\n", - scsiid.scsi_type, sg_version); + trace_file_hdev_is_sg(scsiid.scsi_type, sg_version); return true; } =20 diff --git a/block/trace-events b/block/trace-events index 8ea8d1eaeb..41b998b7eb 100644 --- a/block/trace-events +++ b/block/trace-events @@ -186,3 +186,10 @@ curl_open(const char *file) "opening %s" curl_open_size(uint64_t size) "size =3D %" PRIu64 curl_setup_preadv(uint64_t bytes, uint64_t start, const char *range) "read= ing %" PRIu64 " at %" PRIu64 " (%s)" curl_close(void) "close" + +# block/file-posix.c +file_xfs_write_zeroes(const char *error) "cannot write zero range (%s)" +file_xfs_discard(const char *error) "cannot punch hole (%s)" +file_FindEjectableOpticalMedia(const char *media) "Matching using %s" +file_setup_cdrom(const char *partition) "Using %s as optical disc" +file_hdev_is_sg(int type, int version) "SG device found: type=3D%d, versio= n=3D%d" --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15488967703151.161612468422959; Wed, 30 Jan 2019 17:06:10 -0800 (PST) Received: from localhost ([127.0.0.1]:46913 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0ns-0003r1-6t for importer@patchew.org; Wed, 30 Jan 2019 20:06:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0iW-0008UX-Cl for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0iS-0008PC-8h for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33624) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0iH-0007wi-PV; Wed, 30 Jan 2019 20:00:17 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 885EE89AC7; Thu, 31 Jan 2019 01:00:11 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B0B1617D58; Thu, 31 Jan 2019 01:00:04 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:38 +0100 Message-Id: <20190131005945.20149-7-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 31 Jan 2019 01:00:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/13] block/sheepdog: Convert from DPRINTF() macro to trace events 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Laurent Vivier Signed-off-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20181213162727.17438-5-lvivier@redhat.com [mreitz: Fixed sheepdog_snapshot_create_inode's format string to use PRIx32 for uint32_ts] Signed-off-by: Max Reitz --- block/sheepdog.c | 47 +++++++++++++++++----------------------------- block/trace-events | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index ed14f7afbe..b916ba07bf 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -28,6 +28,7 @@ #include "sysemu/block-backend.h" #include "qemu/bitops.h" #include "qemu/cutils.h" +#include "trace.h" =20 #define SD_PROTO_VER 0x01 =20 @@ -299,19 +300,6 @@ static inline size_t count_data_objs(const struct Shee= pdogInode *inode) (1UL << inode->block_size_shift)); } =20 -#undef DPRINTF -#ifdef DEBUG_SDOG -#define DEBUG_SDOG_PRINT 1 -#else -#define DEBUG_SDOG_PRINT 0 -#endif -#define DPRINTF(fmt, args...) \ - do { \ - if (DEBUG_SDOG_PRINT) { \ - fprintf(stderr, "%s %d: " fmt, __func__, __LINE__, ##args); \ - } \ - } while (0) - typedef struct SheepdogAIOCB SheepdogAIOCB; typedef struct BDRVSheepdogState BDRVSheepdogState; =20 @@ -750,7 +738,7 @@ static coroutine_fn void reconnect_to_sdog(void *opaque) Error *local_err =3D NULL; s->fd =3D get_sheep_fd(s, &local_err); if (s->fd < 0) { - DPRINTF("Wait for connection to be established\n"); + trace_sheepdog_reconnect_to_sdog(); error_report_err(local_err); qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000000ULL); } @@ -847,7 +835,7 @@ static void coroutine_fn aio_read_response(void *opaque) break; case AIOCB_FLUSH_CACHE: if (rsp.result =3D=3D SD_RES_INVALID_PARMS) { - DPRINTF("disable cache since the server doesn't support it\n"); + trace_sheepdog_aio_read_response(); s->cache_flags =3D SD_FLAG_CMD_DIRECT; rsp.result =3D SD_RES_SUCCESS; } @@ -1639,7 +1627,7 @@ static int sd_open(BlockDriverState *bs, QDict *optio= ns, int flags, s->discard_supported =3D true; =20 if (snap_id || tag[0]) { - DPRINTF("%" PRIx32 " snapshot inode was open.\n", vid); + trace_sheepdog_open(vid); s->is_snapshot =3D true; } =20 @@ -2252,7 +2240,7 @@ static void sd_close(BlockDriverState *bs) unsigned int wlen, rlen =3D 0; int fd, ret; =20 - DPRINTF("%s\n", s->name); + trace_sheepdog_close(s->name); =20 fd =3D connect_to_sdog(s, &local_err); if (fd < 0) { @@ -2429,7 +2417,7 @@ static int sd_create_branch(BDRVSheepdogState *s) char *buf; bool deleted; =20 - DPRINTF("%" PRIx32 " is snapshot.\n", s->inode.vdi_id); + trace_sheepdog_create_branch_snapshot(s->inode.vdi_id); =20 buf =3D g_malloc(SD_INODE_SIZE); =20 @@ -2445,7 +2433,7 @@ static int sd_create_branch(BDRVSheepdogState *s) goto out; } =20 - DPRINTF("%" PRIx32 " is created.\n", vid); + trace_sheepdog_create_branch_created(vid); =20 fd =3D connect_to_sdog(s, &local_err); if (fd < 0) { @@ -2467,7 +2455,7 @@ static int sd_create_branch(BDRVSheepdogState *s) =20 s->is_snapshot =3D false; ret =3D 0; - DPRINTF("%" PRIx32 " was newly created.\n", s->inode.vdi_id); + trace_sheepdog_create_branch_new(s->inode.vdi_id); =20 out: g_free(buf); @@ -2561,11 +2549,11 @@ static void coroutine_fn sd_co_rw_vector(SheepdogAI= OCB *acb) } =20 if (create) { - DPRINTF("update ino (%" PRIu32 ") %" PRIu64 " %" PRIu64 " %ld\= n", - inode->vdi_id, oid, - vid_to_data_oid(inode->data_vdi_id[idx], idx), idx); + trace_sheepdog_co_rw_vector_update(inode->vdi_id, oid, + vid_to_data_oid(inode->data_vdi_id[idx],= idx), + idx); oid =3D vid_to_data_oid(inode->vdi_id, idx); - DPRINTF("new oid %" PRIx64 "\n", oid); + trace_sheepdog_co_rw_vector_new(oid); } =20 aio_req =3D alloc_aio_req(s, acb, oid, len, offset, flags, create, @@ -2670,9 +2658,8 @@ static int sd_snapshot_create(BlockDriverState *bs, Q= EMUSnapshotInfo *sn_info) SheepdogInode *inode; unsigned int datalen; =20 - DPRINTF("sn_info: name %s id_str %s s: name %s vm_state_size %" PRId64= " " - "is_snapshot %d\n", sn_info->name, sn_info->id_str, - s->name, sn_info->vm_state_size, s->is_snapshot); + trace_sheepdog_snapshot_create_info(sn_info->name, sn_info->id_str, s-= >name, + sn_info->vm_state_size, s->is_snap= shot); =20 if (s->is_snapshot) { error_report("You can't create a snapshot of a snapshot VDI, " @@ -2681,7 +2668,7 @@ static int sd_snapshot_create(BlockDriverState *bs, Q= EMUSnapshotInfo *sn_info) return -EINVAL; } =20 - DPRINTF("%s %s\n", sn_info->name, sn_info->id_str); + trace_sheepdog_snapshot_create(sn_info->name, sn_info->id_str); =20 s->inode.vm_state_size =3D sn_info->vm_state_size; s->inode.vm_clock_nsec =3D sn_info->vm_clock_nsec; @@ -2726,8 +2713,8 @@ static int sd_snapshot_create(BlockDriverState *bs, Q= EMUSnapshotInfo *sn_info) } =20 memcpy(&s->inode, inode, datalen); - DPRINTF("s->inode: name %s snap_id %x oid %x\n", - s->inode.name, s->inode.snap_id, s->inode.vdi_id); + trace_sheepdog_snapshot_create_inode(s->inode.name, s->inode.snap_id, + s->inode.vdi_id); =20 cleanup: g_free(inode); diff --git a/block/trace-events b/block/trace-events index 41b998b7eb..70056eafd2 100644 --- a/block/trace-events +++ b/block/trace-events @@ -193,3 +193,17 @@ file_xfs_discard(const char *error) "cannot punch hole= (%s)" file_FindEjectableOpticalMedia(const char *media) "Matching using %s" file_setup_cdrom(const char *partition) "Using %s as optical disc" file_hdev_is_sg(int type, int version) "SG device found: type=3D%d, versio= n=3D%d" + +# block/sheepdog.c +sheepdog_reconnect_to_sdog(void) "Wait for connection to be established" +sheepdog_aio_read_response(void) "disable cache since the server doesn't s= upport it" +sheepdog_open(uint32_t vid) "0x%" PRIx32 " snapshot inode was open" +sheepdog_close(const char *name) "%s" +sheepdog_create_branch_snapshot(uint32_t vdi) "0x%" PRIx32 " is snapshot" +sheepdog_create_branch_created(uint32_t vdi) "0x%" PRIx32 " is created" +sheepdog_create_branch_new(uint32_t vdi) "0x%" PRIx32 " was newly created" +sheepdog_co_rw_vector_update(uint32_t vdi, uint64_t oid, uint64_t data, lo= ng idx) "update ino (%" PRIu32 ") %" PRIu64 " %" PRIu64 " %ld" +sheepdog_co_rw_vector_new(uint64_t oid) "new oid 0x%" PRIx64 +sheepdog_snapshot_create_info(const char *sn_name, const char *id, const c= har *name, int64_t size, int is_snapshot) "sn_info: name %s id_str %s s: na= me %s vm_state_size %" PRId64 " " "is_snapshot %d" +sheepdog_snapshot_create(const char *sn_name, const char *id) "%s %s" +sheepdog_snapshot_create_inode(const char *name, uint32_t snap, uint32_t v= di) "s->inode: name %s snap_id 0x%" PRIx32 " vdi 0x%" PRIx32 --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548896776108125.30448647418939; Wed, 30 Jan 2019 17:06:16 -0800 (PST) Received: from localhost ([127.0.0.1]:46917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0ny-0003v4-46 for importer@patchew.org; Wed, 30 Jan 2019 20:06:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0iW-0008UW-CU for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0iR-0008Oj-R7 for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35368) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0iF-00083z-Ne; Wed, 30 Jan 2019 20:00:17 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BCB08F51F; Thu, 31 Jan 2019 01:00:14 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C725C62671; Thu, 31 Jan 2019 01:00:13 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:39 +0100 Message-Id: <20190131005945.20149-8-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 31 Jan 2019 01:00:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/13] qemu-io: Add generic function for reinitializing optind. 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Richard W.M. Jones" On FreeBSD 11.2: $ nbdkit memory size=3D1M --run './qemu-io -f raw -c "aio_write 0 512" $n= bd' Parsing error: non-numeric argument, or extraneous/unrecognized suffix --= aio_write After main option parsing, we reinitialize optind so we can parse each command. However reinitializing optind to 0 does not work on FreeBSD. What happens when you do this is optind remains 0 after the option parsing loop, and the result is we try to parse argv[optind] =3D=3D argv[0] =3D=3D "aio_write" as if it was the first parameter. The FreeBSD manual page says: In order to use getopt() to evaluate multiple sets of arguments, or to evaluate a single set of arguments multiple times, the variable optreset must be set to 1 before the second and each additional set of calls to getopt(), and the variable optind must be reinitialized. (From the rest of the man page it is clear that optind must be reinitialized to 1). The glibc man page says: A program that scans multiple argument vectors, or rescans the same vector more than once, and wants to make use of GNU extensions such as '+' and '-' at the start of optstring, or changes the value of POSIXLY_CORRECT between scans, must reinitialize getopt() by resetting optind to 0, rather than the traditional value of 1. (Resetting to 0 forces the invocation of an internal initialization routine that rechecks POSIXLY_CORRECT and checks for GNU extensions in optstring.) This commit introduces an OS-portability function called qemu_reset_optind which provides a way of resetting optind that works on FreeBSD and platforms that use optreset, while keeping it the same as now on other platforms. Note that the qemu codebase sets optind in many other places, but in those other places it's setting a local variable and not using getopt. This change is only needed in places where we are using getopt and the associated global variable optind. Signed-off-by: Richard W.M. Jones Message-id: 20190118101114.11759-2-rjones@redhat.com Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- configure | 14 ++++++++++++++ include/qemu/osdep.h | 16 ++++++++++++++++ qemu-img.c | 2 +- qemu-io-cmds.c | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/configure b/configure index b18281c61f..831d26d4ae 100755 --- a/configure +++ b/configure @@ -4269,6 +4269,17 @@ if compile_prog "" "" ; then signalfd=3Dyes fi =20 +# check if optreset global is declared by +optreset=3D"no" +cat > $TMPC << EOF +#include +int main(void) { return optreset; } +EOF + +if compile_prog "" "" ; then + optreset=3Dyes +fi + # check if eventfd is supported eventfd=3Dno cat > $TMPC << EOF @@ -6643,6 +6654,9 @@ fi if test "$signalfd" =3D "yes" ; then echo "CONFIG_SIGNALFD=3Dy" >> $config_host_mak fi +if test "$optreset" =3D "yes" ; then + echo "HAVE_OPTRESET=3Dy" >> $config_host_mak +fi if test "$tcg" =3D "yes"; then echo "CONFIG_TCG=3Dy" >> $config_host_mak if test "$tcg_interpreter" =3D "yes" ; then diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 80df7253db..840af09cb0 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -109,6 +109,7 @@ extern int daemon(int, int); #include #include #include +#include #include #include #include @@ -604,4 +605,19 @@ extern int qemu_icache_linesize_log; extern int qemu_dcache_linesize; extern int qemu_dcache_linesize_log; =20 +/* + * After using getopt or getopt_long, if you need to parse another set + * of options, then you must reset optind. Unfortunately the way to + * do this varies between implementations of getopt. + */ +static inline void qemu_reset_optind(void) +{ +#ifdef HAVE_OPTRESET + optind =3D 1; + optreset =3D 1; +#else + optind =3D 0; +#endif +} + #endif diff --git a/qemu-img.c b/qemu-img.c index ad04f59565..25288c4d18 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4962,7 +4962,7 @@ int main(int argc, char **argv) return 0; } argv +=3D optind; - optind =3D 0; + qemu_reset_optind(); =20 if (!trace_init_backends()) { exit(1); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 2c39124036..ee8f56e46a 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -114,7 +114,7 @@ static int command(BlockBackend *blk, const cmdinfo_t *= ct, int argc, } } =20 - optind =3D 0; + qemu_reset_optind(); return ct->cfunc(blk, argc, argv); } =20 --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548897106391654.713701329538; Wed, 30 Jan 2019 17:11:46 -0800 (PST) Received: from localhost ([127.0.0.1]:47010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0tN-0000L1-Db for importer@patchew.org; Wed, 30 Jan 2019 20:11:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0ie-000069-SF for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0iW-0008TK-CR for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59222) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0iI-0008EO-1a; Wed, 30 Jan 2019 20:00:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BB4580F9A; Thu, 31 Jan 2019 01:00:17 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7996019743; Thu, 31 Jan 2019 01:00:16 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:40 +0100 Message-Id: <20190131005945.20149-9-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 31 Jan 2019 01:00:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/13] nvme: use TYPE_NVME instead of constant string 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Li Qiang Signed-off-by: Li Qiang Reviewed-by: Max Reitz Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20190120055558.32984-2-liq3ea@163.com Signed-off-by: Max Reitz --- hw/block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 7c8c63e8f5..f206391e8e 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1381,7 +1381,7 @@ static void nvme_instance_init(Object *obj) } =20 static const TypeInfo nvme_info =3D { - .name =3D "nvme", + .name =3D TYPE_NVME, .parent =3D TYPE_PCI_DEVICE, .instance_size =3D sizeof(NvmeCtrl), .class_init =3D nvme_class_init, --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548897224857755.3434838670113; Wed, 30 Jan 2019 17:13:44 -0800 (PST) Received: from localhost ([127.0.0.1]:47034 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0vH-0001wN-QA for importer@patchew.org; Wed, 30 Jan 2019 20:13:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0in-0000Cj-I7 for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0ik-00009Z-TU for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35418) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0iP-0008Kq-QA; Wed, 30 Jan 2019 20:00:28 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E6FD9387E; Thu, 31 Jan 2019 01:00:20 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 86C2C9067; Thu, 31 Jan 2019 01:00:19 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:41 +0100 Message-Id: <20190131005945.20149-10-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 31 Jan 2019 01:00:20 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/13] nvme: ensure the num_queues is not zero 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Li Qiang When it is zero, it causes segv. Using following command: "-drive file=3D//home/test/test1.img,if=3Dnone,id=3Did0 -device nvme,drive=3Did0,serial=3Dtest,num_queues=3D0" causes following Backtrack: Thread 4 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffe9735700 (LWP 30952)] 0x0000555555a7a77c in nvme_start_ctrl (n=3D0x5555577473f0) at hw/block/nvme= .c:825 825 if (unlikely(n->cq[0])) { (gdb) bt 0 0x0000555555a7a77c in nvme_start_ctrl (n=3D0x5555577473f0) at hw/block/nvme.c:825 1 0x0000555555a7af7f in nvme_write_bar (n=3D0x5555577473f0, offset=3D20, data=3D4587521, size=3D4) at hw/block/nvme.c:969 2 0x0000555555a7b81a in nvme_mmio_write (opaque=3D0x5555577473f0, addr=3D2= 0, data=3D4587521, size=3D4) at hw/block/nvme.c:1163 3 0x0000555555869236 in memory_region_write_accessor (mr=3D0x555557747cd0, addr=3D20, value=3D0x7fffe97320f8, size=3D4, shift=3D0, mask=3D42949672= 95, attrs=3D...) at /home/test/qemu1/qemu/memory.c:502 4 0x0000555555869446 in access_with_adjusted_size (addr=3D20, value=3D0x7fffe97320f8, size=3D4, access_size_min=3D2, access_size_max= =3D8, access_fn=3D0x55555586914d , mr=3D0x555557747cd0, attrs=3D...) at /home/test/qemu1/qemu/memory.c:568 5 0x000055555586c479 in memory_region_dispatch_write (mr=3D0x555557747cd0, addr=3D20, data=3D4587521, size=3D4, attrs=3D...) at /home/test/qemu1/qemu/memory.c:1499 6 0x00005555558030af in flatview_write_continue (fv=3D0x7fffe0061130, addr=3D4273930260, attrs=3D..., buf=3D0x7ffff7ff0028 "\001", len=3D4, a= ddr1=3D20, l=3D4, mr=3D0x555557747cd0) at /home/test/qemu1/qemu/exec.c:3234 7 0x00005555558031f9 in flatview_write (fv=3D0x7fffe0061130, addr=3D427393= 0260, attrs=3D..., buf=3D0x7ffff7ff0028 "\001", len=3D4) at /home/test/qemu1/qemu/exec.c:3273 8 0x00005555558034ff in address_space_write ( Reviewed-by: Philippe Mathieu-Daud=C3=A9 ---Type to continue, or q to quit--- as=3D0x555556758480 , addr=3D4273930260, attrs=3D= ..., buf=3D0x7ffff7ff0028 "\001", len=3D4) at /home/test/qemu1/qemu/exec.c:3= 363 9 0x0000555555803550 in address_space_rw ( as=3D0x555556758480 , addr=3D4273930260, attrs=3D= ..., buf=3D0x7ffff7ff0028 "\001", len=3D4, is_write=3Dtrue) at /home/test/qemu1/qemu/exec.c:3374 10 0x00005555558884a1 in kvm_cpu_exec (cpu=3D0x555556920e40) at /home/test/qemu1/qemu/accel/kvm/kvm-all.c:2031 11 0x000055555584cd9d in qemu_kvm_cpu_thread_fn (arg=3D0x555556920e40) at /home/test/qemu1/qemu/cpus.c:1281 12 0x0000555555dbaf6d in qemu_thread_start (args=3D0x5555569438a0) at util/qemu-thread-posix.c:502 13 0x00007ffff5dc86db in start_thread (arg=3D0x7fffe9735700) at pthread_create.c:463 14 0x00007ffff5af188f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 Signed-off-by: Li Qiang Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20190120055558.32984-3-liq3ea@163.com Signed-off-by: Max Reitz --- hw/block/nvme.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index f206391e8e..0b77b49b36 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1208,6 +1208,11 @@ static void nvme_realize(PCIDevice *pci_dev, Error *= *errp) int64_t bs_size; uint8_t *pci_conf; =20 + if (!n->num_queues) { + error_setg(errp, "num_queues can't be zero"); + return; + } + if (!n->conf.blk) { error_setg(errp, "drive property not set"); return; --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548896799849864.0489219931362; Wed, 30 Jan 2019 17:06:39 -0800 (PST) Received: from localhost ([127.0.0.1]:46919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0oL-0004IW-Nm for importer@patchew.org; Wed, 30 Jan 2019 20:06:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0io-0000DQ-AL for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0im-0000BK-Bl for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33166) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0iT-0008MP-RX; Wed, 30 Jan 2019 20:00:32 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DFE0F81DEB; Thu, 31 Jan 2019 01:00:22 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4BBEB5C236; Thu, 31 Jan 2019 01:00:22 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:42 +0100 Message-Id: <20190131005945.20149-11-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 31 Jan 2019 01:00:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/13] nvme: use pci_dev directly in nvme_realize 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Li Qiang There is no need to make another reference. Signed-off-by: Li Qiang Reviewed-by: Max Reitz Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20190120055558.32984-4-liq3ea@163.com Signed-off-by: Max Reitz --- hw/block/nvme.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 0b77b49b36..8325b5e88a 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1238,7 +1238,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **= errp) pci_conf[PCI_INTERRUPT_PIN] =3D 1; pci_config_set_prog_interface(pci_dev->config, 0x2); pci_config_set_class(pci_dev->config, PCI_CLASS_STORAGE_EXPRESS); - pcie_endpoint_cap_init(&n->parent_obj, 0x80); + pcie_endpoint_cap_init(pci_dev, 0x80); =20 n->num_namespaces =3D 1; n->reg_size =3D pow2ceil(0x1004 + 2 * (n->num_queues + 1) * 4); @@ -1250,10 +1250,10 @@ static void nvme_realize(PCIDevice *pci_dev, Error = **errp) =20 memory_region_init_io(&n->iomem, OBJECT(n), &nvme_mmio_ops, n, "nvme", n->reg_size); - pci_register_bar(&n->parent_obj, 0, + pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64, &n->iomem); - msix_init_exclusive_bar(&n->parent_obj, n->num_queues, 4, NULL); + msix_init_exclusive_bar(pci_dev, n->num_queues, 4, NULL); =20 id->vid =3D cpu_to_le16(pci_get_word(pci_conf + PCI_VENDOR_ID)); id->ssvid =3D cpu_to_le16(pci_get_word(pci_conf + PCI_SUBSYSTEM_VENDOR= _ID)); @@ -1308,7 +1308,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **= errp) n->cmbuf =3D g_malloc0(NVME_CMBSZ_GETSIZE(n->bar.cmbsz)); memory_region_init_io(&n->ctrl_mem, OBJECT(n), &nvme_cmb_ops, n, "nvme-cmb", NVME_CMBSZ_GETSIZE(n->bar.cmbsz)= ); - pci_register_bar(&n->parent_obj, NVME_CMBLOC_BIR(n->bar.cmbloc), + pci_register_bar(pci_dev, NVME_CMBLOC_BIR(n->bar.cmbloc), PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64 | PCI_BASE_ADDRESS_MEM_PREFETCH, &n->ctrl_mem); =20 --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548896952315183.84465241816213; Wed, 30 Jan 2019 17:09:12 -0800 (PST) Received: from localhost ([127.0.0.1]:46941 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0qj-0006HX-SK for importer@patchew.org; Wed, 30 Jan 2019 20:09:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0iq-0000Eo-AC for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0io-0000Kv-9K for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33220) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0iZ-0008OT-FC; Wed, 30 Jan 2019 20:00:37 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D82F81DFE; Thu, 31 Jan 2019 01:00:27 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 278F45D96F; Thu, 31 Jan 2019 01:00:24 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:43 +0100 Message-Id: <20190131005945.20149-12-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 31 Jan 2019 01:00:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/13] iotests.py: Add qemu_nbd_pipe() 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In some cases, we may want to deal with qemu-nbd errors (e.g. by launching it in a different configuration until it no longer throws any). In that case, we do not want its output ending up in the test output. It may still be useful for handling the error, though, so add a new function that works basically like qemu_nbd(), only that it returns the qemu-nbd output instead of making it end up in the log. In contrast to qemu_img_pipe(), it does still return the exit code as well, though, because that is even more important for error handling. Signed-off-by: Max Reitz Message-id: 20181221234750.23577-2-mreitz@redhat.com Reviewed-by: John Snow Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- tests/qemu-iotests/iotests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index cbedfaf1df..009c614ef7 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -201,6 +201,20 @@ def qemu_nbd(*args): '''Run qemu-nbd in daemon mode and return the parent's exit code''' return subprocess.call(qemu_nbd_args + ['--fork'] + list(args)) =20 +def qemu_nbd_pipe(*args): + '''Run qemu-nbd in daemon mode and return both the parent's exit code + and its output''' + subp =3D subprocess.Popen(qemu_nbd_args + ['--fork'] + list(args), + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, + universal_newlines=3DTrue) + exitcode =3D subp.wait() + if exitcode < 0: + sys.stderr.write('qemu-nbd received signal %i: %s\n' % + (-exitcode, + ' '.join(qemu_nbd_args + ['--fork'] + list(args)= ))) + return exitcode, subp.communicate()[0] + def compare_images(img1, img2, fmt1=3Dimgfmt, fmt2=3Dimgfmt): '''Return True if two image files are identical''' return qemu_img('compare', '-f', fmt1, --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15488971119985.087012498090303; Wed, 30 Jan 2019 17:11:51 -0800 (PST) Received: from localhost ([127.0.0.1]:47012 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0tN-0000MI-Sf for importer@patchew.org; Wed, 30 Jan 2019 20:11:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0j1-0000QU-Ok for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:01:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0iz-0000Zu-0P for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:01:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57428) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0iu-0008Sa-HQ; Wed, 30 Jan 2019 20:00:56 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2919FC059B77; Thu, 31 Jan 2019 01:00:31 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 702085D97E; Thu, 31 Jan 2019 01:00:29 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:44 +0100 Message-Id: <20190131005945.20149-13-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 31 Jan 2019 01:00:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/13] iotests: Bind qemu-nbd to localhost in 147 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" By default, qemu-nbd binds to 0.0.0.0. However, we then proceed to connect to "localhost". Usually, this works out fine; but if this test is run concurrently, some other test function may have bound a different server to ::1 (on the same port -- you can bind different serves to the same port, as long as one is on IPv4 and the other on IPv6). So running qemu-nbd works, it can bind to 0.0.0.0:NBD_PORT. But potentially a concurrent test has successfully taken [::1]:NBD_PORT. In this case, trying to connect to "localhost" will lead us to the IPv6 instance, where we do not want to end up. Fix this by just binding to "localhost". This will make qemu-nbd error out immediately and not give us cryptic errors later. (Also, it will allow us to just try a different port as of a future patch.) Signed-off-by: Max Reitz Message-id: 20181221234750.23577-3-mreitz@redhat.com Reviewed-by: John Snow Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- tests/qemu-iotests/147 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/147 b/tests/qemu-iotests/147 index 05b374b7d3..3e10a9969e 100755 --- a/tests/qemu-iotests/147 +++ b/tests/qemu-iotests/147 @@ -92,7 +92,7 @@ class QemuNBD(NBDBlockdevAddBase): self.assertEqual(qemu_nbd('-f', imgfmt, test_img, *args), 0) =20 def test_inet(self): - self._server_up('-p', str(NBD_PORT)) + self._server_up('-b', 'localhost', '-p', str(NBD_PORT)) address =3D { 'type': 'inet', 'data': { 'host': 'localhost', --=20 2.20.1 From nobody Thu May 2 20:44:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548896953251345.7014923719263; Wed, 30 Jan 2019 17:09:13 -0800 (PST) Received: from localhost ([127.0.0.1]:46944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0qo-0006Ng-V1 for importer@patchew.org; Wed, 30 Jan 2019 20:09:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37851) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gp0iu-0000J2-KU for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gp0is-0000Od-Ko for qemu-devel@nongnu.org; Wed, 30 Jan 2019 20:00:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35606) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gp0im-00006m-AV; Wed, 30 Jan 2019 20:00:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D1518B10D; Thu, 31 Jan 2019 01:00:41 +0000 (UTC) Received: from localhost (ovpn-204-20.brq.redhat.com [10.40.204.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FF7A5C239; Thu, 31 Jan 2019 01:00:33 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 31 Jan 2019 01:59:45 +0100 Message-Id: <20190131005945.20149-14-mreitz@redhat.com> In-Reply-To: <20190131005945.20149-1-mreitz@redhat.com> References: <20190131005945.20149-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 31 Jan 2019 01:00:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 13/13] iotests: Allow 147 to be run concurrently 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" To do this, we need to allow creating the NBD server on various ports instead of a single one (which may not even work if you run just one instance, because something entirely else might be using that port). So we just pick a random port in [32768, 32768 + 1024) and try to create a server there. If that fails, we just retry until something sticks. For the IPv6 test, we need a different range, though (just above that one). This is because "localhost" resolves to both 127.0.0.1 and ::1. This means that if you bind to it, it will bind to both, if possible, or just one if the other is already in use. Therefore, if the IPv6 test has already taken [::1]:some_port and we then try to take localhost:some_port, that will work -- only the second server will be bound to 127.0.0.1:some_port alone and not [::1]:some_port in addition. So we have two different servers on the same port, one for IPv4 and one for IPv6. But when we then try to connect to the server through localhost:some_port, we will always end up at the IPv6 one (as long as it is up), and this may not be the one we want. Thus, we must make sure not to create an IPv6-only NBD server on the same port as a normal "dual-stack" NBD server -- which is done by using distinct port ranges, as explained above. Signed-off-by: Max Reitz Message-id: 20181221234750.23577-4-mreitz@redhat.com Reviewed-by: John Snow Signed-off-by: Max Reitz --- tests/qemu-iotests/147 | 98 +++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 30 deletions(-) diff --git a/tests/qemu-iotests/147 b/tests/qemu-iotests/147 index 3e10a9969e..82513279b0 100755 --- a/tests/qemu-iotests/147 +++ b/tests/qemu-iotests/147 @@ -19,13 +19,17 @@ # =20 import os +import random import socket import stat import time import iotests -from iotests import cachemode, imgfmt, qemu_img, qemu_nbd +from iotests import cachemode, imgfmt, qemu_img, qemu_nbd, qemu_nbd_pipe =20 -NBD_PORT =3D 10811 +NBD_PORT_START =3D 32768 +NBD_PORT_END =3D NBD_PORT_START + 1024 +NBD_IPV6_PORT_START =3D NBD_PORT_END +NBD_IPV6_PORT_END =3D NBD_IPV6_PORT_START + 1024 =20 test_img =3D os.path.join(iotests.test_dir, 'test.img') unix_socket =3D os.path.join(iotests.test_dir, 'nbd.socket') @@ -88,17 +92,29 @@ class QemuNBD(NBDBlockdevAddBase): except OSError: pass =20 + def _try_server_up(self, *args): + status, msg =3D qemu_nbd_pipe('-f', imgfmt, test_img, *args) + if status =3D=3D 0: + return True + if 'Address already in use' in msg: + return False + self.fail(msg) + def _server_up(self, *args): - self.assertEqual(qemu_nbd('-f', imgfmt, test_img, *args), 0) + self.assertTrue(self._try_server_up(*args)) =20 def test_inet(self): - self._server_up('-b', 'localhost', '-p', str(NBD_PORT)) + while True: + nbd_port =3D random.randrange(NBD_PORT_START, NBD_PORT_END) + if self._try_server_up('-b', 'localhost', '-p', str(nbd_port)): + break + address =3D { 'type': 'inet', 'data': { 'host': 'localhost', - 'port': str(NBD_PORT) + 'port': str(nbd_port) } } - self.client_test('nbd://localhost:%i' % NBD_PORT, + self.client_test('nbd://localhost:%i' % nbd_port, flatten_sock_addr(address)) =20 def test_unix(self): @@ -130,8 +146,13 @@ class BuiltinNBD(NBDBlockdevAddBase): except OSError: pass =20 - def _server_up(self, address, export_name=3DNone, export_name2=3DNone): + # Returns False on EADDRINUSE; fails an assertion on other errors. + # Returns True on success. + def _try_server_up(self, address, export_name=3DNone, export_name2=3DN= one): result =3D self.server.qmp('nbd-server-start', addr=3Daddress) + if 'error' in result and \ + 'Address already in use' in result['error']['desc']: + return False self.assert_qmp(result, 'return', {}) =20 if export_name is None: @@ -146,20 +167,28 @@ class BuiltinNBD(NBDBlockdevAddBase): name=3Dexport_name2) self.assert_qmp(result, 'return', {}) =20 + return True + + def _server_up(self, address, export_name=3DNone, export_name2=3DNone): + self.assertTrue(self._try_server_up(address, export_name, export_n= ame2)) =20 def _server_down(self): result =3D self.server.qmp('nbd-server-stop') self.assert_qmp(result, 'return', {}) =20 def do_test_inet(self, export_name=3DNone): - address =3D { 'type': 'inet', - 'data': { - 'host': 'localhost', - 'port': str(NBD_PORT) - } } - self._server_up(address, export_name) + while True: + nbd_port =3D random.randrange(NBD_PORT_START, NBD_PORT_END) + address =3D { 'type': 'inet', + 'data': { + 'host': 'localhost', + 'port': str(nbd_port) + } } + if self._try_server_up(address, export_name): + break + export_name =3D export_name or 'nbd-export' - self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, export_name), + self.client_test('nbd://localhost:%i/%s' % (nbd_port, export_name), flatten_sock_addr(address), export_name) self._server_down() =20 @@ -173,15 +202,19 @@ class BuiltinNBD(NBDBlockdevAddBase): self.do_test_inet('shadow') =20 def test_inet_two_exports(self): - address =3D { 'type': 'inet', - 'data': { - 'host': 'localhost', - 'port': str(NBD_PORT) - } } - self._server_up(address, 'exp1', 'exp2') - self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, 'exp1'), + while True: + nbd_port =3D random.randrange(NBD_PORT_START, NBD_PORT_END) + address =3D { 'type': 'inet', + 'data': { + 'host': 'localhost', + 'port': str(nbd_port) + } } + if self._try_server_up(address, 'exp1', 'exp2'): + break + + self.client_test('nbd://localhost:%i/%s' % (nbd_port, 'exp1'), flatten_sock_addr(address), 'exp1', 'node1', Fals= e) - self.client_test('nbd://localhost:%i/%s' % (NBD_PORT, 'exp2'), + self.client_test('nbd://localhost:%i/%s' % (nbd_port, 'exp2'), flatten_sock_addr(address), 'exp2', 'node2', Fals= e) result =3D self.vm.qmp('blockdev-del', node_name=3D'node1') self.assert_qmp(result, 'return', {}) @@ -197,20 +230,25 @@ class BuiltinNBD(NBDBlockdevAddBase): except socket.gaierror: # IPv6 not available, skip return - address =3D { 'type': 'inet', - 'data': { - 'host': '::1', - 'port': str(NBD_PORT), - 'ipv4': False, - 'ipv6': True - } } + + while True: + nbd_port =3D random.randrange(NBD_IPV6_PORT_START, NBD_IPV6_PO= RT_END) + address =3D { 'type': 'inet', + 'data': { + 'host': '::1', + 'port': str(nbd_port), + 'ipv4': False, + 'ipv6': True + } } + if self._try_server_up(address): + break + filename =3D { 'driver': 'raw', 'file': { 'driver': 'nbd', 'export': 'nbd-export', 'server': flatten_sock_addr(address) } } - self._server_up(address) self.client_test(filename, flatten_sock_addr(address), 'nbd-export= ') self._server_down() =20 --=20 2.20.1