From: agk@sourceware.org <agk@sourceware.org>
To: lvm-devel@redhat.com
Subject: LVM2 ./WHATS_NEW lib/commands/toolcontext.c li ...
Date: 8 Jul 2009 12:36:02 -0000 [thread overview]
Message-ID: <20090708123602.27413.qmail@sourceware.org> (raw)
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: agk at sourceware.org 2009-07-08 12:36:01
Modified files:
. : WHATS_NEW
lib/commands : toolcontext.c
lib/metadata : segtype.h
Log message:
Permit several segment types to be registered by a single shared object.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1166&r2=1.1167
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/commands/toolcontext.c.diff?cvsroot=lvm2&r1=1.76&r2=1.77
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/segtype.h.diff?cvsroot=lvm2&r1=1.23&r2=1.24
--- LVM2/WHATS_NEW 2009/07/06 19:17:15 1.1166
+++ LVM2/WHATS_NEW 2009/07/08 12:36:01 1.1167
@@ -1,5 +1,6 @@
Version 2.02.49 -
================================
+ Permit several segment types to be registered by a single shared object.
Update the man pages to document size units uniformly.
Allow commandline sizes to be specified in terms of bytes and sectors.
Update 'md_chunk_alignment' to use stripe-width to align PV data area.
--- LVM2/lib/commands/toolcontext.c 2009/06/17 20:54:20 1.76
+++ LVM2/lib/commands/toolcontext.c 2009/07/08 12:36:01 1.77
@@ -806,12 +806,59 @@
return 1;
}
+struct segtype_library {
+ struct cmd_context *cmd;
+ void *lib;
+ const char *libname;
+};
+
+int lvm_register_segtype(struct segtype_library *seglib,
+ struct segment_type *segtype)
+{
+ struct segment_type *segtype2;
+
+ segtype->library = seglib->lib;
+ segtype->cmd = seglib->cmd;
+
+ dm_list_iterate_items(segtype2, &seglib->cmd->segtypes) {
+ if (strcmp(segtype2->name, segtype->name))
+ continue;
+ log_error("Duplicate segment type %s: "
+ "unloading shared library %s",
+ segtype->name, seglib->libname);
+ segtype->ops->destroy(segtype);
+ return 0;
+ }
+
+ dm_list_add(&seglib->cmd->segtypes, &segtype->list);
+
+ return 1;
+}
+
+static int _init_single_segtype(struct segtype_library *seglib)
+{
+ struct segment_type *(*init_segtype_fn) (struct cmd_context *);
+ struct segment_type *segtype;
+
+ if (!(init_segtype_fn = dlsym(seglib->lib, "init_segtype"))) {
+ log_error("Shared library %s does not contain segment type "
+ "functions", seglib->libname);
+ return 0;
+ }
+
+ if (!(segtype = init_segtype_fn(seglib->cmd)))
+ return_0;
+
+ return lvm_register_segtype(seglib, segtype);
+}
+
static int _init_segtypes(struct cmd_context *cmd)
{
struct segment_type *segtype;
#ifdef HAVE_LIBDL
const struct config_node *cn;
+ struct segtype_library seglib;
#endif
if (!(segtype = init_striped_segtype(cmd)))
@@ -854,9 +901,9 @@
(cn = find_config_tree_node(cmd, "global/segment_libraries"))) {
struct config_value *cv;
- struct segment_type *(*init_segtype_fn) (struct cmd_context *);
- void *lib;
- struct segment_type *segtype2;
+ int (*init_multiple_segtypes_fn) (struct segtype_library *);
+
+ seglib.cmd = cmd;
for (cv = cn->v; cv; cv = cv->next) {
if (cv->type != CFG_STRING) {
@@ -864,32 +911,37 @@
"global/segment_libraries");
return 0;
}
- if (!(lib = load_shared_library(cmd, cv->v.str,
+ seglib.libname = cv->v.str;
+ if (!(seglib.lib = load_shared_library(cmd,
+ seglib.libname,
"segment type", 0)))
return_0;
- if (!(init_segtype_fn = dlsym(lib, "init_segtype"))) {
- log_error("Shared library %s does not contain "
- "segment type functions", cv->v.str);
- dlclose(lib);
- return 0;
- }
-
- if (!(segtype = init_segtype_fn(cmd)))
- return 0;
- segtype->library = lib;
- dm_list_add(&cmd->segtypes, &segtype->list);
-
- dm_list_iterate_items(segtype2, &cmd->segtypes) {
- if ((segtype == segtype2) ||
- strcmp(segtype2->name, segtype->name))
- continue;
- log_error("Duplicate segment type %s: "
- "unloading shared library %s",
- segtype->name, cv->v.str);
- dm_list_del(&segtype->list);
- segtype->ops->destroy(segtype);
- dlclose(lib);
+ if ((init_multiple_segtypes_fn =
+ dlsym(seglib.lib, "init_multiple_segtypes"))) {
+ if (dlsym(seglib.lib, "init_segtype"))
+ log_warn("WARNING: Shared lib %s has "
+ "conflicting init fns. Using"
+ " init_multiple_segtypes().",
+ seglib.libname);
+ } else
+ init_multiple_segtypes_fn =
+ _init_single_segtype;
+
+ if (!init_multiple_segtypes_fn(&seglib)) {
+ struct dm_list *sgtl, *tmp;
+ log_error("init_multiple_segtypes() failed: "
+ "Unloading shared library %s",
+ seglib.libname);
+ dm_list_iterate_safe(sgtl, tmp, &cmd->segtypes) {
+ segtype = dm_list_item(sgtl, struct segment_type);
+ if (segtype->library == seglib.lib) {
+ dm_list_del(&segtype->list);
+ segtype->ops->destroy(segtype);
+ }
+ }
+ dlclose(seglib.lib);
+ return_0;
}
}
}
@@ -1154,8 +1206,18 @@
lib = segtype->library;
segtype->ops->destroy(segtype);
#ifdef HAVE_LIBDL
- if (lib)
+ /*
+ * If no segtypes remain from this library, close it.
+ */
+ if (lib) {
+ struct segment_type *segtype2;
+ dm_list_iterate_items(segtype2, segtypes)
+ if (segtype2->library == lib)
+ goto skip_dlclose;
dlclose(lib);
+skip_dlclose:
+ ;
+ }
#endif
}
}
--- LVM2/lib/metadata/segtype.h 2009/02/28 20:04:25 1.23
+++ LVM2/lib/metadata/segtype.h 2009/07/08 12:36:01 1.24
@@ -47,13 +47,13 @@
#define segtype_is_virtual(segtype) ((segtype)->flags & SEG_VIRTUAL ? 1 : 0)
struct segment_type {
- struct dm_list list;
- struct cmd_context *cmd;
+ struct dm_list list; /* Internal */
+ struct cmd_context *cmd; /* lvm_register_segtype() sets this. */
uint32_t flags;
struct segtype_handler *ops;
const char *name;
- void *library;
- void *private;
+ void *library; /* lvm_register_segtype() sets this. */
+ void *private; /* For the segtype handler to use. */
};
struct segtype_handler {
@@ -93,6 +93,10 @@
struct segment_type *get_segtype_from_string(struct cmd_context *cmd,
const char *str);
+struct segtype_library;
+int lvm_register_segtype(struct segtype_library *seglib,
+ struct segment_type *segtype);
+
struct segment_type *init_striped_segtype(struct cmd_context *cmd);
struct segment_type *init_zero_segtype(struct cmd_context *cmd);
struct segment_type *init_error_segtype(struct cmd_context *cmd);
next reply other threads:[~2009-07-08 12:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-08 12:36 agk [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-02-01 13:42 LVM2 ./WHATS_NEW lib/commands/toolcontext.c li zkabelac
2012-01-11 20:38 agk
2011-01-06 15:29 zkabelac
2010-11-11 17:29 agk
2010-11-12 7:54 ` Zdenek Kabelac
2010-09-09 13:07 prajnoha
2010-08-11 12:14 prajnoha
2010-04-29 1:38 agk
2008-12-07 4:27 wysochanski
2007-07-28 12:26 meyering
2007-07-23 10:45 mbroz
2006-11-04 3:34 agk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090708123602.27413.qmail@sourceware.org \
--to=agk@sourceware.org \
--cc=lvm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.