Whamcloud - gitweb
b=19674
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4-alloc-policy-2.6-sles11.patch
1 Index: linux-2.6.27.21-0.1/fs/ext4/ialloc.c
2 ===================================================================
3 --- linux-2.6.27.21-0.1.orig/fs/ext4/ialloc.c
4 +++ linux-2.6.27.21-0.1/fs/ext4/ialloc.c
5 @@ -1005,6 +1005,36 @@ fail_drop:
6         return ERR_PTR(err);
7  }
8  
9 +unsigned long ext4_find_reverse(struct super_block *sb)
10 +{
11 +       struct ext4_group_desc *desc;
12 +       struct buffer_head *bitmap_bh = NULL;
13 +       int group;
14 +       unsigned long ino, offset;
15 +
16 +       for (offset = (EXT4_INODES_PER_GROUP(sb) >> 1); offset >= 0;
17 +            offset >>= 1) {
18 +               for (group = EXT4_SB(sb)->s_groups_count - 1; group >= 0;
19 +                    --group) {
20 +                       desc = ext4_get_group_desc(sb, group, NULL);
21 +                       if (ext4_free_inodes_count(sb, desc) == 0)
22 +                               continue;
23 +
24 +                       bitmap_bh = ext4_read_inode_bitmap(sb, group);
25 +                       if (!bitmap_bh)
26 +                               continue;
27 +
28 +                       ino = ext4_find_next_zero_bit((unsigned long *)
29 +                                       bitmap_bh->b_data,
30 +                                       EXT4_INODES_PER_GROUP(sb), offset);
31 +                       if (ino < EXT4_INODES_PER_GROUP(sb))
32 +                               return (group * EXT4_INODES_PER_GROUP(sb) +
33 +                                      ino + 1);
34 +               }
35 +       }
36 +       return 0;
37 +}
38 +
39  /* Verify that we are loading a valid orphan from disk */
40  struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
41  {
42 Index: linux-2.6.27.21-0.1/fs/ext4/namei.c
43 ===================================================================
44 --- linux-2.6.27.21-0.1.orig/fs/ext4/namei.c
45 +++ linux-2.6.27.21-0.1/fs/ext4/namei.c
46 @@ -151,14 +151,24 @@ struct dx_map_entry
47         u16 size;
48  };
49  
50 +/*
51 + * dentry_param used by ext4_new_inode_wantedi()
52 + */
53  #define LVFS_DENTRY_PARAM_MAGIC                20070216UL
54  struct lvfs_dentry_params
55  {
56 -       unsigned long   p_inum;
57 -       void        *p_ptr;
58 -       u32          magic;
59 +       unsigned long   ldp_inum;
60 +       long            ldp_flags;
61 +       u32             ldp_magic;
62  };
63  
64 +/* Only use the least 3 bits of ldp_flags for goal policy */
65 +typedef enum {
66 +       DP_GOAL_POLICY       = 0,
67 +       DP_LASTGROUP_REVERSE = 1,
68 +} dp_policy_t;
69 +
70 +
71  static inline ext4_lblk_t dx_get_block(struct dx_entry *entry);
72  static void dx_set_block(struct dx_entry *entry, ext4_lblk_t value);
73  static inline unsigned dx_get_hash(struct dx_entry *entry);
74 @@ -1770,8 +1780,13 @@ static struct inode * ext4_new_inode_wan
75         if (dentry->d_fsdata != NULL) {
76                 struct lvfs_dentry_params *param = dentry->d_fsdata;
77  
78 -               if (param->magic == LVFS_DENTRY_PARAM_MAGIC)
79 -                       inum = param->p_inum;
80 +               if (param->ldp_magic == LVFS_DENTRY_PARAM_MAGIC) {
81 +                       if ((dp_policy_t)(param->ldp_flags & 0x7) ==
82 +                           DP_LASTGROUP_REVERSE)
83 +                               inum = ext4_find_reverse(dir->i_sb);
84 +                        else /* DP_GOAL_POLICY */
85 +                               inum = param->ldp_inum;
86 +                }
87         }
88         return ext4_new_inode(handle, dir, mode, inum);
89  }
90 Index: linux-2.6.27.21-0.1/fs/ext4/ext4.h
91 ===================================================================
92 --- linux-2.6.27.21-0.1.orig/fs/ext4/ext4.h
93 +++ linux-2.6.27.21-0.1/fs/ext4/ext4.h
94 @@ -1089,6 +1089,7 @@ extern int ext4fs_dirhash(const char *na
95  /* ialloc.c */
96  extern struct inode * ext4_new_inode(handle_t *, struct inode *, int,
97                                      unsigned long);
98 +extern unsigned long ext4_find_reverse(struct super_block *);
99  extern void ext4_free_inode(handle_t *, struct inode *);
100  extern struct inode * ext4_orphan_get(struct super_block *, unsigned long);
101  extern unsigned long ext4_count_free_inodes(struct super_block *);