@@ -4579,31 +4579,26 @@ static long ext4_zero_range(struct file *file, loff_t offset,
4579
4579
int ret , flags , credits ;
4580
4580
4581
4581
trace_ext4_zero_range (inode , offset , len , mode );
4582
+ WARN_ON_ONCE (!inode_is_locked (inode ));
4582
4583
4583
- inode_lock (inode );
4584
-
4585
- /*
4586
- * Indirect files do not support unwritten extents
4587
- */
4588
- if (!(ext4_test_inode_flag (inode , EXT4_INODE_EXTENTS ))) {
4589
- ret = - EOPNOTSUPP ;
4590
- goto out ;
4591
- }
4584
+ /* Indirect files do not support unwritten extents */
4585
+ if (!(ext4_test_inode_flag (inode , EXT4_INODE_EXTENTS )))
4586
+ return - EOPNOTSUPP ;
4592
4587
4593
4588
if (!(mode & FALLOC_FL_KEEP_SIZE ) &&
4594
4589
(end > inode -> i_size || end > EXT4_I (inode )-> i_disksize )) {
4595
4590
new_size = end ;
4596
4591
ret = inode_newsize_ok (inode , new_size );
4597
4592
if (ret )
4598
- goto out ;
4593
+ return ret ;
4599
4594
}
4600
4595
4601
4596
/* Wait all existing dio workers, newcomers will block on i_rwsem */
4602
4597
inode_dio_wait (inode );
4603
4598
4604
4599
ret = file_modified (file );
4605
4600
if (ret )
4606
- goto out ;
4601
+ return ret ;
4607
4602
4608
4603
/*
4609
4604
* Prevent page faults from reinstantiating pages we have released
@@ -4685,8 +4680,6 @@ static long ext4_zero_range(struct file *file, loff_t offset,
4685
4680
ext4_journal_stop (handle );
4686
4681
out_invalidate_lock :
4687
4682
filemap_invalidate_unlock (mapping );
4688
- out :
4689
- inode_unlock (inode );
4690
4683
return ret ;
4691
4684
}
4692
4685
@@ -4700,12 +4693,11 @@ static long ext4_do_fallocate(struct file *file, loff_t offset,
4700
4693
int ret ;
4701
4694
4702
4695
trace_ext4_fallocate_enter (inode , offset , len , mode );
4696
+ WARN_ON_ONCE (!inode_is_locked (inode ));
4703
4697
4704
4698
start_lblk = offset >> inode -> i_blkbits ;
4705
4699
len_lblk = EXT4_MAX_BLOCKS (len , offset , inode -> i_blkbits );
4706
4700
4707
- inode_lock (inode );
4708
-
4709
4701
/* We only support preallocation for extent-based files only. */
4710
4702
if (!(ext4_test_inode_flag (inode , EXT4_INODE_EXTENTS ))) {
4711
4703
ret = - EOPNOTSUPP ;
@@ -4737,7 +4729,6 @@ static long ext4_do_fallocate(struct file *file, loff_t offset,
4737
4729
EXT4_I (inode )-> i_sync_tid );
4738
4730
}
4739
4731
out :
4740
- inode_unlock (inode );
4741
4732
trace_ext4_fallocate_exit (inode , offset , len_lblk , ret );
4742
4733
return ret ;
4743
4734
}
@@ -4772,9 +4763,8 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
4772
4763
4773
4764
inode_lock (inode );
4774
4765
ret = ext4_convert_inline_data (inode );
4775
- inode_unlock (inode );
4776
4766
if (ret )
4777
- return ret ;
4767
+ goto out_inode_lock ;
4778
4768
4779
4769
if (mode & FALLOC_FL_PUNCH_HOLE )
4780
4770
ret = ext4_punch_hole (file , offset , len );
@@ -4786,7 +4776,8 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
4786
4776
ret = ext4_zero_range (file , offset , len , mode );
4787
4777
else
4788
4778
ret = ext4_do_fallocate (file , offset , len , mode );
4789
-
4779
+ out_inode_lock :
4780
+ inode_unlock (inode );
4790
4781
return ret ;
4791
4782
}
4792
4783
@@ -5291,36 +5282,27 @@ static int ext4_collapse_range(struct file *file, loff_t offset, loff_t len)
5291
5282
int ret ;
5292
5283
5293
5284
trace_ext4_collapse_range (inode , offset , len );
5294
-
5295
- inode_lock (inode );
5285
+ WARN_ON_ONCE (!inode_is_locked (inode ));
5296
5286
5297
5287
/* Currently just for extent based files */
5298
- if (!ext4_test_inode_flag (inode , EXT4_INODE_EXTENTS )) {
5299
- ret = - EOPNOTSUPP ;
5300
- goto out ;
5301
- }
5302
-
5288
+ if (!ext4_test_inode_flag (inode , EXT4_INODE_EXTENTS ))
5289
+ return - EOPNOTSUPP ;
5303
5290
/* Collapse range works only on fs cluster size aligned regions. */
5304
- if (!IS_ALIGNED (offset | len , EXT4_CLUSTER_SIZE (sb ))) {
5305
- ret = - EINVAL ;
5306
- goto out ;
5307
- }
5308
-
5291
+ if (!IS_ALIGNED (offset | len , EXT4_CLUSTER_SIZE (sb )))
5292
+ return - EINVAL ;
5309
5293
/*
5310
5294
* There is no need to overlap collapse range with EOF, in which case
5311
5295
* it is effectively a truncate operation
5312
5296
*/
5313
- if (end >= inode -> i_size ) {
5314
- ret = - EINVAL ;
5315
- goto out ;
5316
- }
5297
+ if (end >= inode -> i_size )
5298
+ return - EINVAL ;
5317
5299
5318
5300
/* Wait for existing dio to complete */
5319
5301
inode_dio_wait (inode );
5320
5302
5321
5303
ret = file_modified (file );
5322
5304
if (ret )
5323
- goto out ;
5305
+ return ret ;
5324
5306
5325
5307
/*
5326
5308
* Prevent page faults from reinstantiating pages we have released from
@@ -5395,8 +5377,6 @@ static int ext4_collapse_range(struct file *file, loff_t offset, loff_t len)
5395
5377
ext4_journal_stop (handle );
5396
5378
out_invalidate_lock :
5397
5379
filemap_invalidate_unlock (mapping );
5398
- out :
5399
- inode_unlock (inode );
5400
5380
return ret ;
5401
5381
}
5402
5382
@@ -5422,39 +5402,27 @@ static int ext4_insert_range(struct file *file, loff_t offset, loff_t len)
5422
5402
loff_t start ;
5423
5403
5424
5404
trace_ext4_insert_range (inode , offset , len );
5425
-
5426
- inode_lock (inode );
5405
+ WARN_ON_ONCE (!inode_is_locked (inode ));
5427
5406
5428
5407
/* Currently just for extent based files */
5429
- if (!ext4_test_inode_flag (inode , EXT4_INODE_EXTENTS )) {
5430
- ret = - EOPNOTSUPP ;
5431
- goto out ;
5432
- }
5433
-
5408
+ if (!ext4_test_inode_flag (inode , EXT4_INODE_EXTENTS ))
5409
+ return - EOPNOTSUPP ;
5434
5410
/* Insert range works only on fs cluster size aligned regions. */
5435
- if (!IS_ALIGNED (offset | len , EXT4_CLUSTER_SIZE (sb ))) {
5436
- ret = - EINVAL ;
5437
- goto out ;
5438
- }
5439
-
5411
+ if (!IS_ALIGNED (offset | len , EXT4_CLUSTER_SIZE (sb )))
5412
+ return - EINVAL ;
5440
5413
/* Offset must be less than i_size */
5441
- if (offset >= inode -> i_size ) {
5442
- ret = - EINVAL ;
5443
- goto out ;
5444
- }
5445
-
5414
+ if (offset >= inode -> i_size )
5415
+ return - EINVAL ;
5446
5416
/* Check whether the maximum file size would be exceeded */
5447
- if (len > inode -> i_sb -> s_maxbytes - inode -> i_size ) {
5448
- ret = - EFBIG ;
5449
- goto out ;
5450
- }
5417
+ if (len > inode -> i_sb -> s_maxbytes - inode -> i_size )
5418
+ return - EFBIG ;
5451
5419
5452
5420
/* Wait for existing dio to complete */
5453
5421
inode_dio_wait (inode );
5454
5422
5455
5423
ret = file_modified (file );
5456
5424
if (ret )
5457
- goto out ;
5425
+ return ret ;
5458
5426
5459
5427
/*
5460
5428
* Prevent page faults from reinstantiating pages we have released from
@@ -5555,8 +5523,6 @@ static int ext4_insert_range(struct file *file, loff_t offset, loff_t len)
5555
5523
ext4_journal_stop (handle );
5556
5524
out_invalidate_lock :
5557
5525
filemap_invalidate_unlock (mapping );
5558
- out :
5559
- inode_unlock (inode );
5560
5526
return ret ;
5561
5527
}
5562
5528
0 commit comments