Skip to content

Commit 461cb41

Browse files
AstralBobswhiteho
authored andcommitted
GFS2: Simplify gfs2_write_alloc_required
Function gfs2_write_alloc_required always returned zero as its return code. Therefore, it doesn't need to return a return code at all. Given that, we can use the return value to return whether or not the dinode needs block allocations rather than passing that value in, which in turn simplifies a bunch of error checking. Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent ba6e936 commit 461cb41

6 files changed

Lines changed: 14 additions & 35 deletions

File tree

‎fs/gfs2/aops.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
634634
}
635635
}
636636

637-
error = gfs2_write_alloc_required(ip, pos, len, &alloc_required);
638-
if (error)
639-
goto out_unlock;
637+
alloc_required = gfs2_write_alloc_required(ip, pos, len);
640638

641639
if (alloc_required || gfs2_is_jdata(ip))
642640
gfs2_write_calc_reserv(ip, len, &data_blocks, &ind_blocks);

‎fs/gfs2/bmap.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,53 +1244,48 @@ int gfs2_file_dealloc(struct gfs2_inode *ip)
12441244
* @ip: the file being written to
12451245
* @offset: the offset to write to
12461246
* @len: the number of bytes being written
1247-
* @alloc_required: set to 1 if an alloc is required, 0 otherwise
12481247
*
1249-
* Returns: errno
1248+
* Returns: 1 if an alloc is required, 0 otherwise
12501249
*/
12511250

12521251
int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
1253-
unsigned int len, int *alloc_required)
1252+
unsigned int len)
12541253
{
12551254
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
12561255
struct buffer_head bh;
12571256
unsigned int shift;
12581257
u64 lblock, lblock_stop, size;
12591258
u64 end_of_file;
12601259

1261-
*alloc_required = 0;
1262-
12631260
if (!len)
12641261
return 0;
12651262

12661263
if (gfs2_is_stuffed(ip)) {
12671264
if (offset + len >
12681265
sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode))
1269-
*alloc_required = 1;
1266+
return 1;
12701267
return 0;
12711268
}
12721269

1273-
*alloc_required = 1;
12741270
shift = sdp->sd_sb.sb_bsize_shift;
12751271
BUG_ON(gfs2_is_dir(ip));
12761272
end_of_file = (ip->i_disksize + sdp->sd_sb.sb_bsize - 1) >> shift;
12771273
lblock = offset >> shift;
12781274
lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift;
12791275
if (lblock_stop > end_of_file)
1280-
return 0;
1276+
return 1;
12811277

12821278
size = (lblock_stop - lblock) << shift;
12831279
do {
12841280
bh.b_state = 0;
12851281
bh.b_size = size;
12861282
gfs2_block_map(&ip->i_inode, lblock, &bh, 0);
12871283
if (!buffer_mapped(&bh))
1288-
return 0;
1284+
return 1;
12891285
size -= bh.b_size;
12901286
lblock += (bh.b_size >> ip->i_inode.i_blkbits);
12911287
} while(size > 0);
12921288

1293-
*alloc_required = 0;
12941289
return 0;
12951290
}
12961291

‎fs/gfs2/bmap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ int gfs2_truncatei(struct gfs2_inode *ip, u64 size);
5252
int gfs2_truncatei_resume(struct gfs2_inode *ip);
5353
int gfs2_file_dealloc(struct gfs2_inode *ip);
5454
int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
55-
unsigned int len, int *alloc_required);
55+
unsigned int len);
5656

5757
#endif /* __BMAP_DOT_H__ */

‎fs/gfs2/file.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
351351
unsigned long last_index;
352352
u64 pos = page->index << PAGE_CACHE_SHIFT;
353353
unsigned int data_blocks, ind_blocks, rblocks;
354-
int alloc_required = 0;
355354
struct gfs2_holder gh;
356355
struct gfs2_alloc *al;
357356
int ret;
@@ -364,8 +363,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
364363
set_bit(GLF_DIRTY, &ip->i_gl->gl_flags);
365364
set_bit(GIF_SW_PAGED, &ip->i_flags);
366365

367-
ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required);
368-
if (ret || !alloc_required)
366+
if (!gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE))
369367
goto out_unlock;
370368
ret = -ENOMEM;
371369
al = gfs2_alloc_get(ip);

‎fs/gfs2/quota.c‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -787,15 +787,9 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
787787
goto out;
788788

789789
for (x = 0; x < num_qd; x++) {
790-
int alloc_required;
791-
792790
offset = qd2offset(qda[x]);
793-
error = gfs2_write_alloc_required(ip, offset,
794-
sizeof(struct gfs2_quota),
795-
&alloc_required);
796-
if (error)
797-
goto out_gunlock;
798-
if (alloc_required)
791+
if (gfs2_write_alloc_required(ip, offset,
792+
sizeof(struct gfs2_quota)))
799793
nalloc++;
800794
}
801795

@@ -1584,10 +1578,7 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
15841578
goto out_i;
15851579

15861580
offset = qd2offset(qd);
1587-
error = gfs2_write_alloc_required(ip, offset, sizeof(struct gfs2_quota),
1588-
&alloc_required);
1589-
if (error)
1590-
goto out_i;
1581+
alloc_required = gfs2_write_alloc_required(ip, offset, sizeof(struct gfs2_quota));
15911582
if (alloc_required) {
15921583
al = gfs2_alloc_get(ip);
15931584
if (al == NULL)

‎fs/gfs2/super.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,6 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd)
342342
{
343343
struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
344344
struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
345-
int ar;
346-
int error;
347345

348346
if (ip->i_disksize < (8 << 20) || ip->i_disksize > (1 << 30) ||
349347
(ip->i_disksize & (sdp->sd_sb.sb_bsize - 1))) {
@@ -352,13 +350,12 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd)
352350
}
353351
jd->jd_blocks = ip->i_disksize >> sdp->sd_sb.sb_bsize_shift;
354352

355-
error = gfs2_write_alloc_required(ip, 0, ip->i_disksize, &ar);
356-
if (!error && ar) {
353+
if (gfs2_write_alloc_required(ip, 0, ip->i_disksize)) {
357354
gfs2_consist_inode(ip);
358-
error = -EIO;
355+
return -EIO;
359356
}
360357

361-
return error;
358+
return 0;
362359
}
363360

364361
/**

0 commit comments

Comments
 (0)