|
Packit Service |
ea0369 |
/*
|
|
Packit Service |
ea0369 |
* libvirt-gconfig-storage-pool.c: libvirt storage pool configuration
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Copyright (C) 2008 Daniel P. Berrange
|
|
Packit Service |
ea0369 |
* Copyright (C) 2010-2011 Red Hat, Inc.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
ea0369 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
ea0369 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
ea0369 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
ea0369 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
ea0369 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
ea0369 |
* Lesser General Public License for more details.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
ea0369 |
* License along with this library. If not, see
|
|
Packit Service |
ea0369 |
* <http://www.gnu.org/licenses/>.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Authors: Daniel P. Berrange <berrange@redhat.com>
|
|
Packit Service |
ea0369 |
* Christophe Fergeau <cfergeau@redhat.com>
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
#include <config.h>
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
#include "libvirt-gconfig/libvirt-gconfig.h"
|
|
Packit Service |
ea0369 |
#include "libvirt-gconfig/libvirt-gconfig-private.h"
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
#define GVIR_CONFIG_STORAGE_POOL_GET_PRIVATE(obj) \
|
|
Packit Service |
ea0369 |
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_STORAGE_POOL, GVirConfigStoragePoolPrivate))
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
struct _GVirConfigStoragePoolPrivate
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
gboolean unused;
|
|
Packit Service |
ea0369 |
};
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigStoragePool, gvir_config_storage_pool, GVIR_CONFIG_TYPE_OBJECT);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
static void gvir_config_storage_pool_class_init(GVirConfigStoragePoolClass *klass G_GNUC_UNUSED)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
static void gvir_config_storage_pool_init(GVirConfigStoragePool *pool)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
pool->priv = GVIR_CONFIG_STORAGE_POOL_GET_PRIVATE(pool);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
GVirConfigStoragePool *gvir_config_storage_pool_new(void)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
GVirConfigObject *object;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
object = gvir_config_object_new(GVIR_CONFIG_TYPE_STORAGE_POOL,
|
|
Packit Service |
ea0369 |
"pool",
|
|
Packit Service |
ea0369 |
DATADIR "/libvirt/schemas/storagepool.rng");
|
|
Packit Service |
ea0369 |
return GVIR_CONFIG_STORAGE_POOL(object);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
GVirConfigStoragePool *gvir_config_storage_pool_new_from_xml(const gchar *xml,
|
|
Packit Service |
ea0369 |
GError **error)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
GVirConfigObject *object;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_STORAGE_POOL,
|
|
Packit Service |
ea0369 |
"pool",
|
|
Packit Service |
ea0369 |
DATADIR "/libvirt/schemas/storagepool.rng",
|
|
Packit Service |
ea0369 |
xml, error);
|
|
Packit Service |
ea0369 |
return GVIR_CONFIG_STORAGE_POOL(object);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_get_pool_type:
|
|
Packit Service |
ea0369 |
* @pool: a #GVirConfigStoragePool
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Gets the type of the pool.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: #Gname of @pool.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
GVirConfigStoragePoolType gvir_config_storage_pool_get_pool_type(GVirConfigStoragePool *pool)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool),
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_STORAGE_POOL_TYPE_DIR);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
NULL, "type",
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_TYPE_STORAGE_POOL_TYPE,
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_STORAGE_POOL_TYPE_DIR);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
void gvir_config_storage_pool_set_pool_type(GVirConfigStoragePool *pool,
|
|
Packit Service |
ea0369 |
GVirConfigStoragePoolType type)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"type",
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_TYPE_STORAGE_POOL_TYPE,
|
|
Packit Service |
ea0369 |
type,
|
|
Packit Service |
ea0369 |
NULL);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_get_name:
|
|
Packit Service |
ea0369 |
* @pool: a #GVirConfigStoragePool
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Gets the name of the pool.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: name of @pool.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
const char *gvir_config_storage_pool_get_name(GVirConfigStoragePool *pool)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), NULL);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"name");
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_set_name:
|
|
Packit Service |
ea0369 |
* @name: (allow-none):
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
void gvir_config_storage_pool_set_name(GVirConfigStoragePool *pool,
|
|
Packit Service |
ea0369 |
const char *name)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"name", name);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_get_uuid:
|
|
Packit Service |
ea0369 |
* @pool: a #GVirConfigStoragePool
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Gets the unique identifier for @pool.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: unique identifier for @pool.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
const char *gvir_config_storage_pool_get_uuid(GVirConfigStoragePool *pool)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), NULL);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"uuid");
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_set_uuid:
|
|
Packit Service |
ea0369 |
* @uuid: (allow-none):
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
void gvir_config_storage_pool_set_uuid(GVirConfigStoragePool *pool,
|
|
Packit Service |
ea0369 |
const char *uuid)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"uuid", uuid);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_get_capacity:
|
|
Packit Service |
ea0369 |
* @pool: a #GVirConfigStoragePool
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Gets the total storage capacity for the pool.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: total storage capacity in bytes.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
guint64 gvir_config_storage_pool_get_capacity(GVirConfigStoragePool *pool)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), 0);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"capacity");
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
void gvir_config_storage_pool_set_capacity(GVirConfigStoragePool *pool,
|
|
Packit Service |
ea0369 |
guint64 capacity)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"capacity", capacity);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_get_allocation:
|
|
Packit Service |
ea0369 |
* @pool: a #GVirConfigStoragePool
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Gets the total storage allocation for the pool.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: total storage allocation in bytes.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
guint64 gvir_config_storage_pool_get_allocation(GVirConfigStoragePool *pool)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), 0);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"allocation");
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
void gvir_config_storage_pool_set_allocation(GVirConfigStoragePool *pool,
|
|
Packit Service |
ea0369 |
guint64 allocation)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"allocation", allocation);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_get_available:
|
|
Packit Service |
ea0369 |
* @pool: a #GVirConfigStoragePool
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Gets the free space available for allocating new volumes in the pool.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: free space available in bytes.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
guint64 gvir_config_storage_pool_get_available(GVirConfigStoragePool *pool)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), 0);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"available");
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
void gvir_config_storage_pool_set_available(GVirConfigStoragePool *pool,
|
|
Packit Service |
ea0369 |
guint64 available)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"available", available);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_get_source:
|
|
Packit Service |
ea0369 |
* @pool: a #GVirConfigStoragePool
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Gets the source for @pool
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: (transfer full): a new #GVirConfigStoragePoolSource instance.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
GVirConfigStoragePoolSource *gvir_config_storage_pool_get_source(GVirConfigStoragePool *pool)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
GVirConfigObject *object;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), NULL);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
object = gvir_config_object_get_child_with_type
|
|
Packit Service |
ea0369 |
(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"source",
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_TYPE_STORAGE_POOL_SOURCE);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return GVIR_CONFIG_STORAGE_POOL_SOURCE(object);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_set_source:
|
|
Packit Service |
ea0369 |
* @source: (allow-none):
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
void gvir_config_storage_pool_set_source(GVirConfigStoragePool *pool,
|
|
Packit Service |
ea0369 |
GVirConfigStoragePoolSource *source)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
|
|
Packit Service |
ea0369 |
g_return_if_fail(source == NULL ||
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_IS_STORAGE_POOL_SOURCE(source));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"source",
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_OBJECT(source));
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_get_target:
|
|
Packit Service |
ea0369 |
* @pool: a #GVirConfigStoragePool
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Gets the target for @pool
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: (transfer full): a new #GVirConfigStoragePoolTarget instance.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
GVirConfigStoragePoolTarget *gvir_config_storage_pool_get_target(GVirConfigStoragePool *pool)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
GVirConfigObject *object;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), NULL);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
object = gvir_config_object_get_child_with_type
|
|
Packit Service |
ea0369 |
(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"target",
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_TYPE_STORAGE_POOL_TARGET);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return GVIR_CONFIG_STORAGE_POOL_TARGET(object);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_storage_pool_set_target:
|
|
Packit Service |
ea0369 |
* @target: (allow-none):
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
void gvir_config_storage_pool_set_target(GVirConfigStoragePool *pool,
|
|
Packit Service |
ea0369 |
GVirConfigStoragePoolTarget *target)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
|
|
Packit Service |
ea0369 |
g_return_if_fail(target == NULL ||
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_IS_STORAGE_POOL_TARGET(target));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(pool),
|
|
Packit Service |
ea0369 |
"target",
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_OBJECT(target));
|
|
Packit Service |
ea0369 |
}
|