Skip to contentSkip to conversation

Fixes and speedups

PATCH New Zdenek Kabelac 3 participants 21 messages Jan 7, 2011 – Jan 8, 2011

lore
Share & tools
lore
#0 lore raw

cover Fixes and speedups

Patchset combines few fixes from the last review. Hopefully they should be now in the 'acceptable' state.

And also fix for ocfdir and its selection is added.

I hope it'll hit 2.02.80 version.

Zdenek Kabelac (8):
Add support for OCF dir selection
Add default error path for get_property
Change import_vg_from_buffer to use config_tree
Cache config_tree
Define DM_COOKIE_AUTO_CREATE
Add internal fs cookie
Stop calling fs_unlock() and dm_udev_wait()
Add fs_unlock calls

 configure.in                  |    5 +++++
 daemons/clvmd/clvmd-command.c |    1 +
 daemons/clvmd/lvm-functions.c |    8 ++++++++
 daemons/clvmd/lvm-functions.h |    1 +
 include/.symlinks.in          |    1 +
 lib/activate/activate.c       |    2 --
 lib/activate/dev_manager.c    |   25 ++++++++-----------------
 lib/activate/fs.c             |   22 +++++++++++++++++++++-
 lib/activate/fs.h             |    2 ++
 lib/cache/lvmcache.c          |   19 +++++++++++++++++--
 lib/cache/lvmcache.h          |    3 +++
 lib/format_text/import.c      |    9 ++-------
 lib/locking/file_locking.c    |    2 ++
 lib/metadata/lv_manip.c       |    3 +++
 lib/metadata/metadata.h       |    3 +++
 libdm/libdevmapper.h          |    5 +++++
 liblvm/lvm_misc.c             |   26 +++++++++++---------------
 make.tmpl.in                  |    2 +-
 18 files changed, 94 insertions(+), 45 deletions(-)
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 1/8 Add support for OCF dir selection

Add --with-ocfdir supported configure option.
Fixes also superfluous '/usr' in 'ocf_scriptdir'.

Note: After commit regeneration of configure file is needed.

---
 configure.in |    5 +++++
 make.tmpl.in |    2 +-
 2 files changed, 6 insertions(+), 1 deletions(-)
configure.in +5 -0
index 6cb5e8d..b58a6ba 100644
@@ -368,6 +368,10 @@ AC_ARG_ENABLE(ocf,
 			     [enable Open Cluster Framework (OCF) compliant resource agents]),
 	      OCF=$enableval, OCF=no)
 AC_MSG_RESULT($OCF)
+AC_ARG_WITH(ocfdir,
+	    AC_HELP_STRING([--with-ocfdir=DIR],
+			   [install OCF files in DIR [[PREFIX/lib/ocf/resource.d/lvm2]]]),
+	    OCFDIR=$withval, OCFDIR='${prefix}/lib/ocf/resource.d/lvm2')
 
 ################################################################################
 dnl -- Init pkg-config with dummy invokation:
@@ -1328,6 +1332,7 @@ AC_SUBST(LVM_RELEASE)
 AC_SUBST(LVM_RELEASE_DATE)
 AC_SUBST(MIRRORS)
 AC_SUBST(OCF)
+AC_SUBST(OCFDIR)
 AC_SUBST(REPLICATORS)
 AC_SUBST(MSGFMT)
 AC_SUBST(PKGCONFIG)
make.tmpl.in +1 -1
index 806f77a..48fd617 100644
@@ -65,7 +65,7 @@ staticdir = $(DESTDIR)@STATICDIR@
 udevdir = $(DESTDIR)@udevdir@
 pkgconfigdir = $(usrlibdir)/pkgconfig
 initdir = $(DESTDIR)@sysconfdir@/rc.d/init.d
-ocf_scriptdir = $(DESTDIR)@prefix@/usr/lib/ocf/resource.d/lvm2
+ocf_scriptdir = $(DESTDIR)@OCFDIR@
 
 USRLIB_RELPATH = $(shell echo $(abspath $(usrlibdir) $(libdir)) | \
   $(AWK) -f $(top_srcdir)/scripts/relpath.awk)
Signature · 1 line
1.7.3.4
#2 lore raw

PATCH 1/8 Add support for OCF dir selection

Quoted 1 line · Zdenek Kabelac

Add --with-ocfdir supported configure option.

Ack.

Quoted 1 line

Note: After commit regeneration of configure file is needed.

If you have F14 installed, use that now.

Alasdair

#3 lore raw

PATCH 2/8 Add default error path for get_property

In reply to Zdenek Kabelac

Set invalid property value for error path when none of handlers is set. Fixes use of uninitialized prop variable as we return 'v' by value.

---
 liblvm/lvm_misc.c |   26 +++++++++++---------------
 1 files changed, 11 insertions(+), 15 deletions(-)
liblvm/lvm_misc.c +11 -15
index 62fef61..e5464fe 100644
@@ -52,33 +52,29 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
 	struct lvm_property_type prop;
 	struct lvm_property_value v;
 
+	memset(&v, 0, sizeof(v));
 	prop.id = name;
+
 	if (pv) {
-		if (!pv_get_property(pv, &prop)) {
-			v.is_valid = 0;
+		if (!pv_get_property(pv, &prop))
 			return v;
-		}
 	} else if (vg) {
-		if (!vg_get_property(vg, &prop)) {
-			v.is_valid = 0;
+		if (!vg_get_property(vg, &prop))
 			return v;
-		}
 	} else if (lv) {
-		if (!lv_get_property(lv, &prop)) {
-			v.is_valid = 0;
+		if (!lv_get_property(lv, &prop))
 			return v;
-		}
 	} else if (lvseg) {
-		if (!lvseg_get_property(lvseg, &prop)) {
-			v.is_valid = 0;
+		if (!lvseg_get_property(lvseg, &prop))
 			return v;
-		}
 	} else if (pvseg) {
-		if (!pvseg_get_property(pvseg, &prop)) {
-			v.is_valid = 0;
+		if (!pvseg_get_property(pvseg, &prop))
+			return v;
+	} else {
+			log_errno(EINVAL, "Invalid query for property.");
 			return v;
-		}
 	}
+
 	v.is_settable = prop.is_settable;
 	v.is_string = prop.is_string;
 	v.is_integer = prop.is_integer;
Signature · 1 line
1.7.3.4
#4 lore raw

PATCH 2/8 Add default error path for get_property

liblvm/lvm_misc.c struct lvm_property_value get_property(const pv_t pv, const vg_t vg, · line 74

Quoted 1 line · Zdenek Kabelac
liblvm/lvm_misc.c +1 -0
+			log_errno(EINVAL, "Invalid query for property.");

Do we have any information about the property to include in that error message, such as its name?

Ack.

Alasdair

#5 lore raw

PATCH 2/8 Add default error path for get_property

Dne 7.1.2011 14:41, Alasdair G Kergon napsal(a):

Quoted 6 lines · Zdenek Kabelac

liblvm/lvm_misc.c struct lvm_property_value get_property(const pv_t pv, const vg_t vg, · line 74

Quoted 1 line
liblvm/lvm_misc.c +1 -0
+			log_errno(EINVAL, "Invalid query for property.");

Do we have any information about the property to include in that error message, such as its name?

No - all parameters passed to get_property are NULL in this case - so programmer's error.

Zdenek

#6 lore raw

PATCH 2/8 Add default error path for get_property

Quoted 2 lines · Zdenek Kabelac

No - all parameters passed to get_property are NULL in this case - so programmer's error.

So in what sense is it invalid?
(I'm basically asking if a more-useful error message is possible. So you could say in it the function was called without any parameters set?)

Alasdair

#7 lore raw

PATCH 2/8 Add default error path for get_property

Dne 7.1.2011 14:55, Alasdair G Kergon napsal(a):

Quoted 8 lines · Zdenek Kabelac
Quoted 2 lines

No - all parameters passed to get_property are NULL in this case - so programmer's error.

So in what sense is it invalid?
(I'm basically asking if a more-useful error message is possible. So you could say in it the function was called without any parameters set?)

Examle of such error use-case could be:

lv = NULL;
lvm_lv_get_property(lv, "name");

i.e. user will use invalid lv handle for some reason - code mistake, missing check...

Maybe "Invalid library use." ?

Zdenek

#8 lore raw

PATCH 2/8 Add default error path for get_property

Quoted 15 lines · Zdenek Kabelac

Dne 7.1.2011 14:55, Alasdair G Kergon napsal(a):

Quoted 8 lines · Zdenek Kabelac
Quoted 2 lines

No - all parameters passed to get_property are NULL in this case - so programmer's error.

So in what sense is it invalid?
(I'm basically asking if a more-useful error message is possible. So you could say in it the function was called without any parameters set?)

Examle of such error use-case could be:

lv = NULL;
lvm_lv_get_property(lv, "name");

Quoted 7 lines

i.e. user will use invalid lv handle for some reason - code mistake, missing check...

Maybe "Invalid library use." ?

Zdenek

Cleanup in this patch looks great. Ack.

However, some handle validation should be done at the beginning of every library call (problem not unique to this function), not just in this function.

#9 lore raw

PATCH 3/8 Change import_vg_from_buffer to use config_tree

In reply to Zdenek Kabelac

Change function import_vg_from_buffer() to import_vg_from_config_tree(). Instead of creating config tree inside the function allow cft to be passed as parameter - usable later for caching.

Patch only moves the code and presents no functional change.

---
 lib/cache/lvmcache.c     |   13 +++++++++++--
 lib/cache/lvmcache.h     |    2 ++
 lib/format_text/import.c |    9 ++-------
 lib/metadata/metadata.h  |    3 +++
 4 files changed, 18 insertions(+), 9 deletions(-)
lib/cache/lvmcache.c +11 -2
index d545563..ebd6d44 100644
@@ -26,6 +26,7 @@
 #include "format-text.h"
 #include "format_pool.h"
 #include "format1.h"
+#include "config.h"
 
 static struct dm_hash_table *_pvid_hash = NULL;
 static struct dm_hash_table *_vgid_hash = NULL;
@@ -650,12 +651,20 @@ struct volume_group *lvmcache_get_vg(const char *vgid, unsigned precommitted)
 						      vgid, NULL)))
 		return_NULL;
 
-	if (!(vg = import_vg_from_buffer(vginfo->vgmetadata, fid))) {
+	if (!(vginfo->cft =
+	      create_config_tree_from_string(fid->fmt->cmd,
+					     vginfo->vgmetadata))) {
 		_free_cached_vgmetadata(vginfo);
-		free_vg(vg);
 		return_NULL;
 	}
 
+	if (!(vg = import_vg_from_config_tree(vginfo->cft, fid))) {
+		_free_cached_vgmetadata(vginfo);
+		destroy_config_tree(vginfo->cft);
+		return_NULL;
+	}
+	destroy_config_tree(vginfo->cft);
+
 	log_debug("Using cached %smetadata for VG %s.",
 		  vginfo->precommitted ? "pre-committed" : "", vginfo->vgname);
 
lib/cache/lvmcache.h +2 -0
index 06838dc..8c07a26 100644
@@ -33,6 +33,7 @@
 struct cmd_context;
 struct format_type;
 struct volume_group;
+struct config_tree;
 
 /* One per VG */
 struct lvmcache_vginfo {
@@ -46,6 +47,7 @@ struct lvmcache_vginfo {
 	struct lvmcache_vginfo *next; /* Another VG with same name? */
 	char *creation_host;
 	char *vgmetadata;	/* Copy of VG metadata as format_text string */
+	struct config_tree *cft; /* Config tree created from vgmetadata */
 	unsigned precommitted;	/* Is vgmetadata live or precommitted? */
 };
 
lib/format_text/import.c +2 -7
index 60f465f..aa8c807 100644
@@ -131,18 +131,14 @@ struct volume_group *text_vg_import_file(struct format_instance *fid,
 				 when, desc);
 }
 
-struct volume_group *import_vg_from_buffer(const char *buf,
-                                           struct format_instance *fid)
+struct volume_group *import_vg_from_config_tree(const struct config_tree *cft,
+						struct format_instance *fid)
 {
 	struct volume_group *vg = NULL;
-	struct config_tree *cft;
 	struct text_vg_version_ops **vsn;
 
 	_init_text_import();
 
-	if (!(cft = create_config_tree_from_string(fid->fmt->cmd, buf)))
-		return_NULL;
-
 	for (vsn = &_text_vsn_list[0]; *vsn; vsn++) {
 		if (!(*vsn)->check_version(cft))
 			continue;
@@ -155,6 +151,5 @@ struct volume_group *import_vg_from_buffer(const char *buf,
 		break;
 	}
 
-	destroy_config_tree(cft);
 	return vg;
 }
lib/metadata/metadata.h +3 -0
index 08bff4a..c0f9148 100644
@@ -100,6 +100,7 @@
 //#define FMT_RESIZE_PV		0x00000080U	/* Supports pvresize? */
 //#define FMT_UNLIMITED_STRIPESIZE 0x00000100U	/* Unlimited stripe size? */
 
+struct config_tree;
 struct metadata_area;
 
 /* Per-format per-metadata area operations */
@@ -388,6 +389,8 @@ void lv_calculate_readahead(const struct logical_volume *lv, uint32_t *read_ahea
 int export_vg_to_buffer(struct volume_group *vg, char **buf);
 struct volume_group *import_vg_from_buffer(const char *buf,
 					   struct format_instance *fid);
+struct volume_group *import_vg_from_config_tree(const struct config_tree *cft,
+						struct format_instance *fid);
 
 /*
  * Mirroring functions
Signature · 1 line
1.7.3.4
#10 lore raw

PATCH 3/8 Change import_vg_from_buffer to use config_tree

Quoted 3 lines · Zdenek Kabelac

Change function import_vg_from_buffer() to import_vg_from_config_tree(). Instead of creating config tree inside the function allow cft to be passed as parameter - usable later for caching.

Ack.

Alasdair

#11 lore raw

PATCH 4/8 Cache config_tree

In reply to Zdenek Kabelac

Start to use config_tree for cache just like vgmetedata. When vgmetadata are erased - destroy its config tree.

---
 lib/cache/lvmcache.c |   12 +++++++++---
 lib/cache/lvmcache.h |    1 +
 2 files changed, 10 insertions(+), 3 deletions(-)
lib/cache/lvmcache.c +9 -3
index ebd6d44..0e9cae1 100644
@@ -83,6 +83,12 @@ static void _free_cached_vgmetadata(struct lvmcache_vginfo *vginfo)
 
 	vginfo->vgmetadata = NULL;
 
+	/* Release also cached config tree */
+	if (vginfo->cft) {
+		destroy_config_tree(vginfo->cft);
+		vginfo->cft = NULL;
+	}
+
 	log_debug("Metadata cache: VG %s wiped.", vginfo->vgname);
 }
 
@@ -651,7 +657,9 @@ struct volume_group *lvmcache_get_vg(const char *vgid, unsigned precommitted)
 						      vgid, NULL)))
 		return_NULL;
 
-	if (!(vginfo->cft =
+	/* Build config tree from vgmetadata, if not yet cached */
+	if (!vginfo->cft &&
+	    !(vginfo->cft =
 	      create_config_tree_from_string(fid->fmt->cmd,
 					     vginfo->vgmetadata))) {
 		_free_cached_vgmetadata(vginfo);
@@ -660,10 +668,8 @@ struct volume_group *lvmcache_get_vg(const char *vgid, unsigned precommitted)
 
 	if (!(vg = import_vg_from_config_tree(vginfo->cft, fid))) {
 		_free_cached_vgmetadata(vginfo);
-		destroy_config_tree(vginfo->cft);
 		return_NULL;
 	}
-	destroy_config_tree(vginfo->cft);
 
 	log_debug("Using cached %smetadata for VG %s.",
 		  vginfo->precommitted ? "pre-committed" : "", vginfo->vgname);
lib/cache/lvmcache.h +1 -0
index 8c07a26..080f3b5 100644
@@ -48,6 +48,7 @@ struct lvmcache_vginfo {
 	char *creation_host;
 	char *vgmetadata;	/* Copy of VG metadata as format_text string */
 	struct config_tree *cft; /* Config tree created from vgmetadata */
+				/* Lifetime is directly tied to vgmetadata */
 	unsigned precommitted;	/* Is vgmetadata live or precommitted? */
 };
 
Signature · 1 line
1.7.3.4
#12 lore raw

PATCH 4/8 Cache config_tree

Quoted 2 lines · Zdenek Kabelac

Start to use config_tree for cache just like vgmetedata. When vgmetadata are erased - destroy its config tree.

Ack.

Alasdair

#13 lore raw

PATCH 5/8 Define DM_COOKIE_AUTO_CREATE

In reply to Zdenek Kabelac

TODO: Use it also for already written code.

---
 libdm/libdevmapper.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
libdm/libdevmapper.h +5 -0
index 994a364..eea1a6c 100644
@@ -1214,6 +1214,11 @@ void dm_udev_set_sync_support(int sync_with_udev);
 int dm_udev_get_sync_support(void);
 void dm_udev_set_checking(int checking);
 int dm_udev_get_checking(void);
+
+/*
+ * Default value to get new auto generated cookie created
+ */
+#define DM_COOKIE_AUTO_CREATE 0
 int dm_udev_create_cookie(uint32_t *cookie);
 int dm_udev_complete(uint32_t cookie);
 int dm_udev_wait(uint32_t cookie);
Signature · 1 line
1.7.3.4
#14 lore raw

PATCH 5/8 Define DM_COOKIE_AUTO_CREATE

Quoted 1 line · Zdenek Kabelac

+#define DM_COOKIE_AUTO_CREATE 0

Ack.
(If anyone has a better idea for a name, we've got till Monday before this one becomes part of the API.)

Alasdair

#15 lore raw

PATCH 6/8 Add internal fs cookie

In reply to Zdenek Kabelac

Add functions for handling internal lvm cookie used for all dm_tree operations until fs_unlock is called.

---
 lib/activate/fs.c |   22 +++++++++++++++++++++-
 lib/activate/fs.h |    2 ++
 2 files changed, 23 insertions(+), 1 deletions(-)
lib/activate/fs.c +21 -1
index 1523115..cbe823a 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-2011 Red Hat, Inc. All rights reserved.
  *
  * This file is part of LVM2.
  *
@@ -26,6 +26,12 @@
 #include <limits.h>
 #include <dirent.h>
 
+/*
+ * Library cookie to combine multiple fs transactions.
+ * Supports to wait for udev device settle only when needed.
+ */
+static uint32_t _fs_cookie = DM_COOKIE_AUTO_CREATE;
+
 static int _mk_dir(const char *dev_dir, const char *vg_name)
 {
 	char vg_path[PATH_MAX];
@@ -396,7 +402,21 @@ int fs_rename_lv(struct logical_volume *lv, const char *dev,
 void fs_unlock(void)
 {
 	if (!memlock()) {
+		/* Wait for all processed udev devices */
+		if (!dm_udev_wait(_fs_cookie))
+			stack;
+		_fs_cookie = DM_COOKIE_AUTO_CREATE; /* Reset cookie */
 		dm_lib_release();
 		_pop_fs_ops();
 	}
 }
+
+uint32_t fs_get_cookie(void)
+{
+	return _fs_cookie;
+}
+
+void fs_set_cookie(uint32_t cookie)
+{
+	_fs_cookie = cookie;
+}
lib/activate/fs.h +2 -0
index 28b2c73..695c529 100644
@@ -30,5 +30,7 @@ int fs_del_lv_byname(const char *dev_dir, const char *vg_name,
 int fs_rename_lv(struct logical_volume *lv, const char *dev, 
 		 const char *old_vgname, const char *old_lvname);
 void fs_unlock(void);
+uint32_t fs_get_cookie(void);
+void fs_set_cookie(uint32_t cookie);
 
 #endif
Signature · 1 line
1.7.3.4
#16 lore raw

PATCH 6/8 Add internal fs cookie

Quoted 2 lines · Zdenek Kabelac

Add functions for handling internal lvm cookie used for all dm_tree operations until fs_unlock is called.

Ack.

lib/activate/fs.c int fs_rename_lv(struct logical_volume *lv, const char *dev, · line 406

Quoted 1 line
lib/activate/fs.c +1 -0
+		if (!dm_udev_wait(_fs_cookie))

(This function returns succesfully immediately if _fs_cookie still holds DM_COOKIE_AUTO_CREATE.)

Alasdair

#17 lore raw

PATCH 7/8 Stop calling fs_unlock() and dm_udev_wait()

In reply to Zdenek Kabelac

Stop calling fs_unlock() from lv_de/activate()

Start using internal lvm fs cookie for dm_tree.

Stop directly calling dm_udev_wait() and
dm_tree_set/get_cookie() from activate code -
it's now called through fs_unlock() function.

---
 lib/activate/activate.c    |    2 --
 lib/activate/dev_manager.c |   25 ++++++++-----------------
 2 files changed, 8 insertions(+), 19 deletions(-)
lib/activate/activate.c +0 -2
index 174f09e..e199fbb 100644
@@ -1206,7 +1206,6 @@ int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
 	memlock_inc(cmd);
 	r = _lv_deactivate(lv);
 	memlock_dec(cmd);
-	fs_unlock();
 
 	if (!lv_info(cmd, lv, 0, &info, 1, 0) || info.exists)
 		r = 0;
@@ -1305,7 +1304,6 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
 	if (!(r = _lv_activate_lv(lv, 0)))
 		stack;
 	memlock_dec(cmd);
-	fs_unlock();
 
 	if (r && !monitor_dev_for_events(cmd, lv, 0, 1))
 		stack;
lib/activate/dev_manager.c +8 -17
index 6d7d905..1fbefc4 100644
@@ -1622,7 +1622,6 @@ static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root, char *
 	struct dm_tree_node *child;
 	char *vgname, *lvname, *layer;
 	const char *name, *uuid;
-	int r;
 
 	while ((child = dm_tree_next_child(&handle, root, 0))) {
 		if (!(name = dm_tree_node_get_name(child)))
@@ -1644,12 +1643,7 @@ static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root, char *
 		if (non_toplevel_tree_dlid && !strcmp(non_toplevel_tree_dlid, uuid))
 			continue;
 
-		dm_tree_set_cookie(root, 0);
-		r = dm_tree_deactivate_children(root, uuid, strlen(uuid));
-		if (!dm_udev_wait(dm_tree_get_cookie(root)))
-			stack;
-
-		if (!r)
+		if (!dm_tree_deactivate_children(root, uuid, strlen(uuid)))
 			return_0;
 	}
 
@@ -1669,9 +1663,12 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv,
 
 	if (!(root = dm_tree_find_node(dtree, 0, 0))) {
 		log_error("Lost dependency tree root node");
-		goto out;
+		goto out_no_root;
 	}
 
+	/* Restore fs cookie */
+	dm_tree_set_cookie(root, fs_get_cookie());
+
 	if (!(dlid = build_dm_uuid(dm->mem, lv->lvid.s, origin_only ? "real" : NULL)))
 		goto_out;
 
@@ -1684,10 +1681,7 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv,
 		break;
 	case DEACTIVATE:
  		/* Deactivate LV and all devices it references that nothing else has open. */
-		dm_tree_set_cookie(root, 0);
 		r = dm_tree_deactivate_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1);
-		if (!dm_udev_wait(dm_tree_get_cookie(root)))
-			stack;
 		if (!r)
 			goto_out;
 		if (!_remove_lv_symlinks(dm, root))
@@ -1708,10 +1702,7 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv,
 			goto_out;
 
 		/* Preload any devices required before any suspensions */
-		dm_tree_set_cookie(root, 0);
 		r = dm_tree_preload_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1);
-		if (!dm_udev_wait(dm_tree_get_cookie(root)))
-			stack;
 		if (!r)
 			goto_out;
 
@@ -1719,10 +1710,7 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv,
 			dm->flush_required = 1;
 
 		if (action == ACTIVATE) {
-			dm_tree_set_cookie(root, 0);
 			r = dm_tree_activate_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1);
-			if (!dm_udev_wait(dm_tree_get_cookie(root)))
-				stack;
 			if (!r)
 				goto_out;
 			if (!_create_lv_symlinks(dm, root)) {
@@ -1740,6 +1728,9 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv,
 	r = 1;
 
 out:
+	/* Save fs cookie for udev settle, do not wait here */
+	fs_set_cookie(dm_tree_get_cookie(root));
+out_no_root:
 	dm_tree_free(dtree);
 
 	return r;
Signature · 1 line
1.7.3.4
#18 lore raw

PATCH 7/8 Stop calling fs_unlock() and dm_udev_wait()

Quoted 1 line · Zdenek Kabelac

Stop calling fs_unlock() from lv_de/activate()

Ack.

lib/activate/dev_manager.c static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, · line 1664

Quoted 3 lines
lib/activate/dev_manager.c +1 -0
@@ -1669,9 +1663,12 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv,
 
+	/* Restore fs cookie */

Restore?

If a cookie is already allocated, re-use it; otherwise create a new one?

lib/activate/dev_manager.c static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, · line 1670

Quoted 1 line
lib/activate/dev_manager.c +1 -0
+	dm_tree_set_cookie(root, fs_get_cookie());

Alasdair

#19 lore raw

PATCH 8/8 Add fs_unlock calls

In reply to Zdenek Kabelac

Add lvm_do_fs_unlock()

Call fs_unlock() when unlocking vg where implicit unlock solves the problem also for cluster - thus no extra command for clustering environment is required - only lvm_do_fs_unlock() function is added to call lvm's fs_unlock() while holding lvm_lock mutex in clvmd.

Add fs_unlock() also to set_lv() so the command waits until devices are ready for regular open (i.e. wiping its begining).

---
 daemons/clvmd/clvmd-command.c |    1 +
 daemons/clvmd/lvm-functions.c |    8 ++++++++
 daemons/clvmd/lvm-functions.h |    1 +
 include/.symlinks.in          |    1 +
 lib/locking/file_locking.c    |    2 ++
 lib/metadata/lv_manip.c       |    3 +++
 6 files changed, 16 insertions(+), 0 deletions(-)
daemons/clvmd/clvmd-command.c +1 -0
index b1ea9fa..f613e0c 100644
@@ -212,6 +212,7 @@ static int lock_vg(struct local_client *client)
 	if (lkid == 0)
 	    return EINVAL;
 
+	lvm_do_fs_unlock(); /* Wait for devices */
 	status = sync_unlock(lockname, lkid);
 	if (status)
 	    status = errno;
daemons/clvmd/lvm-functions.c +8 -0
index 214f229..b74d3da 100644
@@ -30,6 +30,7 @@
 #include "activate.h"
 #include "archiver.h"
 #include "memlock.h"
+#include "fs.h"
 
 #include <syslog.h>
 
@@ -894,6 +895,13 @@ struct dm_hash_node *get_next_excl_lock(struct dm_hash_node *v, char **name)
 	return v;
 }
 
+void lvm_do_fs_unlock(void)
+{
+	pthread_mutex_lock(&lvm_lock);
+	fs_unlock();
+	pthread_mutex_unlock(&lvm_lock);
+}
+
 /* Called to initialise the LVM context of the daemon */
 int init_clvm(int using_gulm, char **argv)
 {
daemons/clvmd/lvm-functions.h +1 -0
index 97153d4..a132f4a 100644
@@ -36,5 +36,6 @@ extern char *get_last_lvm_error(void);
 extern void do_lock_vg(unsigned char command, unsigned char lock_flags,
 		      char *resource);
 extern struct dm_hash_node *get_next_excl_lock(struct dm_hash_node *v, char **name);
+void lvm_do_fs_unlock(void);
 
 #endif
include/.symlinks.in +1 -0
index c16e107..263c530 100644
@@ -2,6 +2,7 @@
 @top_srcdir@/daemons/dmeventd/libdevmapper-event.h
 @top_srcdir@/liblvm/lvm2app.h
 @top_srcdir@/lib/activate/activate.h
+ at top_srcdir@/lib/activate/fs.h
 @top_srcdir@/lib/activate/targets.h
 @top_srcdir@/lib/cache/lvmcache.h
 @top_srcdir@/lib/commands/errors.h
lib/locking/file_locking.c +2 -0
index d74bfd1..566a05b 100644
@@ -22,6 +22,7 @@
 #include "lvm-file.h"
 #include "lvm-string.h"
 #include "lvmcache.h"
+#include "fs.h"
 
 #include <limits.h>
 #include <unistd.h>
@@ -215,6 +216,7 @@ static int _lock_file(const char *file, uint32_t flags)
 		state = 'W';
 		break;
 	case LCK_UNLOCK:
+		fs_unlock(); /* Wait until devices are available */
 		return _release_lock(file, 1);
 	default:
 		log_error("Unrecognised lock type: %d", flags & LCK_TYPE_MASK);
lib/metadata/lv_manip.c +3 -0
index 4a984a5..6480e18 100644
@@ -26,6 +26,7 @@
 #include "archiver.h"
 #include "activate.h"
 #include "str_list.h"
+#include "fs.h"
 
 struct lv_names {
 	const char *old;
@@ -3022,6 +3023,8 @@ int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
 		return 0;
 	}
 
+	fs_unlock();  /* Wait until devices are available */
+
 	log_verbose("Clearing start of logical volume \"%s\"", lv->name);
 
 	if (!(dev = dev_cache_get(name, NULL))) {
Signature · 1 line
1.7.3.4
#20 lore raw

PATCH 8/8 Add fs_unlock calls

Quoted 1 line · Zdenek Kabelac

Add lvm_do_fs_unlock()

Ack.

Quoted 1 line

+ at top_srcdir@/lib/activate/fs.h

Please would you export it via activate.h instead? (I'd prefer not to expose the other functions in fs.h.)

Alasdair