1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-08 08:58:50 +03:00

Add lvm_{pv|vg|lv}_get_{uuid|name}.

Caller must free the memory of the uuid / name returned.
This may not be the best memory management policy since it may lead to
memory leaks if the caller has code like this:
if (!lvm_vg_get_name(vg))

Maybe we don't care - if we do we can use pools tied to handles later
or some other scheme.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
Acked-by: Thomas Woerner <twoerner@redhat.com>
This commit is contained in:
Dave Wysochanski 2009-07-23 23:40:05 +00:00
parent 6c6c821445
commit f032ed7498
6 changed files with 126 additions and 0 deletions

View File

@ -1,6 +1,12 @@
lvm_create
lvm_destroy
lvm_reload_config
lvm_pv_get_uuid
lvm_vg_get_uuid
lvm_lv_get_uuid
lvm_pv_get_name
lvm_vg_get_name
lvm_lv_get_name
lvm_vg_create
lvm_vg_extend
lvm_vg_set_extent_size

View File

@ -18,6 +18,8 @@ VPATH = @srcdir@
SOURCES =\
lvm_base.c \
lvm_lv.c \
lvm_pv.c \
lvm_vg.c
LIB_NAME = liblvm2app

View File

@ -197,6 +197,22 @@ int lvm_vg_write(vg_t *vg);
*/
int lvm_vg_remove(vg_t *vg);
/**
* Get the current name or uuid of a PV, VG, or LV.
*
* Returns a copy of the current name or uuid for the given PV,
* VG, or LV.
*
* Memory is allocated using malloc() and caller must free the memory
* using free().
*/
char *lvm_pv_get_uuid(const pv_t *pv);
char *lvm_vg_get_uuid(const vg_t *vg);
char *lvm_lv_get_uuid(const lv_t *lv);
char *lvm_pv_get_name(const pv_t *pv);
char *lvm_vg_get_name(const vg_t *vg);
char *lvm_lv_get_name(const lv_t *lv);
/**
* Close a VG opened with lvm_vg_create
*

40
liblvm/lvm_lv.c Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2008,2009 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v.2.1.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lib.h"
#include "lvm.h"
#include "metadata-exported.h"
#include "lvm-string.h"
char *lvm_lv_get_uuid(const lv_t *lv)
{
char uuid[64] __attribute((aligned(8)));
if (!id_write_format(&lv->lvid.id[1], uuid, sizeof(uuid))) {
log_error("Internal error converting uuid");
return NULL;
}
return strndup((const char *)uuid, 64);
}
char *lvm_lv_get_name(const lv_t *lv)
{
char *name;
name = malloc(NAME_LEN + 1);
strncpy(name, (const char *)lv->name, NAME_LEN);
name[NAME_LEN] = '\0';
return name;
}

40
liblvm/lvm_pv.c Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2008,2009 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License v.2.1.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lib.h"
#include "lvm.h"
#include "metadata-exported.h"
#include "lvm-string.h"
char *lvm_pv_get_uuid(const pv_t *pv)
{
char uuid[64] __attribute((aligned(8)));
if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
log_error("Internal error converting uuid");
return NULL;
}
return strndup((const char *)uuid, 64);
}
char *lvm_pv_get_name(const pv_t *pv)
{
char *name;
name = malloc(NAME_LEN + 1);
strncpy(name, (const char *)pv_dev_name(pv), NAME_LEN);
name[NAME_LEN] = '\0';
return name;
}

View File

@ -21,6 +21,7 @@
#include "metadata-exported.h"
#include "archiver.h"
#include "locking.h"
#include "lvm-string.h"
vg_t *lvm_vg_create(lvm_t libh, const char *vg_name)
{
@ -166,3 +167,24 @@ struct dm_list *lvm_vg_list_lvs(vg_t *vg)
}
return list;
}
char *lvm_vg_get_uuid(const vg_t *vg)
{
char uuid[64] __attribute((aligned(8)));
if (!id_write_format(&vg->id, uuid, sizeof(uuid))) {
log_error("Internal error converting uuid");
return NULL;
}
return strndup((const char *)uuid, 64);
}
char *lvm_vg_get_name(const vg_t *vg)
{
char *name;
name = malloc(NAME_LEN + 1);
strncpy(name, (const char *)vg->name, NAME_LEN);
name[NAME_LEN] = '\0';
return name;
}