summaryrefslogtreecommitdiff
path: root/source4/ntvfs/sysdep
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-04-05 05:54:10 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:00:17 -0500
commit416d7b421001d00c4d494fceb4f2d0ab3e30cfaf (patch)
tree5551bf9f5e19d758417dff28b6b80fea16ad7b0c /source4/ntvfs/sysdep
parentbacf1152fc711560ed141fa8e6e470cbd9de6efc (diff)
downloadsamba-416d7b421001d00c4d494fceb4f2d0ab3e30cfaf.tar.gz
samba-416d7b421001d00c4d494fceb4f2d0ab3e30cfaf.tar.bz2
samba-416d7b421001d00c4d494fceb4f2d0ab3e30cfaf.zip
r14920: allow a notify backend to separately specify if it has handled the
given mask for the current directory and sub-directories. This allows us to setup the less efficient internal handling for subdirectories, while using the kernel inotify service for the current directory if available. It also allows inotify to handle only some of the filter bits, leaving the other filter bits for the user space handler. (This used to be commit 7c3d989fa44c7f57853a825337159f476d7dff80)
Diffstat (limited to 'source4/ntvfs/sysdep')
-rw-r--r--source4/ntvfs/sysdep/inotify.c22
-rw-r--r--source4/ntvfs/sysdep/sys_notify.c38
-rw-r--r--source4/ntvfs/sysdep/sys_notify.h21
3 files changed, 48 insertions, 33 deletions
diff --git a/source4/ntvfs/sysdep/inotify.c b/source4/ntvfs/sysdep/inotify.c
index ec8669306e..c95c39ff01 100644
--- a/source4/ntvfs/sysdep/inotify.c
+++ b/source4/ntvfs/sysdep/inotify.c
@@ -190,13 +190,15 @@ static NTSTATUS inotify_setup(struct sys_notify_context *ctx)
/*
- map from a change notify mask to a inotify mask. Approximate only :(
+ map from a change notify mask to a inotify mask. Remove any bits
+ which we can handle
*/
static const struct {
uint32_t notify_mask;
uint32_t inotify_mask;
} inotify_mapping[] = {
{FILE_NOTIFY_CHANGE_FILE_NAME, IN_CREATE|IN_DELETE|IN_MOVED_FROM|IN_MOVED_TO},
+ {FILE_NOTIFY_CHANGE_DIR_NAME, IN_CREATE|IN_DELETE|IN_MOVED_FROM|IN_MOVED_TO},
{FILE_NOTIFY_CHANGE_ATTRIBUTES, IN_ATTRIB},
{FILE_NOTIFY_CHANGE_SIZE, IN_MODIFY},
{FILE_NOTIFY_CHANGE_LAST_WRITE, IN_ATTRIB},
@@ -204,13 +206,14 @@ static const struct {
{FILE_NOTIFY_CHANGE_SECURITY, IN_ATTRIB}
};
-static uint32_t inotify_map(uint32_t mask)
+static uint32_t inotify_map(struct notify_entry *e)
{
int i;
uint32_t out=0;
for (i=0;i<ARRAY_SIZE(inotify_mapping);i++) {
- if (inotify_mapping[i].notify_mask & mask) {
+ if (inotify_mapping[i].notify_mask & e->filter) {
out |= inotify_mapping[i].inotify_mask;
+ e->filter &= ~inotify_mapping[i].notify_mask;
}
}
return out;
@@ -241,14 +244,15 @@ static int watch_destructor(void *ptr)
add a watch. The watch is removed when the caller calls
talloc_free() on *handle
*/
-static NTSTATUS inotify_watch(struct sys_notify_context *ctx, const char *dirpath,
- uint32_t filter, sys_notify_callback_t callback,
- void *private, void **handle)
+static NTSTATUS inotify_watch(struct sys_notify_context *ctx, struct notify_entry *e,
+ sys_notify_callback_t callback, void *private,
+ void **handle)
{
struct inotify_private *in;
int wd;
uint32_t mask;
struct watch_context *w;
+ uint32_t filter = e->filter;
/* maybe setup the inotify fd */
if (ctx->private == NULL) {
@@ -259,7 +263,7 @@ static NTSTATUS inotify_watch(struct sys_notify_context *ctx, const char *dirpat
in = talloc_get_type(ctx->private, struct inotify_private);
- mask = inotify_map(filter);
+ mask = inotify_map(e);
if (mask == 0) {
/* this filter can't be handled by inotify */
return NT_STATUS_INVALID_PARAMETER;
@@ -270,14 +274,16 @@ static NTSTATUS inotify_watch(struct sys_notify_context *ctx, const char *dirpat
mask |= (IN_MASK_ADD | IN_ONLYDIR);
/* get a new watch descriptor for this path */
- wd = inotify_add_watch(in->fd, dirpath, mask);
+ wd = inotify_add_watch(in->fd, e->path, mask);
if (wd == -1) {
+ e->filter = filter;
return map_nt_error_from_unix(errno);
}
w = talloc(in, struct watch_context);
if (w == NULL) {
inotify_rm_watch(in->fd, wd);
+ e->filter = filter;
return NT_STATUS_NO_MEMORY;
}
diff --git a/source4/ntvfs/sysdep/sys_notify.c b/source4/ntvfs/sysdep/sys_notify.c
index 1927ac61ce..1be57dd55a 100644
--- a/source4/ntvfs/sysdep/sys_notify.c
+++ b/source4/ntvfs/sysdep/sys_notify.c
@@ -31,7 +31,7 @@
/* list of registered backends */
static struct sys_notify_backend *backends;
-
+static uint32_t num_backends;
/*
initialise a system change notify backend
@@ -43,8 +43,9 @@ struct sys_notify_context *sys_notify_init(int snum,
struct sys_notify_context *ctx;
const char *bname;
struct sys_notify_backend *b;
+ int i;
- if (backends == NULL) {
+ if (num_backends == 0) {
return NULL;
}
@@ -61,16 +62,16 @@ struct sys_notify_context *sys_notify_init(int snum,
bname = lp_parm_string(snum, "notify", "backend");
if (!bname) {
- if (backends) {
- bname = backends->name;
+ if (num_backends) {
+ bname = backends[0].name;
} else {
bname = "__unknown__";
}
}
- for (b=backends;b;b=b->next) {
- if (strcasecmp(b->name, bname) == 0) {
- bname = b->name;
+ for (i=0;i<num_backends;i++) {
+ if (strcasecmp(backends[i].name, bname) == 0) {
+ bname = backends[i].name;
break;
}
}
@@ -78,8 +79,8 @@ struct sys_notify_context *sys_notify_init(int snum,
ctx->name = bname;
ctx->notify_watch = NULL;
- if (b != NULL) {
- ctx->notify_watch = b->notify_watch;
+ if (i < num_backends) {
+ ctx->notify_watch = backends[i].notify_watch;
}
return ctx;
@@ -87,15 +88,18 @@ struct sys_notify_context *sys_notify_init(int snum,
/*
add a watch
+
+ note that this call must modify the e->filter and e->subdir_filter
+ bits to remove ones handled by this backend. Any remaining bits will
+ be handled by the generic notify layer
*/
-NTSTATUS sys_notify_watch(struct sys_notify_context *ctx, const char *dirpath,
- uint32_t filter, sys_notify_callback_t callback,
- void *private, void **handle)
+NTSTATUS sys_notify_watch(struct sys_notify_context *ctx, struct notify_entry *e,
+ sys_notify_callback_t callback, void *private, void **handle)
{
if (!ctx->notify_watch) {
return NT_STATUS_NOT_IMPLEMENTED;
}
- return ctx->notify_watch(ctx, dirpath, filter, callback, private, handle);
+ return ctx->notify_watch(ctx, e, callback, private, handle);
}
/*
@@ -103,6 +107,12 @@ NTSTATUS sys_notify_watch(struct sys_notify_context *ctx, const char *dirpath,
*/
NTSTATUS sys_notify_register(struct sys_notify_backend *backend)
{
- DLIST_ADD(backends, backend);
+ struct sys_notify_backend *b;
+ b = talloc_realloc(talloc_autofree_context(), backends,
+ struct sys_notify_backend, num_backends+1);
+ NT_STATUS_HAVE_NO_MEMORY(b);
+ backends = b;
+ backends[num_backends] = *backend;
+ num_backends++;
return NT_STATUS_OK;
}
diff --git a/source4/ntvfs/sysdep/sys_notify.h b/source4/ntvfs/sysdep/sys_notify.h
index 9ad5ed7555..9cb01a1db4 100644
--- a/source4/ntvfs/sysdep/sys_notify.h
+++ b/source4/ntvfs/sysdep/sys_notify.h
@@ -25,28 +25,27 @@ struct sys_notify_context;
typedef void (*sys_notify_callback_t)(struct sys_notify_context *,
void *, struct notify_event *ev);
+typedef NTSTATUS (*notify_watch_t)(struct sys_notify_context *ctx,
+ struct notify_event *e,
+ sys_notify_callback_t callback, void *private,
+ void **handle);
+
struct sys_notify_context {
struct event_context *ev;
void *private; /* for use of backend */
- NTSTATUS (*notify_watch)(struct sys_notify_context *ctx, const char *dirpath,
- uint32_t filter, sys_notify_callback_t callback,
- void *private, void **handle);
const char *name;
+ notify_watch_t notify_watch;
};
struct sys_notify_backend {
- struct sys_notify_backend *next, *prev;
const char *name;
- NTSTATUS (*notify_watch)(struct sys_notify_context *ctx, const char *dirpath,
- uint32_t filter, sys_notify_callback_t callback,
- void *private, void **handle);
+ notify_watch_t notify_watch;
};
NTSTATUS sys_notify_register(struct sys_notify_backend *backend);
struct sys_notify_context *sys_notify_init(int snum,
TALLOC_CTX *mem_ctx,
struct event_context *ev);
-NTSTATUS sys_notify_watch(struct sys_notify_context *ctx, const char *dirpath,
- uint32_t filter, sys_notify_callback_t callback,
- void *private, void **handle);
-
+NTSTATUS sys_notify_watch(struct sys_notify_context *ctx, struct notify_entry *e,
+ sys_notify_callback_t callback, void *private,
+ void **handle);