git: 6cb261620da3 - main - bhyve: Use designated initializers for virtio_consts tables

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Thu, 29 Sep 2022 16:37:44 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=6cb261620da3a9888f7a09244a8efe691c12ae47

commit 6cb261620da3a9888f7a09244a8efe691c12ae47
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-09-29 15:53:04 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-09-29 16:36:44 +0000

    bhyve: Use designated initializers for virtio_consts tables
    
    This is easier to read and addresses some compiler warnings.
    
    One might expect these tables to be read-only but it seems that the
    snapshot/restore code may modify them.
    
    MFC after:      2 weeks
---
 usr.sbin/bhyve/pci_virtio_9p.c      | 18 ++++++++----------
 usr.sbin/bhyve/pci_virtio_block.c   | 24 ++++++++++++------------
 usr.sbin/bhyve/pci_virtio_console.c | 18 ++++++++----------
 usr.sbin/bhyve/pci_virtio_input.c   | 16 +++++++---------
 usr.sbin/bhyve/pci_virtio_net.c     | 23 +++++++++++------------
 usr.sbin/bhyve/pci_virtio_rnd.c     | 16 ++++++----------
 usr.sbin/bhyve/pci_virtio_scsi.c    | 17 ++++++++---------
 7 files changed, 60 insertions(+), 72 deletions(-)

diff --git a/usr.sbin/bhyve/pci_virtio_9p.c b/usr.sbin/bhyve/pci_virtio_9p.c
index c741f0f94d9f..1ed0eba6a8ed 100644
--- a/usr.sbin/bhyve/pci_virtio_9p.c
+++ b/usr.sbin/bhyve/pci_virtio_9p.c
@@ -105,18 +105,16 @@ static int pci_vt9p_cfgread(void *, int, int, uint32_t *);
 static void pci_vt9p_neg_features(void *, uint64_t);
 
 static struct virtio_consts vt9p_vi_consts = {
-	"vt9p",			/* our name */
-	1,			/* we support 1 virtqueue */
-	VT9P_CONFIGSPACESZ,	/* config reg size */
-	pci_vt9p_reset,		/* reset */
-	pci_vt9p_notify,	/* device-wide qnotify */
-	pci_vt9p_cfgread,	/* read virtio config */
-	NULL,			/* write virtio config */
-	pci_vt9p_neg_features,	/* apply negotiated features */
-	(1 << 0),		/* our capabilities */
+	.vc_name =	"vt9p",
+	.vc_nvq =	1,
+	.vc_cfgsize =	VT9P_CONFIGSPACESZ,
+	.vc_reset =	pci_vt9p_reset,
+	.vc_qnotify =	pci_vt9p_notify,
+	.vc_cfgread =	pci_vt9p_cfgread,
+	.vc_apply_features = pci_vt9p_neg_features,
+	.vc_hv_caps =	(1 << 0),
 };
 
-
 static void
 pci_vt9p_reset(void *vsc)
 {
diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c
index 1459f0e6c02d..8cdcbb777691 100644
--- a/usr.sbin/bhyve/pci_virtio_block.c
+++ b/usr.sbin/bhyve/pci_virtio_block.c
@@ -208,19 +208,19 @@ static int pci_vtblk_snapshot(void *, struct vm_snapshot_meta *);
 #endif
 
 static struct virtio_consts vtblk_vi_consts = {
-	"vtblk",		/* our name */
-	1,			/* we support 1 virtqueue */
-	sizeof(struct vtblk_config),	/* config reg size */
-	pci_vtblk_reset,	/* reset */
-	pci_vtblk_notify,	/* device-wide qnotify */
-	pci_vtblk_cfgread,	/* read PCI config */
-	pci_vtblk_cfgwrite,	/* write PCI config */
-	NULL,			/* apply negotiated features */
-	VTBLK_S_HOSTCAPS,	/* our capabilities */
+	.vc_name =	"vtblk",
+	.vc_nvq =	1,
+	.vc_cfgsize =	sizeof(struct vtblk_config),
+	.vc_reset =	pci_vtblk_reset,
+	.vc_qnotify =	pci_vtblk_notify,
+	.vc_cfgread =	pci_vtblk_cfgread,
+	.vc_cfgwrite =	pci_vtblk_cfgwrite,
+	.vc_apply_features = NULL,
+	.vc_hv_caps =	VTBLK_S_HOSTCAPS,
 #ifdef BHYVE_SNAPSHOT
-	pci_vtblk_pause,	/* pause blockif threads */
-	pci_vtblk_resume,	/* resume blockif threads */
-	pci_vtblk_snapshot,	/* save / restore device state */
+	.vc_pause =	pci_vtblk_pause,
+	.vc_resume =	pci_vtblk_resume,
+	.vc_snapshot =	pci_vtblk_snapshot,
 #endif
 };
 
diff --git a/usr.sbin/bhyve/pci_virtio_console.c b/usr.sbin/bhyve/pci_virtio_console.c
index 341f0857bade..663ead8d165e 100644
--- a/usr.sbin/bhyve/pci_virtio_console.c
+++ b/usr.sbin/bhyve/pci_virtio_console.c
@@ -169,18 +169,16 @@ static void pci_vtcon_announce_port(struct pci_vtcon_port *);
 static void pci_vtcon_open_port(struct pci_vtcon_port *, bool);
 
 static struct virtio_consts vtcon_vi_consts = {
-	"vtcon",		/* our name */
-	VTCON_MAXQ,		/* we support VTCON_MAXQ virtqueues */
-	sizeof(struct pci_vtcon_config), /* config reg size */
-	pci_vtcon_reset,	/* reset */
-	NULL,			/* device-wide qnotify */
-	pci_vtcon_cfgread,	/* read virtio config */
-	pci_vtcon_cfgwrite,	/* write virtio config */
-	pci_vtcon_neg_features,	/* apply negotiated features */
-	VTCON_S_HOSTCAPS,	/* our capabilities */
+	.vc_name =	"vtcon",
+	.vc_nvq =	VTCON_MAXQ,
+	.vc_cfgsize =	sizeof(struct pci_vtcon_config),
+	.vc_reset =	pci_vtcon_reset,
+	.vc_cfgread =	pci_vtcon_cfgread,
+	.vc_cfgwrite =	pci_vtcon_cfgwrite,
+	.vc_apply_features = pci_vtcon_neg_features,
+	.vc_hv_caps =	VTCON_S_HOSTCAPS,
 };
 
-
 static void
 pci_vtcon_reset(void *vsc)
 {
diff --git a/usr.sbin/bhyve/pci_virtio_input.c b/usr.sbin/bhyve/pci_virtio_input.c
index 404213d907e7..e3d5264b8b22 100644
--- a/usr.sbin/bhyve/pci_virtio_input.c
+++ b/usr.sbin/bhyve/pci_virtio_input.c
@@ -159,15 +159,13 @@ static int pci_vtinput_cfgread(void *, int, int, uint32_t *);
 static int pci_vtinput_cfgwrite(void *, int, int, uint32_t);
 
 static struct virtio_consts vtinput_vi_consts = {
-	"vtinput",		       /* our name */
-	VTINPUT_MAXQ,		       /* we support 1 virtqueue */
-	sizeof(struct vtinput_config), /* config reg size */
-	pci_vtinput_reset,	       /* reset */
-	NULL,			       /* device-wide qnotify -- not used */
-	pci_vtinput_cfgread,	       /* read virtio config */
-	pci_vtinput_cfgwrite,	       /* write virtio config */
-	NULL,			       /* apply negotiated features */
-	0,			       /* our capabilities */
+	.vc_name =	"vtinput",
+	.vc_nvq =	VTINPUT_MAXQ,
+	.vc_cfgsize =	sizeof(struct vtinput_config),
+	.vc_reset =	pci_vtinput_reset,
+	.vc_cfgread =	pci_vtinput_cfgread,
+	.vc_cfgwrite =	pci_vtinput_cfgwrite,
+	.vc_hv_caps =	0,
 };
 
 static void
diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c
index a0c7e2c585b4..068a3f267b09 100644
--- a/usr.sbin/bhyve/pci_virtio_net.c
+++ b/usr.sbin/bhyve/pci_virtio_net.c
@@ -145,19 +145,18 @@ static int pci_vtnet_snapshot(void *, struct vm_snapshot_meta *);
 #endif
 
 static struct virtio_consts vtnet_vi_consts = {
-	"vtnet",		/* our name */
-	VTNET_MAXQ - 1,		/* we currently support 2 virtqueues */
-	sizeof(struct virtio_net_config), /* config reg size */
-	pci_vtnet_reset,	/* reset */
-	NULL,			/* device-wide qnotify -- not used */
-	pci_vtnet_cfgread,	/* read PCI config */
-	pci_vtnet_cfgwrite,	/* write PCI config */
-	pci_vtnet_neg_features,	/* apply negotiated features */
-	VTNET_S_HOSTCAPS,	/* our capabilities */
+	.vc_name =	"vtnet",
+	.vc_nvq =	VTNET_MAXQ - 1,
+	.vc_cfgsize =	sizeof(struct virtio_net_config),
+	.vc_reset =	pci_vtnet_reset,
+	.vc_cfgread =	pci_vtnet_cfgread,
+	.vc_cfgwrite =	pci_vtnet_cfgwrite,
+	.vc_apply_features = pci_vtnet_neg_features,
+	.vc_hv_caps =	VTNET_S_HOSTCAPS,
 #ifdef BHYVE_SNAPSHOT
-	pci_vtnet_pause,	/* pause rx/tx threads */
-	pci_vtnet_resume,	/* resume rx/tx threads */
-	pci_vtnet_snapshot,	/* save / restore device state */
+	.vc_pause =	pci_vtnet_pause,
+	.vc_resume =	pci_vtnet_resume,
+	.vc_snapshot =	pci_vtnet_snapshot,
 #endif
 };
 
diff --git a/usr.sbin/bhyve/pci_virtio_rnd.c b/usr.sbin/bhyve/pci_virtio_rnd.c
index db8dc143e0b2..4049494177f9 100644
--- a/usr.sbin/bhyve/pci_virtio_rnd.c
+++ b/usr.sbin/bhyve/pci_virtio_rnd.c
@@ -84,18 +84,14 @@ static void pci_vtrnd_reset(void *);
 static void pci_vtrnd_notify(void *, struct vqueue_info *);
 
 static struct virtio_consts vtrnd_vi_consts = {
-	"vtrnd",		/* our name */
-	1,			/* we support 1 virtqueue */
-	0,			/* config reg size */
-	pci_vtrnd_reset,	/* reset */
-	pci_vtrnd_notify,	/* device-wide qnotify */
-	NULL,			/* read virtio config */
-	NULL,			/* write virtio config */
-	NULL,			/* apply negotiated features */
-	0,			/* our capabilities */
+	.vc_name =	"vtrnd",
+	.vc_nvq =	1,
+	.vc_cfgsize =	0,
+	.vc_reset =	pci_vtrnd_reset,
+	.vc_qnotify =	pci_vtrnd_notify,
+	.vc_hv_caps =	0,
 };
 
-
 static void
 pci_vtrnd_reset(void *vsc)
 {
diff --git a/usr.sbin/bhyve/pci_virtio_scsi.c b/usr.sbin/bhyve/pci_virtio_scsi.c
index b50b6e9fd047..235f96eca233 100644
--- a/usr.sbin/bhyve/pci_virtio_scsi.c
+++ b/usr.sbin/bhyve/pci_virtio_scsi.c
@@ -248,15 +248,14 @@ static int  pci_vtscsi_init_queue(struct pci_vtscsi_softc *,
 static int pci_vtscsi_init(struct vmctx *, struct pci_devinst *, nvlist_t *);
 
 static struct virtio_consts vtscsi_vi_consts = {
-	"vtscsi",				/* our name */
-	VTSCSI_MAXQ,				/* we support 2+n virtqueues */
-	sizeof(struct pci_vtscsi_config),	/* config reg size */
-	pci_vtscsi_reset,			/* reset */
-	NULL,					/* device-wide qnotify */
-	pci_vtscsi_cfgread,			/* read virtio config */
-	pci_vtscsi_cfgwrite,			/* write virtio config */
-	pci_vtscsi_neg_features,		/* apply negotiated features */
-	0,					/* our capabilities */
+	.vc_name =	"vtscsi",
+	.vc_nvq =	VTSCSI_MAXQ,
+	.vc_cfgsize =	sizeof(struct pci_vtscsi_config),
+	.vc_reset =	pci_vtscsi_reset,
+	.vc_cfgread =	pci_vtscsi_cfgread,
+	.vc_cfgwrite =	pci_vtscsi_cfgwrite,
+	.vc_apply_features = pci_vtscsi_neg_features,
+	.vc_hv_caps =	0,
 };
 
 static void *