From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19644C433E0 for ; Mon, 15 Feb 2021 21:30:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7BAD264DEB for ; Mon, 15 Feb 2021 21:30:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BAD264DEB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBlRR-0005D6-8y for qemu-devel@archiver.kernel.org; Mon, 15 Feb 2021 16:30:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBlQ3-0004Xp-Vs; Mon, 15 Feb 2021 16:28:36 -0500 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]:33978) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lBlQ1-0007Yk-KZ; Mon, 15 Feb 2021 16:28:35 -0500 Received: by mail-ej1-x631.google.com with SMTP id hs11so13585904ejc.1; Mon, 15 Feb 2021 13:28:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NpqTHORryW2lD2kJnhsTDbHkDVnXJfU8VQv92tNoQ54=; b=ppB9qJu224DQCoBu1dJYmPKn35ht28jnS6Ty5d8yJSHoRhcpFQ2CUuqZ5NJ/GHpqdG zR+4+K0lr3j5fwEW6Zgly1dq7qzceJ5vZ3jhwV1txSRlsoLesQs0pcbUZ5vO0wS+C2W7 bskyHwaoF7q6rJ+JQSRX1/jr1K/I5jABL6MqR00YN+aVzx/tOo/875aJyp3tR1RKdQK5 YqVPB/MbT5WmkcQ5HZytie+pdkidiA0j1ATpZLRs15CQgwzuOdmyd1xx33ryQZUUdFEM kdneAqLUDW9LqNgu7/VBY2j8EEbYQ4IZKwNgxnlV4JaiHtN4IeFbxIvVc+d7g9t+Uehe v3yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NpqTHORryW2lD2kJnhsTDbHkDVnXJfU8VQv92tNoQ54=; b=jGLbxEN/F5al0NR4s+0ZmWdXXiqthx8Nd3mJdEufBcIjkMn36Dntw3V3olRhTjMNCK 1Y1cHwZUrAAcPr8QFKcp7VXLZt/w/fFZ/nLyECsyqXVfU2gqijQ5tcr8dr+N6zH5NVN3 OvVZB94pO+OyZ/FYlraI0Phr3/4ipL19/j42DfKmX3K7IOOdSRmvN5+RJS92/b3DLNzb B3F0H8u5pKZ29a9aZKxVK/T8jK0JWv3FW5L+aZGB89v2otLFvlJQsKAydaMipeVDoQI9 Pr50hNLKDhiGURhGyBsaU0Vw7RJ+y0lg93JHzsxo1rX9ZgRuKUtYnJ5ImVBo6Gjk7oaW rxNQ== X-Gm-Message-State: AOAM5302oqsuNAvE4TJmQLd7Uld01raZW0nCofFcf5kn1q7hEQaHQjQE ROP+9TAdmP8D1ZmuN1TQpW7E+9iFTU9LSsNKN64= X-Google-Smtp-Source: ABdhPJzr+DeeLW+fEUEyLmkTacKdRo4Afveu9tn+SyV7soWynFj9o5z/c2Xb5vlMJ8lNraDCbxlArLC7cZgBkSCErQo= X-Received: by 2002:a17:906:798:: with SMTP id l24mr17656756ejc.92.1613424511337; Mon, 15 Feb 2021 13:28:31 -0800 (PST) MIME-Version: 1.0 References: <20210215090225.1046239-1-thuth@redhat.com> In-Reply-To: <20210215090225.1046239-1-thuth@redhat.com> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Tue, 16 Feb 2021 01:28:19 +0400 Message-ID: Subject: Re: [PATCH] net: Use id_generate() in the network subsystem, too To: Thomas Huth Content-Type: multipart/alternative; boundary="000000000000deca7905bb66aa25" Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=marcandre.lureau@gmail.com; helo=mail-ej1-x631.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: qemu trival , Jason Wang , QEMU , Markus Armbruster Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000deca7905bb66aa25 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 15, 2021 at 1:03 PM Thomas Huth wrote: > We already got a global function called id_generate() to create unique > IDs within QEMU. Let's use it in the network subsytem, too, instead of > inventing our own ID scheme here. > > Signed-off-by: Thomas Huth > Reviewed-by: Marc-Andr=C3=A9 Lureau --- > include/qemu/id.h | 1 + > net/net.c | 6 +++--- > util/id.c | 1 + > 3 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/include/qemu/id.h b/include/qemu/id.h > index b55c406e69..46b759b284 100644 > --- a/include/qemu/id.h > +++ b/include/qemu/id.h > @@ -5,6 +5,7 @@ typedef enum IdSubSystems { > ID_QDEV, > ID_BLOCK, > ID_CHR, > + ID_NET, > ID_MAX /* last element, used as array size */ > } IdSubSystems; > > diff --git a/net/net.c b/net/net.c > index fb7b7dcc25..ca30df963d 100644 > --- a/net/net.c > +++ b/net/net.c > @@ -43,6 +43,7 @@ > #include "qemu/cutils.h" > #include "qemu/config-file.h" > #include "qemu/ctype.h" > +#include "qemu/id.h" > #include "qemu/iov.h" > #include "qemu/qemu-print.h" > #include "qemu/main-loop.h" > @@ -1111,8 +1112,7 @@ static int net_client_init(QemuOpts *opts, bool > is_netdev, Error **errp) > > /* Create an ID for -net if the user did not specify one */ > if (!is_netdev && !qemu_opts_id(opts)) { > - static int idx; > - qemu_opts_set_id(opts, g_strdup_printf("__org.qemu.net%i", > idx++)); > + qemu_opts_set_id(opts, id_generate(ID_NET)); > } > > if (visit_type_Netdev(v, NULL, &object, errp)) { > @@ -1467,7 +1467,7 @@ static int net_param_nic(void *dummy, QemuOpts > *opts, Error **errp) > /* Create an ID if the user did not specify one */ > nd_id =3D g_strdup(qemu_opts_id(opts)); > if (!nd_id) { > - nd_id =3D g_strdup_printf("__org.qemu.nic%i", idx); > + nd_id =3D id_generate(ID_NET); > qemu_opts_set_id(opts, nd_id); > } > > diff --git a/util/id.c b/util/id.c > index 5addb4460e..ded41c5025 100644 > --- a/util/id.c > +++ b/util/id.c > @@ -35,6 +35,7 @@ static const char *const id_subsys_str[ID_MAX] =3D { > [ID_QDEV] =3D "qdev", > [ID_BLOCK] =3D "block", > [ID_CHR] =3D "chr", > + [ID_NET] =3D "net", > }; > > /* > -- > 2.27.0 > > > --=20 Marc-Andr=C3=A9 Lureau --000000000000deca7905bb66aa25 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Mon, Feb 15, 2021 at 1:03 PM Thoma= s Huth <thuth@redhat.com> wro= te:
We already g= ot a global function called id_generate() to create unique
IDs within QEMU. Let's use it in the network subsytem, too, instead of<= br> inventing our own ID scheme here.

Signed-off-by: Thomas Huth <thuth@redhat.com>

Re= viewed-by: Marc-Andr=C3=A9 Lureau <marcandre.lureau@redhat.com>=C2=A0

---
=C2=A0include/qemu/id.h | 1 +
=C2=A0net/net.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 6 +++---
=C2=A0util/id.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 1 +
=C2=A03 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/qemu/id.h b/include/qemu/id.h
index b55c406e69..46b759b284 100644
--- a/include/qemu/id.h
+++ b/include/qemu/id.h
@@ -5,6 +5,7 @@ typedef enum IdSubSystems {
=C2=A0 =C2=A0 =C2=A0ID_QDEV,
=C2=A0 =C2=A0 =C2=A0ID_BLOCK,
=C2=A0 =C2=A0 =C2=A0ID_CHR,
+=C2=A0 =C2=A0 ID_NET,
=C2=A0 =C2=A0 =C2=A0ID_MAX=C2=A0 =C2=A0 =C2=A0 /* last element, used as arr= ay size */
=C2=A0} IdSubSystems;

diff --git a/net/net.c b/net/net.c
index fb7b7dcc25..ca30df963d 100644
--- a/net/net.c
+++ b/net/net.c
@@ -43,6 +43,7 @@
=C2=A0#include "qemu/cutils.h"
=C2=A0#include "qemu/config-file.h"
=C2=A0#include "qemu/ctype.h"
+#include "qemu/id.h"
=C2=A0#include "qemu/iov.h"
=C2=A0#include "qemu/qemu-print.h"
=C2=A0#include "qemu/main-loop.h"
@@ -1111,8 +1112,7 @@ static int net_client_init(QemuOpts *opts, bool is_ne= tdev, Error **errp)

=C2=A0 =C2=A0 =C2=A0/* Create an ID for -net if the user did not specify on= e */
=C2=A0 =C2=A0 =C2=A0if (!is_netdev && !qemu_opts_id(opts)) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 static int idx;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 qemu_opts_set_id(opts, g_strdup_printf("_= _org.q= emu.net%i", idx++));
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 qemu_opts_set_id(opts, id_generate(ID_NET)); =C2=A0 =C2=A0 =C2=A0}

=C2=A0 =C2=A0 =C2=A0if (visit_type_Netdev(v, NULL, &object, errp)) { @@ -1467,7 +1467,7 @@ static int net_param_nic(void *dummy, QemuOpts *opts,= Error **errp)
=C2=A0 =C2=A0 =C2=A0/* Create an ID if the user did not specify one */
=C2=A0 =C2=A0 =C2=A0nd_id =3D g_strdup(qemu_opts_id(opts));
=C2=A0 =C2=A0 =C2=A0if (!nd_id) {
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 nd_id =3D g_strdup_printf("__org.qemu.nic= %i", idx);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 nd_id =3D id_generate(ID_NET);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_opts_set_id(opts, nd_id);
=C2=A0 =C2=A0 =C2=A0}

diff --git a/util/id.c b/util/id.c
index 5addb4460e..ded41c5025 100644
--- a/util/id.c
+++ b/util/id.c
@@ -35,6 +35,7 @@ static const char *const id_subsys_str[ID_MAX] =3D {
=C2=A0 =C2=A0 =C2=A0[ID_QDEV]=C2=A0 =3D "qdev",
=C2=A0 =C2=A0 =C2=A0[ID_BLOCK] =3D "block",
=C2=A0 =C2=A0 =C2=A0[ID_CHR] =3D "chr",
+=C2=A0 =C2=A0 [ID_NET] =3D "net",
=C2=A0};

=C2=A0/*
--
2.27.0




--
Marc-Andr=C3=A9 Lureau
--000000000000deca7905bb66aa25--