Blame libvirt-gconfig/libvirt-gconfig-storage-pool.c

Packit a07778
/*
Packit a07778
 * libvirt-gconfig-storage-pool.c: libvirt storage pool configuration
Packit a07778
 *
Packit a07778
 * Copyright (C) 2008 Daniel P. Berrange
Packit a07778
 * Copyright (C) 2010-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
 * Authors: Daniel P. Berrange <berrange@redhat.com>
Packit a07778
 *          Christophe Fergeau <cfergeau@redhat.com>
Packit a07778
 */
Packit a07778
Packit a07778
#include <config.h>
Packit a07778
Packit a07778
#include "libvirt-gconfig/libvirt-gconfig.h"
Packit a07778
#include "libvirt-gconfig/libvirt-gconfig-private.h"
Packit a07778
Packit a07778
#define GVIR_CONFIG_STORAGE_POOL_GET_PRIVATE(obj)                         \
Packit a07778
        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_STORAGE_POOL, GVirConfigStoragePoolPrivate))
Packit a07778
Packit a07778
struct _GVirConfigStoragePoolPrivate
Packit a07778
{
Packit a07778
    gboolean unused;
Packit a07778
};
Packit a07778
Packit a07778
G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigStoragePool, gvir_config_storage_pool, GVIR_CONFIG_TYPE_OBJECT);
Packit a07778
Packit a07778
Packit a07778
static void gvir_config_storage_pool_class_init(GVirConfigStoragePoolClass *klass G_GNUC_UNUSED)
Packit a07778
{
Packit a07778
}
Packit a07778
Packit a07778
Packit a07778
static void gvir_config_storage_pool_init(GVirConfigStoragePool *pool)
Packit a07778
{
Packit a07778
    pool->priv = GVIR_CONFIG_STORAGE_POOL_GET_PRIVATE(pool);
Packit a07778
}
Packit a07778
Packit a07778
Packit a07778
GVirConfigStoragePool *gvir_config_storage_pool_new(void)
Packit a07778
{
Packit a07778
    GVirConfigObject *object;
Packit a07778
Packit a07778
    object = gvir_config_object_new(GVIR_CONFIG_TYPE_STORAGE_POOL,
Packit a07778
                                    "pool",
Packit a07778
                                    DATADIR "/libvirt/schemas/storagepool.rng");
Packit a07778
    return GVIR_CONFIG_STORAGE_POOL(object);
Packit a07778
}
Packit a07778
Packit a07778
GVirConfigStoragePool *gvir_config_storage_pool_new_from_xml(const gchar *xml,
Packit a07778
                                                             GError **error)
Packit a07778
{
Packit a07778
    GVirConfigObject *object;
Packit a07778
Packit a07778
    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_STORAGE_POOL,
Packit a07778
                                             "pool",
Packit a07778
                                             DATADIR "/libvirt/schemas/storagepool.rng",
Packit a07778
                                             xml, error);
Packit a07778
    return GVIR_CONFIG_STORAGE_POOL(object);
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_get_pool_type:
Packit a07778
 * @pool: a #GVirConfigStoragePool
Packit a07778
 *
Packit a07778
 * Gets the type of the pool.
Packit a07778
 *
Packit a07778
 * Returns: #Gname of @pool.
Packit a07778
 */
Packit a07778
GVirConfigStoragePoolType gvir_config_storage_pool_get_pool_type(GVirConfigStoragePool *pool)
Packit a07778
{
Packit a07778
    g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool),
Packit a07778
                         GVIR_CONFIG_STORAGE_POOL_TYPE_DIR);
Packit a07778
Packit a07778
    return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                                  NULL, "type",
Packit a07778
                                                  GVIR_CONFIG_TYPE_STORAGE_POOL_TYPE,
Packit a07778
                                                  GVIR_CONFIG_STORAGE_POOL_TYPE_DIR);
Packit a07778
}
Packit a07778
Packit a07778
void gvir_config_storage_pool_set_pool_type(GVirConfigStoragePool *pool,
Packit a07778
                                            GVirConfigStoragePoolType type)
Packit a07778
{
Packit a07778
    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
Packit a07778
Packit a07778
    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                               "type",
Packit a07778
                                               GVIR_CONFIG_TYPE_STORAGE_POOL_TYPE,
Packit a07778
                                               type,
Packit a07778
                                               NULL);
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_get_name:
Packit a07778
 * @pool: a #GVirConfigStoragePool
Packit a07778
 *
Packit a07778
 * Gets the name of the pool.
Packit a07778
 *
Packit a07778
 * Returns: name of @pool.
Packit a07778
 */
Packit a07778
const char *gvir_config_storage_pool_get_name(GVirConfigStoragePool *pool)
Packit a07778
{
Packit a07778
    g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), NULL);
Packit a07778
Packit a07778
    return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                               "name");
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_set_name:
Packit a07778
 * @name: (allow-none):
Packit a07778
 */
Packit a07778
void gvir_config_storage_pool_set_name(GVirConfigStoragePool *pool,
Packit a07778
                                       const char *name)
Packit a07778
{
Packit a07778
    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
Packit a07778
Packit a07778
    gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                        "name", name);
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_get_uuid:
Packit a07778
 * @pool: a #GVirConfigStoragePool
Packit a07778
 *
Packit a07778
 * Gets the unique identifier for @pool.
Packit a07778
 *
Packit a07778
 * Returns: unique identifier for @pool.
Packit a07778
 */
Packit a07778
const char *gvir_config_storage_pool_get_uuid(GVirConfigStoragePool *pool)
Packit a07778
{
Packit a07778
    g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), NULL);
Packit a07778
Packit a07778
    return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                               "uuid");
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_set_uuid:
Packit a07778
 * @uuid: (allow-none):
Packit a07778
 */
Packit a07778
void gvir_config_storage_pool_set_uuid(GVirConfigStoragePool *pool,
Packit a07778
                                       const char *uuid)
Packit a07778
{
Packit a07778
    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
Packit a07778
Packit a07778
    gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                        "uuid", uuid);
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_get_capacity:
Packit a07778
 * @pool: a #GVirConfigStoragePool
Packit a07778
 *
Packit a07778
 * Gets the total storage capacity for the pool.
Packit a07778
 *
Packit a07778
 * Returns: total storage capacity in bytes.
Packit a07778
 */
Packit a07778
guint64 gvir_config_storage_pool_get_capacity(GVirConfigStoragePool *pool)
Packit a07778
{
Packit a07778
    g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), 0);
Packit a07778
Packit a07778
    return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                                      "capacity");
Packit a07778
}
Packit a07778
Packit a07778
void gvir_config_storage_pool_set_capacity(GVirConfigStoragePool *pool,
Packit a07778
                                           guint64 capacity)
Packit a07778
{
Packit a07778
    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
Packit a07778
Packit a07778
    gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                               "capacity", capacity);
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_get_allocation:
Packit a07778
 * @pool: a #GVirConfigStoragePool
Packit a07778
 *
Packit a07778
 * Gets the total storage allocation for the pool.
Packit a07778
 *
Packit a07778
 * Returns: total storage allocation in bytes.
Packit a07778
 */
Packit a07778
guint64 gvir_config_storage_pool_get_allocation(GVirConfigStoragePool *pool)
Packit a07778
{
Packit a07778
    g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), 0);
Packit a07778
Packit a07778
    return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                                      "allocation");
Packit a07778
}
Packit a07778
Packit a07778
void gvir_config_storage_pool_set_allocation(GVirConfigStoragePool *pool,
Packit a07778
                                             guint64 allocation)
Packit a07778
{
Packit a07778
    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
Packit a07778
Packit a07778
    gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                               "allocation", allocation);
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_get_available:
Packit a07778
 * @pool: a #GVirConfigStoragePool
Packit a07778
 *
Packit a07778
 * Gets the free space available for allocating new volumes in the pool.
Packit a07778
 *
Packit a07778
 * Returns: free space available in bytes.
Packit a07778
 */
Packit a07778
guint64 gvir_config_storage_pool_get_available(GVirConfigStoragePool *pool)
Packit a07778
{
Packit a07778
    g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), 0);
Packit a07778
Packit a07778
    return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                                      "available");
Packit a07778
}
Packit a07778
Packit a07778
void gvir_config_storage_pool_set_available(GVirConfigStoragePool *pool,
Packit a07778
                                            guint64 available)
Packit a07778
{
Packit a07778
    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
Packit a07778
Packit a07778
    gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                               "available", available);
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_get_source:
Packit a07778
 * @pool: a #GVirConfigStoragePool
Packit a07778
 *
Packit a07778
 * Gets the source for @pool
Packit a07778
 *
Packit a07778
 * Returns: (transfer full): a new #GVirConfigStoragePoolSource instance.
Packit a07778
 */
Packit a07778
GVirConfigStoragePoolSource *gvir_config_storage_pool_get_source(GVirConfigStoragePool *pool)
Packit a07778
{
Packit a07778
    GVirConfigObject *object;
Packit a07778
Packit a07778
    g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), NULL);
Packit a07778
Packit a07778
    object = gvir_config_object_get_child_with_type
Packit a07778
                                (GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                 "source",
Packit a07778
                                 GVIR_CONFIG_TYPE_STORAGE_POOL_SOURCE);
Packit a07778
Packit a07778
    return GVIR_CONFIG_STORAGE_POOL_SOURCE(object);
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_set_source:
Packit a07778
 * @source: (allow-none):
Packit a07778
 */
Packit a07778
void gvir_config_storage_pool_set_source(GVirConfigStoragePool *pool,
Packit a07778
                                         GVirConfigStoragePoolSource *source)
Packit a07778
{
Packit a07778
    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
Packit a07778
    g_return_if_fail(source == NULL ||
Packit a07778
                     GVIR_CONFIG_IS_STORAGE_POOL_SOURCE(source));
Packit a07778
Packit a07778
    gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                      "source",
Packit a07778
                                      GVIR_CONFIG_OBJECT(source));
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_get_target:
Packit a07778
 * @pool: a #GVirConfigStoragePool
Packit a07778
 *
Packit a07778
 * Gets the target for @pool
Packit a07778
 *
Packit a07778
 * Returns: (transfer full): a new #GVirConfigStoragePoolTarget instance.
Packit a07778
 */
Packit a07778
GVirConfigStoragePoolTarget *gvir_config_storage_pool_get_target(GVirConfigStoragePool *pool)
Packit a07778
{
Packit a07778
    GVirConfigObject *object;
Packit a07778
Packit a07778
    g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool), NULL);
Packit a07778
Packit a07778
    object = gvir_config_object_get_child_with_type
Packit a07778
                                (GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                 "target",
Packit a07778
                                 GVIR_CONFIG_TYPE_STORAGE_POOL_TARGET);
Packit a07778
Packit a07778
    return GVIR_CONFIG_STORAGE_POOL_TARGET(object);
Packit a07778
}
Packit a07778
Packit a07778
/**
Packit a07778
 * gvir_config_storage_pool_set_target:
Packit a07778
 * @target: (allow-none):
Packit a07778
 */
Packit a07778
void gvir_config_storage_pool_set_target(GVirConfigStoragePool *pool,
Packit a07778
                                        GVirConfigStoragePoolTarget *target)
Packit a07778
{
Packit a07778
    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL(pool));
Packit a07778
    g_return_if_fail(target == NULL ||
Packit a07778
                     GVIR_CONFIG_IS_STORAGE_POOL_TARGET(target));
Packit a07778
Packit a07778
    gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(pool),
Packit a07778
                                      "target",
Packit a07778
                                      GVIR_CONFIG_OBJECT(target));
Packit a07778
}