From nobody Fri May 10 18:32:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775325; cv=none; d=zohomail.com; s=zohoarc; b=ejXG8/cZRt/TyS6KNneFH3aCbGpMIavLwd9ZWJ97rNtHFaM9T+0hptpkxR7pEdUiBXLsaUS6emMbEA8omcQ8Dyx4qFu3CINL1XCUoWlJ7jc05Owz2t+DWY5UsTcf67bkxMgHzRrqBj2S5RJBTCeN0z0st6af2BjQ/A85VmdYxEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775325; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iUPaYx9SEogE5y/lpqf3W4dYtEIMMMgaH2X8hn5+Asw=; b=XtDsQwUGNdfAZfRAxUJVc9TgCmNKt5KBblXoLn117DCSoHs5fN3lqAB1UtKEsp6LDgNTgLT5YnNOJp/kdbtgmMf6g2fR7NESvJk72w0l9SYLjwIBERRDRc9xVzcb0O55VvFP2rj5GoYK7zn2mgxb7OgSZ1qr11QHbF5JUlbOvZ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775325400957.4789030794639; Mon, 26 Oct 2020 22:08:45 -0700 (PDT) Received: from localhost ([::1]:38178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHDw-0005Tm-72 for importer@patchew.org; Tue, 27 Oct 2020 01:08:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBV-0003Zv-D0 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBR-0003aU-9f for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-126-yopv1wYTM3qun-NVjv9TiQ-1; Tue, 27 Oct 2020 01:06:04 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 073928049D8; Tue, 27 Oct 2020 05:06:03 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CE7010013C4; Tue, 27 Oct 2020 05:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iUPaYx9SEogE5y/lpqf3W4dYtEIMMMgaH2X8hn5+Asw=; b=BxhR+B7dBO1232K3zJdSYg5R6ikg/9vnFIMvMaMKmHZ+CqSPgzpsjb1Lreb2MoK4tuL41D lRkUfFvZGQFtN0njjPg+V7OLKxko4jxqMNvqjQ5/11tHWAw6zM70zzh4Rq16ZgUwvV/Zyd o1//OL3uk4fqyrrG3+FuD+Z0ImCM4k0= X-MC-Unique: yopv1wYTM3qun-NVjv9TiQ-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 01/11] block: Simplify QAPI_LIST_ADD Date: Tue, 27 Oct 2020 00:05:46 -0500 Message-Id: <20201027050556.269064-2-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, rjones@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There is no need to rely on the verbosity of the gcc/clang compiler extension of g_new(typeof(X), 1) when we can instead use the standard g_malloc(sizeof(X)). In general, we like g_new over g_malloc for returning type X rather than void* to let the compiler catch more potential typing mistakes, but in this particular macro, our other use of typeof on the same line already ensures we are getting correct results. Suggested-by: Markus Armbruster Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block.c b/block.c index 430edf79bb10..857387f3912f 100644 --- a/block.c +++ b/block.c @@ -5231,7 +5231,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(bool flat, } #define QAPI_LIST_ADD(list, element) do { \ - typeof(list) _tmp =3D g_new(typeof(*(list)), 1); \ + typeof(list) _tmp =3D g_malloc(sizeof(*(list))); \ _tmp->value =3D (element); \ _tmp->next =3D (list); \ (list) =3D _tmp; \ --=20 2.29.0 From nobody Fri May 10 18:32:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775325; cv=none; d=zohomail.com; s=zohoarc; b=Ke5WxQV5c6Fja/UjZtup7hbSq05uvOd+I9QMGp4jyb61o73atJ2S3moD7ddncYO3iWvxpm5Y17Ithjjb57ZbdPr//5qLXuAS4LEfrDXL5iJsRrdvGaboz+G/d+0J9H+lqySLJUoXI+XBcWSp32Q5mbsCGSfTOafsNkvQf7DAwdc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775325; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SvTmrX5dvWmHG4tb3pp1JPR9105Ks56YCJEDsQySNkE=; b=mDuTwvqyvEIzykM69VTdl4p7Oy5+ryFySkNpErGCwXlBfulIJtWleoqY9wmsd713m4ZcgWKbc4lh4r+TKWXsiuzda5wrHwfAxWFUU6LEU8F/xJVM9uZcofij1ZxXGTFFege79Zpp8IGnzykRRqD2wb8mwGBEnEOa+iOyVnapVds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775325053364.7459323983353; Mon, 26 Oct 2020 22:08:45 -0700 (PDT) Received: from localhost ([::1]:38162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHDw-0005TU-1l for importer@patchew.org; Tue, 27 Oct 2020 01:08:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBV-0003Zw-Dm for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28209) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBR-0003ZU-6q for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-240-VRXYWAVRN2-YK2aFBHnN7Q-1; Tue, 27 Oct 2020 01:06:05 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 489618030A9; Tue, 27 Oct 2020 05:06:04 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 364CD10021AA; Tue, 27 Oct 2020 05:06:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SvTmrX5dvWmHG4tb3pp1JPR9105Ks56YCJEDsQySNkE=; b=L6sbJT/oPL9ttF7ShZgKMiX7a5TUn3xQxxhAt9hvr62HXx8E/Xgr6Kiv9UXlMBPaZZKN51 bDYuKMVWAtueyNuHoQh4ncGhvYm/qjKCUc/KFigwpJoY9Eg3fRVWIKHdHpQdaayI1yxqD/ JnOdq/IWNmYt+e7/zXKSJTl0dzC+nag= X-MC-Unique: VRXYWAVRN2-YK2aFBHnN7Q-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 02/11] qapi: Make QAPI_LIST_ADD() public Date: Tue, 27 Oct 2020 00:05:47 -0500 Message-Id: <20201027050556.269064-3-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, Michael Roth , qemu-block@nongnu.org, armbru@redhat.com, rjones@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We have a useful macro for inserting at the front of any QAPI-generated list; move it from block.c to qapi/util.h so more places can use it, including one earlier place in block.c. There are many more places in the codebase that can benefit from using the macro, but converting them will be left to later patches. In theory, all QAPI list types are child classes of GenericList; but in practice, that relationship is not explicitly spelled out in the C type declarations (rather, it is something that happens implicitly due to C compatible layouts), and the macro does not actually depend on the GenericList type. We considered moving GenericList from visitor.h into util.h to group related code; however, such a move would be awkward if we do not also move GenericAlternate. Unfortunately, moving GenericAlternate would introduce its own problems of declaration circularity (qapi-builtin-types.h needs a complete definition of QEnumLookup from util.h, but GenericAlternate needs a complete definition of QType from qapi-builtin-types.h). Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Markus Armbruster --- include/qapi/util.h | 8 ++++++++ block.c | 14 ++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/qapi/util.h b/include/qapi/util.h index a7c3c6414874..501abca38eaa 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -22,4 +22,12 @@ int qapi_enum_parse(const QEnumLookup *lookup, const cha= r *buf, int parse_qapi_name(const char *name, bool complete); +/* For any GenericList @list, insert @element at the front. */ +#define QAPI_LIST_ADD(list, element) do { \ + typeof(list) _tmp =3D g_malloc(sizeof(*(list))); \ + _tmp->value =3D (element); \ + _tmp->next =3D (list); \ + (list) =3D _tmp; \ +} while (0) + #endif diff --git a/block.c b/block.c index 857387f3912f..8f9df5547d5a 100644 --- a/block.c +++ b/block.c @@ -5211,7 +5211,7 @@ BlockDriverState *bdrv_find_node(const char *node_nam= e) BlockDeviceInfoList *bdrv_named_nodes_list(bool flat, Error **errp) { - BlockDeviceInfoList *list, *entry; + BlockDeviceInfoList *list; BlockDriverState *bs; list =3D NULL; @@ -5221,22 +5221,12 @@ BlockDeviceInfoList *bdrv_named_nodes_list(bool fla= t, qapi_free_BlockDeviceInfoList(list); return NULL; } - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D list; - list =3D entry; + QAPI_LIST_ADD(list, info); } return list; } -#define QAPI_LIST_ADD(list, element) do { \ - typeof(list) _tmp =3D g_malloc(sizeof(*(list))); \ - _tmp->value =3D (element); \ - _tmp->next =3D (list); \ - (list) =3D _tmp; \ -} while (0) - typedef struct XDbgBlockGraphConstructor { XDbgBlockGraph *graph; GHashTable *graph_nodes; --=20 2.29.0 From nobody Fri May 10 18:32:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775498; cv=none; d=zohomail.com; s=zohoarc; b=b52bqRS1K9zwuvLiCY0bpYmHalEvO1A9UKkavXvSoonmLE8juN1Z9qFlPXGnzQQ37LlltBTZUU5AqMYgBYr+DBsLqCgoVIDN6ShaTPOTtYiWyVPJapOUed/W/tsoB8SZoLgDH2xUmUvErSDlzlUxrxMt+UNmVjnM05QGfuLGSHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775498; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZWYbqFNwxpKPiT1i+Cn0vPwrw+2jp+Lik7CHaPsATHQ=; b=NDzI2pgmDZA84yqKqD+hODKkNTEUfsMdAziX8L5fZr5fO1Eb8wqfJMEbK/sTB0MSGySmdTqEIfdb8o/L+YZdVPP78fH97kmx9dtdapBXWsatyy03E1QbOl7bpuXFxLgG8JJUWkx4twPh0Um0oU7THzO9/mT/q6W/6sgCAOfEXRI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775498641331.9785185716521; Mon, 26 Oct 2020 22:11:38 -0700 (PDT) Received: from localhost ([::1]:46510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHGj-0000ea-GZ for importer@patchew.org; Tue, 27 Oct 2020 01:11:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBZ-0003dy-U6 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26223) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBR-0003aj-F0 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-175-TQowQxPpN26t39LJ3YpTrQ-1; Tue, 27 Oct 2020 01:06:06 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 310AD8049DD; Tue, 27 Oct 2020 05:06:05 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74CCC10013C4; Tue, 27 Oct 2020 05:06:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZWYbqFNwxpKPiT1i+Cn0vPwrw+2jp+Lik7CHaPsATHQ=; b=Go3fvZ7mx8s0qxO8wwevq07WE2NOhlin1LOFccTgklidOsKURfbS19vcSdUMJVwijvsbor sw9OOX3VTMcEjRW6+8pGY12/o51rKn6eqR33XqNFJK4QYOQhltgVKIJAVxRP7HS1Xq9k/s 6xepieS0TrJScXaso4cS/SLa9QUonmc= X-MC-Unique: TQowQxPpN26t39LJ3YpTrQ-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 03/11] nbd: Utilize QAPI_CLONE for type conversion Date: Tue, 27 Oct 2020 00:05:48 -0500 Message-Id: <20201027050556.269064-4-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:06 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, rjones@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Rather than open-coding the translation from the deprecated NbdServerAddOptions type to the preferred BlockExportOptionsNbd, it's better to utilize QAPI_CLONE_MEMBERS. This solves a couple of issues: first, if we do any more refactoring of the base type (which an upcoming patch plans to do), we don't have to revisit the open-coding. Second, our assignment to arg->name is fishy: the generated QAPI code for qapi_free_NbdServerAddOptions does not visit arg->name if arg->has_name is false, but if it DID visit it, we would have introduced a double-free situation when arg is finally freed. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Markus Armbruster --- blockdev-nbd.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 8174023e5c47..cee9134b12eb 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -14,6 +14,8 @@ #include "sysemu/block-backend.h" #include "hw/block/block.h" #include "qapi/error.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-block-export.h" #include "qapi/qapi-commands-block-export.h" #include "block/nbd.h" #include "io/channel-socket.h" @@ -195,7 +197,8 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Error= **errp) * the device name as a default here for compatibility. */ if (!arg->has_name) { - arg->name =3D arg->device; + arg->has_name =3D true; + arg->name =3D g_strdup(arg->device); } export_opts =3D g_new(BlockExportOptions, 1); @@ -205,15 +208,9 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Erro= r **errp) .node_name =3D g_strdup(bdrv_get_node_name(bs)), .has_writable =3D arg->has_writable, .writable =3D arg->writable, - .u.nbd =3D { - .has_name =3D true, - .name =3D g_strdup(arg->name), - .has_description =3D arg->has_description, - .description =3D g_strdup(arg->description), - .has_bitmap =3D arg->has_bitmap, - .bitmap =3D g_strdup(arg->bitmap), - }, }; + QAPI_CLONE_MEMBERS(BlockExportOptionsNbd, &export_opts->u.nbd, + qapi_NbdServerAddOptions_base(arg)); /* * nbd-server-add doesn't complain when a read-only device should be --=20 2.29.0 From nobody Fri May 10 18:32:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775537; cv=none; d=zohomail.com; s=zohoarc; b=JRAYR0qaptRXINVyoGsj3VCnvpED7qTczLN4TPLz7Ln4KS3hQ6BO+C9nEtY4UHgMsmInA+mW33wjJg90L9lXVmZyK+x3u893nK14lrZv/KSHNyrzZBQBxac0kQDwNw6+jJLDx7tGC5PD+l0fM41iCRkMdq3cD/8VsUj6gW53UKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775537; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FvaDvtH3P5Qsc6kTB1OKH+ufr3m1DHjzyCnu6/82Acs=; b=X/k4tPHYOTnIH7Mm4tG537/77/xp2sRO6D2ZsbQUuis1hDd63lXngpDZ6ADWzlbe5JAI0y4sPLSyW/EMjcJ83Xei0yICD96LETQbI30ynQ/iXCG0d755ALxHbov/27jk+ckrf5a4FLUjBnCNTT7eCrmqoGcqzbhqDmK3Mhs25Qw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775537042360.01968650348806; Mon, 26 Oct 2020 22:12:17 -0700 (PDT) Received: from localhost ([::1]:47366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHHL-00011M-9k for importer@patchew.org; Tue, 27 Oct 2020 01:12:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45168) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBa-0003eX-4s for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60819) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBV-0003c2-4y for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-418-FlVAcpqzPT-9w0Jg86Mj2Q-1; Tue, 27 Oct 2020 01:06:10 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E57511074658; Tue, 27 Oct 2020 05:06:08 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 612CF10013C4; Tue, 27 Oct 2020 05:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FvaDvtH3P5Qsc6kTB1OKH+ufr3m1DHjzyCnu6/82Acs=; b=Jmh2dK65Xcc6eaLypQVHrJiFziynKSF5hgrx6sK27ne2Xs7KhVE7biLP8vnLrK6l/YF0lq 2k4my8zNR2ky5kam5HqK0QBXFjaWOHAKY3nvG5jeHFuu9uqs5A4HE71WkGhAvBRv2h5+6D T8wJrhEGgYLjjA1CSf/wXZY4gB5RUH8= X-MC-Unique: FlVAcpqzPT-9w0Jg86Mj2Q-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 04/11] nbd: Update qapi to support exporting multiple bitmaps Date: Tue, 27 Oct 2020 00:05:49 -0500 Message-Id: <20201027050556.269064-5-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-block@nongnu.org, "reviewer:Incompatible changes" , armbru@redhat.com, rjones@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Since 'block-export-add' is new to 5.2, we can still tweak the interface; there, allowing 'bitmaps':['str'] is nicer than 'bitmap':'str'. This wires up the qapi and qemu-nbd changes to permit passing multiple bitmaps as distinct metadata contexts that the NBD client may request, but the actual support for more than one will require a further patch to the server. Note that there are no changes made to the existing deprecated 'nbd-server-add' command; this required splitting the QAPI type BlockExportOptionsNbd, which fortunately does not affect QMP introspection. Signed-off-by: Eric Blake Reviewed-by: Peter Krempa Reviewed-by: Vladimir Sementsov-Ogievskiy --- docs/system/deprecated.rst | 3 ++- qapi/block-export.json | 41 +++++++++++++++++++++++++++----------- blockdev-nbd.c | 6 +++++- nbd/server.c | 19 ++++++++++++------ qemu-nbd.c | 18 ++++++++--------- 5 files changed, 58 insertions(+), 29 deletions(-) diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst index 0ebce37a1919..32a0e620dbb9 100644 --- a/docs/system/deprecated.rst +++ b/docs/system/deprecated.rst @@ -257,7 +257,8 @@ the 'wait' field, which is only applicable to sockets i= n server mode '''''''''''''''''''''''''''''''''''''''''''''''''''''''' Use the more generic commands ``block-export-add`` and ``block-export-del`` -instead. +instead. As part of this deprecation, where ``nbd-server-add`` used a +single ``bitmap``, the new ``block-export-add`` uses a list of ``bitmaps``. Human Monitor Protocol (HMP) commands ------------------------------------- diff --git a/qapi/block-export.json b/qapi/block-export.json index 480c497690b0..c4125f4d2104 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -63,10 +63,10 @@ '*max-connections': 'uint32' } } ## -# @BlockExportOptionsNbd: +# @BlockExportOptionsNbdBase: # -# An NBD block export (options shared between nbd-server-add and the NBD b= ranch -# of block-export-add). +# An NBD block export (common options shared between nbd-server-add and +# the NBD branch of block-export-add). # # @name: Export name. If unspecified, the @device parameter is used as the # export name. (Since 2.12) @@ -74,15 +74,27 @@ # @description: Free-form description of the export, up to 4096 bytes. # (Since 5.0) # -# @bitmap: Also export the dirty bitmap reachable from @device, so the -# NBD client can use NBD_OPT_SET_META_CONTEXT with -# "qemu:dirty-bitmap:NAME" to inspect the bitmap. (since 4.0) -# # Since: 5.0 ## +{ 'struct': 'BlockExportOptionsNbdBase', + 'data': { '*name': 'str', '*description': 'str' } } + +## +# @BlockExportOptionsNbd: +# +# An NBD block export (distinct options used in the NBD branch of +# block-export-add). +# +# @bitmaps: Also export each of the named dirty bitmaps reachable from +# @device, so the NBD client can use NBD_OPT_SET_META_CONTEXT wi= th +# the metadata context name "qemu:dirty-bitmap:BITMAP" to inspect +# each bitmap. +# +# Since: 5.2 +## { 'struct': 'BlockExportOptionsNbd', - 'data': { '*name': 'str', '*description': 'str', - '*bitmap': 'str' } } + 'base': 'BlockExportOptionsNbdBase', + 'data': { '*bitmaps': ['str'] } } ## # @BlockExportOptionsVhostUserBlk: @@ -106,19 +118,24 @@ ## # @NbdServerAddOptions: # -# An NBD block export. +# An NBD block export, per legacy nbd-server-add command. # # @device: The device name or node name of the node to be exported # # @writable: Whether clients should be able to write to the device via the # NBD connection (default false). # +# @bitmap: Also export a single dirty bitmap reachable from @device, so the +# NBD client can use NBD_OPT_SET_META_CONTEXT with the metadata +# context name "qemu:dirty-bitmap:BITMAP" to inspect the bitmap +# (since 4.0). +# # Since: 5.0 ## { 'struct': 'NbdServerAddOptions', - 'base': 'BlockExportOptionsNbd', + 'base': 'BlockExportOptionsNbdBase', 'data': { 'device': 'str', - '*writable': 'bool' } } + '*writable': 'bool', '*bitmap': 'str' } } ## # @nbd-server-add: diff --git a/blockdev-nbd.c b/blockdev-nbd.c index cee9134b12eb..d1d41f635564 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -209,8 +209,12 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Erro= r **errp) .has_writable =3D arg->has_writable, .writable =3D arg->writable, }; - QAPI_CLONE_MEMBERS(BlockExportOptionsNbd, &export_opts->u.nbd, + QAPI_CLONE_MEMBERS(BlockExportOptionsNbdBase, &export_opts->u.nbd, qapi_NbdServerAddOptions_base(arg)); + if (arg->has_bitmap) { + export_opts->u.nbd.has_bitmaps =3D true; + QAPI_LIST_ADD(export_opts->u.nbd.bitmaps, g_strdup(arg->bitmap)); + } /* * nbd-server-add doesn't complain when a read-only device should be diff --git a/nbd/server.c b/nbd/server.c index 08b621f70a3a..8d01662b4511 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1474,6 +1474,7 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, uint64_t perm, shared_perm; bool readonly =3D !exp_args->writable; bool shared =3D !exp_args->writable; + strList *bitmaps; int ret; assert(exp_args->type =3D=3D BLOCK_EXPORT_TYPE_NBD); @@ -1533,12 +1534,18 @@ static int nbd_export_create(BlockExport *blk_exp, = BlockExportOptions *exp_args, } exp->size =3D QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE); - if (arg->bitmap) { + /* XXX Allow more than one bitmap */ + if (arg->bitmaps && arg->bitmaps->next) { + error_setg(errp, "multiple bitmaps per export not supported yet"); + return -EOPNOTSUPP; + } + for (bitmaps =3D arg->bitmaps; bitmaps; bitmaps =3D bitmaps->next) { + const char *bitmap =3D bitmaps->value; BlockDriverState *bs =3D blk_bs(blk); BdrvDirtyBitmap *bm =3D NULL; while (bs) { - bm =3D bdrv_find_dirty_bitmap(bs, arg->bitmap); + bm =3D bdrv_find_dirty_bitmap(bs, bitmap); if (bm !=3D NULL) { break; } @@ -1548,7 +1555,7 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, if (bm =3D=3D NULL) { ret =3D -ENOENT; - error_setg(errp, "Bitmap '%s' is not found", arg->bitmap); + error_setg(errp, "Bitmap '%s' is not found", bitmap); goto fail; } @@ -1562,15 +1569,15 @@ static int nbd_export_create(BlockExport *blk_exp, = BlockExportOptions *exp_args, ret =3D -EINVAL; error_setg(errp, "Enabled bitmap '%s' incompatible with readonly exp= ort", - arg->bitmap); + bitmap); goto fail; } bdrv_dirty_bitmap_set_busy(bm, true); exp->export_bitmap =3D bm; - assert(strlen(arg->bitmap) <=3D BDRV_BITMAP_MAX_NAME_SIZE); + assert(strlen(bitmap) <=3D BDRV_BITMAP_MAX_NAME_SIZE); exp->export_bitmap_context =3D g_strdup_printf("qemu:dirty-bitmap:= %s", - arg->bitmap); + bitmap); assert(strlen(exp->export_bitmap_context) < NBD_MAX_STRING_SIZE); } diff --git a/qemu-nbd.c b/qemu-nbd.c index a0701cdf369d..4b7825c44093 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -574,7 +574,7 @@ int main(int argc, char **argv) QDict *options =3D NULL; const char *export_name =3D NULL; /* defaults to "" later for server m= ode */ const char *export_description =3D NULL; - const char *bitmap =3D NULL; + strList *bitmaps =3D NULL; const char *tlscredsid =3D NULL; bool imageOpts =3D false; bool writethrough =3D true; @@ -690,7 +690,7 @@ int main(int argc, char **argv) flags &=3D ~BDRV_O_RDWR; break; case 'B': - bitmap =3D optarg; + QAPI_LIST_ADD(bitmaps, g_strdup(optarg)); break; case 'k': sockpath =3D optarg; @@ -786,7 +786,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } if (export_name || export_description || dev_offset || - device || disconnect || fmt || sn_id_or_name || bitmap || + device || disconnect || fmt || sn_id_or_name || bitmaps || seen_aio || seen_discard || seen_cache) { error_report("List mode is incompatible with per-device settin= gs"); exit(EXIT_FAILURE); @@ -1067,12 +1067,12 @@ int main(int argc, char **argv) .has_writable =3D true, .writable =3D !readonly, .u.nbd =3D { - .has_name =3D true, - .name =3D g_strdup(export_name), - .has_description =3D !!export_description, - .description =3D g_strdup(export_description), - .has_bitmap =3D !!bitmap, - .bitmap =3D g_strdup(bitmap), + .has_name =3D true, + .name =3D g_strdup(export_name), + .has_description =3D !!export_description, + .description =3D g_strdup(export_description), + .has_bitmaps =3D !!bitmaps, + .bitmaps =3D bitmaps, }, }; blk_exp_add(export_opts, &error_fatal); --=20 2.29.0 From nobody Fri May 10 18:32:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775698; cv=none; d=zohomail.com; s=zohoarc; b=d9xy3JTsl9Ou7OzhaDgQ+ijn18QIHVIGr+z0oJpuyVI21/lHf2WmWx7uFYjxKJWJ5uQ3OeMwr9VFMaxRqM0M2u4KGP7soeP/7j/NLM2357ne0M5NxantrWHLzVRcIT6aDPEtaw0CS7iIVyEu9mbZOQzwBMyawnW8oObyl890pak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775698; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zwBP9HjsGxV5iraIIjZ56i2ALzjA/r7kkxOclK2kfv4=; b=WMSMycaI6xpUioneCjmfOFlMcd5Ws9mOlWNkkpvyG9gy6EF1jHuMFUiCMTINXKPd7eusEPSr5Qks9UfpxIDhIo514Jtym7/MvfIsnZ9HsNvnh2V0Tagr4ZuelnXWjpA2fEl5qHlOIZtwZERUIoeEfC1JrQHnPAKeW8N96SX9Vrw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775698981733.2604964680577; Mon, 26 Oct 2020 22:14:58 -0700 (PDT) Received: from localhost ([::1]:56416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHJu-0004l0-Q2 for importer@patchew.org; Tue, 27 Oct 2020 01:14:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBf-0003l6-4O for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36340) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBZ-0003cy-5J for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-423-_EgDuB2oNIyoXKjK_CPP4w-1; Tue, 27 Oct 2020 01:06:10 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE5328030A9; Tue, 27 Oct 2020 05:06:09 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FA5510013C4; Tue, 27 Oct 2020 05:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zwBP9HjsGxV5iraIIjZ56i2ALzjA/r7kkxOclK2kfv4=; b=CAdHtupqQAAL9ESWfZPKUcnbDrxBFQZQaVzF+JxT2+xYUJO8uTnhlri3bn6jQttLFLNlDo o8yhFehzG6cPFj95vKICXEBDCBphULA4VJ8qdPlBqF+d+t3DLxVZyodTf06ZP32B/PKq3J /XaiCIDaEi29zBoDBQP1Hdo29qRbwi4= X-MC-Unique: _EgDuB2oNIyoXKjK_CPP4w-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 05/11] nbd: Simplify qemu bitmap context name Date: Tue, 27 Oct 2020 00:05:50 -0500 Message-Id: <20201027050556.269064-6-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:06 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, rjones@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Each dirty bitmap already knows its name; by reducing the scope of the places where we construct "qemu:dirty-bitmap:NAME" strings, tracking the name is more localized, and there are fewer per-export fields to worry about. This in turn will make it easier for an upcoming patch to export more than one bitmap at once. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 8d01662b4511..77fdecdf9dec 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -95,7 +95,6 @@ struct NBDExport { Notifier eject_notifier; BdrvDirtyBitmap *export_bitmap; - char *export_bitmap_context; }; static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_HEAD_INITIALIZER(export= s); @@ -871,14 +870,15 @@ static bool nbd_meta_qemu_query(NBDClient *client, NB= DExportMetaContexts *meta, } if (nbd_strshift(&query, "dirty-bitmap:")) { + const char *bm_name; + trace_nbd_negotiate_meta_query_parse("dirty-bitmap:"); if (!meta->exp->export_bitmap) { trace_nbd_negotiate_meta_query_skip("no dirty-bitmap exported"= ); return true; } - if (nbd_meta_empty_or_pattern(client, - meta->exp->export_bitmap_context + - strlen("qemu:dirty-bitmap:"), query)= ) { + bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_bitmap); + if (nbd_meta_empty_or_pattern(client, bm_name, query)) { meta->bitmap =3D true; } return true; @@ -1004,8 +1004,11 @@ static int nbd_negotiate_meta_queries(NBDClient *cli= ent, } if (meta->bitmap) { - ret =3D nbd_negotiate_send_meta_context(client, - meta->exp->export_bitmap_con= text, + const char *bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_b= itmap); + g_autofree char *context =3D g_strdup_printf("qemu:dirty-bitmap:%s= ", + bm_name); + + ret =3D nbd_negotiate_send_meta_context(client, context, NBD_META_ID_DIRTY_BITMAP, errp); if (ret < 0) { @@ -1576,9 +1579,6 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, bdrv_dirty_bitmap_set_busy(bm, true); exp->export_bitmap =3D bm; assert(strlen(bitmap) <=3D BDRV_BITMAP_MAX_NAME_SIZE); - exp->export_bitmap_context =3D g_strdup_printf("qemu:dirty-bitmap:= %s", - bitmap); - assert(strlen(exp->export_bitmap_context) < NBD_MAX_STRING_SIZE); } blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, ex= p); @@ -1656,7 +1656,6 @@ static void nbd_export_delete(BlockExport *blk_exp) if (exp->export_bitmap) { bdrv_dirty_bitmap_set_busy(exp->export_bitmap, false); - g_free(exp->export_bitmap_context); } } --=20 2.29.0 From nobody Fri May 10 18:32:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775363; cv=none; d=zohomail.com; s=zohoarc; b=RiX9Qj+ceOjxuJ7SKlEX6/fDF5mBCWUReoK7Z2MbBV3AJqfvqRzXo3P+x+m1mDYRGi4wuAnOrUyh7Jqa3uUe6IDz58kJUPolBpTf/OsNvyey3MP23/R4Dbc/ywpdfgGzif+ndTmgsKwF4eAnPAIgoIu+3i9oX7aMm3A5CF7gl/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775363; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9Fx4Xc8KNGhO1AvvQtLftNIsCL8c/r5u79mPg3Yj20A=; b=iVrW6cNlbDqKXQyhexoRwZffGwkl5irobwKxFbfaQoqJSI6MP3CKrvPqFcjpLLTw9bO/9k/yxfEmY0xCkT5qFOIfUybXKQSGIHiSkqDwx2bQFEy6d9LoOid5DA7eR0B8GLMIjzq5CtSN1kZXPf27I8CH/JumYbBT826vsciR5YA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775363499603.518690454906; Mon, 26 Oct 2020 22:09:23 -0700 (PDT) Received: from localhost ([::1]:39824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHEY-0006B3-E7 for importer@patchew.org; Tue, 27 Oct 2020 01:09:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBc-0003gM-E4 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26243) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBW-0003cM-Ny for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:20 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-447-ATwnL2hfPYO7x8QhqGCYsw-1; Tue, 27 Oct 2020 01:06:11 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 966CC100746B; Tue, 27 Oct 2020 05:06:10 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBA3910013C4; Tue, 27 Oct 2020 05:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Fx4Xc8KNGhO1AvvQtLftNIsCL8c/r5u79mPg3Yj20A=; b=XWKwPKX6TuTelOIsYuSUgVchnoUZ82spLm9js/cft3ytsFLuvQogK5RTIlW99BEza4IGhA ReLjyXi1ucU4e9o5OCcv9xN4HiOVucMfrKMgsH5Ai+Qin37ITd9esU4v3y3U0prCaUjnXd jL0RXuJgii23ntbPcWennLTuwYF0wQU= X-MC-Unique: ATwnL2hfPYO7x8QhqGCYsw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 06/11] nbd: Refactor counting of metadata contexts Date: Tue, 27 Oct 2020 00:05:51 -0500 Message-Id: <20201027050556.269064-7-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:06 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, rjones@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Rather than open-code the count of negotiated contexts at several sites, embed it directly into the struct. This will make it easier for upcoming commits to support even more simultaneous contexts. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 77fdecdf9dec..42d494bc9616 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -104,8 +104,7 @@ static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_HEAD= _INITIALIZER(exports); * NBD_OPT_LIST_META_CONTEXT. */ typedef struct NBDExportMetaContexts { NBDExport *exp; - bool valid; /* means that negotiation of the option finished without - errors */ + size_t count; /* number of negotiated contexts */ bool base_allocation; /* export base:allocation context (block status)= */ bool bitmap; /* export qemu:dirty-bitmap: */ } NBDExportMetaContexts; @@ -445,7 +444,9 @@ static int nbd_negotiate_handle_list(NBDClient *client,= Error **errp) static void nbd_check_meta_export(NBDClient *client) { - client->export_meta.valid &=3D client->exp =3D=3D client->export_meta.= exp; + if (client->exp !=3D client->export_meta.exp) { + client->export_meta.count =3D 0; + } } /* Send a reply to NBD_OPT_EXPORT_NAME. @@ -945,6 +946,7 @@ static int nbd_negotiate_meta_queries(NBDClient *client, NBDExportMetaContexts local_meta; uint32_t nb_queries; int i; + size_t count =3D 0; if (!client->structured_reply) { return nbd_opt_invalid(client, errp, @@ -1001,6 +1003,7 @@ static int nbd_negotiate_meta_queries(NBDClient *clie= nt, if (ret < 0) { return ret; } + count++; } if (meta->bitmap) { @@ -1014,11 +1017,12 @@ static int nbd_negotiate_meta_queries(NBDClient *cl= ient, if (ret < 0) { return ret; } + count++; } ret =3D nbd_negotiate_send_rep(client, NBD_REP_ACK, errp); if (ret =3D=3D 0) { - meta->valid =3D true; + meta->count =3D count; } return ret; @@ -2337,18 +2341,16 @@ static coroutine_fn int nbd_handle_request(NBDClien= t *client, return nbd_send_generic_reply(client, request->handle, -EINVAL, "need non-zero length", errp); } - if (client->export_meta.valid && - (client->export_meta.base_allocation || - client->export_meta.bitmap)) - { + if (client->export_meta.count) { bool dont_fragment =3D request->flags & NBD_CMD_FLAG_REQ_ONE; + int contexts_remaining =3D client->export_meta.count; if (client->export_meta.base_allocation) { ret =3D nbd_co_send_block_status(client, request->handle, blk_bs(exp->common.blk), request->from, request->len, dont_fragment, - !client->export_meta.bitmap, + !--contexts_remaining, NBD_META_ID_BASE_ALLOCATION, errp); if (ret < 0) { @@ -2360,13 +2362,15 @@ static coroutine_fn int nbd_handle_request(NBDClien= t *client, ret =3D nbd_co_send_bitmap(client, request->handle, client->exp->export_bitmap, request->from, request->len, - dont_fragment, - true, NBD_META_ID_DIRTY_BITMAP, e= rrp); + dont_fragment, !--contexts_remain= ing, + NBD_META_ID_DIRTY_BITMAP, errp); if (ret < 0) { return ret; } } + assert(!contexts_remaining); + return 0; } else { return nbd_send_generic_reply(client, request->handle, -EINVAL, --=20 2.29.0 From nobody Fri May 10 18:32:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775501; cv=none; d=zohomail.com; s=zohoarc; b=UkBE5OOlttp94E3oR+fjkiSOWptssYLJgzKnS389pf6SmqzrhopbH95NWwSsDmKTEp0IjjTC44rPjWuT/6f0EI+OTTpc/YHuJanrPyIyawi+pVAQCkdtR/M52ny44OUCwzkx+YFRekSwgJoIw2eB5EdpULiV+hz1Ur5Z4ttS6DQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775501; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/RegGtDczshYmkbCCsHc+yotURCo6VJW03YdInOIJ3k=; b=CUTYmPFjI4KDvjVgh9mpUzvm7JUEEOygczDZw4UoSAA/pIrZBmZIgxQYiT5M+sL3N5fcXuKxB5uClIkYLtwiK2ItIqLIYZIr5ccnuE5UMWDlPhzRwCL89ERW98hWEzBruaNfRTAlmavzmhqL5cDJG8dr34yj3Nm2cqBL+SbivUY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775501209323.3188474560287; Mon, 26 Oct 2020 22:11:41 -0700 (PDT) Received: from localhost ([::1]:46652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHGl-0000ib-Uf for importer@patchew.org; Tue, 27 Oct 2020 01:11:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBi-0003n9-QH for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBZ-0003d2-5C for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:26 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-503-9urZGgFXPba77dSDNmr7Iw-1; Tue, 27 Oct 2020 01:06:12 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83303100746A; Tue, 27 Oct 2020 05:06:11 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id C85B610013C4; Tue, 27 Oct 2020 05:06:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/RegGtDczshYmkbCCsHc+yotURCo6VJW03YdInOIJ3k=; b=T5dcFXeKfHyl6VU1WfMY0UU/oUg3DdHA6BYKYg2j5Ny8fS6imygaqaM2n0Xo3mG6arJjMS WT4Ket2Jpc+oxqJD04WXxOgioXmKhu9+tdRxHSgM34k9uoLP7KtPsufQBv4GMrpj8/8+63 q70Mgkg3zSkBLtfPKU7HEU85hFCbwiU= X-MC-Unique: 9urZGgFXPba77dSDNmr7Iw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 07/11] nbd: Allow export of multiple bitmaps for one device Date: Tue, 27 Oct 2020 00:05:52 -0500 Message-Id: <20201027050556.269064-8-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:06 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, rjones@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" With this, 'qemu-nbd -B b0 -B b1 -f qcow2 img.qcow2' can let you sniff out multiple bitmaps from one server. qemu-img as client can still only read one bitmap per client connection, but other NBD clients (hello libnbd) can now read multiple bitmaps in a single pass. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 100 ++++++++++++++++++++++++++++------------- tests/qemu-iotests/291 | 6 +-- 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 42d494bc9616..b6841e455414 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -27,6 +27,7 @@ #include "qemu/units.h" #define NBD_META_ID_BASE_ALLOCATION 0 +/* Dirty bitmaps use 'NBD_META_ID_DIRTY_BITMAP + i', so keep this id last.= */ #define NBD_META_ID_DIRTY_BITMAP 1 /* @@ -94,7 +95,8 @@ struct NBDExport { BlockBackend *eject_notifier_blk; Notifier eject_notifier; - BdrvDirtyBitmap *export_bitmap; + BdrvDirtyBitmap **export_bitmaps; + size_t nr_export_bitmaps; }; static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_HEAD_INITIALIZER(export= s); @@ -106,7 +108,10 @@ typedef struct NBDExportMetaContexts { NBDExport *exp; size_t count; /* number of negotiated contexts */ bool base_allocation; /* export base:allocation context (block status)= */ - bool bitmap; /* export qemu:dirty-bitmap: */ + bool *bitmaps; /* + * export qemu:dirty-bitmap:, + * sized by exp->nr_export_bitmaps + */ } NBDExportMetaContexts; struct NBDClient { @@ -857,6 +862,8 @@ static bool nbd_meta_base_query(NBDClient *client, NBDE= xportMetaContexts *meta, static bool nbd_meta_qemu_query(NBDClient *client, NBDExportMetaContexts *= meta, const char *query) { + size_t i; + if (!nbd_strshift(&query, "qemu:")) { return false; } @@ -864,24 +871,33 @@ static bool nbd_meta_qemu_query(NBDClient *client, NB= DExportMetaContexts *meta, if (!*query) { if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { - meta->bitmap =3D !!meta->exp->export_bitmap; + memset(meta->bitmaps, 1, meta->exp->nr_export_bitmaps); } trace_nbd_negotiate_meta_query_parse("empty"); return true; } if (nbd_strshift(&query, "dirty-bitmap:")) { - const char *bm_name; - trace_nbd_negotiate_meta_query_parse("dirty-bitmap:"); - if (!meta->exp->export_bitmap) { - trace_nbd_negotiate_meta_query_skip("no dirty-bitmap exported"= ); + if (!*query) { + if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { + memset(meta->bitmaps, 1, meta->exp->nr_export_bitmaps); + } + trace_nbd_negotiate_meta_query_parse("empty"); return true; } - bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_bitmap); - if (nbd_meta_empty_or_pattern(client, bm_name, query)) { - meta->bitmap =3D true; + + for (i =3D 0; i < meta->exp->nr_export_bitmaps; i++) { + const char *bm_name; + + bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_bitmaps[i= ]); + if (strcmp(bm_name, query) =3D=3D 0) { + meta->bitmaps[i] =3D true; + trace_nbd_negotiate_meta_query_parse(query); + return true; + } } + trace_nbd_negotiate_meta_query_skip("no dirty-bitmap match"); return true; } @@ -943,9 +959,10 @@ static int nbd_negotiate_meta_queries(NBDClient *clien= t, { int ret; g_autofree char *export_name =3D NULL; - NBDExportMetaContexts local_meta; + g_autofree bool *bitmaps =3D NULL; + NBDExportMetaContexts local_meta =3D {0}; uint32_t nb_queries; - int i; + size_t i; size_t count =3D 0; if (!client->structured_reply) { @@ -960,6 +977,7 @@ static int nbd_negotiate_meta_queries(NBDClient *client, meta =3D &local_meta; } + g_free(meta->bitmaps); memset(meta, 0, sizeof(*meta)); ret =3D nbd_opt_read_name(client, &export_name, NULL, errp); @@ -974,6 +992,10 @@ static int nbd_negotiate_meta_queries(NBDClient *clien= t, return nbd_opt_drop(client, NBD_REP_ERR_UNKNOWN, errp, "export '%s' not present", sane_name); } + meta->bitmaps =3D g_new0(bool, meta->exp->nr_export_bitmaps); + if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { + bitmaps =3D meta->bitmaps; + } ret =3D nbd_opt_read(client, &nb_queries, sizeof(nb_queries), false, e= rrp); if (ret <=3D 0) { @@ -986,7 +1008,7 @@ static int nbd_negotiate_meta_queries(NBDClient *clien= t, if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT && !nb_queries) { /* enable all known contexts */ meta->base_allocation =3D true; - meta->bitmap =3D !!meta->exp->export_bitmap; + memset(meta->bitmaps, 1, meta->exp->nr_export_bitmaps); } else { for (i =3D 0; i < nb_queries; ++i) { ret =3D nbd_negotiate_meta_query(client, meta, errp); @@ -1006,13 +1028,19 @@ static int nbd_negotiate_meta_queries(NBDClient *cl= ient, count++; } - if (meta->bitmap) { - const char *bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_b= itmap); - g_autofree char *context =3D g_strdup_printf("qemu:dirty-bitmap:%s= ", - bm_name); + for (i =3D 0; i < meta->exp->nr_export_bitmaps; i++) { + const char *bm_name; + g_autofree char *context =3D NULL; + + if (!meta->bitmaps[i]) { + continue; + } + + bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_bitmaps[i]); + context =3D g_strdup_printf("qemu:dirty-bitmap:%s", bm_name); ret =3D nbd_negotiate_send_meta_context(client, context, - NBD_META_ID_DIRTY_BITMAP, + NBD_META_ID_DIRTY_BITMAP + i, errp); if (ret < 0) { return ret; @@ -1366,6 +1394,7 @@ void nbd_client_put(NBDClient *client) QTAILQ_REMOVE(&client->exp->clients, client, next); blk_exp_unref(&client->exp->common); } + g_free(client->export_meta.bitmaps); g_free(client); } } @@ -1482,6 +1511,7 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, bool readonly =3D !exp_args->writable; bool shared =3D !exp_args->writable; strList *bitmaps; + size_t i; int ret; assert(exp_args->type =3D=3D BLOCK_EXPORT_TYPE_NBD); @@ -1541,12 +1571,12 @@ static int nbd_export_create(BlockExport *blk_exp, = BlockExportOptions *exp_args, } exp->size =3D QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE); - /* XXX Allow more than one bitmap */ - if (arg->bitmaps && arg->bitmaps->next) { - error_setg(errp, "multiple bitmaps per export not supported yet"); - return -EOPNOTSUPP; - } for (bitmaps =3D arg->bitmaps; bitmaps; bitmaps =3D bitmaps->next) { + exp->nr_export_bitmaps++; + } + exp->export_bitmaps =3D g_new0(BdrvDirtyBitmap *, exp->nr_export_bitma= ps); + for (i =3D 0, bitmaps =3D arg->bitmaps; bitmaps; + i++, bitmaps =3D bitmaps->next) { const char *bitmap =3D bitmaps->value; BlockDriverState *bs =3D blk_bs(blk); BdrvDirtyBitmap *bm =3D NULL; @@ -1580,11 +1610,15 @@ static int nbd_export_create(BlockExport *blk_exp, = BlockExportOptions *exp_args, goto fail; } - bdrv_dirty_bitmap_set_busy(bm, true); - exp->export_bitmap =3D bm; + exp->export_bitmaps[i] =3D bm; assert(strlen(bitmap) <=3D BDRV_BITMAP_MAX_NAME_SIZE); } + /* Mark bitmaps busy in a separate loop, to simplify roll-back concern= s. */ + for (i =3D 0; i < exp->nr_export_bitmaps; i++) { + bdrv_dirty_bitmap_set_busy(exp->export_bitmaps[i], true); + } + blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, ex= p); QTAILQ_INSERT_TAIL(&exports, exp, next); @@ -1592,6 +1626,7 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, return 0; fail: + g_free(exp->export_bitmaps); g_free(exp->name); g_free(exp->description); return ret; @@ -1641,6 +1676,7 @@ static void nbd_export_request_shutdown(BlockExport *= blk_exp) static void nbd_export_delete(BlockExport *blk_exp) { + size_t i; NBDExport *exp =3D container_of(blk_exp, NBDExport, common); assert(exp->name =3D=3D NULL); @@ -1658,8 +1694,8 @@ static void nbd_export_delete(BlockExport *blk_exp) blk_aio_detach, exp); } - if (exp->export_bitmap) { - bdrv_dirty_bitmap_set_busy(exp->export_bitmap, false); + for (i =3D 0; i < exp->nr_export_bitmaps; i++) { + bdrv_dirty_bitmap_set_busy(exp->export_bitmaps[i], false); } } @@ -2268,6 +2304,7 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, int flags; NBDExport *exp =3D client->exp; char *msg; + size_t i; switch (request->type) { case NBD_CMD_CACHE: @@ -2358,12 +2395,15 @@ static coroutine_fn int nbd_handle_request(NBDClien= t *client, } } - if (client->export_meta.bitmap) { + for (i =3D 0; i < client->exp->nr_export_bitmaps; i++) { + if (!client->export_meta.bitmaps[i]) { + continue; + } ret =3D nbd_co_send_bitmap(client, request->handle, - client->exp->export_bitmap, + client->exp->export_bitmaps[i], request->from, request->len, dont_fragment, !--contexts_remain= ing, - NBD_META_ID_DIRTY_BITMAP, errp); + NBD_META_ID_DIRTY_BITMAP + i, err= p); if (ret < 0) { return ret; } diff --git a/tests/qemu-iotests/291 b/tests/qemu-iotests/291 index 4f837b205655..37848ac60bba 100755 --- a/tests/qemu-iotests/291 +++ b/tests/qemu-iotests/291 @@ -107,16 +107,14 @@ echo # x-dirty-bitmap is a hack for reading bitmaps; it abuses block status to # report "data":false for portions of the bitmap which are set IMG=3D"driver=3Dnbd,server.type=3Dunix,server.path=3D$nbd_unix_socket" -nbd_server_start_unix_socket -r -f qcow2 -B b0 "$TEST_IMG" +nbd_server_start_unix_socket -r -f qcow2 \ + -B b0 -B b1 -B b2 -B b3 "$TEST_IMG" $QEMU_IMG map --output=3Djson --image-opts \ "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b0" | _filter_qemu_img_map -nbd_server_start_unix_socket -r -f qcow2 -B b1 "$TEST_IMG" $QEMU_IMG map --output=3Djson --image-opts \ "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b1" | _filter_qemu_img_map -nbd_server_start_unix_socket -r -f qcow2 -B b2 "$TEST_IMG" $QEMU_IMG map --output=3Djson --image-opts \ "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b2" | _filter_qemu_img_map -nbd_server_start_unix_socket -r -f qcow2 -B b3 "$TEST_IMG" $QEMU_IMG map --output=3Djson --image-opts \ "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b3" | _filter_qemu_img_map --=20 2.29.0 From nobody Fri May 10 18:32:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775555; cv=none; d=zohomail.com; s=zohoarc; b=NKVDEGok10Oe8rSWfkv1lMFc9VWPZ2dqeaedIkXvZwWZ83AhUV18+8Ti4q6FfJlZtGHX43dhp8M2An6kAIWLzhB/eoWCdN97/VPzUo2cz0zyOpDgWBQzLomGInnisYySZwcLI8hH1HYTzPNNYw9YDygPrKEdx8jA3JV/fBizQJo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775555; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1DgFsjp5kXE2igP1wRvz+9bFBaIzsEpsTueZ87OgvUU=; b=cqq+5FBsMvvhq6mVj4tLe7i4OKWgpSR5TFUeLvudy9UYisBpiDEkwJ94z9uw5jAmsfGWRgj3m8z38/FH/hYpUfP1cLMkYCL/7FAbws2gtYLcGVbCTQnmrKbYPWanfRB0W7ouTOs4MA/zDQM4p0dH3SRrvexVerhslH8GE2UTGZc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775555592912.4419220479114; Mon, 26 Oct 2020 22:12:35 -0700 (PDT) Received: from localhost ([::1]:48954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHHe-0001fV-Ap for importer@patchew.org; Tue, 27 Oct 2020 01:12:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBi-0003mI-IN for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31296) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBb-0003eA-OJ for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-542-L1d52sWpO5i6WMkoW9d9NQ-1; Tue, 27 Oct 2020 01:06:13 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 929608030A9; Tue, 27 Oct 2020 05:06:12 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9CA910013C4; Tue, 27 Oct 2020 05:06:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1DgFsjp5kXE2igP1wRvz+9bFBaIzsEpsTueZ87OgvUU=; b=F4sPG6/lgVZpsP6EVHbAoXrbSve3Rw9T6E3vMPVLcLWr+tQx4uYYJsiriQGlH/g04M0/S5 Z/Xma+hGTr+Lq4WXfkUg2Me7pZghoc3BhD2jkwbuxjK7EDkY1kw3Hyd5Ql0P4h5H5pKSzc vx5GxWa7E7CXVAbzrEfta2eOP4QuEEE= X-MC-Unique: L1d52sWpO5i6WMkoW9d9NQ-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 08/11] block: Return depth level during bdrv_is_allocated_above Date: Tue, 27 Oct 2020 00:05:53 -0500 Message-Id: <20201027050556.269064-9-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Fam Zheng , pkrempa@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, rjones@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, Max Reitz , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When checking for allocation across a chain, it's already easy to count the depth within the chain at which the allocation is found. Instead of throwing that information away, return it to the caller. Existing callers only cared about allocated/non-allocated, but having a depth available will be used by NBD in the next patch. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/coroutines.h | 6 ++++-- block/io.c | 29 ++++++++++++++++++++++------- block/commit.c | 2 +- block/mirror.c | 2 +- block/stream.c | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index 1cb3128b942c..4cfb4946e65e 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -47,7 +47,8 @@ bdrv_co_common_block_status_above(BlockDriverState *bs, int64_t bytes, int64_t *pnum, int64_t *map, - BlockDriverState **file); + BlockDriverState **file, + int *depth); int generated_co_wrapper bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, @@ -57,7 +58,8 @@ bdrv_common_block_status_above(BlockDriverState *bs, int64_t bytes, int64_t *pnum, int64_t *map, - BlockDriverState **file); + BlockDriverState **file, + int *depth); int coroutine_fn bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); diff --git a/block/io.c b/block/io.c index 02528b3823fe..7751cdb81948 100644 --- a/block/io.c +++ b/block/io.c @@ -2349,20 +2349,28 @@ bdrv_co_common_block_status_above(BlockDriverState = *bs, int64_t bytes, int64_t *pnum, int64_t *map, - BlockDriverState **file) + BlockDriverState **file, + int *depth) { int ret; BlockDriverState *p; int64_t eof =3D 0; + int dummy; assert(!include_base || base); /* Can't include NULL base */ + if (!depth) { + depth =3D &dummy; + } + *depth =3D 0; + if (!include_base && bs =3D=3D base) { *pnum =3D bytes; return 0; } ret =3D bdrv_co_block_status(bs, want_zero, offset, bytes, pnum, map, = file); + ++*depth; if (ret < 0 || *pnum =3D=3D 0 || ret & BDRV_BLOCK_ALLOCATED || bs =3D= =3D base) { return ret; } @@ -2379,6 +2387,7 @@ bdrv_co_common_block_status_above(BlockDriverState *b= s, { ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, file); + ++*depth; if (ret < 0) { return ret; } @@ -2437,7 +2446,7 @@ int bdrv_block_status_above(BlockDriverState *bs, Blo= ckDriverState *base, int64_t *map, BlockDriverState **file) { return bdrv_common_block_status_above(bs, base, false, true, offset, b= ytes, - pnum, map, file); + pnum, map, file, NULL); } int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, @@ -2455,7 +2464,7 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *= bs, int64_t offset, ret =3D bdrv_common_block_status_above(bs, bs, true, false, offset, bytes, pnum ? pnum : &dummy, NULL, - NULL); + NULL, NULL); if (ret < 0) { return ret; } @@ -2465,8 +2474,9 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *= bs, int64_t offset, /* * Given an image chain: ... -> [BASE] -> [INTER1] -> [INTER2] -> [TOP] * - * Return 1 if (a prefix of) the given range is allocated in any image - * between BASE and TOP (BASE is only included if include_base is set). + * Return a positive depth if (a prefix of) the given range is allocated + * in any image between BASE and TOP (BASE is only included if include_base + * is set). Depth 1 is TOP, 2 is the first backing layer, and so forth. * BASE can be NULL to check if the given offset is allocated in any * image of the chain. Return 0 otherwise, or negative errno on * failure. @@ -2483,13 +2493,18 @@ int bdrv_is_allocated_above(BlockDriverState *top, bool include_base, int64_t offset, int64_t bytes, int64_t *pnum) { + int depth; int ret =3D bdrv_common_block_status_above(top, base, include_base, fa= lse, - offset, bytes, pnum, NULL, NU= LL); + offset, bytes, pnum, NULL, NU= LL, + &depth); if (ret < 0) { return ret; } - return !!(ret & BDRV_BLOCK_ALLOCATED); + if (ret & BDRV_BLOCK_ALLOCATED) { + return depth; + } + return 0; } int coroutine_fn diff --git a/block/commit.c b/block/commit.c index 1e85c306cc41..71db7ba7472e 100644 --- a/block/commit.c +++ b/block/commit.c @@ -156,7 +156,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) /* Copy if allocated above the base */ ret =3D bdrv_is_allocated_above(blk_bs(s->top), s->base_overlay, t= rue, offset, COMMIT_BUFFER_SIZE, &n); - copy =3D (ret =3D=3D 1); + copy =3D (ret > 0); trace_commit_one_iteration(s, offset, n, ret); if (copy) { assert(n < SIZE_MAX); diff --git a/block/mirror.c b/block/mirror.c index 26acf4af6fb7..8e1ad6eceb57 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -846,7 +846,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) } assert(count); - if (ret =3D=3D 1) { + if (ret > 0) { bdrv_set_dirty_bitmap(s->dirty_bitmap, offset, count); } offset +=3D count; diff --git a/block/stream.c b/block/stream.c index 8ce6729a33da..236384f2f739 100644 --- a/block/stream.c +++ b/block/stream.c @@ -167,7 +167,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) n =3D len - offset; } - copy =3D (ret =3D=3D 1); + copy =3D (ret > 0); } trace_stream_one_iteration(s, offset, n, ret); if (copy) { --=20 2.29.0 From nobody Fri May 10 18:32:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775693; cv=none; d=zohomail.com; s=zohoarc; b=PxZAUFEuzXcWGMeUUgBNbzAzAIMvMCyVyjna0uX9vjJwJ9qA/eyOQley96bVU+Jf6PwaT/EqmTVAtx8geRUvNo2l9O6H2liQ6bz+4weK1583f/cYAsXWGe5+S8cJuej4RIMv4E5hDVqtKmqPfC9IISYQw5TGZxIphPWQk8AmNyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775693; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2YUr/GnO3pi3/hs0Zjz7TWTMTcZodaMQLTF2OHrVYnI=; b=JPOiKmF3GipQFVPG9zfhvJOk9m6U64qCTcg4nxYeS7AqskqWH+xkp9ZRR6xJKQLyLLrjU5u9m6yFlkjxTEMQ9NLsqJAkEaQ6qzI7KSO7rUTv+T8DvWcJZnGJ5H59gzZZSe+0QKsxlqfUrS3BWwrXJGnrUDZDWwSuh162bkKz80M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775693901960.8868933255192; Mon, 26 Oct 2020 22:14:53 -0700 (PDT) Received: from localhost ([::1]:56134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHJs-0004dx-Ch for importer@patchew.org; Tue, 27 Oct 2020 01:14:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBg-0003l9-0g for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43246) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBb-0003e7-NG for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-332-cEOy1TxBPb2oPB6oNcwEmA-1; Tue, 27 Oct 2020 01:06:14 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 81F3C100746B; Tue, 27 Oct 2020 05:06:13 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id C552310013C4; Tue, 27 Oct 2020 05:06:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775177; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2YUr/GnO3pi3/hs0Zjz7TWTMTcZodaMQLTF2OHrVYnI=; b=dTJjtg5O9IWoYXf5BdUCOOn+lHn/bmNhiXJhPWaiErK3MU6yzra5waRjjWj1DzdKM78ncg ZiSex0tGczF2ukmvvKA2LFHLUE5h+EyVl7sw+PrTYGkSicznGrQTyuIWWmT4jLsBgrxLaD tysMhMNJMBnfUOcduV8H1QQVUAllKD4= X-MC-Unique: cEOy1TxBPb2oPB6oNcwEmA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 09/11] nbd: Add new qemu:allocation-depth metadata context Date: Tue, 27 Oct 2020 00:05:54 -0500 Message-Id: <20201027050556.269064-10-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, rjones@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 'qemu-img map' provides a way to determine which extents of an image come from the top layer vs. inherited from a backing chain. This is useful information worth exposing over NBD. There is a proposal to add a QMP command block-dirty-bitmap-populate which can create a dirty bitmap that reflects allocation information, at which point the qemu:dirty-bitmap:NAME metadata context can expose that information via the creation of a temporary bitmap, but we can shorten the effort by adding a new qemu:allocation-depth metadata context that does the same thing without an intermediate bitmap (this patch does not eliminate the need for that proposal, as it will have other uses as well). While documenting things, remember that although the NBD protocol has NBD_OPT_SET_META_CONTEXT, the rest of its documentation refers to 'metadata context', which is a more apt description of what is actually being used by NBD_CMD_BLOCK_STATUS: the user is requesting metadata by passing one or more context names. So I also touched up some existing wording to prefer the term 'metadata context' where it makes sense. Note that this patch does not actually enable any way to request a server to enable this context; that will come in the next patch. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- docs/interop/nbd.txt | 23 +++++++++++---- include/block/nbd.h | 8 +++-- nbd/server.c | 70 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 89 insertions(+), 12 deletions(-) diff --git a/docs/interop/nbd.txt b/docs/interop/nbd.txt index f3b3cacc9621..10ce098a29bf 100644 --- a/docs/interop/nbd.txt +++ b/docs/interop/nbd.txt @@ -17,19 +17,31 @@ namespace "qemu". =3D=3D "qemu" namespace =3D=3D -The "qemu" namespace currently contains only one type of context, -related to exposing the contents of a dirty bitmap alongside the -associated disk contents. That context has the following form: +The "qemu" namespace currently contains two available metadata context +types. The first is related to exposing the contents of a dirty +bitmap alongside the associated disk contents. That metadata context +is named with the following form: qemu:dirty-bitmap: Each dirty-bitmap metadata context defines only one flag for extents in reply for NBD_CMD_BLOCK_STATUS: - bit 0: NBD_STATE_DIRTY, means that the extent is "dirty" + bit 0: NBD_STATE_DIRTY, set when the extent is "dirty" + +The second is related to exposing the source of various extents within +the image, with a single metadata context named: + + qemu:allocation-depth + +In the allocation depth context, the entire 32-bit value represents a +depth of which layer in a thin-provisioned backing chain provided the +data (0 for unallocated, 1 for the active layer, 2 for the first +backing layer, and so forth). For NBD_OPT_LIST_META_CONTEXT the following queries are supported -in addition to "qemu:dirty-bitmap:": +in addition to the specific "qemu:allocation-depth" and +"qemu:dirty-bitmap:": * "qemu:" - returns list of all available metadata contexts in the namespace. @@ -55,3 +67,4 @@ the operation of that feature. NBD_CMD_BLOCK_STATUS for "qemu:dirty-bitmap:", NBD_CMD_CACHE * 4.2: NBD_FLAG_CAN_MULTI_CONN for shareable read-only exports, NBD_CMD_FLAG_FAST_ZERO +* 5.2: NBD_CMD_BLOCK_STATUS for "qemu:allocation-depth" diff --git a/include/block/nbd.h b/include/block/nbd.h index 3dd9a04546ec..4a52a43ef598 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016-2019 Red Hat, Inc. + * Copyright (C) 2016-2020 Red Hat, Inc. * Copyright (C) 2005 Anthony Liguori * * Network Block Device @@ -47,7 +47,7 @@ typedef struct NBDOptionReply NBDOptionReply; typedef struct NBDOptionReplyMetaContext { NBDOptionReply h; /* h.type =3D NBD_REP_META_CONTEXT, h.length > 4 */ uint32_t context_id; - /* meta context name follows */ + /* metadata context name follows */ } QEMU_PACKED NBDOptionReplyMetaContext; /* Transmission phase structs @@ -229,7 +229,7 @@ enum { #define NBD_MAX_BUFFER_SIZE (32 * 1024 * 1024) /* - * Maximum size of a protocol string (export name, meta context name, + * Maximum size of a protocol string (export name, metadata context name, * etc.). Use malloc rather than stack allocation for storage of a * string. */ @@ -259,6 +259,8 @@ enum { /* Extent flags for qemu:dirty-bitmap in NBD_REPLY_TYPE_BLOCK_STATUS */ #define NBD_STATE_DIRTY (1 << 0) +/* No flags needed for qemu:allocation-depth in NBD_REPLY_TYPE_BLOCK_STATU= S */ + static inline bool nbd_reply_type_is_error(int type) { return type & (1 << 15); diff --git a/nbd/server.c b/nbd/server.c index b6841e455414..ebbefcb6d3ec 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -27,8 +27,9 @@ #include "qemu/units.h" #define NBD_META_ID_BASE_ALLOCATION 0 +#define NBD_META_ID_ALLOCATION_DEPTH 1 /* Dirty bitmaps use 'NBD_META_ID_DIRTY_BITMAP + i', so keep this id last.= */ -#define NBD_META_ID_DIRTY_BITMAP 1 +#define NBD_META_ID_DIRTY_BITMAP 2 /* * NBD_MAX_BLOCK_STATUS_EXTENTS: 1 MiB of extents data. An empirical @@ -95,6 +96,7 @@ struct NBDExport { BlockBackend *eject_notifier_blk; Notifier eject_notifier; + bool allocation_depth; BdrvDirtyBitmap **export_bitmaps; size_t nr_export_bitmaps; }; @@ -108,6 +110,7 @@ typedef struct NBDExportMetaContexts { NBDExport *exp; size_t count; /* number of negotiated contexts */ bool base_allocation; /* export base:allocation context (block status)= */ + bool allocation_depth; /* export qemu:allocation-depth */ bool *bitmaps; /* * export qemu:dirty-bitmap:, * sized by exp->nr_export_bitmaps @@ -857,7 +860,8 @@ static bool nbd_meta_base_query(NBDClient *client, NBDE= xportMetaContexts *meta, /* nbd_meta_qemu_query * * Handle queries to 'qemu' namespace. For now, only the qemu:dirty-bitmap: - * context is available. Return true if @query has been handled. + * and qemu:allocation-depth contexts are available. Return true if @query + * has been handled. */ static bool nbd_meta_qemu_query(NBDClient *client, NBDExportMetaContexts *= meta, const char *query) @@ -871,12 +875,19 @@ static bool nbd_meta_qemu_query(NBDClient *client, NB= DExportMetaContexts *meta, if (!*query) { if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { + meta->allocation_depth =3D meta->exp->allocation_depth; memset(meta->bitmaps, 1, meta->exp->nr_export_bitmaps); } trace_nbd_negotiate_meta_query_parse("empty"); return true; } + if (strcmp(query, "allocation-depth") =3D=3D 0) { + trace_nbd_negotiate_meta_query_parse("allocation-depth"); + meta->allocation_depth =3D meta->exp->allocation_depth; + return true; + } + if (nbd_strshift(&query, "dirty-bitmap:")) { trace_nbd_negotiate_meta_query_parse("dirty-bitmap:"); if (!*query) { @@ -901,7 +912,7 @@ static bool nbd_meta_qemu_query(NBDClient *client, NBDE= xportMetaContexts *meta, return true; } - trace_nbd_negotiate_meta_query_skip("not dirty-bitmap"); + trace_nbd_negotiate_meta_query_skip("unknown qemu context"); return true; } @@ -1008,6 +1019,7 @@ static int nbd_negotiate_meta_queries(NBDClient *clie= nt, if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT && !nb_queries) { /* enable all known contexts */ meta->base_allocation =3D true; + meta->allocation_depth =3D meta->exp->allocation_depth; memset(meta->bitmaps, 1, meta->exp->nr_export_bitmaps); } else { for (i =3D 0; i < nb_queries; ++i) { @@ -1028,6 +1040,16 @@ static int nbd_negotiate_meta_queries(NBDClient *cli= ent, count++; } + if (meta->allocation_depth) { + ret =3D nbd_negotiate_send_meta_context(client, "qemu:allocation-d= epth", + NBD_META_ID_ALLOCATION_DEPTH, + errp); + if (ret < 0) { + return ret; + } + count++; + } + for (i =3D 0; i < meta->exp->nr_export_bitmaps; i++) { const char *bm_name; g_autofree char *context =3D NULL; @@ -2005,6 +2027,29 @@ static int blockstatus_to_extents(BlockDriverState *= bs, uint64_t offset, return 0; } +static int blockalloc_to_extents(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, NBDExtentArray *ea) +{ + while (bytes) { + int64_t num; + int ret =3D bdrv_is_allocated_above(bs, NULL, false, offset, bytes, + &num); + + if (ret < 0) { + return ret; + } + + if (nbd_extent_array_add(ea, num, ret) < 0) { + return 0; + } + + offset +=3D num; + bytes -=3D num; + } + + return 0; +} + /* * nbd_co_send_extents * @@ -2044,7 +2089,11 @@ static int nbd_co_send_block_status(NBDClient *clien= t, uint64_t handle, unsigned int nb_extents =3D dont_fragment ? 1 : NBD_MAX_BLOCK_STATUS_E= XTENTS; g_autoptr(NBDExtentArray) ea =3D nbd_extent_array_new(nb_extents); - ret =3D blockstatus_to_extents(bs, offset, length, ea); + if (context_id =3D=3D NBD_META_ID_BASE_ALLOCATION) { + ret =3D blockstatus_to_extents(bs, offset, length, ea); + } else { + ret =3D blockalloc_to_extents(bs, offset, length, ea); + } if (ret < 0) { return nbd_co_send_structured_error( client, handle, -ret, "can't get block status", errp); @@ -2395,6 +2444,19 @@ static coroutine_fn int nbd_handle_request(NBDClient= *client, } } + if (client->export_meta.allocation_depth) { + ret =3D nbd_co_send_block_status(client, request->handle, + blk_bs(exp->common.blk), + request->from, request->len, + dont_fragment, + !--contexts_remaining, + NBD_META_ID_ALLOCATION_DEPT= H, + errp); + if (ret < 0) { + return ret; + } + } + for (i =3D 0; i < client->exp->nr_export_bitmaps; i++) { if (!client->export_meta.bitmaps[i]) { continue; --=20 2.29.0 From nobody Fri May 10 18:32:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775717; cv=none; d=zohomail.com; s=zohoarc; b=Nh+NjUH72SzjsdtlL7Pw3Lgp74ZP+x63jPblwtD921eaX7JFu5hJGjt2YxphjRMqjNw9Mjskp8hCSIhUAYo0xjycrW4j/MOVq4KxqFDglk2y8KkSd3n2T+kvd9K7sWGXjsICD1agJ2wZyuTgRvYXonxsNKkdh6XQeQprTBQN8ag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775717; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NVKP8FKlHDzvpIJ9H6KWNWNNAKOSIHy/fRKXbEXTHIo=; b=dRb2RC+0IPHHBRzDorvQXHQOKdNVx5pFCfwqhfPxIomrnY5JLR8bYqxsg/yhy60MwDkWYBnaXg3L98z8gpDdECcszchfSpUCWv/dYIWc+JEo186/5Hqvgi0C+9CoLVCXUCke63hZKIz0fVFB+WCZcnaBdSd4om3N35nPhqIJ3lw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775717576295.7034755819334; Mon, 26 Oct 2020 22:15:17 -0700 (PDT) Received: from localhost ([::1]:57314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHKG-00059j-EX for importer@patchew.org; Tue, 27 Oct 2020 01:15:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBl-0003ok-1J for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52730) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBb-0003f6-Nx for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-550-DIqymWOiOlKLqsLPNhkhGw-1; Tue, 27 Oct 2020 01:06:15 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D24F1074649; Tue, 27 Oct 2020 05:06:14 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2A0A10013C4; Tue, 27 Oct 2020 05:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775178; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NVKP8FKlHDzvpIJ9H6KWNWNNAKOSIHy/fRKXbEXTHIo=; b=e/Fz3TS8uiGK2Plf6tHeDfkWmbIcKwa8+rql8VvfT5YHzbKtm+YcxxaaDvBN/cp2HYzOWb zZpIwyWeLwn49NtREgc3TW8SuLc06lkvVFX0ML3yt/ENMGFFI6EWo5xv3siIk7JqFigU+M 2el428vQGSYP+IPHBGYn62wDkkv8V7c= X-MC-Unique: DIqymWOiOlKLqsLPNhkhGw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 10/11] nbd: Add 'qemu-nbd -A' to expose allocation depth Date: Tue, 27 Oct 2020 00:05:55 -0500 Message-Id: <20201027050556.269064-11-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pkrempa@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, rjones@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Allow the server to expose an additional metacontext to be requested by savvy clients. qemu-nbd adds a new option -A to expose the qemu:allocation-depth metacontext through NBD_CMD_BLOCK_STATUS; this can also be set via QMP when using block-export-add. qemu as client is hacked into viewing the key aspects of this new context by abusing the already-experimental x-dirty-bitmap option to collapse all depths greater than 2, which results in a tri-state value visible in the output of 'qemu-img map --output=3Djson' (yes, that means x-dirty-bitmap is now a bit of a misnomer, but I didn't feel like renaming it as it would introduce a needless break of back-compat, even though we make no compat guarantees with x- members): unallocated (depth 0) =3D> "zero":false, "data":true local (depth 1) =3D> "zero":false, "data":false backing (depth 2+) =3D> "zero":true, "data":true libnbd as client is probably a nicer way to get at the information without having to decipher such hacks in qemu as client. ;) Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- docs/tools/qemu-nbd.rst | 8 +++- qapi/block-core.json | 7 +++- qapi/block-export.json | 7 +++- block/nbd.c | 26 ++++++++++--- nbd/server.c | 2 + qemu-nbd.c | 12 +++++- tests/qemu-iotests/309 | 77 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/309.out | 22 +++++++++++ tests/qemu-iotests/group | 1 + 9 files changed, 151 insertions(+), 11 deletions(-) create mode 100755 tests/qemu-iotests/309 create mode 100644 tests/qemu-iotests/309.out diff --git a/docs/tools/qemu-nbd.rst b/docs/tools/qemu-nbd.rst index 667861cb22e9..fe41336dc550 100644 --- a/docs/tools/qemu-nbd.rst +++ b/docs/tools/qemu-nbd.rst @@ -72,10 +72,16 @@ driver options if ``--image-opts`` is specified. Export the disk as read-only. +.. option:: -A, --allocation-depth + + Expose allocation depth information via the + ``qemu:allocation-depth`` metadata context accessible through + NBD_OPT_SET_META_CONTEXT. + .. option:: -B, --bitmap=3DNAME If *filename* has a qcow2 persistent bitmap *NAME*, expose - that bitmap via the ``qemu:dirty-bitmap:NAME`` context + that bitmap via the ``qemu:dirty-bitmap:NAME`` metadata context accessible through NBD_OPT_SET_META_CONTEXT. .. option:: -s, --snapshot diff --git a/qapi/block-core.json b/qapi/block-core.json index e00fc27b5ea4..1b8b4156b4b9 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3905,9 +3905,12 @@ # # @tls-creds: TLS credentials ID # -# @x-dirty-bitmap: A "qemu:dirty-bitmap:NAME" string to query in place of +# @x-dirty-bitmap: A metadata context name such as "qemu:dirty-bitmap:NAME" +# or "qemu:allocation-depth" to query in place of the # traditional "base:allocation" block status (see -# NBD_OPT_LIST_META_CONTEXT in the NBD protocol) (since 3= .0) +# NBD_OPT_LIST_META_CONTEXT in the NBD protocol; and +# yes, naming this option x-context would have made +# more sense) (since 3.0) # # @reconnect-delay: On an unexpected disconnect, the nbd client tries to # connect again until succeeding or encountering a serio= us diff --git a/qapi/block-export.json b/qapi/block-export.json index c4125f4d2104..a9f488f99c1a 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -90,11 +90,16 @@ # the metadata context name "qemu:dirty-bitmap:BITMAP" to inspect # each bitmap. # +# @allocation-depth: Also export the allocation depth map for @device, so +# the NBD client can use NBD_OPT_SET_META_CONTEXT with +# the metadata context name "qemu:allocation-depth" to +# inspect allocation details. (since 5.2) +# # Since: 5.2 ## { 'struct': 'BlockExportOptionsNbd', 'base': 'BlockExportOptionsNbdBase', - 'data': { '*bitmaps': ['str'] } } + 'data': { '*bitmaps': ['str'], '*allocation-depth': 'bool' } } ## # @BlockExportOptionsVhostUserBlk: diff --git a/block/nbd.c b/block/nbd.c index 4548046cd7cd..42536702b6f9 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -135,6 +135,7 @@ typedef struct BDRVNBDState { QCryptoTLSCreds *tlscreds; const char *hostname; char *x_dirty_bitmap; + bool alloc_depth; bool wait_connect; NBDConnectThread *connect_thread; @@ -961,6 +962,16 @@ static int nbd_parse_blockstatus_payload(BDRVNBDState = *s, trace_nbd_parse_blockstatus_compliance("extent length too large"); } + /* + * HACK: if we are using x-dirty-bitmaps to access + * qemu:allocation-depth, treat all depths > 2 the same as 2, + * since nbd_client_co_block_status is only expecting the low two + * bits to be set. + */ + if (s->alloc_depth && extent->flags > 2) { + extent->flags =3D 2; + } + return 0; } @@ -1795,11 +1806,16 @@ static int nbd_client_handshake(BlockDriverState *b= s, QIOChannelSocket *sioc, s->sioc =3D NULL; return ret; } - if (s->x_dirty_bitmap && !s->info.base_allocation) { - error_setg(errp, "requested x-dirty-bitmap %s not found", - s->x_dirty_bitmap); - ret =3D -EINVAL; - goto fail; + if (s->x_dirty_bitmap) { + if (!s->info.base_allocation) { + error_setg(errp, "requested x-dirty-bitmap %s not found", + s->x_dirty_bitmap); + ret =3D -EINVAL; + goto fail; + } + if (strcmp(s->x_dirty_bitmap, "qemu:allocation-depth") =3D=3D 0) { + s->alloc_depth =3D true; + } } if (s->info.flags & NBD_FLAG_READ_ONLY) { ret =3D bdrv_apply_auto_read_only(bs, "NBD export is read-only", e= rrp); diff --git a/nbd/server.c b/nbd/server.c index ebbefcb6d3ec..d145e1a69083 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1641,6 +1641,8 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, bdrv_dirty_bitmap_set_busy(exp->export_bitmaps[i], true); } + exp->allocation_depth =3D arg->allocation_depth; + blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, ex= p); QTAILQ_INSERT_TAIL(&exports, exp, next); diff --git a/qemu-nbd.c b/qemu-nbd.c index 4b7825c44093..808db07fca70 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -100,6 +100,7 @@ static void usage(const char *name) "\n" "Exposing part of the image:\n" " -o, --offset=3DOFFSET offset into the image\n" +" -A, --allocation-depth expose the allocation depth\n" " -B, --bitmap=3DNAME expose a persistent dirty bitmap\n" "\n" "General purpose options:\n" @@ -524,7 +525,7 @@ int main(int argc, char **argv) char *device =3D NULL; QemuOpts *sn_opts =3D NULL; const char *sn_id_or_name =3D NULL; - const char *sopt =3D "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:B:L"; + const char *sopt =3D "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:AB:L"; struct option lopt[] =3D { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, @@ -533,6 +534,7 @@ int main(int argc, char **argv) { "socket", required_argument, NULL, 'k' }, { "offset", required_argument, NULL, 'o' }, { "read-only", no_argument, NULL, 'r' }, + { "allocation-depth", no_argument, NULL, 'A' }, { "bitmap", required_argument, NULL, 'B' }, { "connect", required_argument, NULL, 'c' }, { "disconnect", no_argument, NULL, 'd' }, @@ -575,6 +577,7 @@ int main(int argc, char **argv) const char *export_name =3D NULL; /* defaults to "" later for server m= ode */ const char *export_description =3D NULL; strList *bitmaps =3D NULL; + bool alloc_depth =3D false; const char *tlscredsid =3D NULL; bool imageOpts =3D false; bool writethrough =3D true; @@ -689,6 +692,9 @@ int main(int argc, char **argv) readonly =3D true; flags &=3D ~BDRV_O_RDWR; break; + case 'A': + alloc_depth =3D true; + break; case 'B': QAPI_LIST_ADD(bitmaps, g_strdup(optarg)); break; @@ -787,7 +793,7 @@ int main(int argc, char **argv) } if (export_name || export_description || dev_offset || device || disconnect || fmt || sn_id_or_name || bitmaps || - seen_aio || seen_discard || seen_cache) { + alloc_depth || seen_aio || seen_discard || seen_cache) { error_report("List mode is incompatible with per-device settin= gs"); exit(EXIT_FAILURE); } @@ -1073,6 +1079,8 @@ int main(int argc, char **argv) .description =3D g_strdup(export_description), .has_bitmaps =3D !!bitmaps, .bitmaps =3D bitmaps, + .has_allocation_depth =3D alloc_depth, + .allocation_depth =3D alloc_depth, }, }; blk_exp_add(export_opts, &error_fatal); diff --git a/tests/qemu-iotests/309 b/tests/qemu-iotests/309 new file mode 100755 index 000000000000..fb61157c2e1d --- /dev/null +++ b/tests/qemu-iotests/309 @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# +# Test qemu-nbd -A +# +# Copyright (C) 2018-2020 Red Hat, Inc. +# +# 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 . +# + +seq=3D"$(basename $0)" +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + nbd_server_stop +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.nbd + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux +_require_command QEMU_NBD + +echo +echo "=3D=3D=3D Initial image setup =3D=3D=3D" +echo + +TEST_IMG=3D"$TEST_IMG.base" _make_test_img 4M +$QEMU_IO -c 'w 0 2M' -f $IMGFMT "$TEST_IMG.base" | _filter_qemu_io +_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 4M +$QEMU_IO -c 'w 1M 2M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io + +echo +echo "=3D=3D=3D Check allocation over NBD =3D=3D=3D" +echo + +$QEMU_IMG map --output=3Djson -f qcow2 "$TEST_IMG" +IMG=3D"driver=3Dnbd,server.type=3Dunix,server.path=3D$nbd_unix_socket" +nbd_server_start_unix_socket -r -f qcow2 -A "$TEST_IMG" +# Normal -f raw NBD block status loses access to allocation information +$QEMU_IMG map --output=3Djson --image-opts \ + "$IMG" | _filter_qemu_img_map +# But when we use -A, coupled with x-dirty-bitmap in the client for feeding +# 2-bit block status from an alternative NBD metadata context (note that +# the client code for x-dirty-bitmap intentionally collapses all depths +# beyond 2 into a single value), we can determine: +# unallocated (depth 0) =3D> "zero":false, "data":true +# local (depth 1) =3D> "zero":false, "data":false +# backing (depth 2+) =3D> "zero":true, "data":true +$QEMU_IMG map --output=3Djson --image-opts \ + "$IMG,x-dirty-bitmap=3Dqemu:allocation-depth" | _filter_qemu_img_map +# More accurate results can be obtained by other NBD clients such as +# libnbd, but this test works without such external dependencies. + +# success, all done +echo '*** done' +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/309.out b/tests/qemu-iotests/309.out new file mode 100644 index 000000000000..db75bb6b0df9 --- /dev/null +++ b/tests/qemu-iotests/309.out @@ -0,0 +1,22 @@ +QA output created by 309 + +=3D=3D=3D Initial image setup =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D4194304 +wrote 2097152/2097152 bytes at offset 0 +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D4194304 backing_file= =3DTEST_DIR/t.IMGFMT.base backing_fmt=3DIMGFMT +wrote 2097152/2097152 bytes at offset 1048576 +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D=3D Check allocation over NBD =3D=3D=3D + +[{ "start": 0, "length": 1048576, "depth": 1, "zero": false, "data": true,= "offset": 327680}, +{ "start": 1048576, "length": 2097152, "depth": 0, "zero": false, "data": = true, "offset": 327680}, +{ "start": 3145728, "length": 1048576, "depth": 1, "zero": true, "data": f= alse}] +[{ "start": 0, "length": 3145728, "depth": 0, "zero": false, "data": true,= "offset": OFFSET}, +{ "start": 3145728, "length": 1048576, "depth": 0, "zero": true, "data": f= alse, "offset": OFFSET}] +[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": true, = "offset": OFFSET}, +{ "start": 1048576, "length": 2097152, "depth": 0, "zero": false, "data": = false}, +{ "start": 3145728, "length": 1048576, "depth": 0, "zero": false, "data": = true, "offset": OFFSET}] +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 343298928350..2960dff72864 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -315,3 +315,4 @@ 304 rw quick 305 rw quick 307 rw quick export +309 rw auto quick --=20 2.29.0 From nobody Fri May 10 18:32:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 ARC-Seal: i=1; a=rsa-sha256; t=1603775693; cv=none; d=zohomail.com; s=zohoarc; b=FUYbacf0W4L+YX48xF9HVVgDaqEMv4KBttuRvhUI6R8Zwqe+6AMO1rF1cMiJsWShT6/iuT2ME6WJQOuBwxPWQCRrdTRp64tV1gorbge6hSNi0mWpwcAUO/o10cDgReNyZgU67CH2hdiNkr1G+jkFXyoag8KpOhMuvL8MT0flLYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603775693; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ncY4NCXmT95SMTQF/f+jFlHPahOTtGHpjQn5yuHeqBc=; b=C7v5H8eYy+J4pba6wbgk9IXzIlN4yk+/wjgeLJxu9nd7cpakg0imPBnQdvGJEwKwC25FnezG67E+XgO/8f6oSduMdYXhmUlIDZw1aqx8ubNiVKN/KRd5b500o4feg7fpVTD7Qn5DfXlDR6ZdY+rJg+zz4LyXFHeoHIbezGjLD/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603775693972606.616840588925; Mon, 26 Oct 2020 22:14:53 -0700 (PDT) Received: from localhost ([::1]:56056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXHJs-0004bx-CD for importer@patchew.org; Tue, 27 Oct 2020 01:14:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXHBy-0004B7-57 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49691) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXHBt-0003ke-E1 for qemu-devel@nongnu.org; Tue, 27 Oct 2020 01:06:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-322-HCpsqfczONKubSkswN28bA-1; Tue, 27 Oct 2020 01:06:33 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 880498049E0; Tue, 27 Oct 2020 05:06:30 +0000 (UTC) Received: from blue.redhat.com (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0119D10013C4; Tue, 27 Oct 2020 05:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603775196; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ncY4NCXmT95SMTQF/f+jFlHPahOTtGHpjQn5yuHeqBc=; b=cYBtQg8pMPVLJLrlZKXA+1hpsAKDGOmUTVWbnp2Jiak9PuFnZFz2XpUtd40GshAxbpn3ZY +UMXtUFa6xEKoD+MsWtgOUB/q1uizpEyzA/Pa1JAJ5Akr0sBlbibbL/etNJwZfRWWHnqAg 7gyHnoBadrW0sBvUq0F0KoIdPOdXWcc= X-MC-Unique: HCpsqfczONKubSkswN28bA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v6 11/11] qapi: Use QAPI_LIST_ADD() where possible Date: Tue, 27 Oct 2020 00:05:56 -0500 Message-Id: <20201027050556.269064-12-eblake@redhat.com> In-Reply-To: <20201027050556.269064-1-eblake@redhat.com> References: <20201027050556.269064-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/27 01:06:07 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , pkrempa@redhat.com, "Michael S. Tsirkin" , Jason Wang , Thomas Huth , Jiaxun Yang , rjones@redhat.com, Gerd Hoffmann , Michael Roth , qemu-block@nongnu.org, Juan Quintela , David Hildenbrand , armbru@redhat.com, Halil Pasic , Christian Borntraeger , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Gibson , Aleksandar Rikalo , Jiri Pirko , Eduardo Habkost , "Dr. David Alan Gilbert" , "open list:S390 KVM CPUs" , "open list:GLUSTER" , stefanha@redhat.com, Richard Henderson , kwolf@redhat.com, vsementsov@virtuozzo.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Cornelia Huck , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , "open list:ARM TCG CPUs" , "open list:PowerPC TCG CPUs" , Paolo Bonzini , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Anywhere we create a list of just one item or by prepending items (typically because order doesn't matter), we can use the now-public macro. But places where we must keep the list in order by appending remain open-coded. Signed-off-by: Eric Blake Acked-by: David Gibson Acked-by: Dr. David Alan Gilbert --- docs/devel/writing-qmp-commands.txt | 13 +++------ hw/net/rocker/rocker_fp.h | 2 +- block/gluster.c | 19 +++++-------- chardev/char.c | 21 +++++++-------- hw/core/machine.c | 6 +---- hw/net/rocker/rocker.c | 8 +++--- hw/net/rocker/rocker_fp.c | 14 +++++----- hw/net/virtio-net.c | 21 +++++---------- migration/migration.c | 7 ++--- migration/postcopy-ram.c | 7 ++--- monitor/hmp-cmds.c | 11 ++++---- qemu-img.c | 5 ++-- qga/commands-posix.c | 13 +++------ qga/commands-win32.c | 17 +++--------- qga/commands.c | 6 +---- qom/qom-qmp-cmds.c | 29 ++++++-------------- target/arm/helper.c | 6 +---- target/arm/monitor.c | 13 ++------- target/i386/cpu.c | 6 +---- target/mips/helper.c | 6 +---- target/s390x/cpu_models.c | 12 ++------- tests/test-clone-visitor.c | 7 ++--- tests/test-qobject-output-visitor.c | 42 ++++++++++++++--------------- tests/test-visitor-serialization.c | 5 +--- trace/qmp.c | 22 +++++++-------- ui/vnc.c | 21 +++++---------- util/qemu-config.c | 14 +++------- target/ppc/translate_init.c.inc | 12 ++------- 28 files changed, 119 insertions(+), 246 deletions(-) diff --git a/docs/devel/writing-qmp-commands.txt b/docs/devel/writing-qmp-c= ommands.txt index 46a6c48683f5..3e11eeaa1893 100644 --- a/docs/devel/writing-qmp-commands.txt +++ b/docs/devel/writing-qmp-commands.txt @@ -531,15 +531,10 @@ TimerAlarmMethodList *qmp_query_alarm_methods(Error *= *errp) bool current =3D true; for (p =3D alarm_timers; p->name; p++) { - TimerAlarmMethodList *info =3D g_malloc0(sizeof(*info)); - info->value =3D g_malloc0(sizeof(*info->value)); - info->value->method_name =3D g_strdup(p->name); - info->value->current =3D current; - - current =3D false; - - info->next =3D method_list; - method_list =3D info; + TimerAlarmMethod *value =3D g_new0(TimerAlarmMethod, 1); + value->method_name =3D g_strdup(p->name); + value->current =3D current; + QAPI_LIST_ADD(method_list, value); } return method_list; diff --git a/hw/net/rocker/rocker_fp.h b/hw/net/rocker/rocker_fp.h index dbe1dd329a4b..4cb0bb9ccf81 100644 --- a/hw/net/rocker/rocker_fp.h +++ b/hw/net/rocker/rocker_fp.h @@ -28,7 +28,7 @@ int fp_port_eg(FpPort *port, const struct iovec *iov, int= iovcnt); char *fp_port_get_name(FpPort *port); bool fp_port_get_link_up(FpPort *port); -void fp_port_get_info(FpPort *port, RockerPortList *info); +void fp_port_get_info(FpPort *port, RockerPort *info); void fp_port_get_macaddr(FpPort *port, MACAddr *macaddr); void fp_port_set_macaddr(FpPort *port, MACAddr *macaddr); uint8_t fp_port_get_learning(FpPort *port); diff --git a/block/gluster.c b/block/gluster.c index 4f1448e2bc88..cf446c23f85d 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -359,8 +359,8 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluste= r *gconf, return -EINVAL; } - gconf->server =3D g_new0(SocketAddressList, 1); - gconf->server->value =3D gsconf =3D g_new0(SocketAddress, 1); + gsconf =3D g_new0(SocketAddress, 1); + QAPI_LIST_ADD(gconf->server, gsconf); /* transport */ if (!uri->scheme || !strcmp(uri->scheme, "gluster")) { @@ -514,7 +514,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlust= er *gconf, { QemuOpts *opts; SocketAddress *gsconf =3D NULL; - SocketAddressList *curr =3D NULL; + SocketAddressList **curr; QDict *backing_options =3D NULL; Error *local_err =3D NULL; char *str =3D NULL; @@ -547,6 +547,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlust= er *gconf, } gconf->path =3D g_strdup(ptr); qemu_opts_del(opts); + curr =3D &gconf->server; for (i =3D 0; i < num_servers; i++) { str =3D g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN"%d.", i); @@ -655,15 +656,9 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlus= ter *gconf, qemu_opts_del(opts); } - if (gconf->server =3D=3D NULL) { - gconf->server =3D g_new0(SocketAddressList, 1); - gconf->server->value =3D gsconf; - curr =3D gconf->server; - } else { - curr->next =3D g_new0(SocketAddressList, 1); - curr->next->value =3D gsconf; - curr =3D curr->next; - } + *curr =3D g_new0(SocketAddressList, 1); + (*curr)->value =3D gsconf; + curr =3D &(*curr)->next; gsconf =3D NULL; qobject_unref(backing_options); diff --git a/chardev/char.c b/chardev/char.c index 78553125d311..8dd7ef4c5935 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -776,15 +776,14 @@ static int qmp_query_chardev_foreach(Object *obj, voi= d *data) { Chardev *chr =3D CHARDEV(obj); ChardevInfoList **list =3D data; - ChardevInfoList *info =3D g_malloc0(sizeof(*info)); + ChardevInfo *value; - info->value =3D g_malloc0(sizeof(*info->value)); - info->value->label =3D g_strdup(chr->label); - info->value->filename =3D g_strdup(chr->filename); - info->value->frontend_open =3D chr->be && chr->be->fe_open; + value =3D g_malloc0(sizeof(*value)); + value->label =3D g_strdup(chr->label); + value->filename =3D g_strdup(chr->filename); + value->frontend_open =3D chr->be && chr->be->fe_open; - info->next =3D *list; - *list =3D info; + QAPI_LIST_ADD(*list, value); return 0; } @@ -803,12 +802,10 @@ static void qmp_prepend_backend(const char *name, void *opaque) { ChardevBackendInfoList **list =3D opaque; - ChardevBackendInfoList *info =3D g_malloc0(sizeof(*info)); + ChardevBackendInfo *value =3D g_new0(ChardevBackendInfo, 1); - info->value =3D g_malloc0(sizeof(*info->value)); - info->value->name =3D g_strdup(name); - info->next =3D *list; - *list =3D info; + value->name =3D g_strdup(name); + QAPI_LIST_ADD(*list, value); } ChardevBackendInfoList *qmp_query_chardev_backends(Error **errp) diff --git a/hw/core/machine.c b/hw/core/machine.c index c5e0e79e6dbc..a05c4739ca7a 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -492,11 +492,7 @@ static void machine_set_nvdimm_persistence(Object *obj= , const char *value, void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *= type) { - strList *item =3D g_new0(strList, 1); - - item->value =3D g_strdup(type); - item->next =3D mc->allowed_dynamic_sysbus_devices; - mc->allowed_dynamic_sysbus_devices =3D item; + QAPI_LIST_ADD(mc->allowed_dynamic_sysbus_devices, g_strdup(type)); } static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque) diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c index 1af1e6fa2f9b..a1137e11ff48 100644 --- a/hw/net/rocker/rocker.c +++ b/hw/net/rocker/rocker.c @@ -127,13 +127,11 @@ RockerPortList *qmp_query_rocker_ports(const char *na= me, Error **errp) } for (i =3D r->fp_ports - 1; i >=3D 0; i--) { - RockerPortList *info =3D g_malloc0(sizeof(*info)); - info->value =3D g_malloc0(sizeof(*info->value)); + RockerPort *value =3D g_malloc0(sizeof(*value)); struct fp_port *port =3D r->fp_port[i]; - fp_port_get_info(port, info); - info->next =3D list; - list =3D info; + fp_port_get_info(port, value); + QAPI_LIST_ADD(list, value); } return list; diff --git a/hw/net/rocker/rocker_fp.c b/hw/net/rocker/rocker_fp.c index 4aa7da79b81d..a616e709292e 100644 --- a/hw/net/rocker/rocker_fp.c +++ b/hw/net/rocker/rocker_fp.c @@ -51,14 +51,14 @@ bool fp_port_get_link_up(FpPort *port) return !qemu_get_queue(port->nic)->link_down; } -void fp_port_get_info(FpPort *port, RockerPortList *info) +void fp_port_get_info(FpPort *port, RockerPort *value) { - info->value->name =3D g_strdup(port->name); - info->value->enabled =3D port->enabled; - info->value->link_up =3D fp_port_get_link_up(port); - info->value->speed =3D port->speed; - info->value->duplex =3D port->duplex; - info->value->autoneg =3D port->autoneg; + value->name =3D g_strdup(port->name); + value->enabled =3D port->enabled; + value->link_up =3D fp_port_get_link_up(port); + value->speed =3D port->speed; + value->duplex =3D port->duplex; + value->autoneg =3D port->autoneg; } void fp_port_get_macaddr(FpPort *port, MACAddr *macaddr) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 277289d56e76..6b13d3ca3c8f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -437,17 +437,14 @@ static void rxfilter_notify(NetClientState *nc) static intList *get_vlan_table(VirtIONet *n) { - intList *list, *entry; + intList *list; int i, j; list =3D NULL; for (i =3D 0; i < MAX_VLAN >> 5; i++) { for (j =3D 0; n->vlans[i] && j <=3D 0x1f; j++) { if (n->vlans[i] & (1U << j)) { - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D (i << 5) + j; - entry->next =3D list; - list =3D entry; + QAPI_LIST_ADD(list, (i << 5) + j); } } } @@ -460,7 +457,7 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClien= tState *nc) VirtIONet *n =3D qemu_get_nic_opaque(nc); VirtIODevice *vdev =3D VIRTIO_DEVICE(n); RxFilterInfo *info; - strList *str_list, *entry; + strList *str_list; int i; info =3D g_malloc0(sizeof(*info)); @@ -491,19 +488,15 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetCli= entState *nc) str_list =3D NULL; for (i =3D 0; i < n->mac_table.first_multi; i++) { - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D qemu_mac_strdup_printf(n->mac_table.macs + i * ET= H_ALEN); - entry->next =3D str_list; - str_list =3D entry; + QAPI_LIST_ADD(str_list, + qemu_mac_strdup_printf(n->mac_table.macs + i * ETH_A= LEN)); } info->unicast_table =3D str_list; str_list =3D NULL; for (i =3D n->mac_table.first_multi; i < n->mac_table.in_use; i++) { - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D qemu_mac_strdup_printf(n->mac_table.macs + i * ET= H_ALEN); - entry->next =3D str_list; - str_list =3D entry; + QAPI_LIST_ADD(str_list, + qemu_mac_strdup_printf(n->mac_table.macs + i * ETH_A= LEN)); } info->multicast_table =3D str_list; info->vlan_table =3D get_vlan_table(n); diff --git a/migration/migration.c b/migration/migration.c index deb6005b8d37..239a7e430214 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -368,12 +368,9 @@ int migration_incoming_enable_colo(void) void migrate_add_address(SocketAddress *address) { MigrationIncomingState *mis =3D migration_incoming_get_current(); - SocketAddressList *addrs; - addrs =3D g_new0(SocketAddressList, 1); - addrs->next =3D mis->socket_address_list; - mis->socket_address_list =3D addrs; - addrs->value =3D QAPI_CLONE(SocketAddress, address); + QAPI_LIST_ADD(mis->socket_address_list, + QAPI_CLONE(SocketAddress, address)); } void qemu_start_incoming_migration(const char *uri, Error **errp) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 0a2f88a87d06..18ac7e06c581 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -145,14 +145,11 @@ static struct PostcopyBlocktimeContext *blocktime_con= text_new(void) static uint32List *get_vcpu_blocktime_list(PostcopyBlocktimeContext *ctx) { MachineState *ms =3D MACHINE(qdev_get_machine()); - uint32List *list =3D NULL, *entry =3D NULL; + uint32List *list =3D NULL; int i; for (i =3D ms->smp.cpus - 1; i >=3D 0; i--) { - entry =3D g_new0(uint32List, 1); - entry->value =3D ctx->vcpu_blocktime[i]; - entry->next =3D list; - list =3D entry; + QAPI_LIST_ADD(list, ctx->vcpu_blocktime[i]); } return list; diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 9789f4277f50..629c3d1bf741 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1248,7 +1248,8 @@ void hmp_migrate_set_capability(Monitor *mon, const Q= Dict *qdict) const char *cap =3D qdict_get_str(qdict, "capability"); bool state =3D qdict_get_bool(qdict, "state"); Error *err =3D NULL; - MigrationCapabilityStatusList *caps =3D g_malloc0(sizeof(*caps)); + MigrationCapabilityStatusList *caps =3D NULL; + MigrationCapabilityStatus *value =3D NULL; int val; val =3D qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); @@ -1256,10 +1257,10 @@ void hmp_migrate_set_capability(Monitor *mon, const= QDict *qdict) goto end; } - caps->value =3D g_malloc0(sizeof(*caps->value)); - caps->value->capability =3D val; - caps->value->state =3D state; - caps->next =3D NULL; + value =3D g_malloc0(sizeof(*value)); + value->capability =3D val; + value->state =3D state; + QAPI_LIST_ADD(caps, value); qmp_migrate_set_capabilities(caps, &err); end: diff --git a/qemu-img.c b/qemu-img.c index 2103507936ea..4cfa8bccc5e7 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1643,14 +1643,13 @@ static void do_dirty_bitmap_merge(const char *dst_n= ode, const char *dst_name, Error **errp) { BlockDirtyBitmapMergeSource *merge_src; - BlockDirtyBitmapMergeSourceList *list; + BlockDirtyBitmapMergeSourceList *list =3D NULL; merge_src =3D g_new0(BlockDirtyBitmapMergeSource, 1); merge_src->type =3D QTYPE_QDICT; merge_src->u.external.node =3D g_strdup(src_node); merge_src->u.external.name =3D g_strdup(src_name); - list =3D g_new0(BlockDirtyBitmapMergeSourceList, 1); - list->value =3D merge_src; + QAPI_LIST_ADD(list, merge_src); qmp_block_dirty_bitmap_merge(dst_node, dst_name, list, errp); qapi_free_BlockDirtyBitmapMergeSourceList(list); } diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 3bffee99d4c9..06540425ded2 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1211,7 +1211,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error *= *errp) { FsMountList mounts; struct FsMount *mount; - GuestFilesystemInfoList *new, *ret =3D NULL; + GuestFilesystemInfoList *ret =3D NULL; Error *local_err =3D NULL; QTAILQ_INIT(&mounts); @@ -1224,10 +1224,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error = **errp) QTAILQ_FOREACH(mount, &mounts, next) { g_debug("Building guest fsinfo for '%s'", mount->dirname); - new =3D g_malloc0(sizeof(*ret)); - new->value =3D build_guest_fsinfo(mount, &local_err); - new->next =3D ret; - ret =3D new; + QAPI_LIST_ADD(ret, build_guest_fsinfo(mount, &local_err)); if (local_err) { error_propagate(errp, local_err); qapi_free_GuestFilesystemInfoList(ret); @@ -1493,7 +1490,6 @@ GuestFilesystemTrimResponse * qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) { GuestFilesystemTrimResponse *response; - GuestFilesystemTrimResultList *list; GuestFilesystemTrimResult *result; int ret =3D 0; FsMountList mounts; @@ -1517,10 +1513,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, = Error **errp) result =3D g_malloc0(sizeof(*result)); result->path =3D g_strdup(mount->dirname); - list =3D g_malloc0(sizeof(*list)); - list->value =3D result; - list->next =3D response->paths; - response->paths =3D list; + QAPI_LIST_ADD(response->paths, result); fd =3D qemu_open_old(mount->dirname, O_RDONLY); if (fd =3D=3D -1) { diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 0c3c05484f5f..cc5736c3bba8 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -926,10 +926,8 @@ static GuestDiskAddressList *build_guest_disk_info(cha= r *guid, Error **errp) error_free(local_err); goto out; } - list =3D g_malloc0(sizeof(*list)); - list->value =3D disk; + QAPI_LIST_ADD(list, disk); disk =3D NULL; - list->next =3D NULL; goto out; } else { error_setg_win32(errp, GetLastError(), @@ -1064,7 +1062,7 @@ free: GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) { HANDLE vol_h; - GuestFilesystemInfoList *new, *ret =3D NULL; + GuestFilesystemInfoList *ret =3D NULL; char guid[256]; vol_h =3D FindFirstVolume(guid, sizeof(guid)); @@ -1082,10 +1080,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error = **errp) error_free(local_err); continue; } - new =3D g_malloc(sizeof(*ret)); - new->value =3D info; - new->next =3D ret; - ret =3D new; + QAPI_LIST_ADD(ret, info); } while (FindNextVolume(vol_h, guid, sizeof(guid))); if (GetLastError() !=3D ERROR_NO_MORE_FILES) { @@ -1268,11 +1263,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, = Error **errp) res->path =3D path; - list =3D g_new0(GuestFilesystemTrimResultList, 1); - list->value =3D res; - list->next =3D resp->paths; - - resp->paths =3D list; + QAPI_LIST_ADD(resp->paths, res); memset(argv, 0, sizeof(argv)); argv[0] =3D (gchar *)"defrag.exe"; diff --git a/qga/commands.c b/qga/commands.c index 3dcd5fbe5c4d..27118df6caea 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -66,17 +66,13 @@ static void qmp_command_info(const QmpCommand *cmd, voi= d *opaque) { GuestAgentInfo *info =3D opaque; GuestAgentCommandInfo *cmd_info; - GuestAgentCommandInfoList *cmd_info_list; cmd_info =3D g_new0(GuestAgentCommandInfo, 1); cmd_info->name =3D g_strdup(qmp_command_name(cmd)); cmd_info->enabled =3D qmp_command_is_enabled(cmd); cmd_info->success_response =3D qmp_has_success_response(cmd); - cmd_info_list =3D g_new0(GuestAgentCommandInfoList, 1); - cmd_info_list->value =3D cmd_info; - cmd_info_list->next =3D info->supported_commands; - info->supported_commands =3D cmd_info_list; + QAPI_LIST_ADD(info->supported_commands, cmd_info); } struct GuestAgentInfo *qmp_guest_info(Error **errp) diff --git a/qom/qom-qmp-cmds.c b/qom/qom-qmp-cmds.c index 310ab2d0481d..5ac9272ffeea 100644 --- a/qom/qom-qmp-cmds.c +++ b/qom/qom-qmp-cmds.c @@ -46,14 +46,12 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, = Error **errp) object_property_iter_init(&iter, obj); while ((prop =3D object_property_iter_next(&iter))) { - ObjectPropertyInfoList *entry =3D g_malloc0(sizeof(*entry)); + ObjectPropertyInfo *value =3D g_malloc0(sizeof(ObjectPropertyInfo)= ); - entry->value =3D g_malloc0(sizeof(ObjectPropertyInfo)); - entry->next =3D props; - props =3D entry; + QAPI_LIST_ADD(props, value); - entry->value->name =3D g_strdup(prop->name); - entry->value->type =3D g_strdup(prop->type); + value->name =3D g_strdup(prop->name); + value->type =3D g_strdup(prop->type); } return props; @@ -90,7 +88,7 @@ QObject *qmp_qom_get(const char *path, const char *proper= ty, Error **errp) static void qom_list_types_tramp(ObjectClass *klass, void *data) { - ObjectTypeInfoList *e, **pret =3D data; + ObjectTypeInfoList **pret =3D data; ObjectTypeInfo *info; ObjectClass *parent =3D object_class_get_parent(klass); @@ -102,10 +100,7 @@ static void qom_list_types_tramp(ObjectClass *klass, v= oid *data) info->parent =3D g_strdup(object_class_get_name(parent)); } - e =3D g_malloc0(sizeof(*e)); - e->value =3D info; - e->next =3D *pret; - *pret =3D e; + QAPI_LIST_ADD(*pret, info); } ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, @@ -155,7 +150,6 @@ ObjectPropertyInfoList *qmp_device_list_properties(cons= t char *typename, object_property_iter_init(&iter, obj); while ((prop =3D object_property_iter_next(&iter))) { ObjectPropertyInfo *info; - ObjectPropertyInfoList *entry; /* Skip Object and DeviceState properties */ if (strcmp(prop->name, "type") =3D=3D 0 || @@ -181,10 +175,7 @@ ObjectPropertyInfoList *qmp_device_list_properties(con= st char *typename, info->default_value =3D qobject_ref(prop->defval); info->has_default_value =3D !!info->default_value; - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D prop_list; - prop_list =3D entry; + QAPI_LIST_ADD(prop_list, info); } object_unref(obj); @@ -222,7 +213,6 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const c= har *typename, } while ((prop =3D object_property_iter_next(&iter))) { ObjectPropertyInfo *info; - ObjectPropertyInfoList *entry; info =3D g_malloc0(sizeof(*info)); info->name =3D g_strdup(prop->name); @@ -230,10 +220,7 @@ ObjectPropertyInfoList *qmp_qom_list_properties(const = char *typename, info->has_description =3D !!prop->description; info->description =3D g_strdup(prop->description); - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D prop_list; - prop_list =3D entry; + QAPI_LIST_ADD(prop_list, info); } object_unref(obj); diff --git a/target/arm/helper.c b/target/arm/helper.c index 97bb6b8c01b4..df150f3c3eeb 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -8293,7 +8293,6 @@ static void arm_cpu_add_definition(gpointer data, gpo= inter user_data) { ObjectClass *oc =3D data; CpuDefinitionInfoList **cpu_list =3D user_data; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; const char *typename; @@ -8303,10 +8302,7 @@ static void arm_cpu_add_definition(gpointer data, gp= ointer user_data) strlen(typename) - strlen("-" TYPE_ARM_CPU)); info->q_typename =3D g_strdup(typename); - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D *cpu_list; - *cpu_list =3D entry; + QAPI_LIST_ADD(*cpu_list, info); } CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) diff --git a/target/arm/monitor.c b/target/arm/monitor.c index 169d8a64b651..771101656535 100644 --- a/target/arm/monitor.c +++ b/target/arm/monitor.c @@ -42,15 +42,6 @@ static GICCapability *gic_cap_new(int version) return cap; } -static GICCapabilityList *gic_cap_list_add(GICCapabilityList *head, - GICCapability *cap) -{ - GICCapabilityList *item =3D g_new0(GICCapabilityList, 1); - item->value =3D cap; - item->next =3D head; - return item; -} - static inline void gic_cap_kvm_probe(GICCapability *v2, GICCapability *v3) { #ifdef CONFIG_KVM @@ -84,8 +75,8 @@ GICCapabilityList *qmp_query_gic_capabilities(Error **err= p) gic_cap_kvm_probe(v2, v3); - head =3D gic_cap_list_add(head, v2); - head =3D gic_cap_list_add(head, v3); + QAPI_LIST_ADD(head, v2); + QAPI_LIST_ADD(head, v3); return head; } diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0d8606958e9e..9ae6661f97e3 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4984,7 +4984,6 @@ static void x86_cpu_definition_entry(gpointer data, g= pointer user_data) ObjectClass *oc =3D data; X86CPUClass *cc =3D X86_CPU_CLASS(oc); CpuDefinitionInfoList **cpu_list =3D user_data; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; info =3D g_malloc0(sizeof(*info)); @@ -5009,10 +5008,7 @@ static void x86_cpu_definition_entry(gpointer data, = gpointer user_data) info->has_alias_of =3D !!info->alias_of; } - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D *cpu_list; - *cpu_list =3D entry; + QAPI_LIST_ADD(*cpu_list, info); } CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) diff --git a/target/mips/helper.c b/target/mips/helper.c index afd78b1990be..036bacc24b22 100644 --- a/target/mips/helper.c +++ b/target/mips/helper.c @@ -1502,7 +1502,6 @@ static void mips_cpu_add_definition(gpointer data, gp= ointer user_data) { ObjectClass *oc =3D data; CpuDefinitionInfoList **cpu_list =3D user_data; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; const char *typename; @@ -1512,10 +1511,7 @@ static void mips_cpu_add_definition(gpointer data, g= pointer user_data) strlen(typename) - strlen("-" TYPE_MIPS_CPU)); info->q_typename =3D g_strdup(typename); - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D *cpu_list; - *cpu_list =3D entry; + QAPI_LIST_ADD(*cpu_list, info); } CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 461e0b8f4a8d..a837ac66c9c8 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -427,7 +427,6 @@ static void create_cpu_model_list(ObjectClass *klass, v= oid *opaque) { struct CpuDefinitionInfoListData *cpu_list_data =3D opaque; CpuDefinitionInfoList **cpu_list =3D &cpu_list_data->list; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; char *name =3D g_strdup(object_class_get_name(klass)); S390CPUClass *scc =3D S390_CPU_CLASS(klass); @@ -454,10 +453,7 @@ static void create_cpu_model_list(ObjectClass *klass, = void *opaque) object_unref(obj); } - entry =3D g_new0(CpuDefinitionInfoList, 1); - entry->value =3D info; - entry->next =3D *cpu_list; - *cpu_list =3D entry; + QAPI_LIST_ADD(*cpu_list, info); } CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) @@ -624,12 +620,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(C= puModelExpansionType type, static void list_add_feat(const char *name, void *opaque) { strList **last =3D (strList **) opaque; - strList *entry; - entry =3D g_new0(strList, 1); - entry->value =3D g_strdup(name); - entry->next =3D *last; - *last =3D entry; + QAPI_LIST_ADD(*last, g_strdup(name)); } CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *infoa, diff --git a/tests/test-clone-visitor.c b/tests/test-clone-visitor.c index 5e1e8b2f5e8a..03788d355130 100644 --- a/tests/test-clone-visitor.c +++ b/tests/test-clone-visitor.c @@ -65,16 +65,13 @@ static void test_clone_alternate(void) static void test_clone_list_union(void) { - uint8List *src, *dst; + uint8List *src =3D NULL, *dst; uint8List *tmp =3D NULL; int i; /* Build list in reverse */ for (i =3D 10; i; i--) { - src =3D g_new0(uint8List, 1); - src->next =3D tmp; - src->value =3D i; - tmp =3D src; + QAPI_LIST_ADD(src, i); } dst =3D QAPI_CLONE(uint8List, src); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 1c856d9bd20a..95487b139801 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -223,7 +223,8 @@ static void test_visitor_out_list(TestOutputVisitorData= *data, const void *unused) { const char *value_str =3D "list value"; - TestStructList *p, *head =3D NULL; + TestStruct *value; + TestStructList *head =3D NULL; const int max_items =3D 10; bool value_bool =3D true; int value_int =3D 10; @@ -233,14 +234,12 @@ static void test_visitor_out_list(TestOutputVisitorDa= ta *data, /* Build the list in reverse order... */ for (i =3D 0; i < max_items; i++) { - p =3D g_malloc0(sizeof(*p)); - p->value =3D g_malloc0(sizeof(*p->value)); - p->value->integer =3D value_int + (max_items - i - 1); - p->value->boolean =3D value_bool; - p->value->string =3D g_strdup(value_str); + value =3D g_malloc0(sizeof(*value)); + value->integer =3D value_int + (max_items - i - 1); + value->boolean =3D value_bool; + value->string =3D g_strdup(value_str); - p->next =3D head; - head =3D p; + QAPI_LIST_ADD(head, value); } visit_type_TestStructList(data->ov, NULL, &head, &error_abort); @@ -270,26 +269,25 @@ static void test_visitor_out_list(TestOutputVisitorDa= ta *data, static void test_visitor_out_list_qapi_free(TestOutputVisitorData *data, const void *unused) { - UserDefTwoList *p, *head =3D NULL; + UserDefTwo *value; + UserDefTwoList *head =3D NULL; const char string[] =3D "foo bar"; int i, max_count =3D 1024; for (i =3D 0; i < max_count; i++) { - p =3D g_malloc0(sizeof(*p)); - p->value =3D g_malloc0(sizeof(*p->value)); + value =3D g_malloc0(sizeof(*value)); - p->value->string0 =3D g_strdup(string); - p->value->dict1 =3D g_new0(UserDefTwoDict, 1); - p->value->dict1->string1 =3D g_strdup(string); - p->value->dict1->dict2 =3D g_new0(UserDefTwoDictDict, 1); - p->value->dict1->dict2->userdef =3D g_new0(UserDefOne, 1); - p->value->dict1->dict2->userdef->string =3D g_strdup(string); - p->value->dict1->dict2->userdef->integer =3D 42; - p->value->dict1->dict2->string =3D g_strdup(string); - p->value->dict1->has_dict3 =3D false; + value->string0 =3D g_strdup(string); + value->dict1 =3D g_new0(UserDefTwoDict, 1); + value->dict1->string1 =3D g_strdup(string); + value->dict1->dict2 =3D g_new0(UserDefTwoDictDict, 1); + value->dict1->dict2->userdef =3D g_new0(UserDefOne, 1); + value->dict1->dict2->userdef->string =3D g_strdup(string); + value->dict1->dict2->userdef->integer =3D 42; + value->dict1->dict2->string =3D g_strdup(string); + value->dict1->has_dict3 =3D false; - p->next =3D head; - head =3D p; + QAPI_LIST_ADD(head, value); } qapi_free_UserDefTwoList(head); diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serial= ization.c index 1c5a8b94ea87..efbf744fcf25 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -704,10 +704,7 @@ static void test_nested_struct_list(gconstpointer opaq= ue) int i =3D 0; for (i =3D 0; i < 8; i++) { - tmp =3D g_new0(UserDefTwoList, 1); - tmp->value =3D nested_struct_create(); - tmp->next =3D listp; - listp =3D tmp; + QAPI_LIST_ADD(listp, nested_struct_create()); } ops->serialize(listp, &serialize_data, visit_nested_struct_list, diff --git a/trace/qmp.c b/trace/qmp.c index 38246e1aa692..8755835edabc 100644 --- a/trace/qmp.c +++ b/trace/qmp.c @@ -92,39 +92,37 @@ TraceEventInfoList *qmp_trace_event_get_state(const cha= r *name, /* Get states (all errors checked above) */ trace_event_iter_init(&iter, name); while ((ev =3D trace_event_iter_next(&iter)) !=3D NULL) { - TraceEventInfoList *elem; + TraceEventInfo *value; bool is_vcpu =3D trace_event_is_vcpu(ev); if (has_vcpu && !is_vcpu) { continue; } - elem =3D g_new(TraceEventInfoList, 1); - elem->value =3D g_new(TraceEventInfo, 1); - elem->value->vcpu =3D is_vcpu; - elem->value->name =3D g_strdup(trace_event_get_name(ev)); + value =3D g_new(TraceEventInfo, 1); + value->vcpu =3D is_vcpu; + value->name =3D g_strdup(trace_event_get_name(ev)); if (!trace_event_get_state_static(ev)) { - elem->value->state =3D TRACE_EVENT_STATE_UNAVAILABLE; + value->state =3D TRACE_EVENT_STATE_UNAVAILABLE; } else { if (has_vcpu) { if (is_vcpu) { if (trace_event_get_vcpu_state_dynamic(cpu, ev)) { - elem->value->state =3D TRACE_EVENT_STATE_ENABLED; + value->state =3D TRACE_EVENT_STATE_ENABLED; } else { - elem->value->state =3D TRACE_EVENT_STATE_DISABLED; + value->state =3D TRACE_EVENT_STATE_DISABLED; } } /* else: already skipped above */ } else { if (trace_event_get_state_dynamic(ev)) { - elem->value->state =3D TRACE_EVENT_STATE_ENABLED; + value->state =3D TRACE_EVENT_STATE_ENABLED; } else { - elem->value->state =3D TRACE_EVENT_STATE_DISABLED; + value->state =3D TRACE_EVENT_STATE_DISABLED; } } } - elem->next =3D events; - events =3D elem; + QAPI_LIST_ADD(events, value); } return events; diff --git a/ui/vnc.c b/ui/vnc.c index f006aa1afdb2..f39cfc952906 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -365,14 +365,11 @@ static VncDisplay *vnc_display_find(const char *id) static VncClientInfoList *qmp_query_client_list(VncDisplay *vd) { - VncClientInfoList *cinfo, *prev =3D NULL; + VncClientInfoList *prev =3D NULL; VncState *client; QTAILQ_FOREACH(client, &vd->clients, next) { - cinfo =3D g_new0(VncClientInfoList, 1); - cinfo->value =3D qmp_query_vnc_client(client); - cinfo->next =3D prev; - prev =3D cinfo; + QAPI_LIST_ADD(prev, qmp_query_vnc_client(client)); } return prev; } @@ -453,7 +450,6 @@ static VncServerInfo2List *qmp_query_server_entry(QIOCh= annelSocket *ioc, int subauth, VncServerInfo2List *prev) { - VncServerInfo2List *list; VncServerInfo2 *info; Error *err =3D NULL; SocketAddress *addr; @@ -476,10 +472,8 @@ static VncServerInfo2List *qmp_query_server_entry(QIOC= hannelSocket *ioc, qmp_query_auth(auth, subauth, &info->auth, &info->vencrypt, &info->has_vencrypt); - list =3D g_new0(VncServerInfo2List, 1); - list->value =3D info; - list->next =3D prev; - return list; + QAPI_LIST_ADD(prev, info); + return prev; } static void qmp_query_auth(int auth, int subauth, @@ -554,7 +548,7 @@ static void qmp_query_auth(int auth, int subauth, VncInfo2List *qmp_query_vnc_servers(Error **errp) { - VncInfo2List *item, *prev =3D NULL; + VncInfo2List *prev =3D NULL; VncInfo2 *info; VncDisplay *vd; DeviceState *dev; @@ -583,10 +577,7 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp) vd->ws_subauth, info->server); } - item =3D g_new0(VncInfo2List, 1); - item->value =3D info; - item->next =3D prev; - prev =3D item; + QAPI_LIST_ADD(prev, info); } return prev; } diff --git a/util/qemu-config.c b/util/qemu-config.c index 660f47b0050f..495ada45f3df 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -55,7 +55,7 @@ QemuOpts *qemu_find_opts_singleton(const char *group) static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc = *desc) { - CommandLineParameterInfoList *param_list =3D NULL, *entry; + CommandLineParameterInfoList *param_list =3D NULL; CommandLineParameterInfo *info; int i; @@ -87,10 +87,7 @@ static CommandLineParameterInfoList *query_option_descs(= const QemuOptDesc *desc) info->q_default =3D g_strdup(desc[i].def_value_str); } - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D param_list; - param_list =3D entry; + QAPI_LIST_ADD(param_list, info); } return param_list; @@ -246,7 +243,7 @@ CommandLineOptionInfoList *qmp_query_command_line_optio= ns(bool has_option, const char *opti= on, Error **errp) { - CommandLineOptionInfoList *conf_list =3D NULL, *entry; + CommandLineOptionInfoList *conf_list =3D NULL; CommandLineOptionInfo *info; int i; @@ -262,10 +259,7 @@ CommandLineOptionInfoList *qmp_query_command_line_opti= ons(bool has_option, info->parameters =3D query_option_descs(vm_config_groups[i]->desc); } - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D conf_list; - conf_list =3D entry; + QAPI_LIST_ADD(conf_list, info); } } diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.= inc index bb66526280ef..5795d0e5af2c 100644 --- a/target/ppc/translate_init.c.inc +++ b/target/ppc/translate_init.c.inc @@ -10621,7 +10621,6 @@ static void ppc_cpu_defs_entry(gpointer data, gpoin= ter user_data) ObjectClass *oc =3D data; CpuDefinitionInfoList **first =3D user_data; const char *typename; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; typename =3D object_class_get_name(oc); @@ -10629,10 +10628,7 @@ static void ppc_cpu_defs_entry(gpointer data, gpoi= nter user_data) info->name =3D g_strndup(typename, strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFF= IX)); - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D *first; - *first =3D entry; + QAPI_LIST_ADD(*first, info); } CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) @@ -10648,7 +10644,6 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Er= ror **errp) for (i =3D 0; ppc_cpu_aliases[i].alias !=3D NULL; i++) { PowerPCCPUAlias *alias =3D &ppc_cpu_aliases[i]; ObjectClass *oc; - CpuDefinitionInfoList *entry; CpuDefinitionInfo *info; oc =3D ppc_cpu_class_by_name(alias->model); @@ -10660,10 +10655,7 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(E= rror **errp) info->name =3D g_strdup(alias->alias); info->q_typename =3D g_strdup(object_class_get_name(oc)); - entry =3D g_malloc0(sizeof(*entry)); - entry->value =3D info; - entry->next =3D cpu_list; - cpu_list =3D entry; + QAPI_LIST_ADD(cpu_list, info); } return cpu_list; --=20 2.29.0