@@ -29,6 +29,7 @@ static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset,
29
29
struct iomap * iomap , struct iomap * srcmap )
30
30
{
31
31
struct zonefs_inode_info * zi = ZONEFS_I (inode );
32
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
32
33
struct super_block * sb = inode -> i_sb ;
33
34
loff_t isize ;
34
35
@@ -46,7 +47,7 @@ static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset,
46
47
iomap -> length = length ;
47
48
} else {
48
49
iomap -> type = IOMAP_MAPPED ;
49
- iomap -> addr = (zi -> i_zsector << SECTOR_SHIFT ) + iomap -> offset ;
50
+ iomap -> addr = (z -> z_sector << SECTOR_SHIFT ) + iomap -> offset ;
50
51
iomap -> length = isize - iomap -> offset ;
51
52
}
52
53
mutex_unlock (& zi -> i_truncate_mutex );
@@ -65,19 +66,20 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset,
65
66
struct iomap * iomap , struct iomap * srcmap )
66
67
{
67
68
struct zonefs_inode_info * zi = ZONEFS_I (inode );
69
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
68
70
struct super_block * sb = inode -> i_sb ;
69
71
loff_t isize ;
70
72
71
73
/* All write I/Os should always be within the file maximum size */
72
- if (WARN_ON_ONCE (offset + length > zi -> i_max_size ))
74
+ if (WARN_ON_ONCE (offset + length > z -> z_capacity ))
73
75
return - EIO ;
74
76
75
77
/*
76
78
* Sequential zones can only accept direct writes. This is already
77
79
* checked when writes are issued, so warn if we see a page writeback
78
80
* operation.
79
81
*/
80
- if (WARN_ON_ONCE (zonefs_zone_is_seq (zi ) && !(flags & IOMAP_DIRECT )))
82
+ if (WARN_ON_ONCE (zonefs_zone_is_seq (z ) && !(flags & IOMAP_DIRECT )))
81
83
return - EIO ;
82
84
83
85
/*
@@ -88,11 +90,11 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset,
88
90
mutex_lock (& zi -> i_truncate_mutex );
89
91
iomap -> bdev = inode -> i_sb -> s_bdev ;
90
92
iomap -> offset = ALIGN_DOWN (offset , sb -> s_blocksize );
91
- iomap -> addr = (zi -> i_zsector << SECTOR_SHIFT ) + iomap -> offset ;
93
+ iomap -> addr = (z -> z_sector << SECTOR_SHIFT ) + iomap -> offset ;
92
94
isize = i_size_read (inode );
93
95
if (iomap -> offset >= isize ) {
94
96
iomap -> type = IOMAP_UNWRITTEN ;
95
- iomap -> length = zi -> i_max_size - iomap -> offset ;
97
+ iomap -> length = z -> z_capacity - iomap -> offset ;
96
98
} else {
97
99
iomap -> type = IOMAP_MAPPED ;
98
100
iomap -> length = isize - iomap -> offset ;
@@ -125,9 +127,9 @@ static void zonefs_readahead(struct readahead_control *rac)
125
127
static int zonefs_write_map_blocks (struct iomap_writepage_ctx * wpc ,
126
128
struct inode * inode , loff_t offset )
127
129
{
128
- struct zonefs_inode_info * zi = ZONEFS_I (inode );
130
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
129
131
130
- if (WARN_ON_ONCE (zonefs_zone_is_seq (zi )))
132
+ if (WARN_ON_ONCE (zonefs_zone_is_seq (z )))
131
133
return - EIO ;
132
134
if (WARN_ON_ONCE (offset >= i_size_read (inode )))
133
135
return - EIO ;
@@ -137,7 +139,8 @@ static int zonefs_write_map_blocks(struct iomap_writepage_ctx *wpc,
137
139
offset < wpc -> iomap .offset + wpc -> iomap .length )
138
140
return 0 ;
139
141
140
- return zonefs_write_iomap_begin (inode , offset , zi -> i_max_size - offset ,
142
+ return zonefs_write_iomap_begin (inode , offset ,
143
+ z -> z_capacity - offset ,
141
144
IOMAP_WRITE , & wpc -> iomap , NULL );
142
145
}
143
146
@@ -185,6 +188,7 @@ const struct address_space_operations zonefs_file_aops = {
185
188
int zonefs_file_truncate (struct inode * inode , loff_t isize )
186
189
{
187
190
struct zonefs_inode_info * zi = ZONEFS_I (inode );
191
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
188
192
loff_t old_isize ;
189
193
enum req_op op ;
190
194
int ret = 0 ;
@@ -194,12 +198,12 @@ int zonefs_file_truncate(struct inode *inode, loff_t isize)
194
198
* only down to a 0 size, which is equivalent to a zone reset, and to
195
199
* the maximum file size, which is equivalent to a zone finish.
196
200
*/
197
- if (!zonefs_zone_is_seq (zi ))
201
+ if (!zonefs_zone_is_seq (z ))
198
202
return - EPERM ;
199
203
200
204
if (!isize )
201
205
op = REQ_OP_ZONE_RESET ;
202
- else if (isize == zi -> i_max_size )
206
+ else if (isize == z -> z_capacity )
203
207
op = REQ_OP_ZONE_FINISH ;
204
208
else
205
209
return - EPERM ;
@@ -216,15 +220,15 @@ int zonefs_file_truncate(struct inode *inode, loff_t isize)
216
220
if (isize == old_isize )
217
221
goto unlock ;
218
222
219
- ret = zonefs_zone_mgmt (inode , op );
223
+ ret = zonefs_inode_zone_mgmt (inode , op );
220
224
if (ret )
221
225
goto unlock ;
222
226
223
227
/*
224
228
* If the mount option ZONEFS_MNTOPT_EXPLICIT_OPEN is set,
225
229
* take care of open zones.
226
230
*/
227
- if (zi -> i_flags & ZONEFS_ZONE_OPEN ) {
231
+ if (z -> z_flags & ZONEFS_ZONE_OPEN ) {
228
232
/*
229
233
* Truncating a zone to EMPTY or FULL is the equivalent of
230
234
* closing the zone. For a truncation to 0, we need to
@@ -234,15 +238,15 @@ int zonefs_file_truncate(struct inode *inode, loff_t isize)
234
238
* the open flag.
235
239
*/
236
240
if (!isize )
237
- ret = zonefs_zone_mgmt (inode , REQ_OP_ZONE_OPEN );
241
+ ret = zonefs_inode_zone_mgmt (inode , REQ_OP_ZONE_OPEN );
238
242
else
239
- zi -> i_flags &= ~ZONEFS_ZONE_OPEN ;
243
+ z -> z_flags &= ~ZONEFS_ZONE_OPEN ;
240
244
}
241
245
242
246
zonefs_update_stats (inode , isize );
243
247
truncate_setsize (inode , isize );
244
- zi -> i_wpoffset = isize ;
245
- zonefs_account_active (inode );
248
+ z -> z_wpoffset = isize ;
249
+ zonefs_inode_account_active (inode );
246
250
247
251
unlock :
248
252
mutex_unlock (& zi -> i_truncate_mutex );
@@ -349,7 +353,7 @@ static int zonefs_file_write_dio_end_io(struct kiocb *iocb, ssize_t size,
349
353
return error ;
350
354
}
351
355
352
- if (size && zonefs_zone_is_seq ( zi )) {
356
+ if (size && zonefs_inode_is_seq ( inode )) {
353
357
/*
354
358
* Note that we may be seeing completions out of order,
355
359
* but that is not a problem since a write completed
@@ -375,7 +379,7 @@ static const struct iomap_dio_ops zonefs_write_dio_ops = {
375
379
static ssize_t zonefs_file_dio_append (struct kiocb * iocb , struct iov_iter * from )
376
380
{
377
381
struct inode * inode = file_inode (iocb -> ki_filp );
378
- struct zonefs_inode_info * zi = ZONEFS_I (inode );
382
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
379
383
struct block_device * bdev = inode -> i_sb -> s_bdev ;
380
384
unsigned int max = bdev_max_zone_append_sectors (bdev );
381
385
struct bio * bio ;
@@ -392,7 +396,7 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)
392
396
393
397
bio = bio_alloc (bdev , nr_pages ,
394
398
REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE , GFP_NOFS );
395
- bio -> bi_iter .bi_sector = zi -> i_zsector ;
399
+ bio -> bi_iter .bi_sector = z -> z_sector ;
396
400
bio -> bi_ioprio = iocb -> ki_ioprio ;
397
401
if (iocb_is_dsync (iocb ))
398
402
bio -> bi_opf |= REQ_FUA ;
@@ -417,12 +421,12 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from)
417
421
*/
418
422
if (!ret ) {
419
423
sector_t wpsector =
420
- zi -> i_zsector + (zi -> i_wpoffset >> SECTOR_SHIFT );
424
+ z -> z_sector + (z -> z_wpoffset >> SECTOR_SHIFT );
421
425
422
426
if (bio -> bi_iter .bi_sector != wpsector ) {
423
427
zonefs_warn (inode -> i_sb ,
424
428
"Corrupted write pointer %llu for zone at %llu\n" ,
425
- wpsector , zi -> i_zsector );
429
+ wpsector , z -> z_sector );
426
430
ret = - EIO ;
427
431
}
428
432
}
@@ -450,9 +454,9 @@ static loff_t zonefs_write_check_limits(struct file *file, loff_t pos,
450
454
loff_t count )
451
455
{
452
456
struct inode * inode = file_inode (file );
453
- struct zonefs_inode_info * zi = ZONEFS_I (inode );
457
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
454
458
loff_t limit = rlimit (RLIMIT_FSIZE );
455
- loff_t max_size = zi -> i_max_size ;
459
+ loff_t max_size = z -> z_capacity ;
456
460
457
461
if (limit != RLIM_INFINITY ) {
458
462
if (pos >= limit ) {
@@ -476,6 +480,7 @@ static ssize_t zonefs_write_checks(struct kiocb *iocb, struct iov_iter *from)
476
480
struct file * file = iocb -> ki_filp ;
477
481
struct inode * inode = file_inode (file );
478
482
struct zonefs_inode_info * zi = ZONEFS_I (inode );
483
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
479
484
loff_t count ;
480
485
481
486
if (IS_SWAPFILE (inode ))
@@ -488,10 +493,10 @@ static ssize_t zonefs_write_checks(struct kiocb *iocb, struct iov_iter *from)
488
493
return - EINVAL ;
489
494
490
495
if (iocb -> ki_flags & IOCB_APPEND ) {
491
- if (zonefs_zone_is_cnv (zi ))
496
+ if (zonefs_zone_is_cnv (z ))
492
497
return - EINVAL ;
493
498
mutex_lock (& zi -> i_truncate_mutex );
494
- iocb -> ki_pos = zi -> i_wpoffset ;
499
+ iocb -> ki_pos = z -> z_wpoffset ;
495
500
mutex_unlock (& zi -> i_truncate_mutex );
496
501
}
497
502
@@ -518,6 +523,7 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from)
518
523
{
519
524
struct inode * inode = file_inode (iocb -> ki_filp );
520
525
struct zonefs_inode_info * zi = ZONEFS_I (inode );
526
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
521
527
struct super_block * sb = inode -> i_sb ;
522
528
bool sync = is_sync_kiocb (iocb );
523
529
bool append = false;
@@ -528,7 +534,7 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from)
528
534
* as this can cause write reordering (e.g. the first aio gets EAGAIN
529
535
* on the inode lock but the second goes through but is now unaligned).
530
536
*/
531
- if (zonefs_zone_is_seq (zi ) && !sync && (iocb -> ki_flags & IOCB_NOWAIT ))
537
+ if (zonefs_zone_is_seq (z ) && !sync && (iocb -> ki_flags & IOCB_NOWAIT ))
532
538
return - EOPNOTSUPP ;
533
539
534
540
if (iocb -> ki_flags & IOCB_NOWAIT ) {
@@ -550,9 +556,9 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from)
550
556
}
551
557
552
558
/* Enforce sequential writes (append only) in sequential zones */
553
- if (zonefs_zone_is_seq (zi )) {
559
+ if (zonefs_zone_is_seq (z )) {
554
560
mutex_lock (& zi -> i_truncate_mutex );
555
- if (iocb -> ki_pos != zi -> i_wpoffset ) {
561
+ if (iocb -> ki_pos != z -> z_wpoffset ) {
556
562
mutex_unlock (& zi -> i_truncate_mutex );
557
563
ret = - EINVAL ;
558
564
goto inode_unlock ;
@@ -566,7 +572,7 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from)
566
572
else
567
573
ret = iomap_dio_rw (iocb , from , & zonefs_write_iomap_ops ,
568
574
& zonefs_write_dio_ops , 0 , NULL , 0 );
569
- if (zonefs_zone_is_seq (zi ) &&
575
+ if (zonefs_zone_is_seq (z ) &&
570
576
(ret > 0 || ret == - EIOCBQUEUED )) {
571
577
if (ret > 0 )
572
578
count = ret ;
@@ -577,8 +583,8 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from)
577
583
* will correct it. Also do active seq file accounting.
578
584
*/
579
585
mutex_lock (& zi -> i_truncate_mutex );
580
- zi -> i_wpoffset += count ;
581
- zonefs_account_active (inode );
586
+ z -> z_wpoffset += count ;
587
+ zonefs_inode_account_active (inode );
582
588
mutex_unlock (& zi -> i_truncate_mutex );
583
589
}
584
590
@@ -629,15 +635,16 @@ static ssize_t zonefs_file_buffered_write(struct kiocb *iocb,
629
635
static ssize_t zonefs_file_write_iter (struct kiocb * iocb , struct iov_iter * from )
630
636
{
631
637
struct inode * inode = file_inode (iocb -> ki_filp );
638
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
632
639
633
640
if (unlikely (IS_IMMUTABLE (inode )))
634
641
return - EPERM ;
635
642
636
643
if (sb_rdonly (inode -> i_sb ))
637
644
return - EROFS ;
638
645
639
- /* Write operations beyond the zone size are not allowed */
640
- if (iocb -> ki_pos >= ZONEFS_I ( inode ) -> i_max_size )
646
+ /* Write operations beyond the zone capacity are not allowed */
647
+ if (iocb -> ki_pos >= z -> z_capacity )
641
648
return - EFBIG ;
642
649
643
650
if (iocb -> ki_flags & IOCB_DIRECT ) {
@@ -669,6 +676,7 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
669
676
{
670
677
struct inode * inode = file_inode (iocb -> ki_filp );
671
678
struct zonefs_inode_info * zi = ZONEFS_I (inode );
679
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
672
680
struct super_block * sb = inode -> i_sb ;
673
681
loff_t isize ;
674
682
ssize_t ret ;
@@ -677,7 +685,7 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
677
685
if (unlikely (IS_IMMUTABLE (inode ) && !(inode -> i_mode & 0777 )))
678
686
return - EPERM ;
679
687
680
- if (iocb -> ki_pos >= zi -> i_max_size )
688
+ if (iocb -> ki_pos >= z -> z_capacity )
681
689
return 0 ;
682
690
683
691
if (iocb -> ki_flags & IOCB_NOWAIT ) {
@@ -738,6 +746,7 @@ static inline bool zonefs_seq_file_need_wro(struct inode *inode,
738
746
static int zonefs_seq_file_write_open (struct inode * inode )
739
747
{
740
748
struct zonefs_inode_info * zi = ZONEFS_I (inode );
749
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
741
750
int ret = 0 ;
742
751
743
752
mutex_lock (& zi -> i_truncate_mutex );
@@ -755,14 +764,15 @@ static int zonefs_seq_file_write_open(struct inode *inode)
755
764
goto unlock ;
756
765
}
757
766
758
- if (i_size_read (inode ) < zi -> i_max_size ) {
759
- ret = zonefs_zone_mgmt (inode , REQ_OP_ZONE_OPEN );
767
+ if (i_size_read (inode ) < z -> z_capacity ) {
768
+ ret = zonefs_inode_zone_mgmt (inode ,
769
+ REQ_OP_ZONE_OPEN );
760
770
if (ret ) {
761
771
atomic_dec (& sbi -> s_wro_seq_files );
762
772
goto unlock ;
763
773
}
764
- zi -> i_flags |= ZONEFS_ZONE_OPEN ;
765
- zonefs_account_active (inode );
774
+ z -> z_flags |= ZONEFS_ZONE_OPEN ;
775
+ zonefs_inode_account_active (inode );
766
776
}
767
777
}
768
778
}
@@ -792,6 +802,7 @@ static int zonefs_file_open(struct inode *inode, struct file *file)
792
802
static void zonefs_seq_file_write_close (struct inode * inode )
793
803
{
794
804
struct zonefs_inode_info * zi = ZONEFS_I (inode );
805
+ struct zonefs_zone * z = zonefs_inode_zone (inode );
795
806
struct super_block * sb = inode -> i_sb ;
796
807
struct zonefs_sb_info * sbi = ZONEFS_SB (sb );
797
808
int ret = 0 ;
@@ -807,8 +818,8 @@ static void zonefs_seq_file_write_close(struct inode *inode)
807
818
* its maximum size or it was fully written). For this case, we only
808
819
* need to decrement the write open count.
809
820
*/
810
- if (zi -> i_flags & ZONEFS_ZONE_OPEN ) {
811
- ret = zonefs_zone_mgmt (inode , REQ_OP_ZONE_CLOSE );
821
+ if (z -> z_flags & ZONEFS_ZONE_OPEN ) {
822
+ ret = zonefs_inode_zone_mgmt (inode , REQ_OP_ZONE_CLOSE );
812
823
if (ret ) {
813
824
__zonefs_io_error (inode , false);
814
825
/*
@@ -817,20 +828,20 @@ static void zonefs_seq_file_write_close(struct inode *inode)
817
828
* exhausted). So take preventive action by remounting
818
829
* read-only.
819
830
*/
820
- if (zi -> i_flags & ZONEFS_ZONE_OPEN &&
831
+ if (z -> z_flags & ZONEFS_ZONE_OPEN &&
821
832
!(sb -> s_flags & SB_RDONLY )) {
822
833
zonefs_warn (sb ,
823
834
"closing zone at %llu failed %d\n" ,
824
- zi -> i_zsector , ret );
835
+ z -> z_sector , ret );
825
836
zonefs_warn (sb ,
826
837
"remounting filesystem read-only\n" );
827
838
sb -> s_flags |= SB_RDONLY ;
828
839
}
829
840
goto unlock ;
830
841
}
831
842
832
- zi -> i_flags &= ~ZONEFS_ZONE_OPEN ;
833
- zonefs_account_active (inode );
843
+ z -> z_flags &= ~ZONEFS_ZONE_OPEN ;
844
+ zonefs_inode_account_active (inode );
834
845
}
835
846
836
847
atomic_dec (& sbi -> s_wro_seq_files );
0 commit comments