|
Packit |
a07778 |
/*
|
|
Packit |
a07778 |
* libvirt-gobject-domain-interface.c: libvirt gobject integration
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Copyright (C) 2011 Red Hat, Inc.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
a07778 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
a07778 |
* License as published by the Free Software Foundation; either
|
|
Packit |
a07778 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
a07778 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a07778 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
a07778 |
* Lesser General Public License for more details.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
a07778 |
* License along with this library. If not, see
|
|
Packit |
a07778 |
* <http://www.gnu.org/licenses/>.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Author: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
Packit |
a07778 |
*/
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include <config.h>
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include <libvirt/virterror.h>
|
|
Packit |
a07778 |
#include <string.h>
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include "libvirt-glib/libvirt-glib.h"
|
|
Packit |
a07778 |
#include "libvirt-gobject/libvirt-gobject.h"
|
|
Packit |
a07778 |
#include "libvirt-gobject-compat.h"
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#include "libvirt-gobject/libvirt-gobject-domain-device-private.h"
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#define GVIR_DOMAIN_INTERFACE_GET_PRIVATE(obj) \
|
|
Packit |
a07778 |
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_DOMAIN_INTERFACE, GVirDomainInterfacePrivate))
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
struct _GVirDomainInterfacePrivate
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
gboolean unused;
|
|
Packit |
a07778 |
};
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
G_DEFINE_TYPE_WITH_PRIVATE(GVirDomainInterface, gvir_domain_interface, GVIR_TYPE_DOMAIN_DEVICE);
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#define GVIR_DOMAIN_INTERFACE_ERROR gvir_domain_interface_error_quark()
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static GQuark
|
|
Packit |
a07778 |
gvir_domain_interface_error_quark(void)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
return g_quark_from_static_string("gvir-domain-interface");
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void gvir_domain_interface_class_init(GVirDomainInterfaceClass *klass G_GNUC_UNUSED)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void gvir_domain_interface_init(GVirDomainInterface *self)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
self->priv = GVIR_DOMAIN_INTERFACE_GET_PRIVATE(self);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static GVirDomainInterfaceStats *
|
|
Packit |
a07778 |
gvir_domain_interface_stats_copy(GVirDomainInterfaceStats *stats)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
return g_slice_dup(GVirDomainInterfaceStats, stats);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void
|
|
Packit |
a07778 |
gvir_domain_interface_stats_free(GVirDomainInterfaceStats *stats)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
g_slice_free(GVirDomainInterfaceStats, stats);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
G_DEFINE_BOXED_TYPE(GVirDomainInterfaceStats, gvir_domain_interface_stats,
|
|
Packit |
a07778 |
gvir_domain_interface_stats_copy, gvir_domain_interface_stats_free)
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static const gchar *gvir_domain_interface_get_path(GVirDomainInterface *self)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
GVirConfigDomainDevice *config;
|
|
Packit |
a07778 |
const gchar *path = NULL;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self));
|
|
Packit |
a07778 |
if (GVIR_CONFIG_IS_DOMAIN_INTERFACE_USER(self))
|
|
Packit |
a07778 |
/* FIXME: One of the limitations of user-mode networking of libvirt */
|
|
Packit |
a07778 |
g_debug("Statistics gathering for user-mode network not yet supported");
|
|
Packit |
a07778 |
else
|
|
Packit |
a07778 |
path = gvir_config_domain_interface_get_ifname(GVIR_CONFIG_DOMAIN_INTERFACE (config));
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
g_object_unref (config);
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
return path;
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/**
|
|
Packit |
a07778 |
* gvir_domain_interface_get_stats:
|
|
Packit |
a07778 |
* @self: the domain interface
|
|
Packit |
a07778 |
* @err: an error
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This function returns network interface stats. Individual fields
|
|
Packit |
a07778 |
* within the stats structure may be returned as -1, which indicates
|
|
Packit |
a07778 |
* that the hypervisor does not support that particular statistic.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Returns: (transfer full): the stats or %NULL in case of error. The
|
|
Packit |
a07778 |
* returned object should be unreffed with g_object_unref() when no longer
|
|
Packit |
a07778 |
* needed.
|
|
Packit |
a07778 |
**/
|
|
Packit |
a07778 |
GVirDomainInterfaceStats *gvir_domain_interface_get_stats(GVirDomainInterface *self, GError **err)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
GVirDomainInterfaceStats *ret = NULL;
|
|
Packit |
a07778 |
virDomainInterfaceStatsStruct stats;
|
|
Packit |
a07778 |
virDomainPtr handle;
|
|
Packit |
a07778 |
const gchar *path;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
g_return_val_if_fail(GVIR_IS_DOMAIN_INTERFACE(self), NULL);
|
|
Packit |
a07778 |
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self));
|
|
Packit |
a07778 |
path = gvir_domain_interface_get_path (self);
|
|
Packit |
a07778 |
if (path == NULL) {
|
|
Packit |
a07778 |
ret = g_slice_new0(GVirDomainInterfaceStats);
|
|
Packit |
a07778 |
goto end;
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
if (virDomainInterfaceStats(handle, path, &stats, sizeof (stats)) < 0) {
|
|
Packit |
a07778 |
gvir_set_error_literal(err, GVIR_DOMAIN_INTERFACE_ERROR,
|
|
Packit |
a07778 |
0,
|
|
Packit |
a07778 |
"Unable to get domain interface stats");
|
|
Packit |
a07778 |
goto end;
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
ret = g_slice_new(GVirDomainInterfaceStats);
|
|
Packit |
a07778 |
ret->rx_bytes = stats.rx_bytes;
|
|
Packit |
a07778 |
ret->rx_packets = stats.rx_packets;
|
|
Packit |
a07778 |
ret->rx_errs = stats.rx_errs;
|
|
Packit |
a07778 |
ret->rx_drop = stats.rx_drop;
|
|
Packit |
a07778 |
ret->tx_bytes = stats.tx_bytes;
|
|
Packit |
a07778 |
ret->tx_packets = stats.tx_packets;
|
|
Packit |
a07778 |
ret->tx_errs = stats.tx_errs;
|
|
Packit |
a07778 |
ret->tx_drop = stats.tx_drop;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
end:
|
|
Packit |
a07778 |
virDomainFree(handle);
|
|
Packit |
a07778 |
return ret;
|
|
Packit |
a07778 |
}
|