1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-02-27 01:57:55 +03:00

Use vg->vgmem to allocate vg/lv/pv string properties instead of dm_malloc/fr

Everywhere else in the API the caller can rely on lvm2app taking care of
memory allocation and free, so make the 'name' and 'uuid' properties of a
vg/lv/pv use the vg handle to allocate memory.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
This commit is contained in:
Dave Wysochanski 2010-04-19 15:22:24 +00:00
parent c7cc4b7ac2
commit 8fb6bd930b
4 changed files with 32 additions and 45 deletions

View File

@ -642,12 +642,12 @@ uint64_t lvm_vg_is_partial(vg_t vg);
uint64_t lvm_vg_get_seqno(const vg_t vg); uint64_t lvm_vg_get_seqno(const vg_t vg);
/** /**
* Get the current name of a volume group. * Get the current uuid of a volume group.
* *
* \memberof vg_t * \memberof vg_t
* *
* Memory is allocated using dm_malloc() and caller must free the memory * The memory allocated for the uuid is tied to the vg_t handle and will be
* using dm_free(). * released when lvm_vg_close() is called.
* *
* \param vg * \param vg
* VG handle obtained from lvm_vg_create or lvm_vg_open(). * VG handle obtained from lvm_vg_create or lvm_vg_open().
@ -655,15 +655,15 @@ uint64_t lvm_vg_get_seqno(const vg_t vg);
* \return * \return
* Copy of the uuid string. * Copy of the uuid string.
*/ */
char *lvm_vg_get_uuid(const vg_t vg); const char *lvm_vg_get_uuid(const vg_t vg);
/** /**
* Get the current uuid of a volume group. * Get the current name of a volume group.
* *
* \memberof vg_t * \memberof vg_t
* *
* Memory is allocated using dm_malloc() and caller must free the memory * The memory allocated for the name is tied to the vg_t handle and will be
* using dm_free(). * released when lvm_vg_close() is called.
* *
* \param vg * \param vg
* VG handle obtained from lvm_vg_create or lvm_vg_open(). * VG handle obtained from lvm_vg_create or lvm_vg_open().
@ -671,7 +671,7 @@ char *lvm_vg_get_uuid(const vg_t vg);
* \return * \return
* Copy of the name. * Copy of the name.
*/ */
char *lvm_vg_get_name(const vg_t vg); const char *lvm_vg_get_name(const vg_t vg);
/** /**
* Get the current size in bytes of a volume group. * Get the current size in bytes of a volume group.
@ -783,7 +783,7 @@ uint64_t lvm_vg_get_max_lv(const vg_t vg);
* \memberof vg_t * \memberof vg_t
* *
* The memory allocated for the list is tied to the vg_t handle and will be * The memory allocated for the list is tied to the vg_t handle and will be
* released when lvm_vg_close is called. * released when lvm_vg_close() is called.
* *
* To process the list, use the dm_list iterator functions. For example: * To process the list, use the dm_list iterator functions. For example:
* vg_t vg; * vg_t vg;
@ -896,7 +896,7 @@ int lvm_vg_remove_lv(lv_t lv);
* \return * \return
* Copy of the uuid string. * Copy of the uuid string.
*/ */
char *lvm_lv_get_uuid(const lv_t lv); const char *lvm_lv_get_uuid(const lv_t lv);
/** /**
* Get the current uuid of a logical volume. * Get the current uuid of a logical volume.
@ -912,7 +912,7 @@ char *lvm_lv_get_uuid(const lv_t lv);
* \return * \return
* Copy of the name. * Copy of the name.
*/ */
char *lvm_lv_get_name(const lv_t lv); const char *lvm_lv_get_name(const lv_t lv);
/** /**
* Get the current size in bytes of a logical volume. * Get the current size in bytes of a logical volume.
@ -1001,7 +1001,7 @@ int lvm_lv_remove_tag(lv_t lv, const char *tag);
* \memberof lv_t * \memberof lv_t
* *
* The memory allocated for the list is tied to the vg_t handle and will be * The memory allocated for the list is tied to the vg_t handle and will be
* released when lvm_vg_close is called. * released when lvm_vg_close() is called.
* *
* To process the list, use the dm_list iterator functions. For example: * To process the list, use the dm_list iterator functions. For example:
* lv_t lv; * lv_t lv;
@ -1057,8 +1057,8 @@ int lvm_lv_resize(const lv_t lv, uint64_t new_size);
* *
* \memberof pv_t * \memberof pv_t
* *
* Memory is allocated using dm_malloc() and caller must free the memory * The memory allocated for the uuid is tied to the vg_t handle and will be
* using dm_free(). * released when lvm_vg_close() is called.
* *
* \param pv * \param pv
* Physical volume handle. * Physical volume handle.
@ -1066,15 +1066,15 @@ int lvm_lv_resize(const lv_t lv, uint64_t new_size);
* \return * \return
* Copy of the uuid string. * Copy of the uuid string.
*/ */
char *lvm_pv_get_uuid(const pv_t pv); const char *lvm_pv_get_uuid(const pv_t pv);
/** /**
* Get the current name of a physical volume. * Get the current name of a physical volume.
* *
* \memberof pv_t * \memberof pv_t
* *
* Memory is allocated using dm_malloc() and caller must free the memory * The memory allocated for the uuid is tied to the vg_t handle and will be
* using dm_free(). * released when lvm_vg_close() is called.
* *
* \param pv * \param pv
* Physical volume handle. * Physical volume handle.
@ -1082,7 +1082,7 @@ char *lvm_pv_get_uuid(const pv_t pv);
* \return * \return
* Copy of the name. * Copy of the name.
*/ */
char *lvm_pv_get_name(const pv_t pv); const char *lvm_pv_get_name(const pv_t pv);
/** /**
* Get the current number of metadata areas in the physical volume. * Get the current number of metadata areas in the physical volume.

View File

@ -39,7 +39,7 @@ uint64_t lvm_lv_get_size(const lv_t lv)
return SECTOR_SIZE * lv_size(lv); return SECTOR_SIZE * lv_size(lv);
} }
char *lvm_lv_get_uuid(const lv_t lv) const char *lvm_lv_get_uuid(const lv_t lv)
{ {
char uuid[64] __attribute((aligned(8))); char uuid[64] __attribute((aligned(8)));
@ -47,17 +47,13 @@ char *lvm_lv_get_uuid(const lv_t lv)
log_error(INTERNAL_ERROR "unable to convert uuid"); log_error(INTERNAL_ERROR "unable to convert uuid");
return NULL; return NULL;
} }
return strndup((const char *)uuid, 64); return dm_pool_strndup(lv->vg->vgmem, (const char *)uuid, 64);
} }
char *lvm_lv_get_name(const lv_t lv) const char *lvm_lv_get_name(const lv_t lv)
{ {
char *name; return dm_pool_strndup(lv->vg->vgmem, (const char *)lv->name,
NAME_LEN+1);
name = dm_malloc(NAME_LEN + 1);
strncpy(name, (const char *)lv->name, NAME_LEN);
name[NAME_LEN] = '\0';
return name;
} }
uint64_t lvm_lv_is_active(const lv_t lv) uint64_t lvm_lv_is_active(const lv_t lv)

View File

@ -17,7 +17,7 @@
#include "metadata-exported.h" #include "metadata-exported.h"
#include "lvm-string.h" #include "lvm-string.h"
char *lvm_pv_get_uuid(const pv_t pv) const char *lvm_pv_get_uuid(const pv_t pv)
{ {
char uuid[64] __attribute((aligned(8))); char uuid[64] __attribute((aligned(8)));
@ -25,17 +25,13 @@ char *lvm_pv_get_uuid(const pv_t pv)
log_error(INTERNAL_ERROR "Unable to convert uuid"); log_error(INTERNAL_ERROR "Unable to convert uuid");
return NULL; return NULL;
} }
return strndup((const char *)uuid, 64); return dm_pool_strndup(pv->vg->vgmem, (const char *)uuid, 64);
} }
char *lvm_pv_get_name(const pv_t pv) const char *lvm_pv_get_name(const pv_t pv)
{ {
char *name; return dm_pool_strndup(pv->vg->vgmem,
(const char *)pv_dev_name(pv), NAME_LEN + 1);
name = dm_malloc(NAME_LEN + 1);
strncpy(name, (const char *)pv_dev_name(pv), NAME_LEN);
name[NAME_LEN] = '\0';
return name;
} }
uint64_t lvm_pv_get_mda_count(const pv_t pv) uint64_t lvm_pv_get_mda_count(const pv_t pv)

View File

@ -328,7 +328,7 @@ uint64_t lvm_vg_get_max_lv(const vg_t vg)
return vg_max_lv(vg); return vg_max_lv(vg);
} }
char *lvm_vg_get_uuid(const vg_t vg) const char *lvm_vg_get_uuid(const vg_t vg)
{ {
char uuid[64] __attribute((aligned(8))); char uuid[64] __attribute((aligned(8)));
@ -336,17 +336,12 @@ char *lvm_vg_get_uuid(const vg_t vg)
log_error(INTERNAL_ERROR "Unable to convert uuid"); log_error(INTERNAL_ERROR "Unable to convert uuid");
return NULL; return NULL;
} }
return strndup((const char *)uuid, 64); return dm_pool_strndup(vg->vgmem, (const char *)uuid, 64);
} }
char *lvm_vg_get_name(const vg_t vg) const char *lvm_vg_get_name(const vg_t vg)
{ {
char *name; return dm_pool_strndup(vg->vgmem, (const char *)vg->name, NAME_LEN+1);
name = dm_malloc(NAME_LEN + 1);
strncpy(name, (const char *)vg->name, NAME_LEN);
name[NAME_LEN] = '\0';
return name;
} }
struct dm_list *lvm_list_vg_names(lvm_t libh) struct dm_list *lvm_list_vg_names(lvm_t libh)