: Add vg_attr 'get' functions to lvm2app
cover : Add vg_attr 'get' functions to lvm2app
These patches add the most useful vgs 'vg_attr' fields as lvm2app 'get' functions. The first patch adds the lvm2app functions, and the second patch is just cleanup for the lvm codebase.
PATCH 1/2 Add most relevant vg_attr fields as lvm2app 'get' functions.
Of the vgs field vg_attr, a few of the most likely to be used attributes are clustered, exported, and partial. I thought explicitly stating what 'partial' meant was clearer. So this patch adds the following 3 functions:uint64_t lvm_vg_is_clustered(const vg_t vg)uint64_t lvm_vg_is_exported(const vg_t vg)uint64_t lvm_vg_is_missing_pvs(const vg_t vg)
--- lib/metadata/metadata-exported.h | 1 + liblvm/lvm2app.h | 33 +++++++++++++++++++++++++++++++++ liblvm/lvm_vg.c | 15 +++++++++++++++ 3 files changed, 49 insertions(+), 0 deletions(-)
lib/metadata/metadata-exported.h +1 -0
@@ -721,6 +721,7 @@ uint64_t vg_max_pv(const struct volume_group *vg);uint64_t vg_max_lv (const struct volume_group *vg);int vg_check_write_mode (struct volume_group *vg);#define vg_is_clustered (vg) (vg_status((vg)) & CLUSTERED) +#define vg_is_exported (vg) (vg_status((vg)) & EXPORTED_VG)struct vgcreate_params {char *vg_name;
liblvm/lvm2app.h +33 -0
@@ -481,6 +481,39 @@ int lvm_vg_reduce(vg_t vg, const char *device);int lvm_vg_set_extent_size (vg_t vg,uint32_t new_size);/** +* Get whether or not a volume group is clustered. +* +* \param vg +* VG handle obtained from lvm_vg_create or lvm_vg_open. +* +* \return +* 1 if the VG is clustered, 0 if not +*/ +uint64_t lvm_vg_is_clustered (vg_t vg); + +/** +* Get whether or not a volume group is exported. +* +* \param vg +* VG handle obtained from lvm_vg_create or lvm_vg_open. +* +* \return +* 1 if the VG is exported, 0 if not +*/ +uint64_t lvm_vg_is_exported (vg_t vg); + +/** +* Get whether or not a volume group is missing physical volumes. +* +* \param vg +* VG handle obtained from lvm_vg_create or lvm_vg_open. +* +* \return +* 1 if the VG is missing PVs, 0 if not +*/ +uint64_t lvm_vg_is_missing_pvs (vg_t vg); + +/** * Get the current metadata sequence number of a volume group. * * The metadata sequence number is incrented for each metadata change.
liblvm/lvm_vg.c +15 -0
@@ -243,6 +243,21 @@ uint64_t lvm_vg_get_seqno(const vg_t vg)return vg_seqno (vg); } +uint64_t lvm_vg_is_clustered (const vg_t vg) +{ +return vg_is_clustered (vg); +} + +uint64_t lvm_vg_is_exported (const vg_t vg) +{ +return vg_is_exported (vg); +} + +uint64_t lvm_vg_is_missing_pvs (const vg_t vg) +{ +return (vg_missing_pv_count (vg) !=0 ); +} +/* FIXME: invalid handle? return INTMAX? */ uint64_t lvm_vg_get_size (const vg_t vg) {
Signature · 1 line
1.6.0.6
PATCH 2/2 Use vg_is_exported(vg) macro everywhere.
This patch is all just cleanup and no other patch depends on it. Replace explicit dereference and check with vg_is_exported(). Update a few copyrights and remove unnecessary whitespace. Should be no functional change.
--- lib/cache/lvmcache.c | 2 +- lib/display/display.c | 2 +- lib/format1/import-export.c | 6 +++--- lib/format_text/archiver.c | 2 +- lib/report/report.c | 2 +- tools/vgchange.c | 4 ++-- tools/vgimport.c | 4 ++-- tools/vgscan.c | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-)
lib/cache/lvmcache.c +1 -1
@@ -821,7 +821,7 @@ static int _insert_vginfo(struct lvmcache_vginfo *new_vginfo, const char *vgid, char uuid_primary[64] __attribute((aligned(8))); char uuid_new[64] __attribute((aligned(8)));int use_new =0 ; - +/* Pre-existing VG takes precedence. Unexported VG takes precedence. */ if (primary_vginfo) {if (!id_write_format ((const struct id *)vgid, uuid_new,sizeof (uuid_new)))
lib/display/display.c +1 -1
@@ -597,7 +597,7 @@ void vgdisplay_full(const struct volume_group *vg) access_str ==LVM_WRITE ?"write" :"" , access_str == 0 ? "error" : "");log_print ("VG Status %s%sresizable" , - vg->status &EXPORTED_VG ?"exported/" :"" , +vg_is_exported (vg) ?"exported/" :"" , vg->status &RESIZEABLE_VG ?"" :"NOT " );/* vg number not part of LVM2 design log_print ("VG # %u\n", vg->vg_number);
lib/format1/import-export.c +3 -3
@@ -160,7 +160,7 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute((unused))strncpy ((char *)pvd->system_id, vg->system_id,sizeof (pvd->system_id));/* Is VG already exported or being exported? */ - if (vg && (vg->status & EXPORTED_VG)) { + if (vg && vg_is_exported(EXPORTED_VG)) { /* Does system_id need setting? */ if (!*vg->system_id || strncmp(vg->system_id, EXPORTED_TAG,
@@ -178,7 +178,7 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute((unused)) }/* Is VG being imported? */ -if (vg && !(vg->status &EXPORTED_VG ) && *vg->system_id && +if (vg && !vg_is_exported (vg) && *vg->system_id && !strncmp (vg->system_id,EXPORTED_TAG ,sizeof (EXPORTED_TAG ) -1 )) {if (!_system_id (cmd, (char *)pvd->system_id,IMPORTED_TAG )) return_0;
@@ -275,7 +275,7 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg)if (vg->status &SHARED ) vgd->vg_access |=VG_SHARED ; -if (vg->status &EXPORTED_VG ) +if (vg_is_exported (vg)) vgd->vg_status |=VG_EXPORTED ;if (vg->status &RESIZEABLE_VG )
lib/format_text/archiver.c +1 -1
@@ -415,7 +415,7 @@ void check_current_backup(struct volume_group *vg)struct volume_group *vg_backup;int old_suppress; -if (vg->status &EXPORTED_VG ) +if (vg_is_exported (vg))return ; if (dm_snprintf(path, sizeof(path), "%s/%s",
lib/report/report.c +1 -1
@@ -434,7 +434,7 @@ static int _vgstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_else repstr[1 ] ='-' ; -if (vg->status &EXPORTED_VG ) +if (vg_is_exported (vg)) repstr[2 ] ='x' ;else repstr[2 ] ='-' ;
tools/vgchange.c +2 -2
@@ -446,7 +446,7 @@ static int _vgchange_refresh(struct cmd_context *cmd, struct volume_group *vg)if (!vg_refresh_visible (cmd, vg))return ECMD_FAILED ; - +return ECMD_PROCESSED ; }
@@ -459,7 +459,7 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,if (vg_read_error (vg))return ECMD_FAILED ; -if (vg_status (vg) &EXPORTED_VG ) { +if (vg_is_exported (EXPORTED_VG )) {log_error ("Volume group \"%s\" is exported" , vg_name);return ECMD_FAILED ; }
tools/vgimport.c +2 -2
@@ -1,6 +1,6 @@/* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. -* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. +* Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. *
@@ -26,7 +26,7 @@ static int vgimport_single(struct cmd_context *cmd __attribute((unused)),if (vg_read_error (vg)) goto error; -if (!(vg_status (vg) &EXPORTED_VG )) { +if (!vg_is_exported (vg)) {log_error ("Volume group \"%s\" is not exported" , vg_name); goto error; }
tools/vgscan.c +2 -2
@@ -1,6 +1,6 @@/* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. -* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. +* Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. *
@@ -23,7 +23,7 @@ static int vgscan_single(struct cmd_context *cmd, const char *vg_name,return ECMD_FAILED ;log_print ("Found %svolume group \"%s\" using metadata type %s" , - (vg_status (vg) &EXPORTED_VG ) ?"exported " :"" , vg_name, +vg_is_exported (vg) ?"exported " :"" , vg_name, vg->fid->fmt->name);check_current_backup (vg);
Signature · 1 line
1.6.0.6