ocfs2: Simplify ocfs2_read_block()
[safe/jmp/linux-2.6] / fs / ocfs2 / inode.c
index 1d5e0cb..c5ee9e3 100644 (file)
@@ -49,7 +49,7 @@
 #include "symlink.h"
 #include "sysfile.h"
 #include "uptodate.h"
-#include "vote.h"
+#include "xattr.h"
 
 #include "buffer_head_io.h"
 
@@ -58,8 +58,11 @@ struct ocfs2_find_inode_args
        u64             fi_blkno;
        unsigned long   fi_ino;
        unsigned int    fi_flags;
+       unsigned int    fi_sysfile_type;
 };
 
+static struct lock_class_key ocfs2_sysfile_lock_key[NUM_SYSTEM_INODES];
+
 static int ocfs2_read_locked_inode(struct inode *inode,
                                   struct ocfs2_find_inode_args *args);
 static int ocfs2_init_locked_inode(struct inode *inode, void *opaque);
@@ -107,7 +110,8 @@ void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
                oi->ip_attr |= OCFS2_DIRSYNC_FL;
 }
 
-struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, int flags)
+struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
+                        int sysfile_type)
 {
        struct inode *inode = NULL;
        struct super_block *sb = osb->sb;
@@ -127,6 +131,7 @@ struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, int flags)
        args.fi_blkno = blkno;
        args.fi_flags = flags;
        args.fi_ino = ino_from_blkno(sb, blkno);
+       args.fi_sysfile_type = sysfile_type;
 
        inode = iget5_locked(sb, args.fi_ino, ocfs2_find_actor,
                             ocfs2_init_locked_inode, &args);
@@ -201,6 +206,9 @@ static int ocfs2_init_locked_inode(struct inode *inode, void *opaque)
 
        inode->i_ino = args->fi_ino;
        OCFS2_I(inode)->ip_blkno = args->fi_blkno;
+       if (args->fi_sysfile_type != 0)
+               lockdep_set_class(&inode->i_mutex,
+                       &ocfs2_sysfile_lock_key[args->fi_sysfile_type]);
 
        mlog_exit(0);
        return 0;
@@ -212,6 +220,7 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
        struct super_block *sb;
        struct ocfs2_super *osb;
        int status = -EINVAL;
+       int use_plocks = 1;
 
        mlog_entry("(0x%p, size:%llu)\n", inode,
                   (unsigned long long)le64_to_cpu(fe->i_size));
@@ -219,6 +228,10 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
        sb = inode->i_sb;
        osb = OCFS2_SB(sb);
 
+       if ((osb->s_mount_opt & OCFS2_MOUNT_LOCALFLOCKS) ||
+           ocfs2_mount_local(osb) || !ocfs2_stack_supports_plocks())
+               use_plocks = 0;
+
        /* this means that read_inode cannot create a superblock inode
         * today.  change if needed. */
        if (!OCFS2_IS_VALID_DINODE(fe) ||
@@ -288,13 +301,19 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
 
        switch (inode->i_mode & S_IFMT) {
            case S_IFREG:
-                   inode->i_fop = &ocfs2_fops;
+                   if (use_plocks)
+                           inode->i_fop = &ocfs2_fops;
+                   else
+                           inode->i_fop = &ocfs2_fops_no_plocks;
                    inode->i_op = &ocfs2_file_iops;
                    i_size_write(inode, le64_to_cpu(fe->i_size));
                    break;
            case S_IFDIR:
                    inode->i_op = &ocfs2_dir_iops;
-                   inode->i_fop = &ocfs2_dops;
+                   if (use_plocks)
+                           inode->i_fop = &ocfs2_dops;
+                   else
+                           inode->i_fop = &ocfs2_dops_no_plocks;
                    i_size_write(inode, le64_to_cpu(fe->i_size));
                    break;
            case S_IFLNK:
@@ -322,7 +341,7 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
                 */
                BUG_ON(le32_to_cpu(fe->i_flags) & OCFS2_SYSTEM_FL);
 
-               ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_meta_lockres,
+               ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_inode_lockres,
                                          OCFS2_LOCK_TYPE_META, 0, inode);
 
                ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_open_lockres,
@@ -333,10 +352,6 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
                                  OCFS2_LOCK_TYPE_RW, inode->i_generation,
                                  inode);
 
-       ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_data_lockres,
-                                 OCFS2_LOCK_TYPE_DATA, inode->i_generation,
-                                 inode);
-
        ocfs2_set_inode_flags(inode);
 
        status = 0;
@@ -414,7 +429,7 @@ static int ocfs2_read_locked_inode(struct inode *inode,
        if (args->fi_flags & OCFS2_FI_FLAG_SYSFILE)
                generation = osb->fs_generation;
 
-       ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_meta_lockres,
+       ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_inode_lockres,
                                  OCFS2_LOCK_TYPE_META,
                                  generation, inode);
 
@@ -429,7 +444,7 @@ static int ocfs2_read_locked_inode(struct inode *inode,
                        mlog_errno(status);
                        return status;
                }
-               status = ocfs2_meta_lock(inode, NULL, 0);
+               status = ocfs2_inode_lock(inode, NULL, 0);
                if (status) {
                        make_bad_inode(inode);
                        mlog_errno(status);
@@ -445,8 +460,10 @@ static int ocfs2_read_locked_inode(struct inode *inode,
                }
        }
 
-       status = ocfs2_read_block(osb, args->fi_blkno, &bh, 0,
-                                 can_lock ? inode : NULL);
+       if (can_lock)
+               status = ocfs2_read_blocks(inode, args->fi_blkno, 1, &bh, 0);
+       else
+               status = ocfs2_read_blocks_sync(osb, args->fi_blkno, 1, &bh);
        if (status < 0) {
                mlog_errno(status);
                goto bail;
@@ -455,8 +472,8 @@ static int ocfs2_read_locked_inode(struct inode *inode,
        status = -EINVAL;
        fe = (struct ocfs2_dinode *) bh->b_data;
        if (!OCFS2_IS_VALID_DINODE(fe)) {
-               mlog(ML_ERROR, "Invalid dinode #%llu: signature = %.*s\n",
-                    (unsigned long long)le64_to_cpu(fe->i_blkno), 7,
+               mlog(0, "Invalid dinode #%llu: signature = %.*s\n",
+                    (unsigned long long)args->fi_blkno, 7,
                     fe->i_signature);
                goto bail;
        }
@@ -484,7 +501,7 @@ static int ocfs2_read_locked_inode(struct inode *inode,
 
 bail:
        if (can_lock)
-               ocfs2_meta_unlock(inode, 0);
+               ocfs2_inode_unlock(inode, 0);
 
        if (status < 0)
                make_bad_inode(inode);
@@ -519,6 +536,9 @@ static int ocfs2_truncate_for_delete(struct ocfs2_super *osb,
         * data and fast symlinks.
         */
        if (fe->i_clusters) {
+               if (ocfs2_should_order_data(inode))
+                       ocfs2_begin_ordered_truncate(inode, 0);
+
                handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
                if (IS_ERR(handle)) {
                        status = PTR_ERR(handle);
@@ -586,7 +606,7 @@ static int ocfs2_remove_inode(struct inode *inode,
        }
 
        mutex_lock(&inode_alloc_inode->i_mutex);
-       status = ocfs2_meta_lock(inode_alloc_inode, &inode_alloc_bh, 1);
+       status = ocfs2_inode_lock(inode_alloc_inode, &inode_alloc_bh, 1);
        if (status < 0) {
                mutex_unlock(&inode_alloc_inode->i_mutex);
 
@@ -617,7 +637,7 @@ static int ocfs2_remove_inode(struct inode *inode,
        }
 
        di->i_dtime = cpu_to_le64(CURRENT_TIME.tv_sec);
-       le32_and_cpu(&di->i_flags, ~(OCFS2_VALID_FL | OCFS2_ORPHANED_FL));
+       di->i_flags &= cpu_to_le32(~(OCFS2_VALID_FL | OCFS2_ORPHANED_FL));
 
        status = ocfs2_journal_dirty(handle, di_bh);
        if (status < 0) {
@@ -635,7 +655,7 @@ static int ocfs2_remove_inode(struct inode *inode,
 bail_commit:
        ocfs2_commit_trans(osb, handle);
 bail_unlock:
-       ocfs2_meta_unlock(inode_alloc_inode, 1);
+       ocfs2_inode_unlock(inode_alloc_inode, 1);
        mutex_unlock(&inode_alloc_inode->i_mutex);
        brelse(inode_alloc_bh);
 bail:
@@ -709,7 +729,7 @@ static int ocfs2_wipe_inode(struct inode *inode,
         * delete_inode operation. We do this now to avoid races with
         * recovery completion on other nodes. */
        mutex_lock(&orphan_dir_inode->i_mutex);
-       status = ocfs2_meta_lock(orphan_dir_inode, &orphan_dir_bh, 1);
+       status = ocfs2_inode_lock(orphan_dir_inode, &orphan_dir_bh, 1);
        if (status < 0) {
                mutex_unlock(&orphan_dir_inode->i_mutex);
 
@@ -718,8 +738,8 @@ static int ocfs2_wipe_inode(struct inode *inode,
        }
 
        /* we do this while holding the orphan dir lock because we
-        * don't want recovery being run from another node to vote for
-        * an inode delete on us -- this will result in two nodes
+        * don't want recovery being run from another node to try an
+        * inode delete underneath us -- this will result in two nodes
         * truncating the same file! */
        status = ocfs2_truncate_for_delete(osb, inode, di_bh);
        if (status < 0) {
@@ -727,13 +747,20 @@ static int ocfs2_wipe_inode(struct inode *inode,
                goto bail_unlock_dir;
        }
 
+       /*Free extended attribute resources associated with this inode.*/
+       status = ocfs2_xattr_remove(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)
                mlog_errno(status);
 
 bail_unlock_dir:
-       ocfs2_meta_unlock(orphan_dir_inode, 1);
+       ocfs2_inode_unlock(orphan_dir_inode, 1);
        mutex_unlock(&orphan_dir_inode->i_mutex);
        brelse(orphan_dir_bh);
 bail:
@@ -744,7 +771,7 @@ bail:
 }
 
 /* There is a series of simple checks that should be done before a
- * vote is even considered. Encapsulate those in this function. */
+ * trylock is even considered. Encapsulate those in this function. */
 static int ocfs2_inode_is_valid_to_delete(struct inode *inode)
 {
        int ret = 0;
@@ -758,14 +785,14 @@ static int ocfs2_inode_is_valid_to_delete(struct inode *inode)
                goto bail;
        }
 
-       /* If we're coming from process_vote we can't go into our own
+       /* If we're coming from downconvert_thread we can't go into our own
         * voting [hello, deadlock city!], so unforuntately we just
         * have to skip deleting this guy. That's OK though because
         * the node who's doing the actual deleting should handle it
         * anyway. */
-       if (current == osb->vote_task) {
+       if (current == osb->dc_task) {
                mlog(0, "Skipping delete of %lu because we're currently "
-                    "in process_vote\n", inode->i_ino);
+                    "in downconvert\n", inode->i_ino);
                goto bail;
        }
 
@@ -779,10 +806,9 @@ static int ocfs2_inode_is_valid_to_delete(struct inode *inode)
                goto bail_unlock;
        }
 
-       /* If we have voted "yes" on the wipe of this inode for
-        * another node, it will be marked here so we can safely skip
-        * it. Recovery will cleanup any inodes we might inadvertantly
-        * skip here. */
+       /* If we have allowd wipe of this inode for another node, it
+        * will be marked here so we can safely skip it. Recovery will
+        * cleanup any inodes we might inadvertantly skip here. */
        if (oi->ip_flags & OCFS2_INODE_SKIP_DELETE) {
                mlog(0, "Skipping delete of %lu because another node "
                     "has done this for us.\n", inode->i_ino);
@@ -863,7 +889,7 @@ static int ocfs2_query_inode_wipe(struct inode *inode,
        status = ocfs2_try_open_lock(inode, 1);
        if (status == -EAGAIN) {
                status = 0;
-               mlog(0, "Skipping delete of %llu because it is in use on"
+               mlog(0, "Skipping delete of %llu because it is in use on "
                     "other nodes\n", (unsigned long long)oi->ip_blkno);
                goto bail;
        }
@@ -929,13 +955,13 @@ void ocfs2_delete_inode(struct inode *inode)
 
        /* 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 votes. 
+        * serialize delete_inode on multiple nodes.
         *
         * Even though we might be doing a truncate, we don't take the
         * allocation lock here as it won't be needed - nobody will
         * have the file open.
         */
-       status = ocfs2_meta_lock(inode, &di_bh, 1);
+       status = ocfs2_inode_lock(inode, &di_bh, 1);
        if (status < 0) {
                if (status != -ENOENT)
                        mlog_errno(status);
@@ -947,15 +973,15 @@ void ocfs2_delete_inode(struct inode *inode)
         * before we go ahead and wipe the inode. */
        status = ocfs2_query_inode_wipe(inode, di_bh, &wipe);
        if (!wipe || status < 0) {
-               /* Error and inode busy vote both mean we won't be
+               /* Error and remote inode busy both mean we won't be
                 * removing the inode, so they take almost the same
                 * path. */
                if (status < 0)
                        mlog_errno(status);
 
-               /* Someone in the cluster has voted to not wipe this
-                * inode, or it was never completely orphaned. Write
-                * out the pages and exit now. */
+               /* Someone in the cluster has disallowed a wipe of
+                * this inode, or it was never completely
+                * orphaned. Write out the pages and exit now. */
                ocfs2_cleanup_delete_inode(inode, 1);
                goto bail_unlock_inode;
        }
@@ -981,7 +1007,7 @@ void ocfs2_delete_inode(struct inode *inode)
        OCFS2_I(inode)->ip_flags |= OCFS2_INODE_DELETED;
 
 bail_unlock_inode:
-       ocfs2_meta_unlock(inode, 1);
+       ocfs2_inode_unlock(inode, 1);
        brelse(di_bh);
 bail_unblock:
        status = sigprocmask(SIG_SETMASK, &oldset, NULL);
@@ -1008,15 +1034,14 @@ void ocfs2_clear_inode(struct inode *inode)
        mlog_bug_on_msg(OCFS2_SB(inode->i_sb) == NULL,
                        "Inode=%lu\n", inode->i_ino);
 
-       /* For remove delete_inode vote, we hold open lock before,
-        * now it is time to unlock PR and EX open locks. */
+       /* To preven remote deletes we hold open lock before, now it
+        * is time to unlock PR and EX open locks. */
        ocfs2_open_unlock(inode);
 
        /* Do these before all the other work so that we don't bounce
-        * the vote thread while waiting to destroy the locks. */
+        * the downconvert thread while waiting to destroy the locks. */
        ocfs2_mark_lockres_freeing(&oi->ip_rw_lockres);
-       ocfs2_mark_lockres_freeing(&oi->ip_meta_lockres);
-       ocfs2_mark_lockres_freeing(&oi->ip_data_lockres);
+       ocfs2_mark_lockres_freeing(&oi->ip_inode_lockres);
        ocfs2_mark_lockres_freeing(&oi->ip_open_lockres);
 
        /* We very well may get a clear_inode before all an inodes
@@ -1039,8 +1064,7 @@ void ocfs2_clear_inode(struct inode *inode)
                mlog_errno(status);
 
        ocfs2_lock_res_free(&oi->ip_rw_lockres);
-       ocfs2_lock_res_free(&oi->ip_meta_lockres);
-       ocfs2_lock_res_free(&oi->ip_data_lockres);
+       ocfs2_lock_res_free(&oi->ip_inode_lockres);
        ocfs2_lock_res_free(&oi->ip_open_lockres);
 
        ocfs2_metadata_cache_purge(inode);
@@ -1081,6 +1105,8 @@ void ocfs2_clear_inode(struct inode *inode)
        oi->ip_last_trans = 0;
        oi->ip_dir_start_lookup = 0;
        oi->ip_blkno = 0ULL;
+       jbd2_journal_release_jbd_inode(OCFS2_SB(inode->i_sb)->journal->j_journal,
+                                      &oi->ip_jinode);
 
 bail:
        mlog_exit_void();
@@ -1139,8 +1165,7 @@ struct buffer_head *ocfs2_bread(struct inode *inode,
                goto fail;
        }
 
-       tmperr = ocfs2_read_block(OCFS2_SB(inode->i_sb), p_blkno, &bh,
-                                 readflags, inode);
+       tmperr = ocfs2_read_blocks(inode, p_blkno, 1, &bh, readflags);
        if (tmperr < 0)
                goto fail;
 
@@ -1150,10 +1175,9 @@ struct buffer_head *ocfs2_bread(struct inode *inode,
        return bh;
 
 fail:
-       if (bh) {
-               brelse(bh);
-               bh = NULL;
-       }
+       brelse(bh);
+       bh = NULL;
+
        *err = -EIO;
        return NULL;
 }
@@ -1184,15 +1208,15 @@ int ocfs2_inode_revalidate(struct dentry *dentry)
        }
        spin_unlock(&OCFS2_I(inode)->ip_lock);
 
-       /* Let ocfs2_meta_lock do the work of updating our struct
+       /* Let ocfs2_inode_lock do the work of updating our struct
         * inode for us. */
-       status = ocfs2_meta_lock(inode, NULL, 0);
+       status = ocfs2_inode_lock(inode, NULL, 0);
        if (status < 0) {
                if (status != -ENOENT)
                        mlog_errno(status);
                goto bail;
        }
-       ocfs2_meta_unlock(inode, 0);
+       ocfs2_inode_unlock(inode, 0);
 bail:
        mlog_exit(status);