]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/ext4/ialloc.c
ext4: move headers out of include/linux
[linux-2.6-omap-h63xx.git] / fs / ext4 / ialloc.c
index 575b5215c8084f3613484555afb0f5727a404826..d59bdf7233b50aacd285bce4882c51620c40bc51 100644 (file)
@@ -15,8 +15,6 @@
 #include <linux/time.h>
 #include <linux/fs.h>
 #include <linux/jbd2.h>
-#include <linux/ext4_fs.h>
-#include <linux/ext4_jbd2.h>
 #include <linux/stat.h>
 #include <linux/string.h>
 #include <linux/quotaops.h>
@@ -25,7 +23,8 @@
 #include <linux/bitops.h>
 #include <linux/blkdev.h>
 #include <asm/byteorder.h>
-
+#include "ext4.h"
+#include "ext4_jbd2.h"
 #include "xattr.h"
 #include "acl.h"
 #include "group.h"
@@ -75,7 +74,7 @@ unsigned ext4_init_inode_bitmap(struct super_block *sb, struct buffer_head *bh,
        /* If checksum is bad mark all blocks and inodes use to prevent
         * allocation, essentially implementing a per-group read-only flag. */
        if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) {
-               ext4_error(sb, __FUNCTION__, "Checksum bad for group %lu\n",
+               ext4_error(sb, __func__, "Checksum bad for group %lu\n",
                           block_group);
                gdp->bg_free_blocks_count = 0;
                gdp->bg_free_inodes_count = 0;
@@ -223,11 +222,9 @@ void ext4_free_inode (handle_t *handle, struct inode * inode)
 
                if (gdp) {
                        spin_lock(sb_bgl_lock(sbi, block_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 (is_directory)
-                               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);
                        gdp->bg_checksum = ext4_group_desc_csum(sbi,
                                                        block_group, gdp);
                        spin_unlock(sb_bgl_lock(sbi, block_group));
@@ -305,7 +302,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).
@@ -588,7 +585,7 @@ got:
        ino++;
        if ((group == 0 && ino < EXT4_FIRST_INO(sb)) ||
            ino > EXT4_INODES_PER_GROUP(sb)) {
-               ext4_error(sb, __FUNCTION__,
+               ext4_error(sb, __func__,
                           "reserved inode or inode > inodes count - "
                           "block_group = %lu, inode=%lu", group,
                           ino + group * EXT4_INODES_PER_GROUP(sb));
@@ -664,11 +661,9 @@ got:
                                cpu_to_le16(EXT4_INODES_PER_GROUP(sb) - ino);
        }
 
-       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)) {
-               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);
        }
        gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp);
        spin_unlock(sb_bgl_lock(sbi, group));
@@ -702,7 +697,12 @@ got:
        ei->i_dir_start_lookup = 0;
        ei->i_disksize = 0;
 
-       ei->i_flags = EXT4_I(dir)->i_flags & ~EXT4_INDEX_FL;
+       /*
+        * Don't inherit extent flag from directory. We set extent flag on
+        * newly created directory and file only if -o extent mount option is
+        * specified
+        */
+       ei->i_flags = EXT4_I(dir)->i_flags & ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL);
        if (S_ISLNK(mode))
                ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
        /* dirsync only applies to directories */
@@ -745,12 +745,15 @@ got:
                goto fail_free_drop;
        }
        if (test_opt(sb, EXTENTS)) {
-               EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL;
-               ext4_ext_tree_init(handle, inode);
-               err = ext4_update_incompat_feature(handle, sb,
-                                               EXT4_FEATURE_INCOMPAT_EXTENTS);
-               if (err)
-                       goto fail;
+               /* set extent flag only for diretory, file and normal symlink*/
+               if (S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode)) {
+                       EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL;
+                       ext4_ext_tree_init(handle, inode);
+                       err = ext4_update_incompat_feature(handle, sb,
+                                       EXT4_FEATURE_INCOMPAT_EXTENTS);
+                       if (err)
+                               goto fail;
+               }
        }
 
        ext4_debug("allocating inode %lu\n", inode->i_ino);
@@ -782,54 +785,66 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
        unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
        ext4_group_t block_group;
        int bit;
-       struct buffer_head *bitmap_bh = NULL;
+       struct buffer_head *bitmap_bh;
        struct inode *inode = NULL;
+       long err = -EIO;
 
        /* Error cases - e2fsck has already cleaned up for us */
        if (ino > max_ino) {
-               ext4_warning(sb, __FUNCTION__,
+               ext4_warning(sb, __func__,
                             "bad orphan ino %lu!  e2fsck was run?", ino);
-               goto out;
+               goto error;
        }
 
        block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
        bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
        bitmap_bh = read_inode_bitmap(sb, block_group);
        if (!bitmap_bh) {
-               ext4_warning(sb, __FUNCTION__,
+               ext4_warning(sb, __func__,
                             "inode bitmap error for orphan %lu", ino);
-               goto out;
+               goto error;
        }
 
        /* Having the inode bit set should be a 100% indicator that this
         * is a valid orphan (no e2fsck run on fs).  Orphans also include
         * inodes that were being truncated, so we can't check i_nlink==0.
         */
-       if (!ext4_test_bit(bit, bitmap_bh->b_data) ||
-                       !(inode = iget(sb, ino)) || is_bad_inode(inode) ||
-                       NEXT_ORPHAN(inode) > max_ino) {
-               ext4_warning(sb, __FUNCTION__,
-                            "bad orphan inode %lu!  e2fsck was run?", ino);
-               printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
-                      bit, (unsigned long long)bitmap_bh->b_blocknr,
-                      ext4_test_bit(bit, bitmap_bh->b_data));
-               printk(KERN_NOTICE "inode=%p\n", inode);
-               if (inode) {
-                       printk(KERN_NOTICE "is_bad_inode(inode)=%d\n",
-                              is_bad_inode(inode));
-                       printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n",
-                              NEXT_ORPHAN(inode));
-                       printk(KERN_NOTICE "max_ino=%lu\n", max_ino);
-               }
+       if (!ext4_test_bit(bit, bitmap_bh->b_data))
+               goto bad_orphan;
+
+       inode = ext4_iget(sb, ino);
+       if (IS_ERR(inode))
+               goto iget_failed;
+
+       if (NEXT_ORPHAN(inode) > max_ino)
+               goto bad_orphan;
+       brelse(bitmap_bh);
+       return inode;
+
+iget_failed:
+       err = PTR_ERR(inode);
+       inode = NULL;
+bad_orphan:
+       ext4_warning(sb, __func__,
+                    "bad orphan inode %lu!  e2fsck was run?", ino);
+       printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
+              bit, (unsigned long long)bitmap_bh->b_blocknr,
+              ext4_test_bit(bit, bitmap_bh->b_data));
+       printk(KERN_NOTICE "inode=%p\n", inode);
+       if (inode) {
+               printk(KERN_NOTICE "is_bad_inode(inode)=%d\n",
+                      is_bad_inode(inode));
+               printk(KERN_NOTICE "NEXT_ORPHAN(inode)=%u\n",
+                      NEXT_ORPHAN(inode));
+               printk(KERN_NOTICE "max_ino=%lu\n", max_ino);
                /* Avoid freeing blocks if we got a bad deleted inode */
-               if (inode && inode->i_nlink == 0)
+               if (inode->i_nlink == 0)
                        inode->i_blocks = 0;
                iput(inode);
-               inode = NULL;
        }
-out:
        brelse(bitmap_bh);
-       return inode;
+error:
+       return ERR_PTR(err);
 }
 
 unsigned long ext4_count_free_inodes (struct super_block * sb)