Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[powerpc.git] / fs / ocfs2 / namei.c
index daf7060..f3d7803 100644 (file)
@@ -75,12 +75,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,
@@ -93,12 +93,12 @@ 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,
@@ -111,7 +111,7 @@ static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
                                    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,
@@ -119,11 +119,11 @@ static int ocfs2_orphan_add(struct ocfs2_super *osb,
                            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,
@@ -236,7 +236,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,
@@ -311,7 +311,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;
@@ -379,7 +379,7 @@ static int ocfs2_mknod(struct inode *dir,
                }
        }
 
-       handle = ocfs2_start_trans(osb, NULL, OCFS2_MKNOD_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_MKNOD_CREDITS);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -440,7 +440,7 @@ static int ocfs2_mknod(struct inode *dir,
        status = 0;
 leave:
        if (handle)
-               ocfs2_commit_trans(handle);
+               ocfs2_commit_trans(osb, handle);
 
        ocfs2_meta_unlock(dir, 1);
 
@@ -476,7 +476,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)
 {
@@ -587,9 +587,11 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
        }
 
        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 */
@@ -642,7 +644,7 @@ static int ocfs2_link(struct dentry *old_dentry,
                      struct inode *dir,
                      struct dentry *dentry)
 {
-       struct ocfs2_journal_handle *handle;
+       handle_t *handle;
        struct inode *inode = old_dentry->d_inode;
        int err;
        struct buffer_head *fe_bh = NULL;
@@ -696,7 +698,7 @@ static int ocfs2_link(struct dentry *old_dentry,
                goto out_unlock_inode;
        }
 
-       handle = ocfs2_start_trans(osb, NULL, OCFS2_LINK_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_LINK_CREDITS);
        if (IS_ERR(handle)) {
                err = PTR_ERR(handle);
                handle = NULL;
@@ -746,7 +748,7 @@ static int ocfs2_link(struct dentry *old_dentry,
        d_instantiate(dentry, inode);
 
 out_commit:
-       ocfs2_commit_trans(handle);
+       ocfs2_commit_trans(osb, handle);
 out_unlock_inode:
        ocfs2_meta_unlock(inode, 1);
 
@@ -807,7 +809,7 @@ static int ocfs2_unlink(struct inode *dir,
        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];
@@ -886,7 +888,7 @@ static int ocfs2_unlink(struct inode *dir,
                }
        }
 
-       handle = ocfs2_start_trans(osb, NULL, OCFS2_UNLINK_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_UNLINK_CREDITS);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -930,19 +932,20 @@ static int ocfs2_unlink(struct inode *dir,
                goto leave;
        }
 
-       if (S_ISDIR(inode->i_mode)) {
+       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);
+
+       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 (handle)
-               ocfs2_commit_trans(handle);
+               ocfs2_commit_trans(osb, handle);
 
        if (child_locked)
                ocfs2_meta_unlock(inode, 1);
@@ -1066,10 +1069,11 @@ static int ocfs2_rename(struct inode *old_dir,
        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
@@ -1077,7 +1081,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;
+       nlink_t old_dir_nlink = old_dir->i_nlink;
 
        /* At some point it might be nice to break this function up a
         * bit. */
@@ -1137,12 +1141,11 @@ static int ocfs2_rename(struct inode *old_dir,
        }
 
        /*
-        * Though we don't require an inode meta data update if
-        * old_inode is not a directory, we lock anyway here to ensure
-        * the vote thread on other nodes won't have to concurrently
-        * downconvert the inode and the dentry locks.
+        * 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, NULL, 1);
+       status = ocfs2_meta_lock(old_inode, &old_inode_bh, 1);
        if (status < 0) {
                if (status != -ENOENT)
                        mlog_errno(status);
@@ -1284,7 +1287,7 @@ static int ocfs2_rename(struct inode *old_dir,
                }
        }
 
-       handle = ocfs2_start_trans(osb, NULL, OCFS2_RENAME_CREDITS);
+       handle = ocfs2_start_trans(osb, OCFS2_RENAME_CREDITS);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -1353,6 +1356,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);
@@ -1382,27 +1386,22 @@ static int ocfs2_rename(struct inode *old_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 %llu from %d to %d but bh is NULL\n",
-                                    (unsigned long long)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) {
@@ -1428,7 +1427,7 @@ bail:
                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);
@@ -1453,6 +1452,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)
@@ -1478,7 +1479,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)
 {
@@ -1593,7 +1594,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;
 
@@ -1652,7 +1653,7 @@ static int ocfs2_symlink(struct inode *dir,
                }
        }
 
-       handle = ocfs2_start_trans(osb, NULL, credits);
+       handle = ocfs2_start_trans(osb, credits);
        if (IS_ERR(handle)) {
                status = PTR_ERR(handle);
                handle = NULL;
@@ -1730,7 +1731,7 @@ static int ocfs2_symlink(struct inode *dir,
        d_instantiate(dentry, inode);
 bail:
        if (handle)
-               ocfs2_commit_trans(handle);
+               ocfs2_commit_trans(osb, handle);
 
        ocfs2_meta_unlock(dir, 1);
 
@@ -1784,7 +1785,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,
@@ -1824,6 +1825,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 */
@@ -1846,7 +1854,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;
@@ -1870,7 +1877,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)
@@ -2159,7 +2166,7 @@ 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,
@@ -2232,7 +2239,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)
@@ -2311,4 +2318,5 @@ struct inode_operations ocfs2_dir_iops = {
        .rename         = ocfs2_rename,
        .setattr        = ocfs2_setattr,
        .getattr        = ocfs2_getattr,
+       .permission     = ocfs2_permission,
 };