Skip to contentSkip to conversation

master - polldaemon: refactor polling interfaces

PATCH okozina 1 participant 1 message May 5, 2015

lore
Share & tools
lore

okozina

author
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=76a0dffe6f4869de9ca457119c9d7ced837d4e0b
Commit:        76a0dffe6f4869de9ca457119c9d7ced837d4e0b
Parent:        bda26acf70e92232b1ed644dba6b44ecbff2a058
Author:        Ondrej Kozina <[email protected]>
AuthorDate:    Fri Apr 10 14:08:19 2015 +0200
Committer:     Ondrej Kozina <[email protected]>
CommitterDate: Tue May 5 20:52:07 2015 +0200

polldaemon: refactor polling interfaces

Routines responsible for polling of in-progress pvmove, snapshot merge or mirror conversion each used custom lookup functions to find vg and lv involved in polling.

Especially pvmove used pvname to lookup pvmove in-progress. The future lvmpolld will poll each operation by vg/lv name (internally by lvid). Also there're plans to make pvmove able to move non-overlaping ranges of extents instead of single PVs as of now. This would also require to identify the opertion in different manner.

The poll_operation_id structure together with daemon_parms structure they identify unambiguously the polling task.

---
 tools/lvconvert.c   |   69 +++++++++++++++++------
 tools/polldaemon.c  |  122 ++++++++++++++++++++++++++++++-----------
 tools/polldaemon.h  |   12 +++-
 tools/pvmove.c      |  153 ++++++++++++++++++++++++++++++++++++++++++++++-----
 tools/pvmove_poll.c |   27 ---------
 tools/pvmove_poll.h |    9 ---
 tools/toollib.c     |    2 +-
 tools/tools.h       |    5 +-
 8 files changed, 291 insertions(+), 108 deletions(-)
tools/lvconvert.c +50 -19
index 41aaad6..5b2ab65 100644
@@ -720,37 +720,68 @@ static struct poll_functions _lvconvert_thin_merge_fns = {
 	.finish_copy = lvconvert_merge_finish,
 };
 
+static void _destroy_id(struct cmd_context *cmd, struct poll_operation_id *id)
+{
+	if (!id)
+		return;
+
+	dm_pool_free(cmd->mem, (void *)id);
+}
+
+static struct poll_operation_id *_create_id(struct cmd_context *cmd,
+					    const char *vg_name,
+					    const char *lv_name,
+					    const char *uuid)
+{
+	char lv_full_name[NAME_LEN];
+	struct poll_operation_id *id = dm_pool_alloc(cmd->mem, sizeof(struct poll_operation_id));
+	if (!id) {
+		log_error("Poll operation ID allocation failed.");
+		return NULL;
+	}
+
+	if (dm_snprintf(lv_full_name, sizeof(lv_full_name), "%s/%s", vg_name, lv_name) < 0) {
+		log_error(INTERNAL_ERROR "Name \"%s/%s\" is too long.", vg_name, lv_name);
+		_destroy_id(cmd, id);
+		return NULL;
+	}
+
+	id->display_name = dm_pool_strdup(cmd->mem, lv_full_name);
+	id->vg_name = vg_name ? dm_pool_strdup(cmd->mem, vg_name) : NULL;
+	id->lv_name = id->display_name ? strchr(id->display_name, '/') + 1 : NULL;
+	id->uuid = uuid ? dm_pool_strdup(cmd->mem, uuid) : NULL;
+
+	if (!id->vg_name || !id->lv_name || !id->display_name || !id->uuid) {
+		log_error("Failed to copy one or more poll operation ID members.");
+		_destroy_id(cmd, id);
+		id = NULL;
+	}
+
+	return id;
+}
+
 int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv,
 		   unsigned background)
 {
-	/*
-	 * FIXME allocate an "object key" structure with split
-	 * out members (vg_name, lv_name, uuid, etc) and pass that
-	 * around the lvconvert and polldaemon code
-	 * - will avoid needless work, e.g. extract_vgname()
-	 * - unfortunately there are enough overloaded "name" dragons in
-	 *   the polldaemon, lvconvert, pvmove code that a comprehensive
-	 *   audit/rework is needed
-	 */
-	char uuid[sizeof(lv->lvid)];
-	char lv_full_name[NAME_LEN];
 	int is_thin, r;
+	struct poll_operation_id *id = _create_id(cmd, lv->vg->name, lv->name, lv->lvid.s);
 
-	if (dm_snprintf(lv_full_name, sizeof(lv_full_name), "%s/%s", lv->vg->name, lv->name) < 0) {
-		log_error(INTERNAL_ERROR "Name \"%s/%s\" is too long.", lv->vg->name, lv->name);
+	if (!id) {
+		log_error("Failed to allocate poll identifier for lvconvert.");
 		return ECMD_FAILED;
 	}
 
-	memcpy(uuid, &lv->lvid, sizeof(lv->lvid));
-
 	if (lv_is_merging_origin(lv)) {
 		is_thin = seg_is_thin_volume(find_snapshot(lv));
-		r = poll_daemon(cmd, lv_full_name, uuid, background, 0,
+		r = poll_daemon(cmd, background,
+				(MERGING | (is_thin ? THIN_VOLUME : SNAPSHOT)),
 				is_thin ? &_lvconvert_thin_merge_fns : &_lvconvert_merge_fns,
-				"Merged");
+				"Merged", id);
 	} else
-		r = poll_daemon(cmd, lv_full_name, uuid, background, 0,
-				&_lvconvert_mirror_fns, "Converted");
+		r = poll_daemon(cmd, background, CONVERTING,
+				&_lvconvert_mirror_fns, "Converted", id);
+
+	_destroy_id(cmd, id);
 
 	return r;
 }
tools/polldaemon.c +90 -32

225 lines not on this page · raw message

tools/polldaemon.h +9 -3
index 1779007..9c33250 100644
@@ -52,6 +52,13 @@ struct poll_functions {
 			    struct dm_list *lvs_changed);
 };
 
+struct poll_operation_id {
+	const char *vg_name;
+	const char *lv_name;
+	const char *display_name;
+	const char *uuid;
+};
+
 struct daemon_parms {
 	unsigned interval;
 	unsigned wait_before_testing;
@@ -64,10 +71,9 @@ struct daemon_parms {
 	struct poll_functions *poll_fns;
 };
 
-int poll_daemon(struct cmd_context *cmd, const char *name, const char *uuid,
-		unsigned background,
+int poll_daemon(struct cmd_context *cmd, unsigned background,
 		uint64_t lv_type, struct poll_functions *poll_fns,
-		const char *progress_title);
+		const char *progress_title, struct poll_operation_id *id);
 
 progress_t poll_mirror_progress(struct cmd_context *cmd,
 				struct logical_volume *lv, const char *name,
tools/pvmove.c +138 -15

210 lines not on this page · raw message

tools/pvmove_poll.c +0 -27
index eeaf390..61ebd23 100644
@@ -16,13 +16,6 @@
 #include "pvmove_poll.h"
 #include "tools.h"
 
-struct volume_group *get_vg(struct cmd_context *cmd, const char *vgname)
-{
-	dev_close_all();
-
-	return vg_read_for_update(cmd, vgname, NULL, 0);
-}
-
 static int _is_pvmove_image_removable(struct logical_volume *mimage_lv,
 				      void *baton)
 {
@@ -201,23 +194,3 @@ int pvmove_finish(struct cmd_context *cmd, struct volume_group *vg,
 
 	return r;
 }
-
-struct volume_group *pvmove_get_copy_vg(struct cmd_context *cmd, const char *name,
-					const char *uuid __attribute__((unused)),
-					uint32_t flags __attribute__((unused)))
-{
-	struct physical_volume *pv;
-	struct volume_group *vg;
-
-	/* Reread all metadata in case it got changed */
-	if (!(pv = find_pv_by_name(cmd, name, 0, 0))) {
-		log_error("ABORTING: Can't reread PV %s", name);
-		/* What more could we do here? */
-		return NULL;
-	}
-
-	vg = get_vg(cmd, pv_vg_name(pv));
-	free_pv_fid(pv);
-
-	return vg;
-}
tools/pvmove_poll.h +0 -9
index ae7505a..b12458f 100644
@@ -15,16 +15,11 @@
 #ifndef _LVM_PVMOVE_H
 #define _LVM_PVMOVE_H
 
-/* FIXME: remove it after refactoring completes */
-#include <stdint.h>
-
 struct cmd_context;
 struct dm_list;
 struct logical_volume;
 struct volume_group;
 
-struct volume_group *get_vg(struct cmd_context *cmd, const char *vgname);
-
 int pvmove_update_metadata(struct cmd_context *cmd, struct volume_group *vg,
 			   struct logical_volume *lv_mirr,
 			   struct dm_list *lvs_changed, unsigned flags);
@@ -32,8 +27,4 @@ int pvmove_update_metadata(struct cmd_context *cmd, struct volume_group *vg,
 int pvmove_finish(struct cmd_context *cmd, struct volume_group *vg,
 		  struct logical_volume *lv_mirr, struct dm_list *lvs_changed);
 
-struct volume_group *pvmove_get_copy_vg(struct cmd_context *cmd,
-					const char *name, const char *uuid,
-					uint32_t flags);
-
 #endif  /* _LVM_PVMOVE_H */
tools/toollib.c +1 -1
index d29bebf..e6c3cdb 100644
@@ -921,7 +921,7 @@ void lv_spawn_background_polling(struct cmd_context *cmd,
 	    (pvname = get_pvmove_pvname_from_lv_mirr(lv_mirr))) {
 		log_verbose("Spawning background pvmove process for %s.",
 			    pvname);
-		pvmove_poll(cmd, pvname, 1);
+		pvmove_poll(cmd, pvname, lv_mirr->lvid.s, lv_mirr->vg->name, lv_mirr->name, 1);
 	}
 
 	if (lv_is_converting(lv) || lv_is_merging(lv)) {
tools/tools.h +3 -2
index 1f344b0..e959d80 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.  
- * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2015 Red Hat, Inc. All rights reserved.
  *
  * This file is part of LVM2.
  *
@@ -176,7 +176,8 @@ int32_t grouped_arg_int_value(const struct arg_values *av, int a, const int32_t
 
 const char *command_name(struct cmd_context *cmd);
 
-int pvmove_poll(struct cmd_context *cmd, const char *pv, unsigned background);
+int pvmove_poll(struct cmd_context *cmd, const char *pv_name, const char *uuid,
+		const char *vg_name, const char *lv_name, unsigned background);
 int lvconvert_poll(struct cmd_context *cmd, struct logical_volume *lv, unsigned background);
 
 int mirror_remove_missing(struct cmd_context *cmd,