Whamcloud - gitweb
LU-7922 ldiskfs: correction in ext4_kzalloc
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / sles11sp2 / ext4-introduce-ext4_kvmalloc-ext4_kzalloc-and-ext4_kvfree.patch
1 From 9933fc0ac1ac14b795819cd63d05ea92112f690a Mon Sep 17 00:00:00 2001
2 From: Theodore Ts'o <tytso@mit.edu>
3 Date: Mon, 1 Aug 2011 08:45:02 -0400
4 Subject: ext4: introduce ext4_kvmalloc(), ext4_kzalloc(), and ext4_kvfree()
5 Git-commit: 9933fc0a
6 Patch-mainline: v3.1-rc1
7
8 Introduce new helper functions which try kmalloc, and then fall back
9 to vmalloc if necessary, and use them for allocating and deallocating
10 s_flex_groups.
11
12 Upstream-Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
13 Signed-off-by: Jeff Mahoney <jeffm@suse.com>
14 ---
15  fs/ext4/ext4.h  |    3 +++
16  fs/ext4/super.c |   54 ++++++++++++++++++++++++++++++++++++------------------
17  2 files changed, 39 insertions(+), 18 deletions(-)
18
19 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
20 index ba2009b..db9fead 100644
21 --- a/fs/ext4/ext4.h
22 +++ b/fs/ext4/ext4.h
23 @@ -1874,6 +1874,9 @@ extern int ext4_group_extend(struct super_block *sb,
24                                 ext4_fsblk_t n_blocks_count);
25
26  /* super.c */
27 +extern void *ext4_kvmalloc(size_t size, gfp_t flags);
28 +extern void *ext4_kvzalloc(size_t size, gfp_t flags);
29 +extern void ext4_kvfree(void *ptr);
30  extern void __ext4_error(struct super_block *, const char *, unsigned int,
31                          const char *, ...)
32         __attribute__ ((format (printf, 4, 5)));
33 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
34 index cfe9f39..658f586 100644
35 --- a/fs/ext4/super.c
36 +++ b/fs/ext4/super.c
37 @@ -110,6 +110,35 @@ static struct file_system_type ext3_fs_type = {
38  #define IS_EXT3_SB(sb) (0)
39  #endif
40
41 +void *ext4_kvmalloc(size_t size, gfp_t flags)
42 +{
43 +       void *ret;
44 +
45 +       ret = kmalloc(size, flags | __GFP_NOWARN);
46 +       if (!ret)
47 +               ret = __vmalloc(size, flags, PAGE_KERNEL);
48 +       return ret;
49 +}
50 +
51 +void *ext4_kvzalloc(size_t size, gfp_t flags)
52 +{
53 +       void *ret;
54 +
55 +       ret = kzalloc(size, flags | __GFP_NOWARN);
56 +       if (!ret)
57 +               ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
58 +       return ret;
59 +}
60 +
61 +void ext4_kvfree(void *ptr)
62 +{
63 +       if (is_vmalloc_addr(ptr))
64 +               vfree(ptr);
65 +       else
66 +               kfree(ptr);
67 +
68 +}
69 +
70  ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
71                                struct ext4_group_desc *bg)
72  {
73 @@ -791,10 +820,7 @@ static void ext4_put_super(struct super_block *sb)
74         for (i = 0; i < sbi->s_gdb_count; i++)
75                 brelse(sbi->s_group_desc[i]);
76         kfree(sbi->s_group_desc);
77 -       if (is_vmalloc_addr(sbi->s_flex_groups))
78 -               vfree(sbi->s_flex_groups);
79 -       else
80 -               kfree(sbi->s_flex_groups);
81 +       ext4_kvfree(sbi->s_flex_groups);
82         percpu_counter_destroy(&sbi->s_freeblocks_counter);
83         percpu_counter_destroy(&sbi->s_freeinodes_counter);
84         percpu_counter_destroy(&sbi->s_dirs_counter);
85 @@ -1977,15 +2003,11 @@ static int ext4_fill_flex_info(struct super_block *sb)
86                         ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
87                               EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex;
88         size = flex_group_count * sizeof(struct flex_groups);
89 -       sbi->s_flex_groups = kzalloc(size, GFP_KERNEL);
90 +       sbi->s_flex_groups = ext4_kvzalloc(size, GFP_KERNEL);
91         if (sbi->s_flex_groups == NULL) {
92 -               sbi->s_flex_groups = vzalloc(size);
93 -               if (sbi->s_flex_groups == NULL) {
94 -                       ext4_msg(sb, KERN_ERR,
95 -                                "not enough memory for %u flex groups",
96 -                                flex_group_count);
97 -                       goto failed;
98 -               }
99 +               ext4_msg(sb, KERN_ERR, "not enough memory for %u flex groups",
100 +                        flex_group_count);
101 +               goto failed;
102         }
103
104         for (i = 0; i < sbi->s_groups_count; i++) {
105 @@ -3750,12 +3772,8 @@ failed_mount_wq:
106         }
107  failed_mount3:
108         del_timer(&sbi->s_err_report);
109 -       if (sbi->s_flex_groups) {
110 -               if (is_vmalloc_addr(sbi->s_flex_groups))
111 -                       vfree(sbi->s_flex_groups);
112 -               else
113 -                       kfree(sbi->s_flex_groups);
114 -       }
115 +       if (sbi->s_flex_groups)
116 +               ext4_kvfree(sbi->s_flex_groups);
117         percpu_counter_destroy(&sbi->s_freeblocks_counter);
118         percpu_counter_destroy(&sbi->s_freeinodes_counter);
119         percpu_counter_destroy(&sbi->s_dirs_counter);
120