Remove trailing whitespace from "allow read-only mouts with corrupted
[ext4-patch-queue.git] / sync_up_block_and_inode_bitmap_reading_functions
blobc8f35c76f766f4e75ba15173218c5b7af83cd103
1 sync up block & inode bitmap reading functions
3 From: Eric Sandeen <sandeen@redhat.com>
5 ext4_read_block_bitmap and read_inode_bitmap do essentially
6 the same thing, and yet they are structured quite differently.
7 I came across this difference while looking at doing bg locking
8 during bg initialization.
10 This patch:
12 * removes unnecessary casts in the error messages
13 * renames read_inode_bitmap to ext4_read_inode_bitmap
14 * and more substantially, restructures the inode bitmap
15   reading function to be more like the block bitmap counterpart.
17 The change to the inode bitmap reader simplifies the locking
18 to be applied in the next patch.
20 Signed-off-by: Eric Sandeen <sandeen@redhat.com>
21 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
23 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
24 index 63e5658..b18d590 100644
25 --- a/fs/ext4/balloc.c
26 +++ b/fs/ext4/balloc.c
27 @@ -314,8 +314,8 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
28         if (unlikely(!bh)) {
29                 ext4_error(sb, __func__,
30                             "Cannot read block bitmap - "
31 -                           "block_group = %d, block_bitmap = %llu",
32 -                           (int)block_group, (unsigned long long)bitmap_blk);
33 +                           "block_group = %lu, block_bitmap = %llu",
34 +                           block_group, bitmap_blk);
35                 return NULL;
36         }
37         if (bh_uptodate_or_lock(bh))
38 @@ -331,8 +331,8 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
39                 put_bh(bh);
40                 ext4_error(sb, __func__,
41                             "Cannot read block bitmap - "
42 -                           "block_group = %d, block_bitmap = %llu",
43 -                           (int)block_group, (unsigned long long)bitmap_blk);
44 +                           "block_group = %lu, block_bitmap = %llu",
45 +                           block_group, bitmap_blk);
46                 return NULL;
47         }
48         ext4_valid_block_bitmap(sb, desc, block_group, bh);
49 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
50 index a92eb30..09cdcd5 100644
51 --- a/fs/ext4/ialloc.c
52 +++ b/fs/ext4/ialloc.c
53 @@ -97,34 +97,41 @@ unsigned ext4_init_inode_bitmap(struct super_block *sb, struct buffer_head *bh,
54   * Return buffer_head of bitmap on success or NULL.
55   */
56  static struct buffer_head *
57 -read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
58 +ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
59  {
60         struct ext4_group_desc *desc;
61         struct buffer_head *bh = NULL;
62 +       ext4_fsblk_t bitmap_blk;
64         desc = ext4_get_group_desc(sb, block_group, NULL);
65         if (!desc)
66 -               goto error_out;
67 +               return NULL;
68 +       bitmap_blk = ext4_inode_bitmap(sb, desc);
69 +       bh = sb_getblk(sb, bitmap_blk);
70 +       if (unlikely(!bh)) {
71 +               ext4_error(sb, __func__,
72 +                           "Cannot read inode bitmap - "
73 +                           "block_group = %lu, inode_bitmap = %llu",
74 +                           block_group, bitmap_blk);
75 +               return NULL;
76 +       }
77 +       if (bh_uptodate_or_lock(bh))
78 +               return bh;
80         if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {
81 -               bh = sb_getblk(sb, ext4_inode_bitmap(sb, desc));
82 -               if (!buffer_uptodate(bh)) {
83 -                       lock_buffer(bh);
84 -                       if (!buffer_uptodate(bh)) {
85 -                               ext4_init_inode_bitmap(sb, bh, block_group,
86 -                                                      desc);
87 -                               set_buffer_uptodate(bh);
88 -                       }
89 -                       unlock_buffer(bh);
90 -               }
91 -       } else {
92 -               bh = sb_bread(sb, ext4_inode_bitmap(sb, desc));
93 +               ext4_init_inode_bitmap(sb, bh, block_group, desc);
94 +               set_buffer_uptodate(bh);
95 +               unlock_buffer(bh);
96 +               return bh;
97         }
98 -       if (!bh)
99 -               ext4_error(sb, "read_inode_bitmap",
100 +       if (bh_submit_read(bh) < 0) {
101 +               put_bh(bh);
102 +               ext4_error(sb, __func__,
103                             "Cannot read inode bitmap - "
104                             "block_group = %lu, inode_bitmap = %llu",
105 -                           block_group, ext4_inode_bitmap(sb, desc));
106 -error_out:
107 +                           block_group, bitmap_blk);
108 +               return NULL;
109 +       }
110         return bh;
113 @@ -200,7 +207,7 @@ void ext4_free_inode (handle_t *handle, struct inode * inode)
114         }
115         block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
116         bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
117 -       bitmap_bh = read_inode_bitmap(sb, block_group);
118 +       bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
119         if (!bitmap_bh)
120                 goto error_return;
122 @@ -623,7 +630,7 @@ got_group:
123                         goto fail;
125                 brelse(bitmap_bh);
126 -               bitmap_bh = read_inode_bitmap(sb, group);
127 +               bitmap_bh = ext4_read_inode_bitmap(sb, group);
128                 if (!bitmap_bh)
129                         goto fail;
131 @@ -891,7 +898,7 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
133         block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
134         bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
135 -       bitmap_bh = read_inode_bitmap(sb, block_group);
136 +       bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
137         if (!bitmap_bh) {
138                 ext4_warning(sb, __func__,
139                              "inode bitmap error for orphan %lu", ino);
140 @@ -969,7 +976,7 @@ unsigned long ext4_count_free_inodes (struct super_block * sb)
141                         continue;
142                 desc_count += le16_to_cpu(gdp->bg_free_inodes_count);
143                 brelse(bitmap_bh);
144 -               bitmap_bh = read_inode_bitmap(sb, i);
145 +               bitmap_bh = ext4_read_inode_bitmap(sb, i);
146                 if (!bitmap_bh)
147                         continue;