100 Commits

Author SHA1 Message Date
7776c38a09 1.1-alt2
- use rpm macros for install systemd unit.
1.1-alt2 gb-p11-task356646.12100 gb-sisyphus-task351483.100
2024-06-24 20:09:20 +03:00
791990e4c6 Merge remote-tracking branch 'upstream/master' 2024-06-24 20:09:07 +03:00
5adec3e804 Revert "Fix path to systemd units"
This reverts commit 8a220aa565d9628a9125ed0929045062d0521792.
2024-06-24 20:03:43 +03:00
Jim Fehlig
f74a9bb2d3 Fix buffer accounting when generating metric XML
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>
2024-01-11 16:55:46 -07:00
Jim Fehlig
b956b9ef68 Fix compiler warning
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>
2024-01-11 16:55:46 -07:00
rwmjones
2b66c8967c
Merge pull request #13 from yselkowitz/modern-c
Fix implicit declarations
2024-01-02 12:24:54 +00:00
Yaakov Selkowitz
cf555d3bf0 Fix implicit declarations
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>
2023-12-24 15:02:04 -05:00
Jim Fehlig
51b7105ab2 Change actions to retrieve vendor and product info
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>
2023-06-23 15:22:12 -06:00
Jim Fehlig
27d6cbf362 Add a 'unit' attribute to the metrics element
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>
2023-06-23 14:41:13 -06:00
9032620184 1.1-alt1
- Initial build.
1.1-alt1 gb-sisyphus-task282145.640
2023-03-01 02:45:28 +03:00
8a220aa565 Fix path to systemd units 2023-03-01 02:45:28 +03:00
922cf64e60 Fix undefined symbol
Verifying ELF objects in /usr/src/tmp/vhostmd-buildroot (arch=normal,fhs=normal,lfs=relaxed,lint=relaxed,rpath=normal,stack=normal,textrel=normal,unresolved=normal)
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlFreeDoc
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlInitParser
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlGetProp
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlCleanupParser
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlCtxtReadMemory
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlXPathFreeObject
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlXPathNewContext
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlNodeListGetString
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlFreeParserCtxt
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlXPathFreeContext
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlNewParserCtxt
verify-elf: ERROR: ./usr/lib64/libmetrics.so.0.0.0: undefined symbol: xmlXPathEval
2023-03-01 02:45:28 +03:00
2777e4f9b8 Disable -static 2023-03-01 02:45:28 +03:00
Jim Fehlig
5896b548fe
Merge pull request #10 from srowe/master
vif-stats.py: convert to Python3
2022-10-06 13:56:46 -06:00
Simon Rowe
f397523515 vif-stats.py: convert to Python3
Python2 has been EOL for nearly three years.

Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
2022-10-06 14:03:08 +00:00
Jim Fehlig
99995e4ba1 virtio: Fix strncpy length parameter
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>
2020-01-14 16:22:48 -07:00
Jim Fehlig
ff6959fd92 vhostmd: Fix memory leak in vhostmd_run
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>
2020-01-14 16:11:37 -07:00
Jim Fehlig
d86c51d98c vhostmd: Check for valide file handle before calling close
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>
2020-01-14 16:04:09 -07:00
Jim Fehlig
4f7b23e19c vhostmd: Check return value of file functions
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>
2020-01-14 15:33:39 -07:00
Jim Fehlig
d9eeede678 vhostmd: Remove unsafe XML_PARSE_NOENT option
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>
2020-01-14 15:12:28 -07:00
Jim Fehlig
71a94a18c4 vhostmd: Fix memory leak in parse_transports
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>
2020-01-14 15:08:54 -07:00
Jim Fehlig
1771ddb83f Check return value of asprintf
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>
2020-01-07 11:52:23 -07:00
Jim Fehlig
4350fcf7a5 util: Check return value of strstr
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>
2020-01-07 11:47:33 -07:00
Jim Fehlig
b39f7cc778 util: Fix potential memory leak
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>
2020-01-07 11:42:01 -07:00
Jim Fehlig
69fcc2075d util: Add missing call to va_end
From coverity scan

Error: VARARGS (CWE-237):
vhostmd-1.1/vhostmd/util.c:209: va_init: Initializing va_list "argptr".
vhostmd-1.1/vhostmd/util.c:218: missing_va_end: va_end was not called for "argptr".
  216|           grow_size = (count > 1000) ? count : 1000;
  217|           if (buffer_grow(buf, grow_size) < 0)
  218|->             return;
  219|
  220|           size = buf->size - buf->use - 1;

Error: VARARGS (CWE-237):
vhostmd-1.1/vhostmd/util.c:209: va_init: Initializing va_list "argptr".
vhostmd-1.1/vhostmd/util.c:226: missing_va_end: va_end was not called for "argptr".
  224|       buf->use += count;
  225|       buf->content[buf->use] = '\0';
  226|-> }
  227|
  228|   /*

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2020-01-07 11:36:56 -07:00
Jim Fehlig
cba4dddebc libmetrics: Fix potential leak of FILE pointer
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>
2020-01-06 18:59:18 -07:00
Jim Fehlig
bc5da0b996 libmetrics: Use proper conversion specifier when calling log function
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>
2020-01-06 18:51:40 -07:00
Jim Fehlig
2cbce5fcb6 libmetrics: Fix potential memory leak
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>
2020-01-06 18:40:33 -07:00
Jim Fehlig
855326a8c9 libmetrics: Ensure libmetrics mutex is unlocked in error paths
From coverity scan

vhostmd-1.1/libmetrics/libmetrics.c:595: missing_unlock: Returning without unlocking "libmetrics_mutex".
  593|          if (mdisk_alloc() == NULL) {
  594|              errno = ENOMEM;
  595|->            return -1;
  596|          }
  597|          read_mdisk(mdisk);

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2020-01-06 17:47:10 -07:00
Jim Fehlig
3d4f3acdfc libmetrics: Remove unsafe XML_PARSE_NOENT option
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>
2020-01-06 17:42:39 -07:00
Jim Fehlig
f659ec7742 libmetrics: Check return value of asprintf
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>
2020-01-06 16:52:30 -07:00
Jim Fehlig
9db959c9e3 libmetrics: Initialize local variable 'ret' to failure
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>
2020-01-06 16:48:07 -07:00
Jim Fehlig
06e73264b2 libmetrics: Set pointer NULL after free
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>
2020-01-06 16:14:18 -07:00
Jim Fehlig
83cc269f68 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>
2019-10-08 20:56:18 -06:00
Jim Fehlig
52b2dbf5c7 vhostmd release 1.1
Update configure.ac and vhostmd.changes for release.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
v1.1
2019-04-10 16:25:00 -06:00
Michael Trapp
68997b09da Add a timeout to the metrics request and fix the timeout value
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.
2019-03-15 11:42:50 -06:00
Michael Trapp
7d31666a22 Add function name to error messages in dump_virtio functions 2019-03-15 11:18:43 -06:00
Michael Trapp
c2c22fa2b8 Remove read_metrics() from the libmetrics constructor
The metrics disk can be opened with the first get_metrics() request.
2019-03-15 11:17:19 -06:00
Michael Trapp
ad0777cd20 Remove d_type check for channel directory.
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.
2019-02-06 10:03:29 -07:00
Michael Trapp
57698b6b2c Don't pass NULL string to library log function 2018-12-10 16:45:05 -07:00
Michael Trapp
89ba5ba4ba Remove libserialclient
There is no need to keep the dump_virtio code in a separate library.
Revert libserialclient changes and move the code to libmetrics.
2018-12-10 16:41:32 -07:00
Jim Fehlig
29c8c5ef6c vhostmd release 1.0
Update conigure.ac, AUTHORS, and vhostmd.changes for release.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
v1.0
2018-11-30 15:05:20 -07:00
Jim Fehlig
4323a00ace Change bug report notification to virt-tools-list
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>
2018-11-30 13:20:26 -07:00
Jim Fehlig
e5b56a4f76 Change last occurrences of C++ comment style to C
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2018-11-30 12:06:07 -07:00
Jim Fehlig
386228b841 Remove commented code
The code has been commented since importing vhostmd to git. I think
it is safe to remove it.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2018-11-30 12:02:01 -07:00
Michael Trapp
983bb879c3 Add virtio support to vm-dump-metrics
virtio functions are available in libmetrics
and in libserialclient (with minimal dependencies).
2018-11-30 11:49:49 -07:00
Michael Trapp
dffac68595 Activate virtio support in vhostmd
Activate the virtio code and extend DTD/XML to support a virtio section
for virtio related configuration and a new transport type virtio.
2018-11-30 11:49:49 -07:00
Michael Trapp
cfd4e6f198 Add virtio functions
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
2018-11-30 11:49:34 -07:00
Michael Trapp
c1d67a50fa Extend vu_buffer struct
With the virtio implementation vu_buffer is used for socket IO
and therefore information about the current position after a
write is required.
2018-11-29 11:02:58 -07:00
Michael Trapp
ce60e3d98f Fix update_interval behaviour
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.
2018-11-29 11:02:44 -07:00