1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

More dmeventd support.

This commit is contained in:
Alasdair Kergon 2005-12-02 20:35:07 +00:00
parent 06f62ad1e4
commit 15d91f5a68
10 changed files with 154 additions and 5 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.02 -
====================================
Bring lvdisplay man page example into line.
Add mirror dmeventd library.
Add some activation logic to remove_mirror_images().
lvconvert can remove specified PVs from a mirror.

5
configure vendored
View File

@ -858,7 +858,7 @@ Optional Features:
--disable-o_direct Disable O_DIRECT
--enable-cmdlib Build shared command library
--enable-fsadm Enable fsadm
--enable-dmeventd Enable dmeventd
--enable-dmeventd Enable the device-mapper event daemon
--enable-nls Enable Native Language Support
Optional Packages:
@ -7448,6 +7448,9 @@ echo "$as_me: error: --enable-dmeventd currently requires --with-mirrors=interna
{ (exit 1); exit 1; }; }
fi
if test x$DMEVENTD = xyes; then
CFLAGS="$CFLAGS -DDMEVENTD"
fi
################################################################################
if [ "x$exec_prefix" = xNONE -a "x$prefix" = xNONE ];
then exec_prefix="";

View File

@ -369,6 +369,9 @@ AC_MSG_ERROR(
)
fi
if test x$DMEVENTD = xyes; then
CFLAGS="$CFLAGS -DDMEVENTD"
fi
################################################################################
dnl -- Mess with default exec_prefix
if [[ "x$exec_prefix" = xNONE -a "x$prefix" = xNONE ]];

View File

@ -133,6 +133,10 @@ ifeq ("@HAVE_LIBDL@", "yes")
misc/sharedlib.c
endif
ifeq ("@DMEVENTD@", "yes")
CLDFLAGS += -ldevmapper-event
endif
LIB_STATIC = liblvm.a
$(SUBDIRS): $(LIB_STATIC)

View File

@ -27,6 +27,7 @@
#include "str_list.h"
#include "config.h"
#include "filter.h"
#include "segtype.h"
#include <limits.h>
#include <fcntl.h>
@ -563,6 +564,35 @@ int lvs_in_vg_opened(struct volume_group *vg)
return count;
}
#ifdef DMEVENTD
static int _register_dev(struct cmd_context *cmd, struct logical_volume *lv,
int do_reg)
{
struct list *tmp;
struct lv_segment *seg;
int (*reg) (struct dm_pool *mem, struct lv_segment *,
struct config_tree *cft, int events);
list_iterate(tmp, &lv->segments) {
seg = list_item(tmp, struct lv_segment);
if (do_reg)
reg = seg->segtype->ops->target_register;
else
reg = seg->segtype->ops->target_unregister;
if (reg)
/* FIXME specify events */
if (!reg(cmd->mem, seg, cmd->cft, 0)) {
stack;
return 0;
}
}
return 1;
}
#endif
static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
int error_if_not_suspended)
{
@ -595,6 +625,9 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
}
}
#ifdef DMEVENTD
_register_dev(cmd, lv, 0);
#endif
memlock_inc();
if (!_lv_suspend_lv(lv)) {
memlock_dec();
@ -645,6 +678,10 @@ static int _lv_resume(struct cmd_context *cmd, const char *lvid_s,
memlock_dec();
fs_unlock();
#ifdef DMEVENTD
_register_dev(cmd, lv, 1);
#endif
return 1;
}
@ -688,6 +725,10 @@ int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
return 0;
}
#ifdef DMEVENTD
_register_dev(cmd, lv, 0);
#endif
memlock_inc();
r = _lv_deactivate(lv);
memlock_dec();
@ -758,6 +799,10 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
memlock_dec();
fs_unlock();
#ifdef DMEVENTD
_register_dev(cmd, lv, 1);
#endif
return r;
}

View File

@ -717,7 +717,7 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc,
next_le = (prev_lvseg ? prev_lvseg->le + prev_lvseg->len : 0) + *allocated;
if (next_le >= spvs->le) {
if (next_le + max_parallel > spvs->le + spvs->len)
max_parallel = spvs->le + spvs->len - next_le;
max_parallel = (spvs->le + spvs->len - next_le) * ah->area_multiple;
parallel_pvs = &spvs->pvs;
break;
}

View File

@ -78,6 +78,10 @@ struct segtype_handler {
uint64_t *total_denominator, float *percent);
int (*target_present) (void);
void (*destroy) (const struct segment_type * segtype);
int (*target_register) (struct dm_pool *mem, struct lv_segment *seg,
struct config_tree *cft, int events);
int (*target_unregister) (struct dm_pool *mem, struct lv_segment *seg,
struct config_tree *cft, int events);
};
struct segment_type *get_segtype_from_string(struct cmd_context *cmd,

View File

@ -25,6 +25,7 @@
#include "lvm-string.h"
#include "targets.h"
#include "activate.h"
#include "libdevmapper-event.h"
enum {
MIRR_DISABLED,
@ -324,7 +325,87 @@ static int _target_present(void)
return present;
}
#endif
#ifdef DMEVENTD
static int _setup_registration(struct dm_pool *mem, struct config_tree *cft,
char **dso)
{
/* FIXME Follow lvm2 searching rules (see sharedlib.c) */
/* FIXME Use naming convention in config file */
if (!(*dso = find_config_str(cft->root, "global/mirror_dso", NULL))) {
log_error("No mirror dso specified in config file"); /* FIXME readability */
return 0;
}
return 1;
}
/* FIXME This gets run while suspended and performs banned operations. */
static int _target_register(struct dm_pool *mem, struct lv_segment *seg,
struct config_tree *cft, int events)
{
char *dso;
char dm_name[PATH_MAX];
struct logical_volume *lv;
struct volume_group *vg;
int err;
lv = seg->lv;
vg = lv->vg;
if (!_setup_registration(mem, cft, &dso)) {
stack;
return 0;
}
/* FIXME lvm_ error */
strncpy(dm_name, build_dm_name(mem, vg->name, lv->name, NULL),
PATH_MAX);
if((err = dm_event_register(dso, dm_name, ALL_ERRORS)) < 0) {
log_error("Unable to register %s for events: %s", dm_name,
strerror(-err));
return 0;
}
log_info("Registered %s for events", dm_name);
return 1;
}
static int _target_unregister(struct dm_pool *mem, struct lv_segment *seg,
struct config_tree *cft, int events)
{
char *dso;
char devpath[PATH_MAX];
struct logical_volume *lv;
struct volume_group *vg;
int err;
lv = seg->lv;
vg = lv->vg;
if(!_setup_registration(mem, cft, &dso)) {
stack;
return 0;
}
/* FIXME lvm_ error */
strncpy(devpath, build_dm_name(mem, vg->name, lv->name, NULL),
PATH_MAX);
/* FIXME put MIR_DSO into config file */
if((err = dm_event_unregister(dso, devpath, DM_EVENT_ALL_ERRORS)) < 0) {
log_error("Unable to unregister %s for events: %s", devpath, strerror(-err));
return 0;
}
log_info("Unregistered %s for events", devpath);
return 1;
}
#endif /* DMEVENTD */
#endif /* DEVMAPPER_SUPPORT */
static void _destroy(const struct segment_type *segtype)
{
@ -341,6 +422,10 @@ static struct segtype_handler _mirrored_ops = {
add_target_line:_add_target_line,
target_percent:_target_percent,
target_present:_target_present,
#endif
#ifdef DMEVENTD
target_register:_target_register,
target_unregister:_target_unregister,
#endif
destroy:_destroy,
};

View File

@ -43,8 +43,8 @@ The values are:
Display the mapping of logical extents to physical volumes and
physical extents.
.SH Examples
"lvdisplay -v /dev/vg00/lvol2" shows attributes of that logical volume
and its mapping of logical to physical extents. In case snapshot
"lvdisplay -v /dev/vg00/lvol2" shows attributes of that logical volume.
If snapshot
logical volumes have been created for this original logical volume,
this command shows a list of all snapshot logical volumes and their
status (active or inactive) as well.

View File

@ -91,6 +91,10 @@ ifeq ("@DEVMAPPER@", "yes")
LVMLIBS += -ldevmapper
endif
ifeq ("@DMEVENTD@", "yes")
LVMLIBS += -ldevmapper-event
endif
CFLAGS += -DLVM_SHARED_PATH=\"$(exec_prefix)/sbin/lvm\"
include $(top_srcdir)/make.tmpl