Date: Mon, 2 Aug 2010 08:39:29 GMT From: Ilya Putsikau <ilya@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 181710 for review Message-ID: <201008020839.o728dTKV042127@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@181710?ac=10 Change 181710 by ilya@ilya_triton on 2010/08/02 08:39:17 Add linux source code compatability. Tested with inotify-tools port and misc examples. Use kernel unit number allocator for watch descriptors Affected files ... .. //depot/projects/soc2010/ilya_fsnotify/src/sys/kern/vfs_notify.c#9 edit .. //depot/projects/soc2010/ilya_fsnotify/src/sys/sys/fsnotify.h#7 edit .. //depot/projects/soc2010/ilya_fsnotify/src/sys/sys/inotify.h#1 add Differences ... ==== //depot/projects/soc2010/ilya_fsnotify/src/sys/kern/vfs_notify.c#9 (text+ko) ==== @@ -40,6 +40,7 @@ #include <sys/hash.h> #include <sys/kernel.h> #include <sys/kthread.h> +#include <sys/limits.h> #include <sys/lock.h> #include <sys/malloc.h> #include <sys/module.h> @@ -124,6 +125,7 @@ TAILQ_HEAD_INITIALIZER(fsnotify_queue); static struct mtx fsnotify_queue_mtx; static struct proc *fsnotify_proc; +static struct unrhdr *fsnotify_wds; static struct fnnode_hashhead *fnnode_inohashtbl; static struct mtx fnnode_hashmtx; @@ -233,6 +235,7 @@ mtx_init(&fsnotify_queue_mtx, "fsnotify_queue", NULL, MTX_DEF); mtx_init(&fnnode_hashmtx, "fsnotify_hash", NULL, MTX_DEF); + fsnotify_wds = new_unrhdr(1, INT_MAX, NULL); error = kproc_create(fsnotify_daemon, NULL, &fsnotify_proc, RFHIGHPID, 0, "fsnotify"); @@ -291,6 +294,7 @@ } } free(fnnode_inohashtbl, M_FSNOTIFYHASH); + delete_unrhdr(fsnotify_wds); mtx_destroy(&fsnotify_queue_mtx); mtx_destroy(&fnnode_hashmtx); break; @@ -769,23 +773,6 @@ event_enqueue(tdirnode, ap->a_tcnp, &cookie, FN_RENAME_TO); } -static int -watch_nextwd(void) -{ - static volatile int wd = 1; - int nwd; - -again: - nwd = atomic_fetchadd_int(&wd, 1); - - if (nwd <= 0) { - if (atomic_cmpset_int(&wd, nwd, 1) == 0) - goto again; - } - - return (nwd); -} - static void watch_detachnode(struct fnwatch *watch) { @@ -823,6 +810,7 @@ TAILQ_REMOVE(&ss->ss_watchlist, watch, wt_sessionentry); watch->wt_session = NULL; + free_unr(fsnotify_wds, watch->wt_wd); TAILQ_FOREACH(eh, &ss->ss_queue, eh_queueentry) { MPASS(eh->eh_watch != watch); @@ -1137,8 +1125,7 @@ if (name != NULL) { MPASS((node->nd_flags & NODE_ISDIR) != 0); memcpy(event->ev_pathfree + event->ev_pathpos, name, namelen); - } else - MPASS((node->nd_flags & NODE_ISDIR) == 0); + } printf("event alloc: %p\n", event); return (event); @@ -1282,7 +1269,7 @@ watch = malloc(sizeof(struct fnwatch), M_FSNOTIFY, M_WAITOK | M_ZERO); printf("watch alloc: %p\n", watch); - watch->wt_wd = watch_nextwd(); + watch->wt_wd = alloc_unr(fsnotify_wds); watch->wt_mask = mask; watch->wt_session = ss; watch->wt_node = node; @@ -1292,8 +1279,8 @@ if (w->wt_node != node) continue; if ((w->wt_mask & mask) == mask) { + watch_free(watch); SESSION_UNLOCK(ss); - watch_free(watch); return (EEXIST); } break; ==== //depot/projects/soc2010/ilya_fsnotify/src/sys/sys/fsnotify.h#7 (text+ko) ==== @@ -58,6 +58,8 @@ /* Extra flags */ #define FN_CLOSEFD 0x01000000 +#define FN_INVALID 0x80000000 + #define FN_FLAGS_INTERNAL FN_CLOSEFD /* Ioctls */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008020839.o728dTKV042127>