util: virstatslinux: make more generic

Rename linuxDomainInterfaceStats to virNetInterfaceStats in order
to allow adding platform specific implementations without
making consumer worrying about specific implementation to be used.

Also, rename util/virstatslinux.c to util/virstats.c so placing
other platform specific implementations into this file don't
look unexpected from the file name.
This commit is contained in:
Roman Bogorodskiy 2014-07-05 19:34:39 +04:00
parent 2f97ea328f
commit 5559a8b838
12 changed files with 43 additions and 54 deletions

View File

@ -198,7 +198,7 @@ src/util/virrandom.c
src/util/virsexpr.c
src/util/virscsi.c
src/util/virsocketaddr.c
src/util/virstatslinux.c
src/util/virstats.c
src/util/virstorageencryption.c
src/util/virstoragefile.c
src/util/virstring.c

View File

@ -149,7 +149,7 @@ UTIL_SOURCES = \
util/virseclabel.c util/virseclabel.h \
util/virsexpr.c util/virsexpr.h \
util/virsocketaddr.h util/virsocketaddr.c \
util/virstatslinux.c util/virstatslinux.h \
util/virstats.c util/virstats.h \
util/virstorageencryption.c util/virstorageencryption.h \
util/virstoragefile.c util/virstoragefile.h \
util/virstring.h util/virstring.c \

View File

@ -6,9 +6,6 @@
linuxNodeGetCPUStats;
linuxNodeInfoCPUPopulate;
# util/virstatslinux.h
linuxDomainInterfaceStats;
# Let emacs know we want case-insensitive sorting
# Local Variables:
# sort-fold-case: t

View File

@ -1886,6 +1886,8 @@ virSocketAddrPrefixToNetmask;
virSocketAddrSetIPv4Addr;
virSocketAddrSetPort;
# util/virstats.h
virNetInterfaceStats;
# util/virstorageencryption.h
virStorageEncryptionFormat;

View File

@ -51,7 +51,7 @@
#include "virnetdevveth.h"
#include "nodeinfo.h"
#include "viruuid.h"
#include "virstatslinux.h"
#include "virstats.h"
#include "virhook.h"
#include "virfile.h"
#include "virpidfile.h"
@ -3132,7 +3132,7 @@ lxcDomainInterfaceStats(virDomainPtr dom,
}
if (ret == 0)
ret = linuxDomainInterfaceStats(path, stats);
ret = virNetInterfaceStats(path, stats);
else
virReportError(VIR_ERR_INVALID_ARG,
_("Invalid path, '%s' is not a known interface"), path);

View File

@ -56,7 +56,7 @@
#include "virlog.h"
#include "vircommand.h"
#include "viruri.h"
#include "virstatslinux.h"
#include "virstats.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_OPENVZ
@ -2010,7 +2010,7 @@ openvzDomainInterfaceStats(virDomainPtr dom,
}
if (ret == 0)
ret = linuxDomainInterfaceStats(path, stats);
ret = virNetInterfaceStats(path, stats);
else
virReportError(VIR_ERR_INVALID_ARG,
_("invalid path, '%s' is not a known interface"), path);

View File

@ -61,7 +61,7 @@
#include "datatypes.h"
#include "virbuffer.h"
#include "nodeinfo.h"
#include "virstatslinux.h"
#include "virstats.h"
#include "capabilities.h"
#include "viralloc.h"
#include "viruuid.h"
@ -9765,7 +9765,6 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
return ret;
}
#ifdef __linux__
static int
qemuDomainInterfaceStats(virDomainPtr dom,
const char *path,
@ -9797,7 +9796,7 @@ qemuDomainInterfaceStats(virDomainPtr dom,
}
if (ret == 0)
ret = linuxDomainInterfaceStats(path, stats);
ret = virNetInterfaceStats(path, stats);
else
virReportError(VIR_ERR_INVALID_ARG,
_("invalid path, '%s' is not a known interface"), path);
@ -9807,17 +9806,6 @@ qemuDomainInterfaceStats(virDomainPtr dom,
virObjectUnlock(vm);
return ret;
}
#else
static int
qemuDomainInterfaceStats(virDomainPtr dom ATTRIBUTE_UNUSED,
const char *path ATTRIBUTE_UNUSED,
struct _virDomainInterfaceStats *stats ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("interface stats not implemented on this platform"));
return -1;
}
#endif
static int
qemuDomainSetInterfaceParameters(virDomainPtr dom,

View File

@ -47,7 +47,7 @@
#include "uml_conf.h"
#include "virbuffer.h"
#include "nodeinfo.h"
#include "virstatslinux.h"
#include "virstats.h"
#include "capabilities.h"
#include "viralloc.h"
#include "viruuid.h"

View File

@ -1,5 +1,5 @@
/*
* virstatslinux.c: Linux block and network stats.
* virstats.c: Block and network stats.
*
* Copyright (C) 2007-2010 Red Hat, Inc.
*
@ -22,23 +22,20 @@
#include <config.h>
/* This file only applies on Linux. */
#ifdef __linux__
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <regex.h>
# include <stdio.h>
# include <stdlib.h>
# include <fcntl.h>
# include <string.h>
# include <unistd.h>
# include <regex.h>
#include "virerror.h"
#include "datatypes.h"
#include "virstats.h"
#include "viralloc.h"
#include "virfile.h"
# include "virerror.h"
# include "datatypes.h"
# include "virstatslinux.h"
# include "viralloc.h"
# include "virfile.h"
# define VIR_FROM_THIS VIR_FROM_STATS_LINUX
#define VIR_FROM_THIS VIR_FROM_STATS_LINUX
/*-------------------- interface stats --------------------*/
@ -46,10 +43,10 @@
* NB. Caller must check that libvirt user is trying to query
* the interface of a domain they own. We do no such checking.
*/
#ifdef __linux__
int
linuxDomainInterfaceStats(const char *path,
struct _virDomainInterfaceStats *stats)
virNetInterfaceStats(const char *path,
struct _virDomainInterfaceStats *stats)
{
int path_len;
FILE *fp;
@ -117,5 +114,14 @@ linuxDomainInterfaceStats(const char *path,
_("/proc/net/dev: Interface not found"));
return -1;
}
#else
int
virNetInterfaceStats(const char *path ATTRIBUTE_UNUSED,
struct _virDomainInterfaceStats *stats ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("interface stats not implemented on this platform"));
return -1;
}
#endif /* __linux__ */

View File

@ -1,5 +1,5 @@
/*
* virstatslinux.h: Linux block and network stats.
* virstats.h: Block and network stats.
*
* Copyright (C) 2007 Red Hat, Inc.
*
@ -23,13 +23,9 @@
#ifndef __STATS_LINUX_H__
# define __STATS_LINUX_H__
# ifdef __linux__
# include "internal.h"
# include "internal.h"
extern int linuxDomainInterfaceStats(const char *path,
struct _virDomainInterfaceStats *stats);
# endif /* __linux__ */
extern int virNetInterfaceStats(const char *path,
struct _virDomainInterfaceStats *stats);
#endif /* __STATS_LINUX_H__ */

View File

@ -68,7 +68,7 @@
#include "xen_driver.h"
#include "xen_hypervisor.h"
#include "xs_internal.h"
#include "virstatslinux.h"
#include "virstats.h"
#include "block_stats.h"
#include "xend_internal.h"
#include "virbuffer.h"
@ -1470,7 +1470,7 @@ xenHypervisorDomainInterfaceStats(virDomainDefPtr def,
return -1;
}
return linuxDomainInterfaceStats(path, stats);
return virNetInterfaceStats(path, stats);
#else
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("/proc/net/dev: Interface not found"));

View File

@ -5,7 +5,7 @@
#include <string.h>
#include <sys/utsname.h>
#include "virstatslinux.h"
#include "virstats.h"
#include "internal.h"
#include "xen/block_stats.h"
#include "testutils.h"