Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 146727 Details for
Bug 178979
request for "full snapshot" warnings
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
preview of snapshot monitoring DSO
lvm2-snapshot-dmeventd.patch (text/plain), 17.31 KB, created by
Milan Broz
on 2007-01-26 22:56:41 UTC
(
hide
)
Description:
preview of snapshot monitoring DSO
Filename:
MIME Type:
Creator:
Milan Broz
Created:
2007-01-26 22:56:41 UTC
Size:
17.31 KB
patch
obsolete
>Index: lvm2.up/configure >=================================================================== >--- lvm2.up.orig/configure 2007-01-25 17:15:22.000000000 +0100 >+++ lvm2.up/configure 2007-01-25 17:15:32.000000000 +0100 >@@ -11202,7 +11202,7 @@ fi > > > ################################################################################ >- ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile dmeventd/Makefile dmeventd/mirror/Makefile doc/Makefile include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/snapshot/Makefile man/Makefile po/Makefile scripts/Makefile tools/Makefile tools/version.h tools/fsadm/Makefile test/mm/Makefile test/device/Makefile test/format1/Makefile test/regex/Makefile test/filters/Makefile" >+ ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile dmeventd/Makefile dmeventd/mirror/Makefile dmeventd/snapshot/Makefile doc/Makefile include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/snapshot/Makefile man/Makefile po/Makefile scripts/Makefile tools/Makefile tools/version.h tools/fsadm/Makefile test/mm/Makefile test/device/Makefile test/format1/Makefile test/regex/Makefile test/filters/Makefile" > cat >confcache <<\_ACEOF > # This file is a shell script that caches the results of configure > # tests run on this system so they can be shared between configure >@@ -11734,6 +11734,7 @@ do > "daemons/clvmd/Makefile" ) CONFIG_FILES="$CONFIG_FILES daemons/clvmd/Makefile" ;; > "dmeventd/Makefile" ) CONFIG_FILES="$CONFIG_FILES dmeventd/Makefile" ;; > "dmeventd/mirror/Makefile" ) CONFIG_FILES="$CONFIG_FILES dmeventd/mirror/Makefile" ;; >+ "dmeventd/snapshot/Makefile" ) CONFIG_FILES="$CONFIG_FILES dmeventd/snapshot/Makefile" ;; > "doc/Makefile" ) CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;; > "include/Makefile" ) CONFIG_FILES="$CONFIG_FILES include/Makefile" ;; > "lib/Makefile" ) CONFIG_FILES="$CONFIG_FILES lib/Makefile" ;; >Index: lvm2.up/configure.in >=================================================================== >--- lvm2.up.orig/configure.in 2007-01-25 17:15:22.000000000 +0100 >+++ lvm2.up/configure.in 2007-01-25 17:15:32.000000000 +0100 >@@ -627,6 +627,7 @@ daemons/Makefile \ > daemons/clvmd/Makefile \ > dmeventd/Makefile \ > dmeventd/mirror/Makefile \ >+dmeventd/snapshot/Makefile \ > doc/Makefile \ > include/Makefile \ > lib/Makefile \ >Index: lvm2.up/dmeventd/Makefile.in >=================================================================== >--- lvm2.up.orig/dmeventd/Makefile.in 2007-01-25 17:15:22.000000000 +0100 >+++ lvm2.up/dmeventd/Makefile.in 2007-01-25 17:15:32.000000000 +0100 >@@ -16,7 +16,7 @@ srcdir = @srcdir@ > top_srcdir = @top_srcdir@ > VPATH = @srcdir@ > >-SUBDIRS += mirror >+SUBDIRS += mirror snapshot > > include $(top_srcdir)/make.tmpl > >Index: lvm2.up/lib/metadata/snapshot_manip.c >=================================================================== >--- lvm2.up.orig/lib/metadata/snapshot_manip.c 2007-01-25 17:15:22.000000000 +0100 >+++ lvm2.up/lib/metadata/snapshot_manip.c 2007-01-25 17:15:32.000000000 +0100 >@@ -17,6 +17,8 @@ > #include "metadata.h" > #include "toolcontext.h" > #include "lv_alloc.h" >+#include "activate.h" >+#include "segtype.h" > > int lv_is_origin(const struct logical_volume *lv) > { >@@ -89,7 +91,6 @@ int vg_add_snapshot(struct format_instan > cow->snapshot = seg; > > cow->status &= ~VISIBLE_LV; >- > list_add(&origin->snapshot_segs, &seg->origin_list); > > return 1; >Index: lvm2.up/lib/snapshot/snapshot.c >=================================================================== >--- lvm2.up.orig/lib/snapshot/snapshot.c 2007-01-25 17:15:22.000000000 +0100 >+++ lvm2.up/lib/snapshot/snapshot.c 2007-01-25 17:45:45.000000000 +0100 >@@ -1,6 +1,6 @@ > /* > * Copyright (C) 2003-2004 Sistina Software, Inc. All rights reserved. >- * Copyright (C) 2004 Red Hat, Inc. All rights reserved. >+ * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. > * > * This file is part of LVM2. > * >@@ -21,6 +21,10 @@ > #include "config.h" > #include "activate.h" > #include "str_list.h" >+#ifdef DMEVENTD >+# include "sharedlib.h" >+# include <libdevmapper-event.h> >+#endif > > static const char *_snap_name(const struct lv_segment *seg) > { >@@ -125,6 +129,133 @@ static int _snap_target_present(const st > > return _snap_present; > } >+ >+#ifdef DMEVENTD >+static int _get_snapshot_dso_path(struct cmd_context *cmd, char **dso) >+{ >+ char *path; >+ const char *libpath; >+ >+ if (!(path = dm_pool_alloc(cmd->mem, PATH_MAX))) { >+ log_error("Failed to allocate dmeventd library path."); >+ return 0; >+ } >+ >+ libpath = find_config_tree_str(cmd, "dmeventd/snapshot_library", NULL); >+ if (!libpath) >+ return 0; >+ >+ get_shared_library_path(cmd, libpath, path, PATH_MAX); >+ >+ *dso = path; >+ >+ return 1; >+} >+ >+static struct dm_event_handler *_create_dm_event_handler(const char *dmname, >+ const char *dso, >+ const int timeout, >+ enum dm_event_mask mask) >+{ >+ struct dm_event_handler *dmevh; >+ >+ if (!(dmevh = dm_event_handler_create())) >+ return_0; >+ >+ if (dm_event_handler_set_dso(dmevh, dso)) >+ goto fail; >+ >+ if (dm_event_handler_set_dev_name(dmevh, dmname)) >+ goto fail; >+ >+ dm_event_handler_set_timeout(dmevh, timeout); >+ dm_event_handler_set_event_mask(dmevh, mask); >+ return dmevh; >+ >+fail: >+ dm_event_handler_destroy(dmevh); >+ return NULL; >+} >+ >+static int _target_registered(struct lv_segment *seg, int *pending) >+{ >+ char *dso, *name; >+ struct logical_volume *lv; >+ struct volume_group *vg; >+ enum dm_event_mask evmask = 0; >+ struct dm_event_handler *dmevh; >+ >+ lv = seg->lv; >+ vg = lv->vg; >+ >+ *pending = 0; >+ if (!_get_snapshot_dso_path(vg->cmd, &dso)) >+ return_0; >+ >+ if (!(name = build_dm_name(vg->cmd->mem, vg->name, seg->cow->name, NULL))) >+ return_0; >+ >+ if (!(dmevh = _create_dm_event_handler(name, dso, 0, DM_EVENT_ALL_ERRORS))) >+ return_0; >+ >+ if (dm_event_get_registered_device(dmevh, 0)) { >+ dm_event_handler_destroy(dmevh); >+ return 0; >+ } >+ >+ evmask = dm_event_handler_get_event_mask(dmevh); >+ if (evmask & DM_EVENT_REGISTRATION_PENDING) { >+ *pending = 1; >+ evmask &= ~DM_EVENT_REGISTRATION_PENDING; >+ } >+ >+ dm_event_handler_destroy(dmevh); >+ >+ return evmask; >+} >+ >+/* FIXME This gets run while suspended and performs banned operations. */ >+static int _target_set_events(struct lv_segment *seg, int events, int set) >+{ >+ char *dso, *name; >+ struct volume_group *vg = seg->lv->vg; >+ struct dm_event_handler *dmevh; >+ int r; >+ >+ if (!_get_snapshot_dso_path(vg->cmd, &dso)) >+ return_0; >+ >+ if (!(name = build_dm_name(vg->cmd->mem, vg->name, seg->cow->name, NULL))) >+ return_0; >+ >+ /* FIXME: make timeout configurable */ >+ if (!(dmevh = _create_dm_event_handler(name, dso, 10, >+ DM_EVENT_ALL_ERRORS|DM_EVENT_TIMEOUT))) >+ return_0; >+ >+ r = set ? dm_event_register_handler(dmevh) : dm_event_unregister_handler(dmevh); >+ dm_event_handler_destroy(dmevh); >+ if (!r) >+ return_0; >+ >+ log_info("%s %s for events", set ? "Registered" : "Unregistered", name); >+ >+ return 1; >+} >+ >+static int _target_register_events(struct lv_segment *seg, >+ int events) >+{ >+ return _target_set_events(seg, events, 1); >+} >+ >+static int _target_unregister_events(struct lv_segment *seg, >+ int events) >+{ >+ return _target_set_events(seg, events, 0); >+} >+ >+#endif /* DMEVENTD */ > #endif > > static int _snap_modules_needed(struct dm_pool *mem, >@@ -151,6 +282,11 @@ static struct segtype_handler _snapshot_ > #ifdef DEVMAPPER_SUPPORT > .target_percent = _snap_target_percent, > .target_present = _snap_target_present, >+#ifdef DMEVENTD >+ .target_monitored = _target_registered, >+ .target_monitor_events = _target_register_events, >+ .target_unmonitor_events = _target_unregister_events, >+#endif > #endif > .modules_needed = _snap_modules_needed, > .destroy = _snap_destroy, >@@ -164,6 +300,7 @@ struct segment_type *init_segtype(struct > #endif > { > struct segment_type *segtype = dm_malloc(sizeof(*segtype)); >+ char *dso; > > if (!segtype) { > stack; >@@ -176,6 +313,11 @@ struct segment_type *init_segtype(struct > segtype->private = NULL; > segtype->flags = SEG_SNAPSHOT; > >+/* FIXME: SEG_MONITORED must depend on lvm.conf setting of dmeventd library */ >+#ifdef DMEVENTD >+ if (_get_snapshot_dso_path(cmd, &dso)) >+ segtype->flags |= SEG_MONITORED; >+#endif > log_very_verbose("Initialised segtype: %s", segtype->name); > > return segtype; >Index: lvm2.up/dmeventd/snapshot/dmeventd_snapshot.c >=================================================================== >--- /dev/null 1970-01-01 00:00:00.000000000 +0000 >+++ lvm2.up/dmeventd/snapshot/dmeventd_snapshot.c 2007-01-25 17:15:32.000000000 +0100 >@@ -0,0 +1,206 @@ >+/* >+ * Copyright (C) 2007 Red Hat, Inc. All rights reserved. >+ * >+ * This file is part of LVM2. >+ * >+ * This copyrighted material is made available to anyone wishing to use, >+ * modify, copy, or redistribute it subject to the terms and conditions >+ * of the GNU Lesser General Public License v.2.1. >+ * >+ * You should have received a copy of the GNU Lesser General Public License >+ * along with this program; if not, write to the Free Software Foundation, >+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA >+ */ >+ >+#include "libdevmapper.h" >+#include "libdevmapper-event.h" >+#include "lvm2cmd.h" >+#include "lvm-string.h" >+ >+#include <errno.h> >+#include <signal.h> >+#include <string.h> >+#include <stdio.h> >+#include <stdlib.h> >+#include <pthread.h> >+#include <unistd.h> >+ >+#include <syslog.h> /* FIXME Replace syslog with multilog */ >+/* FIXME Missing openlog? */ >+ >+static pthread_mutex_t _register_mutex = PTHREAD_MUTEX_INITIALIZER; >+ >+/* >+ * Number of active registrations. >+ */ >+static int _register_count = 0; >+ >+static struct dm_pool *_mem_pool = NULL; >+static void *_lvm_handle = NULL; >+ >+struct snap_status { >+ int invalid; >+ int f; >+ int f_max; >+ >+}; >+ >+/* >+ * Currently only one event can be processed at a time. >+ */ >+static pthread_mutex_t _event_mutex = PTHREAD_MUTEX_INITIALIZER; >+ >+static void _temporary_log_fn(int level, const char *file, >+ int line, const char *format) >+{ >+ if (!strncmp(format, "WARNING: ", 9) && (level < 5)) >+ syslog(LOG_CRIT, "%s", format); >+ else >+ syslog(LOG_DEBUG, "%s", format); >+} >+ >+static void _parse_snapshot_params(char *params, struct snap_status *stat) >+{ >+ char *p; >+ /* xx/xx -- fractions used/max >+ * Invalid -- snapshot invalidated >+ * Unknown -- status unknown >+ */ >+ stat->f = stat->f_max = 0; >+ >+ if (!strncmp(params, "Invalid", 7)) { >+ stat->invalid = 1; >+ return; >+ } >+ >+ if (!strncmp(params, "Unknown", 7)) >+ return; >+ >+ if (!(p = strstr(params, "/"))) >+ return; >+ >+ *p = '\0'; p++; >+ stat->f = atoi(params); >+ stat->f_max = atoi(p); >+} >+ >+/* send unregister command to itself */ >+static void _unregister_itself(struct dm_task *dmt) >+{ >+ const char *name = dm_task_get_name(dmt); >+ struct dm_event_handler *dmevh; >+ >+ if (!(dmevh = dm_event_handler_create())) >+ return; >+ >+ if (dm_event_handler_set_dev_name(dmevh, name)) >+ goto fail; >+ >+ dm_event_handler_set_event_mask(dmevh, DM_EVENT_ALL_ERRORS|DM_EVENT_TIMEOUT); >+ dm_event_unregister_handler(dmevh); >+fail: >+ dm_event_handler_destroy(dmevh); >+} >+ >+void process_event(struct dm_task *dmt, enum dm_event_mask event, >+ void **private) >+{ >+ void *next = NULL; >+ uint64_t start, length; >+ char *target_type = NULL; >+ char *params; >+ struct snap_status stat = {0}; >+ const char *device = dm_task_get_name(dmt); >+ int p, *pwarning = (int*)private; >+ >+ /* No longer monitoring, waiting for remove */ >+ if (!*pwarning) >+ return; >+ >+ if (pthread_mutex_trylock(&_event_mutex)) { >+ syslog(LOG_NOTICE, "Another thread is handling an event. Waiting..."); >+ pthread_mutex_lock(&_event_mutex); >+ } >+ >+ dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms); >+ if (!target_type) >+ goto out; >+ >+ _parse_snapshot_params(params, &stat); >+ if (stat.invalid || !stat.f_max) { >+ syslog(LOG_ERR, "Snapshot %s changed state to: %s\n", device, params); >+ _unregister_itself(dmt); >+ *pwarning = 0; >+ goto out; >+ } >+ >+ p = 100 * stat.f / stat.f_max; >+ if (p >= *pwarning) { >+ syslog(LOG_WARNING, "Snapshot %s is now %i%% full.\n", device, p); >+ *pwarning = (p / 5) * 5 + 5; >+ } >+out: >+ pthread_mutex_unlock(&_event_mutex); >+} >+ >+int register_device(const char *device, const char *uuid, int major, int minor, >+ void **private) >+{ >+ int r = 0; >+ int *pwarning = (int*)private; >+ >+ pthread_mutex_lock(&_register_mutex); >+ >+ /* >+ * Need some space for allocations. 1024 should be more >+ * than enough for what we need (device mapper name splitting) >+ */ >+ if (!_mem_pool && !(_mem_pool = dm_pool_create("snapshot_dso", 1024))) >+ goto out; >+ >+ /* FIXME: make this configurable */ >+ *pwarning = 80; /* Print warning if snapshot is full */ >+ >+ if (!_lvm_handle) { >+ lvm2_log_fn(_temporary_log_fn); >+ if (!(_lvm_handle = lvm2_init())) { >+ dm_pool_destroy(_mem_pool); >+ _mem_pool = NULL; >+ goto out; >+ } >+ lvm2_log_level(_lvm_handle, LVM2_LOG_SUPPRESS); >+ /* FIXME Temporary: move to dmeventd core */ >+ lvm2_run(_lvm_handle, "_memlock_inc"); >+ } >+ >+ syslog(LOG_INFO, "Monitoring snapshot %s\n", device); >+ >+ _register_count++; >+ r = 1; >+ >+out: >+ pthread_mutex_unlock(&_register_mutex); >+ >+ return r; >+} >+ >+int unregister_device(const char *device, const char *uuid, int major, int minor, >+ void **unused __attribute((unused))) >+{ >+ pthread_mutex_lock(&_register_mutex); >+ >+ syslog(LOG_INFO, "No longer monitoring snapshot %s\n", >+ device); >+ >+ if (!--_register_count) { >+ dm_pool_destroy(_mem_pool); >+ _mem_pool = NULL; >+ lvm2_run(_lvm_handle, "_memlock_dec"); >+ lvm2_exit(_lvm_handle); >+ _lvm_handle = NULL; >+ } >+ >+ pthread_mutex_unlock(&_register_mutex); >+ >+ return 1; >+} >Index: lvm2.up/dmeventd/snapshot/Makefile.in >=================================================================== >--- /dev/null 1970-01-01 00:00:00.000000000 +0000 >+++ lvm2.up/dmeventd/snapshot/Makefile.in 2007-01-25 17:15:32.000000000 +0100 >@@ -0,0 +1,36 @@ >+# >+# Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. >+# Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. >+# >+# This file is part of the LVM2. >+# >+# This copyrighted material is made available to anyone wishing to use, >+# modify, copy, or redistribute it subject to the terms and conditions >+# of the GNU General Public License v.2. >+# >+# You should have received a copy of the GNU General Public License >+# along with this program; if not, write to the Free Software Foundation, >+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA >+ >+srcdir = @srcdir@ >+top_srcdir = @top_srcdir@ >+VPATH = @srcdir@ >+ >+INCLUDES += -I${top_srcdir}/tools >+CLDFLAGS += -L${top_srcdir}/tools -ldevmapper -llvm2cmd >+ >+SOURCES = dmeventd_snapshot.c >+ >+ifeq ("@LIB_SUFFIX@","dylib") >+ LIB_SHARED = libdevmapper-event-lvm2snapshot.dylib >+else >+ LIB_SHARED = libdevmapper-event-lvm2snapshot.so >+endif >+ >+include $(top_srcdir)/make.tmpl >+ >+install: libdevmapper-event-lvm2snapshot.$(LIB_SUFFIX) >+ $(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \ >+ $(libdir)/$<.$(LIB_VERSION) >+ $(LN_S) -f $<.$(LIB_VERSION) $(libdir)/$< >+ >Index: lvm2.up/tools/lvremove.c >=================================================================== >--- lvm2.up.orig/tools/lvremove.c 2007-01-25 17:15:22.000000000 +0100 >+++ lvm2.up/tools/lvremove.c 2007-01-25 17:15:32.000000000 +0100 >@@ -85,6 +85,12 @@ static int lvremove_single(struct cmd_co > } > } > >+/* FIXME: ugly hack, cannot call in vg_remove_snapshot, because it is deactivated already */ >+#ifdef DMEVENTD >+ if (lv_is_cow(lv)) >+ monitor_dev_for_events(cmd, lv->snapshot->lv, 0); >+#endif >+ > /* FIXME Snapshot commit out of sequence if it fails after here? */ > if (!deactivate_lv(cmd, lv)) { > log_error("Unable to deactivate logical volume \"%s\"", >Index: lvm2.up/tools/lvcreate.c >=================================================================== >--- lvm2.up.orig/tools/lvcreate.c 2007-01-25 17:15:22.000000000 +0100 >+++ lvm2.up/tools/lvcreate.c 2007-01-25 17:15:32.000000000 +0100 >@@ -826,6 +826,10 @@ static int _lvcreate(struct cmd_context > log_error("Problem reactivating origin %s", org->name); > return 0; > } >+/* FIXME: this is ugly hack */ >+#ifdef DMEVENTD >+ monitor_dev_for_events(cmd, lv->snapshot->lv, 1); >+#endif > } > /* FIXME out of sequence */ > backup(vg); >Index: lvm2.up/tools/lvconvert.c >=================================================================== >--- lvm2.up.orig/tools/lvconvert.c 2007-01-10 15:13:46.000000000 +0100 >+++ lvm2.up/tools/lvconvert.c 2007-01-25 17:15:32.000000000 +0100 >@@ -487,6 +487,11 @@ static int lvconvert_snapshot(struct cmd > > log_print("Logical volume %s converted to snapshot.", lv->name); > >+/* FIXME: this is ugly hack */ >+#ifdef DMEVENTD >+ monitor_dev_for_events(cmd, lv->snapshot->lv, 1); >+#endif >+ > return 1; > } > >Index: lvm2.up/dmeventd/snapshot/.exported_symbols >=================================================================== >--- /dev/null 1970-01-01 00:00:00.000000000 +0000 >+++ lvm2.up/dmeventd/snapshot/.exported_symbols 2007-01-25 17:48:08.000000000 +0100 >@@ -0,0 +1,3 @@ >+process_event >+register_device >+unregister_device
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 178979
:
146727
|
282811