/** * gvir_storage_pool_get_info: * @pool: the storage_pool * @err: Place-holder for possible errors * * Returns: (transfer full): the info. The returned pointer should be * freed using #g_boxed_free() when no longer needed. */ GVirStoragePoolInfo *gvir_storage_pool_get_info(GVirStoragePool *pool, GError **err) { GVirStoragePoolPrivate *priv; virStoragePoolInfo info; GVirStoragePoolInfo *ret; g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL); g_return_val_if_fail(err == NULL || *err == NULL, NULL); priv = pool->priv; if (virStoragePoolGetInfo(priv->handle, &info) < 0) { if (err) *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, 0, "Unable to get storage pool info"); return NULL; } ret = g_slice_new(GVirStoragePoolInfo); ret->state = info.state; ret->capacity = info.capacity; ret->allocation = info.allocation; ret->available = info.available; return ret; }
/** * gvir_storage_pool_refresh_finish: * @pool: the storage pool * @result: (transfer none): async method result */ gboolean gvir_storage_pool_refresh_finish(GVirStoragePool *pool, GAsyncResult *result, GError **err) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); g_return_val_if_fail(g_task_is_valid(result, pool), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); return g_task_propagate_boolean(G_TASK(result), err); }
const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool) { const char *name; g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL); if (!(name = virStoragePoolGetName(pool->priv->handle))) gvir_warning("Failed to get storage_pool name on %p", pool->priv->handle); return name; }
/** * gvir_storage_pool_create_volume: * @pool: the storage pool in which to create the volume * @conf: the configuration for the new volume * @err: Place-holder for possible errors * * Returns: (transfer full): the newly created volume. The returned object * should be unreffed with g_object_unref() when no longer needed. */ GVirStorageVol *gvir_storage_pool_create_volume (GVirStoragePool *pool, GVirConfigStorageVol *conf, GError **err) { const gchar *xml; virStorageVolPtr handle; GVirStoragePoolPrivate *priv; g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL); g_return_val_if_fail(GVIR_CONFIG_IS_STORAGE_VOL(conf), NULL); g_return_val_if_fail(err == NULL || *err == NULL, NULL); xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf)); g_return_val_if_fail(xml != NULL, NULL); priv = pool->priv; if (!(handle = virStorageVolCreateXML(priv->handle, xml, 0))) { gvir_set_error_literal(err, GVIR_STORAGE_POOL_ERROR, 0, "Failed to create volume"); return NULL; } GVirStorageVol *volume; const char *name; volume = GVIR_STORAGE_VOL(g_object_new(GVIR_TYPE_STORAGE_VOL, "handle", handle, "pool", pool, NULL)); name = gvir_storage_vol_get_name(volume); if (name == NULL) { g_object_unref(G_OBJECT(volume)); return NULL; } g_mutex_lock(priv->lock); if (priv->volumes != NULL) { g_hash_table_insert(priv->volumes, g_strdup(name), volume); } else { g_warn_if_reached(); g_object_unref(G_OBJECT(volume)); g_mutex_unlock(priv->lock); return NULL; } g_mutex_unlock(priv->lock); return g_object_ref(volume); }
/** * gvir_storage_pool_refresh_finish: * @pool: the storage pool * @result: (transfer none): async method result */ gboolean gvir_storage_pool_refresh_finish(GVirStoragePool *pool, GAsyncResult *result, GError **err) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool), gvir_storage_pool_refresh_async), FALSE); if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) return FALSE; return TRUE; }
/** * gvir_storage_pool_build: * @pool: the storage pool to build * @flags: the flags * @err: return location for any #GError * * Return value: #True on success, #False otherwise. */ gboolean gvir_storage_pool_build (GVirStoragePool *pool, guint flags, GError **err) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); if (virStoragePoolBuild(pool->priv->handle, flags)) { gvir_set_error_literal(err, GVIR_STORAGE_POOL_ERROR, 0, "Failed to build storage pool"); return FALSE; } return TRUE; }
/** * gvir_storage_pool_refresh_async: * @pool: the storage pool * @cancellable: (allow-none)(transfer none): cancellation object * @callback: (scope async): completion callback * @user_data: (closure): opaque data for callback */ void gvir_storage_pool_refresh_async(GVirStoragePool *pool, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); task = g_task_new(G_OBJECT(pool), cancellable, callback, user_data); g_task_run_in_thread(task, gvir_storage_pool_refresh_helper); g_object_unref(task); }
/** * gvir_storage_pool_get_volume: * @pool: the storage pool * @name: Name of the requested storage volume * * Return value: (transfer full): the #GVirStorageVol, or NULL. The * returned object should be unreffed with g_object_unref() when no longer * needed. */ GVirStorageVol *gvir_storage_pool_get_volume(GVirStoragePool *pool, const gchar *name) { GVirStoragePoolPrivate *priv; GVirStorageVol *volume; g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL); priv = pool->priv; g_mutex_lock(priv->lock); volume = g_hash_table_lookup(priv->volumes, name); if (volume) g_object_ref(volume); g_mutex_unlock(priv->lock); return volume; }
/** * gvir_storage_pool_get_volumes: * @pool: the storage pool * * Return value: (element-type LibvirtGObject.StorageVol) (transfer full): * List of #GVirStorageVol. The returned list should be freed with * g_list_free(), after its elements have been unreffed with * g_object_unref(). */ GList *gvir_storage_pool_get_volumes(GVirStoragePool *pool) { GVirStoragePoolPrivate *priv; GList *volumes = NULL; g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL); priv = pool->priv; g_mutex_lock(priv->lock); if (priv->volumes != NULL) { volumes = g_hash_table_get_values(priv->volumes); g_list_foreach(volumes, gvir_storage_vol_ref, NULL); } g_mutex_unlock(priv->lock); return volumes; }
/** * gvir_storage_pool_refresh_async: * @pool: the storage pool * @cancellable: (allow-none)(transfer none): cancellation object * @callback: (scope async): completion callback * @user_data: (closure): opaque data for callback */ void gvir_storage_pool_refresh_async(GVirStoragePool *pool, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *res; g_return_if_fail(GVIR_IS_STORAGE_POOL(pool)); g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); res = g_simple_async_result_new(G_OBJECT(pool), callback, user_data, gvir_storage_pool_refresh_async); g_simple_async_result_run_in_thread(res, gvir_storage_pool_refresh_helper, G_PRIORITY_DEFAULT, cancellable); g_object_unref(res); }
/** * gvir_storage_pool_get_config: * @pool: the storage_pool * @flags: the flags * @err: Place-holder for possible errors * * Returns: (transfer full): the config. The returned object should be * unreffed with g_object_unref() when no longer needed. */ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, guint flags, GError **err) { GVirStoragePoolPrivate *priv; gchar *xml; g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL); g_return_val_if_fail(err == NULL || *err == NULL, NULL); priv = pool->priv; if (!(xml = virStoragePoolGetXMLDesc(priv->handle, flags))) { gvir_set_error_literal(err, GVIR_STORAGE_POOL_ERROR, 0, "Unable to get storage_pool XML config"); return NULL; } GVirConfigStoragePool *conf = gvir_config_storage_pool_new_from_xml(xml, err); free(xml); return conf; }
/** * gvir_storage_pool_refresh: * @pool: the storage pool * @cancellable: (allow-none)(transfer none): cancellation object */ gboolean gvir_storage_pool_refresh(GVirStoragePool *pool, GCancellable *cancellable, GError **err) { GVirStoragePoolPrivate *priv; GHashTable *vol_hash; gchar **volumes = NULL; gint nvolumes = 0; gboolean ret = FALSE; gint i; virStoragePoolPtr vpool = NULL; GError *lerr = NULL; g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); g_return_val_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable), FALSE); g_return_val_if_fail(err == NULL || *err == NULL, FALSE); priv = pool->priv; vpool = priv->handle; if (virStoragePoolRefresh(vpool, 0) < 0) { gvir_set_error_literal(err, GVIR_STORAGE_POOL_ERROR, 0, "Unable to refresh storage pool"); goto cleanup; } volumes = fetch_list(vpool, "Storage Volumes", virStoragePoolNumOfVolumes, virStoragePoolListVolumes, cancellable, &nvolumes, &lerr); if (lerr) { g_propagate_error(err, lerr); lerr = NULL; goto cleanup; } if (g_cancellable_set_error_if_cancelled(cancellable, err)) goto cleanup; vol_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref); for (i = 0 ; i < nvolumes ; i++) { if (g_cancellable_set_error_if_cancelled(cancellable, err)) goto cleanup; virStorageVolPtr vvolume; GVirStorageVol *volume; vvolume = virStorageVolLookupByName(vpool, volumes[i]); if (!vvolume) continue; volume = GVIR_STORAGE_VOL(g_object_new(GVIR_TYPE_STORAGE_VOL, "handle", vvolume, "pool", pool, NULL)); virStorageVolFree(vvolume); g_hash_table_insert(vol_hash, g_strdup(volumes[i]), volume); } g_mutex_lock(priv->lock); if (priv->volumes) g_hash_table_unref(priv->volumes); priv->volumes = vol_hash; g_mutex_unlock(priv->lock); ret = TRUE; cleanup: for (i = 0 ; i < nvolumes ; i++) g_free(volumes[i]); g_free(volumes); return ret; }
gboolean gvir_storage_pool_get_persistent(GVirStoragePool *pool) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE); return virStoragePoolIsPersistent(pool->priv->handle); }
const gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool) { g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL); return pool->priv->uuid; }