|
Packit |
a07778 |
/*
|
|
Packit |
a07778 |
* libvirt-gobject-domain-disk.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_DISK_GET_PRIVATE(obj) \
|
|
Packit |
a07778 |
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_DOMAIN_DISK, GVirDomainDiskPrivate))
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
struct _GVirDomainDiskPrivate
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
gboolean unused;
|
|
Packit |
a07778 |
};
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
G_DEFINE_TYPE_WITH_PRIVATE(GVirDomainDisk, gvir_domain_disk, GVIR_TYPE_DOMAIN_DEVICE);
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
#define GVIR_DOMAIN_DISK_ERROR gvir_domain_disk_error_quark()
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static GQuark
|
|
Packit |
a07778 |
gvir_domain_disk_error_quark(void)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
return g_quark_from_static_string("gvir-domain-disk");
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void gvir_domain_disk_class_init(GVirDomainDiskClass *klass G_GNUC_UNUSED)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void gvir_domain_disk_init(GVirDomainDisk *self)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
self->priv = GVIR_DOMAIN_DISK_GET_PRIVATE(self);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static GVirDomainDiskStats *
|
|
Packit |
a07778 |
gvir_domain_disk_stats_copy(GVirDomainDiskStats *stats)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
return g_slice_dup(GVirDomainDiskStats, stats);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static void
|
|
Packit |
a07778 |
gvir_domain_disk_stats_free(GVirDomainDiskStats *stats)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
g_slice_free(GVirDomainDiskStats, stats);
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
G_DEFINE_BOXED_TYPE(GVirDomainDiskStats, gvir_domain_disk_stats,
|
|
Packit |
a07778 |
gvir_domain_disk_stats_copy, gvir_domain_disk_stats_free)
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
static const gchar *gvir_domain_disk_get_path(GVirDomainDisk *self)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
GVirConfigDomainDevice *config;
|
|
Packit |
a07778 |
const gchar *path;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
config = gvir_domain_device_get_config(GVIR_DOMAIN_DEVICE(self));
|
|
Packit |
a07778 |
path = gvir_config_domain_disk_get_target_dev(GVIR_CONFIG_DOMAIN_DISK(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_disk_get_stats:
|
|
Packit |
a07778 |
* @self: the domain disk
|
|
Packit |
a07778 |
* @err: an error
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This function returns network disk 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 |
GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk *self, GError **err)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
GVirDomainDiskStats *ret = NULL;
|
|
Packit |
a07778 |
virDomainBlockStatsStruct stats;
|
|
Packit |
a07778 |
virDomainPtr handle;
|
|
Packit |
a07778 |
const gchar *path;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(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_disk_get_path (self);
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
if (virDomainBlockStats(handle, path, &stats, sizeof (stats)) < 0) {
|
|
Packit |
a07778 |
gvir_set_error_literal(err, GVIR_DOMAIN_DISK_ERROR,
|
|
Packit |
a07778 |
0,
|
|
Packit |
a07778 |
"Unable to get domain disk stats");
|
|
Packit |
a07778 |
goto end;
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
ret = g_slice_new(GVirDomainDiskStats);
|
|
Packit |
a07778 |
ret->rd_req = stats.rd_req;
|
|
Packit |
a07778 |
ret->rd_bytes = stats.rd_bytes;
|
|
Packit |
a07778 |
ret->wr_req = stats.wr_req;
|
|
Packit |
a07778 |
ret->wr_bytes = stats.wr_bytes;
|
|
Packit |
a07778 |
ret->errs = stats.errs;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
end:
|
|
Packit |
a07778 |
virDomainFree(handle);
|
|
Packit |
a07778 |
return ret;
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
/**
|
|
Packit |
a07778 |
* gvir_domain_disk_resize:
|
|
Packit |
a07778 |
* @self: the domain disk
|
|
Packit |
a07778 |
* @size: new size of the block image in kilobytes
|
|
Packit |
a07778 |
* @flags: flags, currently unused. Pass '0'.
|
|
Packit |
a07778 |
* @err: placeholder for an error, or NULL
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* This function resize the disk of a running domain.
|
|
Packit |
a07778 |
*
|
|
Packit |
a07778 |
* Returns: TRUE if size was successfully changed, FALSE otherwise.
|
|
Packit |
a07778 |
**/
|
|
Packit |
a07778 |
gboolean gvir_domain_disk_resize(GVirDomainDisk *self,
|
|
Packit |
a07778 |
guint64 size,
|
|
Packit |
a07778 |
guint flags,
|
|
Packit |
a07778 |
GError **err)
|
|
Packit |
a07778 |
{
|
|
Packit |
a07778 |
gboolean ret = FALSE;
|
|
Packit |
a07778 |
virDomainPtr handle;
|
|
Packit |
a07778 |
const gchar *path;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), FALSE);
|
|
Packit |
a07778 |
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self));
|
|
Packit |
a07778 |
path = gvir_domain_disk_get_path (self);
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
if (virDomainBlockResize(handle, path, size, flags) < 0) {
|
|
Packit |
a07778 |
gvir_set_error_literal(err, GVIR_DOMAIN_DISK_ERROR,
|
|
Packit |
a07778 |
0,
|
|
Packit |
a07778 |
"Failed to resize domain disk");
|
|
Packit |
a07778 |
goto end;
|
|
Packit |
a07778 |
}
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
ret = TRUE;
|
|
Packit |
a07778 |
|
|
Packit |
a07778 |
end:
|
|
Packit |
a07778 |
virDomainFree(handle);
|
|
Packit |
a07778 |
return ret;
|
|
Packit |
a07778 |
}
|