dquot: cleanup dquot drop routine
[safe/jmp/linux-2.6] / fs / ocfs2 / inode.c
index 4a88bce..00eb6a0 100644 (file)
@@ -53,6 +53,7 @@
 #include "sysfile.h"
 #include "uptodate.h"
 #include "xattr.h"
+#include "refcounttree.h"
 
 #include "buffer_head_io.h"
 
@@ -113,6 +114,17 @@ void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
                oi->ip_attr |= OCFS2_DIRSYNC_FL;
 }
 
+struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
+{
+       struct ocfs2_find_inode_args args;
+
+       args.fi_blkno = blkno;
+       args.fi_flags = 0;
+       args.fi_ino = ino_from_blkno(sb, blkno);
+       args.fi_sysfile_type = 0;
+
+       return ilookup5(sb, blkno, ocfs2_find_actor, &args);
+}
 struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
                         int sysfile_type)
 {
@@ -204,6 +216,8 @@ bail:
 static int ocfs2_init_locked_inode(struct inode *inode, void *opaque)
 {
        struct ocfs2_find_inode_args *args = opaque;
+       static struct lock_class_key ocfs2_quota_ip_alloc_sem_key,
+                                    ocfs2_file_ip_alloc_sem_key;
 
        mlog_entry("inode = %p, opaque = %p\n", inode, opaque);
 
@@ -212,6 +226,15 @@ static int ocfs2_init_locked_inode(struct inode *inode, void *opaque)
        if (args->fi_sysfile_type != 0)
                lockdep_set_class(&inode->i_mutex,
                        &ocfs2_sysfile_lock_key[args->fi_sysfile_type]);
+       if (args->fi_sysfile_type == USER_QUOTA_SYSTEM_INODE ||
+           args->fi_sysfile_type == GROUP_QUOTA_SYSTEM_INODE ||
+           args->fi_sysfile_type == LOCAL_USER_QUOTA_SYSTEM_INODE ||
+           args->fi_sysfile_type == LOCAL_GROUP_QUOTA_SYSTEM_INODE)
+               lockdep_set_class(&OCFS2_I(inode)->ip_alloc_sem,
+                                 &ocfs2_quota_ip_alloc_sem_key);
+       else
+               lockdep_set_class(&OCFS2_I(inode)->ip_alloc_sem,
+                                 &ocfs2_file_ip_alloc_sem_key);
 
        mlog_exit(0);
        return 0;
@@ -452,7 +475,7 @@ static int ocfs2_read_locked_inode(struct inode *inode,
        if (args->fi_flags & OCFS2_FI_FLAG_ORPHAN_RECOVERY) {
                status = ocfs2_try_open_lock(inode, 0);
                if (status) {
-                       make_bad_inode(inode);  
+                       make_bad_inode(inode);
                        return status;
                }
        }
@@ -540,7 +563,8 @@ static int ocfs2_truncate_for_delete(struct ocfs2_super *osb,
                        goto out;
                }
 
-               status = ocfs2_journal_access_di(handle, inode, fe_bh,
+               status = ocfs2_journal_access_di(handle, INODE_CACHE(inode),
+                                                fe_bh,
                                                 OCFS2_JOURNAL_ACCESS_WRITE);
                if (status < 0) {
                        mlog_errno(status);
@@ -624,7 +648,7 @@ static int ocfs2_remove_inode(struct inode *inode,
        }
 
        /* set the inodes dtime */
-       status = ocfs2_journal_access_di(handle, inode, di_bh,
+       status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
                                         OCFS2_JOURNAL_ACCESS_WRITE);
        if (status < 0) {
                mlog_errno(status);
@@ -640,8 +664,8 @@ static int ocfs2_remove_inode(struct inode *inode,
                goto bail_commit;
        }
 
-       ocfs2_remove_from_cache(inode, di_bh);
-       vfs_dq_free_inode(inode);
+       ocfs2_remove_from_cache(INODE_CACHE(inode), di_bh);
+       dquot_free_inode(inode);
 
        status = ocfs2_free_dinode(handle, inode_alloc_inode,
                                   inode_alloc_bh, di);
@@ -660,7 +684,7 @@ bail:
        return status;
 }
 
-/* 
+/*
  * Serialize with orphan dir recovery. If the process doing
  * recovery on this orphan dir does an iget() with the dir
  * i_mutex held, we'll deadlock here. Instead we detect this
@@ -759,6 +783,12 @@ static int ocfs2_wipe_inode(struct inode *inode,
                goto bail_unlock_dir;
        }
 
+       status = ocfs2_remove_refcount_tree(inode, di_bh);
+       if (status < 0) {
+               mlog_errno(status);
+               goto bail_unlock_dir;
+       }
+
        status = ocfs2_remove_inode(inode, di_bh, orphan_dir_inode,
                                    orphan_dir_bh);
        if (status < 0)
@@ -961,6 +991,17 @@ void ocfs2_delete_inode(struct inode *inode)
                goto bail;
        }
 
+       /*
+        * Synchronize us against ocfs2_get_dentry. We take this in
+        * shared mode so that all nodes can still concurrently
+        * process deletes.
+        */
+       status = ocfs2_nfs_sync_lock(OCFS2_SB(inode->i_sb), 0);
+       if (status < 0) {
+               mlog(ML_ERROR, "getting nfs sync lock(PR) failed %d\n", status);
+               ocfs2_cleanup_delete_inode(inode, 0);
+               goto bail_unblock;
+       }
        /* Lock down the inode. This gives us an up to date view of
         * it's metadata (for verification), and allows us to
         * serialize delete_inode on multiple nodes.
@@ -974,7 +1015,7 @@ void ocfs2_delete_inode(struct inode *inode)
                if (status != -ENOENT)
                        mlog_errno(status);
                ocfs2_cleanup_delete_inode(inode, 0);
-               goto bail_unblock;
+               goto bail_unlock_nfs_sync;
        }
 
        /* Query the cluster. This will be the final decision made
@@ -1017,6 +1058,10 @@ void ocfs2_delete_inode(struct inode *inode)
 bail_unlock_inode:
        ocfs2_inode_unlock(inode, 1);
        brelse(di_bh);
+
+bail_unlock_nfs_sync:
+       ocfs2_nfs_sync_unlock(OCFS2_SB(inode->i_sb), 0);
+
 bail_unblock:
        status = sigprocmask(SIG_SETMASK, &oldset, NULL);
        if (status < 0)
@@ -1042,6 +1087,8 @@ void ocfs2_clear_inode(struct inode *inode)
        mlog_bug_on_msg(OCFS2_SB(inode->i_sb) == NULL,
                        "Inode=%lu\n", inode->i_ino);
 
+       dquot_drop(inode);
+
        /* To preven remote deletes we hold open lock before, now it
         * is time to unlock PR and EX open locks. */
        ocfs2_open_unlock(inode);
@@ -1075,13 +1122,14 @@ void ocfs2_clear_inode(struct inode *inode)
        ocfs2_lock_res_free(&oi->ip_inode_lockres);
        ocfs2_lock_res_free(&oi->ip_open_lockres);
 
-       ocfs2_metadata_cache_purge(inode);
+       ocfs2_metadata_cache_exit(INODE_CACHE(inode));
 
-       mlog_bug_on_msg(oi->ip_metadata_cache.ci_num_cached,
+       mlog_bug_on_msg(INODE_CACHE(inode)->ci_num_cached,
                        "Clear inode of %llu, inode has %u cache items\n",
-                       (unsigned long long)oi->ip_blkno, oi->ip_metadata_cache.ci_num_cached);
+                       (unsigned long long)oi->ip_blkno,
+                       INODE_CACHE(inode)->ci_num_cached);
 
-       mlog_bug_on_msg(!(oi->ip_flags & OCFS2_INODE_CACHE_INLINE),
+       mlog_bug_on_msg(!(INODE_CACHE(inode)->ci_flags & OCFS2_CACHE_FL_INLINE),
                        "Clear inode of %llu, inode has a bad flag\n",
                        (unsigned long long)oi->ip_blkno);
 
@@ -1108,9 +1156,7 @@ void ocfs2_clear_inode(struct inode *inode)
                        (unsigned long long)oi->ip_blkno, oi->ip_open_count);
 
        /* Clear all other flags. */
-       oi->ip_flags = OCFS2_INODE_CACHE_INLINE;
-       oi->ip_created_trans = 0;
-       oi->ip_last_trans = 0;
+       oi->ip_flags = 0;
        oi->ip_dir_start_lookup = 0;
        oi->ip_blkno = 0ULL;
 
@@ -1202,7 +1248,7 @@ int ocfs2_mark_inode_dirty(handle_t *handle,
        mlog_entry("(inode %llu)\n",
                   (unsigned long long)OCFS2_I(inode)->ip_blkno);
 
-       status = ocfs2_journal_access_di(handle, inode, bh,
+       status = ocfs2_journal_access_di(handle, INODE_CACHE(inode), bh,
                                         OCFS2_JOURNAL_ACCESS_WRITE);
        if (status < 0) {
                mlog_errno(status);
@@ -1343,8 +1389,8 @@ int ocfs2_read_inode_block_full(struct inode *inode, struct buffer_head **bh,
        int rc;
        struct buffer_head *tmp = *bh;
 
-       rc = ocfs2_read_blocks(inode, OCFS2_I(inode)->ip_blkno, 1, &tmp,
-                              flags, ocfs2_validate_inode_block);
+       rc = ocfs2_read_blocks(INODE_CACHE(inode), OCFS2_I(inode)->ip_blkno,
+                              1, &tmp, flags, ocfs2_validate_inode_block);
 
        /* If ocfs2_read_blocks() got us a new bh, pass it up. */
        if (!rc && !*bh)
@@ -1357,3 +1403,56 @@ int ocfs2_read_inode_block(struct inode *inode, struct buffer_head **bh)
 {
        return ocfs2_read_inode_block_full(inode, bh, 0);
 }
+
+
+static u64 ocfs2_inode_cache_owner(struct ocfs2_caching_info *ci)
+{
+       struct ocfs2_inode_info *oi = cache_info_to_inode(ci);
+
+       return oi->ip_blkno;
+}
+
+static struct super_block *ocfs2_inode_cache_get_super(struct ocfs2_caching_info *ci)
+{
+       struct ocfs2_inode_info *oi = cache_info_to_inode(ci);
+
+       return oi->vfs_inode.i_sb;
+}
+
+static void ocfs2_inode_cache_lock(struct ocfs2_caching_info *ci)
+{
+       struct ocfs2_inode_info *oi = cache_info_to_inode(ci);
+
+       spin_lock(&oi->ip_lock);
+}
+
+static void ocfs2_inode_cache_unlock(struct ocfs2_caching_info *ci)
+{
+       struct ocfs2_inode_info *oi = cache_info_to_inode(ci);
+
+       spin_unlock(&oi->ip_lock);
+}
+
+static void ocfs2_inode_cache_io_lock(struct ocfs2_caching_info *ci)
+{
+       struct ocfs2_inode_info *oi = cache_info_to_inode(ci);
+
+       mutex_lock(&oi->ip_io_mutex);
+}
+
+static void ocfs2_inode_cache_io_unlock(struct ocfs2_caching_info *ci)
+{
+       struct ocfs2_inode_info *oi = cache_info_to_inode(ci);
+
+       mutex_unlock(&oi->ip_io_mutex);
+}
+
+const struct ocfs2_caching_operations ocfs2_inode_caching_ops = {
+       .co_owner               = ocfs2_inode_cache_owner,
+       .co_get_super           = ocfs2_inode_cache_get_super,
+       .co_cache_lock          = ocfs2_inode_cache_lock,
+       .co_cache_unlock        = ocfs2_inode_cache_unlock,
+       .co_io_lock             = ocfs2_inode_cache_io_lock,
+       .co_io_unlock           = ocfs2_inode_cache_io_unlock,
+};
+