From owner-p4-projects@FreeBSD.ORG Mon Aug 2 08:39:29 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C1E57106568A; Mon, 2 Aug 2010 08:39:29 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 67E8C1065687 for ; Mon, 2 Aug 2010 08:39:29 +0000 (UTC) (envelope-from ilya@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 4C4CF8FC18 for ; Mon, 2 Aug 2010 08:39:29 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.4/8.14.4) with ESMTP id o728dTMv042129 for ; Mon, 2 Aug 2010 08:39:29 GMT (envelope-from ilya@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.4/8.14.4/Submit) id o728dTKV042127 for perforce@freebsd.org; Mon, 2 Aug 2010 08:39:29 GMT (envelope-from ilya@FreeBSD.org) Date: Mon, 2 Aug 2010 08:39:29 GMT Message-Id: <201008020839.o728dTKV042127@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ilya@FreeBSD.org using -f From: Ilya Putsikau To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 181710 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Aug 2010 08:39:30 -0000 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 #include #include +#include #include #include #include @@ -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 */