1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-07 21:18:59 +03:00

Update error return and comments for lvm_list_vg_names/uuids.

The two liblvm functions that return a list of vgnames and vguuids use
cmd->mem to allocate the list.  Make it clear to the caller that this
memory will be freed when the LVM handle is freed.

Clean up and clarify the return value of the functions.  In the
case of a memory allocation error, add a couple log_errnos to the internal
code, and make it clear that memory allocation returns a NULL pointer.
If there are no VGs in the system, the list returned is an empty list.

Make a note of the fact that currently we return hidden VG names, how
these can be detected (always start with "#"), and that they should
not be used.


Author: Dave Wysochanski <dwysocha@redhat.com>
This commit is contained in:
Dave Wysochanski 2009-07-27 11:00:17 +00:00
parent f6b1eaf700
commit 0589e19fd7
4 changed files with 27 additions and 8 deletions
lib
cache
datastruct
liblvm

View File

@ -563,14 +563,14 @@ struct dm_list *lvmcache_get_vgnames(struct cmd_context *cmd, int full_scan)
lvmcache_label_scan(cmd, full_scan);
if (!(vgnames = str_list_create(cmd->mem))) {
log_error("vgnames list allocation failed");
log_errno(ENOMEM, "vgnames list allocation failed");
return NULL;
}
dm_list_iterate_items(vginfo, &_vginfos) {
if (!str_list_add(cmd->mem, vgnames,
dm_pool_strdup(cmd->mem, vginfo->vgname))) {
log_error("strlist allocation failed");
log_errno(ENOMEM, "strlist allocation failed");
return NULL;
}
}

View File

@ -20,8 +20,10 @@ struct dm_list *str_list_create(struct dm_pool *mem)
{
struct dm_list *sl;
if (!(sl = dm_pool_alloc(mem, sizeof(struct dm_list))))
return_NULL;
if (!(sl = dm_pool_alloc(mem, sizeof(struct dm_list)))) {
log_errno(ENOMEM, "str_list allocation failed");
return NULL;
}
dm_list_init(sl);

View File

@ -185,8 +185,13 @@ int lvm_scan(lvm_t libh);
/**
* Return the list of volume group names.
*
* The memory allocated for the list is tied to the lvm_t handle and will be
* released when lvm_destroy is called.
*
* NOTE: This function will _NOT_ scan devices in the system for LVM metadata.
* To scan the system, use lvm_scan.
* NOTE: This function currently returns hidden VG names. These names always
* begin with a "#" and should be filtered out and not used.
*
* To process the list, use the dm_list iterator functions. For example:
* vg_t *vg;
@ -203,23 +208,30 @@ int lvm_scan(lvm_t libh);
*
*
* \return A list of struct lvm_str_list
* If no VGs exist on the system, NULL is returned.
*
* FIXME: handle list memory cleanup
* NULL is returned if unable to allocate memory.
* An empty list (verify with dm_list_empty) is returned if no VGs
* exist on the system.
*/
struct dm_list *lvm_list_vg_names(lvm_t libh);
/**
* Return the list of volume group uuids.
*
* The memory allocated for the list is tied to the lvm_t handle and will be
* released when lvm_destroy is called.
*
* NOTE: This function will _NOT_ scan devices in the system for LVM metadata.
* To scan the system, use lvm_scan.
* NOTE: This function currently returns hidden VG names. These names always
* begin with a "#" and should be filtered out and not used.
*
* \param libh
* Handle obtained from lvm_create.
*
* \return List of copied uuid strings.
* If no VGs exist on the system, NULL is returned.
* NULL is returned if unable to allocate memory.
* An empty list (verify with dm_list_empty) is returned if no VGs
* exist on the system.
*/
struct dm_list *lvm_list_vg_uuids(lvm_t libh);

View File

@ -240,6 +240,11 @@ char *lvm_vg_get_name(const vg_t *vg)
return name;
}
/*
* FIXME: These functions currently return hidden VGs. We should either filter
* these out and not return them in the list, or export something like
* is_orphan_vg and tell the caller to filter.
*/
struct dm_list *lvm_list_vg_names(lvm_t libh)
{
return get_vgnames((struct cmd_context *)libh, 0);