btrfs: replace inode uid,gid,mode initialization with helper function
[safe/jmp/linux-2.6] / fs / ext2 / ialloc.c
index 5deb8b7..f0c5286 100644 (file)
@@ -75,11 +75,9 @@ static void ext2_release_inode(struct super_block *sb, int group, int dir)
        }
 
        spin_lock(sb_bgl_lock(EXT2_SB(sb), group));
-       desc->bg_free_inodes_count =
-               cpu_to_le16(le16_to_cpu(desc->bg_free_inodes_count) + 1);
+       le16_add_cpu(&desc->bg_free_inodes_count, 1);
        if (dir)
-               desc->bg_used_dirs_count =
-                       cpu_to_le16(le16_to_cpu(desc->bg_used_dirs_count) - 1);
+               le16_add_cpu(&desc->bg_used_dirs_count, -1);
        spin_unlock(sb_bgl_lock(EXT2_SB(sb), group));
        if (dir)
                percpu_counter_dec(&EXT2_SB(sb)->s_dirs_counter);
@@ -108,7 +106,7 @@ void ext2_free_inode (struct inode * inode)
        struct super_block * sb = inode->i_sb;
        int is_directory;
        unsigned long ino;
-       struct buffer_head *bitmap_bh = NULL;
+       struct buffer_head *bitmap_bh;
        unsigned long block_group;
        unsigned long bit;
        struct ext2_super_block * es;
@@ -123,8 +121,8 @@ void ext2_free_inode (struct inode * inode)
        if (!is_bad_inode(inode)) {
                /* Quota is already initialized in iput() */
                ext2_xattr_delete_inode(inode);
-               DQUOT_FREE_INODE(inode);
-               DQUOT_DROP(inode);
+               dquot_free_inode(inode);
+               dquot_drop(inode);
        }
 
        es = EXT2_SB(sb)->s_es;
@@ -137,14 +135,13 @@ void ext2_free_inode (struct inode * inode)
            ino > le32_to_cpu(es->s_inodes_count)) {
                ext2_error (sb, "ext2_free_inode",
                            "reserved or nonexistent inode %lu", ino);
-               goto error_return;
+               return;
        }
        block_group = (ino - 1) / EXT2_INODES_PER_GROUP(sb);
        bit = (ino - 1) % EXT2_INODES_PER_GROUP(sb);
-       brelse(bitmap_bh);
        bitmap_bh = read_inode_bitmap(sb, block_group);
        if (!bitmap_bh)
-               goto error_return;
+               return;
 
        /* Ok, now we can actually update the inode bitmaps.. */
        if (!ext2_clear_bit_atomic(sb_bgl_lock(EXT2_SB(sb), block_group),
@@ -156,7 +153,7 @@ void ext2_free_inode (struct inode * inode)
        mark_buffer_dirty(bitmap_bh);
        if (sb->s_flags & MS_SYNCHRONOUS)
                sync_dirty_buffer(bitmap_bh);
-error_return:
+
        brelse(bitmap_bh);
 }
 
@@ -253,7 +250,7 @@ static int find_group_dir(struct super_block *sb, struct inode *parent)
  * it has too few free inodes left (min_inodes) or 
  * it has too few free blocks left (min_blocks) or 
  * it's already running too large debt (max_debt). 
- * Parent's group is prefered, if it doesn't satisfy these 
+ * Parent's group is preferred, if it doesn't satisfy these 
  * conditions we search cyclically through the rest. If none 
  * of the groups look good we just look for a group with more 
  * free inodes than average (starting at parent's group). 
@@ -539,13 +536,11 @@ got:
                percpu_counter_inc(&sbi->s_dirs_counter);
 
        spin_lock(sb_bgl_lock(sbi, group));
-       gdp->bg_free_inodes_count =
-                cpu_to_le16(le16_to_cpu(gdp->bg_free_inodes_count) - 1);
+       le16_add_cpu(&gdp->bg_free_inodes_count, -1);
        if (S_ISDIR(mode)) {
                if (sbi->s_debts[group] < 255)
                        sbi->s_debts[group]++;
-               gdp->bg_used_dirs_count =
-                       cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1);
+               le16_add_cpu(&gdp->bg_used_dirs_count, 1);
        } else {
                if (sbi->s_debts[group])
                        sbi->s_debts[group]--;
@@ -554,7 +549,7 @@ got:
 
        sb->s_dirt = 1;
        mark_buffer_dirty(bh2);
-       inode->i_uid = current->fsuid;
+       inode->i_uid = current_fsuid();
        if (test_opt (sb, GRPID))
                inode->i_gid = dir->i_gid;
        else if (dir->i_mode & S_ISGID) {
@@ -562,19 +557,15 @@ got:
                if (S_ISDIR(mode))
                        mode |= S_ISGID;
        } else
-               inode->i_gid = current->fsgid;
+               inode->i_gid = current_fsgid();
        inode->i_mode = mode;
 
        inode->i_ino = ino;
        inode->i_blocks = 0;
        inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
        memset(ei->i_data, 0, sizeof(ei->i_data));
-       ei->i_flags = EXT2_I(dir)->i_flags & ~EXT2_BTREE_FL;
-       if (S_ISLNK(mode))
-               ei->i_flags &= ~(EXT2_IMMUTABLE_FL|EXT2_APPEND_FL);
-       /* dirsync is only applied to directories */
-       if (!S_ISDIR(mode))
-               ei->i_flags &= ~EXT2_DIRSYNC_FL;
+       ei->i_flags =
+               ext2_mask_flags(mode, EXT2_I(dir)->i_flags & EXT2_FL_INHERITED);
        ei->i_faddr = 0;
        ei->i_frag_no = 0;
        ei->i_frag_size = 0;
@@ -589,13 +580,16 @@ got:
        spin_lock(&sbi->s_next_gen_lock);
        inode->i_generation = sbi->s_next_generation++;
        spin_unlock(&sbi->s_next_gen_lock);
-       insert_inode_hash(inode);
-
-       if (DQUOT_ALLOC_INODE(inode)) {
-               err = -EDQUOT;
+       if (insert_inode_locked(inode) < 0) {
+               err = -EINVAL;
                goto fail_drop;
        }
 
+       dquot_initialize(inode);
+       err = dquot_alloc_inode(inode);
+       if (err)
+               goto fail_drop;
+
        err = ext2_init_acl(inode, dir);
        if (err)
                goto fail_free_drop;
@@ -610,12 +604,13 @@ got:
        return inode;
 
 fail_free_drop:
-       DQUOT_FREE_INODE(inode);
+       dquot_free_inode(inode);
 
 fail_drop:
-       DQUOT_DROP(inode);
+       dquot_drop(inode);
        inode->i_flags |= S_NOQUOTA;
        inode->i_nlink = 0;
+       unlock_new_inode(inode);
        iput(inode);
        return ERR_PTR(err);