New library interface for vg_read.
PATCH 1/1 New library interface for vg_read.
Hi,
this is a once-more rehashed set of patches. I have re-done the changes in a different, more structured order. The patches towards the end (not touching library) should be fairly independent of each other -- these can be applied without applying the rest. The patches toward the start of the sequence are adding library bits that will be used by the later patches. Generally, the library patches shouldn't change any existing functionality (unlike the previous version of the patchset).
Also, I am trying to use git-send-email with darcs here, so please forgive if I have botched something in this sequence...
Yours,
Petr.
PATCH 1/11 Move vg_read out of the way, renaming it to vg_read_internal.
Fri Jan 9 14:04:27 CET 2009 Petr Rockai <[email protected]>
* Move vg_read out of the way, renaming it to vg_read_internal.
daemons/clvmd/lvm-functions.c +1 -1
@@ -711,7 +711,7 @@ void lvm_do_backup(const char *vgname)DEBUGLOG ("Triggering backup of VG metadata for %s. suspended=%d\n" , vgname, suspended); - vg =vg_read (cmd, vgname,NULL /*vgid*/ , &consistent); + vg =vg_read_internal (cmd, vgname,NULL /*vgid*/ , &consistent);if (vg) {if (consistent)check_current_backup (vg);
lib/format1/format1.c +2 -2
@@ -163,7 +163,7 @@ static struct volume_group *_format1_vg_const char *vg_name, struct metadata_area *mda __attribute((unused))) { -struct dm_pool *mem =dm_pool_create ("lvm1 vg_read" ,1024 *10 ); +struct dm_pool *mem =dm_pool_create ("lvm1 vg_read_internal" ,1024 *10 );struct dm_list pvs;struct volume_group *vg =NULL ;dm_list_init (&pvs);
@@ -441,7 +441,7 @@ static int _format1_segtype_supported(st }static struct metadata_area_ops _metadata_format1_ops = { - .vg_read = _format1_vg_read, + .vg_read_internal = _format1_vg_read, .vg_write = _format1_vg_write, };
lib/format_pool/format_pool.c +3 -3
@@ -160,7 +160,7 @@ static struct volume_group *_pool_vg_reaconst char *vg_name, struct metadata_area *mda __attribute((unused))) { -struct dm_pool *mem =dm_pool_create ("pool vg_read" ,1024 ); +struct dm_pool *mem =dm_pool_create ("pool vg_read_internal" ,1024 );struct dm_list pds;struct volume_group *vg =NULL ;
@@ -220,7 +220,7 @@ static int _pool_pv_read(const struct fo/* * I need to read the disk and populate a pv structure here * I'll probably need to abstract some of this later for the -* vg_read code +* vg_read_internal code */ if (!(pl =read_pool_disk (fmt, dev, mem,NULL ))) goto_out;
@@ -239,7 +239,7 @@ static int _pool_pv_read(const struct fo/* *INDENT-OFF* */ static struct metadata_area_ops _metadata_format_pool_ops = { - .vg_read = _pool_vg_read, + .vg_read_internal = _pool_vg_read, };/* *INDENT-ON* */
lib/format_text/archiver.c +1 -1
@@ -265,7 +265,7 @@ struct volume_group *backup_read_vg(stru } dm_list_iterate_items(mda, &tf->metadata_areas) { -if (!(vg = mda->ops->vg_read (tf, vg_name, mda))) +if (!(vg = mda->ops->vg_read_internal (tf, vg_name, mda))) stack;break ; }
lib/format_text/format-text.c +3 -3
@@ -1543,7 +1543,7 @@ static void _text_destroy(const struct f }static struct metadata_area_ops _metadata_text_file_ops = { - .vg_read = _vg_read_file, + .vg_read_internal = _vg_read_file, .vg_read_precommit = _vg_read_precommit_file, .vg_write = _vg_write_file, .vg_remove = _vg_remove_file,
@@ -1551,14 +1551,14 @@ static struct metadata_area_ops _metadat };static struct metadata_area_ops _metadata_text_file_backup_ops = { - .vg_read = _vg_read_file, + .vg_read_internal = _vg_read_file, .vg_write = _vg_write_file, .vg_remove = _vg_remove_file, .vg_commit = _vg_commit_file_backup };static struct metadata_area_ops _metadata_text_raw_ops = { - .vg_read = _vg_read_raw, + .vg_read_internal = _vg_read_raw, .vg_read_precommit = _vg_read_precommit_raw, .vg_write = _vg_write_raw, .vg_remove = _vg_remove_raw,
lib/metadata/metadata.c +13 -13
@@ -224,8 +224,8 @@ int get_pv_from_vg_by_id(const struct fostruct pv_list *pvl;int consistent =0 ; -if (!(vg =vg_read (fmt->cmd, vg_name, vgid, &consistent))) { -log_error ("get_pv_from_vg_by_id: vg_read failed to read VG %s" , +if (!(vg =vg_read_internal (fmt->cmd, vg_name, vgid, &consistent))) { +log_error ("get_pv_from_vg_by_id: vg_read_internal failed to read VG %s" , vg_name);return 0 ; }
@@ -503,7 +503,7 @@ struct volume_group *vg_create(struct cm return_NULL;/* is this vg name already in use ? */ -if (vg_read (cmd, vg_name,NULL , &consistent)) { +if (vg_read_internal (cmd, vg_name,NULL , &consistent)) {log_err ("A volume group called '%s' already exists." , vg_name); goto bad; }
@@ -1684,12 +1684,12 @@ int vg_missing_pv_count(const vg_t *vg)return ret; } -/* Caller sets consistent to 1 if it's safe for vg_read to correct +/* Caller sets consistent to 1 if it's safe for vg_read_internal to correct * inconsistent metadata on disk (i.e. the VG write lock is held). * This guarantees only consistent metadata is returned. * If consistent is 0, caller must check whether consistent == 1 on return * and take appropriate action if it isn't (e.g. abort; get write lock -* and call vg_read again). +* and call vg_read_internal again). * * If precommitted is set, use precommitted metadata if present. *
@@ -1716,7 +1716,7 @@ static struct volume_group *_vg_read(strif (is_orphan_vg (vgname)) {if (use_precommitted) { -log_error ("Internal error: vg_read requires vgname " +log_error ("Internal error: vg_read_internal requires vgname " "with pre-commit." );return NULL ; }
@@ -1769,7 +1769,7 @@ static struct volume_group *_vg_read(strif ((use_precommitted && !(vg = mda->ops->vg_read_precommit (fid, vgname, mda))) || (!use_precommitted && - !(vg = mda->ops->vg_read (fid, vgname, mda)))) { + !(vg = mda->ops->vg_read_internal (fid, vgname, mda)))) { inconsistent =1 ;continue ; }
@@ -1873,7 +1873,7 @@ static struct volume_group *_vg_read(str !(vg = mda->ops->vg_read_precommit(fid, vgname, mda))) || (!use_precommitted && - !(vg = mda->ops->vg_read(fid, vgname, mda)))) { + !(vg = mda->ops->vg_read_internal(fid, vgname, mda)))) { inconsistent =1 ;continue ; }
@@ -1974,7 +1974,7 @@ static struct volume_group *_vg_read(strreturn correct_vg; } -struct volume_group *vg_read (struct cmd_context *cmd,const char *vgname, +struct volume_group *vg_read_internal (struct cmd_context *cmd,const char *vgname,const char *vgid,int *consistent) {struct volume_group *vg;
@@ -2002,7 +2002,7 @@ struct volume_group *vg_read(struct cmd_/* This is only called by lv_from_lvid, which is only called from * activate.c so we know the appropriate VG lock is already held and -* the vg_read is therefore safe. +* the vg_read_internal is therefore safe. */ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd, const char *vgid,
@@ -2034,7 +2034,7 @@ static struct volume_group *_vg_read_by_if (memlock ())return NULL ; -/* FIXME Need a genuine read by ID here - don't vg_read by name! */ +/* FIXME Need a genuine read by ID here - don't vg_read_internal by name! */ /* FIXME Disabled vgrenames while active for now because we aren't * allowed to do a full scan here any more. */
@@ -2218,7 +2218,7 @@ static int _get_pvs(struct cmd_context * stack;continue ; } -if (!(vg =vg_read (cmd, vgname, vgid, &consistent))) { +if (!(vg =vg_read_internal (cmd, vgname, vgid, &consistent))) { stack;continue ; }
@@ -2446,7 +2446,7 @@ vg_t *vg_lock_and_read(struct cmd_contexreturn NULL ; } -if (!(vg =vg_read (cmd, vg_name, vgid, &consistent)) || +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent)) || ((misc_flags &FAIL_INCONSISTENT ) && !consistent)) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);
lib/metadata/metadata-exported.h +2 -2
@@ -76,7 +76,7 @@ struct pv_segment;written out in metadata*/ //#define POSTORDER_FLAG 0x02000000U /* Not real flags, reserved for -//#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read. */ +//#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read_internal. */ #define LVM_READ 0x00000100U/* LV VG */ #define LVM_WRITE 0x00000200U/* LV VG */
@@ -328,7 +328,7 @@ struct lv_list {int vg_write (struct volume_group *vg);int vg_commit (struct volume_group *vg);int vg_revert (struct volume_group *vg); -struct volume_group *vg_read (struct cmd_context *cmd,const char *vg_name, +struct volume_group *vg_read_internal (struct cmd_context *cmd,const char *vg_name,const char *vgid,int *consistent); struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, struct dm_list *mdas, uint64_t *label_sector,
lib/metadata/metadata.h +2 -2
@@ -79,7 +79,7 @@// written out in metadata*/ #define POSTORDER_FLAG 0x02000000U/* Not real flags, reserved for */ -#define POSTORDER_OPEN_FLAG 0x04000000U/* temporary use inside vg_read. */ +#define POSTORDER_OPEN_FLAG 0x04000000U/* temporary use inside vg_read_internal. */ //#define LVM_READ 0x00000100U /* LV VG */ //#define LVM_WRITE 0x00000200U /* LV VG */
@@ -101,7 +101,7 @@ struct metadata_area;/* Per-format per-metadata area operations */ struct metadata_area_ops { -struct volume_group *(*vg_read) (struct format_instance * fi, +struct volume_group *(*vg_read_internal) (struct format_instance * fi,const char *vg_name,struct metadata_area * mda); struct volume_group *(*vg_read_precommit) (struct format_instance * fi,
old-tests/format1/read_vg_t.c +1 -1
@@ -55,7 +55,7 @@ int main(int argc, char **argv)exit (1 ); } - vg = ios->vg_read (ios, argv[1 ]); + vg = ios->vg_read_internal (ios, argv[1 ]);if (!vg) {fprintf (stderr,"couldn't read vg %s\n" , argv[1 ]);
old-tests/format1/write_vg_t.c +1 -1
@@ -55,7 +55,7 @@ int main(int argc, char **argv)exit (1 ); } - vg = ios->vg_read (ios, argv[1 ]); + vg = ios->vg_read_internal (ios, argv[1 ]);if (!vg) {fprintf (stderr,"couldn't read vg %s\n" , argv[1 ]);
test/format1/read_vg_t.c +1 -1
@@ -55,7 +55,7 @@ int main(int argc, char **argv)exit (1 ); } - vg = ios->vg_read (ios, argv[1 ]); + vg = ios->vg_read_internal (ios, argv[1 ]);if (!vg) {fprintf (stderr,"couldn't read vg %s\n" , argv[1 ]);
test/format1/write_vg_t.c +1 -1
@@ -55,7 +55,7 @@ int main(int argc, char **argv)exit (1 ); } - vg = ios->vg_read (ios, argv[1 ]); + vg = ios->vg_read_internal (ios, argv[1 ]);if (!vg) {fprintf (stderr,"couldn't read vg %s\n" , argv[1 ]);
tools/pvdisplay.c +1 -1
@@ -37,7 +37,7 @@ static int _pvdisplay_single(struct cmd_/* * Replace possibly incomplete PV structure with new one -* allocated in vg_read() path. +* allocated in vg_read_internal() path. */ if (!(pvl =find_pv_in_vg (vg, pv_name))) { log_error("Unable to find \"%s\" in volume group \"%s\"",
tools/pvresize.c +1 -1
@@ -62,7 +62,7 @@ static int _pv_resize_single(struct cmd_return 0 ; } -if (!(vg =vg_read (cmd, vg_name,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent))) {unlock_vg (cmd, vg_name);log_error ("Unable to find volume group of \"%s\"" , pv_name);
tools/reporter.c +1 -1
@@ -136,7 +136,7 @@ static int _pvs_single(struct cmd_contex/* * Replace possibly incomplete PV structure with new one -* allocated in vg_read() path. +* allocated in vg_read_internal() path. */ if (!(pvl =find_pv_in_vg (vg,pv_dev_name (pv)))) { log_error("Unable to find \"%s\" in volume group \"%s\"",
tools/toollib.c +4 -4
@@ -291,7 +291,7 @@ int process_each_lv(struct cmd_context * consistent =1 ; else consistent =0 ; -if (!(vg =vg_read (cmd, vgname,NULL , &consistent)) || !consistent) { +if (!(vg =vg_read_internal (cmd, vgname,NULL , &consistent)) || !consistent) {unlock_vg (cmd, vgname);if (!vg) log_error("Volume group \"%s\" "
@@ -433,7 +433,7 @@ static int _process_one_vg(struct cmd_co }log_verbose ("Finding volume group \"%s\"" , vg_name); -if (!(vg =vg_read (cmd, vg_name, vgid, &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);return ECMD_FAILED ;
@@ -720,7 +720,7 @@ int process_each_pv(struct cmd_context *log_error ("Can't lock %s: skipping" , sll->str);continue ; } -if (!(vg =vg_read (cmd, sll->str,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, sll->str,NULL , &consistent))) {log_error ("Volume group \"%s\" not found" , sll->str);unlock_vg (cmd, sll->str); ret_max =ECMD_FAILED ;
@@ -1143,7 +1143,7 @@ struct volume_group *recover_vg(struct creturn NULL ; } -return vg_read (cmd, vgname,NULL , &consistent); +return vg_read_internal (cmd, vgname,NULL , &consistent); }int apply_lvname_restrictions (const char *name)
tools/vgreduce.c +3 -3
@@ -426,7 +426,7 @@ static int _vgreduce_single(struct cmd_c vg->free_count -=pv_pe_count (pv) -pv_pe_alloc_count (pv); vg->extent_count -=pv_pe_count (pv); -if (!(orphan_vg =vg_read (cmd, vg->fid->fmt->orphan_vg_name,NULL , &consistent)) || +if (!(orphan_vg =vg_read_internal (cmd, vg->fid->fmt->orphan_vg_name,NULL , &consistent)) || !consistent) {log_error ("Unable to read existing orphan PVs" );unlock_vg (cmd,VG_ORPHANS );
@@ -520,7 +520,7 @@ int vgreduce(struct cmd_context *cmd, inreturn ECMD_FAILED ; } -if ((!(vg =vg_read (cmd, vg_name,NULL , &consistent)) || !consistent) +if ((!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent)) || !consistent) && !repairing) {log_error ("Volume group \"%s\" doesn't exist" , vg_name);unlock_vg (cmd, vg_name);
@@ -541,7 +541,7 @@ int vgreduce(struct cmd_context *cmd, in } consistent = !arg_count (cmd, force_ARG); -if (!(vg =vg_read (cmd, vg_name,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent))) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);return ECMD_FAILED ;
tools/vgrename.c +2 -2
@@ -75,7 +75,7 @@ static int vg_rename_path(struct cmd_conreturn 0 ; } -if (!(vg =vg_read (cmd, vg_name_old, vgid, &consistent)) || !consistent) { +if (!(vg =vg_read_internal (cmd, vg_name_old, vgid, &consistent)) || !consistent) {log_error ("Volume group %s %s%s%snot found." , vg_name_old, vgid ?"(" :"" , vgid ? vgid :"" , vgid ?") " :"" );unlock_vg (cmd, vg_name_old);
@@ -107,7 +107,7 @@ static int vg_rename_path(struct cmd_con } consistent =0 ; -if ((vg_new =vg_read (cmd, vg_name_new,NULL , &consistent))) { +if ((vg_new =vg_read_internal (cmd, vg_name_new,NULL , &consistent))) {log_error ("New volume group \"%s\" already exists" , vg_name_new); goto error;
tools/vgsplit.c +2 -2
@@ -334,7 +334,7 @@ int vgsplit(struct cmd_context *cmd, int } consistent =0 ; -if ((vg_to =vg_read (cmd, vg_name_to,NULL , &consistent))) { +if ((vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent))) { existing_vg =1 ;if (new_vg_option_specified (cmd)) { log_error("Volume group \"%s\" exists, but new VG "
@@ -451,7 +451,7 @@ int vgsplit(struct cmd_context *cmd, int*/ consistent =1 ;if (!test_mode () && - (!(vg_to =vg_read (cmd, vg_name_to,NULL , &consistent)) || + (!(vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent)) || !consistent)) {log_error ("Volume group \"%s\" became inconsistent: please " "fix manually" , vg_name_to);
PATCH 2/11 Provide _vg_lock_and_read, a new implementation of lock+vg_read_internal.
Fri Jan 9 14:21:23 CET 2009 Petr Rockai <[email protected]>
* Provide _vg_lock_and_read, a new implementation of lock+vg_read_internal.
This is an internal function, to be later used by vg_read and vg_read_for_update. Not to be confused with the public function vg_lock_and_read, which will be removed later.
lib/metadata/metadata.c +154 -0
@@ -2461,6 +2461,160 @@ vg_t *vg_lock_and_read(struct cmd_contexreturn vg; } +static vg_t *_vg_make_handle (struct cmd_context *cmd, +struct volume_group *vg, +uint32_t failure) +{ +if (!vg) +if (!(vg =dm_pool_zalloc (cmd->mem,sizeof (*vg)))) + return_NULL; + vg->read_failed = failure; +return vg; +} + +static uint32_t _vg_check_status (const struct volume_group *vg,uint32_t status) +{ +uint32_t ret =0 ; +if ((status &CLUSTERED ) && + (vg_is_clustered (vg)) && !locking_is_clustered () && + !lockingfailed ()) { +log_error ("Skipping clustered volume group %s" , vg->name); + ret |=FAILED_CLUSTERED ; + } + +if ((status &EXPORTED_VG ) && + (vg->status &EXPORTED_VG )) { +log_error ("Volume group %s is exported" , vg->name); + ret |=FAILED_EXPORTED ; + } + +if ((status &LVM_WRITE ) && + !(vg->status &LVM_WRITE )) { +log_error ("Volume group %s is read-only" , vg->name); + ret |=FAILED_READ_ONLY ; + } + +if ((status &RESIZEABLE_VG ) && + !(vg->status &RESIZEABLE_VG )) { +log_error ("Volume group %s is not resizeable." , vg->name); + ret |=FAILED_RESIZEABLE ; + } + +return ret; +} + +static vg_t *_recover_vg (struct cmd_context *cmd,const char *lock, +const char *vg_name,const char *vgid, +uint32_t lock_flags) +{ +int consistent =1 ; +struct volume_group *vg; + + lock_flags &= ~LCK_TYPE_MASK ; + lock_flags |=LCK_WRITE ; + +unlock_vg (cmd, lock); + +dev_close_all (); + +if (!lock_vol (cmd, lock, lock_flags)) + return_NULL; + +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) + return_NULL; +if (!consistent) + return_NULL; +return vg; +} + +/* +* _vg_lock_and_read - consolidate vg locking, reading, and status flag checking +* This is an internal function. +* +* misc_flags: +* ALLOW_INCONSISTENT: disable autocorrection +* +* Setting ALLOW_INCONSISTENT might give you inconsistent metadata. You will +* *still* get FAILED_INCONSISTENT in case the metadata has *really* been +* inconsistent. However, you still get the latest version of metadata in VG. +* +* Returns: +* Use vg_read_error(vg) to determine the result. Nonzero vg_read_error(vg) +* means there were problems reading the volume group. +* Zero value means that the VG is open and appropriate locks are held. +*/ +static vg_t *_vg_lock_and_read (struct cmd_context *cmd,const char *vg_name, +const char *vgid, +uint32_t lock_flags,uint32_t status_flags, +uint32_t misc_flags) +{ +struct volume_group *vg =0 ; +const char *lock; +int consistent =1 ; +int consistent_in; +uint32_t failure =0 ; + +if (misc_flags &ALLOW_INCONSISTENT || !(lock_flags &LCK_WRITE )) + consistent =0 ; + +if (!validate_name (vg_name) && !is_orphan_vg (vg_name)) { +log_error ("Volume group name %s has invalid characters" , + vg_name); +return NULL ; + } + + lock = (misc_flags &ORPHAN_LOCK ?VG_ORPHANS : vg_name); +if (!(misc_flags &DISABLE_LOCK )) { +if (!lock_vol (cmd, lock, lock_flags)) { +log_error ("Can't get lock for %s" , vg_name); +return _vg_make_handle (cmd, vg,FAILED_LOCKING ); + } + } + +if (misc_flags &ORPHAN_LOCK ) + status_flags &= ~LVM_WRITE ; + +if (misc_flags &EXISTENCE_CHECK ) + consistent =0 ; + + consistent_in = consistent; + +/* If consistent == 1, we get NULL here if correction fails. */ +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) { +if (consistent_in && !consistent) { +log_error ("Volume group \"%s\" inconsistent." , vg_name); + failure |=FAILED_INCONSISTENT ; + goto_bad; + } +if (!(misc_flags &EXISTENCE_CHECK )) +log_error ("Volume group \"%s\" not found" , vg_name); + failure |=FAILED_NOTFOUND | (misc_flags &EXISTENCE_CHECK ); + goto_bad; + } + +/* consistent == 0 when VG is not found, but failed == FAILED_NOTFOUND */ +if (!consistent && !failure) { + vg =_recover_vg (cmd, lock, vg_name, vgid, lock_flags); +if (!vg) { +log_error ("Recovery of volume group \"%s\" failed." , + vg_name); + failure |=FAILED_INCONSISTENT ; + goto_bad; + } + } + + failure |=_vg_check_status (vg, status_flags); +if (failure) + goto_bad; + +return _vg_make_handle (cmd, vg, failure); + bad: +if (failure != (FAILED_NOTFOUND |EXISTENCE_CHECK )) +if (!(misc_flags &KEEP_LOCK ) && !(misc_flags &DISABLE_LOCK )) +unlock_vg (cmd, lock); +return _vg_make_handle (cmd, vg, failure); +} +/* * Gets/Sets for external LVM library */
lib/metadata/metadata-exported.h +27 -0
@@ -104,6 +104,32 @@ struct pv_segment;#define MIRROR_BY_LV 0x00000002U/* mirror using whole mimage LVs */ #define MIRROR_SKIP_INIT_SYNC 0x00000010U/* skip initial sync */ +/* vg_read and vg_read_for_update flags */ +#define ALLOW_INCONSISTENT 0x1 +#define ALLOW_EXPORTED 0x2 +#define REQUIRE_RESIZEABLE 0x4 +#define EXISTENCE_CHECK 0x8 + +#define NONBLOCKING_LOCK 0x100 +#define KEEP_LOCK 0x200 +#define DISABLE_LOCK 0x400 +#define ORPHAN_LOCK 0x800 + +#define READ_FOR_UPDATE 0x1000 + +/* vg's "read_failed" field */ +#define FAILED_INCONSISTENT 0x1 +#define FAILED_LOCKING 0x2 +#define FAILED_NOTFOUND 0x4 +// 0x8 is left out for EXISTENCE_CHECK + +#define FAILED_READ_ONLY 0x10 +#define FAILED_EXPORTED 0x20 +#define FAILED_RESIZEABLE 0x40 +#define FAILED_CLUSTERED 0x80 + +#define FAILED_ALLOCATION 0x100 +/* Ordered list - see lv_manip.c */ typedef enum { ALLOC_INVALID,
@@ -197,6 +223,7 @@ struct volume_group {char *system_id;uint32_t status; +uint32_t read_failed;alloc_policy_t alloc;uint32_t extent_size;
PATCH 3/11 Replace implementation of vg_check_status with a call to _vg_check_status.
Fri Jan 9 14:29:02 CET 2009 Petr Rockai <[email protected]>
* Replace implementation of vg_check_status with a call to _vg_check_status.
lib/metadata/metadata.c +22 -48
@@ -2377,44 +2377,49 @@ int pv_analyze(struct cmd_context *cmd,return 1 ; } - - -/** -* vg_check_status - check volume group status flags and log error -* @vg - volume group to check status flags -* @status - specific status flags to check (e.g. EXPORTED_VG) -* -* Returns: -* 0 - fail -* 1 - success -*/ -int vg_check_status (const struct volume_group *vg,uint32_t status) +static uint32_t _vg_check_status (const struct volume_group *vg,uint32_t status) { +uint32_t ret =0 ;if ((status &CLUSTERED ) && (vg_is_clustered (vg)) && !locking_is_clustered () && !lockingfailed ()) {log_error ("Skipping clustered volume group %s" , vg->name); -return 0 ; + ret |=FAILED_CLUSTERED ; }if ((status &EXPORTED_VG ) && (vg->status &EXPORTED_VG )) {log_error ("Volume group %s is exported" , vg->name); -return 0 ; + ret |=FAILED_EXPORTED ; }if ((status &LVM_WRITE ) && !(vg->status &LVM_WRITE )) {log_error ("Volume group %s is read-only" , vg->name); -return 0 ; + ret |=FAILED_READ_ONLY ; } +if ((status &RESIZEABLE_VG ) && !(vg->status &RESIZEABLE_VG )) {log_error ("Volume group %s is not resizeable." , vg->name); -return 0 ; + ret |=FAILED_RESIZEABLE ; } -return 1 ; +return ret; +} + +/** +* vg_check_status - check volume group status flags and log error +* @vg - volume group to check status flags +* @status - specific status flags to check (e.g. EXPORTED_VG) +* +* Returns: +* 0 - fail +* 1 - success +*/ +int vg_check_status (const struct volume_group *vg,uint32_t status) +{ +return !_vg_check_status (vg, status); }/*
@@ -2472,37 +2477,6 @@ static vg_t *_vg_make_handle(struct cmd_return vg; } -static uint32_t _vg_check_status (const struct volume_group *vg,uint32_t status) -{ -uint32_t ret =0 ; -if ((status &CLUSTERED ) && - (vg_is_clustered (vg)) && !locking_is_clustered () && - !lockingfailed ()) { -log_error ("Skipping clustered volume group %s" , vg->name); - ret |=FAILED_CLUSTERED ; - } - -if ((status &EXPORTED_VG ) && - (vg->status &EXPORTED_VG )) { -log_error ("Volume group %s is exported" , vg->name); - ret |=FAILED_EXPORTED ; - } - -if ((status &LVM_WRITE ) && - !(vg->status &LVM_WRITE )) { -log_error ("Volume group %s is read-only" , vg->name); - ret |=FAILED_READ_ONLY ; - } - -if ((status &RESIZEABLE_VG ) && - !(vg->status &RESIZEABLE_VG )) { -log_error ("Volume group %s is not resizeable." , vg->name); - ret |=FAILED_RESIZEABLE ; - } - -return ret; -} -static vg_t *_recover_vg (struct cmd_context *cmd,const char *lock,const char *vg_name,const char *vgid,uint32_t lock_flags)
PATCH 4/11 Add vg_read_error and vg_might_exist.
Fri Jan 9 14:40:58 CET 2009 Petr Rockai <[email protected]>
* Add vg_read_error and vg_might_exist.
lib/metadata/metadata.c +21 -0
@@ -2589,6 +2589,27 @@ static vg_t *_vg_lock_and_read(struct cmreturn _vg_make_handle (cmd, vg, failure); } +uint32_t vg_read_error (vg_t *vg) { +if (!vg) +return FAILED_ALLOCATION ; +if (vg->read_failed &EXISTENCE_CHECK ) +return vg->read_failed & ~(EXISTENCE_CHECK |FAILED_NOTFOUND ); +return vg->read_failed; +} + +/* +* Returns true if the volume group already exists. If unsure, it will return +* true (it might exist, but we are not sure, as the read failed for some other +* reason). +*/ +uint32_t vg_might_exist (vg_t *vg) { +if (!vg) +return 1 ; +if (vg->read_failed == (FAILED_NOTFOUND |EXISTENCE_CHECK )) +return 0 ; +return 1 ; +} +/* * Gets/Sets for external LVM library */
lib/metadata/metadata-exported.h +4 -0
@@ -380,6 +380,10 @@ vg_t *vg_lock_and_read(struct cmd_contex uint32_t lock_flags, uint32_t status_flags, uint32_t misc_flags); +/* Queries on a (possibly error-indicating) VG handle. */ +uint32_t vg_read_error (vg_t *vg); +uint32_t vg_might_exist (vg_t *vg); +/* pe_start and pe_end relate to any existing data so that new metadata * areas can avoid overlap */ pv_t *pv_create(const struct cmd_context *cmd,
PATCH 5/11 Implement vg_read and vg_read_for_update.
Fri Jan 9 15:32:37 CET 2009 Petr Rockai <[email protected]>
* Implement vg_read and vg_read_for_update.
lib/metadata/metadata.c +68 -0
@@ -2589,6 +2589,74 @@ static vg_t *_vg_lock_and_read(struct cmreturn _vg_make_handle (cmd, vg, failure); } +/* +* vg_read: High-level volume group metadata read function. +* +* On failure, an error-indicating handle is returned. Users should use +* "vg_read_error" to check whether handle indicates an error or it points to +* valid volume group data. Moreover, vg_read_error will provide more details +* about the kind of failure: +* +* - metadata inconsistent and automatic correction failed: FAILED_INCONSISTENT +* - VG is read-only: FAILED_READ_ONLY +* - VG is EXPORTED, unless flags has ALLOW_EXPORTED: FAILED_EXPORTED +* - VG is not RESIZEABLE, unless flags has ALLOW_NONRESIZEABLE: +* FAILED_RESIZEABLE +* - locking failed: FAILED_LOCKING +* +* On failures, all locks are released, unless KEEP_LOCK has been supplied. +* +* By default, volume groups are opened read-only. To open a VG for updates, +* please use vg_read_for_update (see below). +* +* Checking for VG existence: +* +* If EXISTENCE_CHECK is set in flags, if the VG exists, a non-NULL struct +* volume_group will be returned every time, but if it has INCONSISTENT_VG set, +* the other fields will be uninitialized. You *have to* check for +* INCONSISTENT_VG if passing EXISTENCE_CHECK. You also *must not* use it if it +* has INCONSISTENT_VG set. +* +* FIXME: We want vg_read to attempt automatic recovery after acquiring a +* temporary write lock -- if that fails, we bail out as usual, with failed & +* FAILED_INCONSISTENT. If it works, we are good to go. Code that's been in +* toollib just set lock type to LCK_WRITE and called vg_read_internal with +* *consistent = 1. +*/ +vg_t *vg_read (struct cmd_context *cmd,const char *vg_name, +const char *vgid,uint32_t flags) +{ +uint32_t status =CLUSTERED ; +uint32_t lock =LCK_VG_READ ; + +if (flags &READ_FOR_UPDATE ) { + status |=EXPORTED_VG |LVM_WRITE ; + lock =LCK_VG_WRITE ; + } + +if (flags &ALLOW_EXPORTED ) + status &= ~EXPORTED_VG ; + +if (flags &REQUIRE_RESIZEABLE ) + status |=RESIZEABLE_VG ; + +if (flags &NONBLOCKING_LOCK ) + lock |=LCK_NONBLOCK ; + +return _vg_lock_and_read (cmd, vg_name, vgid, lock, status, flags); +} + +/* +* A high-level volume group metadata reading function. Open a volume group for +* later update (this means the user code can change the metadata and later +* request the new metadata to be written and committed). +*/ +vg_t *vg_read_for_update (struct cmd_context *cmd,const char *vg_name, +const char *vgid,uint32_t flags) +{ +return vg_read (cmd, vg_name, vgid, flags |READ_FOR_UPDATE ); +} +uint32_t vg_read_error (vg_t *vg) {if (!vg)return FAILED_ALLOCATION ;
lib/metadata/metadata-exported.h +6 -0
@@ -380,6 +380,12 @@ vg_t *vg_lock_and_read(struct cmd_contex uint32_t lock_flags, uint32_t status_flags, uint32_t misc_flags); +/* Loading volume group metadata. */ +vg_t *vg_read (struct cmd_context *cmd,const char *vg_name, +const char *vgid,uint32_t flags); +vg_t *vg_read_for_update (struct cmd_context *cmd,const char *vg_name, +const char *vgid,uint32_t flags); +/* Queries on a (possibly error-indicating) VG handle. */ uint32_t vg_read_error (vg_t *vg);uint32_t vg_might_exist (vg_t *vg);
PATCH 6/11 Convert the straight instances of vg_lock_and_read to new vg_read(_for_update).
Fri Jan 9 15:21:07 CET 2009 Petr Rockai <[email protected]>
* Convert the straight instances of vg_lock_and_read to new vg_read(_for_update).
tools/lvconvert.c +4 -7
@@ -240,10 +240,8 @@ static struct volume_group *_get_lvconve {dev_close_all (); -return vg_lock_and_read (cmd,extract_vgname (cmd, lv_name), -NULL ,LCK_VG_WRITE , -CLUSTERED |EXPORTED_VG |LVM_WRITE , -CORRECT_INCONSISTENT |FAIL_INCONSISTENT ); +return vg_read_for_update (cmd,extract_vgname (cmd, lv_name), +NULL ,0 ); } static struct logical_volume *_get_lvconvert_lv(struct cmd_context *cmd __attribute((unused)),
@@ -746,9 +744,8 @@ int lvconvert(struct cmd_context * cmd,log_verbose ("Checking for existing volume group \"%s\"" , lp.vg_name); -if (!(vg =vg_lock_and_read (cmd, lp.vg_name,NULL ,LCK_VG_WRITE , -CLUSTERED |EXPORTED_VG |LVM_WRITE , -CORRECT_INCONSISTENT ))) + vg =vg_read_for_update (cmd, lp.vg_name,NULL ,0 ); +if (vg_read_error (vg))return ECMD_FAILED ;if (!(lvl =find_lv_in_vg (vg, lp.lv_name))) {
tools/lvcreate.c +2 -3
@@ -896,9 +896,8 @@ int lvcreate(struct cmd_context *cmd, inreturn EINVALID_CMD_LINE ;log_verbose ("Finding volume group \"%s\"" , lp.vg_name); -if (!(vg =vg_lock_and_read (cmd, lp.vg_name,NULL ,LCK_VG_WRITE , -CLUSTERED |EXPORTED_VG |LVM_WRITE , -CORRECT_INCONSISTENT ))) + vg =vg_read_for_update (cmd, lp.vg_name,NULL ,0 ); +if (vg_read_error (vg))return ECMD_FAILED ;if (!_lvcreate (cmd, vg, &lp))
tools/lvrename.c +2 -3
@@ -101,9 +101,8 @@ int lvrename(struct cmd_context *cmd, in }log_verbose ("Checking for existing volume group \"%s\"" , vg_name); -if (!(vg =vg_lock_and_read (cmd, vg_name,NULL ,LCK_VG_WRITE , -CLUSTERED |EXPORTED_VG |LVM_WRITE , -CORRECT_INCONSISTENT ))) + vg =vg_read_for_update (cmd, vg_name,NULL ,0 ); +if (vg_read_error (vg))return ECMD_FAILED ;if (!(lvl =find_lv_in_vg (vg, lv_name_old))) {
tools/lvresize.c +2 -3
@@ -661,9 +661,8 @@ int lvresize(struct cmd_context *cmd, inreturn EINVALID_CMD_LINE ;log_verbose ("Finding volume group %s" , lp.vg_name); -if (!(vg =vg_lock_and_read (cmd, lp.vg_name,NULL ,LCK_VG_WRITE , -CLUSTERED |EXPORTED_VG |LVM_WRITE , -CORRECT_INCONSISTENT ))) { + vg =vg_read_for_update (cmd, lp.vg_name,NULL ,0 ); +if (vg_read_error (vg)) { stack;return ECMD_FAILED ; }
tools/polldaemon.c +2 -1
@@ -147,7 +147,8 @@ static int _wait_for_single_mirror(struc }/* Locks the (possibly renamed) VG again */ -if (!(vg = parms->poll_fns->get_copy_vg (cmd, name))) { + vg = parms->poll_fns->get_copy_vg (cmd, name); +if (vg_read_error (vg)) {log_error ("ABORTING: Can't reread VG for %s" , name);/* What more could we do here? */ return 0 ;
tools/pvchange.c +2 -3
@@ -56,9 +56,8 @@ static int _pvchange_single(struct cmd_clog_verbose ("Finding volume group %s of physical volume %s" , vg_name, pv_name); -if (!(vg =vg_lock_and_read (cmd, vg_name,NULL ,LCK_VG_WRITE , -CLUSTERED |EXPORTED_VG |LVM_WRITE , -CORRECT_INCONSISTENT ))) + vg =vg_read_for_update (cmd, vg_name,NULL ,0 ); +if (vg_read_error (vg)) return_0;if (!(pvl =find_pv_in_vg (vg, pv_name))) {
tools/pvdisplay.c +2 -2
@@ -28,8 +28,8 @@ static int _pvdisplay_single(struct cmd_if (!is_orphan (pv) && !vg) { vg_name =pv_vg_name (pv); -if (!(vg =vg_lock_and_read (cmd, vg_name, (char *)&pv->vgid, -LCK_VG_READ ,CLUSTERED ,0 ))) { + vg =vg_read (cmd, vg_name, (char *)&pv->vgid,0 ); +if (vg_read_error (vg)) {log_error ("Skipping volume group %s" , vg_name);/* FIXME If CLUSTERED should return ECMD_PROCESSED here */ return ECMD_FAILED ;
tools/pvmove.c +3 -9
@@ -89,16 +89,9 @@ static const char *_extract_lvname(strucstatic struct volume_group *_get_vg (struct cmd_context *cmd,const char *vgname) { -struct volume_group *vg; -dev_close_all (); -if (!(vg =vg_lock_and_read (cmd, vgname,NULL ,LCK_VG_WRITE , -CLUSTERED |EXPORTED_VG |LVM_WRITE , -CORRECT_INCONSISTENT |FAIL_INCONSISTENT ))) -return NULL ; - -return vg; +return vg_read_for_update (cmd, vgname,NULL ,0 ); }/* Create list of PVs for allocation of replacement extents */
@@ -382,7 +375,8 @@ static int _set_up_pvmove(struct cmd_con/* Read VG */ log_verbose ("Finding volume group \"%s\"" ,pv_vg_name (pv)); -if (!(vg =_get_vg (cmd,pv_vg_name (pv)))) { + vg =_get_vg (cmd,pv_vg_name (pv)); +if (vg_read_error (vg)) { stack;return ECMD_FAILED ; }
tools/pvresize.c +2 -15
@@ -29,7 +29,6 @@ static int _pv_resize_single(struct cmd_ const uint64_t new_size) {struct pv_list *pvl; -int consistent =1 ;uint64_t size =0 ;uint32_t new_pe_count =0 ;struct dm_list mdas;
@@ -57,22 +56,10 @@ static int _pv_resize_single(struct cmd_ }else { vg_name =pv_vg_name (pv); -if (!lock_vol (cmd, vg_name,LCK_VG_WRITE )) { -log_error ("Can't get lock for %s" ,pv_vg_name (pv)); -return 0 ; - } - -if (!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent))) { -unlock_vg (cmd, vg_name); -log_error ("Unable to find volume group of \"%s\"" , - pv_name); -return 0 ; - } + vg =vg_read_for_update (cmd, vg_name,NULL ,0 ); -if (!vg_check_status (vg,CLUSTERED |EXPORTED_VG |LVM_WRITE )) { -unlock_vg (cmd, vg_name); +if (vg_read_error (vg))return 0 ; - }if (!(pvl =find_pv_in_vg (vg, pv_name))) {unlock_vg (cmd, vg_name);
tools/reporter.c +2 -2
@@ -128,8 +128,8 @@ static int _pvs_single(struct cmd_contexif (is_pv (pv) && !is_orphan (pv) && !vg) { vg_name =pv_vg_name (pv); -if (!(vg =vg_lock_and_read (cmd, vg_name, (char *)&pv->vgid, -LCK_VG_READ ,CLUSTERED ,0 ))) { + vg =vg_read (cmd, vg_name, (char *)&pv->vgid,0 ); +if (vg_read_error (vg)) {log_error ("Skipping volume group %s" , vg_name);return ECMD_FAILED ; }
tools/vgextend.c +4 -5
@@ -41,11 +41,10 @@ int vgextend(struct cmd_context *cmd, in }log_verbose ("Checking for volume group \"%s\"" , vg_name); -if (!(vg =vg_lock_and_read (cmd, vg_name,NULL ,LCK_VG_WRITE |LCK_NONBLOCK , -CLUSTERED |EXPORTED_VG | -LVM_WRITE |RESIZEABLE_VG , -CORRECT_INCONSISTENT |FAIL_INCONSISTENT ))) { -unlock_vg (cmd,VG_ORPHANS ); + vg =vg_read_for_update (cmd, vg_name,NULL , +REQUIRE_RESIZEABLE |NONBLOCKING_LOCK ); +if (vg_read_error (vg)) { +unlock_vg (cmd,VG_ORPHANS );return ECMD_FAILED ; }/********** FIXME
tools/vgmerge.c +5 -7
@@ -27,16 +27,14 @@ static int _vgmerge_single(struct cmd_co }log_verbose ("Checking for volume group \"%s\"" , vg_name_to); -if (!(vg_to =vg_lock_and_read (cmd, vg_name_to,NULL ,LCK_VG_WRITE , -CLUSTERED |EXPORTED_VG |LVM_WRITE , -CORRECT_INCONSISTENT |FAIL_INCONSISTENT ))) + vg_to =vg_read_for_update (cmd, vg_name_to,NULL ,0 ); +if (vg_read_error (vg_to))return ECMD_FAILED ;log_verbose ("Checking for volume group \"%s\"" , vg_name_from); -if (!(vg_from =vg_lock_and_read (cmd, vg_name_from,NULL , -LCK_VG_WRITE |LCK_NONBLOCK , -CLUSTERED |EXPORTED_VG |LVM_WRITE , -CORRECT_INCONSISTENT |FAIL_INCONSISTENT ))) { + vg_from =vg_read_for_update (cmd, vg_name_from,NULL , +NONBLOCKING_LOCK ); +if (vg_read_error (vg_from)) {unlock_vg (cmd, vg_name_to);return ECMD_FAILED ; }
PATCH 7/11 Rework the toollib interface (process_each_*) on top of new vg_read.
Fri Jan 9 15:34:41 CET 2009 Petr Rockai <[email protected]>
* Rework the toollib interface (process_each_*) on top of new vg_read.
Since this makes an incompatible change to the interface of process_each_* functions, all of these need to go in at once.
lib/metadata/metadata.c +2 -2
@@ -332,7 +332,7 @@ static int remove_lvs_in_vg(struct cmd_c/* FIXME: remove redundant vg_name */ int vg_remove_single (struct cmd_context *cmd,const char *vg_name, -struct volume_group *vg,int consistent, +struct volume_group *vg,force_t force __attribute((unused))) {struct physical_volume *pv;
@@ -340,7 +340,7 @@ int vg_remove_single(struct cmd_contextunsigned lv_count;int ret =1 ; -if (!vg || !consistent ||vg_missing_pv_count (vg)) { +if (vg_read_error (vg) ||vg_missing_pv_count (vg)) {log_error ("Volume group \"%s\" not found, is inconsistent " "or has PVs missing." , vg_name); log_error("Consider vgreduce --removemissing if metadata "
lib/metadata/metadata-exported.h +1 -1
@@ -415,7 +415,7 @@ struct volume_group *vg_create(struct cm int pv_count, char **pv_names);int vg_remove (struct volume_group *vg);int vg_remove_single (struct cmd_context *cmd,const char *vg_name, -struct volume_group *vg,int consistent, +struct volume_group *vg,force_t force);int vg_rename (struct cmd_context *cmd,struct volume_group *vg,const char *new_name);
tools/lvchange.c +1 -1
@@ -728,6 +728,6 @@ int lvchange(struct cmd_context *cmd, inreturn EINVALID_CMD_LINE ; } -return process_each_lv (cmd, argc, argv,LCK_VG_WRITE ,NULL , +return process_each_lv (cmd, argc, argv,READ_FOR_UPDATE ,NULL , &lvchange_single); }
tools/lvdisplay.c +1 -1
@@ -54,6 +54,6 @@ int lvdisplay(struct cmd_context *cmd, ireturn EINVALID_CMD_LINE ; } -return process_each_lv (cmd, argc, argv,LCK_VG_READ ,NULL , +return process_each_lv (cmd, argc, argv,0 ,NULL , &_lvdisplay_single); }
tools/lvremove.c +1 -1
@@ -33,6 +33,6 @@ int lvremove(struct cmd_context *cmd, in cmd->handles_missing_pvs =1 ; -return process_each_lv (cmd, argc, argv,LCK_VG_WRITE ,NULL , +return process_each_lv (cmd, argc, argv,READ_FOR_UPDATE ,NULL , &lvremove_single); }
tools/lvscan.c +1 -1
@@ -80,6 +80,6 @@ int lvscan(struct cmd_context *cmd, intreturn EINVALID_CMD_LINE ; } -return process_each_lv (cmd, argc, argv,LCK_VG_READ ,NULL , +return process_each_lv (cmd, argc, argv,0 ,NULL , &lvscan_single); }
tools/polldaemon.c +3 -14
@@ -175,7 +175,7 @@ static int _wait_for_single_mirror(struc }static int _poll_vg (struct cmd_context *cmd,const char *vgname, -struct volume_group *vg,int consistent,void *handle) +struct volume_group *vg,void *handle) {struct daemon_parms *parms = (struct daemon_parms *) handle;struct lv_list *lvl;
@@ -183,18 +183,7 @@ static int _poll_vg(struct cmd_context *const char *name;int finished; -if (!vg) { -log_error ("Couldn't read volume group %s" , vgname); -return ECMD_FAILED ; - } - -if (!consistent) { -log_error ("Volume Group %s inconsistent - skipping" , vgname); -/* FIXME Should we silently recover it here or not? */ -return ECMD_FAILED ; - } - -if (!vg_check_status (vg,EXPORTED_VG )) +if (vg_read_error (vg))return ECMD_FAILED ; dm_list_iterate_items(lvl, &vg->lvs) {
@@ -219,7 +208,7 @@ static void _poll_for_all_vgs(struct cmd {while (1 ) { parms->outstanding_count =0 ; -process_each_vg (cmd,0 ,NULL ,LCK_VG_WRITE ,1 , parms, _poll_vg); +process_each_vg (cmd,0 ,NULL ,READ_FOR_UPDATE , parms, _poll_vg);if (!parms->outstanding_count)break ;sleep (parms->interval);
tools/reporter.c +10 -18
@@ -18,12 +18,10 @@static int _vgs_single (struct cmd_context *cmd __attribute((unused)),const char *vg_name,struct volume_group *vg, -int consistent __attribute((unused)),void *handle) +void *handle) { -if (!vg) { -log_error ("Volume group %s not found" , vg_name); +if (vg_read_error (vg))return ECMD_FAILED ; - }if (!report_object (handle, vg,NULL ,NULL ,NULL ,NULL ))return ECMD_FAILED ;
@@ -160,26 +158,20 @@ out:static int _pvs_in_vg (struct cmd_context *cmd,const char *vg_name,struct volume_group *vg, -int consistent __attribute((unused)),void *handle) { -if (!vg) { -log_error ("Volume group %s not found" , vg_name); +if (vg_read_error (vg))return ECMD_FAILED ; - }return process_each_pv_in_vg (cmd, vg,NULL , handle, &_pvs_single); }static int _pvsegs_in_vg (struct cmd_context *cmd,const char *vg_name,struct volume_group *vg, -int consistent __attribute((unused)),void *handle) { -if (!vg) { -log_error ("Volume group %s not found" , vg_name); +if (vg_read_error (vg))return ECMD_FAILED ; - }return process_each_pv_in_vg (cmd, vg,NULL , handle, &_pvsegs_single); }
@@ -352,23 +344,23 @@ static int _report(struct cmd_context *cswitch (report_type) {case LVS : - r =process_each_lv (cmd, argc, argv,LCK_VG_READ , report_handle, + r =process_each_lv (cmd, argc, argv,0 , report_handle, &_lvs_single);break ;case VGS : - r =process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 , - report_handle, &_vgs_single); + r =process_each_vg (cmd, argc, argv,0 , report_handle, + &_vgs_single);break ;case PVS :if (args_are_pvs) r =process_each_pv (cmd, argc, argv,NULL ,LCK_VG_READ , report_handle, &_pvs_single);else - r =process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 , + r =process_each_vg (cmd, argc, argv,0 , report_handle, &_pvs_in_vg);break ;case SEGS : - r =process_each_lv (cmd, argc, argv,LCK_VG_READ , report_handle, + r =process_each_lv (cmd, argc, argv,0 , report_handle, &_lvsegs_single);break ;case PVSEGS :
@@ -376,7 +368,7 @@ static int _report(struct cmd_context *c r =process_each_pv (cmd, argc, argv,NULL ,LCK_VG_READ , report_handle, &_pvsegs_single); else - r =process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 , + r =process_each_vg (cmd, argc, argv,0 , report_handle, &_pvsegs_in_vg);break ; }
tools/toollib.c +13 -80
167 lines not on this page · raw message
tools/toollib.h +3 -3
@@ -27,11 +27,11 @@ struct volume_group *recover_vg(struct c uint32_t lock_type);int process_each_vg (struct cmd_context *cmd,int argc,char **argv, -uint32_t lock_type,int consistent,void *handle, +uint32_t flags,void *handle,int (*process_single) (struct cmd_context * cmd,const char *vg_name,struct volume_group * vg, -int consistent,void *handle)); +void *handle)); int process_each_pv(struct cmd_context *cmd, int argc, char **argv, struct volume_group *vg, uint32_t lock_type, void *handle,
@@ -49,7 +49,7 @@ int process_each_segment_in_pv(struct cm void *handle));int process_each_lv (struct cmd_context *cmd,int argc,char **argv, -uint32_t lock_type,void *handle, +uint32_t flags,void *handle,int (*process_single) (struct cmd_context * cmd,struct logical_volume * lv,void *handle));
tools/vgcfgbackup.c +4 -9
@@ -48,19 +48,14 @@ static char *_expand_filename(const char } static int vg_backup_single(struct cmd_context *cmd, const char *vg_name, - struct volume_group *vg, int consistent, + struct volume_group *vg, void *handle) { char **last_filename = (char **)handle; char *filename; - if (!vg) { - log_error("Volume group \"%s\" not found", vg_name); + if (vg_read_error(vg) && !vg_read_error(vg) == FAILED_INCONSISTENT) return ECMD_FAILED; - } - - if (!consistent) - log_error("WARNING: Volume group \"%s\" inconsistent", vg_name); if (arg_count(cmd, file_ARG)) { if (!(filename = _expand_filename(arg_value(cmd, file_ARG),
@@ -72,7 +67,7 @@ static int vg_backup_single(struct cmd_cif (!backup_to_file (filename, vg->cmd->cmd_line, vg))return ECMD_FAILED ; }else { -if (!consistent) { +if (vg_read_error (vg) ==FAILED_INCONSISTENT ) {log_error ("No backup taken: specify filename with -f " "to backup an inconsistent VG" ); stack;
@@ -98,7 +93,7 @@ int vgcfgbackup(struct cmd_context *cmd,init_pvmove (1 ); - ret =process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 , &last_filename, + ret =process_each_vg (cmd, argc, argv,0 , &last_filename, &vg_backup_single);dm_free (last_filename);
tools/vgchange.c +3 -18
@@ -521,28 +521,13 @@ static int _vgchange_refresh(struct cmd_ }static int vgchange_single (struct cmd_context *cmd,const char *vg_name, -struct volume_group *vg,int consistent, +struct volume_group *vg,void *handle __attribute((unused))) {int r =ECMD_FAILED ; -if (!vg) { -log_error ("Unable to find volume group \"%s\"" , vg_name); +if (vg_read_error (vg))return ECMD_FAILED ; - } - -if (!consistent) { -unlock_vg (cmd, vg_name); -dev_close_all (); -log_error ("Volume group \"%s\" inconsistent" , vg_name); -if (!(vg =recover_vg (cmd, vg_name,LCK_VG_WRITE ))) -return ECMD_FAILED ; - } - -if (!(vg_status (vg) &LVM_WRITE ) && !arg_count (cmd, available_ARG)) { -log_error ("Volume group \"%s\" is read-only" , vg->name); -return ECMD_FAILED ; - }if (vg_status (vg) &EXPORTED_VG ) {log_error ("Volume group \"%s\" is exported" , vg_name);
@@ -633,6 +618,6 @@ int vgchange(struct cmd_context *cmd, inreturn process_each_vg (cmd, argc, argv, (arg_count (cmd, available_ARG)) ? -LCK_VG_READ :LCK_VG_WRITE ,0 ,NULL , +0 :READ_FOR_UPDATE ,NULL , &vgchange_single); }
tools/vgck.c +2 -15
@@ -17,27 +17,14 @@static int vgck_single (struct cmd_context *cmd __attribute((unused)),const char *vg_name, -struct volume_group *vg,int consistent, +struct volume_group *vg,void *handle __attribute((unused))) { -if (!vg) { -log_error ("Volume group \"%s\" not found" , vg_name); -return ECMD_FAILED ; - } - -if (!consistent) { -log_error ("Volume group \"%s\" inconsistent" , vg_name); -return ECMD_FAILED ; - } - -if (!vg_check_status (vg,EXPORTED_VG )) -return ECMD_FAILED ; -return ECMD_PROCESSED ; }int vgck (struct cmd_context *cmd,int argc,char **argv) { -return process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 ,NULL , +return process_each_vg (cmd, argc, argv,0 ,NULL , &vgck_single); }
tools/vgconvert.c +3 -16
@@ -16,7 +16,7 @@#include "tools.h" static int vgconvert_single (struct cmd_context *cmd,const char *vg_name, -struct volume_group *vg,int consistent, +struct volume_group *vg,void *handle __attribute((unused))) {struct physical_volume *pv, *existing_pv;
@@ -32,20 +32,7 @@ static int vgconvert_single(struct cmd_cstruct lvinfo info;int active =0 ; -if (!vg) { -log_error ("Unable to find volume group \"%s\"" , vg_name); -return ECMD_FAILED ; - } - -if (!consistent) { -unlock_vg (cmd, vg_name); -dev_close_all (); -log_error ("Volume group \"%s\" inconsistent" , vg_name); -if (!(vg =recover_vg (cmd, vg_name,LCK_VG_WRITE ))) -return ECMD_FAILED ; - } - -if (!vg_check_status (vg,LVM_WRITE |EXPORTED_VG )) +if (vg_read_error (vg))return ECMD_FAILED ;if (vg->fid->fmt == cmd->fmt) {
@@ -233,6 +220,6 @@ int vgconvert(struct cmd_context *cmd, ireturn EINVALID_CMD_LINE ; } -return process_each_vg (cmd, argc, argv,LCK_VG_WRITE ,0 ,NULL , +return process_each_vg (cmd, argc, argv,READ_FOR_UPDATE ,NULL , &vgconvert_single); }
tools/vgdisplay.c +3 -9
@@ -16,17 +16,12 @@#include "tools.h" static int vgdisplay_single (struct cmd_context *cmd,const char *vg_name, -struct volume_group *vg,int consistent, +struct volume_group *vg,void *handle __attribute((unused))) {/* FIXME Do the active check here if activevolumegroups_ARG ? */ -if (!vg) { -log_error ("Volume group \"%s\" doesn't exist" , vg_name); +if (vg_read_error (vg))return ECMD_FAILED ; - } - -if (!consistent) -log_error ("WARNING: Volume group \"%s\" inconsistent" , vg_name);vg_check_status (vg,EXPORTED_VG );
@@ -98,8 +93,7 @@ int vgdisplay(struct cmd_context *cmd, i} **********/ -return process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 ,NULL , - vgdisplay_single); +return process_each_vg (cmd, argc, argv,0 ,NULL , vgdisplay_single);/******** FIXME Need to count number processed Add this to process_each_vg if arg_count(cmd,activevolumegroups_ARG) ?
tools/vgexport.c +3 -14
@@ -17,25 +17,14 @@static int vgexport_single (struct cmd_context *cmd __attribute((unused)),const char *vg_name, -struct volume_group *vg,int consistent, +struct volume_group *vg,void *handle __attribute((unused))) {struct pv_list *pvl;struct physical_volume *pv; -if (!vg) { -log_error ("Unable to find volume group \"%s\"" , vg_name); +if (vg_read_error (vg)) goto error; - } - -if (!consistent) { -log_error ("Volume group %s inconsistent" , vg_name); - goto error; - } - -if (!vg_check_status (vg,EXPORTED_VG |LVM_WRITE )) { - goto error; - }if (lvs_in_vg_activated (vg)) { log_error("Volume group \"%s\" has active logical volumes",
@@ -78,6 +67,6 @@ int vgexport(struct cmd_context *cmd, inreturn ECMD_FAILED ; } -return process_each_vg (cmd, argc, argv,LCK_VG_WRITE ,1 ,NULL , +return process_each_vg (cmd, argc, argv,READ_FOR_UPDATE ,NULL , &vgexport_single); }
tools/vgimport.c +4 -6
@@ -17,17 +17,14 @@static int vgimport_single (struct cmd_context *cmd __attribute((unused)),const char *vg_name, -struct volume_group *vg,int consistent, +struct volume_group *vg,void *handle __attribute((unused))) {struct pv_list *pvl;struct physical_volume *pv; -if (!vg || !consistent) { -log_error ("Unable to find exported volume group \"%s\"" , - vg_name); +if (vg_read_error (vg)) goto error; - }if (!(vg_status (vg) &EXPORTED_VG )) {log_error ("Volume group \"%s\" is not exported" , vg_name);
@@ -74,6 +71,7 @@ int vgimport(struct cmd_context *cmd, inreturn ECMD_FAILED ; } -return process_each_vg (cmd, argc, argv,LCK_VG_WRITE ,1 ,NULL , +return process_each_vg (cmd, argc, argv, +READ_FOR_UPDATE |ALLOW_EXPORTED ,NULL , &vgimport_single); }
tools/vgremove.c +3 -3
@@ -16,10 +16,10 @@#include "tools.h" static int vgremove_single (struct cmd_context *cmd,const char *vg_name, -struct volume_group *vg,int consistent, +struct volume_group *vg,void *handle __attribute((unused))) { -if (!vg_remove_single (cmd, vg_name, vg, consistent, +if (!vg_remove_single (cmd, vg_name, vg,arg_count (cmd, force_ARG)))return ECMD_FAILED ;
@@ -41,7 +41,7 @@ int vgremove(struct cmd_context *cmd, in } ret =process_each_vg (cmd, argc, argv, -LCK_VG_WRITE |LCK_NONBLOCK ,1 , +READ_FOR_UPDATE |NONBLOCKING_LOCK ,NULL , &vgremove_single);unlock_vg (cmd,VG_ORPHANS );
tools/vgscan.c +3 -15
@@ -16,22 +16,11 @@#include "tools.h" static int vgscan_single (struct cmd_context *cmd,const char *vg_name, -struct volume_group *vg,int consistent, +struct volume_group *vg,void *handle __attribute((unused))) { -if (!vg) { -log_error ("Volume group \"%s\" not found" , vg_name); +if (vg_read_error (vg))return ECMD_FAILED ; - } - -if (!consistent) { -unlock_vg (cmd, vg_name); -dev_close_all (); -log_error ("Volume group \"%s\" inconsistent" , vg_name); -/* Don't allow partial switch to this program */ -if (!(vg =recover_vg (cmd, vg_name,LCK_VG_WRITE ))) -return ECMD_FAILED ; - } log_print("Found %svolume group \"%s\" using metadata type %s", (vg_status(vg) & EXPORTED_VG) ? "exported " : "", vg_name,
@@ -61,8 +50,7 @@ int vgscan(struct cmd_context *cmd, intlog_print ("Reading all physical volumes. This may take a while..." ); - maxret =process_each_vg (cmd, argc, argv,LCK_VG_READ ,0 ,NULL , - &vgscan_single); + maxret =process_each_vg (cmd, argc, argv,0 ,NULL , &vgscan_single);if (arg_count (cmd, mknodes_ARG)) { ret =vgmknodes (cmd, argc, argv);
PATCH 8/11 Convert vgreduce to use vg_read_for_update.
Fri Jan 9 15:38:20 CET 2009 Petr Rockai <[email protected]>
* Convert vgreduce to use vg_read_for_update.
tools/vgreduce.c +21 -35
@@ -382,7 +382,6 @@ static int _vgreduce_single(struct cmd_c {struct pv_list *pvl;struct volume_group *orphan_vg; -int consistent =1 ;const char *name =pv_dev_name (pv);if (pv_pe_alloc_count (pv)) {
@@ -396,17 +395,10 @@ static int _vgreduce_single(struct cmd_creturn ECMD_FAILED ; } -if (!lock_vol (cmd,VG_ORPHANS ,LCK_VG_WRITE |LCK_NONBLOCK )) { -log_error ("Can't get lock for orphan PVs" ); -return ECMD_FAILED ; - } - pvl =find_pv_in_vg (vg, name); -if (!archive (vg)) { -unlock_vg (cmd,VG_ORPHANS ); +if (!archive (vg))return ECMD_FAILED ; - }log_verbose ("Removing \"%s\" from volume group \"%s\"" , name, vg->name);
@@ -426,12 +418,11 @@ static int _vgreduce_single(struct cmd_c vg->free_count -=pv_pe_count (pv) -pv_pe_alloc_count (pv); vg->extent_count -=pv_pe_count (pv); -if (!(orphan_vg =vg_read_internal (cmd, vg->fid->fmt->orphan_vg_name,NULL , &consistent)) || - !consistent) { -log_error ("Unable to read existing orphan PVs" ); -unlock_vg (cmd,VG_ORPHANS ); + orphan_vg =vg_read_for_update (cmd, vg->fid->fmt->orphan_vg_name, +NULL ,NONBLOCKING_LOCK |ORPHAN_LOCK ); + +if (vg_read_error (orphan_vg))return ECMD_FAILED ; - }if (!vg_split_mdas (cmd, vg, orphan_vg) || !vg->pv_count) { log_error("Cannot remove final metadata area on \"%s\" from \"%s\"",
@@ -468,7 +459,6 @@ int vgreduce(struct cmd_context *cmd, instruct volume_group *vg;char *vg_name;int ret =1 ; -int consistent =1 ;int fixed =1 ;int repairing =arg_count (cmd, removemissing_ARG);
@@ -515,41 +505,37 @@ int vgreduce(struct cmd_context *cmd, in }log_verbose ("Finding volume group \"%s\"" , vg_name); -if (!lock_vol (cmd, vg_name,LCK_VG_WRITE )) { -log_error ("Can't get lock for %s" , vg_name); -return ECMD_FAILED ; - } -if ((!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent)) || !consistent) - && !repairing) { -log_error ("Volume group \"%s\" doesn't exist" , vg_name); -unlock_vg (cmd, vg_name); + vg =vg_read_for_update (cmd, vg_name,NULL ,ALLOW_EXPORTED ); +if (vg_read_error (vg) ==FAILED_ALLOCATION || +vg_read_error (vg) ==FAILED_NOTFOUND )return ECMD_FAILED ; - } -if (vg && !vg_check_status (vg,CLUSTERED )) { -unlock_vg (cmd, vg_name); +/* FIXME We want to allow read-only VGs to be changed here? */ +if (vg_read_error (vg) &&vg_read_error (vg) !=FAILED_READ_ONLY + && !arg_count (cmd, removemissing_ARG))return ECMD_FAILED ; - }if (repairing) { -if (vg && consistent && !vg_missing_pv_count (vg)) { +if (!vg_read_error (vg) && !vg_missing_pv_count (vg)) {log_error ("Volume group \"%s\" is already consistent" , vg_name);unlock_vg (cmd, vg_name);return ECMD_PROCESSED ; } - consistent = !arg_count (cmd, force_ARG); -if (!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent))) { -log_error ("Volume group \"%s\" not found" , vg_name); -unlock_vg (cmd, vg_name); -return ECMD_FAILED ; - } -if (!vg_check_status (vg,CLUSTERED )) { +log_verbose ("Trying to open VG %s for recovery..." , vg_name); + + vg =vg_read_for_update (cmd, vg_name,NULL , +ALLOW_INCONSISTENT |DISABLE_LOCK + |ALLOW_EXPORTED ); + +if (vg_read_error (vg) &&vg_read_error (vg) !=FAILED_READ_ONLY + &&vg_read_error (vg) !=FAILED_INCONSISTENT ) {unlock_vg (cmd, vg_name);return ECMD_FAILED ; } +if (!archive (vg)) {unlock_vg (cmd, vg_name);return ECMD_FAILED ;
PATCH 9/11 Convert vgrename to vg_read_for_update.
Fri Jan 9 15:46:59 CET 2009 Petr Rockai <[email protected]>
* Convert vgrename to vg_read_for_update.
tools/vgrename.c +11 -27
@@ -20,7 +20,6 @@ static int vg_rename_path(struct cmd_con {char *dev_dir;struct id id; -int consistent =1 ;int match =0 ;int found_id =0 ;struct dm_list *vgids;
@@ -70,25 +69,11 @@ static int vg_rename_path(struct cmd_con }else vgid =NULL ; -if (!lock_vol (cmd, vg_name_old,LCK_VG_WRITE )) { -log_error ("Can't get lock for %s" , vg_name_old); -return 0 ; - } - -if (!(vg =vg_read_internal (cmd, vg_name_old, vgid, &consistent)) || !consistent) { -log_error ("Volume group %s %s%s%snot found." , vg_name_old, - vgid ?"(" :"" , vgid ? vgid :"" , vgid ?") " :"" ); -unlock_vg (cmd, vg_name_old); -return 0 ; - } - -if (!vg_check_status (vg,CLUSTERED |LVM_WRITE )) { -unlock_vg (cmd, vg_name_old); -return 0 ; - } - -/* Don't return failure for EXPORTED_VG */ -vg_check_status (vg,EXPORTED_VG ); +/* FIXME we used to print an error about EXPORTED, but proceeded +nevertheless. */ + vg =vg_read_for_update (cmd, vg_name_old, vgid,ALLOW_EXPORTED ); +if (vg_read_error (vg)) + return_0;if (lvs_in_vg_activated_by_uuid_only (vg)) {unlock_vg (cmd, vg_name_old);
@@ -100,14 +85,13 @@ static int vg_rename_path(struct cmd_conlog_verbose ("Checking for new volume group \"%s\"" , vg_name_new); -if (!lock_vol (cmd, vg_name_new,LCK_VG_WRITE |LCK_NONBLOCK )) { -unlock_vg (cmd, vg_name_old); -log_error ("Can't get lock for %s" , vg_name_new); -return 0 ; - } + vg_new =vg_read_for_update (cmd, vg_name_new,NULL ,KEEP_LOCK | +EXISTENCE_CHECK |NONBLOCKING_LOCK ); + +if (vg_read_error (vg_new)) + goto error; - consistent =0 ; -if ((vg_new =vg_read_internal (cmd, vg_name_new,NULL , &consistent))) { +if (vg_might_exist (vg_new)) {log_error ("New volume group \"%s\" already exists" , vg_name_new); goto error;
PATCH 10/11 Convert vgsplit to use vg_read_for_update.
Fri Jan 9 15:47:09 CET 2009 Petr Rockai <[email protected]>
* Convert vgsplit to use vg_read_for_update.
tools/vgsplit.c +19 -18
@@ -320,21 +320,20 @@ int vgsplit(struct cmd_context *cmd, int }log_verbose ("Checking for volume group \"%s\"" , vg_name_from); -if (!(vg_from =vg_lock_and_read (cmd, vg_name_from,NULL ,LCK_VG_WRITE , -CLUSTERED |EXPORTED_VG | -RESIZEABLE_VG |LVM_WRITE , -CORRECT_INCONSISTENT |FAIL_INCONSISTENT ))) -return ECMD_FAILED ; + vg_from =vg_read_for_update (cmd, vg_name_from,NULL , +REQUIRE_RESIZEABLE ); +if (vg_read_error (vg_from)) +return ECMD_FAILED ;log_verbose ("Checking for new volume group \"%s\"" , vg_name_to); -if (!lock_vol (cmd, vg_name_to,LCK_VG_WRITE |LCK_NONBLOCK )) { -log_error ("Can't get lock for %s" , vg_name_to); -unlock_vg (cmd, vg_name_from); -return ECMD_FAILED ; - } + vg_to =vg_read_for_update (cmd, vg_name_to,NULL ,REQUIRE_RESIZEABLE | +NONBLOCKING_LOCK |KEEP_LOCK | +EXISTENCE_CHECK ); + +if (vg_read_error (vg_to)) + goto_bad; - consistent =0 ; -if ((vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent))) { +if (vg_might_exist (vg_to)) { existing_vg =1 ;if (new_vg_option_specified (cmd)) { log_error("Volume group \"%s\" exists, but new VG "
@@ -450,12 +449,14 @@ int vgsplit(struct cmd_context *cmd, int* Finally, remove the EXPORTED flag from the new VG and write it out. */ consistent =1 ; -if (!test_mode () && - (!(vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent)) || - !consistent)) { -log_error ("Volume group \"%s\" became inconsistent: please " -"fix manually" , vg_name_to); - goto_bad; +if (!test_mode ()) { + vg_to =vg_read_for_update (cmd, vg_name_to,NULL , +DISABLE_LOCK |ALLOW_EXPORTED ); +if (vg_read_error (vg_to)) { +log_error ("Volume group \"%s\" became inconsistent: " +"please fix manually" , vg_name_to); + goto_bad; + } } vg_to->status &= ~EXPORTED_VG ;
PATCH 11/11 Remove now-unused vg_lock_and_read.
Fri Jan 9 15:48:51 CET 2009 Petr Rockai <[email protected]>
* Remove now-unused vg_lock_and_read.
lib/metadata/metadata.c +0 -44
@@ -2422,50 +2422,6 @@ int vg_check_status(const struct volume_return !_vg_check_status (vg, status); } -/* -* vg_lock_and_read - consolidate vg locking, reading, and status flag checking -* -* Returns: -* NULL - failure -* non-NULL - success; volume group handle -*/ -vg_t *vg_lock_and_read (struct cmd_context *cmd,const char *vg_name, -const char *vgid, -uint32_t lock_flags,uint32_t status_flags, -uint32_t misc_flags) -{ -struct volume_group *vg; -int consistent =1 ; - -if (!(misc_flags &CORRECT_INCONSISTENT )) - consistent =0 ; - -if (!validate_name (vg_name)) { -log_error ("Volume group name %s has invalid characters" , - vg_name); -return NULL ; - } - -if (!lock_vol (cmd, vg_name, lock_flags)) { -log_error ("Can't get lock for %s" , vg_name); -return NULL ; - } - -if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent)) || - ((misc_flags &FAIL_INCONSISTENT ) && !consistent)) { -log_error ("Volume group \"%s\" not found" , vg_name); -unlock_vg (cmd, vg_name); -return NULL ; - } - -if (!vg_check_status (vg, status_flags)) { -unlock_vg (cmd, vg_name); -return NULL ; - } - -return vg; -} -static vg_t *_vg_make_handle (struct cmd_context *cmd,struct volume_group *vg,uint32_t failure)
PATCH 11/11 Remove now-unused vg_lock_and_read.
Quoted 43 lines · Petr Rockai
Fri Jan 9 15:48:51 CET 2009 Petr Rockai <[email protected]>
* Remove now-unusedvg_lock_and_read.
diff -rN -u -pold-lvmlib_apply/lib/metadata/metadata.cnew-lvmlib_apply/lib/metadata/metadata.clib/metadata/metadata.c +0
-34@@ -2422,50 +2422,6 @@ int vg_check_status(const struct volume_return !_vg_check_status (vg, status); } -/* -* vg_lock_and_read - consolidate vg locking, reading, and status flag checking -* -* Returns: -* NULL - failure -* non-NULL - success; volume group handle -*/ -vg_t *vg_lock_and_read (struct cmd_context *cmd,const char *vg_name, -const char *vgid, -uint32_t lock_flags,uint32_t status_flags, -uint32_t misc_flags) -{ -struct volume_group *vg; -int consistent =1 ; - -if (!(misc_flags &CORRECT_INCONSISTENT )) - consistent =0 ; - -if (!validate_name (vg_name)) { -log_error ("Volume group name %s has invalid characters" , - vg_name); -return NULL ; - } - -if (!lock_vol (cmd, vg_name, lock_flags)) { -log_error ("Can't get lock for %s" , vg_name); -return NULL ; - } - -if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent)) || - ((misc_flags &FAIL_INCONSISTENT ) && !consistent)) { -log_error ("Volume group \"%s\" not found" , vg_name); -unlock_vg (cmd, vg_name); -return NULL ;
lib/metadata/metadata.c int vg_check_status(const struct volume_ · line 2468
Quoted 10 lines
lib/metadata/metadata.c +0
-10- } - -if (!vg_check_status (vg, status_flags)) { -unlock_vg (cmd, vg_name); -return NULL ; - } - -return vg; -} -
Please also remove CORRECT_INCONSISTENT and FAIL_INCONSISTENT definitions with this patch.
PATCH 10/11 Convert vgsplit to use vg_read_for_update.
In reply to Petr RockaiQuoted 39 lines · Petr Rockai
Fri Jan 9 15:47:09 CET 2009 Petr Rockai <[email protected]>
* Convert vgsplit to usevg_read_for_update.
diff -rN -u -pold-lvmlib_apply/tools/vgsplit.cnew-lvmlib_apply/tools/vgsplit.ctools/vgsplit.c +11
-12@@ -320,21 +320,20 @@ int vgsplit(struct cmd_context *cmd, int }log_verbose ("Checking for volume group \"%s\"" , vg_name_from); -if (!(vg_from =vg_lock_and_read (cmd, vg_name_from,NULL ,LCK_VG_WRITE , -CLUSTERED |EXPORTED_VG | -RESIZEABLE_VG |LVM_WRITE , -CORRECT_INCONSISTENT |FAIL_INCONSISTENT ))) -return ECMD_FAILED ; + vg_from =vg_read_for_update (cmd, vg_name_from,NULL , +REQUIRE_RESIZEABLE ); +if (vg_read_error (vg_from)) +return ECMD_FAILED ;log_verbose ("Checking for new volume group \"%s\"" , vg_name_to); -if (!lock_vol (cmd, vg_name_to,LCK_VG_WRITE |LCK_NONBLOCK )) { -log_error ("Can't get lock for %s" , vg_name_to); -unlock_vg (cmd, vg_name_from); -return ECMD_FAILED ; - } + vg_to =vg_read_for_update (cmd, vg_name_to,NULL ,REQUIRE_RESIZEABLE | +NONBLOCKING_LOCK |KEEP_LOCK | +EXISTENCE_CHECK ); + +if (vg_read_error (vg_to)) + goto_bad; - consistent =0 ; -if ((vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent))) { +if (vg_might_exist (vg_to)) { existing_vg =1 ;if (new_vg_option_specified (cmd)) { log_error("Volume group \"%s\" exists, but new VG "
tools/vgsplit.c int vgsplit(struct cmd_context *cmd, int · line 451
Quoted 3 lines
tools/vgsplit.c +0
-0@@ -450,12 +449,14 @@ int vgsplit(struct cmd_context *cmd, int* Finally, remove the EXPORTED flag from the new VG and write it out. */ consistent =1 ;
You can also remove consistent here and in the declaration.
Quoted 22 lines
tools/vgsplit.c +8
-7-if (!test_mode () && - (!(vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent)) || - !consistent)) { -log_error ("Volume group \"%s\" became inconsistent: please " -"fix manually" , vg_name_to); - goto_bad; +if (!test_mode ()) { + vg_to =vg_read_for_update (cmd, vg_name_to,NULL , +DISABLE_LOCK |ALLOW_EXPORTED ); +if (vg_read_error (vg_to)) { +log_error ("Volume group \"%s\" became inconsistent: " +"please fix manually" , vg_name_to); + goto_bad; + } } vg_to->status &= ~EXPORTED_VG ; --lvm-devel mailing list
lvm-devel at redhat.com
https://www.redhat.com/mailman/listinfo/lvm-devel
PATCH 4/11 Add vg_read_error and vg_might_exist.
In reply to Petr RockaiQuoted 1 line · Peter Rockai
+uint32_t
vg_read_error(vg_t *vg){
{ on new line please.
Again, I suggest using a typedef for the return value.
lib/metadata/metadata.c static vg_t *_vg_lock_and_read(struct cm · line 2598
Quoted 6 lines
lib/metadata/metadata.c +6
-0+if (!vg) +return FAILED_ALLOCATION ; +if (vg->read_failed &EXISTENCE_CHECK ) +return vg->read_failed & ~(EXISTENCE_CHECK |FAILED_NOTFOUND ); +return vg->read_failed; +}
Let's explain that logic in a description above the function (or in the .h file where the FAILED* are defined).
- Why are some combinations valid in some parts of the code but not in others?
- Is the EXISTENCE_CHECK part obfuscation that could be done more cleanly?
lib/metadata/metadata-exported.h vg_t *vg_lock_and_read(struct cmd_contex · line 385
Quoted 3 lines
lib/metadata/metadata-exported.h +3
-0+/* Queries on a (possibly error-indicating) VG handle. */ +uint32_t vg_read_error (vg_t *vg); +uint32_t vg_might_exist (vg_t *vg);
Explain what the uint32_t returned means. (Or use a typedef which should be self-documenting.)
Alasdair
Signature · 1 line
agk at redhat.com
PATCH 3/11 Replace implementation of vg_check_status with a call to _vg_check_status.
In reply to Petr Rockailib/metadata/metadata.c int pv_analyze(struct cmd_context *cmd, · line 2380
Quoted 4 lines · Peter Rockai
* Replace implementation of
vg_check_statuswith a call to_vg_check_status.lib/metadata/metadata.c +1
-1-int vg_check_status (const struct volume_group *vg,uint32_t status) +static uint32_t _vg_check_status (const struct volume_group *vg,uint32_t status)
typedef for the return value?
lib/metadata/metadata.c int pv_analyze(struct cmd_context *cmd, · line 2382
Quoted 2 lines
{
lib/metadata/metadata.c +1
-0+uint32_t ret =0 ;
This is more than a simple yes/no return value, call it the same as whatever you decide to call it elsewhere e.g. 'failure'.
lib/metadata/metadata.c int pv_analyze(struct cmd_context *cmd, · line 2388
Quoted 7 lines
lib/metadata/metadata.c +1
-1if ((status &CLUSTERED ) && (vg_is_clustered (vg)) && !locking_is_clustered () && !lockingfailed ()) {log_error ("Skipping clustered volume group %s" , vg->name); -return 0 ; + ret |=FAILED_CLUSTERED ; }
If we're skipping the VG, why do we want to perform the other checks now?
Alasdair
Signature · 1 line
agk at redhat.com
PATCH 2/11 Provide _vg_lock_and_read, a new implementation of lock+vg_read_internal.
In reply to Petr RockaiFirst pass through this patch.
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2469
Quoted 13 lines · Peter Rockai
diff -rN -u -p
old-lvmlib_apply/lib/metadata/metadata.cnew-lvmlib_apply/lib/metadata/metadata.clib/metadata/metadata.c +6
-0@@ -2461,6 +2461,160 @@ vg_t *vg_lock_and_read(struct cmd_contexreturn vg; } +static vg_t *_vg_make_handle (struct cmd_context *cmd, +struct volume_group *vg, +uint32_t failure) +{ +if (!vg) +if (!(vg =dm_pool_zalloc (cmd->mem,sizeof (*vg))))
Join those together with &&.
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2470
Quoted 1 line
lib/metadata/metadata.c +1
-0+ return_NULL;
Error message here, please.dm_pool_zalloc() doesn't issue one itself so the caller can provide more context such as what the thing that couldn't be allocated was for.
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2472
Quoted 3 lines
lib/metadata/metadata.c +2
-0+ vg->read_failed = failure; +return vg;
Explicit cast, please, to make it obvious what's happening.
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2477
Quoted 5 lines
lib/metadata/metadata.c +5
-0+} + +static uint32_t _vg_check_status (const struct volume_group *vg,uint32_t status) +{ +uint32_t ret =0 ;
Add blank line after auto variables are defined.
Quoted 39 lines
lib/metadata/metadata.c +39
-0+if ((status &CLUSTERED ) && + (vg_is_clustered (vg)) && !locking_is_clustered () && + !lockingfailed ()) { +log_error ("Skipping clustered volume group %s" , vg->name); + ret |=FAILED_CLUSTERED ; + } + +if ((status &EXPORTED_VG ) && + (vg->status &EXPORTED_VG )) { +log_error ("Volume group %s is exported" , vg->name); + ret |=FAILED_EXPORTED ; + } + +if ((status &LVM_WRITE ) && + !(vg->status &LVM_WRITE )) { +log_error ("Volume group %s is read-only" , vg->name); + ret |=FAILED_READ_ONLY ; + } + +if ((status &RESIZEABLE_VG ) && + !(vg->status &RESIZEABLE_VG )) { +log_error ("Volume group %s is not resizeable." , vg->name); + ret |=FAILED_RESIZEABLE ; + } + +return ret; +} + +static vg_t *_recover_vg (struct cmd_context *cmd,const char *lock, +const char *vg_name,const char *vgid, +uint32_t lock_flags) +{ +int consistent =1 ; +struct volume_group *vg; + + lock_flags &= ~LCK_TYPE_MASK ; + lock_flags |=LCK_WRITE ; + +unlock_vg (cmd, lock);
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2526
Quoted 10 lines
lib/metadata/metadata.c +10
-0+ +dev_close_all (); + +if (!lock_vol (cmd, lock, lock_flags)) + return_NULL; + +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) + return_NULL; +if (!consistent) + return_NULL;
Add blank line
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2528
Quoted 1 line
lib/metadata/metadata.c +1
-0+return vg;
Explicit cast.
Quoted 21 lines
lib/metadata/metadata.c +21
-0+} + +/* +* _vg_lock_and_read - consolidate vg locking, reading, and status flag checking +* This is an internal function. +* +* misc_flags: +* ALLOW_INCONSISTENT: disable autocorrection +* +* Setting ALLOW_INCONSISTENT might give you inconsistent metadata. You will +* *still* get FAILED_INCONSISTENT in case the metadata has *really* been +* inconsistent. However, you still get the latest version of metadata in VG. +* +* Returns: +* Use vg_read_error(vg) to determine the result. Nonzero vg_read_error(vg) +* means there were problems reading the volume group. +* Zero value means that the VG is open and appropriate locks are held. +*/ +static vg_t *_vg_lock_and_read(struct cmd_context *cmd, const char *vg_name, + const char *vgid, + uint32_t lock_flags, uint32_t status_flags,
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2558
Quoted 10 lines
lib/metadata/metadata.c +10
-0+ uint32_t misc_flags) +{ +struct volume_group *vg =0 ; +const char *lock; +int consistent =1 ; +int consistent_in; +uint32_t failure =0 ; + +if (misc_flags &ALLOW_INCONSISTENT || !(lock_flags &LCK_WRITE )) + consistent =0 ;
indent
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2567
Quoted 8 lines
lib/metadata/metadata.c +8
-0+if (!validate_name (vg_name) && !is_orphan_vg (vg_name)) { +log_error ("Volume group name %s has invalid characters" , + vg_name); +return NULL ; + } + + lock = (misc_flags &ORPHAN_LOCK ?VG_ORPHANS : vg_name); +if (!(misc_flags &DISABLE_LOCK )) {
&&
Quoted 21 lines
lib/metadata/metadata.c +21
-0+if (!lock_vol (cmd, lock, lock_flags)) { +log_error ("Can't get lock for %s" , vg_name); +return _vg_make_handle (cmd, vg,FAILED_LOCKING ); + } + } + +if (misc_flags &ORPHAN_LOCK ) + status_flags &= ~LVM_WRITE ; + +if (misc_flags &EXISTENCE_CHECK ) + consistent =0 ; + + consistent_in = consistent; + +/* If consistent == 1, we get NULL here if correction fails. */ +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) { +if (consistent_in && !consistent) { +log_error ("Volume group \"%s\" inconsistent." , vg_name); + failure |=FAILED_INCONSISTENT ; + goto_bad; + }
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2598
Quoted 10 lines
lib/metadata/metadata.c +10
-0+if (!(misc_flags &EXISTENCE_CHECK )) +log_error ("Volume group \"%s\" not found" , vg_name); + failure |=FAILED_NOTFOUND | (misc_flags &EXISTENCE_CHECK ); + goto_bad; + } + +/* consistent == 0 when VG is not found, but failed == FAILED_NOTFOUND */ +if (!consistent && !failure) { + vg =_recover_vg (cmd, lock, vg_name, vgid, lock_flags); +if (!vg) {
&& (!(vg = ...)
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2610
Quoted 12 lines
lib/metadata/metadata.c +12
-0+log_error ("Recovery of volume group \"%s\" failed." , + vg_name); + failure |=FAILED_INCONSISTENT ; + goto_bad; + } + } + + failure |=_vg_check_status (vg, status_flags); +if (failure) + goto_bad; + +return _vg_make_handle (cmd, vg, failure);
blank line
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2612
Quoted 2 lines
lib/metadata/metadata.c +2
-0+ bad: +if (failure != (FAILED_NOTFOUND |EXISTENCE_CHECK ))
&&
Quoted 17 lines
lib/metadata/metadata.c +5
-0+if (!(misc_flags &KEEP_LOCK ) && !(misc_flags &DISABLE_LOCK )) +unlock_vg (cmd, lock); +return _vg_make_handle (cmd, vg, failure); +} +/* * Gets/Sets for external LVM library */ diff -rN -u -p
old-lvmlib_apply/lib/metadata/metadata-exported.hnew-lvmlib_apply/lib/metadata/metadata-exported.hlib/metadata/metadata-exported.h +2
-0@@ -104,6 +104,32 @@ struct pv_segment;#define MIRROR_BY_LV 0x00000002U/* mirror using whole mimage LVs */ #define MIRROR_SKIP_INIT_SYNC 0x00000010U/* skip initial sync */ +/* vg_read and vg_read_for_update flags */ +#define ALLOW_INCONSISTENT 0x1
lib/metadata/metadata-exported.h struct pv_segment; · line 118
Quoted 10 lines
lib/metadata/metadata-exported.h +10
-0+#define ALLOW_EXPORTED 0x2 +#define REQUIRE_RESIZEABLE 0x4 +#define EXISTENCE_CHECK 0x8 + +#define NONBLOCKING_LOCK 0x100 +#define KEEP_LOCK 0x200 +#define DISABLE_LOCK 0x400 +#define ORPHAN_LOCK 0x800 + +#define READ_FOR_UPDATE 0x1000
Use a common prefix so they get grouped together.
Line up the 0x0000 parts vertically making their "single bit" nature more obvious.
lib/metadata/metadata-exported.h struct pv_segment; · line 124
Quoted 5 lines
lib/metadata/metadata-exported.h +5
-0+/* vg's "read_failed" field */ +#define FAILED_INCONSISTENT 0x1 +#define FAILED_LOCKING 0x2 +#define FAILED_NOTFOUND 0x4 +// 0x8 is left out for EXISTENCE_CHECK
Ambiguous meaning - which is it?
1. self-evident (delete).
2. reserved for future (say 'reserved').
lib/metadata/metadata-exported.h struct pv_segment; · line 131
Quoted 7 lines
lib/metadata/metadata-exported.h +7
-0+ +#define FAILED_READ_ONLY 0x10 +#define FAILED_EXPORTED 0x20 +#define FAILED_RESIZEABLE 0x40 +#define FAILED_CLUSTERED 0x80 + +#define FAILED_ALLOCATION 0x100
line up the 0x0000 parts
lib/metadata/metadata-exported.h struct volume_group { · line 229
Quoted 11 lines
lib/metadata/metadata-exported.h +1
-0/* Ordered list - see lv_manip.c */ typedef enum { ALLOC_INVALID,@@ -197,6 +223,7 @@ struct volume_group {char *system_id;uint32_t status; +uint32_t read_failed;alloc_policy_t alloc;uint32_t extent_size;
Alasdair
Signature · 1 line
agk at redhat.com
PATCH 2/11 Provide _vg_lock_and_read, a new implementation of lock+vg_read_internal.
In reply to Petr RockaiSecond pass.
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2466
Quoted 3 lines
lib/metadata/metadata.c +3
-0+static vg_t *_vg_make_handle (struct cmd_context *cmd, +struct volume_group *vg, +uint32_t failure)
Is this only used for failures?
If so, call it _vg_make_failure_handle.
You can have a typedef for 'failure' if you want.
- Are you planning to expose 'failure' through the API eventually? Use a common prefix like lvm_ or LVM_ for everything you plan to expose. (Cf. dm_ and DM_ in libdevmapper.)
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2518
Quoted 13 lines
lib/metadata/metadata.c +13
-0+static vg_t *_recover_vg (struct cmd_context *cmd,const char *lock, +const char *vg_name,const char *vgid, +uint32_t lock_flags) +{ +int consistent =1 ; +struct volume_group *vg; + + lock_flags &= ~LCK_TYPE_MASK ; + lock_flags |=LCK_WRITE ; + +unlock_vg (cmd, lock); + +dev_close_all ();
[note to check call paths later if more than one VG lock is held simultaneously]
Quoted 16 lines
lib/metadata/metadata.c +9
-0+if (!lock_vol (cmd, lock, lock_flags)) + return_NULL; + +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) + return_NULL; +if (!consistent) + return_NULL; +return vg; +}lib/metadata/metadata-exported.h +0
-0@@ -104,6 +104,32 @@ struct pv_segment;#define MIRROR_BY_LV 0x00000002U/* mirror using whole mimage LVs */ #define MIRROR_SKIP_INIT_SYNC 0x00000010U/* skip initial sync */
lib/metadata/metadata-exported.h struct pv_segment; · line 116
Quoted 10 lines
lib/metadata/metadata-exported.h +10
-0+/* vg_read and vg_read_for_update flags */ +#define ALLOW_INCONSISTENT 0x1 +#define ALLOW_EXPORTED 0x2 +#define REQUIRE_RESIZEABLE 0x4 +#define EXISTENCE_CHECK 0x8 + +#define NONBLOCKING_LOCK 0x100 +#define KEEP_LOCK 0x200 +#define DISABLE_LOCK 0x400 +#define ORPHAN_LOCK 0x800
Define these in comments.
I hope all the '_LOCK' ones will be internal eventually, as locking will be handled internally by the library and the caller has no need to know it's happening. Unsure why ORPHAN and DISABLE are combined into that same group.
lib/metadata/metadata-exported.h struct volume_group { · line 226
Quoted 5 lines
lib/metadata/metadata-exported.h +1
-0@@ -197,6 +223,7 @@ struct volume_group {char *system_id;uint32_t status; +uint32_t read_failed;
Let's add a brief comment explaining this one. read_failed ? Yes or No. Rename it perhaps?
I think it should be completely separate from 'status' and 'alloc'.
lib/metadata/metadata-exported.h struct volume_group { · line 227
Quoted 1 line
lib/metadata/metadata-exported.h +0
-0alloc_policy_t alloc;
Alasdair
Signature · 1 line
agk at redhat.com
PATCH 2/11 Provide _vg_lock_and_read, a new implementation of lock+vg_read_internal.
In reply to Petr RockaiQuoted 44 lines · Petr Rockai
Fri Jan 9 14:21:23 CET 2009 Petr Rockai <[email protected]>
* Provide_vg_lock_and_read, a new implementation of lock+vg_read_internal.This is an internal function, to be later used by
vg_readandvg_read_for_update. Not to be confused with the public functionvg_lock_and_read, which will be removed later.
diff -rN -u -pold-lvmlib_apply/lib/metadata/metadata.cnew-lvmlib_apply/lib/metadata/metadata.clib/metadata/metadata.c +31
-0@@ -2461,6 +2461,160 @@ vg_t *vg_lock_and_read(struct cmd_contexreturn vg; } +static vg_t *_vg_make_handle (struct cmd_context *cmd, +struct volume_group *vg, +uint32_t failure) +{ +if (!vg) +if (!(vg =dm_pool_zalloc (cmd->mem,sizeof (*vg)))) + return_NULL; + vg->read_failed = failure; +return vg; +} + +static uint32_t _vg_check_status (const struct volume_group *vg,uint32_t status) +{ +uint32_t ret =0 ; +if ((status &CLUSTERED ) && + (vg_is_clustered (vg)) && !locking_is_clustered () && + !lockingfailed ()) { +log_error ("Skipping clustered volume group %s" , vg->name); + ret |=FAILED_CLUSTERED ; + } + +if ((status &EXPORTED_VG ) && + (vg->status &EXPORTED_VG )) { +log_error ("Volume group %s is exported" , vg->name); + ret |=FAILED_EXPORTED ; + } + +if ((status &LVM_WRITE ) && + !(vg->status &LVM_WRITE )) { +log_error ("Volume group %s is read-only" , vg->name); + ret |=FAILED_READ_ONLY ;
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2504
Quoted 10 lines
lib/metadata/metadata.c +10
-0+ } + +if ((status &RESIZEABLE_VG ) && + !(vg->status &RESIZEABLE_VG )) { +log_error ("Volume group %s is not resizeable." , vg->name); + ret |=FAILED_RESIZEABLE ; + } + +return ret; +}
Note only FAILED_READ_ONLY is used by any tool today - only vgreduce. Further, FAILED_READ_ONLY can only occur with LVM1 metadata as far as I can tell.
Quoted 50 lines
lib/metadata/metadata.c +50
-0+ +static vg_t *_recover_vg (struct cmd_context *cmd,const char *lock, +const char *vg_name,const char *vgid, +uint32_t lock_flags) +{ +int consistent =1 ; +struct volume_group *vg; + + lock_flags &= ~LCK_TYPE_MASK ; + lock_flags |=LCK_WRITE ; + +unlock_vg (cmd, lock); + +dev_close_all (); + +if (!lock_vol (cmd, lock, lock_flags)) + return_NULL; + +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) + return_NULL; +if (!consistent) + return_NULL; +return vg; +} + +/* +* _vg_lock_and_read - consolidate vg locking, reading, and status flag checking +* This is an internal function. +* +* misc_flags: +* ALLOW_INCONSISTENT: disable autocorrection +* +* Setting ALLOW_INCONSISTENT might give you inconsistent metadata. You will +* *still* get FAILED_INCONSISTENT in case the metadata has *really* been +* inconsistent. However, you still get the latest version of metadata in VG. +* +* Returns: +* Use vg_read_error(vg) to determine the result. Nonzero vg_read_error(vg) +* means there were problems reading the volume group. +* Zero value means that the VG is open and appropriate locks are held. +*/ +static vg_t *_vg_lock_and_read (struct cmd_context *cmd,const char *vg_name, +const char *vgid, +uint32_t lock_flags,uint32_t status_flags, +uint32_t misc_flags) +{ +struct volume_group *vg =0 ; +const char *lock; +int consistent =1 ; +int consistent_in;
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2564
Quoted 10 lines
lib/metadata/metadata.c +10
-0+uint32_t failure =0 ; + +if (misc_flags &ALLOW_INCONSISTENT || !(lock_flags &LCK_WRITE )) + consistent =0 ; + +if (!validate_name (vg_name) && !is_orphan_vg (vg_name)) { +log_error ("Volume group name %s has invalid characters" , + vg_name); +return NULL ; + }
Is there a reason to return NULL here when a handle with an error code is returned everywhere else?
Note that callling vg_read_error() after hitting this path will return FAILED_ALLOCATION. Do we need FAILED_INVALID_NAME or perhaps re-use FAILED_NOT_FOUND?
Quoted 105 lines
lib/metadata/metadata.c +53
-0+ + lock = (misc_flags &ORPHAN_LOCK ?VG_ORPHANS : vg_name); +if (!(misc_flags &DISABLE_LOCK )) { +if (!lock_vol (cmd, lock, lock_flags)) { +log_error ("Can't get lock for %s" , vg_name); +return _vg_make_handle (cmd, vg,FAILED_LOCKING ); + } + } + +if (misc_flags &ORPHAN_LOCK ) + status_flags &= ~LVM_WRITE ; + +if (misc_flags &EXISTENCE_CHECK ) + consistent =0 ; + + consistent_in = consistent; + +/* If consistent == 1, we get NULL here if correction fails. */ +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) { +if (consistent_in && !consistent) { +log_error ("Volume group \"%s\" inconsistent." , vg_name); + failure |=FAILED_INCONSISTENT ; + goto_bad; + } +if (!(misc_flags &EXISTENCE_CHECK )) +log_error ("Volume group \"%s\" not found" , vg_name); + failure |=FAILED_NOTFOUND | (misc_flags &EXISTENCE_CHECK ); + goto_bad; + } + +/* consistent == 0 when VG is not found, but failed == FAILED_NOTFOUND */ +if (!consistent && !failure) { + vg =_recover_vg (cmd, lock, vg_name, vgid, lock_flags); +if (!vg) { +log_error ("Recovery of volume group \"%s\" failed." , + vg_name); + failure |=FAILED_INCONSISTENT ; + goto_bad; + } + } + + failure |=_vg_check_status (vg, status_flags); +if (failure) + goto_bad; + +return _vg_make_handle (cmd, vg, failure); + bad: +if (failure != (FAILED_NOTFOUND |EXISTENCE_CHECK )) +if (!(misc_flags &KEEP_LOCK ) && !(misc_flags &DISABLE_LOCK )) +unlock_vg (cmd, lock); +return _vg_make_handle (cmd, vg, failure); +} +/* * Gets/Sets for external LVM library */ diff -rN -u -p
old-lvmlib_apply/lib/metadata/metadata-exported.hnew-lvmlib_apply/lib/metadata/metadata-exported.hlib/metadata/metadata-exported.h +27
-1@@ -104,6 +104,32 @@ struct pv_segment;#define MIRROR_BY_LV 0x00000002U/* mirror using whole mimage LVs */ #define MIRROR_SKIP_INIT_SYNC 0x00000010U/* skip initial sync */ +/* vg_read and vg_read_for_update flags */ +#define ALLOW_INCONSISTENT 0x1 +#define ALLOW_EXPORTED 0x2 +#define REQUIRE_RESIZEABLE 0x4 +#define EXISTENCE_CHECK 0x8 + +#define NONBLOCKING_LOCK 0x100 +#define KEEP_LOCK 0x200 +#define DISABLE_LOCK 0x400 +#define ORPHAN_LOCK 0x800 + +#define READ_FOR_UPDATE 0x1000 + +/* vg's "read_failed" field */ +#define FAILED_INCONSISTENT 0x1 +#define FAILED_LOCKING 0x2 +#define FAILED_NOTFOUND 0x4 +// 0x8 is left out for EXISTENCE_CHECK + +#define FAILED_READ_ONLY 0x10 +#define FAILED_EXPORTED 0x20 +#define FAILED_RESIZEABLE 0x40 +#define FAILED_CLUSTERED 0x80 + +#define FAILED_ALLOCATION 0x100 +/* Ordered list - see lv_manip.c */ typedef enum { ALLOC_INVALID,@@ -197,6 +223,7 @@ struct volume_group {char *system_id;uint32_t status; +uint32_t read_failed;alloc_policy_t alloc;uint32_t extent_size; --lvm-devel mailing list
lvm-devel at redhat.com
https://www.redhat.com/mailman/listinfo/lvm-devel
PATCH 2/11 Provide _vg_lock_and_read, a new implementation of lock+vg_read_internal.
Quoted 3 lines · Dave Wysochanski
Note only
FAILED_READ_ONLYis used by any tool today - only vgreduce. Further,FAILED_READ_ONLYcan only occur with LVM1 metadata as far as I can tell.
Could be. I'd propose to address this separately though, since I suppose we want to change semantics of things for this -- make the read-only failure deprecated and maybe just issue a warning whenever the flag is encountered, when opening read-write?
Quoted 9 lines
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2564
Quoted 5 lines
lib/metadata/metadata.c +5
-0+if (!validate_name (vg_name) && !is_orphan_vg (vg_name)) { +log_error ("Volume group name %s has invalid characters" , + vg_name); +return NULL ; + }Is there a reason to return NULL here when a handle with an error code is returned everywhere else?
Quoted 3 lines
Note that callling
vg_read_error()after hitting this path will returnFAILED_ALLOCATION. Do we needFAILED_INVALID_NAMEor perhaps re-useFAILED_NOT_FOUND?
Basically, the reason is just that no tool ever seems to care. It's true that it's not very nice to turn up FAILED_ALLOCATION, but in case that's what API user gets, they should just abort anyway -- the library code has already printed the error message (like it is the case here). We could differentiate that though, I have no strong opinion. Maybe add a patch on top though.
Yours,
Petr.
PS: I am sending an amended patch in a while (re. Alasdair's comments), I just need to rebase the rest of the stack on top and check that tests still pass, ie. I didn't botch the thing inadvertently.
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentationPATCH 2/11 Provide _vg_lock_and_read, a new implementation of lock+vg_read_internal.
Quoted 9 lines · Petr Rockai
Quoted 3 lines · Dave Wysochanski
Note only
FAILED_READ_ONLYis used by any tool today - only vgreduce. Further,FAILED_READ_ONLYcan only occur with LVM1 metadata as far as I can tell.Could be. I'd propose to address this separately though, since I suppose we want to change semantics of things for this -- make the read-only failure deprecated and maybe just issue a warning whenever the flag is encountered, when opening read-write?
Fine to address separately - let's make a note of it.
Quoted 9 lines
Quoted 9 lines
lib/metadata/metadata.c vg_t *vg_lock_and_read(struct cmd_contex · line 2564
Quoted 5 lines
lib/metadata/metadata.c +5
-0+if (!validate_name (vg_name) && !is_orphan_vg (vg_name)) { +log_error ("Volume group name %s has invalid characters" , + vg_name); +return NULL ; + }Is there a reason to return NULL here when a handle with an error code is returned everywhere else?
Quoted 9 lines
Quoted 3 lines
Note that callling
vg_read_error()after hitting this path will returnFAILED_ALLOCATION. Do we needFAILED_INVALID_NAMEor perhaps re-useFAILED_NOT_FOUND?Basically, the reason is just that no tool ever seems to care. It's true that it's not very nice to turn up
FAILED_ALLOCATION, but in case that's what API user gets, they should just abort anyway -- the library code has already printed the error message (like it is the case here). We could differentiate that though, I have no strong opinion. Maybe add a patch on top though.
Fine with me to clean up later. I would imagine we'll have some error code refinement to do anyway.
PATCH 1/11 Move vg_read out of the way, renaming it to vg_read_internal.
In reply to Petr RockaiQuoted 6 lines · Petr Rockai
Fri Jan 9 14:04:27 CET 2009 Petr Rockai <[email protected]>
* Movevg_readout of the way, renaming it tovg_read_internal.
diff -rN -u -pold-lvmlib_apply/daemons/clvmd/lvm-functions.cnew-lvmlib_apply/daemons/clvmd/lvm-functions.c
daemons/clvmd/lvm-functions.c void lvm_do_backup(const char *vgname) · line 717
Quoted 8 lines
daemons/clvmd/lvm-functions.c +1
-1@@ -711,7 +711,7 @@ void lvm_do_backup(const char *vgname)DEBUGLOG ("Triggering backup of VG metadata for %s. suspended=%d\n" , vgname, suspended); - vg =vg_read (cmd, vgname,NULL /*vgid*/ , &consistent); + vg =vg_read_internal (cmd, vgname,NULL /*vgid*/ , &consistent);if (vg) {if (consistent)check_current_backup (vg);
ok.
Quoted 82 lines
diff -rN -u -p
old-lvmlib_apply/lib/format1/format1.cnew-lvmlib_apply/lib/format1/format1.clib/format1/format1.c +2
-2@@ -163,7 +163,7 @@ static struct volume_group *_format1_vg_const char *vg_name, struct metadata_area *mda __attribute((unused))) { -struct dm_pool *mem =dm_pool_create ("lvm1 vg_read" ,1024 *10 ); +struct dm_pool *mem =dm_pool_create ("lvm1 vg_read_internal" ,1024 *10 );struct dm_list pvs;struct volume_group *vg =NULL ;dm_list_init (&pvs);@@ -441,7 +441,7 @@ static int _format1_segtype_supported(st }static struct metadata_area_ops _metadata_format1_ops = { - .vg_read = _format1_vg_read, + .vg_read_internal = _format1_vg_read, .vg_write = _format1_vg_write, };diff -rN -u -p
old-lvmlib_apply/lib/format_pool/format_pool.cnew-lvmlib_apply/lib/format_pool/format_pool.clib/format_pool/format_pool.c +3
-3@@ -160,7 +160,7 @@ static struct volume_group *_pool_vg_reaconst char *vg_name, struct metadata_area *mda __attribute((unused))) { -struct dm_pool *mem =dm_pool_create ("pool vg_read" ,1024 ); +struct dm_pool *mem =dm_pool_create ("pool vg_read_internal" ,1024 );struct dm_list pds;struct volume_group *vg =NULL ;@@ -220,7 +220,7 @@ static int _pool_pv_read(const struct fo/* * I need to read the disk and populate a pv structure here * I'll probably need to abstract some of this later for the -* vg_read code +* vg_read_internal code */ if (!(pl =read_pool_disk (fmt, dev, mem,NULL ))) goto_out;@@ -239,7 +239,7 @@ static int _pool_pv_read(const struct fo/* *INDENT-OFF* */ static struct metadata_area_ops _metadata_format_pool_ops = { - .vg_read = _pool_vg_read, + .vg_read_internal = _pool_vg_read, };/* *INDENT-ON* */ diff -rN -u -p
old-lvmlib_apply/lib/format_text/archiver.cnew-lvmlib_apply/lib/format_text/archiver.clib/format_text/archiver.c +1
-1@@ -265,7 +265,7 @@ struct volume_group *backup_read_vg(stru } dm_list_iterate_items(mda, &tf->metadata_areas) { -if (!(vg = mda->ops->vg_read (tf, vg_name, mda))) +if (!(vg = mda->ops->vg_read_internal (tf, vg_name, mda))) stack;break ; }diff -rN -u -p
old-lvmlib_apply/lib/format_text/format-text.cnew-lvmlib_apply/lib/format_text/format-text.clib/format_text/format-text.c +2
-2@@ -1543,7 +1543,7 @@ static void _text_destroy(const struct f }static struct metadata_area_ops _metadata_text_file_ops = { - .vg_read = _vg_read_file, + .vg_read_internal = _vg_read_file, .vg_read_precommit = _vg_read_precommit_file, .vg_write = _vg_write_file, .vg_remove = _vg_remove_file,@@ -1551,14 +1551,14 @@ static struct metadata_area_ops _metadat };static struct metadata_area_ops _metadata_text_file_backup_ops = { - .vg_read = _vg_read_file, + .vg_read_internal = _vg_read_file, .vg_write = _vg_write_file,
lib/format_text/format-text.c static struct metadata_area_ops _metadat · line 1564
Quoted 10 lines
lib/format_text/format-text.c +1
-1.vg_remove = _vg_remove_file, .vg_commit = _vg_commit_file_backup };static struct metadata_area_ops _metadata_text_raw_ops = { - .vg_read = _vg_read_raw, + .vg_read_internal = _vg_read_raw, .vg_read_precommit = _vg_read_precommit_raw, .vg_write = _vg_write_raw, .vg_remove = _vg_remove_raw,
Did you intend to change these format-level vg_read() function names or was this a search/replace error?
Quoted 39 lines
diff -rN -u -p
old-lvmlib_apply/lib/metadata/metadata.cnew-lvmlib_apply/lib/metadata/metadata.clib/metadata/metadata.c +5
-5@@ -224,8 +224,8 @@ int get_pv_from_vg_by_id(const struct fostruct pv_list *pvl;int consistent =0 ; -if (!(vg =vg_read (fmt->cmd, vg_name, vgid, &consistent))) { -log_error ("get_pv_from_vg_by_id: vg_read failed to read VG %s" , +if (!(vg =vg_read_internal (fmt->cmd, vg_name, vgid, &consistent))) { +log_error ("get_pv_from_vg_by_id: vg_read_internal failed to read VG %s" , vg_name);return 0 ; }@@ -503,7 +503,7 @@ struct volume_group *vg_create(struct cm return_NULL;/* is this vg name already in use ? */ -if (vg_read (cmd, vg_name,NULL , &consistent)) { +if (vg_read_internal (cmd, vg_name,NULL , &consistent)) {log_err ("A volume group called '%s' already exists." , vg_name); goto bad; }@@ -1684,12 +1684,12 @@ int vg_missing_pv_count(const vg_t *vg)return ret; } -/* Caller sets consistent to 1 if it's safe for vg_read to correct +/* Caller sets consistent to 1 if it's safe for vg_read_internal to correct * inconsistent metadata on disk (i.e. the VG write lock is held). * This guarantees only consistent metadata is returned. * If consistent is 0, caller must check whether consistent == 1 on return * and take appropriate action if it isn't (e.g. abort; get write lock -* and call vg_read again). +* and call vg_read_internal again). * * If precommitted is set, use precommitted metadata if present. *
lib/metadata/metadata.c static struct volume_group *_vg_read(str · line 1720
Quoted 6 lines
lib/metadata/metadata.c +1
-1@@ -1716,7 +1716,7 @@ static struct volume_group *_vg_read(strif (is_orphan_vg (vgname)) {if (use_precommitted) { -log_error ("Internal error: vg_read requires vgname " +log_error ("Internal error: vg_read_internal requires vgname " "with pre-commit." );
ok
lib/metadata/metadata.c static struct volume_group *_vg_read(str · line 1773
Quoted 9 lines
lib/metadata/metadata.c +1
-1return NULL ; }@@ -1769,7 +1769,7 @@ static struct volume_group *_vg_read(strif ((use_precommitted && !(vg = mda->ops->vg_read_precommit (fid, vgname, mda))) || (!use_precommitted && - !(vg = mda->ops->vg_read (fid, vgname, mda)))) { + !(vg = mda->ops->vg_read_internal (fid, vgname, mda)))) { inconsistent =1 ;
More possible inadvertent renaming.
lib/metadata/metadata.c static struct volume_group *_vg_read(str · line 1877
Quoted 9 lines
lib/metadata/metadata.c +1
-1continue ; }@@ -1873,7 +1873,7 @@ static struct volume_group *_vg_read(str !(vg = mda->ops->vg_read_precommit(fid, vgname, mda))) || (!use_precommitted && - !(vg = mda->ops->vg_read(fid, vgname, mda)))) { + !(vg = mda->ops->vg_read_internal(fid, vgname, mda)))) { inconsistent =1 ;
More possible inadvertent renaming.
Quoted 72 lines
lib/metadata/metadata.c +5
-5continue ; }@@ -1974,7 +1974,7 @@ static struct volume_group *_vg_read(strreturn correct_vg; } -struct volume_group *vg_read (struct cmd_context *cmd,const char *vgname, +struct volume_group *vg_read_internal (struct cmd_context *cmd,const char *vgname,const char *vgid,int *consistent) {struct volume_group *vg;@@ -2002,7 +2002,7 @@ struct volume_group *vg_read(struct cmd_/* This is only called by lv_from_lvid, which is only called from * activate.c so we know the appropriate VG lock is already held and -* the vg_read is therefore safe. +* the vg_read_internal is therefore safe. */ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd, const char *vgid,@@ -2034,7 +2034,7 @@ static struct volume_group *_vg_read_by_if (memlock ())return NULL ; -/* FIXME Need a genuine read by ID here - don't vg_read by name! */ +/* FIXME Need a genuine read by ID here - don't vg_read_internal by name! */ /* FIXME Disabled vgrenames while active for now because we aren't * allowed to do a full scan here any more. */ @@ -2218,7 +2218,7 @@ static int _get_pvs(struct cmd_context * stack;continue ; } -if (!(vg =vg_read (cmd, vgname, vgid, &consistent))) { +if (!(vg =vg_read_internal (cmd, vgname, vgid, &consistent))) { stack;continue ; }@@ -2446,7 +2446,7 @@ vg_t *vg_lock_and_read(struct cmd_contexreturn NULL ; } -if (!(vg =vg_read (cmd, vg_name, vgid, &consistent)) || +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent)) || ((misc_flags &FAIL_INCONSISTENT ) && !consistent)) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);diff -rN -u -p
old-lvmlib_apply/lib/metadata/metadata-exported.hnew-lvmlib_apply/lib/metadata/metadata-exported.hlib/metadata/metadata-exported.h +2
-2@@ -76,7 +76,7 @@ struct pv_segment;written out in metadata*/ //#define POSTORDER_FLAG 0x02000000U /* Not real flags, reserved for -//#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read. */ +//#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read_internal. */ #define LVM_READ 0x00000100U/* LV VG */ #define LVM_WRITE 0x00000200U/* LV VG */ @@ -328,7 +328,7 @@ struct lv_list {int vg_write (struct volume_group *vg);int vg_commit (struct volume_group *vg);int vg_revert (struct volume_group *vg); -struct volume_group *vg_read (struct cmd_context *cmd,const char *vg_name, +struct volume_group *vg_read_internal (struct cmd_context *cmd,const char *vg_name,const char *vgid,int *consistent); struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, struct dm_list *mdas, uint64_t *label_sector,diff -rN -u -p
old-lvmlib_apply/lib/metadata/metadata.hnew-lvmlib_apply/lib/metadata/metadata.h
lib/metadata/metadata.h line 82
Quoted 5 lines
lib/metadata/metadata.h +1
-1@@ -79,7 +79,7 @@// written out in metadata*/ #define POSTORDER_FLAG 0x02000000U/* Not real flags, reserved for */ -#define POSTORDER_OPEN_FLAG 0x04000000U/* temporary use inside vg_read. */ +#define POSTORDER_OPEN_FLAG 0x04000000U/* temporary use inside vg_read_internal. */
ok
lib/metadata/metadata.h struct metadata_area; · line 106
Quoted 11 lines
lib/metadata/metadata.h +1
-1//#define LVM_READ 0x00000100U /* LV VG */ //#define LVM_WRITE 0x00000200U /* LV VG */ @@ -101,7 +101,7 @@ struct metadata_area;/* Per-format per-metadata area operations */ struct metadata_area_ops { -struct volume_group *(*vg_read) (struct format_instance * fi, +struct volume_group *(*vg_read_internal) (struct format_instance * fi,const char *vg_name,struct metadata_area * mda);
More possible inadvertent renaming.
old-tests/format1/read_vg_t.c int main(int argc, char **argv) · line 59
Quoted 11 lines
lib/metadata/metadata.h +0
-0struct volume_group *(*vg_read_precommit) (struct format_instance * fi,diff -rN -u -p
old-lvmlib_apply/old-tests/format1/read_vg_t.cnew-lvmlib_apply/old-tests/format1/read_vg_t.cold-tests/format1/read_vg_t.c +1
-1@@ -55,7 +55,7 @@ int main(int argc, char **argv)exit (1 ); } - vg = ios->vg_read (ios, argv[1 ]); + vg = ios->vg_read_internal (ios, argv[1 ]);
More possible inadvertent renaming.
test/format1/read_vg_t.c
Quoted 17 lines
old-tests/format1/read_vg_t.c +0
-0if (!vg) {fprintf (stderr,"couldn't read vg %s\n" , argv[1 ]);diff -rN -u -p
old-lvmlib_apply/old-tests/format1/write_vg_t.cnew-lvmlib_apply/old-tests/format1/write_vg_t.cold-tests/format1/write_vg_t.c +1
-1@@ -55,7 +55,7 @@ int main(int argc, char **argv)exit (1 ); } - vg = ios->vg_read (ios, argv[1 ]); + vg = ios->vg_read_internal (ios, argv[1 ]);if (!vg) {fprintf (stderr,"couldn't read vg %s\n" , argv[1 ]);diff -rN -u -p
old-lvmlib_apply/test/format1/read_vg_t.cnew-lvmlib_apply/test/format1/read_vg_t.ctest/format1/read_vg_t.c +0
-0
File no longer at this path in CVS - remove this hunk.
test/format1/write_vg_t.c
Quoted 12 lines
test/format1/read_vg_t.c +1
-1@@ -55,7 +55,7 @@ int main(int argc, char **argv)exit (1 ); } - vg = ios->vg_read (ios, argv[1 ]); + vg = ios->vg_read_internal (ios, argv[1 ]);if (!vg) {fprintf (stderr,"couldn't read vg %s\n" , argv[1 ]);diff -rN -u -p
old-lvmlib_apply/test/format1/write_vg_t.cnew-lvmlib_apply/test/format1/write_vg_t.ctest/format1/write_vg_t.c +0
-0
File no longer at this path in CVS - remove this hunk.
Quoted 149 lines
test/format1/write_vg_t.c +1
-1@@ -55,7 +55,7 @@ int main(int argc, char **argv)exit (1 ); } - vg = ios->vg_read (ios, argv[1 ]); + vg = ios->vg_read_internal (ios, argv[1 ]);if (!vg) {fprintf (stderr,"couldn't read vg %s\n" , argv[1 ]);diff -rN -u -p
old-lvmlib_apply/tools/pvdisplay.cnew-lvmlib_apply/tools/pvdisplay.ctools/pvdisplay.c +1
-1@@ -37,7 +37,7 @@ static int _pvdisplay_single(struct cmd_/* * Replace possibly incomplete PV structure with new one -* allocated in vg_read() path. +* allocated in vg_read_internal() path. */ if (!(pvl =find_pv_in_vg (vg, pv_name))) { log_error("Unable to find \"%s\" in volume group \"%s\"",diff -rN -u -p
old-lvmlib_apply/tools/pvresize.cnew-lvmlib_apply/tools/pvresize.ctools/pvresize.c +1
-1@@ -62,7 +62,7 @@ static int _pv_resize_single(struct cmd_return 0 ; } -if (!(vg =vg_read (cmd, vg_name,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent))) {unlock_vg (cmd, vg_name);log_error ("Unable to find volume group of \"%s\"" , pv_name);diff -rN -u -p
old-lvmlib_apply/tools/reporter.cnew-lvmlib_apply/tools/reporter.ctools/reporter.c +1
-1@@ -136,7 +136,7 @@ static int _pvs_single(struct cmd_contex/* * Replace possibly incomplete PV structure with new one -* allocated in vg_read() path. +* allocated in vg_read_internal() path. */ if (!(pvl =find_pv_in_vg (vg,pv_dev_name (pv)))) { log_error("Unable to find \"%s\" in volume group \"%s\"",diff -rN -u -p
old-lvmlib_apply/tools/toollib.cnew-lvmlib_apply/tools/toollib.ctools/toollib.c +4
-4@@ -291,7 +291,7 @@ int process_each_lv(struct cmd_context * consistent =1 ; else consistent =0 ; -if (!(vg =vg_read (cmd, vgname,NULL , &consistent)) || !consistent) { +if (!(vg =vg_read_internal (cmd, vgname,NULL , &consistent)) || !consistent) {unlock_vg (cmd, vgname);if (!vg) log_error("Volume group \"%s\" "@@ -433,7 +433,7 @@ static int _process_one_vg(struct cmd_co }log_verbose ("Finding volume group \"%s\"" , vg_name); -if (!(vg =vg_read (cmd, vg_name, vgid, &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);return ECMD_FAILED ;@@ -720,7 +720,7 @@ int process_each_pv(struct cmd_context *log_error ("Can't lock %s: skipping" , sll->str);continue ; } -if (!(vg =vg_read (cmd, sll->str,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, sll->str,NULL , &consistent))) {log_error ("Volume group \"%s\" not found" , sll->str);unlock_vg (cmd, sll->str); ret_max =ECMD_FAILED ;@@ -1143,7 +1143,7 @@ struct volume_group *recover_vg(struct creturn NULL ; } -return vg_read (cmd, vgname,NULL , &consistent); +return vg_read_internal (cmd, vgname,NULL , &consistent); }int apply_lvname_restrictions (const char *name)diff -rN -u -p
old-lvmlib_apply/tools/vgreduce.cnew-lvmlib_apply/tools/vgreduce.ctools/vgreduce.c +3
-3@@ -426,7 +426,7 @@ static int _vgreduce_single(struct cmd_c vg->free_count -=pv_pe_count (pv) -pv_pe_alloc_count (pv); vg->extent_count -=pv_pe_count (pv); -if (!(orphan_vg =vg_read (cmd, vg->fid->fmt->orphan_vg_name,NULL , &consistent)) || +if (!(orphan_vg =vg_read_internal (cmd, vg->fid->fmt->orphan_vg_name,NULL , &consistent)) || !consistent) {log_error ("Unable to read existing orphan PVs" );unlock_vg (cmd,VG_ORPHANS );@@ -520,7 +520,7 @@ int vgreduce(struct cmd_context *cmd, inreturn ECMD_FAILED ; } -if ((!(vg =vg_read (cmd, vg_name,NULL , &consistent)) || !consistent) +if ((!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent)) || !consistent) && !repairing) {log_error ("Volume group \"%s\" doesn't exist" , vg_name);unlock_vg (cmd, vg_name);@@ -541,7 +541,7 @@ int vgreduce(struct cmd_context *cmd, in } consistent = !arg_count (cmd, force_ARG); -if (!(vg =vg_read (cmd, vg_name,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent))) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);return ECMD_FAILED ;diff -rN -u -p
old-lvmlib_apply/tools/vgrename.cnew-lvmlib_apply/tools/vgrename.ctools/vgrename.c +2
-2@@ -75,7 +75,7 @@ static int vg_rename_path(struct cmd_conreturn 0 ; } -if (!(vg =vg_read (cmd, vg_name_old, vgid, &consistent)) || !consistent) { +if (!(vg =vg_read_internal (cmd, vg_name_old, vgid, &consistent)) || !consistent) {log_error ("Volume group %s %s%s%snot found." , vg_name_old, vgid ?"(" :"" , vgid ? vgid :"" , vgid ?") " :"" );unlock_vg (cmd, vg_name_old);@@ -107,7 +107,7 @@ static int vg_rename_path(struct cmd_con } consistent =0 ; -if ((vg_new =vg_read (cmd, vg_name_new,NULL , &consistent))) { +if ((vg_new =vg_read_internal (cmd, vg_name_new,NULL , &consistent))) {log_error ("New volume group \"%s\" already exists" , vg_name_new); goto error;diff -rN -u -p
old-lvmlib_apply/tools/vgsplit.cnew-lvmlib_apply/tools/vgsplit.ctools/vgsplit.c +1
-1@@ -334,7 +334,7 @@ int vgsplit(struct cmd_context *cmd, int } consistent =0 ; -if ((vg_to =vg_read (cmd, vg_name_to,NULL , &consistent))) { +if ((vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent))) { existing_vg =1 ;if (new_vg_option_specified (cmd)) { log_error("Volume group \"%s\" exists, but new VG "
tools/vgsplit.c int vgsplit(struct cmd_context *cmd, int · line 457
Quoted 8 lines
tools/vgsplit.c +1
-1@@ -451,7 +451,7 @@ int vgsplit(struct cmd_context *cmd, int*/ consistent =1 ;if (!test_mode () && - (!(vg_to =vg_read (cmd, vg_name_to,NULL , &consistent)) || + (!(vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent)) || !consistent)) {log_error ("Volume group \"%s\" became inconsistent: please " "fix manually" , vg_name_to);
ok
Quoted 4 lines
--
lvm-devel mailing list
lvm-devel at redhat.com
https://www.redhat.com/mailman/listinfo/lvm-devel
Re: [PATCH 1/11] Move vg_read out of the way, renaming it to vg_read_internal.
In reply to Petr RockaiSorry for the mismatched patch that renames more than needed (and also in files that are apparently no longer in repo. Gotta fix that...).
Anyhow, amended patch follows (hopefully better this time):
Mon Jan 12 17:38:59 CET 2009 Petr Rockai <[email protected]>
* Move vg_read out of the way, renaming it to vg_read_internal.
daemons/clvmd/lvm-functions.c +1 -1
@@ -711,7 +711,7 @@ void lvm_do_backup(const char *vgname)DEBUGLOG ("Triggering backup of VG metadata for %s. suspended=%d\n" , vgname, suspended); - vg =vg_read (cmd, vgname,NULL /*vgid*/ , &consistent); + vg =vg_read_internal (cmd, vgname,NULL /*vgid*/ , &consistent);if (vg) {if (consistent)check_current_backup (vg);
lib/metadata/metadata.c +11 -11
@@ -224,8 +224,8 @@ int get_pv_from_vg_by_id(const struct fostruct pv_list *pvl;int consistent =0 ; -if (!(vg =vg_read (fmt->cmd, vg_name, vgid, &consistent))) { -log_error ("get_pv_from_vg_by_id: vg_read failed to read VG %s" , +if (!(vg =vg_read_internal (fmt->cmd, vg_name, vgid, &consistent))) { +log_error ("get_pv_from_vg_by_id: vg_read_internal failed to read VG %s" , vg_name);return 0 ; }
@@ -503,7 +503,7 @@ struct volume_group *vg_create(struct cm return_NULL;/* is this vg name already in use ? */ -if (vg_read (cmd, vg_name,NULL , &consistent)) { +if (vg_read_internal (cmd, vg_name,NULL , &consistent)) {log_err ("A volume group called '%s' already exists." , vg_name); goto bad; }
@@ -1684,12 +1684,12 @@ int vg_missing_pv_count(const vg_t *vg)return ret; } -/* Caller sets consistent to 1 if it's safe for vg_read to correct +/* Caller sets consistent to 1 if it's safe for vg_read_internal to correct * inconsistent metadata on disk (i.e. the VG write lock is held). * This guarantees only consistent metadata is returned. * If consistent is 0, caller must check whether consistent == 1 on return * and take appropriate action if it isn't (e.g. abort; get write lock -* and call vg_read again). +* and call vg_read_internal again). * * If precommitted is set, use precommitted metadata if present. *
@@ -1716,7 +1716,7 @@ static struct volume_group *_vg_read(strif (is_orphan_vg (vgname)) {if (use_precommitted) { -log_error ("Internal error: vg_read requires vgname " +log_error ("Internal error: vg_read_internal requires vgname " "with pre-commit." );return NULL ; }
@@ -1974,7 +1974,7 @@ static struct volume_group *_vg_read(strreturn correct_vg; } -struct volume_group *vg_read (struct cmd_context *cmd,const char *vgname, +struct volume_group *vg_read_internal (struct cmd_context *cmd,const char *vgname,const char *vgid,int *consistent) {struct volume_group *vg;
@@ -2002,7 +2002,7 @@ struct volume_group *vg_read(struct cmd_/* This is only called by lv_from_lvid, which is only called from * activate.c so we know the appropriate VG lock is already held and -* the vg_read is therefore safe. +* the vg_read_internal is therefore safe. */ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd, const char *vgid,
@@ -2034,7 +2034,7 @@ static struct volume_group *_vg_read_by_if (memlock ())return NULL ; -/* FIXME Need a genuine read by ID here - don't vg_read by name! */ +/* FIXME Need a genuine read by ID here - don't vg_read_internal by name! */ /* FIXME Disabled vgrenames while active for now because we aren't * allowed to do a full scan here any more. */
@@ -2218,7 +2218,7 @@ static int _get_pvs(struct cmd_context * stack;continue ; } -if (!(vg =vg_read (cmd, vgname, vgid, &consistent))) { +if (!(vg =vg_read_internal (cmd, vgname, vgid, &consistent))) { stack;continue ; }
@@ -2446,7 +2446,7 @@ vg_t *vg_lock_and_read(struct cmd_contexreturn NULL ; } -if (!(vg =vg_read (cmd, vg_name, vgid, &consistent)) || +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent)) || ((misc_flags &FAIL_INCONSISTENT ) && !consistent)) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);
lib/metadata/metadata-exported.h +2 -2
@@ -76,7 +76,7 @@ struct pv_segment;written out in metadata*/ //#define POSTORDER_FLAG 0x02000000U /* Not real flags, reserved for -//#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read. */ +//#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read_internal. */ #define LVM_READ 0x00000100U/* LV VG */ #define LVM_WRITE 0x00000200U/* LV VG */
@@ -328,7 +328,7 @@ struct lv_list {int vg_write (struct volume_group *vg);int vg_commit (struct volume_group *vg);int vg_revert (struct volume_group *vg); -struct volume_group *vg_read (struct cmd_context *cmd,const char *vg_name, +struct volume_group *vg_read_internal (struct cmd_context *cmd,const char *vg_name,const char *vgid,int *consistent); struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, struct dm_list *mdas, uint64_t *label_sector,
lib/metadata/metadata.h +1 -1
@@ -79,7 +79,7 @@// written out in metadata*/ #define POSTORDER_FLAG 0x02000000U/* Not real flags, reserved for */ -#define POSTORDER_OPEN_FLAG 0x04000000U/* temporary use inside vg_read. */ +#define POSTORDER_OPEN_FLAG 0x04000000U/* temporary use inside vg_read_internal. */ //#define LVM_READ 0x00000100U /* LV VG */ //#define LVM_WRITE 0x00000200U /* LV VG */
tools/pvdisplay.c +1 -1
@@ -37,7 +37,7 @@ static int _pvdisplay_single(struct cmd_/* * Replace possibly incomplete PV structure with new one -* allocated in vg_read() path. +* allocated in vg_read_internal() path. */ if (!(pvl =find_pv_in_vg (vg, pv_name))) { log_error("Unable to find \"%s\" in volume group \"%s\"",
tools/pvresize.c +1 -1
@@ -62,7 +62,7 @@ static int _pv_resize_single(struct cmd_return 0 ; } -if (!(vg =vg_read (cmd, vg_name,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent))) {unlock_vg (cmd, vg_name);log_error ("Unable to find volume group of \"%s\"" , pv_name);
tools/reporter.c +1 -1
@@ -136,7 +136,7 @@ static int _pvs_single(struct cmd_contex/* * Replace possibly incomplete PV structure with new one -* allocated in vg_read() path. +* allocated in vg_read_internal() path. */ if (!(pvl =find_pv_in_vg (vg,pv_dev_name (pv)))) { log_error("Unable to find \"%s\" in volume group \"%s\"",
tools/toollib.c +4 -4
@@ -291,7 +291,7 @@ int process_each_lv(struct cmd_context * consistent =1 ; else consistent =0 ; -if (!(vg =vg_read (cmd, vgname,NULL , &consistent)) || !consistent) { +if (!(vg =vg_read_internal (cmd, vgname,NULL , &consistent)) || !consistent) {unlock_vg (cmd, vgname);if (!vg) log_error("Volume group \"%s\" "
@@ -433,7 +433,7 @@ static int _process_one_vg(struct cmd_co }log_verbose ("Finding volume group \"%s\"" , vg_name); -if (!(vg =vg_read (cmd, vg_name, vgid, &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);return ECMD_FAILED ;
@@ -720,7 +720,7 @@ int process_each_pv(struct cmd_context *log_error ("Can't lock %s: skipping" , sll->str);continue ; } -if (!(vg =vg_read (cmd, sll->str,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, sll->str,NULL , &consistent))) {log_error ("Volume group \"%s\" not found" , sll->str);unlock_vg (cmd, sll->str); ret_max =ECMD_FAILED ;
@@ -1143,7 +1143,7 @@ struct volume_group *recover_vg(struct creturn NULL ; } -return vg_read (cmd, vgname,NULL , &consistent); +return vg_read_internal (cmd, vgname,NULL , &consistent); }int apply_lvname_restrictions (const char *name)
tools/vgreduce.c +3 -3
@@ -426,7 +426,7 @@ static int _vgreduce_single(struct cmd_c vg->free_count -=pv_pe_count (pv) -pv_pe_alloc_count (pv); vg->extent_count -=pv_pe_count (pv); -if (!(orphan_vg =vg_read (cmd, vg->fid->fmt->orphan_vg_name,NULL , &consistent)) || +if (!(orphan_vg =vg_read_internal (cmd, vg->fid->fmt->orphan_vg_name,NULL , &consistent)) || !consistent) {log_error ("Unable to read existing orphan PVs" );unlock_vg (cmd,VG_ORPHANS );
@@ -520,7 +520,7 @@ int vgreduce(struct cmd_context *cmd, inreturn ECMD_FAILED ; } -if ((!(vg =vg_read (cmd, vg_name,NULL , &consistent)) || !consistent) +if ((!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent)) || !consistent) && !repairing) {log_error ("Volume group \"%s\" doesn't exist" , vg_name);unlock_vg (cmd, vg_name);
@@ -541,7 +541,7 @@ int vgreduce(struct cmd_context *cmd, in } consistent = !arg_count (cmd, force_ARG); -if (!(vg =vg_read (cmd, vg_name,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent))) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);return ECMD_FAILED ;
tools/vgrename.c +2 -2
@@ -75,7 +75,7 @@ static int vg_rename_path(struct cmd_conreturn 0 ; } -if (!(vg =vg_read (cmd, vg_name_old, vgid, &consistent)) || !consistent) { +if (!(vg =vg_read_internal (cmd, vg_name_old, vgid, &consistent)) || !consistent) {log_error ("Volume group %s %s%s%snot found." , vg_name_old, vgid ?"(" :"" , vgid ? vgid :"" , vgid ?") " :"" );unlock_vg (cmd, vg_name_old);
@@ -107,7 +107,7 @@ static int vg_rename_path(struct cmd_con } consistent =0 ; -if ((vg_new =vg_read (cmd, vg_name_new,NULL , &consistent))) { +if ((vg_new =vg_read_internal (cmd, vg_name_new,NULL , &consistent))) {log_error ("New volume group \"%s\" already exists" , vg_name_new); goto error;
tools/vgsplit.c +2 -2
@@ -334,7 +334,7 @@ int vgsplit(struct cmd_context *cmd, int } consistent =0 ; -if ((vg_to =vg_read (cmd, vg_name_to,NULL , &consistent))) { +if ((vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent))) { existing_vg =1 ;if (new_vg_option_specified (cmd)) { log_error("Volume group \"%s\" exists, but new VG "
@@ -451,7 +451,7 @@ int vgsplit(struct cmd_context *cmd, int*/ consistent =1 ;if (!test_mode () && - (!(vg_to =vg_read (cmd, vg_name_to,NULL , &consistent)) || + (!(vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent)) || !consistent)) {log_error ("Volume group \"%s\" became inconsistent: please " "fix manually" , vg_name_to);
Signature · 6 lines
Peter Rockai | me()mornfall!net | prockai()redhat!com
http://blog.mornfall.net | http://web.mornfall.net
"In My Egotistical Opinion, most people's C programs should be
indented six feet downward and covered with dirt."
-- Blair P. Houghton on the subject of C program indentationDave Wysochanski
Reviewed-byRe: [PATCH 1/11] Move vg_read out of the way, renaming it to vg_read_internal.
Quoted 58 lines · Petr Rockai
Sorry for the mismatched patch that renames more than needed (and also in files that are apparently no longer in repo. Gotta fix that...).
Anyhow, amended patch follows (hopefully better this time):
Mon Jan 12 17:38:59 CET 2009 Petr Rockai <[email protected]>
* Movevg_readout of the way, renaming it tovg_read_internal.
diff -rN -u -pold-lvmlib_apply/daemons/clvmd/lvm-functions.cnew-lvmlib_apply/daemons/clvmd/lvm-functions.cdaemons/clvmd/lvm-functions.c +1
-1@@ -711,7 +711,7 @@ void lvm_do_backup(const char *vgname)DEBUGLOG ("Triggering backup of VG metadata for %s. suspended=%d\n" , vgname, suspended); - vg =vg_read (cmd, vgname,NULL /*vgid*/ , &consistent); + vg =vg_read_internal (cmd, vgname,NULL /*vgid*/ , &consistent);if (vg) {if (consistent)check_current_backup (vg);diff -rN -u -p
old-lvmlib_apply/lib/metadata/metadata.cnew-lvmlib_apply/lib/metadata/metadata.clib/metadata/metadata.c +5
-5@@ -224,8 +224,8 @@ int get_pv_from_vg_by_id(const struct fostruct pv_list *pvl;int consistent =0 ; -if (!(vg =vg_read (fmt->cmd, vg_name, vgid, &consistent))) { -log_error ("get_pv_from_vg_by_id: vg_read failed to read VG %s" , +if (!(vg =vg_read_internal (fmt->cmd, vg_name, vgid, &consistent))) { +log_error ("get_pv_from_vg_by_id: vg_read_internal failed to read VG %s" , vg_name);return 0 ; }@@ -503,7 +503,7 @@ struct volume_group *vg_create(struct cm return_NULL;/* is this vg name already in use ? */ -if (vg_read (cmd, vg_name,NULL , &consistent)) { +if (vg_read_internal (cmd, vg_name,NULL , &consistent)) {log_err ("A volume group called '%s' already exists." , vg_name); goto bad; }@@ -1684,12 +1684,12 @@ int vg_missing_pv_count(const vg_t *vg)return ret; } -/* Caller sets consistent to 1 if it's safe for vg_read to correct +/* Caller sets consistent to 1 if it's safe for vg_read_internal to correct * inconsistent metadata on disk (i.e. the VG write lock is held). * This guarantees only consistent metadata is returned. * If consistent is 0, caller must check whether consistent == 1 on return * and take appropriate action if it isn't (e.g. abort; get write lock -* and call vg_read again). +* and call vg_read_internal again). * * If precommitted is set, use precommitted metadata if present. *
lib/metadata/metadata.c static struct volume_group *_vg_read(str · line 1719
Quoted 5 lines
lib/metadata/metadata.c +1
-1@@ -1716,7 +1716,7 @@ static struct volume_group *_vg_read(strif (is_orphan_vg (vgname)) {if (use_precommitted) { - log_error("Internal error: vg_read requires vgname " + log_error("Internal error: vg_read_internal requires vgname "
Should be "_vg_read" here.
Quoted 224 lines
lib/metadata/metadata.c +5
-5"with pre-commit.");return NULL ; }@@ -1974,7 +1974,7 @@ static struct volume_group *_vg_read(strreturn correct_vg; } -struct volume_group *vg_read (struct cmd_context *cmd,const char *vgname, +struct volume_group *vg_read_internal (struct cmd_context *cmd,const char *vgname,const char *vgid,int *consistent) {struct volume_group *vg;@@ -2002,7 +2002,7 @@ struct volume_group *vg_read(struct cmd_/* This is only called by lv_from_lvid, which is only called from * activate.c so we know the appropriate VG lock is already held and -* the vg_read is therefore safe. +* the vg_read_internal is therefore safe. */ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd, const char *vgid,@@ -2034,7 +2034,7 @@ static struct volume_group *_vg_read_by_if (memlock ())return NULL ; -/* FIXME Need a genuine read by ID here - don't vg_read by name! */ +/* FIXME Need a genuine read by ID here - don't vg_read_internal by name! */ /* FIXME Disabled vgrenames while active for now because we aren't * allowed to do a full scan here any more. */ @@ -2218,7 +2218,7 @@ static int _get_pvs(struct cmd_context * stack;continue ; } -if (!(vg =vg_read (cmd, vgname, vgid, &consistent))) { +if (!(vg =vg_read_internal (cmd, vgname, vgid, &consistent))) { stack;continue ; }@@ -2446,7 +2446,7 @@ vg_t *vg_lock_and_read(struct cmd_contexreturn NULL ; } -if (!(vg =vg_read (cmd, vg_name, vgid, &consistent)) || +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent)) || ((misc_flags &FAIL_INCONSISTENT ) && !consistent)) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);diff -rN -u -p
old-lvmlib_apply/lib/metadata/metadata-exported.hnew-lvmlib_apply/lib/metadata/metadata-exported.hlib/metadata/metadata-exported.h +2
-2@@ -76,7 +76,7 @@ struct pv_segment;written out in metadata*/ //#define POSTORDER_FLAG 0x02000000U /* Not real flags, reserved for -//#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read. */ +//#define POSTORDER_OPEN_FLAG 0x04000000U temporary use inside vg_read_internal. */ #define LVM_READ 0x00000100U/* LV VG */ #define LVM_WRITE 0x00000200U/* LV VG */ @@ -328,7 +328,7 @@ struct lv_list {int vg_write (struct volume_group *vg);int vg_commit (struct volume_group *vg);int vg_revert (struct volume_group *vg); -struct volume_group *vg_read (struct cmd_context *cmd,const char *vg_name, +struct volume_group *vg_read_internal (struct cmd_context *cmd,const char *vg_name,const char *vgid,int *consistent); struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name, struct dm_list *mdas, uint64_t *label_sector,diff -rN -u -p
old-lvmlib_apply/lib/metadata/metadata.hnew-lvmlib_apply/lib/metadata/metadata.hlib/metadata/metadata.h +1
-1@@ -79,7 +79,7 @@// written out in metadata*/ #define POSTORDER_FLAG 0x02000000U/* Not real flags, reserved for */ -#define POSTORDER_OPEN_FLAG 0x04000000U/* temporary use inside vg_read. */ +#define POSTORDER_OPEN_FLAG 0x04000000U/* temporary use inside vg_read_internal. */ //#define LVM_READ 0x00000100U /* LV VG */ //#define LVM_WRITE 0x00000200U /* LV VG */ diff -rN -u -p
old-lvmlib_apply/tools/pvdisplay.cnew-lvmlib_apply/tools/pvdisplay.ctools/pvdisplay.c +1
-1@@ -37,7 +37,7 @@ static int _pvdisplay_single(struct cmd_/* * Replace possibly incomplete PV structure with new one -* allocated in vg_read() path. +* allocated in vg_read_internal() path. */ if (!(pvl =find_pv_in_vg (vg, pv_name))) { log_error("Unable to find \"%s\" in volume group \"%s\"",diff -rN -u -p
old-lvmlib_apply/tools/pvresize.cnew-lvmlib_apply/tools/pvresize.ctools/pvresize.c +1
-1@@ -62,7 +62,7 @@ static int _pv_resize_single(struct cmd_return 0 ; } -if (!(vg =vg_read (cmd, vg_name,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent))) {unlock_vg (cmd, vg_name);log_error ("Unable to find volume group of \"%s\"" , pv_name);diff -rN -u -p
old-lvmlib_apply/tools/reporter.cnew-lvmlib_apply/tools/reporter.ctools/reporter.c +1
-1@@ -136,7 +136,7 @@ static int _pvs_single(struct cmd_contex/* * Replace possibly incomplete PV structure with new one -* allocated in vg_read() path. +* allocated in vg_read_internal() path. */ if (!(pvl =find_pv_in_vg (vg,pv_dev_name (pv)))) { log_error("Unable to find \"%s\" in volume group \"%s\"",diff -rN -u -p
old-lvmlib_apply/tools/toollib.cnew-lvmlib_apply/tools/toollib.ctools/toollib.c +4
-4@@ -291,7 +291,7 @@ int process_each_lv(struct cmd_context * consistent =1 ; else consistent =0 ; -if (!(vg =vg_read (cmd, vgname,NULL , &consistent)) || !consistent) { +if (!(vg =vg_read_internal (cmd, vgname,NULL , &consistent)) || !consistent) {unlock_vg (cmd, vgname);if (!vg) log_error("Volume group \"%s\" "@@ -433,7 +433,7 @@ static int _process_one_vg(struct cmd_co }log_verbose ("Finding volume group \"%s\"" , vg_name); -if (!(vg =vg_read (cmd, vg_name, vgid, &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name, vgid, &consistent))) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);return ECMD_FAILED ;@@ -720,7 +720,7 @@ int process_each_pv(struct cmd_context *log_error ("Can't lock %s: skipping" , sll->str);continue ; } -if (!(vg =vg_read (cmd, sll->str,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, sll->str,NULL , &consistent))) {log_error ("Volume group \"%s\" not found" , sll->str);unlock_vg (cmd, sll->str); ret_max =ECMD_FAILED ;@@ -1143,7 +1143,7 @@ struct volume_group *recover_vg(struct creturn NULL ; } -return vg_read (cmd, vgname,NULL , &consistent); +return vg_read_internal (cmd, vgname,NULL , &consistent); }int apply_lvname_restrictions (const char *name)diff -rN -u -p
old-lvmlib_apply/tools/vgreduce.cnew-lvmlib_apply/tools/vgreduce.ctools/vgreduce.c +3
-3@@ -426,7 +426,7 @@ static int _vgreduce_single(struct cmd_c vg->free_count -=pv_pe_count (pv) -pv_pe_alloc_count (pv); vg->extent_count -=pv_pe_count (pv); -if (!(orphan_vg =vg_read (cmd, vg->fid->fmt->orphan_vg_name,NULL , &consistent)) || +if (!(orphan_vg =vg_read_internal (cmd, vg->fid->fmt->orphan_vg_name,NULL , &consistent)) || !consistent) {log_error ("Unable to read existing orphan PVs" );unlock_vg (cmd,VG_ORPHANS );@@ -520,7 +520,7 @@ int vgreduce(struct cmd_context *cmd, inreturn ECMD_FAILED ; } -if ((!(vg =vg_read (cmd, vg_name,NULL , &consistent)) || !consistent) +if ((!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent)) || !consistent) && !repairing) {log_error ("Volume group \"%s\" doesn't exist" , vg_name);unlock_vg (cmd, vg_name);@@ -541,7 +541,7 @@ int vgreduce(struct cmd_context *cmd, in } consistent = !arg_count (cmd, force_ARG); -if (!(vg =vg_read (cmd, vg_name,NULL , &consistent))) { +if (!(vg =vg_read_internal (cmd, vg_name,NULL , &consistent))) {log_error ("Volume group \"%s\" not found" , vg_name);unlock_vg (cmd, vg_name);return ECMD_FAILED ;diff -rN -u -p
old-lvmlib_apply/tools/vgrename.cnew-lvmlib_apply/tools/vgrename.ctools/vgrename.c +2
-2@@ -75,7 +75,7 @@ static int vg_rename_path(struct cmd_conreturn 0 ; } -if (!(vg =vg_read (cmd, vg_name_old, vgid, &consistent)) || !consistent) { +if (!(vg =vg_read_internal (cmd, vg_name_old, vgid, &consistent)) || !consistent) {log_error ("Volume group %s %s%s%snot found." , vg_name_old, vgid ?"(" :"" , vgid ? vgid :"" , vgid ?") " :"" );unlock_vg (cmd, vg_name_old);@@ -107,7 +107,7 @@ static int vg_rename_path(struct cmd_con } consistent =0 ; -if ((vg_new =vg_read (cmd, vg_name_new,NULL , &consistent))) { +if ((vg_new =vg_read_internal (cmd, vg_name_new,NULL , &consistent))) {log_error ("New volume group \"%s\" already exists" , vg_name_new); goto error;diff -rN -u -p
old-lvmlib_apply/tools/vgsplit.cnew-lvmlib_apply/tools/vgsplit.ctools/vgsplit.c +1
-1@@ -334,7 +334,7 @@ int vgsplit(struct cmd_context *cmd, int } consistent =0 ; -if ((vg_to =vg_read (cmd, vg_name_to,NULL , &consistent))) { +if ((vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent))) { existing_vg =1 ;if (new_vg_option_specified (cmd)) { log_error("Volume group \"%s\" exists, but new VG "
tools/vgsplit.c int vgsplit(struct cmd_context *cmd, int · line 457
Quoted 8 lines
tools/vgsplit.c +1
-1@@ -451,7 +451,7 @@ int vgsplit(struct cmd_context *cmd, int*/ consistent =1 ;if (!test_mode () && - (!(vg_to =vg_read (cmd, vg_name_to,NULL , &consistent)) || + (!(vg_to =vg_read_internal (cmd, vg_name_to,NULL , &consistent)) || !consistent)) {log_error ("Volume group \"%s\" became inconsistent: please " "fix manually" , vg_name_to);
Ack. Reviewed & compiled.
Re: [PATCH 1/11] Move vg_read out of the way, renaming it to vg_read_internal.
In reply to Petr RockaiQuoted 1 line · Peter Rockai
Anyhow, amended patch follows (hopefully better this time):
Ack.
Alasdair
Signature · 1 line
agk at redhat.com