master - vgrename: use process_each_vg
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=796461a9125a8324a63be154fc998245617e5990 Commit: 796461a9125a8324a63be154fc998245617e5990 Parent: 37bd35bc3ddbd4b669c523e2f56aaa68682df2ad Author: David Teigland <[email protected]> AuthorDate: Tue Dec 1 14:09:01 2015 -0600 Committer: David Teigland <[email protected]> CommitterDate: Mon Dec 14 14:26:47 2015 -0600
vgrename: use process_each_vg
Use process_each_vg() to lock and read the old VG, and then call the main vgrename code.
When real VG names are used (not a UUID in place of the old name), the command still pre-locks the new name (when strcmp wants it locked first), before calling process_each_vg on the old name.
In the case where the old name is replaced with a UUID, process_each_vg now translates that UUID into the real VG name, which it locks and reads. In this case, we cannot do pre-locking to maintain lock ordering because the old name is unknown. So, in this case the strcmp based lock ordering is suppressed and the old name is always locked first. This opens a remote chance for lock ordering conflict between racing vgrenames between two names where one or both commands use the UUID.
--- daemons/clvmd/lvm-functions.c | 3 +- lib/cache/lvmcache.c | 51 ++++++-- lib/cache/lvmcache.h | 13 ++- lib/format_pool/disk_rep.c | 4 +- lib/format_text/format-text.c | 2 +- lib/metadata/metadata.c | 23 ++-- liblvm/lvm_vg.c | 3 +- tools/commands.h | 2 +- tools/reporter.c | 2 +- tools/toollib.c | 10 ++ tools/tools.h | 2 + tools/vgrename.c | 290 ++++++++++++++++++++++------------------- 12 files changed, 242 insertions(+), 163 deletions(-)
daemons/clvmd/lvm-functions.c +2 -1
@@ -663,7 +663,8 @@ int do_refresh_cache(void)init_full_scan_done (0 );init_ignore_suspended_devices (1 ); -lvmcache_label_scan (cmd,2 ); +lvmcache_force_next_label_scan (); +lvmcache_label_scan (cmd);dm_pool_empty (cmd->mem);pthread_mutex_unlock (&lvm_lock);
lib/cache/lvmcache.c +40 -11
135 lines not on this page · raw message
lib/cache/lvmcache.h +10 -3
@@ -66,9 +66,14 @@ void lvmcache_allow_reads_with_lvmetad(void);void lvmcache_destroy (struct cmd_context *cmd,int retain_orphans,int reset); -/* Set full_scan to 1 to reread every filtered device label or -* 2 to rescan /dev for new devices */ -int lvmcache_label_scan (struct cmd_context *cmd,int full_scan); +/* +* lvmcache_label_scan() will scan labels the first time it's +* called, but not on subsequent calls, unless +* lvmcache_force_next_label_scan() is called first +* to force the next lvmcache_label_scan() to scan again. +*/ +void lvmcache_force_next_label_scan (void ); +int lvmcache_label_scan (struct cmd_context *cmd);/* Add/delete a device */ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
@@ -197,4 +202,6 @@ void lvmcache_get_max_name_lengths(struct cmd_context *cmd,int lvmcache_vg_is_foreign (struct cmd_context *cmd,const char *vgname,const char *vgid); +void lvmcache_lock_ordering (int enable); +#endif
lib/format_pool/disk_rep.c +3 -1
@@ -373,7 +373,9 @@ int read_pool_pds(const struct format_type *fmt, const char *vg_name, vg_name);return 0 ; } -lvmcache_label_scan (fmt->cmd, full_scan); +if (full_scan >0 ) +lvmcache_force_next_label_scan (); +lvmcache_label_scan (fmt->cmd); }while (1 );
lib/format_text/format-text.c +1 -1
@@ -1963,7 +1963,7 @@ static int _create_vg_text_instance(struct format_instance *fid,*/ if (!critical_section ())/* Scan PVs in VG for any further MDAs */ -lvmcache_label_scan (fid->fmt->cmd,0 ); +lvmcache_label_scan (fid->fmt->cmd);if (!(vginfo =lvmcache_vginfo_from_vgname (vg_name, vg_id))) goto_out;
lib/metadata/metadata.c +14 -9
@@ -1539,7 +1539,8 @@ out: }if (scan_needed) { -if (!lvmcache_label_scan (cmd,2 )) { +lvmcache_force_next_label_scan (); +if (!lvmcache_label_scan (cmd)) { stack; r =0 ; }
@@ -3299,7 +3300,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd,struct pv_list head;dm_list_init (&head.list); -lvmcache_label_scan (cmd,0 ); +lvmcache_label_scan (cmd);lvmcache_seed_infos_from_lvmetad (cmd);if (!(vginfo =lvmcache_vginfo_from_vgname (orphan_vgname,NULL )))
@@ -3605,12 +3606,13 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,/* Find the vgname in the cache */ /* If it's not there we must do full scan to be completely sure */ if (!(fmt =lvmcache_fmt_from_vgname (cmd, vgname, vgid,1 ))) { -lvmcache_label_scan (cmd,0 ); +lvmcache_label_scan (cmd);if (!(fmt =lvmcache_fmt_from_vgname (cmd, vgname, vgid,1 ))) {/* Independent MDAs aren't supported under low memory */ if (!cmd->independent_metadata_areas &&critical_section ()) return_NULL; -lvmcache_label_scan (cmd,2 ); +lvmcache_force_next_label_scan (); +lvmcache_label_scan (cmd);if (!(fmt =lvmcache_fmt_from_vgname (cmd, vgname, vgid,0 ))) return_NULL; }
@@ -3820,7 +3822,8 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,/* Independent MDAs aren't supported under low memory */ if (!cmd->independent_metadata_areas &&critical_section ()) return_NULL; -lvmcache_label_scan (cmd,2 ); +lvmcache_force_next_label_scan (); +lvmcache_label_scan (cmd);if (!(fmt =lvmcache_fmt_from_vgname (cmd, vgname, vgid,0 ))) return_NULL;
@@ -4113,7 +4116,8 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,* allowed to do a full scan here any more. */ // The slow way - full scan required to cope with vgrename -lvmcache_label_scan (cmd,2 ); +lvmcache_force_next_label_scan (); +lvmcache_label_scan (cmd);if (!(vgnames =get_vgnames (cmd,0 ))) {log_error ("vg_read_by_vgid: get_vgnames failed" );return NULL ;
@@ -4374,7 +4378,7 @@ static int _get_pvs(struct cmd_context *cmd, uint32_t warn_flags,struct vg_list *vgl_item =NULL ;int have_pv =0 ; -lvmcache_label_scan (cmd,0 ); +lvmcache_label_scan (cmd);/* Get list of VGs */ if (!(vgids =get_vgids (cmd,1 ))) {
@@ -5179,7 +5183,7 @@ uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname)/* Find the vgname in the cache */ /* If it's not there we must do full scan to be completely sure */ if (!lvmcache_fmt_from_vgname (cmd, vgname,NULL ,1 )) { -lvmcache_label_scan (cmd,0 ); +lvmcache_label_scan (cmd);if (!lvmcache_fmt_from_vgname (cmd, vgname,NULL ,1 )) {/* Independent MDAs aren't supported under low memory */ if (!cmd->independent_metadata_areas &&critical_section ()) {
@@ -5190,7 +5194,8 @@ uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname)unlock_vg (cmd, vgname);return FAILED_LOCKING ; } -lvmcache_label_scan (cmd,2 ); +lvmcache_force_next_label_scan (); +lvmcache_label_scan (cmd);if (!lvmcache_fmt_from_vgname (cmd, vgname,NULL ,0 )) {/* vgname not found after scanning */ return SUCCESS ;
liblvm/lvm_vg.c +2 -1
@@ -511,7 +511,8 @@ int lvm_scan(lvm_t libh)int rc =0 ;struct saved_env e =store_user_env ((struct cmd_context *)libh); -if (!lvmcache_label_scan ((struct cmd_context *)libh,2 )) +lvmcache_force_next_label_scan (); +if (!lvmcache_label_scan ((struct cmd_context *)libh)) rc =-1 ;restore_user_env (&e);
tools/commands.h +1 -1
@@ -1323,7 +1323,7 @@ xx(vgremove,xx (vgrename,"Rename a volume group" , -ALLOW_UUID_AS_NAME , +ALLOW_UUID_AS_NAME |REQUIRES_FULL_LABEL_SCAN ,"vgrename\n" "\t[-A|--autobackup y|n]\n" "\t[--commandprofile ProfileName]\n"
tools/reporter.c +1 -1
@@ -582,7 +582,7 @@ static void _check_pv_list(struct cmd_context *cmd, int argc, char **argv,if (!rescan_done && !dev_cache_get (argv[i], cmd->full_filter)) { cmd->filter->wipe (cmd->filter);/* FIXME scan only one device */ -lvmcache_label_scan (cmd,0 ); +lvmcache_label_scan (cmd); rescan_done =1 ; }if (*argv[i] =='@' ) {
tools/toollib.c +10 -0
@@ -2205,6 +2205,16 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv, }/* +* First rescan for available devices, then force the next +* label scan to be done. get_vgnameids() will scan labels +* (when not using lvmetad). +*/ +if (cmd->command->flags &REQUIRES_FULL_LABEL_SCAN ) { +dev_cache_full_scan (cmd->full_filter); +lvmcache_force_next_label_scan (); + } + +/* * A list of all VGs on the system is needed when: * . processing all VGs on the system * . A VG name is specified which may refer to one
tools/tools.h +2 -0
@@ -105,6 +105,8 @@ struct arg_value_group_list {#define LOCKD_VG_SH 0x00000020/* Command does not process any metadata. */ #define NO_METADATA_PROCESSING 0x00000040 +/* Command wants to scan for new devices and force labels to be read from them all. */ +#define REQUIRES_FULL_LABEL_SCAN 0x00000080/* a register of the lvm commands */ struct command {
tools/vgrename.c +156 -134
357 lines not on this page · raw message