From: David Gibson <david@gibson.dropbear.id.au>
To: Laurent Vivier <lvivier@redhat.com>
Cc: qemu-devel@nongnu.org, "Thomas Huth" <thuth@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eric Blake" <eblake@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Samuel Thibault" <samuel.thibault@ens-lyon.org>,
"Markus Armbruster" <armbru@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Stefan Weil" <sw@weilnetz.de>, "Greg Kurz" <groug@kaod.org>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH v10 05/17] net: introduce qemu_set_info_str() function
Date: Thu, 6 Oct 2022 19:08:20 +1100 [thread overview]
Message-ID: <Yz6M9Azhfa9RRYA2@yekko> (raw)
In-Reply-To: <20221005162051.1120041-6-lvivier@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 11145 bytes --]
On Wed, Oct 05, 2022 at 06:20:39PM +0200, Laurent Vivier wrote:
> Embed the setting of info_str in a function.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> include/net/net.h | 1 +
> net/l2tpv3.c | 3 +--
> net/net.c | 17 ++++++++++++-----
> net/slirp.c | 5 ++---
> net/socket.c | 33 ++++++++++++++-------------------
> net/tap-win32.c | 3 +--
> net/tap.c | 13 +++++--------
> net/vde.c | 3 +--
> net/vhost-user.c | 3 +--
> net/vhost-vdpa.c | 2 +-
> 10 files changed, 39 insertions(+), 44 deletions(-)
>
> diff --git a/include/net/net.h b/include/net/net.h
> index 025dbf1e143b..3db75ff841ff 100644
> --- a/include/net/net.h
> +++ b/include/net/net.h
> @@ -177,6 +177,7 @@ ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf,
> void qemu_purge_queued_packets(NetClientState *nc);
> void qemu_flush_queued_packets(NetClientState *nc);
> void qemu_flush_or_purge_queued_packets(NetClientState *nc, bool purge);
> +void qemu_set_info_str(NetClientState *nc, const char *fmt, ...);
> void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]);
> bool qemu_has_ufo(NetClientState *nc);
> bool qemu_has_vnet_hdr(NetClientState *nc);
> diff --git a/net/l2tpv3.c b/net/l2tpv3.c
> index af373e5c300c..350041a0d6c0 100644
> --- a/net/l2tpv3.c
> +++ b/net/l2tpv3.c
> @@ -723,8 +723,7 @@ int net_init_l2tpv3(const Netdev *netdev,
>
> l2tpv3_read_poll(s, true);
>
> - snprintf(s->nc.info_str, sizeof(s->nc.info_str),
> - "l2tpv3: connected");
> + qemu_set_info_str(&s->nc, "l2tpv3: connected");
> return 0;
> outerr:
> qemu_del_net_client(nc);
> diff --git a/net/net.c b/net/net.c
> index ffe3e5a2cf1d..41e05137d431 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -141,13 +141,20 @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr)
> macaddr[3], macaddr[4], macaddr[5]);
> }
>
> +void qemu_set_info_str(NetClientState *nc, const char *fmt, ...)
> +{
> + va_list ap;
> +
> + va_start(ap, fmt);
> + vsnprintf(nc->info_str, sizeof(nc->info_str), fmt, ap);
> + va_end(ap);
> +}
> +
> void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6])
> {
> - snprintf(nc->info_str, sizeof(nc->info_str),
> - "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
> - nc->model,
> - macaddr[0], macaddr[1], macaddr[2],
> - macaddr[3], macaddr[4], macaddr[5]);
> + qemu_set_info_str(nc, "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
> + nc->model, macaddr[0], macaddr[1], macaddr[2],
> + macaddr[3], macaddr[4], macaddr[5]);
> }
>
> static int mac_table[256] = {0};
> diff --git a/net/slirp.c b/net/slirp.c
> index 8679be644420..14a8d592774c 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -611,9 +611,8 @@ static int net_slirp_init(NetClientState *peer, const char *model,
>
> nc = qemu_new_net_client(&net_slirp_info, peer, model, name);
>
> - snprintf(nc->info_str, sizeof(nc->info_str),
> - "net=%s,restrict=%s", inet_ntoa(net),
> - restricted ? "on" : "off");
> + qemu_set_info_str(nc, "net=%s,restrict=%s", inet_ntoa(net),
> + restricted ? "on" : "off");
>
> s = DO_UPCAST(SlirpState, nc, nc);
>
> diff --git a/net/socket.c b/net/socket.c
> index bfd8596250c4..ade1ecf38b87 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -179,7 +179,7 @@ static void net_socket_send(void *opaque)
> s->fd = -1;
> net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
> s->nc.link_down = true;
> - memset(s->nc.info_str, 0, sizeof(s->nc.info_str));
> + qemu_set_info_str(&s->nc, "");
>
> return;
> }
> @@ -387,16 +387,15 @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
> /* mcast: save bound address as dst */
> if (is_connected && mcast != NULL) {
> s->dgram_dst = saddr;
> - snprintf(nc->info_str, sizeof(nc->info_str),
> - "socket: fd=%d (cloned mcast=%s:%d)",
> - fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> + qemu_set_info_str(nc, "socket: fd=%d (cloned mcast=%s:%d)", fd,
> + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> } else {
> if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) {
> s->dgram_dst.sin_family = AF_UNIX;
> }
>
> - snprintf(nc->info_str, sizeof(nc->info_str),
> - "socket: fd=%d %s", fd, SocketAddressType_str(sa_type));
> + qemu_set_info_str(nc, "socket: fd=%d %s", fd,
> + SocketAddressType_str(sa_type));
> }
>
> return s;
> @@ -430,7 +429,7 @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer,
>
> nc = qemu_new_net_client(&net_socket_info, peer, model, name);
>
> - snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd);
> + qemu_set_info_str(nc, "socket: fd=%d", fd);
>
> s = DO_UPCAST(NetSocketState, nc, nc);
>
> @@ -497,9 +496,8 @@ static void net_socket_accept(void *opaque)
> s->fd = fd;
> s->nc.link_down = false;
> net_socket_connect(s);
> - snprintf(s->nc.info_str, sizeof(s->nc.info_str),
> - "socket: connection from %s:%d",
> - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> + qemu_set_info_str(&s->nc, "socket: connection from %s:%d",
> + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> }
>
> static int net_socket_listen_init(NetClientState *peer,
> @@ -597,9 +595,8 @@ static int net_socket_connect_init(NetClientState *peer,
> return -1;
> }
>
> - snprintf(s->nc.info_str, sizeof(s->nc.info_str),
> - "socket: connect to %s:%d",
> - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> + qemu_set_info_str(&s->nc, "socket: connect to %s:%d",
> + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> return 0;
> }
>
> @@ -642,9 +639,8 @@ static int net_socket_mcast_init(NetClientState *peer,
>
> s->dgram_dst = saddr;
>
> - snprintf(s->nc.info_str, sizeof(s->nc.info_str),
> - "socket: mcast=%s:%d",
> - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> + qemu_set_info_str(&s->nc, "socket: mcast=%s:%d",
> + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
> return 0;
>
> }
> @@ -697,9 +693,8 @@ static int net_socket_udp_init(NetClientState *peer,
>
> s->dgram_dst = raddr;
>
> - snprintf(s->nc.info_str, sizeof(s->nc.info_str),
> - "socket: udp=%s:%d",
> - inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port));
> + qemu_set_info_str(&s->nc, "socket: udp=%s:%d", inet_ntoa(raddr.sin_addr),
> + ntohs(raddr.sin_port));
> return 0;
> }
>
> diff --git a/net/tap-win32.c b/net/tap-win32.c
> index 7466f22e77a4..a49c28ba5dc5 100644
> --- a/net/tap-win32.c
> +++ b/net/tap-win32.c
> @@ -789,8 +789,7 @@ static int tap_win32_init(NetClientState *peer, const char *model,
>
> s = DO_UPCAST(TAPState, nc, nc);
>
> - snprintf(s->nc.info_str, sizeof(s->nc.info_str),
> - "tap: ifname=%s", ifname);
> + qemu_set_info_str(&s->nc, "tap: ifname=%s", ifname);
>
> s->handle = handle;
>
> diff --git a/net/tap.c b/net/tap.c
> index e203d07a1216..1210a0436de8 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -630,8 +630,7 @@ int net_init_bridge(const Netdev *netdev, const char *name,
> }
> s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr);
>
> - snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper,
> - br);
> + qemu_set_info_str(&s->nc, "helper=%s,br=%s", helper, br);
>
> return 0;
> }
> @@ -690,14 +689,12 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
> }
>
> if (tap->has_fd || tap->has_fds) {
> - snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);
> + qemu_set_info_str(&s->nc, "fd=%d", fd);
> } else if (tap->has_helper) {
> - snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s",
> - tap->helper);
> + qemu_set_info_str(&s->nc, "helper=%s", tap->helper);
> } else {
> - snprintf(s->nc.info_str, sizeof(s->nc.info_str),
> - "ifname=%s,script=%s,downscript=%s", ifname, script,
> - downscript);
> + qemu_set_info_str(&s->nc, "ifname=%s,script=%s,downscript=%s", ifname,
> + script, downscript);
>
> if (strcmp(downscript, "no") != 0) {
> snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
> diff --git a/net/vde.c b/net/vde.c
> index 1083916bcf52..c0a08662cc30 100644
> --- a/net/vde.c
> +++ b/net/vde.c
> @@ -98,8 +98,7 @@ static int net_vde_init(NetClientState *peer, const char *model,
>
> nc = qemu_new_net_client(&net_vde_info, peer, model, name);
>
> - snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d",
> - sock, vde_datafd(vde));
> + qemu_set_info_str(nc, "sock=%s,fd=%d", sock, vde_datafd(vde));
>
> s = DO_UPCAST(VDEState, nc, nc);
>
> diff --git a/net/vhost-user.c b/net/vhost-user.c
> index b1a0247b5981..3a6b90da8661 100644
> --- a/net/vhost-user.c
> +++ b/net/vhost-user.c
> @@ -341,8 +341,7 @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
> user = g_new0(struct VhostUserState, 1);
> for (i = 0; i < queues; i++) {
> nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name);
> - snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s",
> - i, chr->label);
> + qemu_set_info_str(nc, "vhost-user%d to %s", i, chr->label);
> nc->queue_index = i;
> if (!nc0) {
> nc0 = nc;
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 4bc3fd01a878..e1865bea6aa3 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -593,7 +593,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,
> nc = qemu_new_net_control_client(&net_vhost_vdpa_cvq_info, peer,
> device, name);
> }
> - snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA);
> + qemu_set_info_str(nc, TYPE_VHOST_VDPA);
> s = DO_UPCAST(VhostVDPAState, nc, nc);
>
> s->vhost_vdpa.device_fd = vdpa_device_fd;
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2022-10-06 8:48 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-05 16:20 [PATCH v10 00/17] qapi: net: add unix socket type support to netdev backend Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 01/17] net: introduce convert_host_port() Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 02/17] net: remove the @errp argument of net_client_inits() Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 03/17] net: simplify net_client_parse() error management Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 04/17] qapi: net: introduce a way to bypass qemu_opts_parse_noisily() Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 05/17] net: introduce qemu_set_info_str() function Laurent Vivier
2022-10-06 8:08 ` David Gibson [this message]
2022-10-05 16:20 ` [PATCH v10 06/17] qapi: net: add stream and dgram netdevs Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 07/17] net: socket: Don't ignore EINVAL on netdev socket connection Laurent Vivier
2022-10-06 8:13 ` David Gibson
2022-10-05 16:20 ` [PATCH v10 08/17] net: stream: " Laurent Vivier
2022-10-06 8:14 ` David Gibson
2022-10-05 16:20 ` [PATCH v10 09/17] net: stream: add unix socket Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 10/17] net: dgram: make dgram_dst generic Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 11/17] net: dgram: move mcast specific code from net_socket_fd_init_dgram() Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 12/17] net: dgram: add unix socket Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 13/17] qemu-sockets: move and rename SocketAddress_to_str() Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 14/17] qemu-sockets: update socket_uri() and socket_parse() to be consistent Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 15/17] net: stream: move to QIO to enable additional parameters Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 16/17] tests/qtest: netdev: test stream and dgram backends Laurent Vivier
2022-10-05 16:20 ` [PATCH v10 17/17] net: stream: add QAPI events to report connection state Laurent Vivier
2022-10-06 11:20 ` [PATCH v10 00/17] qapi: net: add unix socket type support to netdev backend Michael S. Tsirkin
2022-10-09 5:52 ` Jason Wang
2022-10-11 20:04 ` Laurent Vivier
2022-10-12 1:18 ` Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yz6M9Azhfa9RRYA2@yekko \
--to=david@gibson.dropbear.id.au \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=groug@kaod.org \
--cc=jasowang@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=samuel.thibault@ens-lyon.org \
--cc=sw@weilnetz.de \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.