CC: kbuild-all(a)lists.01.org CC: "Darrick J. Wong" CC: linux-kernel(a)vger.kernel.org TO: "Darrick J. Wong" tree: https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git vectorized-scrub head: 142ad7efefdd71fa40628c868530a9357c18ba27 commit: c41e19cbde3dd4d20aaf146a82f4cb8dfa5944f7 [260/303] xfs: wire up realtime refcount btree cursors :::::: branch date: 21 hours ago :::::: commit date: 21 hours ago config: x86_64-randconfig-m001-20210816 (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot Reported-by: Dan Carpenter New smatch warnings: fs/xfs/xfs_reflink.c:169 xfs_reflink_find_shared() warn: variable dereferenced before check 'agbp' (see line 161) Old smatch warnings: fs/xfs/xfs_reflink.c:651 xfs_reflink_end_cow_extent() warn: missing error code 'error' vim +/agbp +169 fs/xfs/xfs_reflink.c 3993baeb3c52f4 Darrick J. Wong 2016-10-03 34 3993baeb3c52f4 Darrick J. Wong 2016-10-03 35 /* 3993baeb3c52f4 Darrick J. Wong 2016-10-03 36 * Copy on Write of Shared Blocks 3993baeb3c52f4 Darrick J. Wong 2016-10-03 37 * 3993baeb3c52f4 Darrick J. Wong 2016-10-03 38 * XFS must preserve "the usual" file semantics even when two files share 3993baeb3c52f4 Darrick J. Wong 2016-10-03 39 * the same physical blocks. This means that a write to one file must not 3993baeb3c52f4 Darrick J. Wong 2016-10-03 40 * alter the blocks in a different file; the way that we'll do that is 3993baeb3c52f4 Darrick J. Wong 2016-10-03 41 * through the use of a copy-on-write mechanism. At a high level, that 3993baeb3c52f4 Darrick J. Wong 2016-10-03 42 * means that when we want to write to a shared block, we allocate a new 3993baeb3c52f4 Darrick J. Wong 2016-10-03 43 * block, write the data to the new block, and if that succeeds we map the 3993baeb3c52f4 Darrick J. Wong 2016-10-03 44 * new block into the file. 3993baeb3c52f4 Darrick J. Wong 2016-10-03 45 * 3993baeb3c52f4 Darrick J. Wong 2016-10-03 46 * XFS provides a "delayed allocation" mechanism that defers the allocation 3993baeb3c52f4 Darrick J. Wong 2016-10-03 47 * of disk blocks to dirty-but-not-yet-mapped file blocks as long as 3993baeb3c52f4 Darrick J. Wong 2016-10-03 48 * possible. This reduces fragmentation by enabling the filesystem to ask 3993baeb3c52f4 Darrick J. Wong 2016-10-03 49 * for bigger chunks less often, which is exactly what we want for CoW. 3993baeb3c52f4 Darrick J. Wong 2016-10-03 50 * 3993baeb3c52f4 Darrick J. Wong 2016-10-03 51 * The delalloc mechanism begins when the kernel wants to make a block 3993baeb3c52f4 Darrick J. Wong 2016-10-03 52 * writable (write_begin or page_mkwrite). If the offset is not mapped, we 3993baeb3c52f4 Darrick J. Wong 2016-10-03 53 * create a delalloc mapping, which is a regular in-core extent, but without 3993baeb3c52f4 Darrick J. Wong 2016-10-03 54 * a real startblock. (For delalloc mappings, the startblock encodes both 3993baeb3c52f4 Darrick J. Wong 2016-10-03 55 * a flag that this is a delalloc mapping, and a worst-case estimate of how 3993baeb3c52f4 Darrick J. Wong 2016-10-03 56 * many blocks might be required to put the mapping into the BMBT.) delalloc 3993baeb3c52f4 Darrick J. Wong 2016-10-03 57 * mappings are a reservation against the free space in the filesystem; 3993baeb3c52f4 Darrick J. Wong 2016-10-03 58 * adjacent mappings can also be combined into fewer larger mappings. 3993baeb3c52f4 Darrick J. Wong 2016-10-03 59 * 5eda43000064a6 Darrick J. Wong 2017-02-02 60 * As an optimization, the CoW extent size hint (cowextsz) creates 5eda43000064a6 Darrick J. Wong 2017-02-02 61 * outsized aligned delalloc reservations in the hope of landing out of 5eda43000064a6 Darrick J. Wong 2017-02-02 62 * order nearby CoW writes in a single extent on disk, thereby reducing 5eda43000064a6 Darrick J. Wong 2017-02-02 63 * fragmentation and improving future performance. 5eda43000064a6 Darrick J. Wong 2017-02-02 64 * 5eda43000064a6 Darrick J. Wong 2017-02-02 65 * D: --RRRRRRSSSRRRRRRRR--- (data fork) 5eda43000064a6 Darrick J. Wong 2017-02-02 66 * C: ------DDDDDDD--------- (CoW fork) 5eda43000064a6 Darrick J. Wong 2017-02-02 67 * 3993baeb3c52f4 Darrick J. Wong 2016-10-03 68 * When dirty pages are being written out (typically in writepage), the 5eda43000064a6 Darrick J. Wong 2017-02-02 69 * delalloc reservations are converted into unwritten mappings by 5eda43000064a6 Darrick J. Wong 2017-02-02 70 * allocating blocks and replacing the delalloc mapping with real ones. 5eda43000064a6 Darrick J. Wong 2017-02-02 71 * A delalloc mapping can be replaced by several unwritten ones if the 5eda43000064a6 Darrick J. Wong 2017-02-02 72 * free space is fragmented. 5eda43000064a6 Darrick J. Wong 2017-02-02 73 * 5eda43000064a6 Darrick J. Wong 2017-02-02 74 * D: --RRRRRRSSSRRRRRRRR--- 5eda43000064a6 Darrick J. Wong 2017-02-02 75 * C: ------UUUUUUU--------- 3993baeb3c52f4 Darrick J. Wong 2016-10-03 76 * 3993baeb3c52f4 Darrick J. Wong 2016-10-03 77 * We want to adapt the delalloc mechanism for copy-on-write, since the 3993baeb3c52f4 Darrick J. Wong 2016-10-03 78 * write paths are similar. The first two steps (creating the reservation 3993baeb3c52f4 Darrick J. Wong 2016-10-03 79 * and allocating the blocks) are exactly the same as delalloc except that 3993baeb3c52f4 Darrick J. Wong 2016-10-03 80 * the mappings must be stored in a separate CoW fork because we do not want 3993baeb3c52f4 Darrick J. Wong 2016-10-03 81 * to disturb the mapping in the data fork until we're sure that the write 3993baeb3c52f4 Darrick J. Wong 2016-10-03 82 * succeeded. IO completion in this case is the process of removing the old 3993baeb3c52f4 Darrick J. Wong 2016-10-03 83 * mapping from the data fork and moving the new mapping from the CoW fork to 3993baeb3c52f4 Darrick J. Wong 2016-10-03 84 * the data fork. This will be discussed shortly. 3993baeb3c52f4 Darrick J. Wong 2016-10-03 85 * 3993baeb3c52f4 Darrick J. Wong 2016-10-03 86 * For now, unaligned directio writes will be bounced back to the page cache. 3993baeb3c52f4 Darrick J. Wong 2016-10-03 87 * Block-aligned directio writes will use the same mechanism as buffered 3993baeb3c52f4 Darrick J. Wong 2016-10-03 88 * writes. 3993baeb3c52f4 Darrick J. Wong 2016-10-03 89 * 5eda43000064a6 Darrick J. Wong 2017-02-02 90 * Just prior to submitting the actual disk write requests, we convert 5eda43000064a6 Darrick J. Wong 2017-02-02 91 * the extents representing the range of the file actually being written 5eda43000064a6 Darrick J. Wong 2017-02-02 92 * (as opposed to extra pieces created for the cowextsize hint) to real 5eda43000064a6 Darrick J. Wong 2017-02-02 93 * extents. This will become important in the next step: 5eda43000064a6 Darrick J. Wong 2017-02-02 94 * 5eda43000064a6 Darrick J. Wong 2017-02-02 95 * D: --RRRRRRSSSRRRRRRRR--- 5eda43000064a6 Darrick J. Wong 2017-02-02 96 * C: ------UUrrUUU--------- 5eda43000064a6 Darrick J. Wong 2017-02-02 97 * 3993baeb3c52f4 Darrick J. Wong 2016-10-03 98 * CoW remapping must be done after the data block write completes, 3993baeb3c52f4 Darrick J. Wong 2016-10-03 99 * because we don't want to destroy the old data fork map until we're sure 3993baeb3c52f4 Darrick J. Wong 2016-10-03 100 * the new block has been written. Since the new mappings are kept in a 3993baeb3c52f4 Darrick J. Wong 2016-10-03 101 * separate fork, we can simply iterate these mappings to find the ones 3993baeb3c52f4 Darrick J. Wong 2016-10-03 102 * that cover the file blocks that we just CoW'd. For each extent, simply 3993baeb3c52f4 Darrick J. Wong 2016-10-03 103 * unmap the corresponding range in the data fork, map the new range into 5eda43000064a6 Darrick J. Wong 2017-02-02 104 * the data fork, and remove the extent from the CoW fork. Because of 5eda43000064a6 Darrick J. Wong 2017-02-02 105 * the presence of the cowextsize hint, however, we must be careful 5eda43000064a6 Darrick J. Wong 2017-02-02 106 * only to remap the blocks that we've actually written out -- we must 5eda43000064a6 Darrick J. Wong 2017-02-02 107 * never remap delalloc reservations nor CoW staging blocks that have 5eda43000064a6 Darrick J. Wong 2017-02-02 108 * yet to be written. This corresponds exactly to the real extents in 5eda43000064a6 Darrick J. Wong 2017-02-02 109 * the CoW fork: 5eda43000064a6 Darrick J. Wong 2017-02-02 110 * 5eda43000064a6 Darrick J. Wong 2017-02-02 111 * D: --RRRRRRrrSRRRRRRRR--- 5eda43000064a6 Darrick J. Wong 2017-02-02 112 * C: ------UU--UUU--------- 3993baeb3c52f4 Darrick J. Wong 2016-10-03 113 * 3993baeb3c52f4 Darrick J. Wong 2016-10-03 114 * Since the remapping operation can be applied to an arbitrary file 3993baeb3c52f4 Darrick J. Wong 2016-10-03 115 * range, we record the need for the remap step as a flag in the ioend 3993baeb3c52f4 Darrick J. Wong 2016-10-03 116 * instead of declaring a new IO type. This is required for direct io 3993baeb3c52f4 Darrick J. Wong 2016-10-03 117 * because we only have ioend for the whole dio, and we have to be able to 3993baeb3c52f4 Darrick J. Wong 2016-10-03 118 * remember the presence of unwritten blocks and CoW blocks with a single 3993baeb3c52f4 Darrick J. Wong 2016-10-03 119 * ioend structure. Better yet, the more ground we can cover with one 3993baeb3c52f4 Darrick J. Wong 2016-10-03 120 * ioend, the better. 3993baeb3c52f4 Darrick J. Wong 2016-10-03 121 */ 2a06705cd59540 Darrick J. Wong 2016-10-03 122 2a06705cd59540 Darrick J. Wong 2016-10-03 123 /* 2a916659ca4d4a Darrick J. Wong 2021-01-05 124 * Given an AG extent, find the lowest-numbered run of shared blocks within 2a916659ca4d4a Darrick J. Wong 2021-01-05 125 * that range and return the range in fbno/flen. If find_end_of_shared is 2a916659ca4d4a Darrick J. Wong 2021-01-05 126 * true, return the longest contiguous extent of shared blocks. If there are 2a916659ca4d4a Darrick J. Wong 2021-01-05 127 * no shared extents, fbno and flen will be set to NULLFSBLOCK and 0, 2a916659ca4d4a Darrick J. Wong 2021-01-05 128 * respectively. 2a06705cd59540 Darrick J. Wong 2016-10-03 129 */ 2a916659ca4d4a Darrick J. Wong 2021-01-05 130 STATIC int 2a06705cd59540 Darrick J. Wong 2016-10-03 131 xfs_reflink_find_shared( 2a916659ca4d4a Darrick J. Wong 2021-01-05 132 struct xfs_inode *ip, 92ff7285f1df55 Darrick J. Wong 2017-06-16 133 struct xfs_trans *tp, 2a916659ca4d4a Darrick J. Wong 2021-01-05 134 struct xfs_bmbt_irec *irec, 2a916659ca4d4a Darrick J. Wong 2021-01-05 135 xfs_fsblock_t *fbno, 2a916659ca4d4a Darrick J. Wong 2021-01-05 136 xfs_filblks_t *flen, 2a06705cd59540 Darrick J. Wong 2016-10-03 137 bool find_end_of_shared) 2a06705cd59540 Darrick J. Wong 2016-10-03 138 { 2a916659ca4d4a Darrick J. Wong 2021-01-05 139 struct xfs_mount *mp = ip->i_mount; c41e19cbde3dd4 Darrick J. Wong 2021-01-05 140 struct xfs_buf *agbp = NULL; 2a06705cd59540 Darrick J. Wong 2016-10-03 141 struct xfs_btree_cur *cur; 2a916659ca4d4a Darrick J. Wong 2021-01-05 142 xfs_agnumber_t agno; a42a3ab16973ba Darrick J. Wong 2021-01-05 143 xfs_fsblock_t agbno; a42a3ab16973ba Darrick J. Wong 2021-01-05 144 xfs_fsblock_t shared_bno; a42a3ab16973ba Darrick J. Wong 2021-01-05 145 xfs_filblks_t shared_len; 2a06705cd59540 Darrick J. Wong 2016-10-03 146 int error; 2a06705cd59540 Darrick J. Wong 2016-10-03 147 c41e19cbde3dd4 Darrick J. Wong 2021-01-05 148 if (XFS_IS_REALTIME_INODE(ip)) { c41e19cbde3dd4 Darrick J. Wong 2021-01-05 149 agno = NULLAGNUMBER; c41e19cbde3dd4 Darrick J. Wong 2021-01-05 150 agbno = irec->br_startblock; c41e19cbde3dd4 Darrick J. Wong 2021-01-05 151 xfs_rtlock(NULL, mp, XFS_RTLOCK_REFCOUNT); c41e19cbde3dd4 Darrick J. Wong 2021-01-05 152 cur = xfs_rtrefcountbt_init_cursor(mp, tp, mp->m_rrefcountip); c41e19cbde3dd4 Darrick J. Wong 2021-01-05 153 } else { 2a916659ca4d4a Darrick J. Wong 2021-01-05 154 agno = XFS_FSB_TO_AGNO(mp, irec->br_startblock); 2a916659ca4d4a Darrick J. Wong 2021-01-05 155 agbno = XFS_FSB_TO_AGBNO(mp, irec->br_startblock); 2a916659ca4d4a Darrick J. Wong 2021-01-05 156 92ff7285f1df55 Darrick J. Wong 2017-06-16 157 error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp); 2a06705cd59540 Darrick J. Wong 2016-10-03 158 if (error) 2a06705cd59540 Darrick J. Wong 2016-10-03 159 return error; 2a06705cd59540 Darrick J. Wong 2016-10-03 160 a81a06211fb43d Dave Chinner 2021-06-02 @161 cur = xfs_refcountbt_init_cursor(mp, tp, agbp, agbp->b_pag); c41e19cbde3dd4 Darrick J. Wong 2021-01-05 162 } 2a06705cd59540 Darrick J. Wong 2016-10-03 163 2a916659ca4d4a Darrick J. Wong 2021-01-05 164 error = xfs_refcount_find_shared(cur, agbno, irec->br_blockcount, 2a916659ca4d4a Darrick J. Wong 2021-01-05 165 &shared_bno, &shared_len, find_end_of_shared); 2a06705cd59540 Darrick J. Wong 2016-10-03 166 0b04b6b875b32f Darrick J. Wong 2018-07-19 167 xfs_btree_del_cursor(cur, error); 2a06705cd59540 Darrick J. Wong 2016-10-03 168 c41e19cbde3dd4 Darrick J. Wong 2021-01-05 @169 if (agbp) 92ff7285f1df55 Darrick J. Wong 2017-06-16 170 xfs_trans_brelse(tp, agbp); c41e19cbde3dd4 Darrick J. Wong 2021-01-05 171 else c41e19cbde3dd4 Darrick J. Wong 2021-01-05 172 xfs_rtunlock(mp, XFS_RTLOCK_REFCOUNT); 2a916659ca4d4a Darrick J. Wong 2021-01-05 173 a42a3ab16973ba Darrick J. Wong 2021-01-05 174 if (shared_bno == NULLFSBLOCK) 2a916659ca4d4a Darrick J. Wong 2021-01-05 175 *fbno = NULLFSBLOCK; c41e19cbde3dd4 Darrick J. Wong 2021-01-05 176 else if (XFS_IS_REALTIME_INODE(ip)) c41e19cbde3dd4 Darrick J. Wong 2021-01-05 177 *fbno = shared_bno; 2a916659ca4d4a Darrick J. Wong 2021-01-05 178 else 2a916659ca4d4a Darrick J. Wong 2021-01-05 179 *fbno = XFS_AGB_TO_FSB(mp, agno, shared_bno); 2a916659ca4d4a Darrick J. Wong 2021-01-05 180 *flen = shared_len; 2a06705cd59540 Darrick J. Wong 2016-10-03 181 return error; 2a06705cd59540 Darrick J. Wong 2016-10-03 182 } 2a06705cd59540 Darrick J. Wong 2016-10-03 183 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org