fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / ocfs2 / namei.c
index f6b77ff..4766841 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/highmem.h>
+#include <linux/vs_tag.h>
 
 #define MLOG_MASK_PREFIX ML_NAMEI
 #include <cluster/masklog.h>
@@ -56,6 +57,7 @@
 #include "journal.h"
 #include "namei.h"
 #include "suballoc.h"
+#include "super.h"
 #include "symlink.h"
 #include "sysfile.h"
 #include "uptodate.h"
@@ -74,12 +76,12 @@ static int inline ocfs2_search_dirblock(struct buffer_head *bh,
                                        unsigned long offset,
                                        struct ocfs2_dir_entry **res_dir);
 
-static int ocfs2_delete_entry(struct ocfs2_journal_handle *handle,
+static int ocfs2_delete_entry(handle_t *handle,
                              struct inode *dir,
                              struct ocfs2_dir_entry *de_del,
                              struct buffer_head *bh);
 
-static int __ocfs2_add_entry(struct ocfs2_journal_handle *handle,
+static int __ocfs2_add_entry(handle_t *handle,
                             struct inode *dir,
                             const char *name, int namelen,
                             struct inode *inode, u64 blkno,
@@ -92,43 +94,37 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
                              dev_t dev,
                              struct buffer_head **new_fe_bh,
                              struct buffer_head *parent_fe_bh,
-                             struct ocfs2_journal_handle *handle,
+                             handle_t *handle,
                              struct inode **ret_inode,
                              struct ocfs2_alloc_context *inode_ac);
 
 static int ocfs2_fill_new_dir(struct ocfs2_super *osb,
-                             struct ocfs2_journal_handle *handle,
+                             handle_t *handle,
                              struct inode *parent,
                              struct inode *inode,
                              struct buffer_head *fe_bh,
                              struct ocfs2_alloc_context *data_ac);
 
-static int ocfs2_double_lock(struct ocfs2_super *osb,
-                            struct ocfs2_journal_handle *handle,
-                            struct buffer_head **bh1,
-                            struct inode *inode1,
-                            struct buffer_head **bh2,
-                            struct inode *inode2);
-
 static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
-                                   struct ocfs2_journal_handle *handle,
+                                   struct inode **ret_orphan_dir,
                                    struct inode *inode,
                                    char *name,
                                    struct buffer_head **de_bh);
 
 static int ocfs2_orphan_add(struct ocfs2_super *osb,
-                           struct ocfs2_journal_handle *handle,
+                           handle_t *handle,
                            struct inode *inode,
                            struct ocfs2_dinode *fe,
                            char *name,
-                           struct buffer_head *de_bh);
+                           struct buffer_head *de_bh,
+                           struct inode *orphan_dir_inode);
 
 static int ocfs2_create_symlink_data(struct ocfs2_super *osb,
-                                    struct ocfs2_journal_handle *handle,
+                                    handle_t *handle,
                                     struct inode *inode,
                                     const char *symname);
 
-static inline int ocfs2_add_entry(struct ocfs2_journal_handle *handle,
+static inline int ocfs2_add_entry(handle_t *handle,
                                  struct dentry *dentry,
                                  struct inode *inode, u64 blkno,
                                  struct buffer_head *parent_fe_bh,
@@ -161,10 +157,10 @@ static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry,
                goto bail;
        }
 
-       mlog(0, "find name %.*s in directory %"MLFu64"\n", dentry->d_name.len,
-            dentry->d_name.name, OCFS2_I(dir)->ip_blkno);
+       mlog(0, "find name %.*s in directory %llu\n", dentry->d_name.len,
+            dentry->d_name.name, (unsigned long long)OCFS2_I(dir)->ip_blkno);
 
-       status = ocfs2_meta_lock(dir, NULL, NULL, 0);
+       status = ocfs2_meta_lock(dir, NULL, 0);
        if (status < 0) {
                if (status != -ENOENT)
                        mlog_errno(status);
@@ -178,9 +174,10 @@ static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry,
        if (status < 0)
                goto bail_add;
 
-       inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno);
+       inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0);
        if (IS_ERR(inode)) {
-               mlog(ML_ERROR, "Unable to create inode %"MLFu64"\n", blkno);
+               mlog(ML_ERROR, "Unable to create inode %llu\n",
+                    (unsigned long long)blkno);
                ret = ERR_PTR(-EACCES);
                goto bail_unlock;
        }
@@ -197,10 +194,32 @@ static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry,
        spin_unlock(&oi->ip_lock);
 
 bail_add:
-
        dentry->d_op = &ocfs2_dentry_ops;
        ret = d_splice_alias(inode, dentry);
 
+       if (inode) {
+               /*
+                * If d_splice_alias() finds a DCACHE_DISCONNECTED
+                * dentry, it will d_move() it on top of ourse. The
+                * return value will indicate this however, so in
+                * those cases, we switch them around for the locking
+                * code.
+                *
+                * NOTE: This dentry already has ->d_op set from
+                * ocfs2_get_parent() and ocfs2_get_dentry()
+                */
+               if (ret)
+                       dentry = ret;
+
+               status = ocfs2_dentry_attach_lock(dentry, inode,
+                                                 OCFS2_I(dir)->ip_blkno);
+               if (status) {
+                       mlog_errno(status);
+                       ret = ERR_PTR(status);
+                       goto bail_unlock;
+               }
+       }
+
 bail_unlock:
        /* Don't drop the cluster lock until *after* the d_add --
         * unlink on another node will message us to remove that
@@ -218,7 +237,7 @@ bail:
 }
 
 static int ocfs2_fill_new_dir(struct ocfs2_super *osb,
-                             struct ocfs2_journal_handle *handle,
+                             handle_t *handle,
                              struct inode *parent,
                              struct inode *inode,
                              struct buffer_head *fe_bh,
@@ -293,7 +312,7 @@ static int ocfs2_mknod(struct inode *dir,
 {
        int status = 0;
        struct buffer_head *parent_fe_bh = NULL;
-       struct ocfs2_journal_handle *handle = NULL;
+       handle_t *handle = NULL;
        struct ocfs2_super *osb;
        struct ocfs2_dinode *dirfe;
        struct buffer_head *new_fe_bh = NULL;
@@ -309,24 +328,15 @@ static int ocfs2_mknod(struct inode *dir,
        /* get our super block */
        osb = OCFS2_SB(dir->i_sb);
 
-       if (S_ISDIR(mode) && (dir->i_nlink >= OCFS2_LINK_MAX)) {
-               mlog(ML_ERROR, "inode %"MLFu64" has i_nlink of %u\n",
-                    OCFS2_I(dir)->ip_blkno, dir->i_nlink);
-               status = -EMLINK;
-               goto leave;
-       }
-
-       handle = ocfs2_alloc_handle(osb);
-       if (handle == NULL) {
-               status = -ENOMEM;
-               mlog_errno(status);
-               goto leave;
-       }
-
-       status = ocfs2_meta_lock(dir, handle, &parent_fe_bh, 1);
+       status = ocfs2_meta_lock(dir, &parent_fe_bh, 1);
        if (status < 0) {
                if (status != -ENOENT)
                        mlog_errno(status);
+               return status;
+       }
+
+       if (S_ISDIR(mode) && (dir->i_nlink >= OCFS2_LINK_MAX)) {
+               status = -EMLINK;
                goto leave;
        }
 
@@ -352,7 +362,7 @@ static int ocfs2_mknod(struct inode *dir,
        }
 
        /* reserve an inode spot */
-       status = ocfs2_reserve_new_inode(osb, handle, &inode_ac);
+       status = ocfs2_reserve_new_inode(osb, &inode_ac);
        if (status < 0) {
                if (status != -ENOSPC)
                        mlog_errno(status);
@@ -362,7 +372,7 @@ static int ocfs2_mknod(struct inode *dir,
        /* are we making a directory? If so, reserve a cluster for his
         * 1st extent. */
        if (S_ISDIR(mode)) {
-               status = ocfs2_reserve_clusters(osb, handle, 1, &data_ac);
+               status = ocfs2_reserve_clusters(osb, 1, &data_ac);
                if (status < 0) {
                        if (status != -ENOSPC)
                                mlog_errno(status);
@@ -370,7 +380,7 @@ static int ocfs2_mknod(struct inode *dir,
                }
        }
 
-       handle = ocfs2_start_trans(osb, handle, OCFS2_MKNOD_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_MKNOD_CREDITS);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -407,7 +417,7 @@ static int ocfs2_mknod(struct inode *dir,
                        mlog_errno(status);
                        goto leave;
                }
-               dir->i_nlink++;
+               inc_nlink(dir);
        }
 
        status = ocfs2_add_entry(handle, dentry, inode,
@@ -418,13 +428,22 @@ static int ocfs2_mknod(struct inode *dir,
                goto leave;
        }
 
+       status = ocfs2_dentry_attach_lock(dentry, inode,
+                                         OCFS2_I(dir)->ip_blkno);
+       if (status) {
+               mlog_errno(status);
+               goto leave;
+       }
+
        insert_inode_hash(inode);
        dentry->d_op = &ocfs2_dentry_ops;
        d_instantiate(dentry, inode);
        status = 0;
 leave:
        if (handle)
-               ocfs2_commit_trans(handle);
+               ocfs2_commit_trans(osb, handle);
+
+       ocfs2_meta_unlock(dir, 1);
 
        if (status == -ENOSPC)
                mlog(0, "Disk is full\n");
@@ -458,7 +477,7 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
                              dev_t dev,
                              struct buffer_head **new_fe_bh,
                              struct buffer_head *parent_fe_bh,
-                             struct ocfs2_journal_handle *handle,
+                             handle_t *handle,
                              struct inode **ret_inode,
                              struct ocfs2_alloc_context *inode_ac)
 {
@@ -468,6 +487,9 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
        u64 fe_blkno = 0;
        u16 suballoc_bit;
        struct inode *inode = NULL;
+       uid_t uid;
+       gid_t gid;
+       tag_t tag;
 
        mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
                   (unsigned long)dev, dentry->d_name.len,
@@ -527,13 +549,19 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
        fe->i_blkno = cpu_to_le64(fe_blkno);
        fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
        fe->i_suballoc_slot = cpu_to_le16(osb->slot_num);
-       fe->i_uid = cpu_to_le32(current->fsuid);
+
+       tag = dx_current_fstag(osb->sb);
+       uid = current->fsuid;
        if (dir->i_mode & S_ISGID) {
-               fe->i_gid = cpu_to_le32(dir->i_gid);
+               gid = dir->i_gid;
                if (S_ISDIR(mode))
                        mode |= S_ISGID;
        } else
-               fe->i_gid = cpu_to_le32(current->fsgid);
+               gid = current->fsgid;
+
+       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
+       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
+       inode->i_tag = tag;
        fe->i_mode = cpu_to_le16(mode);
        if (S_ISCHR(mode) || S_ISBLK(mode))
                fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
@@ -562,16 +590,18 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
 
        if (ocfs2_populate_inode(inode, fe, 1) < 0) {
                mlog(ML_ERROR, "populate inode failed! bh->b_blocknr=%llu, "
-                    "i_blkno=%"MLFu64", i_ino=%lu\n",
+                    "i_blkno=%llu, i_ino=%lu\n",
                     (unsigned long long) (*new_fe_bh)->b_blocknr,
-                    fe->i_blkno, inode->i_ino);
+                    (unsigned long long)fe->i_blkno, inode->i_ino);
                BUG();
        }
 
        ocfs2_inode_set_new(osb, inode);
-       status = ocfs2_create_new_inode_locks(inode);
-       if (status < 0)
-               mlog_errno(status);
+       if (!ocfs2_mount_local(osb)) {
+               status = ocfs2_create_new_inode_locks(inode);
+               if (status < 0)
+                       mlog_errno(status);
+       }
 
        status = 0; /* error in ocfs2_create_new_inode_locks is not
                     * critical */
@@ -624,7 +654,7 @@ static int ocfs2_link(struct dentry *old_dentry,
                      struct inode *dir,
                      struct dentry *dentry)
 {
-       struct ocfs2_journal_handle *handle = NULL;
+       handle_t *handle;
        struct inode *inode = old_dentry->d_inode;
        int err;
        struct buffer_head *fe_bh = NULL;
@@ -637,71 +667,63 @@ static int ocfs2_link(struct dentry *old_dentry,
                   old_dentry->d_name.len, old_dentry->d_name.name,
                   dentry->d_name.len, dentry->d_name.name);
 
-       if (S_ISDIR(inode->i_mode)) {
-               err = -EPERM;
-               goto bail;
-       }
-
-       if (inode->i_nlink >= OCFS2_LINK_MAX) {
-               err = -EMLINK;
-               goto bail;
-       }
-
-       handle = ocfs2_alloc_handle(osb);
-       if (handle == NULL) {
-               err = -ENOMEM;
-               goto bail;
-       }
+       if (S_ISDIR(inode->i_mode))
+               return -EPERM;
 
-       err = ocfs2_meta_lock(dir, handle, &parent_fe_bh, 1);
+       err = ocfs2_meta_lock(dir, &parent_fe_bh, 1);
        if (err < 0) {
                if (err != -ENOENT)
                        mlog_errno(err);
-               goto bail;
+               return err;
+       }
+
+       if (!dir->i_nlink) {
+               err = -ENOENT;
+               goto out;
        }
 
        err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,
                                        dentry->d_name.len);
        if (err)
-               goto bail;
+               goto out;
 
        err = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh,
                                           dentry->d_name.name,
                                           dentry->d_name.len, &de_bh);
        if (err < 0) {
                mlog_errno(err);
-               goto bail;
+               goto out;
        }
 
-       err = ocfs2_meta_lock(inode, handle, &fe_bh, 1);
+       err = ocfs2_meta_lock(inode, &fe_bh, 1);
        if (err < 0) {
                if (err != -ENOENT)
                        mlog_errno(err);
-               goto bail;
+               goto out;
        }
 
        fe = (struct ocfs2_dinode *) fe_bh->b_data;
        if (le16_to_cpu(fe->i_links_count) >= OCFS2_LINK_MAX) {
                err = -EMLINK;
-               goto bail;
+               goto out_unlock_inode;
        }
 
-       handle = ocfs2_start_trans(osb, handle, OCFS2_LINK_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_LINK_CREDITS);
        if (IS_ERR(handle)) {
                err = PTR_ERR(handle);
                handle = NULL;
                mlog_errno(err);
-               goto bail;
+               goto out_unlock_inode;
        }
 
        err = ocfs2_journal_access(handle, inode, fe_bh,
                                   OCFS2_JOURNAL_ACCESS_WRITE);
        if (err < 0) {
                mlog_errno(err);
-               goto bail;
+               goto out_commit;
        }
 
-       inode->i_nlink++;
+       inc_nlink(inode);
        inode->i_ctime = CURRENT_TIME;
        fe->i_links_count = cpu_to_le16(inode->i_nlink);
        fe->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec);
@@ -710,9 +732,9 @@ static int ocfs2_link(struct dentry *old_dentry,
        err = ocfs2_journal_dirty(handle, fe_bh);
        if (err < 0) {
                le16_add_cpu(&fe->i_links_count, -1);
-               inode->i_nlink--;
+               drop_nlink(inode);
                mlog_errno(err);
-               goto bail;
+               goto out_commit;
        }
 
        err = ocfs2_add_entry(handle, dentry, inode,
@@ -720,17 +742,29 @@ static int ocfs2_link(struct dentry *old_dentry,
                              parent_fe_bh, de_bh);
        if (err) {
                le16_add_cpu(&fe->i_links_count, -1);
-               inode->i_nlink--;
+               drop_nlink(inode);
                mlog_errno(err);
-               goto bail;
+               goto out_commit;
+       }
+
+       err = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(dir)->ip_blkno);
+       if (err) {
+               mlog_errno(err);
+               goto out_commit;
        }
 
        atomic_inc(&inode->i_count);
        dentry->d_op = &ocfs2_dentry_ops;
        d_instantiate(dentry, inode);
-bail:
-       if (handle)
-               ocfs2_commit_trans(handle);
+
+out_commit:
+       ocfs2_commit_trans(osb, handle);
+out_unlock_inode:
+       ocfs2_meta_unlock(inode, 1);
+
+out:
+       ocfs2_meta_unlock(dir, 1);
+
        if (de_bh)
                brelse(de_bh);
        if (fe_bh)
@@ -743,18 +777,49 @@ bail:
        return err;
 }
 
+/*
+ * Takes and drops an exclusive lock on the given dentry. This will
+ * force other nodes to drop it.
+ */
+static int ocfs2_remote_dentry_delete(struct dentry *dentry)
+{
+       int ret;
+
+       ret = ocfs2_dentry_lock(dentry, 1);
+       if (ret)
+               mlog_errno(ret);
+       else
+               ocfs2_dentry_unlock(dentry, 1);
+
+       return ret;
+}
+
+static inline int inode_is_unlinkable(struct inode *inode)
+{
+       if (S_ISDIR(inode->i_mode)) {
+               if (inode->i_nlink == 2)
+                       return 1;
+               return 0;
+       }
+
+       if (inode->i_nlink == 1)
+               return 1;
+       return 0;
+}
+
 static int ocfs2_unlink(struct inode *dir,
                        struct dentry *dentry)
 {
        int status;
-       unsigned int saved_nlink = 0;
+       int child_locked = 0;
        struct inode *inode = dentry->d_inode;
+       struct inode *orphan_dir = NULL;
        struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
        u64 blkno;
        struct ocfs2_dinode *fe = NULL;
        struct buffer_head *fe_bh = NULL;
        struct buffer_head *parent_node_bh = NULL;
-       struct ocfs2_journal_handle *handle = NULL;
+       handle_t *handle = NULL;
        struct ocfs2_dir_entry *dirent = NULL;
        struct buffer_head *dirent_bh = NULL;
        char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
@@ -765,26 +830,18 @@ static int ocfs2_unlink(struct inode *dir,
 
        BUG_ON(dentry->d_parent->d_inode != dir);
 
-       mlog(0, "ino = %"MLFu64"\n", OCFS2_I(inode)->ip_blkno);
+       mlog(0, "ino = %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno);
 
        if (inode == osb->root_inode) {
                mlog(0, "Cannot delete the root directory\n");
-               status = -EPERM;
-               goto leave;
-       }
-
-       handle = ocfs2_alloc_handle(osb);
-       if (handle == NULL) {
-               status = -ENOMEM;
-               mlog_errno(status);
-               goto leave;
+               return -EPERM;
        }
 
-       status = ocfs2_meta_lock(dir, handle, &parent_node_bh, 1);
+       status = ocfs2_meta_lock(dir, &parent_node_bh, 1);
        if (status < 0) {
                if (status != -ENOENT)
                        mlog_errno(status);
-               goto leave;
+               return status;
        }
 
        status = ocfs2_find_files_on_disk(dentry->d_name.name,
@@ -799,18 +856,19 @@ static int ocfs2_unlink(struct inode *dir,
        if (OCFS2_I(inode)->ip_blkno != blkno) {
                status = -ENOENT;
 
-               mlog(0, "ip_blkno (%"MLFu64") != dirent blkno (%"MLFu64") "
-                    "ip_flags = %x\n", OCFS2_I(inode)->ip_blkno, blkno,
-                    OCFS2_I(inode)->ip_flags);
+               mlog(0, "ip_blkno %llu != dirent blkno %llu ip_flags = %x\n",
+                    (unsigned long long)OCFS2_I(inode)->ip_blkno,
+                    (unsigned long long)blkno, OCFS2_I(inode)->ip_flags);
                goto leave;
        }
 
-       status = ocfs2_meta_lock(inode, handle, &fe_bh, 1);
+       status = ocfs2_meta_lock(inode, &fe_bh, 1);
        if (status < 0) {
                if (status != -ENOENT)
                        mlog_errno(status);
                goto leave;
        }
+       child_locked = 1;
 
        if (S_ISDIR(inode->i_mode)) {
                if (!ocfs2_empty_dir(inode)) {
@@ -822,18 +880,7 @@ static int ocfs2_unlink(struct inode *dir,
                }
        }
 
-       /* There are still a few steps left until we can consider the
-        * unlink to have succeeded. Save off nlink here before
-        * modification so we can set it back in case we hit an issue
-        * before commit. */
-       saved_nlink = inode->i_nlink;
-       if (S_ISDIR(inode->i_mode))
-               inode->i_nlink = 0;
-       else
-               inode->i_nlink--;
-
-       status = ocfs2_request_unlink_vote(inode, dentry,
-                                          (unsigned int) inode->i_nlink);
+       status = ocfs2_remote_dentry_delete(dentry);
        if (status < 0) {
                /* This vote should succeed under all normal
                 * circumstances. */
@@ -841,8 +888,8 @@ static int ocfs2_unlink(struct inode *dir,
                goto leave;
        }
 
-       if (!inode->i_nlink) {
-               status = ocfs2_prepare_orphan_dir(osb, handle, inode,
+       if (inode_is_unlinkable(inode)) {
+               status = ocfs2_prepare_orphan_dir(osb, &orphan_dir, inode,
                                                  orphan_name,
                                                  &orphan_entry_bh);
                if (status < 0) {
@@ -851,7 +898,7 @@ static int ocfs2_unlink(struct inode *dir,
                }
        }
 
-       handle = ocfs2_start_trans(osb, handle, OCFS2_UNLINK_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_UNLINK_CREDITS);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -868,9 +915,9 @@ static int ocfs2_unlink(struct inode *dir,
 
        fe = (struct ocfs2_dinode *) fe_bh->b_data;
 
-       if (!inode->i_nlink) {
+       if (inode_is_unlinkable(inode)) {
                status = ocfs2_orphan_add(osb, handle, inode, fe, orphan_name,
-                                         orphan_entry_bh);
+                                         orphan_entry_bh, orphan_dir);
                if (status < 0) {
                        mlog_errno(status);
                        goto leave;
@@ -884,10 +931,10 @@ static int ocfs2_unlink(struct inode *dir,
                goto leave;
        }
 
-       /* We can set nlink on the dinode now. clear the saved version
-        * so that it doesn't get set later. */
+       if (S_ISDIR(inode->i_mode))
+               drop_nlink(inode);
+       drop_nlink(inode);
        fe->i_links_count = cpu_to_le16(inode->i_nlink);
-       saved_nlink = 0;
 
        status = ocfs2_journal_dirty(handle, fe_bh);
        if (status < 0) {
@@ -895,22 +942,32 @@ static int ocfs2_unlink(struct inode *dir,
                goto leave;
        }
 
-       if (S_ISDIR(inode->i_mode)) {
-               dir->i_nlink--;
-               status = ocfs2_mark_inode_dirty(handle, dir,
-                                               parent_node_bh);
-               if (status < 0) {
-                       mlog_errno(status);
-                       dir->i_nlink++;
-               }
+       dir->i_ctime = dir->i_mtime = CURRENT_TIME;
+       if (S_ISDIR(inode->i_mode))
+               drop_nlink(dir);
+
+       status = ocfs2_mark_inode_dirty(handle, dir, parent_node_bh);
+       if (status < 0) {
+               mlog_errno(status);
+               if (S_ISDIR(inode->i_mode))
+                       inc_nlink(dir);
        }
 
 leave:
-       if (status < 0 && saved_nlink)
-               inode->i_nlink = saved_nlink;
-
        if (handle)
-               ocfs2_commit_trans(handle);
+               ocfs2_commit_trans(osb, handle);
+
+       if (child_locked)
+               ocfs2_meta_unlock(inode, 1);
+
+       ocfs2_meta_unlock(dir, 1);
+
+       if (orphan_dir) {
+               /* This was locked for us in ocfs2_prepare_orphan_dir() */
+               ocfs2_meta_unlock(orphan_dir, 1);
+               mutex_unlock(&orphan_dir->i_mutex);
+               iput(orphan_dir);
+       }
 
        if (fe_bh)
                brelse(fe_bh);
@@ -934,7 +991,6 @@ leave:
  * if they have the same id, then the 1st one is the only one locked.
  */
 static int ocfs2_double_lock(struct ocfs2_super *osb,
-                            struct ocfs2_journal_handle *handle,
                             struct buffer_head **bh1,
                             struct inode *inode1,
                             struct buffer_head **bh2,
@@ -946,10 +1002,9 @@ static int ocfs2_double_lock(struct ocfs2_super *osb,
        struct buffer_head **tmpbh;
        struct inode *tmpinode;
 
-       mlog_entry("(inode1 = %"MLFu64", inode2 = %"MLFu64")\n",
-                  oi1->ip_blkno, oi2->ip_blkno);
-
-       BUG_ON(!handle);
+       mlog_entry("(inode1 = %llu, inode2 = %llu)\n",
+                  (unsigned long long)oi1->ip_blkno,
+                  (unsigned long long)oi2->ip_blkno);
 
        if (*bh1)
                *bh1 = NULL;
@@ -970,25 +1025,41 @@ static int ocfs2_double_lock(struct ocfs2_super *osb,
                        inode1 = tmpinode;
                }
                /* lock id2 */
-               status = ocfs2_meta_lock(inode2, handle, bh2, 1);
+               status = ocfs2_meta_lock(inode2, bh2, 1);
                if (status < 0) {
                        if (status != -ENOENT)
                                mlog_errno(status);
                        goto bail;
                }
        }
+
        /* lock id1 */
-       status = ocfs2_meta_lock(inode1, handle, bh1, 1);
+       status = ocfs2_meta_lock(inode1, bh1, 1);
        if (status < 0) {
+               /*
+                * An error return must mean that no cluster locks
+                * were held on function exit.
+                */
+               if (oi1->ip_blkno != oi2->ip_blkno)
+                       ocfs2_meta_unlock(inode2, 1);
+
                if (status != -ENOENT)
                        mlog_errno(status);
-               goto bail;
        }
+
 bail:
        mlog_exit(status);
        return status;
 }
 
+static void ocfs2_double_unlock(struct inode *inode1, struct inode *inode2)
+{
+       ocfs2_meta_unlock(inode1, 1);
+
+       if (inode1 != inode2)
+               ocfs2_meta_unlock(inode2, 1);
+}
+
 #define PARENT_INO(buffer) \
        ((struct ocfs2_dir_entry *) \
         ((char *)buffer + \
@@ -999,17 +1070,20 @@ static int ocfs2_rename(struct inode *old_dir,
                        struct inode *new_dir,
                        struct dentry *new_dentry)
 {
-       int status = 0, rename_lock = 0;
+       int status = 0, rename_lock = 0, parents_locked = 0;
+       int old_child_locked = 0, new_child_locked = 0;
        struct inode *old_inode = old_dentry->d_inode;
        struct inode *new_inode = new_dentry->d_inode;
+       struct inode *orphan_dir = NULL;
        struct ocfs2_dinode *newfe = NULL;
        char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
        struct buffer_head *orphan_entry_bh = NULL;
        struct buffer_head *newfe_bh = NULL;
+       struct buffer_head *old_inode_bh = NULL;
        struct buffer_head *insert_entry_bh = NULL;
        struct ocfs2_super *osb = NULL;
        u64 newfe_blkno;
-       struct ocfs2_journal_handle *handle = NULL;
+       handle_t *handle = NULL;
        struct buffer_head *old_dir_bh = NULL;
        struct buffer_head *new_dir_bh = NULL;
        struct ocfs2_dir_entry *old_de = NULL, *new_de = NULL; // dirent for old_dentry
@@ -1017,8 +1091,7 @@ static int ocfs2_rename(struct inode *old_dir,
        struct buffer_head *new_de_bh = NULL, *old_de_bh = NULL; // bhs for above
        struct buffer_head *old_inode_de_bh = NULL; // if old_dentry is a dir,
                                                    // this is the 1st dirent bh
-       nlink_t old_dir_nlink = old_dir->i_nlink, new_dir_nlink = new_dir->i_nlink;
-       unsigned int links_count;
+       nlink_t old_dir_nlink = old_dir->i_nlink;
 
        /* At some point it might be nice to break this function up a
         * bit. */
@@ -1035,14 +1108,6 @@ static int ocfs2_rename(struct inode *old_dir,
                        BUG();
        }
 
-       if (atomic_read(&old_dentry->d_count) > 2) {
-               shrink_dcache_parent(old_dentry);
-               if (atomic_read(&old_dentry->d_count) > 2) {
-                       status = -EBUSY;
-                       goto bail;
-               }
-       }
-
        /* Assume a directory heirarchy thusly:
         * a/b/c
         * a/d
@@ -1063,21 +1128,14 @@ static int ocfs2_rename(struct inode *old_dir,
                rename_lock = 1;
        }
 
-       handle = ocfs2_alloc_handle(osb);
-       if (handle == NULL) {
-               status = -ENOMEM;
-               mlog_errno(status);
-               goto bail;
-       }
-
        /* if old and new are the same, this'll just do one lock. */
-       status = ocfs2_double_lock(osb, handle,
-                                 &old_dir_bh, old_dir,
-                                 &new_dir_bh, new_dir);
+       status = ocfs2_double_lock(osb, &old_dir_bh, old_dir,
+                                  &new_dir_bh, new_dir);
        if (status < 0) {
                mlog_errno(status);
                goto bail;
        }
+       parents_locked = 1;
 
        /* make sure both dirs have bhs
         * get an extra ref on old_dir_bh if old==new */
@@ -1092,23 +1150,26 @@ static int ocfs2_rename(struct inode *old_dir,
                }
        }
 
-       if (S_ISDIR(old_inode->i_mode)) {
-               /* Directories actually require metadata updates to
-                * the directory info so we can't get away with not
-                * doing node locking on it. */
-               status = ocfs2_meta_lock(old_inode, handle, NULL, 1);
-               if (status < 0) {
-                       if (status != -ENOENT)
-                               mlog_errno(status);
-                       goto bail;
-               }
-
-               status = ocfs2_request_rename_vote(old_inode, old_dentry);
-               if (status < 0) {
+       /*
+        * Aside from allowing a meta data update, the locking here
+        * also ensures that the vote thread on other nodes won't have
+        * to concurrently downconvert the inode and the dentry locks.
+        */
+       status = ocfs2_meta_lock(old_inode, &old_inode_bh, 1);
+       if (status < 0) {
+               if (status != -ENOENT)
                        mlog_errno(status);
-                       goto bail;
-               }
+               goto bail;
+       }
+       old_child_locked = 1;
+
+       status = ocfs2_remote_dentry_delete(old_dentry);
+       if (status < 0) {
+               mlog_errno(status);
+               goto bail;
+       }
 
+       if (S_ISDIR(old_inode->i_mode)) {
                status = -EIO;
                old_inode_de_bh = ocfs2_bread(old_inode, 0, &status, 0);
                if (!old_inode_de_bh)
@@ -1122,14 +1183,6 @@ static int ocfs2_rename(struct inode *old_dir,
                if (!new_inode && new_dir!=old_dir &&
                    new_dir->i_nlink >= OCFS2_LINK_MAX)
                        goto bail;
-       } else {
-               /* Ah, the simple case - we're a file so just send a
-                * message. */
-               status = ocfs2_request_rename_vote(old_inode, old_dentry);
-               if (status < 0) {
-                       mlog_errno(status);
-                       goto bail;
-               }
        }
 
        status = -ENOENT;
@@ -1187,27 +1240,22 @@ static int ocfs2_rename(struct inode *old_dir,
                if (OCFS2_I(new_inode)->ip_blkno != newfe_blkno) {
                        status = -EACCES;
 
-                       mlog(0, "Inode blkno (%"MLFu64") and dir (%"MLFu64") "
-                            "disagree. ip_flags = %x\n",
-                            OCFS2_I(new_inode)->ip_blkno, newfe_blkno,
+                       mlog(0, "Inode %llu and dir %llu disagree. flags = %x\n",
+                            (unsigned long long)OCFS2_I(new_inode)->ip_blkno,
+                            (unsigned long long)newfe_blkno,
                             OCFS2_I(new_inode)->ip_flags);
                        goto bail;
                }
 
-               status = ocfs2_meta_lock(new_inode, handle, &newfe_bh, 1);
+               status = ocfs2_meta_lock(new_inode, &newfe_bh, 1);
                if (status < 0) {
                        if (status != -ENOENT)
                                mlog_errno(status);
                        goto bail;
                }
+               new_child_locked = 1;
 
-               if (S_ISDIR(new_inode->i_mode))
-                       links_count = 0;
-               else
-                       links_count = (unsigned int) (new_inode->i_nlink - 1);
-
-               status = ocfs2_request_unlink_vote(new_inode, new_dentry,
-                                                  links_count);
+               status = ocfs2_remote_dentry_delete(new_dentry);
                if (status < 0) {
                        mlog_errno(status);
                        goto bail;
@@ -1215,13 +1263,13 @@ static int ocfs2_rename(struct inode *old_dir,
 
                newfe = (struct ocfs2_dinode *) newfe_bh->b_data;
 
-               mlog(0, "aha rename over existing... new_de=%p "
-                    "new_blkno=%"MLFu64" newfebh=%p bhblocknr=%llu\n",
-                    new_de, newfe_blkno, newfe_bh, newfe_bh ?
+               mlog(0, "aha rename over existing... new_de=%p new_blkno=%llu "
+                    "newfebh=%p bhblocknr=%llu\n", new_de,
+                    (unsigned long long)newfe_blkno, newfe_bh, newfe_bh ?
                     (unsigned long long)newfe_bh->b_blocknr : 0ULL);
 
                if (S_ISDIR(new_inode->i_mode) || (new_inode->i_nlink == 1)) {
-                       status = ocfs2_prepare_orphan_dir(osb, handle,
+                       status = ocfs2_prepare_orphan_dir(osb, &orphan_dir,
                                                          new_inode,
                                                          orphan_name,
                                                          &orphan_entry_bh);
@@ -1249,7 +1297,7 @@ static int ocfs2_rename(struct inode *old_dir,
                }
        }
 
-       handle = ocfs2_start_trans(osb, handle, OCFS2_RENAME_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_RENAME_CREDITS);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -1276,7 +1324,7 @@ static int ocfs2_rename(struct inode *old_dir,
                    (newfe->i_links_count == cpu_to_le16(1))){
                        status = ocfs2_orphan_add(osb, handle, new_inode,
                                                  newfe, orphan_name,
-                                                 orphan_entry_bh);
+                                                 orphan_entry_bh, orphan_dir);
                        if (status < 0) {
                                mlog_errno(status);
                                goto bail;
@@ -1318,6 +1366,7 @@ static int ocfs2_rename(struct inode *old_dir,
 
        old_inode->i_ctime = CURRENT_TIME;
        mark_inode_dirty(old_inode);
+       ocfs2_mark_inode_dirty(handle, old_inode, old_inode_bh);
 
        /* now that the name has been added to new_dir, remove the old name */
        status = ocfs2_delete_entry(handle, old_dir, old_de, old_de_bh);
@@ -1342,40 +1391,34 @@ static int ocfs2_rename(struct inode *old_dir,
                if (new_inode) {
                        new_inode->i_nlink--;
                } else {
-                       new_dir->i_nlink++;
+                       inc_nlink(new_dir);
                        mark_inode_dirty(new_dir);
                }
        }
        mark_inode_dirty(old_dir);
-       if (new_inode)
+       ocfs2_mark_inode_dirty(handle, old_dir, old_dir_bh);
+       if (new_inode) {
                mark_inode_dirty(new_inode);
+               ocfs2_mark_inode_dirty(handle, new_inode, newfe_bh);
+       }
 
-       if (old_dir != new_dir)
-               if (new_dir_nlink != new_dir->i_nlink) {
-                       if (!new_dir_bh) {
-                               mlog(ML_ERROR, "need to change nlink for new "
-                                    "dir %"MLFu64" from %d to %d but bh is "
-                                    "NULL\n", OCFS2_I(new_dir)->ip_blkno,
-                                    (int)new_dir_nlink, new_dir->i_nlink);
-                       } else {
-                               struct ocfs2_dinode *fe;
-                               status = ocfs2_journal_access(handle,
-                                                             new_dir,
-                                                             new_dir_bh,
-                                                             OCFS2_JOURNAL_ACCESS_WRITE);
-                               fe = (struct ocfs2_dinode *) new_dir_bh->b_data;
-                               fe->i_links_count = cpu_to_le16(new_dir->i_nlink);
-                               status = ocfs2_journal_dirty(handle, new_dir_bh);
-                       }
-               }
+       if (old_dir != new_dir) {
+               /* Keep the same times on both directories.*/
+               new_dir->i_ctime = new_dir->i_mtime = old_dir->i_ctime;
+
+               /*
+                * This will also pick up the i_nlink change from the
+                * block above.
+                */
+               ocfs2_mark_inode_dirty(handle, new_dir, new_dir_bh);
+       }
 
        if (old_dir_nlink != old_dir->i_nlink) {
                if (!old_dir_bh) {
                        mlog(ML_ERROR, "need to change nlink for old dir "
-                            "%"MLFu64" from %d to %d but bh is NULL!\n",
-                            OCFS2_I(old_dir)->ip_blkno,
-                            (int)old_dir_nlink,
-                            old_dir->i_nlink);
+                            "%llu from %d to %d but bh is NULL!\n",
+                            (unsigned long long)OCFS2_I(old_dir)->ip_blkno,
+                            (int)old_dir_nlink, old_dir->i_nlink);
                } else {
                        struct ocfs2_dinode *fe;
                        status = ocfs2_journal_access(handle, old_dir,
@@ -1387,13 +1430,30 @@ static int ocfs2_rename(struct inode *old_dir,
                }
        }
 
+       ocfs2_dentry_move(old_dentry, new_dentry, old_dir, new_dir);
        status = 0;
 bail:
        if (rename_lock)
                ocfs2_rename_unlock(osb);
 
        if (handle)
-               ocfs2_commit_trans(handle);
+               ocfs2_commit_trans(osb, handle);
+
+       if (parents_locked)
+               ocfs2_double_unlock(old_dir, new_dir);
+
+       if (old_child_locked)
+               ocfs2_meta_unlock(old_inode, 1);
+
+       if (new_child_locked)
+               ocfs2_meta_unlock(new_inode, 1);
+
+       if (orphan_dir) {
+               /* This was locked for us in ocfs2_prepare_orphan_dir() */
+               ocfs2_meta_unlock(orphan_dir, 1);
+               mutex_unlock(&orphan_dir->i_mutex);
+               iput(orphan_dir);
+       }
 
        if (new_inode)
                sync_mapping_buffers(old_inode->i_mapping);
@@ -1402,6 +1462,8 @@ bail:
                iput(new_inode);
        if (newfe_bh)
                brelse(newfe_bh);
+       if (old_inode_bh)
+               brelse(old_inode_bh);
        if (old_dir_bh)
                brelse(old_dir_bh);
        if (new_dir_bh)
@@ -1427,7 +1489,7 @@ bail:
  * data, including the null terminator.
  */
 static int ocfs2_create_symlink_data(struct ocfs2_super *osb,
-                                    struct ocfs2_journal_handle *handle,
+                                    handle_t *handle,
                                     struct inode *inode,
                                     const char *symname)
 {
@@ -1443,8 +1505,9 @@ static int ocfs2_create_symlink_data(struct ocfs2_super *osb,
         * write i_size + 1 bytes. */
        blocks = (bytes_left + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
 
-       mlog_entry("i_blocks = %lu, i_size = %llu, blocks = %d\n",
-                      inode->i_blocks, i_size_read(inode), blocks);
+       mlog_entry("i_blocks = %llu, i_size = %llu, blocks = %d\n",
+                       (unsigned long long)inode->i_blocks,
+                       i_size_read(inode), blocks);
 
        /* Sanity check -- make sure we're going to fit. */
        if (bytes_left >
@@ -1541,7 +1604,7 @@ static int ocfs2_symlink(struct inode *dir,
        struct buffer_head *parent_fe_bh = NULL;
        struct ocfs2_dinode *fe = NULL;
        struct ocfs2_dinode *dirfe;
-       struct ocfs2_journal_handle *handle = NULL;
+       handle_t *handle = NULL;
        struct ocfs2_alloc_context *inode_ac = NULL;
        struct ocfs2_alloc_context *data_ac = NULL;
 
@@ -1555,19 +1618,12 @@ static int ocfs2_symlink(struct inode *dir,
 
        credits = ocfs2_calc_symlink_credits(sb);
 
-       handle = ocfs2_alloc_handle(osb);
-       if (handle == NULL) {
-               status = -ENOMEM;
-               mlog_errno(status);
-               goto bail;
-       }
-
        /* lock the parent directory */
-       status = ocfs2_meta_lock(dir, handle, &parent_fe_bh, 1);
+       status = ocfs2_meta_lock(dir, &parent_fe_bh, 1);
        if (status < 0) {
                if (status != -ENOENT)
                        mlog_errno(status);
-               goto bail;
+               return status;
        }
 
        dirfe = (struct ocfs2_dinode *) parent_fe_bh->b_data;
@@ -1590,7 +1646,7 @@ static int ocfs2_symlink(struct inode *dir,
                goto bail;
        }
 
-       status = ocfs2_reserve_new_inode(osb, handle, &inode_ac);
+       status = ocfs2_reserve_new_inode(osb, &inode_ac);
        if (status < 0) {
                if (status != -ENOSPC)
                        mlog_errno(status);
@@ -1599,7 +1655,7 @@ static int ocfs2_symlink(struct inode *dir,
 
        /* don't reserve bitmap space for fast symlinks. */
        if (l > ocfs2_fast_symlink_chars(sb)) {
-               status = ocfs2_reserve_clusters(osb, handle, 1, &data_ac);
+               status = ocfs2_reserve_clusters(osb, 1, &data_ac);
                if (status < 0) {
                        if (status != -ENOSPC)
                                mlog_errno(status);
@@ -1607,7 +1663,7 @@ static int ocfs2_symlink(struct inode *dir,
                }
        }
 
-       handle = ocfs2_start_trans(osb, handle, credits);
+       handle = ocfs2_start_trans(osb, credits);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -1634,9 +1690,9 @@ static int ocfs2_symlink(struct inode *dir,
                                                    NULL);
                if (status < 0) {
                        if (status != -ENOSPC && status != -EINTR) {
-                               mlog(ML_ERROR, "Failed to extend file to "
-                                              "%"MLFu64"\n",
-                                    newsize);
+                               mlog(ML_ERROR,
+                                    "Failed to extend file to %llu\n",
+                                    (unsigned long long)newsize);
                                mlog_errno(status);
                                status = -ENOSPC;
                        }
@@ -1674,12 +1730,21 @@ static int ocfs2_symlink(struct inode *dir,
                goto bail;
        }
 
+       status = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(dir)->ip_blkno);
+       if (status) {
+               mlog_errno(status);
+               goto bail;
+       }
+
        insert_inode_hash(inode);
        dentry->d_op = &ocfs2_dentry_ops;
        d_instantiate(dentry, inode);
 bail:
        if (handle)
-               ocfs2_commit_trans(handle);
+               ocfs2_commit_trans(osb, handle);
+
+       ocfs2_meta_unlock(dir, 1);
+
        if (new_fe_bh)
                brelse(new_fe_bh);
        if (parent_fe_bh)
@@ -1716,10 +1781,11 @@ int ocfs2_check_dir_entry(struct inode * dir,
                error_msg = "directory entry across blocks";
 
        if (error_msg != NULL)
-               mlog(ML_ERROR, "bad entry in directory #%"MLFu64": %s - "
-                    "offset=%lu, inode=%"MLFu64", rec_len=%d, name_len=%d\n",
-                    OCFS2_I(dir)->ip_blkno, error_msg, offset,
-                    le64_to_cpu(de->inode), rlen, de->name_len);
+               mlog(ML_ERROR, "bad entry in directory #%llu: %s - "
+                    "offset=%lu, inode=%llu, rec_len=%d, name_len=%d\n",
+                    (unsigned long long)OCFS2_I(dir)->ip_blkno, error_msg,
+                    offset, (unsigned long long)le64_to_cpu(de->inode), rlen,
+                    de->name_len);
        return error_msg == NULL ? 1 : 0;
 }
 
@@ -1729,7 +1795,7 @@ int ocfs2_check_dir_entry(struct inode * dir,
  * If you pass me insert_bh, I'll skip the search of the other dir
  * blocks and put the record in there.
  */
-static int __ocfs2_add_entry(struct ocfs2_journal_handle *handle,
+static int __ocfs2_add_entry(handle_t *handle,
                             struct inode *dir,
                             const char *name, int namelen,
                             struct inode *inode, u64 blkno,
@@ -1769,6 +1835,13 @@ static int __ocfs2_add_entry(struct ocfs2_journal_handle *handle,
                     (le16_to_cpu(de->rec_len) >= rec_len)) ||
                    (le16_to_cpu(de->rec_len) >=
                     (OCFS2_DIR_REC_LEN(de->name_len) + rec_len))) {
+                       dir->i_mtime = dir->i_ctime = CURRENT_TIME;
+                       retval = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh);
+                       if (retval < 0) {
+                               mlog_errno(retval);
+                               goto bail;
+                       }
+
                        status = ocfs2_journal_access(handle, dir, insert_bh,
                                                      OCFS2_JOURNAL_ACCESS_WRITE);
                        /* By now the buffer is marked for journaling */
@@ -1791,7 +1864,6 @@ static int __ocfs2_add_entry(struct ocfs2_journal_handle *handle,
                        de->name_len = namelen;
                        memcpy(de->name, name, namelen);
 
-                       dir->i_mtime = dir->i_ctime = CURRENT_TIME;
                        dir->i_version++;
                        status = ocfs2_journal_dirty(handle, insert_bh);
                        retval = 0;
@@ -1815,7 +1887,7 @@ bail:
  * ocfs2_delete_entry deletes a directory entry by merging it with the
  * previous entry
  */
-static int ocfs2_delete_entry(struct ocfs2_journal_handle *handle,
+static int ocfs2_delete_entry(handle_t *handle,
                              struct inode *dir,
                              struct ocfs2_dir_entry *de_del,
                              struct buffer_head *bh)
@@ -1961,13 +2033,8 @@ restart:
                                }
                                num++;
 
-                               /* XXX: questionable readahead stuff here */
                                bh = ocfs2_bread(dir, b++, &err, 1);
                                bh_use[ra_max] = bh;
-#if 0          // ???
-                               if (bh)
-                                       ll_rw_block(READ, 1, &bh);
-#endif
                        }
                }
                if ((bh = bh_use[ra_ptr++]) == NULL)
@@ -1975,6 +2042,10 @@ restart:
                wait_on_buffer(bh);
                if (!buffer_uptodate(bh)) {
                        /* read error, skip block & hope for the best */
+                       ocfs2_error(dir->i_sb, "reading directory %llu, "
+                                   "offset %lu\n",
+                                   (unsigned long long)OCFS2_I(dir)->ip_blkno,
+                                   block);
                        brelse(bh);
                        goto next;
                }
@@ -2021,8 +2092,8 @@ static int ocfs2_blkno_stringify(u64 blkno, char *name)
 
        mlog_entry_void();
 
-       namelen = snprintf(name, OCFS2_ORPHAN_NAMELEN + 1, "%016"MLFx64,
-                          blkno);
+       namelen = snprintf(name, OCFS2_ORPHAN_NAMELEN + 1, "%016llx",
+                          (long long)blkno);
        if (namelen <= 0) {
                if (namelen)
                        status = namelen;
@@ -2047,19 +2118,19 @@ bail:
 }
 
 static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
-                                   struct ocfs2_journal_handle *handle,
+                                   struct inode **ret_orphan_dir,
                                    struct inode *inode,
                                    char *name,
                                    struct buffer_head **de_bh)
 {
-       struct inode *orphan_dir_inode = NULL;
+       struct inode *orphan_dir_inode;
        struct buffer_head *orphan_dir_bh = NULL;
        int status = 0;
 
        status = ocfs2_blkno_stringify(OCFS2_I(inode)->ip_blkno, name);
        if (status < 0) {
                mlog_errno(status);
-               goto leave;
+               return status;
        }
 
        orphan_dir_inode = ocfs2_get_system_file_inode(osb,
@@ -2068,11 +2139,12 @@ static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
        if (!orphan_dir_inode) {
                status = -ENOENT;
                mlog_errno(status);
-               goto leave;
+               return status;
        }
 
-       ocfs2_handle_add_inode(handle, orphan_dir_inode);
-       status = ocfs2_meta_lock(orphan_dir_inode, handle, &orphan_dir_bh, 1);
+       mutex_lock(&orphan_dir_inode->i_mutex);
+
+       status = ocfs2_meta_lock(orphan_dir_inode, &orphan_dir_bh, 1);
        if (status < 0) {
                mlog_errno(status);
                goto leave;
@@ -2082,13 +2154,19 @@ static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
                                              orphan_dir_bh, name,
                                              OCFS2_ORPHAN_NAMELEN, de_bh);
        if (status < 0) {
+               ocfs2_meta_unlock(orphan_dir_inode, 1);
+
                mlog_errno(status);
                goto leave;
        }
 
+       *ret_orphan_dir = orphan_dir_inode;
+
 leave:
-       if (orphan_dir_inode)
+       if (status) {
+               mutex_unlock(&orphan_dir_inode->i_mutex);
                iput(orphan_dir_inode);
+       }
 
        if (orphan_dir_bh)
                brelse(orphan_dir_bh);
@@ -2098,28 +2176,19 @@ leave:
 }
 
 static int ocfs2_orphan_add(struct ocfs2_super *osb,
-                           struct ocfs2_journal_handle *handle,
+                           handle_t *handle,
                            struct inode *inode,
                            struct ocfs2_dinode *fe,
                            char *name,
-                           struct buffer_head *de_bh)
+                           struct buffer_head *de_bh,
+                           struct inode *orphan_dir_inode)
 {
-       struct inode *orphan_dir_inode = NULL;
        struct buffer_head *orphan_dir_bh = NULL;
        int status = 0;
        struct ocfs2_dinode *orphan_fe;
 
        mlog_entry("(inode->i_ino = %lu)\n", inode->i_ino);
 
-       orphan_dir_inode = ocfs2_get_system_file_inode(osb,
-                                                      ORPHAN_DIR_SYSTEM_INODE,
-                                                      osb->slot_num);
-       if (!orphan_dir_inode) {
-               status = -ENOENT;
-               mlog_errno(status);
-               goto leave;
-       }
-
        status = ocfs2_read_block(osb,
                                  OCFS2_I(orphan_dir_inode)->ip_blkno,
                                  &orphan_dir_bh, OCFS2_BH_CACHED,
@@ -2167,13 +2236,10 @@ static int ocfs2_orphan_add(struct ocfs2_super *osb,
        OCFS2_I(inode)->ip_orphaned_slot = osb->slot_num;
        spin_unlock(&OCFS2_I(inode)->ip_lock);
 
-       mlog(0, "Inode %"MLFu64" orphaned in slot %d\n",
-            OCFS2_I(inode)->ip_blkno, osb->slot_num);
+       mlog(0, "Inode %llu orphaned in slot %d\n",
+            (unsigned long long)OCFS2_I(inode)->ip_blkno, osb->slot_num);
 
 leave:
-       if (orphan_dir_inode)
-               iput(orphan_dir_inode);
-
        if (orphan_dir_bh)
                brelse(orphan_dir_bh);
 
@@ -2183,7 +2249,7 @@ leave:
 
 /* unlike orphan_add, we expect the orphan dir to already be locked here. */
 int ocfs2_orphan_del(struct ocfs2_super *osb,
-                    struct ocfs2_journal_handle *handle,
+                    handle_t *handle,
                     struct inode *orphan_dir_inode,
                     struct inode *inode,
                     struct buffer_head *orphan_dir_bh)
@@ -2202,8 +2268,9 @@ int ocfs2_orphan_del(struct ocfs2_super *osb,
                goto leave;
        }
 
-       mlog(0, "removing '%s' from orphan dir %"MLFu64" (namelen=%d)\n",
-            name, OCFS2_I(orphan_dir_inode)->ip_blkno, OCFS2_ORPHAN_NAMELEN);
+       mlog(0, "removing '%s' from orphan dir %llu (namelen=%d)\n",
+            name, (unsigned long long)OCFS2_I(orphan_dir_inode)->ip_blkno,
+            OCFS2_ORPHAN_NAMELEN);
 
        /* find it's spot in the orphan directory */
        target_de_bh = ocfs2_find_entry(name, OCFS2_ORPHAN_NAMELEN,
@@ -2261,4 +2328,6 @@ struct inode_operations ocfs2_dir_iops = {
        .rename         = ocfs2_rename,
        .setattr        = ocfs2_setattr,
        .getattr        = ocfs2_getattr,
+       .sync_flags     = ocfs2_sync_flags,
+       .permission     = ocfs2_permission,
 };