master - lvmetad: rework command connection setup and checking
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5e9e43074a6c5e251ee44768421879b03ad2e530 Commit: 5e9e43074a6c5e251ee44768421879b03ad2e530 Parent: 593900b795e194608e9e2088aa8f75f4f42484c1 Author: David Teigland <[email protected]> AuthorDate: Wed Apr 13 17:00:01 2016 -0500 Committer: David Teigland <[email protected]> CommitterDate: Tue Apr 19 14:00:02 2016 -0500
lvmetad: rework command connection setup and checking
The lvmetad connection is created within the init_connections() path during command startup, rather than via the old lvmetad_active() check.
The old lvmetad_active() checks are replaced with lvmetad_used() which is a simple check that tests if the command is using/connected to lvmetad.
The old lvmetad_set_active(cmd, 0) calls, which stopped the command from using lvmetad (to revert to disk scanning), are replaced with lvmetad_make_unused(cmd).
--- lib/cache/lvmcache.c | 14 ++-- lib/cache/lvmetad.c | 122 ++++++++++++++++++----------------------- lib/cache/lvmetad.h | 53 ++++------------- lib/commands/toolcontext.c | 46 +++++++++++++-- lib/format_text/archiver.c | 2 +- lib/format_text/format-text.c | 2 +- lib/format_text/import_vsn1.c | 6 +- lib/metadata/metadata.c | 6 +- tools/lvchange.c | 23 +------ tools/lvmcmdline.c | 14 ++--- tools/lvscan.c | 4 +- tools/pvdisplay.c | 2 +- tools/pvscan.c | 4 +- tools/reporter.c | 2 +- tools/vgchange.c | 21 +------ tools/vgck.c | 2 +- tools/vgimport.c | 4 +- tools/vgscan.c | 4 +- 18 files changed, 144 insertions(+), 187 deletions(-)
lib/cache/lvmcache.c +7 -7
@@ -164,7 +164,7 @@ void lvmcache_set_preferred_duplicates(const char *vgid)void lvmcache_seed_infos_from_lvmetad (struct cmd_context *cmd) { -if (!lvmetad_active () || _has_scanned) +if (!lvmetad_used () || _has_scanned)return ;if (!lvmetad_pv_list_to_lvmcache (cmd)) {
@@ -542,7 +542,7 @@ const struct format_type *lvmcache_fmt_from_vgname(struct cmd_context *cmd, char vgid_found[ID_LEN + 1] __attribute__((aligned(8)));if (!(vginfo =lvmcache_vginfo_from_vgname (vgname, vgid))) { -if (!lvmetad_active ()) +if (!lvmetad_used ())return NULL ;/* too bad */ /* If we don't have the info but we have lvmetad, we can ask * there before failing. */
@@ -784,7 +784,7 @@ int lvmcache_label_scan(struct cmd_context *cmd)int r =0 ; -if (lvmetad_active ()) +if (lvmetad_used ())return 1 ;/* Avoid recursion when a PVID can't be found! */
@@ -862,7 +862,7 @@ struct volume_group *lvmcache_get_vg(struct cmd_context *cmd, const char *vgname* using the classic scanning mechanics, and read from disk or from * lvmcache. */ -if (lvmetad_active () && !precommitted) { +if (lvmetad_used () && !precommitted) {/* Still serve the locally cached VG if available */ if (vgid && (vginfo =lvmcache_vginfo_from_vgid (vgid)) && vginfo->vgmetadata && (vg = vginfo->cached_vg))
@@ -1082,7 +1082,7 @@ static struct device *_device_from_pvid(const struct id *pvid,struct label *label;if ((info =lvmcache_info_from_pvid ((const char *) pvid,0 ))) { -if (lvmetad_active ()) { +if (lvmetad_used ()) {if (info->label && label_sector) *label_sector = info->label->sector;return info->dev;
@@ -2397,7 +2397,7 @@ int lvmcache_is_orphan(struct lvmcache_info *info) {int lvmcache_vgid_is_cached (const char *vgid) {struct lvmcache_vginfo *vginfo; -if (lvmetad_active ()) +if (lvmetad_used ())return 1 ; vginfo =lvmcache_vginfo_from_vgid (vgid);
@@ -2497,7 +2497,7 @@ int lvmcache_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const chstruct lvmcache_vginfo *vginfo;int ret =0 ; -if (lvmetad_active ()) +if (lvmetad_used ())return lvmetad_vg_is_foreign (cmd, vgname, vgid);if ((vginfo =lvmcache_vginfo_from_vgid (vgid)))
lib/cache/lvmetad.c +53 -69
265 lines not on this page · raw message
lib/cache/lvmetad.h +13 -40
82 lines not on this page · raw message
lib/commands/toolcontext.c +40 -6
59 lines not on this page · raw message
lib/format_text/archiver.c +1 -1
@@ -502,7 +502,7 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg,if (!vg_write (vg)) return_0; -if (drop_lvmetad &&lvmetad_active ()) { +if (drop_lvmetad &&lvmetad_used ()) {struct volume_group *vg_lvmetad =lvmetad_vg_lookup (cmd, vg->name,NULL );if (vg_lvmetad) {/* FIXME Cope with failure to update lvmetad */
lib/format_text/format-text.c +1 -1
@@ -1525,7 +1525,7 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name,if (!(dev =dev_cache_get (pv_name, fmt->cmd->filter))) return_0; -if (lvmetad_active ()) { +if (lvmetad_used ()) { info =lvmcache_info_from_pvid (dev->pvid,0 );if (!info && !lvmetad_pv_lookup_by_dev (fmt->cmd, dev,NULL ))return 0 ;
lib/format_text/import_vsn1.c +3 -3
@@ -63,7 +63,7 @@ static int _vsn1_check_version(const struct dm_config_tree *cft)const struct dm_config_value *cv;// TODO if this is pvscan --cache, we want this check back. -if (lvmetad_active ()) +if (lvmetad_used ())return 1 ;/*
@@ -241,8 +241,8 @@ static int _read_pv(struct format_instance *fid,return 0 ; } -/* TODO is the !lvmetad_active() too coarse here? */ -if (!pv->dev && !lvmetad_active ()) +/* TODO is the !lvmetad_used() too coarse here? */ +if (!pv->dev && !lvmetad_used ()) pv->status |=MISSING_PV ;if ((pv->status &MISSING_PV ) && pv->dev &&pv_mda_used_count (pv) ==0 ) {
lib/metadata/metadata.c +3 -3
@@ -4122,7 +4122,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,return _vg_read_orphans (cmd, warn_flags, vgname, consistent); } -if (lvmetad_active () && !use_precommitted) { +if (lvmetad_used () && !use_precommitted) {if ((correct_vg =lvmcache_get_vg (cmd, vgname, vgid, precommitted))) {dm_list_iterate_items (pvl, &correct_vg->pvs) if (pvl->pv->dev)
@@ -4949,7 +4949,7 @@ static struct physical_volume *_pv_read(struct cmd_context *cmd,if (!(dev =dev_cache_get (pv_name, cmd->filter))) return_NULL; -if (lvmetad_active ()) { +if (lvmetad_used ()) { info =lvmcache_info_from_pvid (dev->pvid,0 );if (!info) {if (!lvmetad_pv_lookup_by_dev (cmd, dev, &found))
@@ -5044,7 +5044,7 @@ int get_vgnameids(struct cmd_context *cmd, struct dm_list *vgnameids,return 1 ; } -if (lvmetad_active ()) { +if (lvmetad_used ()) {/* * This just gets the list of names/ids from lvmetad * and does not populate lvmcache.
tools/lvchange.c +4 -19
@@ -1258,25 +1258,10 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)* need to take special care here as lvmetad service does * not neet to be running at this moment yet - it could be * just too early during system initialization time. -*/ -if (arg_count (cmd, sysinit_ARG) &&lvmetad_used () && -arg_uint_value (cmd, activate_ARG,0 ) ==CHANGE_AAY ) { -if (!lvmetad_socket_present ()) { -/* -* If lvmetad socket is not present yet, -* the service is just not started. It'll -* be started a bit later so we need to do -* the activation without lvmetad which means -* direct activation instead of autoactivation. -*/ -log_warn ("lvmetad is not active yet, using direct activation during sysinit" ); -lvmetad_set_active (cmd,0 ); - }else if (lvmetad_active ()) { -/* -* If lvmetad is active already, we want -* to make use of the autoactivation. -*/ -log_warn ("lvmetad is active, skipping direct activation during sysinit" ); +*/ +if (arg_count (cmd, sysinit_ARG) && (arg_uint_value (cmd, activate_ARG,0 ) ==CHANGE_AAY )) { +if (lvmetad_used ()) { +log_warn ("WARNING: lvmetad is active, skipping direct activation during sysinit" );return ECMD_PROCESSED ; } }
tools/lvmcmdline.c +5 -9
@@ -1112,9 +1112,6 @@ static int _get_settings(struct cmd_context *cmd)*/ cmd->vg_read_print_access_error =1 ; -if (!arg_count (cmd, sysinit_ARG)) -lvmetad_connect_or_warn (); -if (arg_count (cmd, nosuffix_ARG)) cmd->current_settings.suffix =0 ;
@@ -1474,8 +1471,7 @@ static int _cmd_no_meta_proc(struct cmd_context *cmd)int lvm_run_command (struct cmd_context *cmd,int argc,char **argv) { -struct dm_config_tree *config_string_cft; -struct dm_config_tree *config_profile_command_cft, *config_profile_metadata_cft; +struct dm_config_tree *config_string_cft, *config_profile_command_cft, *config_profile_metadata_cft;const char *reason =NULL ;int ret =0 ;int locking_type;
@@ -1606,7 +1602,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)log_warn ("WARNING: Disabling lvmetad cache which does not support obsolete metadata." );lvmetad_set_disabled (cmd,"LVM1" );log_warn ("WARNING: Not using lvmetad because lvm1 format is used." ); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); } if (cmd->metadata_read_only &&
@@ -1633,7 +1629,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv) }if (lvmetad_used ()) { -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd);log_verbose ("Not using lvmetad because read-only is set." ); } }else if (arg_count (cmd, nolocking_ARG))
@@ -1674,13 +1670,13 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)if (cmd->include_foreign_vgs || !lvmetad_token_matches (cmd)) {if (lvmetad_used () && !lvmetad_pvscan_all_devs (cmd,NULL , cmd->include_foreign_vgs ?1 :0 )) {log_warn ("WARNING: Not using lvmetad because cache update failed." ); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); } }if (lvmetad_used () &&lvmetad_is_disabled (cmd, &reason)) {log_warn ("WARNING: Not using lvmetad because %s." , reason); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); } }
tools/lvscan.c +2 -2
@@ -105,12 +105,12 @@ int lvscan(struct cmd_context *cmd, int argc, char **argv)if (lvmetad_used () && (!lvmetad_token_matches (cmd) ||lvmetad_is_disabled (cmd, &reason))) {if (lvmetad_used () && !lvmetad_pvscan_all_devs (cmd,NULL ,0 )) {log_warn ("WARNING: Not using lvmetad because cache update failed." ); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); }if (lvmetad_used () &&lvmetad_is_disabled (cmd, &reason)) {log_warn ("WARNING: Not using lvmetad because %s." , reason); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); }/*
tools/pvdisplay.c +1 -1
@@ -99,7 +99,7 @@ int pvdisplay(struct cmd_context *cmd, int argc, char **argv)* we lock VG_GLOBAL to enable use of metadata cache. * This can pause alongide pvscan or vgscan process for a while. */ -if (!lvmetad_active ()) { +if (!lvmetad_used ()) { lock_global =1 ;if (!lock_vol (cmd,VG_GLOBAL ,LCK_VG_READ ,NULL )) {log_error ("Unable to obtain global lock." );
tools/pvscan.c +2 -2
@@ -465,12 +465,12 @@ int pvscan(struct cmd_context *cmd, int argc, char **argv)if (lvmetad_used () && (!lvmetad_token_matches (cmd) ||lvmetad_is_disabled (cmd, &reason))) {if (lvmetad_used () && !lvmetad_pvscan_all_devs (cmd,NULL ,0 )) {log_warn ("WARNING: Not using lvmetad because cache update failed." ); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); }if (lvmetad_used () &&lvmetad_is_disabled (cmd, &reason)) {log_warn ("WARNING: Not using lvmetad because %s." , reason); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); } }
tools/reporter.c +1 -1
@@ -897,7 +897,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,* This can pause alongide pvscan or vgscan process for a while. */ if (args_are_pvs && (report_type ==PVS || report_type ==PVSEGS ) && - !lvmetad_active ()) { + !lvmetad_used ()) { lock_global =1 ;if (!lock_vol (cmd,VG_GLOBAL ,LCK_VG_READ ,NULL )) {log_error ("Unable to obtain global lock." );
tools/vgchange.c +3 -18
@@ -1184,24 +1184,9 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)* not neet to be running at this moment yet - it could be * just too early during system initialization time. */ -if (arg_count (cmd, sysinit_ARG) &&lvmetad_used () && -arg_uint_value (cmd, activate_ARG,0 ) ==CHANGE_AAY ) { -if (!lvmetad_socket_present ()) { -/* -* If lvmetad socket is not present yet, -* the service is just not started. It'll -* be started a bit later so we need to do -* the activation without lvmetad which means -* direct activation instead of autoactivation. -*/ -log_warn ("lvmetad is not active yet, using direct activation during sysinit" ); -lvmetad_set_active (cmd,0 ); - }else if (lvmetad_active ()) { -/* -* If lvmetad is active already, we want -* to make use of the autoactivation. -*/ -log_warn ("lvmetad is active, skipping direct activation during sysinit" ); +if (arg_count (cmd, sysinit_ARG) && (arg_uint_value (cmd, activate_ARG,0 ) ==CHANGE_AAY )) { +if (lvmetad_used ()) { +log_warn ("WARNING: lvmetad is active, skipping direct activation during sysinit" );return ECMD_PROCESSED ; } }
tools/vgck.c +1 -1
@@ -37,7 +37,7 @@ static int vgck_single(struct cmd_context *cmd __attribute__((unused)),int vgck (struct cmd_context *cmd,int argc,char **argv) { -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd);return process_each_vg (cmd, argc, argv,NULL ,0 ,NULL , &vgck_single); }
tools/vgimport.c +2 -2
@@ -98,12 +98,12 @@ int vgimport(struct cmd_context *cmd, int argc, char **argv)if (lvmetad_used ()) {if (!lvmetad_pvscan_all_devs (cmd,NULL ,1 )) {log_warn ("WARNING: Not using lvmetad because cache update failed." ); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); }if (lvmetad_used () &&lvmetad_is_disabled (cmd, &reason)) {log_warn ("WARNING: Not using lvmetad because %s." , reason); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); } }
tools/vgscan.c +2 -2
@@ -103,12 +103,12 @@ int vgscan(struct cmd_context *cmd, int argc, char **argv)if (lvmetad_used () && (arg_is_set (cmd, cache_long_ARG) || !lvmetad_token_matches (cmd) ||lvmetad_is_disabled (cmd, &reason))) {if (lvmetad_used () && !lvmetad_pvscan_all_devs (cmd,NULL ,arg_is_set (cmd, cache_long_ARG))) {log_warn ("WARNING: Not using lvmetad because cache update failed." ); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); }if (lvmetad_used () &&lvmetad_is_disabled (cmd, &reason)) {log_warn ("WARNING: Not using lvmetad because %s." , reason); -lvmetad_set_active (cmd,0 ); +lvmetad_make_unused (cmd); } }