01 Aug, 2006

1 commit

  • This is a real deadlock, a nice complex one:
    (warning: long explanation follows so that Andrew can have a complete
    patch description)

    it's an ABCDA deadlock:

    A iprune_mutex
    B inode->inotify_mutex
    C ih->mutex
    D dev->ev_mutex

    The AB relationship comes straight from invalidate_inodes()

    int invalidate_inodes(struct super_block * sb)
    {
    int busy;
    LIST_HEAD(throw_away);

    mutex_lock(&iprune_mutex);
    spin_lock(&inode_lock);
    inotify_unmount_inodes(&sb->s_inodes);

    where inotify_umount_inodes() takes the
    mutex_lock(&inode->inotify_mutex);

    The BC relationship comes directly from inotify_find_update_watch():
    s32 inotify_find_update_watch(struct inotify_handle *ih, struct inode *inode,
    u32 mask)
    {
    ...
    mutex_lock(&inode->inotify_mutex);
    mutex_lock(&ih->mutex);

    The CD relationship comes from inotify_rm_wd:
    inotify_rm_wd does
    mutex_lock(&inode->inotify_mutex);
    mutex_lock(&ih->mutex)
    and then calls inotify_remove_watch_locked() which calls
    notify_dev_queue_event() which does
    mutex_lock(&dev->ev_mutex);

    (this strictly is a BCD relationship)

    The DA relationship comes from the most interesting part:

    [] shrink_icache_memory+0x42/0x270
    [] shrink_slab+0x11d/0x1c9
    [] try_to_free_pages+0x187/0x244
    [] __alloc_pages+0x1cd/0x2e0
    [] cache_alloc_refill+0x3f8/0x821
    [] kmem_cache_alloc+0x85/0xcb
    [] kernel_event+0x2e/0x122
    [] inotify_dev_queue_event+0xcc/0x140

    inotify_dev_queue_event schedules a kernel_event which does a
    kmem_cache_alloc( , GFP_KERNEL) which may try to shrink slabs, including
    the inode cache .. which then takes iprune_mutex.

    And voila, there is an AB, a BC, a CD relationship (even a direct BCD),
    and also now a DA relationship -> a circular type AB-BA deadlock but
    involving 4 locks.

    The solution is simple: kernel_event() is NOT allowed to use GFP_KERNEL,
    but must use GFP_NOFS to not cause recursion into the VFS.

    Signed-off-by: Arjan van de Ven
    Acked-by: Ingo Molnar
    Acked-by: Robert Love
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arjan van de Ven
     

23 Jun, 2006

1 commit

  • Extend the get_sb() filesystem operation to take an extra argument that
    permits the VFS to pass in the target vfsmount that defines the mountpoint.

    The filesystem is then required to manually set the superblock and root dentry
    pointers. For most filesystems, this should be done with simple_set_mnt()
    which will set the superblock pointer and then set the root dentry to the
    superblock's s_root (as per the old default behaviour).

    The get_sb() op now returns an integer as there's now no need to return the
    superblock pointer.

    This patch permits a superblock to be implicitly shared amongst several mount
    points, such as can be done with NFS to avoid potential inode aliasing. In
    such a case, simple_set_mnt() would not be called, and instead the mnt_root
    and mnt_sb would be set directly.

    The patch also makes the following changes:

    (*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
    pointer argument and return an integer, so most filesystems have to change
    very little.

    (*) If one of the convenience function is not used, then get_sb() should
    normally call simple_set_mnt() to instantiate the vfsmount. This will
    always return 0, and so can be tail-called from get_sb().

    (*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
    dcache upon superblock destruction rather than shrink_dcache_anon().

    This is required because the superblock may now have multiple trees that
    aren't actually bound to s_root, but that still need to be cleaned up. The
    currently called functions assume that the whole tree is rooted at s_root,
    and that anonymous dentries are not the roots of trees which results in
    dentries being left unculled.

    However, with the way NFS superblock sharing are currently set to be
    implemented, these assumptions are violated: the root of the filesystem is
    simply a dummy dentry and inode (the real inode for '/' may well be
    inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
    with child trees.

    [*] Anonymous until discovered from another tree.

    (*) The documentation has been adjusted, including the additional bit of
    changing ext2_* into foo_* in the documentation.

    [akpm@osdl.org: convert ipath_fs, do other stuff]
    Signed-off-by: David Howells
    Acked-by: Al Viro
    Cc: Nathan Scott
    Cc: Roland Dreier
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Howells
     

20 Jun, 2006

3 commits

  • 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
    Acked-by: Robert Love
    Acked-by: John McCutchan
    Signed-off-by: Al Viro

    Amy Griffis
     
  • When an inotify event includes a dentry name, also include the inode
    associated with that name.

    Signed-off-by: Amy Griffis
    Acked-by: Robert Love
    Acked-by: John McCutchan
    Signed-off-by: Al Viro

    Amy Griffis
     
  • The following series of patches introduces a kernel API for inotify,
    making it possible for kernel modules to benefit from inotify's
    mechanism for watching inodes. With these patches, inotify will
    maintain for each caller a list of watches (via an embedded struct
    inotify_watch), where each inotify_watch is associated with a
    corresponding struct inode. The caller registers an event handler and
    specifies for which filesystem events their event handler should be
    called per inotify_watch.

    Signed-off-by: Amy Griffis
    Acked-by: Robert Love
    Acked-by: John McCutchan
    Signed-off-by: Al Viro

    Amy Griffis