Skip to contentSkip to conversation

LVM2 daemons/dmeventd/plugins/lvm2/Makefile.in ...

PATCH [email protected] 1 participant 1 message Feb 23, 2012 Library code

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: mornfall at sourceware.org 2012-02-23 13:11:11

Modified files:
daemons/dmeventd/plugins/lvm2: Makefile.in daemons/dmeventd/plugins/mirror: Makefile.in daemons/dmeventd/plugins/snapshot: Makefile.in daemons/lvmetad: lvmetad-client.h
lib : Makefile.in
lib/activate : activate.c
lib/cache : lvmcache.c lvmcache.h
lib/commands : toolcontext.c
lib/device : dev-cache.c dev-cache.h dev-io.c
lib/format1 : format1.c
lib/format_pool: format_pool.c
lib/format_text: export.c format-text.c import_vsn1.c
text_label.c
lib/label : label.c label.h
lib/metadata : metadata-exported.h metadata.c metadata.h
tools : Makefile.in args.h commands.h pvcreate.c
pvremove.c pvscan.c toollib.c tools.h vgcfgrestore.c vgcreate.c vgrename.c vgscan.c
doc : example.conf.in
scripts : vgimportclone.sh
test/lib : aux.sh
test/shell : inconsistent-metadata.sh lvconvert-mirror.sh
lvcreate-repair.sh lvmcache-exercise.sh pool-labels.sh vgimportclone.sh
test/unit : Makefile.in
Added files:
lib/cache : lvmetad.c lvmetad.h

Log message:
The lvmetad client-side integration. Only active when use_lvmetad = 1 is set in lvm.conf *and* lvmetad is running.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/plugins/lvm2/Makefile.in.diff?cvsroot=lvm2&r1=1.7&r2=1.8
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/plugins/mirror/Makefile.in.diff?cvsroot=lvm2&r1=1.23&r2=1.24
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/plugins/snapshot/Makefile.in.diff?cvsroot=lvm2&r1=1.18&r2=1.19
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/lvmetad/lvmetad-client.h.diff?cvsroot=lvm2&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/Makefile.in.diff?cvsroot=lvm2&r1=1.114&r2=1.115
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/activate/activate.c.diff?cvsroot=lvm2&r1=1.241&r2=1.242
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/cache/lvmetad.c.diff?cvsroot=lvm2&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/cache/lvmetad.h.diff?cvsroot=lvm2&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/cache/lvmcache.c.diff?cvsroot=lvm2&r1=1.126&r2=1.127
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/cache/lvmcache.h.diff?cvsroot=lvm2&r1=1.42&r2=1.43
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/commands/toolcontext.c.diff?cvsroot=lvm2&r1=1.150&r2=1.151
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/device/dev-cache.c.diff?cvsroot=lvm2&r1=1.71&r2=1.72
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/device/dev-cache.h.diff?cvsroot=lvm2&r1=1.14&r2=1.15
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/device/dev-io.c.diff?cvsroot=lvm2&r1=1.81&r2=1.82
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format1/format1.c.diff?cvsroot=lvm2&r1=1.147&r2=1.148
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_pool/format_pool.c.diff?cvsroot=lvm2&r1=1.52&r2=1.53
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/export.c.diff?cvsroot=lvm2&r1=1.86&r2=1.87
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.c.diff?cvsroot=lvm2&r1=1.193&r2=1.194
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/import_vsn1.c.diff?cvsroot=lvm2&r1=1.100&r2=1.101
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/text_label.c.diff?cvsroot=lvm2&r1=1.41&r2=1.42
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/label/label.c.diff?cvsroot=lvm2&r1=1.56&r2=1.57
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/label/label.h.diff?cvsroot=lvm2&r1=1.20&r2=1.21
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.231&r2=1.232
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.485&r2=1.486
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.266&r2=1.267
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/Makefile.in.diff?cvsroot=lvm2&r1=1.124&r2=1.125
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/args.h.diff?cvsroot=lvm2&r1=1.86&r2=1.87
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/commands.h.diff?cvsroot=lvm2&r1=1.167&r2=1.168
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.98&r2=1.99
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvremove.c.diff?cvsroot=lvm2&r1=1.36&r2=1.37
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvscan.c.diff?cvsroot=lvm2&r1=1.53&r2=1.54
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/toollib.c.diff?cvsroot=lvm2&r1=1.241&r2=1.242
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/tools.h.diff?cvsroot=lvm2&r1=1.78&r2=1.79
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgcfgrestore.c.diff?cvsroot=lvm2&r1=1.25&r2=1.26
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgcreate.c.diff?cvsroot=lvm2&r1=1.84&r2=1.85
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgrename.c.diff?cvsroot=lvm2&r1=1.77&r2=1.78
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgscan.c.diff?cvsroot=lvm2&r1=1.38&r2=1.39
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/doc/example.conf.in.diff?cvsroot=lvm2&r1=1.43&r2=1.44
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/scripts/vgimportclone.sh.diff?cvsroot=lvm2&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/lib/aux.sh.diff?cvsroot=lvm2&r1=1.37&r2=1.38
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/shell/inconsistent-metadata.sh.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/shell/lvconvert-mirror.sh.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/shell/lvcreate-repair.sh.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/shell/lvmcache-exercise.sh.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/shell/pool-labels.sh.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/shell/vgimportclone.sh.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/unit/Makefile.in.diff?cvsroot=lvm2&r1=1.7&r2=1.8

daemons/dmeventd/plugins/lvm2/Makefile.in +1 -1
@@ -24,7 +24,7 @@
 
 include $(top_builddir)/make.tmpl
 
-LIBS += @LVM2CMD_LIB@ -ldevmapper $(PTHREAD_LIBS)
+LIBS += @LVM2CMD_LIB@ -ldevmapper $(PTHREAD_LIBS) -L$(top_builddir)/daemons/common -ldaemon
 
 install_lvm2: install_lib_shared
 
daemons/dmeventd/plugins/mirror/Makefile.in +1 -1
@@ -30,7 +30,7 @@
 
 include $(top_builddir)/make.tmpl
 
-LIBS += -ldevmapper-event-lvm2 -ldevmapper
+LIBS += -ldevmapper-event-lvm2 -ldevmapper -L$(top_builddir)/daemons/common -ldaemon
 
 install_lvm2: install_dm_plugin
 
daemons/dmeventd/plugins/snapshot/Makefile.in +1 -1
@@ -26,7 +26,7 @@
 
 include $(top_builddir)/make.tmpl
 
-LIBS += -ldevmapper-event-lvm2 -ldevmapper
+LIBS += -ldevmapper-event-lvm2 -ldevmapper -L$(top_builddir)/daemons/common -ldaemon
 
 install_lvm2: install_dm_plugin
 
daemons/lvmetad/lvmetad-client.h +1 -2
@@ -64,11 +64,10 @@
 
 static inline daemon_handle lvmetad_open(const char *socket)
 {
-	/* TODO configurable */
 	daemon_info lvmetad_info = {
 		.path = "lvmetad",
 		.socket = socket ?: DEFAULT_RUN_DIR "/lvmetad.socket",
-		.autostart = 1
+		.autostart = 0
 	};
 
 	return daemon_open(lvmetad_info);
lib/Makefile.in +3 -0
@@ -16,6 +16,8 @@
 top_srcdir = @top_srcdir@
 top_builddir = @top_builddir@
 
+INCLUDES += -I$(top_srcdir)/daemons/common -I$(top_srcdir)/daemons/lvmetad
+
 ifeq ("@LVM1@", "shared")
   SUBDIRS = format1
 endif
@@ -46,6 +48,7 @@
 
 SOURCES =\
 	activate/activate.c \
+	cache/lvmetad.c \
 	cache/lvmcache.c \
 	commands/toolcontext.c \
 	config/config.c \
lib/activate/activate.c +1 -1
@@ -1883,7 +1883,7 @@
 int pv_uses_vg(struct physical_volume *pv,
 	       struct volume_group *vg)
 {
-	if (!activation())
+	if (!activation() || !pv->dev)
 		return 0;
 
 	if (!dm_is_dm_major(MAJOR(pv->dev->dev)))

/cvs/lvm2/LVM2/lib/cache/lvmetad.c,v --> standard output revision 1.1

- renamed from lib/cache/lvmetad.c +633 -0

633 lines not on this page · raw message

/cvs/lvm2/LVM2/lib/cache/lvmetad.h,v --> standard output revision 1.1

- renamed from lib/cache/lvmetad.h +99 -0

99 lines not on this page · raw message

lib/cache/lvmcache.c +75 -6

179 lines not on this page · raw message

lib/cache/lvmcache.h +10 -4
@@ -34,11 +34,13 @@
 struct dm_config_tree;
 struct format_instance;
 struct metadata_area;
-struct data_area_list;
+struct disk_locn;
 
 struct lvmcache_vginfo;
 
 int lvmcache_init(void);
+void lvmcache_allow_reads_with_lvmetad();
+
 void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans);
 
 /* Set full_scan to 1 to reread every filtered device label or
@@ -64,7 +66,7 @@
 int lvmcache_verify_lock_order(const char *vgname);
 
 /* Queries */
-const struct format_type *lvmcache_fmt_from_vgname(const char *vgname, const char *vgid, unsigned revalidate_labels);
+const struct format_type *lvmcache_fmt_from_vgname(struct cmd_context *cmd, const char *vgname, const char *vgid, unsigned revalidate_labels);
 
 /* Decrement and test if there are still vg holders in vginfo. */
 int lvmcache_vginfo_holders_dec_and_test_for_zero(struct lvmcache_vginfo *vginfo);
@@ -79,9 +81,12 @@
 const char *lvmcache_pvid_from_devname(struct cmd_context *cmd,
 			      const char *dev_name);
 char *lvmcache_vgname_from_pvid(struct cmd_context *cmd, const char *pvid);
+const char *lvmcache_vgname_from_info(struct lvmcache_info *info);
 int lvmcache_vgs_locked(void);
 int lvmcache_vgname_is_locked(const char *vgname);
 
+void lvmcache_seed_infos_from_lvmetad(struct cmd_context *cmd);
+
 /* Returns list of struct str_lists containing pool-allocated copy of vgnames */
 /* If include_internal is not set, return only proper vg names. */
 struct dm_list *lvmcache_get_vgnames(struct cmd_context *cmd,
@@ -97,7 +102,8 @@
 				const char *vgid);
 
 /* Returns cached volume group metadata. */
-struct volume_group *lvmcache_get_vg(const char *vgid, unsigned precommitted);
+struct volume_group *lvmcache_get_vg(struct cmd_context *cmd, const char *vgname,
+				     const char *vgid, unsigned precommitted);
 void lvmcache_drop_metadata(const char *vgname, int drop_precommitted);
 void lvmcache_commit_metadata(const char *vgname);
 
@@ -127,7 +133,7 @@
 			 void *baton);
 
 int lvmcache_foreach_da(struct lvmcache_info *info,
-			int (*fun)(struct data_area_list *, void *),
+			int (*fun)(struct disk_locn *, void *),
 			void *baton);
 
 int lvmcache_foreach_pv(struct lvmcache_vginfo *vg,
lib/commands/toolcontext.c +3 -0
@@ -34,6 +34,7 @@
 #include "str_list.h"
 #include "segtype.h"
 #include "lvmcache.h"
+#include "lvmetad.h"
 #include "dev-cache.h"
 #include "archiver.h"
 
@@ -389,6 +390,8 @@
 		(find_config_tree_int(cmd, "global/detect_internal_vg_cache_corruption()",
 				      DEFAULT_DETECT_INTERNAL_VG_CACHE_CORRUPTION));
 
+	lvmetad_set_active(find_config_tree_int(cmd, "global/use_lvmetad", 0));
+
 	return 1;
 }
 
lib/device/dev-cache.c +33 -0
@@ -906,6 +906,39 @@
 		      f->passes_filter(f, d))) ? d : NULL;
 }
 
+static struct device *_dev_cache_seek_devt(dev_t dev)
+{
+	struct device *d = NULL;
+	struct dm_hash_node *n = dm_hash_get_first(_cache.names);
+	while (n) {
+		d = dm_hash_get_data(_cache.names, n);
+		if (d->dev == dev)
+			return d;
+		n = dm_hash_get_next(_cache.names, n);
+	}
+	return NULL;
+}
+
+/*
+ * TODO This is very inefficient. We probably want a hash table indexed by
+ * major:minor for keys to speed up these lookups.
+ */
+struct device *dev_cache_get_by_devt(dev_t dev, struct dev_filter *f)
+{
+	struct device *d = _dev_cache_seek_devt(dev);
+
+	if (d && (d->flags & DEV_REGULAR))
+		return d;
+
+	if (!d) {
+		_full_scan(0);
+		d = _dev_cache_seek_devt(dev);
+	}
+
+	return (d && (!f || (d->flags & DEV_REGULAR) ||
+		      f->passes_filter(f, d))) ? d : NULL;
+}
+
 struct dev_iter *dev_iter_create(struct dev_filter *f, int dev_scan)
 {
 	struct dev_iter *di = dm_malloc(sizeof(*di));
lib/device/dev-cache.h +3 -0
@@ -44,6 +44,9 @@
 int dev_cache_add_loopfile(const char *path);
 struct device *dev_cache_get(const char *name, struct dev_filter *f);
 
+// TODO
+struct device *dev_cache_get_by_devt(dev_t device, struct dev_filter *f);
+
 void dev_set_preferred_name(struct str_list *sl, struct device *dev);
 
 /*
lib/device/dev-io.c +2 -0
@@ -664,6 +664,8 @@
 	where.start = offset;
 	where.size = len;
 
+	// fprintf(stderr, "READ: %s, %lld, %d\n", dev_name(dev), offset, len);
+
 	ret = _aligned_io(&where, buffer, 0);
 	if (!ret)
 		_dev_inc_error_count(dev);
lib/format1/format1.c +3 -0
@@ -415,6 +415,7 @@
 
 	lvmcache_update_pv(info, pv, fmt);
 	lvmcache_del_mdas(info);
+	lvmcache_del_das(info);
 
 	dm_list_init(&pvs);
 
@@ -590,6 +591,8 @@
 			FMT_RESTRICTED_READAHEAD;
 	fmt->private = NULL;
 
+	dm_list_init(&fmt->mda_ops);
+
 	if (!(fmt->labeller = lvm1_labeller_create(fmt))) {
 		log_error("Couldn't create lvm1 label handler.");
 		dm_free(fmt);
lib/format_pool/format_pool.c +2 -0
@@ -301,6 +301,8 @@
 	fmt->features = 0;
 	fmt->private = NULL;
 
+	dm_list_init(&fmt->mda_ops);
+
 	if (!(fmt->labeller = pool_labeller_create(fmt))) {
 		log_error("Couldn't create pool label handler.");
 		dm_free(fmt);
lib/format_text/export.c +3 -0
@@ -395,6 +395,9 @@
 
 	outf(f, "seqno = %u", vg->seqno);
 
+	if (vg->fid && vg->fid->fmt)
+		outf(f, "format = \"%s\" # informational", vg->fid->fmt->name);
+
 	if (!_print_flag_config(f, vg->status, VG_FLAGS))
 		return_0;
 
lib/format_text/format-text.c +58 -6

114 lines not on this page · raw message

lib/format_text/import_vsn1.c +7 -1
@@ -19,6 +19,7 @@
 #include "display.h"
 #include "toolcontext.h"
 #include "lvmcache.h"
+#include "lvmetad.h"
 #include "lv_alloc.h"
 #include "pv_alloc.h"
 #include "segtype.h"
@@ -59,6 +60,10 @@
 	const struct dm_config_node *cn;
 	const struct dm_config_value *cv;
 
+	// TODO if this is pvscan --lvmetad, we want this check back.
+	if (lvmetad_active())
+		return 1;
+
 	/*
 	 * Check the contents field.
 	 */
@@ -212,7 +217,8 @@
 		return 0;
 	}
 
-	if (!pv->dev)
+	/* TODO is the !lvmetad_active() too coarse here? */
+	if (!pv->dev && !lvmetad_active())
 		pv->status |= MISSING_PV;
 
 	/* Late addition */
lib/format_text/text_label.c +5 -5
@@ -19,6 +19,7 @@
 #include "label.h"
 #include "xlate.h"
 #include "lvmcache.h"
+#include "lvmetad.h"
 
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -40,11 +41,11 @@
 	struct device *dev;
 };
 
-static int _da_setup(struct data_area_list *da, void *baton)
+static int _da_setup(struct disk_locn *da, void *baton)
 {
 	struct _da_setup_baton *p = baton;
-	p->pvh_dlocn_xl->offset = xlate64(da->disk_locn.offset);
-	p->pvh_dlocn_xl->size = xlate64(da->disk_locn.size);
+	p->pvh_dlocn_xl->offset = xlate64(da->offset);
+	p->pvh_dlocn_xl->size = xlate64(da->size);
 	p->pvh_dlocn_xl++;
 	return 1;
 }
@@ -275,7 +276,7 @@
 	const struct format_type *fmt = p->label->labeller->private; // Oh dear.
 	struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
 	struct mda_header *mdah;
-	const char *vgname;
+	const char *vgname = NULL;
 	struct id vgid;
 	uint64_t vgstatus;
 	char *creation_host;
@@ -337,7 +338,6 @@
 				  FMT_TEXT_ORPHAN_VG_NAME, 0)))
 		return_0;
 
-	/* this one is leaked forever */
 	*label = lvmcache_get_label(info);
 
 	lvmcache_set_device_size(info, xlate64(pvhdr->device_size_xl));
lib/label/label.c +2 -1
@@ -18,6 +18,7 @@
 #include "crc.h"
 #include "xlate.h"
 #include "lvmcache.h"
+#include "lvmetad.h"
 #include "metadata.h"
 
 #include <sys/stat.h>
@@ -263,7 +264,7 @@
 
 	if ((info = lvmcache_info_from_pvid(dev->pvid, 1))) {
 		log_debug("Using cached label for %s", dev_name(dev));
-		*result = lvmcache_get_label(info); /* leaked */
+		*result = lvmcache_get_label(info);
 		return 1;
 	}
 
lib/label/label.h +2 -0
@@ -26,6 +26,8 @@
 
 struct labeller;
 
+void allow_reads_with_lvmetad(void);
+
 /* On disk - 32 bytes */
 struct label_header {
 	int8_t id[8];		/* LABELONE */
lib/metadata/metadata-exported.h +1 -0
@@ -174,6 +174,7 @@
 	struct dm_list list;
 	struct cmd_context *cmd;
 	struct format_handler *ops;
+	struct dm_list mda_ops; /* List of permissible mda ops. */
 	struct labeller *labeller;
 	const char *name;
 	const char *alias;
lib/metadata/metadata.c +56 -18

205 lines not on this page · raw message

lib/metadata/metadata.h +4 -0
@@ -70,9 +70,11 @@
 struct dm_config_tree;
 struct metadata_area;
 struct alloc_handle;
+struct lvmcache_info;
 
 /* Per-format per-metadata area operations */
 struct metadata_area_ops {
+	struct dm_list list;
 	struct volume_group *(*vg_read) (struct format_instance * fi,
 					 const char *vg_name,
 					 struct metadata_area * mda);
@@ -145,6 +147,8 @@
 				    struct metadata_area *mda2);
 
 	struct device *(*mda_get_device)(struct metadata_area *mda);
+	char *(*mda_export_text)(struct metadata_area *mda);
+	int (*mda_import_text)(struct lvmcache_info *info, const struct dm_config_node *cn);
 };
 
 #define MDA_IGNORED      0x00000001
tools/Makefile.in +2 -0
@@ -16,6 +16,8 @@
 top_srcdir = @top_srcdir@
 top_builddir = @top_builddir@
 
+INCLUDES += -I$(top_srcdir)/daemons/common -I$(top_srcdir)/daemons/lvmetad
+
 SOURCES =\
 	dumpconfig.c \
 	formats.c \
tools/args.h +1 -0
@@ -61,6 +61,7 @@
 arg(monitor_ARG, '\0', "monitor", yes_no_arg, 0)
 arg(config_ARG, '\0', "config", string_arg, 0)
 arg(trustcache_ARG, '\0', "trustcache", NULL, 0)
+arg(lvmetad_ARG, '\0', "lvmetad", NULL, 0)
 arg(ignoremonitoring_ARG, '\0', "ignoremonitoring", NULL, 0)
 arg(nameprefixes_ARG, '\0', "nameprefixes", NULL, 0)
 arg(unquoted_ARG, '\0', "unquoted", NULL, 0)
tools/commands.h +2 -1
@@ -670,11 +670,12 @@
    "\t[-P|--partial] " "\n"
    "\t[-s|--short] " "\n"
    "\t[-u|--uuid] " "\n"
+   "\t[--lvmetad DEVICE] " "\n"
    "\t[-v|--verbose] " "\n"
    "\t[--version]\n",
 
    exported_ARG, ignorelockingfailure_ARG, novolumegroup_ARG, partial_ARG,
-   short_ARG, uuid_ARG)
+   short_ARG, uuid_ARG, lvmetad_ARG)
 
 xx(segtypes,
    "List available segment types",
tools/pvcreate.c +1 -0
@@ -56,6 +56,7 @@
 		if (!id_read_format(&pp->id, uuid))
 			return 0;
 		pp->idp = &pp->id;
+		lvmcache_seed_infos_from_lvmetad(cmd); /* need to check for UUID dups */
 	}
 
 	if (arg_count(cmd, restorefile_ARG)) {
tools/pvremove.c +2 -0
@@ -128,6 +128,8 @@
 		goto error;
 	}
 
+	lvmetad_pv_gone(dev->dev);
+
 	log_print("Labels on physical volume \"%s\" successfully wiped",
 		  pv_name);
 
tools/pvscan.c +12 -4
@@ -15,6 +15,9 @@
 
 #include "tools.h"
 
+#include "lvmetad.h"
+#include "lvmcache.h"
+
 int pv_max_name_len = 0;
 int vg_max_name_len = 0;
 
@@ -96,8 +99,7 @@
 					   pv_pe_size(pv)));
 }
 
-int pvscan(struct cmd_context *cmd, int argc __attribute__((unused)),
-	   char **argv __attribute__((unused)))
+int pvscan(struct cmd_context *cmd, int argc, char **argv)
 {
 	int new_pvs_found = 0;
 	int pvs_found = 0;
@@ -113,6 +115,12 @@
 	pv_max_name_len = 0;
 	vg_max_name_len = 0;
 
+	if (arg_count(cmd, lvmetad_ARG)) {
+		if (!pvscan_lvmetad(cmd, argc, argv))
+			return ECMD_FAILED;
+		return ECMD_PROCESSED;
+	}
+
 	if (arg_count(cmd, novolumegroup_ARG) && arg_count(cmd, exported_ARG)) {
 		log_error("Options -e and -n are incompatible");
 		return EINVALID_CMD_LINE;
@@ -184,8 +192,8 @@
 	vg_max_name_len += 2;
 
 	dm_list_iterate_items(pvl, pvslist) {
-	    _pvscan_display_single(cmd, pvl->pv, NULL);
-	    free_pv_fid(pvl->pv);
+		_pvscan_display_single(cmd, pvl->pv, NULL);
+		free_pv_fid(pvl->pv);
 	}
 
 	if (!pvs_found) {
tools/toollib.c +3 -0
@@ -305,6 +305,7 @@
 
 	if (!argc || !dm_list_empty(&tags)) {
 		log_verbose("Finding all logical volumes");
+		lvmetad_vg_list_to_lvmcache(cmd);
 		if (!(vgnames = get_vgnames(cmd, 0)) || dm_list_empty(vgnames)) {
 			log_error("No volume groups found");
 			return ret_max;
@@ -581,6 +582,7 @@
 
 	if (!argc || !dm_list_empty(&tags)) {
 		log_verbose("Finding all volume groups");
+		lvmetad_vg_list_to_lvmcache(cmd);
 		if (!(vgids = get_vgids(cmd, 0)) || dm_list_empty(vgids)) {
 			log_error("No volume groups found");
 			return ret_max;
@@ -837,6 +839,7 @@
 		} else {
 			log_verbose("Scanning for physical volume names");
 
+			lvmcache_seed_infos_from_lvmetad(cmd);
 			if (!(pvslist = get_pvs(cmd)))
 				goto bad;
 
tools/tools.h +1 -0
@@ -28,6 +28,7 @@
 #include "activate.h"
 #include "archiver.h"
 #include "lvmcache.h"
+#include "lvmetad.h"
 #include "config.h"
 #include "defaults.h"
 #include "dev-cache.h"
tools/vgcfgrestore.c +2 -0
@@ -45,6 +45,8 @@
 		return ECMD_PROCESSED;
 	}
 
+	lvmcache_seed_infos_from_lvmetad(cmd);
+
 	if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
 		log_error("Unable to lock volume group %s", vg_name);
 		return ECMD_FAILED;
tools/vgcreate.c +2 -0
@@ -49,6 +49,8 @@
 	if (vgcreate_params_validate(cmd, &vp_new))
 	    return EINVALID_CMD_LINE;
 
+	lvmcache_seed_infos_from_lvmetad(cmd);
+
 	/* Create the new VG */
 	vg = vg_create(cmd, vp_new.vg_name);
 	if (vg_read_error(vg)) {
tools/vgrename.c +2 -0
@@ -79,6 +79,8 @@
 
 	log_verbose("Checking for existing volume group \"%s\"", vg_name_old);
 
+	lvmetad_vg_list_to_lvmcache(cmd); /* populate lvmcache */
+
 	/* Avoid duplicates */
 	if (!(vgids = get_vgids(cmd, 0)) || dm_list_empty(vgids)) {
 		log_error("No complete volume groups found");
tools/vgscan.c +5 -1
@@ -24,13 +24,14 @@
 		  vg->fid->fmt->name);
 
 	check_current_backup(vg);
+	lvmetad_vg_update(vg); /* keep lvmetad up to date */
 
 	return ECMD_PROCESSED;
 }
 
 int vgscan(struct cmd_context *cmd, int argc, char **argv)
 {
-	int maxret, ret;
+	int maxret, ret, lvmetad;
 
 	if (argc) {
 		log_error("Too many parameters on command line");
@@ -44,6 +45,8 @@
 
 	persistent_filter_wipe(cmd->filter);
 	lvmcache_destroy(cmd, 1);
+	lvmetad = lvmetad_active();
+	lvmetad_set_active(0); /* do not rely on lvmetad info */
 
 	log_print("Reading all physical volumes.  This may take a while...");
 
@@ -56,6 +59,7 @@
 			maxret = ret;
 	}
 
+	lvmetad_set_active(lvmetad); /* restore */
 	unlock_vg(cmd, VG_GLOBAL);
 	return maxret;
 }
doc/example.conf.in +10 -0
@@ -453,6 +453,16 @@
     # Set to 1 to reinstate the previous format.
     #
     # lvdisplay_shows_full_device_path = 0
+
+    # Whether to use (trust) a running instance of lvmetad. If this is set to
+    # 0, all commands fall back to the usual scanning mechanisms. When set to 1
+    # *and* when lvmetad is running (it is not auto-started), the volume group
+    # metadata and PV state flags are obtained from the lvmetad instance and no
+    # scanning is done by the individual commands. In a setup with lvmetad,
+    # lvmetad udev rules *must* be set up for LVM to work correctly. Without
+    # proper udev rules, all changes in block device configuration will be
+    # *ignored* until a manual 'vgscan' is performed.
+    use_lvmetad = 0
 }
 
 activation {
scripts/vgimportclone.sh +1 -0
@@ -249,6 +249,7 @@
     '/^[ \t]*filter[ \t]*=/{print ENVIRON["FILTER"];next} \
      /^[ \t]*scan[ \t]*=/{print "scan = [ \"" DEV "\" ]";next} \
      /^[ \t]*cache[ \t]*=/{print "cache = \"" CACHE "\"";next} \
+     /^[ \t]*use_lvmetad[ \t]*=/{print "use_lvmetad = 0";next} \
      /^[ \t]*cache_dir[ \t]*=/{print "cache_dir = \"" CACHE_DIR "\"";next} \
      {print $0}' > ${LVMCONF}
 
test/lib/aux.sh +6 -2
@@ -70,6 +70,7 @@
 	}
 
 	lvmconf "global/use_lvmetad = 1"
+	lvmconf "devices/md_component_detection = 0"
 
 	lvmetad -f "$@" -s $TESTDIR/lvmetad.socket &
 	echo "$!" > LOCAL_LVMETAD
@@ -323,8 +324,11 @@
 
 	init_udev_transaction
 	for dev in "$@"; do
-        	dmsetup remove -f $dev || true
-		pvscan --lvmetad $dev || true
+	    maj=$(($(stat --printf=0x%t $dev)))
+	    min=$(($(stat --printf=0x%T $dev)))
+	    echo "disabling device $dev ($maj:$min)"
+            dmsetup remove -f $dev || true
+	    pvscan --lvmetad $maj:$min || true
 	done
 	finish_udev_transaction
 
test/shell/inconsistent-metadata.sh +24 -21

53 lines not on this page · raw message

test/shell/lvconvert-mirror.sh +1 -0
@@ -79,6 +79,7 @@
 lvconvert $vg/$lv1 # wait
 lvconvert -m2 $vg/$lv1 $dev1 $dev2 $dev4 $dev3:0 # If the above "should" failed...
 
+sleep 1
 lvconvert -m-1 $vg/$lv1 $dev1
 check mirror_images_on $lv1 $dev2 $dev4
 lvconvert -m-1 $vg/$lv1 $dev2
test/shell/lvcreate-repair.sh +9 -7
@@ -14,31 +14,32 @@
 aux prepare_vg 3
 
 # fail multiple devices
-for i in pv1 pv2 pv3 ; do
-	for j in pv2 pv3 ; do
+for i in $dev1 $dev2 $dev3 ; do
+	for j in $dev2 $dev3 ; do
 
 		if test $i = $j ; then continue ; fi
 
 		vgremove -ff $vg
 		vgcreate $vg $dev1 $dev2 $dev3
+		# exit 1
 
 		lvcreate -l1 -n $lv1 $vg $dev1
 
-		aux lvmconf "devices/filter = [ \"r/.*$i$/\", \"r/.*$j$/\", \"a/dev\/mapper\/.*pv[0-9_]*$/\", \"r/.*/\" ]"
+		aux disable_dev $i $j
 
 		vgreduce --removemissing --force $vg
 
 		# check if reduced device was removed
-		test $i = pv1 && dmsetup table | not egrep "$vg-$lv1: *[^ ]+" >/dev/null
+		test $i = $dev1 && dmsetup table | not egrep "$vg-$lv1: *[^ ]+" >/dev/null
 
 		lvcreate -l1 -n $lv2 $vg
 
-		test $i != pv1 && check lv_exists $vg $lv1
+		test $i != $dev1 && check lv_exists $vg $lv1
 		check lv_exists $vg $lv2
 
-		aux lvmconf 'devices/filter = [ "a/dev\/mapper\/.*pv[0-9_]*$/", "r/.*/" ]'
+		aux enable_dev $i $j
 
-		test $i != pv1 && check lv_exists $vg $lv1
+		test $i != $dev1 && check lv_exists $vg $lv1
 		check lv_exists $vg $lv2
 	done
 done
@@ -84,6 +85,7 @@
 
 # dirty game
 dd if=/dev/zero of="$dev3" bs=256K count=1
+pvscan --lvmetad $dev3 || true # udev be watching you
 
 vgreduce --removemissing --force $vg
 
test/shell/lvmcache-exercise.sh +1 -1
@@ -19,5 +19,5 @@
 pvscan
 vgcreate $vg1 $dev2
 aux enable_dev $dev1
-pvs
+valgrind --trace-children=yes pvs
 pvs
test/shell/pool-labels.sh +1 -0
@@ -18,6 +18,7 @@
   # printf comes from coreutils, and is probably not posix either
   env printf "\x01\x16\x70\x06\x5f\xcf\xff\xb9\xf8\x24\x8apool1" | dd of=$2 bs=5 seek=1 conv=notrunc
   env printf "\x04\x01\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x0$1\x68\x01\x16\x70\x00\x00\x00\x00\x00\x06\x5f\xd0" | dd of=$2 bs=273 seek=1 conv=notrunc
+  pvscan --lvmetad "$2" || true
 }
 
 env printf "" || exit 200 # skip if printf is not available
test/shell/vgimportclone.sh +8 -0
@@ -17,6 +17,7 @@
 
 # Clone the LUN
 dd if=$dev1 of=$dev2 bs=256K count=1
+pvscan --lvmetad $dev2 || true
 
 # Verify pvs works on each device to give us vgname
 check pv_field $dev1 vg_name $vg1
@@ -25,6 +26,13 @@
 # Import the cloned PV to a new VG
 vgimportclone --basevgname $vg2 $dev2
 
+# We need to re-scan *both* $dev1 and $dev2 since a PV, as far as lvmetad is
+# concerned, can only live on a single device. With the last pvscan, we told it
+# that PV from $dev1 now lives on $dev2, but in fact this is not true anymore,
+# since we wrote a different PV over $dev2.
+pvscan --lvmetad $dev2 || true
+pvscan --lvmetad $dev1 || true
+
 # Verify we can activate / deactivate the LV from both VGs
 lvchange -ay $vg1/$lv1 $vg2/$lv1
 vgchange -an $vg1 $vg2
test/unit/Makefile.in +1 -1
@@ -25,7 +25,7 @@
 LDLIBS += -ldevmapper @CUNIT_LIBS@
 CFLAGS += @CUNIT_CFLAGS@
 
-all: unit
+check: unit
 
 unit: $(TARGETS)
 	@echo Running unit tests