Sync from SUSE:SLFO:Main vhostmd revision 8f6ad46e635f9addc71cd1964c71f605

This commit is contained in:
Adrian Schröter 2024-10-11 10:10:45 +02:00
parent de8d2a9d04
commit 0eca4e900d
14 changed files with 334 additions and 59 deletions

View File

@ -0,0 +1,82 @@
From 176fcda44caca807b4bec9fd613991afd9d5a70b Mon Sep 17 00:00:00 2001
From: Jim Fehlig <jfehlig@suse.com>
Date: Fri, 27 Sep 2024 10:48:41 -0600
Subject: [PATCH 2/3] Support libvirt's new channel path naming scheme
libvirt commit 8abc979bb0 changed the channel path naming scheme from
domain-<id>-<name> to <id>-<name>. Change the logic searching for channels
to work with either scheme.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
vhostmd/virtio.c | 49 +++++++++++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 23 deletions(-)
diff --git a/vhostmd/virtio.c b/vhostmd/virtio.c
index d2d07bf..4516b1f 100644
--- a/vhostmd/virtio.c
+++ b/vhostmd/virtio.c
@@ -277,34 +277,37 @@ static int vio_readdir(const char * path)
}
while ((ent = readdir(dir)) != NULL) {
- int rc, id;
+ char tmp[SUN_PATH_LEN + 8];
+ struct stat st;
+ char *name = NULL;
+ int id = -1;
+ int rc;
+ channel_t *c = NULL;
- if (sscanf(ent->d_name, "domain-%d-", &id) == 1) {
+ if (sscanf(ent->d_name, "domain-%d-", &id) == 1)
+ name = strchr(&(ent->d_name[strlen("domain-")]), '-');
+ else if (sscanf(ent->d_name, "%d-", &id) == 1)
+ name = strchr(ent->d_name, '-');
+ else
+ continue;
- char tmp[SUN_PATH_LEN + 8];
- struct stat st;
+ rc = snprintf(tmp, sizeof(tmp), "%s/%s/%s", path, ent->d_name, channel_name);
- rc = snprintf(tmp, sizeof(tmp), "%s/%s/%s", path, ent->d_name, channel_name);
+ if (rc > 0 && rc < (int) sizeof(tmp) &&
+ strlen(tmp) < SUN_PATH_LEN &&
+ stat(tmp, &st) == 0 &&
+ S_ISSOCK(st.st_mode)) {
- if (rc > 0 && rc < (int) sizeof(tmp) &&
- strlen(tmp) < SUN_PATH_LEN &&
- stat(tmp, &st) == 0 &&
- S_ISSOCK(st.st_mode)) {
+ pthread_mutex_lock(&channel_mtx);
+ c = vio_channel_find(id, name, 0);
+ pthread_mutex_unlock(&channel_mtx);
- channel_t *c = NULL;
- const char *name = strchr(&(ent->d_name[strlen("domain-")]), '-');
-
- pthread_mutex_lock(&channel_mtx);
- c = vio_channel_find(id, name, 0);
- pthread_mutex_unlock(&channel_mtx);
-
- if (c && c->fd == FREE) {
- c->uds_name = strdup(tmp);
- if (c->uds_name == NULL)
- goto error;
- if (vio_channel_open(c))
- goto error;
- }
+ if (c && c->fd == FREE) {
+ c->uds_name = strdup(tmp);
+ if (c->uds_name == NULL)
+ goto error;
+ if (vio_channel_open(c))
+ goto error;
}
}
}
--
2.35.3

View File

@ -0,0 +1,148 @@
From 5a04b59495490bf921c661ff95754ea9955e7cd4 Mon Sep 17 00:00:00 2001
From: Jim Fehlig <jfehlig@suse.com>
Date: Fri, 27 Sep 2024 09:20:52 -0600
Subject: [PATCH 1/3] Add channel_path setting to daemon config file
libvirt commit 8abc979b moved the target path for channel devices.
To accommodate libvirt deployments with and without that commit,
allow specifying the path in the daemon configuration file.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
README | 3 +++
include/virtio.h | 2 +-
vhostmd.dtd | 3 ++-
vhostmd.xml | 1 +
vhostmd/vhostmd.c | 12 ++++++++++--
vhostmd/virtio.c | 5 +++--
6 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/README b/README
index 579acd5..2ff7e8b 100644
--- a/README
+++ b/README
@@ -51,6 +51,7 @@ includes a few examples of user-defined metrics, which provide a
<size unit="k">256</size>
</disk>
<virtio>
+ <channel_path>/var/run/libvirt/qemu/channel</channel_path>
<max_channels>1024</max_channels>
<expiration_time>15</expiration_time>
</virtio>
@@ -300,6 +301,8 @@ between the host and VMs. Basically for a virtio serial device, QEMU creates
- 'connects' both to a 'communication channel'
It can be configured in the virtio section of the vhostmd configuration file.
+<channel_path> defines a path on the host where QEMU creates the unix domain
+sockets.
<max_channels> defines the maximum number of virtio channels/VMs supported
by the vhostmd instance with a default value of 1024.
<expiration_time> is the time after which the virtio serial channel of a VM
diff --git a/include/virtio.h b/include/virtio.h
index 1ff31a2..962adea 100644
--- a/include/virtio.h
+++ b/include/virtio.h
@@ -24,7 +24,7 @@
/*
* Initialize virtio layer
*/
-int virtio_init(int max_channel, int expiration_period);
+int virtio_init(char *channel_path, int max_channel, int expiration_period);
/*
* Main virtio function
diff --git a/vhostmd.dtd b/vhostmd.dtd
index 6c159dd..045860d 100644
--- a/vhostmd.dtd
+++ b/vhostmd.dtd
@@ -20,7 +20,8 @@ Virtual Host Metrics Daemon (vhostmd). Configuration file DTD
<!ELEMENT update_period (#PCDATA)>
<!ELEMENT transport (#PCDATA)>
-<!ELEMENT virtio (max_channels,expiration_time)>
+<!ELEMENT virtio (channel_path,max_channels,expiration_time)>
+<!ELEMENT channel_path (#PCDATA)>
<!ELEMENT max_channels (#PCDATA)>
<!ELEMENT expiration_time (#PCDATA)>
diff --git a/vhostmd.xml b/vhostmd.xml
index 5c88d8c..0dff85d 100644
--- a/vhostmd.xml
+++ b/vhostmd.xml
@@ -34,6 +34,7 @@ the logical && operator must be replaced with "&amp;&amp;".
<size unit="k">256</size>
</disk>
<virtio>
+ <channel_path>/var/run/libvirt/qemu/channel</channel_path>
<max_channels>1024</max_channels>
<expiration_time>15</expiration_time>
</virtio>
diff --git a/vhostmd/vhostmd.c b/vhostmd/vhostmd.c
index 4426faf..88e89ac 100644
--- a/vhostmd/vhostmd.c
+++ b/vhostmd/vhostmd.c
@@ -105,6 +105,7 @@ static mdisk_header md_header =
};
static char *search_path = NULL;
static int transports = 0;
+static char *virtio_channel_path = NULL;
static int virtio_max_channels = 1024;
static int virtio_expiration_time = 15;
@@ -623,7 +624,14 @@ static int parse_config_file(const char *filename)
}
if (transports & VIRTIO) {
- if (vu_xpath_long("string(./globals/virtio/max_channels[1])", ctxt, &l) == 0)
+ virtio_channel_path = vu_xpath_string("string(./globals/virtio/channel_path[1])", ctxt);
+ if (virtio_channel_path == NULL) {
+ virtio_channel_path = strdup("/var/lib/libvirt/qemu/channel/target");
+ if (virtio_channel_path == NULL)
+ goto out;
+ }
+
+ if (vu_xpath_long("string(./globals/virtio/max_channels[1])", ctxt, &l) == 0)
virtio_max_channels = (int)l;
if (vu_xpath_long("string(./globals/virtio/expiration_time[1])", ctxt, &l) == 0)
@@ -980,7 +988,7 @@ static int vhostmd_run(int diskfd)
if (virtio_expiration_time < (update_period * 3))
virtio_expiration_time = update_period * 3;
- if (virtio_init(virtio_max_channels, virtio_expiration_time)) {
+ if (virtio_init(virtio_channel_path, virtio_max_channels, virtio_expiration_time)) {
vu_buffer_delete(buf);
return -1;
}
diff --git a/vhostmd/virtio.c b/vhostmd/virtio.c
index 98340ce..d2d07bf 100644
--- a/vhostmd/virtio.c
+++ b/vhostmd/virtio.c
@@ -68,7 +68,7 @@ static channel_t *channel = NULL;
static id_map_t *id_map = NULL;
static time_t exp_period = 0;
-static const char *channel_path = "/var/lib/libvirt/qemu/channel/target";
+static const char *channel_path = NULL;
static const char *channel_name = "org.github.vhostmd.1";
static int channel_max = 0;
static volatile int channel_count = 0;
@@ -572,13 +572,14 @@ static void vio_handle_io(unsigned epoll_wait_ms)
* Once the channel is added to epoll the vu_buffer can be accessed
* by the epoll_event.data.ptr.
*/
-int virtio_init(int _max_channel, int _expiration_period)
+int virtio_init(char *_channel_path, int _max_channel, int _expiration_period)
{
int i;
if (virtio_status == VIRTIO_INIT) {
pthread_mutex_init(&channel_mtx, NULL);
+ channel_path = _channel_path;
channel_max = _max_channel;
exp_period = _expiration_period;
channel_count = 0;
--
2.35.3

View File

@ -0,0 +1,37 @@
From 9d282891eaaeebf1b94c67314d97e55a0b58d9c2 Mon Sep 17 00:00:00 2001
From: Jim Fehlig <jfehlig@suse.com>
Date: Fri, 27 Sep 2024 13:25:58 -0600
Subject: [PATCH 3/3] Fix parsing of vmstat output
The output of `vmstat -s`, which is used to calculate the Paged{In,Out}Memory
metrics, changed from "pages paged {in,out}" to "K paged {in,out}" in procps4.
Change the associated actions to match against the new output.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
vhostmd.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/vhostmd.xml b/vhostmd.xml
index 0dff85d..c957d1d 100644
--- a/vhostmd.xml
+++ b/vhostmd.xml
@@ -98,13 +98,13 @@ the logical && operator must be replaced with "&amp;&amp;".
<metric type="uint64" context="host">
<name>PagedInMemory</name>
<action>
- vmstat -s | awk '/pages paged in/ {printf "%d\n", $1 / 1024 * $(getconf PAGESIZE) / 1024;}'
+ vmstat -s | awk '/K paged in/ {printf "%d\n", $1;}'
</action>
</metric>
<metric type="uint64" context="host">
<name>PagedOutMemory</name>
<action>
- vmstat -s | awk '/pages paged out/ {printf "%d\n", $1 / 1024 * $(getconf PAGESIZE) / 1024;}'
+ vmstat -s | awk '/K paged out/ {printf "%d\n", $1;}'
</action>
</metric>
<metric type="group" context="host">
--
2.35.3

17
_service Normal file
View File

@ -0,0 +1,17 @@
<services>
<service name="tar_scm" mode="manual">
<param name="filename">vhostmd</param>
<param name="revision">v1.2</param>
<param name="scm">git</param>
<param name="submodules">disable</param>
<param name="url">https://github.com/vhostmd/vhostmd.git</param>
<param name="versionformat">@PARENT_TAG@</param>
<param name="versionrewrite-pattern">[v]?([^\+]+)(.*)</param>
<param name="versionrewrite-replacement">\1</param>
</service>
<service name="recompress" mode="manual">
<param name="file">*.tar</param>
<param name="compression">bz2</param>
</service>
<service name="set_version" mode="manual"/>
</services>

View File

@ -1,7 +1,7 @@
Index: vhostmd-1.1/vhostmd.service Index: vhostmd-1.2/vhostmd.service
=================================================================== ===================================================================
--- vhostmd-1.1.orig/vhostmd.service --- vhostmd-1.2.orig/vhostmd.service
+++ vhostmd-1.1/vhostmd.service +++ vhostmd-1.2/vhostmd.service
@@ -4,6 +4,17 @@ After=libvirtd.service @@ -4,6 +4,17 @@ After=libvirtd.service
Documentation=man:vhostmd(8) Documentation=man:vhostmd(8)

View File

@ -2,10 +2,10 @@ link libmetrics with libxml
libmetrics uses libxml, so link with it. libmetrics uses libxml, so link with it.
Index: vhostmd-1.1/libmetrics/Makefile.am Index: vhostmd-1.2/libmetrics/Makefile.am
=================================================================== ===================================================================
--- vhostmd-1.1.orig/libmetrics/Makefile.am --- vhostmd-1.2.orig/libmetrics/Makefile.am
+++ vhostmd-1.1/libmetrics/Makefile.am +++ vhostmd-1.2/libmetrics/Makefile.am
@@ -19,3 +19,5 @@ libmetrics_la_SOURCES = \ @@ -19,3 +19,5 @@ libmetrics_la_SOURCES = \
libmetrics_la_DEPENDENCIES = \ libmetrics_la_DEPENDENCIES = \

View File

@ -1,7 +1,7 @@
Index: vhostmd-1.1/docs/man/vm-dump-metrics.1 Index: vhostmd-1.2/docs/man/vm-dump-metrics.1
=================================================================== ===================================================================
--- vhostmd-1.1.orig/docs/man/vm-dump-metrics.1 --- vhostmd-1.2.orig/docs/man/vm-dump-metrics.1
+++ vhostmd-1.1/docs/man/vm-dump-metrics.1 +++ vhostmd-1.2/docs/man/vm-dump-metrics.1
@@ -10,8 +10,12 @@ vm-dump-metrics \- Dump VM metrics. @@ -10,8 +10,12 @@ vm-dump-metrics \- Dump VM metrics.
.BR vm-dump-metrics .BR vm-dump-metrics
reads virtualization hosts provided metrics decription and dumps output reads virtualization hosts provided metrics decription and dumps output

View File

@ -1,37 +0,0 @@
commit 83cc269f6892852be94467cea771b3ad1da8a369
Author: Jim Fehlig <jfehlig@suse.com>
Date: Tue Oct 8 20:56:18 2019 -0600
Relax virtio requirement in config file
When the virtio transport was introduced the schema was changed to
require a <virtio> transport in vhostmd.conf. When updating existing
deployments without a virtio transport specified in vhostmd.conf,
vhostmd fails to start
/usr/sbin/vhostmd -d
/etc/vhostmd/vhostmd.conf:41: element globals: validity error : Element
globals content does not follow the DTD, expecting (disk , virtio ,
update_period , path , transport+), got (disk update_period path transport )
validate_config_file(): Failed to validate :/etc/vhostmd/vhostmd.conf
Config file: /etc/vhostmd/vhostmd.conf, fails DTD validation
Relax the requirement for virtio transport in the schema. With the
introduction of multiple transports perhaps the others shoud be optional
as well, but requiring virtio is clearly a regression.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Index: vhostmd-1.1/vhostmd.dtd
===================================================================
--- vhostmd-1.1.orig/vhostmd.dtd
+++ vhostmd-1.1/vhostmd.dtd
@@ -9,7 +9,7 @@ Virtual Host Metrics Daemon (vhostmd). C
-->
<!ELEMENT vhostmd (globals,metrics)>
-<!ELEMENT globals (disk,virtio,update_period,path,transport+)>
+<!ELEMENT globals (disk,virtio*,update_period,path,transport+)>
<!ELEMENT disk (name,path,size)>
<!ELEMENT name (#PCDATA)>

View File

@ -1,7 +1,7 @@
Index: vhostmd-1.1/vhostmd/metric.c Index: vhostmd-1.2/vhostmd/metric.c
=================================================================== ===================================================================
--- vhostmd-1.1.orig/vhostmd/metric.c --- vhostmd-1.2.orig/vhostmd/metric.c
+++ vhostmd-1.1/vhostmd/metric.c +++ vhostmd-1.2/vhostmd/metric.c
@@ -280,6 +280,12 @@ int metric_value_get(metric *m) @@ -280,6 +280,12 @@ int metric_value_get(metric *m)
goto out; goto out;

BIN
vhostmd-1.1.tar.bz2 (Stored with Git LFS)

Binary file not shown.

BIN
vhostmd-1.2.tar.bz2 (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -5,10 +5,10 @@ one transport - vbd. Comment the recently added virtio transport.
Users can uncomment it and restart vhostmd if virtio transport is Users can uncomment it and restart vhostmd if virtio transport is
desired, similar to the xenstore transport. desired, similar to the xenstore transport.
Index: vhostmd-1.1/vhostmd.xml Index: vhostmd-1.2/vhostmd.xml
=================================================================== ===================================================================
--- vhostmd-1.1.orig/vhostmd.xml --- vhostmd-1.2.orig/vhostmd.xml
+++ vhostmd-1.1/vhostmd.xml +++ vhostmd-1.2/vhostmd.xml
@@ -40,7 +40,7 @@ the logical && operator must be replaced @@ -40,7 +40,7 @@ the logical && operator must be replaced
<update_period>5</update_period> <update_period>5</update_period>
<path>/usr/sbin:/sbin:/usr/bin:/bin:/usr/share/vhostmd/scripts</path> <path>/usr/sbin:/sbin:/usr/bin:/bin:/usr/share/vhostmd/scripts</path>

View File

@ -1,3 +1,29 @@
-------------------------------------------------------------------
Tue Oct 1 17:55:04 UTC 2024 - James Fehlig <jfehlig@suse.com>
- Fix virtio transport to work with libvirt >= 9.7.0
Added patches:
5a04b594-Add-channel_path-setting.patch,
176fcda4-Support-new-channel-path-naming.patch,
9d282891-Fix-parsing-of-vmstat-output.patch
bsc#1230961
-------------------------------------------------------------------
Fri Sep 20 18:10:53 UTC 2024 - James Fehlig <jfehlig@suse.com>
- Update to version 1.2
- Fix actions using the 'free' command
- Fix buffer accounting when generating metric XML
- Fix warning with gcc >= 13
- Fix implicit declarations
- Change actions to retrieve vendor and product info
- Add a 'unit' attribute to the metrics element
- vif-stats.py: convert to Python3
- Misc coverity fixes
- Relax virtio requirement in config file
- Drop relax-virtio-config-requirement.patch
- Add service file
------------------------------------------------------------------- -------------------------------------------------------------------
Tue Feb 20 13:25:13 UTC 2024 - Dominique Leuenberger <dimstar@opensuse.org> Tue Feb 20 13:25:13 UTC 2024 - Dominique Leuenberger <dimstar@opensuse.org>

View File

@ -1,7 +1,7 @@
# #
# spec file for package vhostmd # spec file for package vhostmd
# #
# Copyright (c) 2022 SUSE LLC # Copyright (c) 2024 SUSE LLC
# #
# All modifications and additions to the file contributed by third parties # All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed # remain the property of their copyright owners, unless otherwise agreed
@ -24,7 +24,7 @@
%endif %endif
Name: vhostmd Name: vhostmd
Version: 1.1 Version: 1.2
Release: 0 Release: 0
Summary: Virtual Host Metrics Daemon (vhostmd) Summary: Virtual Host Metrics Daemon (vhostmd)
License: LGPL-2.1-or-later License: LGPL-2.1-or-later
@ -36,8 +36,10 @@ Patch0: vhostmd-conf.patch
Patch1: manpage.patch Patch1: manpage.patch
Patch2: value-newline.patch Patch2: value-newline.patch
Patch3: libmetrics-link.patch Patch3: libmetrics-link.patch
Patch4: relax-virtio-config-requirement.patch Patch4: harden_vhostmd.service.patch
Patch5: harden_vhostmd.service.patch Patch5: 5a04b594-Add-channel_path-setting.patch
Patch6: 176fcda4-Support-new-channel-path-naming.patch
Patch7: 9d282891-Fix-parsing-of-vmstat-output.patch
BuildRequires: libtool BuildRequires: libtool
BuildRequires: libvirt-devel BuildRequires: libvirt-devel
BuildRequires: libxml2 BuildRequires: libxml2