IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an
email to Administrator. User accounts are meant only to access repo
and report issues and/or generate pull requests.
This is a purpose-specific Git hosting for
BaseALT
projects. Thank you for your understanding!
Только зарегистрированные пользователи имеют доступ к сервису!
Для получения аккаунта, обратитесь к администратору.
The actions to calculate values for the {Used,Free}Mem metrics relied on
output of the 'free' command that no longer exist. Fix the actions to
use the correct lines/fields from the output'.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Commit 27d6cbf362 introduced a buffer accounting bug when adding
the string ">\n" to a buffer, claming the string was 3 characters
long instead of 2. The commit also neglected to free the newly
introduced 'unit' variable.
Fixes: https://github.com/vhostmd/vhostmd/issues/14
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
I noticed the following warning building with gcc 13.2.1
libmetrics.c:283:7: warning: 'obj' may be used uninitialized [-Wmaybe-uninitialized]
283 | if (obj)
| ^
libmetrics.c: In function 'get_metric':
libmetrics.c:228:22: note: 'obj' was declared here
228 | xmlXPathObjectPtr obj;
| ^~~
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Errors raised in Fedora rawhide and ELN which have added the
-Werror=implicit-function-declaration flag for C:
virt-util.c:96:9: error: implicit declaration of function ‘calloc’
virt-util.c:129:10: error: implicit declaration of function ‘free’
virtio.c:160:9: error: implicit declaration of function ‘free’
virtio.c:254:31: error: implicit declaration of function ‘bsearch’
virtio.c:259:13: error: implicit declaration of function ‘qsort’
virtio.c:586:33: error: implicit declaration of function ‘calloc’
libmetrics.c:136:28: error: implicit declaration of function 'atoi'
libmetrics.c:142:29: error: implicit declaration of function 'atoll'
libmetrics.c:148:28: error: implicit declaration of function 'atof'
libmetrics.c:170:12: error: implicit declaration of function 'calloc'
libmetrics.c:189:12: error: implicit declaration of function 'free'
libmetrics.c:311:7: error: implicit declaration of function 'posix_memalign'
libmetrics.c:385:26: error: implicit declaration of function 'malloc'
libmetrics.c:848:28: error: implicit declaration of function 'realloc'
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
On a KVM host, the action to report VirtualizationVendor checks the
vendor of the libvirt RPM, which is typically a meta-package that pulls
in all of libvirt. This is undesirable on a minimalistic hypervisor.
Change the action to check the vendor of the package owning
/etc/os-release, which should be available on even the most minimal
systems and works for both Xen and KVM.
The VirtualizationProductInfo action reports inconsistent information
between Xen and KVM. On a Xen host the Xen version is reported, whereas
the libvirt version is reported on a KVM host. Change the action to
report the "Running hypervisor" as reported by 'virsh version'.
Fixes: https://github.com/vhostmd/vhostmd/issues/7
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Add an optional 'unit' attribute to the <metrics> element. The
value of 'unit' provided in a <metric> definition is opaque to vhostmd
and returned as is when reporting the metric value.
Fixes: https://github.com/vhostmd/vhostmd/issues/8
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Leave an extra byte for null-terminator in call to strncpy. From
coverity scan
vhostmd-1.1/vhostmd/virtio.c:194: buffer_size_warning: Calling "strncpy" with a maximum size argument of 108 bytes on destination array "address.sun_path" of size 108 bytes might leave the destination string unterminated.
192| address.sun_family = AF_LOCAL;
193|
194|-> strncpy(address.sun_path, c->uds_name, SUN_PATH_LEN);
195|
196| if ((c->fd = socket(AF_LOCAL, SOCK_STREAM, 0)) == -1)
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Example from coverity scan
vhostmd-1.1/vhostmd/vhostmd.c:940: alloc_arg: "vu_buffer_create" allocates memory that is stored into "buf".
vhostmd-1.1/vhostmd/vhostmd.c:959: leaked_storage: Variable "buf" going out of scope leaks the storage it points to.
957| vu_log(VHOSTMD_ERR, "Failed to start virtio thread '%s'\n",
958| strerror(rc));
959|-> return -1;
960| }
961| }
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
From coverity scan
vhostmd-1.1/vhostmd/vhostmd.c:778: var_tested_neg: Assigning: "fd" = a negative value.
vhostmd-1.1/vhostmd/vhostmd.c:845: negative_returns: "fd" is passed to a parameter that cannot be negative.
843| free(dir);
844| free(buf);
845|-> close(fd);
846| return -1;
847| }
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Check return value of ftruncate, lseek, and write functions as
reported by coverity. Example from coverity scan
vhostmd-1.1/vhostmd/vhostmd.c: scope_hint: In function 'metrics_disk_create'
vhostmd-1.1/vhostmd/vhostmd.c:821:4: warning: ignoring return value of 'ftruncate', declared with attribute warn_unused_result [-Wunused-result]
ftruncate(fd, mdisk_size);
^~~~~~~~~~~~~~~~~~~~~~~~~
819|
820| /* truncate to a possible new size */
821|-> ftruncate(fd, mdisk_size);
822|
823| /* zero fill metrics data */
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
From coverity scan
vhostmd-1.1/vhostmd/vhostmd.c:553: unsafe_xml_parse_config: XML parse option should not have flag "XML_PARSE_NOENT" set, which is vulnerable to XML external entty attack.
551|
552| xml = xmlCtxtReadFile(pctxt, filename, NULL,
553|-> XML_PARSE_NOENT | XML_PARSE_NONET |
554| XML_PARSE_NOWARNING);
555| if (!xml) {
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
From coverity scan
vhostmd-1.1/vhostmd/vhostmd.c:455: alloc_fn: Storage is returned from allocation function "xmlXPathEval".
vhostmd-1.1/vhostmd/vhostmd.c:455: var_assign: Assigning: "obj" = storage returned from "xmlXPathEval((xmlChar *)"//vhostmd/globals/transport", ctxt)".
vhostmd-1.1/vhostmd/vhostmd.c:474: leaked_storage: Variable "obj" going out of scope leaks the storage it points to.
472| #else
473| vu_log (VHOSTMD_ERR, "No support for xenstore transport in this vhostmd");
474|-> return -1;
475| #endif
476| }
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Example from coverity scan
vhostmd-1.1/vhostmd/util.c: scope_hint: In function 'vu_append_string'
vhostmd-1.1/vhostmd/util.c:484:7: warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result]
asprintf(&cp, "%s,%s", *dest, str);
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
From coverity scan
vhostmd-1.1/vhostmd/util.c:421: returned_null: "strstr" returns "NULL" (checked 6 out of 7 times).
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
From coverity scan
vhostmd-1.1/vhostmd/util.c:415:14: warning: Potential leak of memory pointed to by 'cp'
return(NULL);
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
From coverity scan
vhostmd-1.1/libmetrics/libmetrics.c:892: alloc_fn: Storage is returned from allocation function "fopen".
vhostmd-1.1/libmetrics/libmetrics.c:892: var_assign: Assigning: "fp" = storage returned from "fopen(dest_file, "w")".
vhostmd-1.1/libmetrics/libmetrics.c:900: noescape: Resource "fp" is not freed or pointed-to in "fwrite".
vhostmd-1.1/libmetrics/libmetrics.c:909: leaked_storage: Variable "fp" going out of scope leaks the storage it points to.
907| free(response);
908|
909|-> return 0;
910|
911| error:
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
From coverity scan
vhostmd-1.1/libmetrics/libmetrics.c:817: invalid_type: Argument "5L" to format specifier "%u" was expected to have type "unsigned int" but has type "long".
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
From coverity scan
vhostmd-1.1/libmetrics/libmetrics.c:613:18: warning: Potential leak of memory pointed to by 'pmdef.context'
errno = ENOMEM;
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
From coverity scan
Error: UNSAFE_XML_PARSE_CONFIG:
vhostmd-1.1/libmetrics/libmetrics.c:412: unsafe_xml_parse_config: XML parse option should not have flag "XML_PARSE_NOENT" set, which is vulnerable to XML external entity attack.
410| mdisk->doc = xmlCtxtReadMemory(mdisk->pctxt, mdisk->buffer,
411| mdisk->length, "mdisk.xml", NULL,
412|-> XML_PARSE_NOENT | XML_PARSE_NONET |
413| XML_PARSE_NOWARNING);
414| if (!mdisk->doc) {
It should be safe to remove the option.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Exmaple from coverity scan
vhostmd-1.1/libmetrics/libmetrics.c: scope_hint: In function 'get_mdef'
vhostmd-1.1/libmetrics/libmetrics.c:231:4: warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result]
asprintf(&xpath, "//metrics/metric[name='%s'][@context='%s']", pmdef->name, pmdef->context);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
The get_mdef() and dump_xenstore_metrics() functions have local variables
named 'ret' that are initialized to zero, meaning success. In failure paths
'ret' is set to -1 before jumping to the 'out' label. Invert this logic by
initializing 'ret' to -1 and only setting it to success after the function
bodies have successfully executed.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
From a coverity scan
vhostmd-1.1/libmetrics/libmetrics.c:185:10: warning: Attempt to free released memory
free(mdisk->buffer);
Some error conditions will call mdisk_content_free(), which could result
in a double-free when the entire mdisk is freed and mdisk_content_free()
is called again. Protect agains these potential double-frees by setting
the mdisk contents NULL after freeing them.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
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>
A timeout in the send request part of dump_virtio_metrics()
should prevent the send from looping forever. Also change the
existing 30 second timeout value to a more reasonable value of
5 seconds.
We can't rely on d_type == DT_DIR because on some filesystems
d_type is not supported. A check for domain-ID-NAME/org.github.vhostmd.1
should be sufficient.
The README already states that all correspondence for vhostmd
should take place on the virt-tools-list. Change the bug-report
email in AC_INIT to match.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
At the vhostmd side virtio channels are Unix domain sockets from QEMU
which are created during a VM start and removed when the VM is stopped.
Basically this implementation
- monitors a directory for new virtio channels
- for valid IDs, also known by libvirtd, it connects to the UDS
- buffers VM/HOST metrics and handles request/response on the sockets
It provides the functions
virtio_init()
init function of virtio layer
virtio_run()
the start_routine for the virtio-thread to handle the virtio based
communication
virtio_metrics_update()
called for each VM/HOST metrics update to update the virtio internal
metrics buffer.
virtio_stop()
stop the virtio-thread
Vhostmd uses the update_interval value to sleep() between the metrics updates.
But a long runtime of the metrics updates can result in a noticeable longer
time between the updates and a consumer might read 'old' data after waiting
update_interval seconds.
Fix the delay between updates, that
'runtime of metrics update' + 'sleep time' matches the update_interval value.
buffer_grow uses realloc to extend the buffer, due to the fact that
realloc doesn't guarantee that allocated memory is initialized there
should be a memset.
The use of WITH_XENSTORE in vm-dump-metrics is clumbsy in some
cases and flat out wrong in others. E.g. if WITH_XENSTORE is not
defined then vbd transport is excluded as an option for retrieving
the metrics. Improve use of WITH_XENSTORE and fix the broken logic.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
The formatting in the usage function of vm-dump-metrics used a
lot of spaces for whitespace. Replace some occurrences with tabs
and remove others that were causing ugly formatting of help.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Although the upstream vhostmd config file serves primarily as an
example, it should at least work and not unconditionally call
commands that no longer exist.
While at it, improve the comments describing the <action> element.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
The logic introduced in commit d1276646to check for init script type is
a bit flawed. If the init script type is specified, init_systemv is
always set to 'yes', even when '--with-init-script=systemd'. Split the
logic to only check for init script type when '--with-init-script=check'.
Signed-off-by: Jim Fehlig <jfehlig@suse.com>