1 | /*
|
---|
2 | * Unix SMB/CIFS implementation.
|
---|
3 | *
|
---|
4 | * Copyright (C) Volker Lendecke 2014
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 3 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifndef __NOTIFYD_NOTIFYD_H__
|
---|
21 | #define __NOTIFYD_NOTIFYD_H__
|
---|
22 |
|
---|
23 | #include "includes.h"
|
---|
24 | #include "librpc/gen_ndr/notify.h"
|
---|
25 | #include "librpc/gen_ndr/messaging.h"
|
---|
26 | #include "lib/dbwrap/dbwrap.h"
|
---|
27 | #include "lib/dbwrap/dbwrap_rbt.h"
|
---|
28 | #include "messages.h"
|
---|
29 | #include "tdb.h"
|
---|
30 | #include "util_tdb.h"
|
---|
31 |
|
---|
32 | /*
|
---|
33 | * Filechangenotify based on asynchronous messages
|
---|
34 | *
|
---|
35 | * smbds talk to local notify daemons to inform them about paths they are
|
---|
36 | * interested in. They also tell local notify daemons about changes they have
|
---|
37 | * done to the file system. There's two message types from smbd to
|
---|
38 | * notifyd. The first is used to inform notifyd about changes in notify
|
---|
39 | * interest. These are only sent from smbd to notifyd if the SMB client issues
|
---|
40 | * FileChangeNotify requests.
|
---|
41 | */
|
---|
42 |
|
---|
43 | /*
|
---|
44 | * The notifyd implementation is designed to cope with multiple daemons taking
|
---|
45 | * care of just a subset of smbds. The goal is to minimize the traffic between
|
---|
46 | * the notify daemons. The idea behind this is a samba/ctdb cluster, but it
|
---|
47 | * could also be used to spread the load of notifyd instances on a single
|
---|
48 | * node, should this become a bottleneck. The following diagram illustrates
|
---|
49 | * the setup. The numbers in the boxes are node:process ids.
|
---|
50 | *
|
---|
51 | * +-----------+ +-----------+
|
---|
52 | * |notifyd 0:5|------------------|notifyd 1:6|
|
---|
53 | * +-----------+ +-----------+
|
---|
54 | * / | \ / \
|
---|
55 | * / | \ / \
|
---|
56 | * +--------+ | +--------+ +--------+ +--------+
|
---|
57 | * |smbd 0:1| | |smbd 0:4| |smbd 1:7| |smbd 1:2|
|
---|
58 | * +--------+ | +--------+ +--------+ +--------+
|
---|
59 | * |
|
---|
60 | * +---------+
|
---|
61 | * |smbd 0:20|
|
---|
62 | * +---------+
|
---|
63 | *
|
---|
64 | * Suppose 0:1 and 0:4 are interested in changes for /foo and 0:20 creates the
|
---|
65 | * file /foo/bar, if everything fully connected, 0:20 would have to send two
|
---|
66 | * local messages, one to 0:1 and one to 0:4. With the notifyd design, 0:20
|
---|
67 | * only has to send one message, it lets notifyd 0:5 do the hard work to
|
---|
68 | * multicast the change to 0:1 and 0:4.
|
---|
69 | *
|
---|
70 | * Now lets assume 1:7 on the other node creates /foo/baz. It tells its
|
---|
71 | * notifyd 1:6 about this change. All 1:6 will know about is that its peer
|
---|
72 | * notifyd 0:5 is interested in the change. Thus it forwards the event to 0:5,
|
---|
73 | * which sees it as if it came from just another local event creator. 0:5 will
|
---|
74 | * multicast the change to 0:1 and 0:4. To prevent notify loops, the message
|
---|
75 | * from 1:6 to 0:5 will carry a "proxied" flag, so that 0:5 will only forward
|
---|
76 | * the event to local clients.
|
---|
77 | */
|
---|
78 |
|
---|
79 | /*
|
---|
80 | * Data that notifyd maintains per smbd notify instance
|
---|
81 | */
|
---|
82 | struct notify_instance {
|
---|
83 | struct timespec creation_time;
|
---|
84 | uint32_t filter;
|
---|
85 | uint32_t subdir_filter;
|
---|
86 | void *private_data;
|
---|
87 | };
|
---|
88 |
|
---|
89 | /* MSG_SMB_NOTIFY_REC_CHANGE payload */
|
---|
90 | struct notify_rec_change_msg {
|
---|
91 | struct notify_instance instance;
|
---|
92 | char path[];
|
---|
93 | };
|
---|
94 |
|
---|
95 | /*
|
---|
96 | * The second message from smbd to notifyd is sent whenever an smbd makes a
|
---|
97 | * file system change. It tells notifyd to inform all interested parties about
|
---|
98 | * that change. This is the message that needs to be really fast in smbd
|
---|
99 | * because it is called a lot.
|
---|
100 | */
|
---|
101 |
|
---|
102 | /* MSG_SMB_NOTIFY_TRIGGER payload */
|
---|
103 | struct notify_trigger_msg {
|
---|
104 | struct timespec when;
|
---|
105 | uint32_t action;
|
---|
106 | uint32_t filter;
|
---|
107 | char path[];
|
---|
108 | };
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * In response to a MSG_SMB_NOTIFY_TRIGGER message notifyd walks its database
|
---|
112 | * and sends out the following message to all interested clients
|
---|
113 | */
|
---|
114 |
|
---|
115 | /* MSG_PVFS_NOTIFY payload */
|
---|
116 | struct notify_event_msg {
|
---|
117 | struct timespec when;
|
---|
118 | void *private_data;
|
---|
119 | uint32_t action;
|
---|
120 | char path[];
|
---|
121 | };
|
---|
122 |
|
---|
123 | struct sys_notify_context;
|
---|
124 |
|
---|
125 | typedef int (*sys_notify_watch_fn)(TALLOC_CTX *mem_ctx,
|
---|
126 | struct sys_notify_context *ctx,
|
---|
127 | const char *path,
|
---|
128 | uint32_t *filter,
|
---|
129 | uint32_t *subdir_filter,
|
---|
130 | void (*callback)(struct sys_notify_context *ctx,
|
---|
131 | void *private_data,
|
---|
132 | struct notify_event *ev),
|
---|
133 | void *private_data,
|
---|
134 | void *handle_p);
|
---|
135 |
|
---|
136 | struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
|
---|
137 | struct messaging_context *msg_ctx,
|
---|
138 | struct ctdbd_connection *ctdbd_conn,
|
---|
139 | sys_notify_watch_fn sys_notify_watch,
|
---|
140 | struct sys_notify_context *sys_notify_ctx);
|
---|
141 | int notifyd_recv(struct tevent_req *req);
|
---|
142 |
|
---|
143 | /*
|
---|
144 | * Parse a database received via the MSG_SMB_NOTIFY_[GET_]DB messages to the
|
---|
145 | * notify daemon
|
---|
146 | */
|
---|
147 | int notifyd_parse_db(const uint8_t *buf, size_t buflen,
|
---|
148 | uint64_t *log_index,
|
---|
149 | bool (*fn)(const char *path,
|
---|
150 | struct server_id server,
|
---|
151 | const struct notify_instance *instance,
|
---|
152 | void *private_data),
|
---|
153 | void *private_data);
|
---|
154 |
|
---|
155 |
|
---|
156 | #endif
|
---|