2
* Copyright (C) 2003-2004 Sistina Software, Inc. All rights reserved.
3
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
2
* Copyright (C) 2003-2004 Sistina Software, Inc. All rights reserved.
3
* Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
5
5
* This file is part of LVM2.
7
7
* This copyrighted material is made available to anyone wishing to use,
8
8
* modify, copy, or redistribute it subject to the terms and conditions
9
* of the GNU General Public License v.2.
9
* of the GNU Lesser General Public License v.2.1.
11
* You should have received a copy of the GNU General Public License
11
* You should have received a copy of the GNU Lesser General Public License
12
12
* along with this program; if not, write to the Free Software Foundation,
13
13
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
126
129
return _snap_present;
133
static int _get_snapshot_dso_path(struct cmd_context *cmd, char **dso)
138
if (!(path = dm_pool_alloc(cmd->mem, PATH_MAX))) {
139
log_error("Failed to allocate dmeventd library path.");
143
libpath = find_config_tree_str(cmd, "dmeventd/snapshot_library", NULL);
147
get_shared_library_path(cmd, libpath, path, PATH_MAX);
154
static struct dm_event_handler *_create_dm_event_handler(const char *dmname,
157
enum dm_event_mask mask)
159
struct dm_event_handler *dmevh;
161
if (!(dmevh = dm_event_handler_create()))
164
if (dm_event_handler_set_dso(dmevh, dso))
167
if (dm_event_handler_set_dev_name(dmevh, dmname))
170
dm_event_handler_set_timeout(dmevh, timeout);
171
dm_event_handler_set_event_mask(dmevh, mask);
175
dm_event_handler_destroy(dmevh);
179
static int _target_registered(struct lv_segment *seg, int *pending)
182
struct logical_volume *lv;
183
struct volume_group *vg;
184
enum dm_event_mask evmask = 0;
185
struct dm_event_handler *dmevh;
191
if (!_get_snapshot_dso_path(vg->cmd, &dso))
194
if (!(name = build_dm_name(vg->cmd->mem, vg->name, seg->cow->name, NULL)))
197
if (!(dmevh = _create_dm_event_handler(name, dso, 0, DM_EVENT_ALL_ERRORS)))
200
if (dm_event_get_registered_device(dmevh, 0)) {
201
dm_event_handler_destroy(dmevh);
205
evmask = dm_event_handler_get_event_mask(dmevh);
206
if (evmask & DM_EVENT_REGISTRATION_PENDING) {
208
evmask &= ~DM_EVENT_REGISTRATION_PENDING;
211
dm_event_handler_destroy(dmevh);
216
/* FIXME This gets run while suspended and performs banned operations. */
217
static int _target_set_events(struct lv_segment *seg,
218
int events __attribute((unused)), int set)
221
struct volume_group *vg = seg->lv->vg;
222
struct dm_event_handler *dmevh;
225
if (!_get_snapshot_dso_path(vg->cmd, &dso))
228
if (!(name = build_dm_name(vg->cmd->mem, vg->name, seg->cow->name, NULL)))
231
/* FIXME: make timeout configurable */
232
if (!(dmevh = _create_dm_event_handler(name, dso, 10,
233
DM_EVENT_ALL_ERRORS|DM_EVENT_TIMEOUT)))
236
r = set ? dm_event_register_handler(dmevh) : dm_event_unregister_handler(dmevh);
237
dm_event_handler_destroy(dmevh);
241
log_info("%s %s for events", set ? "Registered" : "Unregistered", name);
246
static int _target_register_events(struct lv_segment *seg,
249
return _target_set_events(seg, events, 1);
252
static int _target_unregister_events(struct lv_segment *seg,
255
return _target_set_events(seg, events, 0);
258
#endif /* DMEVENTD */
130
261
static int _snap_modules_needed(struct dm_pool *mem,
131
const struct lv_segment *seg,
262
const struct lv_segment *seg __attribute((unused)),
132
263
struct list *modules)
134
265
if (!str_list_add(mem, modules, "snapshot")) {