2 * Copyright (C) 2008 Red Hat, Inc., Eric Paris <eparis@redhat.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/list.h>
23 #include <linux/mount.h>
24 #include <linux/mutex.h>
25 #include <linux/namei.h>
26 #include <linux/path.h>
27 #include <linux/slab.h>
28 #include <linux/spinlock.h>
30 #include <asm/atomic.h>
32 #include <linux/fsnotify_backend.h>
35 static struct kmem_cache *fsnotify_event_cachep;
37 void fsnotify_get_event(struct fsnotify_event *event)
39 atomic_inc(&event->refcnt);
42 void fsnotify_put_event(struct fsnotify_event *event)
47 if (atomic_dec_and_test(&event->refcnt)) {
48 if (event->data_type == FSNOTIFY_EVENT_PATH)
49 path_put(&event->path);
51 kmem_cache_free(fsnotify_event_cachep, event);
56 * Allocate a new event which will be sent to each group's handle_event function
57 * if the group was interested in this particular event.
59 struct fsnotify_event *fsnotify_create_event(struct inode *to_tell, __u32 mask,
60 void *data, int data_type)
62 struct fsnotify_event *event;
64 event = kmem_cache_alloc(fsnotify_event_cachep, GFP_KERNEL);
68 atomic_set(&event->refcnt, 1);
70 spin_lock_init(&event->lock);
72 event->path.dentry = NULL;
73 event->path.mnt = NULL;
76 event->to_tell = to_tell;
79 case FSNOTIFY_EVENT_FILE: {
80 struct file *file = data;
81 struct path *path = &file->f_path;
82 event->path.dentry = path->dentry;
83 event->path.mnt = path->mnt;
84 path_get(&event->path);
85 event->data_type = FSNOTIFY_EVENT_PATH;
88 case FSNOTIFY_EVENT_PATH: {
89 struct path *path = data;
90 event->path.dentry = path->dentry;
91 event->path.mnt = path->mnt;
92 path_get(&event->path);
93 event->data_type = FSNOTIFY_EVENT_PATH;
96 case FSNOTIFY_EVENT_INODE:
98 event->data_type = FSNOTIFY_EVENT_INODE;
100 case FSNOTIFY_EVENT_NONE:
102 event->path.dentry = NULL;
103 event->path.mnt = NULL;
114 __init int fsnotify_notification_init(void)
116 fsnotify_event_cachep = KMEM_CACHE(fsnotify_event, SLAB_PANIC);
120 subsys_initcall(fsnotify_notification_init);