hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/ext2/inode.c
....@@ -355,8 +355,7 @@
355355 * @blks: number of data blocks to be mapped.
356356 * @blocks_to_boundary: the offset in the indirect block
357357 *
358
- * return the total number of blocks to be allocate, including the
359
- * direct and indirect blocks.
358
+ * return the number of direct blocks to allocate.
360359 */
361360 static int
362361 ext2_blks_to_allocate(Indirect * branch, int k, unsigned long blks,
....@@ -389,11 +388,9 @@
389388 * ext2_alloc_blocks: multiple allocate blocks needed for a branch
390389 * @indirect_blks: the number of blocks need to allocate for indirect
391390 * blocks
392
- *
391
+ * @blks: the number of blocks need to allocate for direct blocks
393392 * @new_blocks: on return it will store the new block numbers for
394393 * the indirect blocks(if needed) and the first direct block,
395
- * @blks: on return it will store the total number of allocated
396
- * direct blocks
397394 */
398395 static int ext2_alloc_blocks(struct inode *inode,
399396 ext2_fsblk_t goal, int indirect_blks, int blks,
....@@ -451,7 +448,9 @@
451448 /**
452449 * ext2_alloc_branch - allocate and set up a chain of blocks.
453450 * @inode: owner
454
- * @num: depth of the chain (number of blocks to allocate)
451
+ * @indirect_blks: depth of the chain (number of blocks to allocate)
452
+ * @blks: number of allocated direct blocks
453
+ * @goal: preferred place for allocation
455454 * @offsets: offsets (in the blocks) to store the pointers to next.
456455 * @branch: place to store the chain in.
457456 *
....@@ -720,7 +719,7 @@
720719 /* the number of blocks need to allocate for [d,t]indirect blocks */
721720 indirect_blks = (chain + depth) - partial - 1;
722721 /*
723
- * Next look up the indirect map to count the totoal number of
722
+ * Next look up the indirect map to count the total number of
724723 * direct blocks to allocate for this branch.
725724 */
726725 count = ext2_blks_to_allocate(partial, indirect_blks,
....@@ -802,7 +801,7 @@
802801
803802 #ifdef CONFIG_FS_DAX
804803 static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
805
- unsigned flags, struct iomap *iomap)
804
+ unsigned flags, struct iomap *iomap, struct iomap *srcmap)
806805 {
807806 unsigned int blkbits = inode->i_blkbits;
808807 unsigned long first_block = offset >> blkbits;
....@@ -875,11 +874,9 @@
875874 return mpage_readpage(page, ext2_get_block);
876875 }
877876
878
-static int
879
-ext2_readpages(struct file *file, struct address_space *mapping,
880
- struct list_head *pages, unsigned nr_pages)
877
+static void ext2_readahead(struct readahead_control *rac)
881878 {
882
- return mpage_readpages(mapping, pages, nr_pages, ext2_get_block);
879
+ mpage_readahead(rac, ext2_get_block);
883880 }
884881
885882 static int
....@@ -958,13 +955,14 @@
958955 static int
959956 ext2_dax_writepages(struct address_space *mapping, struct writeback_control *wbc)
960957 {
961
- return dax_writeback_mapping_range(mapping,
962
- mapping->host->i_sb->s_bdev, wbc);
958
+ struct ext2_sb_info *sbi = EXT2_SB(mapping->host->i_sb);
959
+
960
+ return dax_writeback_mapping_range(mapping, sbi->s_daxdev, wbc);
963961 }
964962
965963 const struct address_space_operations ext2_aops = {
966964 .readpage = ext2_readpage,
967
- .readpages = ext2_readpages,
965
+ .readahead = ext2_readahead,
968966 .writepage = ext2_writepage,
969967 .write_begin = ext2_write_begin,
970968 .write_end = ext2_write_end,
....@@ -978,7 +976,7 @@
978976
979977 const struct address_space_operations ext2_nobh_aops = {
980978 .readpage = ext2_readpage,
981
- .readpages = ext2_readpages,
979
+ .readahead = ext2_readahead,
982980 .writepage = ext2_nobh_writepage,
983981 .write_begin = ext2_nobh_write_begin,
984982 .write_end = nobh_write_end,
....@@ -1242,6 +1240,7 @@
12421240 mark_inode_dirty(inode);
12431241 ext2_free_branches(inode, &nr, &nr+1, 1);
12441242 }
1243
+ fallthrough;
12451244 case EXT2_IND_BLOCK:
12461245 nr = i_data[EXT2_DIND_BLOCK];
12471246 if (nr) {
....@@ -1249,6 +1248,7 @@
12491248 mark_inode_dirty(inode);
12501249 ext2_free_branches(inode, &nr, &nr+1, 2);
12511250 }
1251
+ fallthrough;
12521252 case EXT2_DIND_BLOCK:
12531253 nr = i_data[EXT2_TIND_BLOCK];
12541254 if (nr) {
....@@ -1399,7 +1399,7 @@
13991399 struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
14001400 {
14011401 struct ext2_inode_info *ei;
1402
- struct buffer_head * bh;
1402
+ struct buffer_head * bh = NULL;
14031403 struct ext2_inode *raw_inode;
14041404 struct inode *inode;
14051405 long ret = -EIO;
....@@ -1445,7 +1445,6 @@
14451445 */
14461446 if (inode->i_nlink == 0 && (inode->i_mode == 0 || ei->i_dtime)) {
14471447 /* this inode is deleted */
1448
- brelse (bh);
14491448 ret = -ESTALE;
14501449 goto bad_inode;
14511450 }
....@@ -1462,7 +1461,6 @@
14621461 !ext2_data_block_valid(EXT2_SB(sb), ei->i_file_acl, 1)) {
14631462 ext2_error(sb, "ext2_iget", "bad extended attribute block %u",
14641463 ei->i_file_acl);
1465
- brelse(bh);
14661464 ret = -EFSCORRUPTED;
14671465 goto bad_inode;
14681466 }
....@@ -1525,6 +1523,7 @@
15251523 return inode;
15261524
15271525 bad_inode:
1526
+ brelse(bh);
15281527 iget_failed(inode);
15291528 return ERR_PTR(ret);
15301529 }
....@@ -1638,6 +1637,32 @@
16381637 return __ext2_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
16391638 }
16401639
1640
+int ext2_getattr(const struct path *path, struct kstat *stat,
1641
+ u32 request_mask, unsigned int query_flags)
1642
+{
1643
+ struct inode *inode = d_inode(path->dentry);
1644
+ struct ext2_inode_info *ei = EXT2_I(inode);
1645
+ unsigned int flags;
1646
+
1647
+ flags = ei->i_flags & EXT2_FL_USER_VISIBLE;
1648
+ if (flags & EXT2_APPEND_FL)
1649
+ stat->attributes |= STATX_ATTR_APPEND;
1650
+ if (flags & EXT2_COMPR_FL)
1651
+ stat->attributes |= STATX_ATTR_COMPRESSED;
1652
+ if (flags & EXT2_IMMUTABLE_FL)
1653
+ stat->attributes |= STATX_ATTR_IMMUTABLE;
1654
+ if (flags & EXT2_NODUMP_FL)
1655
+ stat->attributes |= STATX_ATTR_NODUMP;
1656
+ stat->attributes_mask |= (STATX_ATTR_APPEND |
1657
+ STATX_ATTR_COMPRESSED |
1658
+ STATX_ATTR_ENCRYPTED |
1659
+ STATX_ATTR_IMMUTABLE |
1660
+ STATX_ATTR_NODUMP);
1661
+
1662
+ generic_fillattr(inode, stat);
1663
+ return 0;
1664
+}
1665
+
16411666 int ext2_setattr(struct dentry *dentry, struct iattr *iattr)
16421667 {
16431668 struct inode *inode = d_inode(dentry);