Remove libserialclient.
This commit is contained in:
parent
ac5642f674
commit
bd3e0883ad
422
0001-Remove-libserialclient.patch
Normal file
422
0001-Remove-libserialclient.patch
Normal file
@ -0,0 +1,422 @@
|
||||
From 89ba5ba4bad7267615d2ae77a40abb5de249fb94 Mon Sep 17 00:00:00 2001
|
||||
From: Michael Trapp <Michael.Trapp@sap.com>
|
||||
Date: Fri, 7 Dec 2018 19:12:22 +0100
|
||||
Subject: [PATCH 1/2] 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.
|
||||
---
|
||||
libmetrics/Makefile.am | 18 +---
|
||||
libmetrics/libmetrics.c | 131 ++++++++++++++++++++++++++
|
||||
libmetrics/libmetrics.h | 4 -
|
||||
libmetrics/libserialclient.c | 172 -----------------------------------
|
||||
libmetrics/libserialclient.h | 30 ------
|
||||
5 files changed, 133 insertions(+), 222 deletions(-)
|
||||
delete mode 100644 libmetrics/libserialclient.c
|
||||
delete mode 100644 libmetrics/libserialclient.h
|
||||
|
||||
diff --git a/libmetrics/Makefile.am b/libmetrics/Makefile.am
|
||||
index 468f08f..254b2c8 100644
|
||||
--- a/libmetrics/Makefile.am
|
||||
+++ b/libmetrics/Makefile.am
|
||||
@@ -6,7 +6,7 @@ if WITH_XENSTORE
|
||||
AM_CFLAGS += -DWITH_XENSTORE
|
||||
endif
|
||||
|
||||
-lib_LTLIBRARIES=libmetrics.la libserialclient.la
|
||||
+lib_LTLIBRARIES=libmetrics.la
|
||||
|
||||
libmetricsincdir=$(includedir)/vhostmd
|
||||
libmetricsinc_HEADERS = libmetrics.h
|
||||
@@ -15,21 +15,7 @@ libmetrics_la_SOURCES = \
|
||||
libmetrics.c \
|
||||
vm_metrics.c \
|
||||
host_metrics.c \
|
||||
- libserialclient.c \
|
||||
libmetrics.h
|
||||
|
||||
libmetrics_la_DEPENDENCIES = \
|
||||
- libmetrics.h \
|
||||
- libserialclient.h
|
||||
-
|
||||
-
|
||||
-libserialclientincdir=
|
||||
-libserialclientinc_HEADERS = libserialclient.h
|
||||
-
|
||||
-libserialclient_la_SOURCES = \
|
||||
- libserialclient.c \
|
||||
- libserialclient.h
|
||||
-
|
||||
-libserialclient_la_DEPENDENCIES = \
|
||||
- libserialclient.h
|
||||
-
|
||||
+ libmetrics.h
|
||||
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
|
||||
index bc3ba1d..0a5e3ee 100644
|
||||
--- a/libmetrics/libmetrics.c
|
||||
+++ b/libmetrics/libmetrics.c
|
||||
@@ -775,3 +775,134 @@ out:
|
||||
}
|
||||
#endif
|
||||
|
||||
+/*
|
||||
+ * dump metrics from virtio serial port to buffer
|
||||
+ */
|
||||
+static char *get_virtio_metrics(void)
|
||||
+{
|
||||
+ const char request[] = "GET /metrics/XML\n\n", end_token[] = "\n\n";
|
||||
+ const char dev[] = "/dev/virtio-ports/org.github.vhostmd.1";
|
||||
+
|
||||
+ char *response = NULL;
|
||||
+ int fd = -1;
|
||||
+ size_t pos;
|
||||
+ size_t buf_size = (1 << 16);
|
||||
+ const size_t req_len = (size_t) strlen(request);
|
||||
+ const time_t start_time = time(NULL);
|
||||
+
|
||||
+ response = calloc(1UL, buf_size);
|
||||
+ if (response == NULL)
|
||||
+ goto error;
|
||||
+
|
||||
+ fd = open(dev, O_RDWR | O_NONBLOCK);
|
||||
+
|
||||
+ if (fd < 0) {
|
||||
+ libmsg("Error, unable to export metrics: open(%s) %s\n",
|
||||
+ dev, strerror(errno));
|
||||
+ goto error;
|
||||
+ }
|
||||
+
|
||||
+ pos = 0;
|
||||
+ while (pos < req_len) {
|
||||
+ ssize_t len = write(fd, &request[pos], req_len - pos);
|
||||
+ if (len > 0)
|
||||
+ pos += (size_t) len;
|
||||
+ else {
|
||||
+ if (errno == EAGAIN)
|
||||
+ usleep(10000);
|
||||
+ else
|
||||
+ goto error;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ pos = 0;
|
||||
+ do {
|
||||
+ ssize_t len = read(fd, &response[pos], buf_size - pos - 1);
|
||||
+ if (len > 0) {
|
||||
+ pos += (size_t) len;
|
||||
+ response[pos] = 0;
|
||||
+
|
||||
+ if ((pos + 1) >= buf_size) {
|
||||
+ buf_size = buf_size << 1; /* increase response buffer */
|
||||
+ if (buf_size > (1 << 24)) /* max 16MB */
|
||||
+ goto error;
|
||||
+
|
||||
+ response = realloc(response, buf_size);
|
||||
+ if (response == NULL)
|
||||
+ goto error;
|
||||
+
|
||||
+ memset(&response[pos], 0, buf_size - pos);
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (errno == EAGAIN) {
|
||||
+ usleep(10000);
|
||||
+ if (time(NULL) > (start_time + 30)) {
|
||||
+ libmsg("Error, unable to read metrics"
|
||||
+ " - timeout after 30s\n");
|
||||
+ goto error;
|
||||
+ }
|
||||
+ } else
|
||||
+ goto error;
|
||||
+ }
|
||||
+ } while ((pos < (size_t) strlen(end_token) ||
|
||||
+ strcmp(end_token, &response[pos - (size_t) strlen(end_token)]) != 0) &&
|
||||
+ pos < buf_size);
|
||||
+
|
||||
+ if (fd >= 0)
|
||||
+ close(fd);
|
||||
+
|
||||
+ return response;
|
||||
+
|
||||
+ error:
|
||||
+ if (fd >= 0)
|
||||
+ close(fd);
|
||||
+ if (response)
|
||||
+ free(response);
|
||||
+
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * dump metrics from virtio serial port to xml formatted file
|
||||
+ */
|
||||
+int dump_virtio_metrics(const char *dest_file)
|
||||
+{
|
||||
+ FILE *fp = stdout;
|
||||
+ char *response = NULL;
|
||||
+ size_t len;
|
||||
+
|
||||
+ response = get_virtio_metrics();
|
||||
+ if (response == NULL)
|
||||
+ goto error;
|
||||
+
|
||||
+ len = strlen(response);
|
||||
+
|
||||
+ if (dest_file) {
|
||||
+ fp = fopen(dest_file, "w");
|
||||
+ if (fp == NULL) {
|
||||
+ libmsg("Error, unable to dump metrics: fopen(%s) %s\n",
|
||||
+ dest_file, strerror(errno));
|
||||
+ goto error;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (fwrite(response, 1UL, len, fp) != len) {
|
||||
+ libmsg("Error, unable to export metrics to file:%s %s\n",
|
||||
+ dest_file ? dest_file : "stdout", strerror(errno));
|
||||
+ goto error;
|
||||
+ }
|
||||
+
|
||||
+ if (response)
|
||||
+ free(response);
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+ error:
|
||||
+ if (dest_file && fp)
|
||||
+ fclose(fp);
|
||||
+
|
||||
+ if (response)
|
||||
+ free(response);
|
||||
+
|
||||
+ return -1;
|
||||
+}
|
||||
diff --git a/libmetrics/libmetrics.h b/libmetrics/libmetrics.h
|
||||
index 1908de8..c4873ff 100644
|
||||
--- a/libmetrics/libmetrics.h
|
||||
+++ b/libmetrics/libmetrics.h
|
||||
@@ -102,8 +102,4 @@ int dump_xenstore_metrics(const char *dest_file);
|
||||
|
||||
/* dump metrics from virtio serial port to xml formatted file */
|
||||
int dump_virtio_metrics(const char *dest_file);
|
||||
-
|
||||
-/* dump metrics from virtio serial port to buffer */
|
||||
-const char *get_virtio_metrics(const char *dev_name);
|
||||
-
|
||||
#endif
|
||||
diff --git a/libmetrics/libserialclient.c b/libmetrics/libserialclient.c
|
||||
deleted file mode 100644
|
||||
index d3a4af5..0000000
|
||||
--- a/libmetrics/libserialclient.c
|
||||
+++ /dev/null
|
||||
@@ -1,172 +0,0 @@
|
||||
-/*
|
||||
- * Copyright (C) 2018 SAP SE
|
||||
- *
|
||||
- * This library is free software; you can redistribute it and/or
|
||||
- * modify it under the terms of the GNU Lesser General Public
|
||||
- * License as published by the Free Software Foundation; either
|
||||
- * version 2.1 of the License, or (at your option) any later version.
|
||||
- *
|
||||
- * This library is distributed in the hope that it will be useful,
|
||||
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
- * Lesser General Public License for more details.
|
||||
- *
|
||||
- * You should have received a copy of the GNU Lesser General Public
|
||||
- * License along with this library; if not, write to the Free Software
|
||||
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
- *
|
||||
- * Author: Michael Trapp <michael.trapp@sap.com>
|
||||
- */
|
||||
-
|
||||
-#include <config.h>
|
||||
-
|
||||
-#include <stdio.h>
|
||||
-#include <stdlib.h>
|
||||
-#include <time.h>
|
||||
-#include <string.h>
|
||||
-#include <fcntl.h>
|
||||
-#include <unistd.h>
|
||||
-#include <errno.h>
|
||||
-
|
||||
-#include "libserialclient.h"
|
||||
-
|
||||
-
|
||||
-/*
|
||||
- * dump metrics from virtio serial port to xml formatted file
|
||||
- */
|
||||
-int dump_virtio_metrics(const char *dest_file)
|
||||
-{
|
||||
- FILE *fp = stdout;
|
||||
- char *response;
|
||||
- size_t len;
|
||||
-
|
||||
- response = get_virtio_metrics(NULL);
|
||||
- if (response == NULL)
|
||||
- goto error;
|
||||
-
|
||||
- len = strlen(response);
|
||||
-
|
||||
- if (dest_file) {
|
||||
- fp = fopen(dest_file, "w");
|
||||
- if (fp == NULL) {
|
||||
- fprintf(stderr,
|
||||
- "LIB_SERIALCLIENT: Error, unable to dump metrics: fopen(%s) %s\n",
|
||||
- dest_file, strerror(errno));
|
||||
- goto error;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- if (fwrite(response, 1UL, len, fp) != len) {
|
||||
- fprintf(stderr,
|
||||
- "LIB_SERIALCLIENT: Error, unable to export metrics to file:%s - error:%s\n",
|
||||
- dest_file ? dest_file : "STDOUT", strerror(errno));
|
||||
- goto error;
|
||||
- }
|
||||
-
|
||||
- if (response)
|
||||
- free(response);
|
||||
-
|
||||
- return 0;
|
||||
-
|
||||
- error:
|
||||
- if (dest_file && fp)
|
||||
- fclose(fp);
|
||||
-
|
||||
- if (response)
|
||||
- free(response);
|
||||
-
|
||||
- return -1;
|
||||
-}
|
||||
-
|
||||
-/*
|
||||
- * dump metrics from virtio serial port to buffer
|
||||
- */
|
||||
-char *get_virtio_metrics(const char *dev_name)
|
||||
-{
|
||||
- const char request[] = "GET /metrics/XML\n\n", end_token[] = "\n\n";
|
||||
- const char *dev;
|
||||
- char *response = NULL;
|
||||
- int fd = -1;
|
||||
- size_t pos;
|
||||
- size_t buf_size = (1 << 16);
|
||||
- const size_t req_len = (size_t) strlen(request);
|
||||
- const time_t start_time = time(NULL);
|
||||
-
|
||||
- if (dev_name)
|
||||
- dev = dev_name;
|
||||
- else
|
||||
- dev = "/dev/virtio-ports/org.github.vhostmd.1";
|
||||
-
|
||||
- response = calloc(1UL, buf_size);
|
||||
- if (response == NULL)
|
||||
- goto error;
|
||||
-
|
||||
- fd = open(dev, O_RDWR | O_NONBLOCK);
|
||||
-
|
||||
- if (fd < 0) {
|
||||
- fprintf(stderr,
|
||||
- "LIB_SERIALCLIENT: Error, unable to dump metrics: open(%s) %s\n",
|
||||
- dev, strerror(errno));
|
||||
- goto error;
|
||||
- }
|
||||
-
|
||||
- pos = 0;
|
||||
- while (pos < req_len) {
|
||||
- ssize_t len = write(fd, &request[pos], req_len - pos);
|
||||
- if (len > 0)
|
||||
- pos += (size_t) len;
|
||||
- else {
|
||||
- if (errno == EAGAIN)
|
||||
- usleep(10000);
|
||||
- else
|
||||
- goto error;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- pos = 0;
|
||||
- do {
|
||||
- ssize_t len = read(fd, &response[pos], buf_size - pos - 1);
|
||||
- if (len > 0) {
|
||||
- pos += (size_t) len;
|
||||
- response[pos] = 0;
|
||||
-
|
||||
- if ((pos + 1) >= buf_size) {
|
||||
- buf_size = buf_size << 1; /* increase response buffer */
|
||||
- if (buf_size > (1 << 24)) /* max 16MB */
|
||||
- goto error;
|
||||
-
|
||||
- response = realloc(response, buf_size);
|
||||
- if (response == NULL)
|
||||
- goto error;
|
||||
-
|
||||
- memset(&response[pos], 0, buf_size - pos);
|
||||
- }
|
||||
- } else {
|
||||
- if (errno == EAGAIN) {
|
||||
- usleep(10000);
|
||||
- if (time(NULL) > (start_time + 30)) {
|
||||
- fprintf(stderr,
|
||||
- "LIB_SERIALCLIENT: Error, unable to read metrics"
|
||||
- " - timeout after 30s\n");
|
||||
- goto error;
|
||||
- }
|
||||
- } else
|
||||
- goto error;
|
||||
- }
|
||||
- } while ((pos < (size_t) strlen(end_token) ||
|
||||
- strcmp(end_token, &response[pos - (size_t) strlen(end_token)]) != 0) &&
|
||||
- pos < buf_size);
|
||||
-
|
||||
- if (fd >= 0)
|
||||
- close(fd);
|
||||
-
|
||||
- return response;
|
||||
-
|
||||
- error:
|
||||
- if (fd >= 0)
|
||||
- close(fd);
|
||||
- if (response)
|
||||
- free(response);
|
||||
-
|
||||
- return NULL;
|
||||
-}
|
||||
diff --git a/libmetrics/libserialclient.h b/libmetrics/libserialclient.h
|
||||
deleted file mode 100644
|
||||
index 887c6a5..0000000
|
||||
--- a/libmetrics/libserialclient.h
|
||||
+++ /dev/null
|
||||
@@ -1,30 +0,0 @@
|
||||
-/*
|
||||
- * Copyright (C) 2018 SAP SE
|
||||
- *
|
||||
- * This library is free software; you can redistribute it and/or
|
||||
- * modify it under the terms of the GNU Lesser General Public
|
||||
- * License as published by the Free Software Foundation; either
|
||||
- * version 2.1 of the License, or (at your option) any later version.
|
||||
- *
|
||||
- * This library is distributed in the hope that it will be useful,
|
||||
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
- * Lesser General Public License for more details.
|
||||
- *
|
||||
- * You should have received a copy of the GNU Lesser General Public
|
||||
- * License along with this library; if not, write to the Free Software
|
||||
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
- *
|
||||
- * Author: Michael Trapp <michael.trapp@sap.com>
|
||||
- */
|
||||
-
|
||||
-#ifndef __LIBSERIALCLIENT_H__
|
||||
-#define __LIBSERIALCLIENT_H__
|
||||
-
|
||||
-/* dump metrics from virtio serial port to xml formatted file */
|
||||
-int dump_virtio_metrics(const char *dest_file);
|
||||
-
|
||||
-/* dump metrics from virtio serial port to buffer */
|
||||
-char *get_virtio_metrics(const char *dev_name);
|
||||
-
|
||||
-#endif
|
||||
--
|
||||
2.20.1
|
||||
|
||||
27
0002-Don-t-pass-NULL-string-to-library-log-function.patch
Normal file
27
0002-Don-t-pass-NULL-string-to-library-log-function.patch
Normal file
@ -0,0 +1,27 @@
|
||||
From 57698b6b2c05e2288b72ae36afa93a2e555c72fd Mon Sep 17 00:00:00 2001
|
||||
From: Michael Trapp <Michael.Trapp@sap.com>
|
||||
Date: Fri, 7 Dec 2018 19:12:40 +0100
|
||||
Subject: [PATCH 2/2] Don't pass NULL string to library log function
|
||||
|
||||
---
|
||||
libmetrics/libmetrics.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/libmetrics/libmetrics.c b/libmetrics/libmetrics.c
|
||||
index 0a5e3ee..36c7f5f 100644
|
||||
--- a/libmetrics/libmetrics.c
|
||||
+++ b/libmetrics/libmetrics.c
|
||||
@@ -681,8 +681,8 @@ int dump_metrics(const char *dest_file)
|
||||
}
|
||||
|
||||
if (fwrite(mdisk->buffer, 1, mdisk->length, fp) != mdisk->length) {
|
||||
- libmsg("Error, unable to export metrics to file:%s - error:%s\n",
|
||||
- dest_file, strerror(errno));
|
||||
+ libmsg("Error, unable to export metrics to file:%s - error:%s\n",
|
||||
+ dest_file ? dest_file : "stdout", strerror(errno));
|
||||
}
|
||||
if (dest_file)
|
||||
fclose(fp);
|
||||
--
|
||||
2.20.1
|
||||
|
||||
15
vhostmd.spec
15
vhostmd.spec
@ -3,7 +3,7 @@
|
||||
Summary: Virtualization host metrics daemon
|
||||
Name: vhostmd
|
||||
Version: 1.0
|
||||
Release: 1%{?dist}
|
||||
Release: 2%{?dist}
|
||||
License: GPLv2+
|
||||
|
||||
URL: http://gitorious.org/vhostmd
|
||||
@ -11,6 +11,11 @@ URL: http://gitorious.org/vhostmd
|
||||
Source0: https://github.com/vhostmd/vhostmd/archive/v%{version}/%{name}-%{version}.tar.gz
|
||||
Source1: vhostmd.conf
|
||||
|
||||
# Upstream patches since 1.0 was released. Note the first patch
|
||||
# removes the libserialclient API (present, temporarily, in 1.0).
|
||||
Patch0001: 0001-Remove-libserialclient.patch
|
||||
Patch0002: 0002-Don-t-pass-NULL-string-to-library-log-function.patch
|
||||
|
||||
BuildRequires: gcc
|
||||
BuildRequires: chrpath
|
||||
BuildRequires: perl-generators
|
||||
@ -73,7 +78,6 @@ rm -rf $RPM_BUILD_ROOT
|
||||
make DESTDIR=$RPM_BUILD_ROOT install
|
||||
|
||||
rm $RPM_BUILD_ROOT%{_libdir}/libmetrics.la
|
||||
rm $RPM_BUILD_ROOT%{_libdir}/libserialclient.la
|
||||
|
||||
chrpath --delete $RPM_BUILD_ROOT%{_sbindir}/vm-dump-metrics
|
||||
|
||||
@ -142,26 +146,23 @@ exit 0
|
||||
%{_sbindir}/vm-dump-metrics
|
||||
%{_libdir}/libmetrics.so.0
|
||||
%{_libdir}/libmetrics.so.0.0.0
|
||||
%{_libdir}/libserialclient.so.0
|
||||
%{_libdir}/libserialclient.so.0.0.0
|
||||
%{_mandir}/man1/vm-dump-metrics.1.gz
|
||||
|
||||
|
||||
%files -n vm-dump-metrics-devel
|
||||
%doc README
|
||||
%{_libdir}/libmetrics.so
|
||||
%{_libdir}/libserialclient.so
|
||||
%dir %{_includedir}/vhostmd
|
||||
%{_includedir}/vhostmd/libmetrics.h
|
||||
|
||||
|
||||
%changelog
|
||||
* Fri Jan 18 2019 Richard W.M. Jones <rjones@redhat.com> - 1.0-1
|
||||
* Fri Jan 18 2019 Richard W.M. Jones <rjones@redhat.com> - 1.0-2
|
||||
- Upstream version 1.0.
|
||||
- Remove patches, since all included 1.0.
|
||||
- Add patches since 1.0.
|
||||
- Fix Source0 URL, hosted on github.
|
||||
- Remove old Source1 and Source2, not used.
|
||||
- Add new serial client library.
|
||||
|
||||
* Tue Oct 16 2018 Richard W.M. Jones <rjones@redhat.com> - 0.5-19
|
||||
- Include all upstream patches since 0.5.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user