import source from lvm2 2.02.79
[external/device-mapper.git] / daemons / dmeventd / libdevmapper-event.h
1 /*
2  * Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
3  *
4  * This file is part of the device-mapper userspace tools.
5  *
6  * This copyrighted material is made available to anyone wishing to use,
7  * modify, copy, or redistribute it subject to the terms and conditions
8  * of the GNU Lesser General Public License v.2.1.
9  *
10  * You should have received a copy of the GNU Lesser General Public License
11  * along with this program; if not, write to the Free Software Foundation,
12  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
13  */
14
15 /*
16  * Note that this file is released only as part of a technology preview
17  * and its contents may change in future updates in ways that do not
18  * preserve compatibility.
19  */
20
21 #ifndef LIB_DMEVENT_H
22 #define LIB_DMEVENT_H
23
24 #include <stdint.h>
25
26 /*
27  * Event library interface.
28  */
29
30 enum dm_event_mask {
31         DM_EVENT_SETTINGS_MASK  = 0x0000FF,
32         DM_EVENT_SINGLE         = 0x000001, /* Report multiple errors just once. */
33         DM_EVENT_MULTI          = 0x000002, /* Report all of them. */
34
35         DM_EVENT_ERROR_MASK     = 0x00FF00,
36         DM_EVENT_SECTOR_ERROR   = 0x000100, /* Failure on a particular sector. */
37         DM_EVENT_DEVICE_ERROR   = 0x000200, /* Device failure. */
38         DM_EVENT_PATH_ERROR     = 0x000400, /* Failure on an io path. */
39         DM_EVENT_ADAPTOR_ERROR  = 0x000800, /* Failure of a host adaptor. */
40
41         DM_EVENT_STATUS_MASK    = 0xFF0000,
42         DM_EVENT_SYNC_STATUS    = 0x010000, /* Mirror synchronization completed/failed. */
43         DM_EVENT_TIMEOUT        = 0x020000, /* Timeout has occured */
44
45         DM_EVENT_REGISTRATION_PENDING = 0x1000000, /* Monitor thread is setting-up/shutting-down */
46 };
47
48 #define DM_EVENT_ALL_ERRORS DM_EVENT_ERROR_MASK
49
50 struct dm_event_handler;
51
52 struct dm_event_handler *dm_event_handler_create(void);
53 void dm_event_handler_destroy(struct dm_event_handler *dmevh);
54
55 /*
56  * Path of shared library to handle events.
57  *
58  * All of dmeventd, dso, device_name and uuid strings are duplicated so
59  * you do not need to keep the pointers valid after the call succeeds.
60  * They may return -ENOMEM though.
61  */
62 int dm_event_handler_set_dso(struct dm_event_handler *dmevh, const char *path);
63
64 /*
65  * Path of dmeventd binary.
66  */
67 int dm_event_handler_set_dmeventd_path(struct dm_event_handler *dmevh, const char *dmeventd_path);
68
69 /*
70  * Identify the device to monitor by exactly one of device_name, uuid or
71  * device number. String arguments are duplicated, see above.
72  */
73 int dm_event_handler_set_dev_name(struct dm_event_handler *dmevh, const char *device_name);
74
75 int dm_event_handler_set_uuid(struct dm_event_handler *dmevh, const char *uuid);
76
77 void dm_event_handler_set_major(struct dm_event_handler *dmevh, int major);
78 void dm_event_handler_set_minor(struct dm_event_handler *dmevh, int minor);
79 void dm_event_handler_set_timeout(struct dm_event_handler *dmevh, int timeout);
80
81 /*
82  * Specify mask for events to monitor.
83  */
84 void dm_event_handler_set_event_mask(struct dm_event_handler *dmevh,
85                                      enum dm_event_mask evmask);
86
87 const char *dm_event_handler_get_dso(const struct dm_event_handler *dmevh);
88 const char *dm_event_handler_get_dev_name(const struct dm_event_handler *dmevh);
89 const char *dm_event_handler_get_uuid(const struct dm_event_handler *dmevh);
90 int dm_event_handler_get_major(const struct dm_event_handler *dmevh);
91 int dm_event_handler_get_minor(const struct dm_event_handler *dmevh);
92 int dm_event_handler_get_timeout(const struct dm_event_handler *dmevh);
93 enum dm_event_mask dm_event_handler_get_event_mask(const struct dm_event_handler *dmevh);
94
95 /* FIXME Review interface (what about this next thing?) */
96 int dm_event_get_registered_device(struct dm_event_handler *dmevh, int next);
97
98 /*
99  * Initiate monitoring using dmeventd.
100  */
101 int dm_event_register_handler(const struct dm_event_handler *dmevh);
102 int dm_event_unregister_handler(const struct dm_event_handler *dmevh);
103
104 /* Prototypes for DSO interface, see dmeventd.c, struct dso_data for
105    detailed descriptions. */
106 void process_event(struct dm_task *dmt, enum dm_event_mask evmask, void **user);
107 int register_device(const char *device_name, const char *uuid, int major, int minor, void **user);
108 int unregister_device(const char *device_name, const char *uuid, int major,
109                       int minor, void **user);
110
111 #endif