Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'jfs-6.17' of github.com:kleikamp/linux-shaggy

Pull jfs updates from Dave Kleikamp:
"Fixes and cleanups for JFS filesystem"

* tag 'jfs-6.17' of github.com:kleikamp/linux-shaggy:
jfs: fix metapage reference count leak in dbAllocCtl
jfs: stop using write_cache_pages
jfs: truncate good inode pages when hard link is 0
jfs: jfs_xtree: replace XT_GETPAGE macro with xt_getpage()
jfs: Regular file corruption check
jfs: upper bound check of tree index in dbAllocAG

+96 -69
+3
fs/jfs/file.c
··· 44 44 { 45 45 int rc; 46 46 47 + if (S_ISREG(inode->i_mode) && inode->i_size < 0) 48 + return -EIO; 49 + 47 50 if ((rc = dquot_file_open(inode, file))) 48 51 return rc; 49 52
+1 -1
fs/jfs/inode.c
··· 145 145 if (!inode->i_nlink && !is_bad_inode(inode)) { 146 146 dquot_initialize(inode); 147 147 148 + truncate_inode_pages_final(&inode->i_data); 148 149 if (JFS_IP(inode)->fileset == FILESYSTEM_I) { 149 150 struct inode *ipimap = JFS_SBI(inode->i_sb)->ipimap; 150 - truncate_inode_pages_final(&inode->i_data); 151 151 152 152 if (test_cflag(COMMIT_Freewmap, inode)) 153 153 jfs_free_zero_link(inode);
+9 -1
fs/jfs/jfs_dmap.c
··· 1389 1389 (1 << (L2LPERCTL - (bmp->db_agheight << 1))) / bmp->db_agwidth; 1390 1390 ti = bmp->db_agstart + bmp->db_agwidth * (agno & (agperlev - 1)); 1391 1391 1392 + if (ti < 0 || ti >= le32_to_cpu(dcp->nleafs)) { 1393 + jfs_error(bmp->db_ipbmap->i_sb, "Corrupt dmapctl page\n"); 1394 + release_metapage(mp); 1395 + return -EIO; 1396 + } 1397 + 1392 1398 /* dmap control page trees fan-out by 4 and a single allocation 1393 1399 * group may be described by 1 or 2 subtrees within the ag level 1394 1400 * dmap control page, depending upon the ag size. examine the ag's ··· 1815 1809 return -EIO; 1816 1810 dp = (struct dmap *) mp->data; 1817 1811 1818 - if (dp->tree.budmin < 0) 1812 + if (dp->tree.budmin < 0) { 1813 + release_metapage(mp); 1819 1814 return -EIO; 1815 + } 1820 1816 1821 1817 /* try to allocate the blocks. 1822 1818 */
+5 -3
fs/jfs/jfs_metapage.c
··· 421 421 } 422 422 423 423 static int metapage_write_folio(struct folio *folio, 424 - struct writeback_control *wbc, void *unused) 424 + struct writeback_control *wbc) 425 425 { 426 426 struct bio *bio = NULL; 427 427 int block_offset; /* block offset of mp within page */ ··· 550 550 struct writeback_control *wbc) 551 551 { 552 552 struct blk_plug plug; 553 + struct folio *folio = NULL; 553 554 int err; 554 555 555 556 blk_start_plug(&plug); 556 - err = write_cache_pages(mapping, wbc, metapage_write_folio, NULL); 557 + while ((folio = writeback_iter(mapping, wbc, folio, &err))) 558 + err = metapage_write_folio(folio, wbc); 557 559 blk_finish_plug(&plug); 558 560 559 561 return err; ··· 815 813 816 814 if (folio_clear_dirty_for_io(folio)) { 817 815 folio_get(folio); 818 - ret = metapage_write_folio(folio, &wbc, NULL); 816 + ret = metapage_write_folio(folio, &wbc); 819 817 if (ret == 0) 820 818 folio_wait_writeback(folio); 821 819 folio_put(folio);
+78 -64
fs/jfs/jfs_xtree.c
··· 49 49 50 50 #define XT_PAGE(IP, MP) BT_PAGE(IP, MP, xtpage_t, i_xtroot) 51 51 52 - /* get page buffer for specified block address */ 53 - /* ToDo: Replace this ugly macro with a function */ 54 - #define XT_GETPAGE(IP, BN, MP, SIZE, P, RC) \ 55 - do { \ 56 - BT_GETPAGE(IP, BN, MP, xtpage_t, SIZE, P, RC, i_xtroot); \ 57 - if (!(RC)) { \ 58 - if ((le16_to_cpu((P)->header.nextindex) < XTENTRYSTART) || \ 59 - (le16_to_cpu((P)->header.nextindex) > \ 60 - le16_to_cpu((P)->header.maxentry)) || \ 61 - (le16_to_cpu((P)->header.maxentry) > \ 62 - (((BN) == 0) ? XTROOTMAXSLOT : PSIZE >> L2XTSLOTSIZE))) { \ 63 - jfs_error((IP)->i_sb, \ 64 - "XT_GETPAGE: xtree page corrupt\n"); \ 65 - BT_PUTPAGE(MP); \ 66 - MP = NULL; \ 67 - RC = -EIO; \ 68 - } \ 69 - } \ 70 - } while (0) 71 - 72 52 /* for consistency */ 73 53 #define XT_PUTPAGE(MP) BT_PUTPAGE(MP) 74 54 ··· 93 113 94 114 static int xtSplitRoot(tid_t tid, struct inode *ip, 95 115 struct xtsplit * split, struct metapage ** rmpp); 116 + 117 + /* 118 + * xt_getpage() 119 + * 120 + * function: get the page buffer for a specified block address. 121 + * 122 + * parameters: 123 + * ip - pointer to the inode 124 + * bn - block number (s64) of the xtree page to be retrieved; 125 + * mp - pointer to a metapage pointer where the page buffer is returned; 126 + * 127 + * returns: 128 + * A pointer to the xtree page (xtpage_t) on success, -EIO on error. 129 + */ 130 + 131 + static inline xtpage_t *xt_getpage(struct inode *ip, s64 bn, struct metapage **mp) 132 + { 133 + xtpage_t *p; 134 + int rc; 135 + 136 + BT_GETPAGE(ip, bn, *mp, xtpage_t, PSIZE, p, rc, i_xtroot); 137 + 138 + if (rc) 139 + return ERR_PTR(rc); 140 + if ((le16_to_cpu(p->header.nextindex) < XTENTRYSTART) || 141 + (le16_to_cpu(p->header.nextindex) > 142 + le16_to_cpu(p->header.maxentry)) || 143 + (le16_to_cpu(p->header.maxentry) > 144 + ((bn == 0) ? XTROOTMAXSLOT : PSIZE >> L2XTSLOTSIZE))) { 145 + jfs_error(ip->i_sb, "xt_getpage: xtree page corrupt\n"); 146 + BT_PUTPAGE(*mp); 147 + *mp = NULL; 148 + return ERR_PTR(-EIO); 149 + } 150 + return p; 151 + } 96 152 97 153 /* 98 154 * xtLookup() ··· 232 216 int *cmpp, struct btstack * btstack, int flag) 233 217 { 234 218 struct jfs_inode_info *jfs_ip = JFS_IP(ip); 235 - int rc = 0; 236 219 int cmp = 1; /* init for empty page */ 237 220 s64 bn; /* block number */ 238 221 struct metapage *mp; /* page buffer */ ··· 267 252 */ 268 253 for (bn = 0;;) { 269 254 /* get/pin the page to search */ 270 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 271 - if (rc) 272 - return rc; 255 + p = xt_getpage(ip, bn, &mp); 256 + if (IS_ERR(p)) 257 + return PTR_ERR(p); 273 258 274 259 /* try sequential access heuristics with the previous 275 260 * access entry in target leaf page: ··· 822 807 * insert router entry in parent for new right child page <rp> 823 808 */ 824 809 /* get/pin the parent page <sp> */ 825 - XT_GETPAGE(ip, parent->bn, smp, PSIZE, sp, rc); 826 - if (rc) { 810 + sp = xt_getpage(ip, parent->bn, &smp); 811 + if (IS_ERR(sp)) { 827 812 XT_PUTPAGE(rcmp); 828 - return rc; 813 + return PTR_ERR(sp); 829 814 } 830 815 831 816 /* ··· 1077 1062 * update previous pointer of old next/right page of <sp> 1078 1063 */ 1079 1064 if (nextbn != 0) { 1080 - XT_GETPAGE(ip, nextbn, mp, PSIZE, p, rc); 1081 - if (rc) { 1065 + p = xt_getpage(ip, nextbn, &mp); 1066 + if (IS_ERR(p)) { 1082 1067 XT_PUTPAGE(rmp); 1083 - goto clean_up; 1068 + return PTR_ERR(p); 1084 1069 } 1085 1070 1086 1071 BT_MARK_DIRTY(mp, ip); ··· 1432 1417 return rc; 1433 1418 1434 1419 /* get back old page */ 1435 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 1436 - if (rc) 1437 - return rc; 1420 + p = xt_getpage(ip, bn, &mp); 1421 + if (IS_ERR(p)) 1422 + return PTR_ERR(p); 1438 1423 /* 1439 1424 * if leaf root has been split, original root has been 1440 1425 * copied to new child page, i.e., original entry now ··· 1448 1433 XT_PUTPAGE(mp); 1449 1434 1450 1435 /* get new child page */ 1451 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 1452 - if (rc) 1453 - return rc; 1436 + p = xt_getpage(ip, bn, &mp); 1437 + if (IS_ERR(p)) 1438 + return PTR_ERR(p); 1454 1439 1455 1440 BT_MARK_DIRTY(mp, ip); 1456 1441 if (!test_cflag(COMMIT_Nolink, ip)) { ··· 1726 1711 return rc; 1727 1712 1728 1713 /* get back old page */ 1729 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 1730 - if (rc) 1731 - return rc; 1714 + p = xt_getpage(ip, bn, &mp); 1715 + if (IS_ERR(p)) 1716 + return PTR_ERR(p); 1732 1717 /* 1733 1718 * if leaf root has been split, original root has been 1734 1719 * copied to new child page, i.e., original entry now ··· 1742 1727 XT_PUTPAGE(mp); 1743 1728 1744 1729 /* get new child page */ 1745 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 1746 - if (rc) 1747 - return rc; 1730 + p = xt_getpage(ip, bn, &mp); 1731 + if (IS_ERR(p)) 1732 + return PTR_ERR(p); 1748 1733 1749 1734 BT_MARK_DIRTY(mp, ip); 1750 1735 if (!test_cflag(COMMIT_Nolink, ip)) { ··· 1803 1788 XT_PUTPAGE(mp); 1804 1789 1805 1790 /* get new right page */ 1806 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 1807 - if (rc) 1808 - return rc; 1791 + p = xt_getpage(ip, bn, &mp); 1792 + if (IS_ERR(p)) 1793 + return PTR_ERR(p); 1809 1794 1810 1795 BT_MARK_DIRTY(mp, ip); 1811 1796 if (!test_cflag(COMMIT_Nolink, ip)) { ··· 1879 1864 return rc; 1880 1865 1881 1866 /* get back old page */ 1882 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 1883 - if (rc) 1884 - return rc; 1867 + p = xt_getpage(ip, bn, &mp); 1868 + if (IS_ERR(p)) 1869 + return PTR_ERR(p); 1885 1870 1886 1871 /* 1887 1872 * if leaf root has been split, original root has been ··· 1896 1881 XT_PUTPAGE(mp); 1897 1882 1898 1883 /* get new child page */ 1899 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 1900 - if (rc) 1901 - return rc; 1884 + p = xt_getpage(ip, bn, &mp); 1885 + if (IS_ERR(p)) 1886 + return PTR_ERR(p); 1902 1887 1903 1888 BT_MARK_DIRTY(mp, ip); 1904 1889 if (!test_cflag(COMMIT_Nolink, ip)) { ··· 2202 2187 */ 2203 2188 s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag) 2204 2189 { 2205 - int rc = 0; 2206 2190 s64 teof; 2207 2191 struct metapage *mp; 2208 2192 xtpage_t *p; ··· 2282 2268 * first access of each page: 2283 2269 */ 2284 2270 getPage: 2285 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 2286 - if (rc) 2287 - return rc; 2271 + p = xt_getpage(ip, bn, &mp); 2272 + if (IS_ERR(p)) 2273 + return PTR_ERR(p); 2288 2274 2289 2275 /* process entries backward from last index */ 2290 2276 index = le16_to_cpu(p->header.nextindex) - 1; ··· 2520 2506 2521 2507 /* get back the parent page */ 2522 2508 bn = parent->bn; 2523 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 2524 - if (rc) 2525 - return rc; 2509 + p = xt_getpage(ip, bn, &mp); 2510 + if (IS_ERR(p)) 2511 + return PTR_ERR(p); 2526 2512 2527 2513 index = parent->index; 2528 2514 ··· 2805 2791 * first access of each page: 2806 2792 */ 2807 2793 getPage: 2808 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 2809 - if (rc) 2810 - return rc; 2794 + p = xt_getpage(ip, bn, &mp); 2795 + if (IS_ERR(p)) 2796 + return PTR_ERR(p); 2811 2797 2812 2798 /* process entries backward from last index */ 2813 2799 index = le16_to_cpu(p->header.nextindex) - 1; ··· 2850 2836 2851 2837 /* get back the parent page */ 2852 2838 bn = parent->bn; 2853 - XT_GETPAGE(ip, bn, mp, PSIZE, p, rc); 2854 - if (rc) 2855 - return rc; 2839 + p = xt_getpage(ip, bn, &mp); 2840 + if (IS_ERR(p)) 2841 + return PTR_ERR(p); 2856 2842 2857 2843 index = parent->index; 2858 2844