aboutsummaryrefslogtreecommitdiffstats
path: root/fs/inotify.c
diff options
context:
space:
mode:
authorAmy Griffis <amy.griffis@hp.com>2006-06-01 16:11:03 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2006-06-20 05:25:18 -0400
commita9dc971d3fdb857a2bcd6d53238125a2cd31d5f4 (patch)
tree02e8816f583b5ca40da5789ab9e8d7de9b3ed598 /fs/inotify.c
parent7c29772288b7026504cfe75bfd90d40fbd1574bf (diff)
[PATCH] inotify (3/5): add interfaces to kernel API
Add inotify_init_watch() so caller can use inotify_watch refcounts before calling inotify_add_watch(). Add inotify_find_watch() to find an existing watch for an (ih,inode) pair. This is similar to inotify_find_update_watch(), but does not update the watch's mask if one is found. Add inotify_rm_watch() to remove a watch via the watch pointer instead of the watch descriptor. Signed-off-by: Amy Griffis <amy.griffis@hp.com> Acked-by: Robert Love <rml@novell.com> Acked-by: John McCutchan <john@johnmccutchan.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/inotify.c')
-rw-r--r--fs/inotify.c64
1 files changed, 58 insertions, 6 deletions
diff --git a/fs/inotify.c b/fs/inotify.c
index f25c21801fdc..8477c4fbecb4 100644
--- a/fs/inotify.c
+++ b/fs/inotify.c
@@ -468,6 +468,19 @@ struct inotify_handle *inotify_init(const struct inotify_operations *ops)
468EXPORT_SYMBOL_GPL(inotify_init); 468EXPORT_SYMBOL_GPL(inotify_init);
469 469
470/** 470/**
471 * inotify_init_watch - initialize an inotify watch
472 * @watch: watch to initialize
473 */
474void inotify_init_watch(struct inotify_watch *watch)
475{
476 INIT_LIST_HEAD(&watch->h_list);
477 INIT_LIST_HEAD(&watch->i_list);
478 atomic_set(&watch->count, 0);
479 get_inotify_watch(watch); /* initial get */
480}
481EXPORT_SYMBOL_GPL(inotify_init_watch);
482
483/**
471 * inotify_destroy - clean up and destroy an inotify instance 484 * inotify_destroy - clean up and destroy an inotify instance
472 * @ih: inotify handle 485 * @ih: inotify handle
473 */ 486 */
@@ -515,6 +528,37 @@ void inotify_destroy(struct inotify_handle *ih)
515EXPORT_SYMBOL_GPL(inotify_destroy); 528EXPORT_SYMBOL_GPL(inotify_destroy);
516 529
517/** 530/**
531 * inotify_find_watch - find an existing watch for an (ih,inode) pair
532 * @ih: inotify handle
533 * @inode: inode to watch
534 * @watchp: pointer to existing inotify_watch
535 *
536 * Caller must pin given inode (via nameidata).
537 */
538s32 inotify_find_watch(struct inotify_handle *ih, struct inode *inode,
539 struct inotify_watch **watchp)
540{
541 struct inotify_watch *old;
542 int ret = -ENOENT;
543
544 mutex_lock(&inode->inotify_mutex);
545 mutex_lock(&ih->mutex);
546
547 old = inode_find_handle(inode, ih);
548 if (unlikely(old)) {
549 get_inotify_watch(old); /* caller must put watch */
550 *watchp = old;
551 ret = old->wd;
552 }
553
554 mutex_unlock(&ih->mutex);
555 mutex_unlock(&inode->inotify_mutex);
556
557 return ret;
558}
559EXPORT_SYMBOL_GPL(inotify_find_watch);
560
561/**
518 * inotify_find_update_watch - find and update the mask of an existing watch 562 * inotify_find_update_watch - find and update the mask of an existing watch
519 * @ih: inotify handle 563 * @ih: inotify handle
520 * @inode: inode's watch to update 564 * @inode: inode's watch to update
@@ -593,10 +637,6 @@ s32 inotify_add_watch(struct inotify_handle *ih, struct inotify_watch *watch,
593 goto out; 637 goto out;
594 ret = watch->wd; 638 ret = watch->wd;
595 639
596 atomic_set(&watch->count, 0);
597 INIT_LIST_HEAD(&watch->h_list);
598 INIT_LIST_HEAD(&watch->i_list);
599
600 /* save a reference to handle and bump the count to make it official */ 640 /* save a reference to handle and bump the count to make it official */
601 get_inotify_handle(ih); 641 get_inotify_handle(ih);
602 watch->ih = ih; 642 watch->ih = ih;
@@ -607,8 +647,6 @@ s32 inotify_add_watch(struct inotify_handle *ih, struct inotify_watch *watch,
607 */ 647 */
608 watch->inode = igrab(inode); 648 watch->inode = igrab(inode);
609 649
610 get_inotify_watch(watch); /* initial get */
611
612 if (!inotify_inode_watched(inode)) 650 if (!inotify_inode_watched(inode))
613 set_dentry_child_flags(inode, 1); 651 set_dentry_child_flags(inode, 1);
614 652
@@ -659,6 +697,20 @@ int inotify_rm_wd(struct inotify_handle *ih, u32 wd)
659} 697}
660EXPORT_SYMBOL_GPL(inotify_rm_wd); 698EXPORT_SYMBOL_GPL(inotify_rm_wd);
661 699
700/**
701 * inotify_rm_watch - remove a watch from an inotify instance
702 * @ih: inotify handle
703 * @watch: watch to remove
704 *
705 * Can sleep.
706 */
707int inotify_rm_watch(struct inotify_handle *ih,
708 struct inotify_watch *watch)
709{
710 return inotify_rm_wd(ih, watch->wd);
711}
712EXPORT_SYMBOL_GPL(inotify_rm_watch);
713
662/* 714/*
663 * inotify_setup - core initialization function 715 * inotify_setup - core initialization function
664 */ 716 */