All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org, Qu Wenruo <wqu@suse.com>,
	linux-btrfs@vger.kernel.org
Cc: lkp@intel.com, kbuild-all@lists.01.org
Subject: Re: [PATCH v5 09/11] btrfs: defrag: use defrag_one_cluster() to implement btrfs_defrag_file()
Date: Mon, 9 Aug 2021 14:32:27 +0300	[thread overview]
Message-ID: <202108070109.1tqb3qPy-lkp@intel.com> (raw)
In-Reply-To: <20210806081242.257996-10-wqu@suse.com>

Hi Qu,

url:    https://github.com/0day-ci/linux/commits/Qu-Wenruo/btrfs-defrag-rework-to-support-sector-perfect-defrag/20210806-161501
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
config: h8300-randconfig-m031-20210804 (attached as .config)
compiler: h8300-linux-gcc (GCC) 10.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/btrfs/ioctl.c:1869 btrfs_defrag_file() error: uninitialized symbol 'ret'.

vim +/ret +1869 fs/btrfs/ioctl.c

fe90d1614439a8 Qu Wenruo                 2021-08-06  1757  int btrfs_defrag_file(struct inode *inode, struct file_ra_state *ra,
4cb5300bc839b8 Chris Mason               2011-05-24  1758  		      struct btrfs_ioctl_defrag_range_args *range,
4cb5300bc839b8 Chris Mason               2011-05-24  1759  		      u64 newer_than, unsigned long max_to_defrag)
4cb5300bc839b8 Chris Mason               2011-05-24  1760  {
0b246afa62b0cf Jeff Mahoney              2016-06-22  1761  	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1762  	unsigned long sectors_defragged = 0;
151a31b25e5c94 Li Zefan                  2011-09-02  1763  	u64 isize = i_size_read(inode);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1764  	u64 cur;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1765  	u64 last_byte;
1e2ef46d89ee41 David Sterba              2017-07-17  1766  	bool do_compress = range->flags & BTRFS_DEFRAG_RANGE_COMPRESS;
fe90d1614439a8 Qu Wenruo                 2021-08-06  1767  	bool ra_allocated = false;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1768  	int compress_type = BTRFS_COMPRESS_ZLIB;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1769  	int ret;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1770  	u32 extent_thresh = range->extent_thresh;
4cb5300bc839b8 Chris Mason               2011-05-24  1771  
0abd5b17249ea5 Liu Bo                    2013-04-16  1772  	if (isize == 0)
0abd5b17249ea5 Liu Bo                    2013-04-16  1773  		return 0;
0abd5b17249ea5 Liu Bo                    2013-04-16  1774  
0abd5b17249ea5 Liu Bo                    2013-04-16  1775  	if (range->start >= isize)
0abd5b17249ea5 Liu Bo                    2013-04-16  1776  		return -EINVAL;
1a419d85a76853 Li Zefan                  2010-10-25  1777  
1e2ef46d89ee41 David Sterba              2017-07-17  1778  	if (do_compress) {
ce96b7ffd11e26 Chengguang Xu             2019-10-10  1779  		if (range->compress_type >= BTRFS_NR_COMPRESS_TYPES)
1a419d85a76853 Li Zefan                  2010-10-25  1780  			return -EINVAL;
1a419d85a76853 Li Zefan                  2010-10-25  1781  		if (range->compress_type)
1a419d85a76853 Li Zefan                  2010-10-25  1782  			compress_type = range->compress_type;
1a419d85a76853 Li Zefan                  2010-10-25  1783  	}
f46b5a66b3316e Christoph Hellwig         2008-06-11  1784  
0abd5b17249ea5 Liu Bo                    2013-04-16  1785  	if (extent_thresh == 0)
ee22184b53c823 Byongho Lee               2015-12-15  1786  		extent_thresh = SZ_256K;
940100a4a7b78b Chris Mason               2010-03-10  1787  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1788  	if (range->start + range->len > range->start) {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1789  		/* Got a specific range */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1790  		last_byte = min(isize, range->start + range->len) - 1;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1791  	} else {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1792  		/* Defrag until file end */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1793  		last_byte = isize - 1;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1794  	}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1795  
4cb5300bc839b8 Chris Mason               2011-05-24  1796  	/*
fe90d1614439a8 Qu Wenruo                 2021-08-06  1797  	 * If we were not given a ra, allocate a readahead context. As
0a52d108089f33 David Sterba              2017-06-22  1798  	 * readahead is just an optimization, defrag will work without it so
0a52d108089f33 David Sterba              2017-06-22  1799  	 * we don't error out.
4cb5300bc839b8 Chris Mason               2011-05-24  1800  	 */
fe90d1614439a8 Qu Wenruo                 2021-08-06  1801  	if (!ra) {
fe90d1614439a8 Qu Wenruo                 2021-08-06  1802  		ra_allocated = true;
63e727ecd238be David Sterba              2017-06-22  1803  		ra = kzalloc(sizeof(*ra), GFP_KERNEL);
0a52d108089f33 David Sterba              2017-06-22  1804  		if (ra)
4cb5300bc839b8 Chris Mason               2011-05-24  1805  			file_ra_state_init(ra, inode->i_mapping);
4cb5300bc839b8 Chris Mason               2011-05-24  1806  	}
4cb5300bc839b8 Chris Mason               2011-05-24  1807  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1808  	/* Align the range */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1809  	cur = round_down(range->start, fs_info->sectorsize);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1810  	last_byte = round_up(last_byte, fs_info->sectorsize) - 1;
4cb5300bc839b8 Chris Mason               2011-05-24  1811  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1812  	while (cur < last_byte) {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1813  		u64 cluster_end;
1e701a3292e25a Chris Mason               2010-03-11  1814  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1815  		/* The cluster size 256K should always be page aligned */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1816  		BUILD_BUG_ON(!IS_ALIGNED(CLUSTER_SIZE, PAGE_SIZE));
008873eafbc77d Li Zefan                  2011-09-02  1817  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1818  		/* We want the cluster ends at page boundary when possible */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1819  		cluster_end = (((cur >> PAGE_SHIFT) +
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1820  			       (SZ_256K >> PAGE_SHIFT)) << PAGE_SHIFT) - 1;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1821  		cluster_end = min(cluster_end, last_byte);
940100a4a7b78b Chris Mason               2010-03-10  1822  
64708539cd23b3 Josef Bacik               2021-02-10  1823  		btrfs_inode_lock(inode, 0);
eede2bf34f4fa8 Omar Sandoval             2016-11-03  1824  		if (IS_SWAPFILE(inode)) {
eede2bf34f4fa8 Omar Sandoval             2016-11-03  1825  			ret = -ETXTBSY;
64708539cd23b3 Josef Bacik               2021-02-10  1826  			btrfs_inode_unlock(inode, 0);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1827  			break;
ecb8bea87d05fd Liu Bo                    2012-03-29  1828  		}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1829  		if (!(inode->i_sb->s_flags & SB_ACTIVE)) {
64708539cd23b3 Josef Bacik               2021-02-10  1830  			btrfs_inode_unlock(inode, 0);
4cb5300bc839b8 Chris Mason               2011-05-24  1831  			break;

Can we hit this break statement on the first iteration through the loop?

3eaa2885276fd6 Chris Mason               2008-07-24  1832  		}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1833  		if (do_compress)
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1834  			BTRFS_I(inode)->defrag_compress = compress_type;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1835  		ret = defrag_one_cluster(BTRFS_I(inode), ra, cur,
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1836  				cluster_end + 1 - cur, extent_thresh,
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1837  				newer_than, do_compress,
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1838  				&sectors_defragged, max_to_defrag);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1839  		btrfs_inode_unlock(inode, 0);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1840  		if (ret < 0)
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1841  			break;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1842  		cur = cluster_end + 1;
4cb5300bc839b8 Chris Mason               2011-05-24  1843  	}
f46b5a66b3316e Christoph Hellwig         2008-06-11  1844  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1845  	if (ra_allocated)
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1846  		kfree(ra);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1847  	if (sectors_defragged) {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1848  		/*
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1849  		 * We have defragged some sectors, for compression case
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1850  		 * they need to be written back immediately.
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1851  		 */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1852  		if (range->flags & BTRFS_DEFRAG_RANGE_START_IO) {
1e701a3292e25a Chris Mason               2010-03-11  1853  			filemap_flush(inode->i_mapping);
dec8ef90552f7b Filipe Manana             2014-03-01  1854  			if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
dec8ef90552f7b Filipe Manana             2014-03-01  1855  				     &BTRFS_I(inode)->runtime_flags))
1e701a3292e25a Chris Mason               2010-03-11  1856  				filemap_flush(inode->i_mapping);
dec8ef90552f7b Filipe Manana             2014-03-01  1857  		}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1858  		if (range->compress_type == BTRFS_COMPRESS_LZO)
0b246afa62b0cf Jeff Mahoney              2016-06-22  1859  			btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1860  		else if (range->compress_type == BTRFS_COMPRESS_ZSTD)
5c1aab1dd5445e Nick Terrell              2017-08-09  1861  			btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1862  		ret = sectors_defragged;
1a419d85a76853 Li Zefan                  2010-10-25  1863  	}
1e2ef46d89ee41 David Sterba              2017-07-17  1864  	if (do_compress) {
64708539cd23b3 Josef Bacik               2021-02-10  1865  		btrfs_inode_lock(inode, 0);
eec63c65dcbeb1 David Sterba              2017-07-17  1866  		BTRFS_I(inode)->defrag_compress = BTRFS_COMPRESS_NONE;
64708539cd23b3 Josef Bacik               2021-02-10  1867  		btrfs_inode_unlock(inode, 0);
633085c79c84c3 Filipe David Borba Manana 2013-08-16  1868  	}
940100a4a7b78b Chris Mason               2010-03-10 @1869  	return ret;
f46b5a66b3316e Christoph Hellwig         2008-06-11  1870  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org


WARNING: multiple messages have this Message-ID (diff)
From: kernel test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: Re: [PATCH v5 09/11] btrfs: defrag: use defrag_one_cluster() to implement btrfs_defrag_file()
Date: Sat, 07 Aug 2021 02:01:11 +0800	[thread overview]
Message-ID: <202108070109.1tqb3qPy-lkp@intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 12824 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210806081242.257996-10-wqu@suse.com>
References: <20210806081242.257996-10-wqu@suse.com>
TO: Qu Wenruo <wqu@suse.com>
TO: linux-btrfs(a)vger.kernel.org

Hi Qu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on v5.14-rc4 next-20210805]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Qu-Wenruo/btrfs-defrag-rework-to-support-sector-perfect-defrag/20210806-161501
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
:::::: branch date: 10 hours ago
:::::: commit date: 10 hours ago
config: h8300-randconfig-m031-20210804 (attached as .config)
compiler: h8300-linux-gcc (GCC) 10.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/btrfs/ioctl.c:1869 btrfs_defrag_file() error: uninitialized symbol 'ret'.

Old smatch warnings:
fs/btrfs/ioctl.c:816 create_snapshot() warn: '&pending_snapshot->list' not removed from list
fs/btrfs/ioctl.c:1216 defrag_prepare_one_page() warn: should 'index << 12' be a 64 bit type?
fs/btrfs/ioctl.c:1649 defrag_one_range() warn: should 'start_index << 12' be a 64 bit type?
fs/btrfs/ioctl.c:1677 defrag_one_range() warn: should 'start_index << 12' be a 64 bit type?

vim +/ret +1869 fs/btrfs/ioctl.c

bd3c39b7ee16de Qu Wenruo                 2021-08-06  1746  
fe90d1614439a8 Qu Wenruo                 2021-08-06  1747  /*
fe90d1614439a8 Qu Wenruo                 2021-08-06  1748   * Btrfs entrace for defrag.
fe90d1614439a8 Qu Wenruo                 2021-08-06  1749   *
fe90d1614439a8 Qu Wenruo                 2021-08-06  1750   * @inode:	   Inode to be defragged
fe90d1614439a8 Qu Wenruo                 2021-08-06  1751   * @ra:		   Readahead state. If NULL, one will be allocated@runtime.
fe90d1614439a8 Qu Wenruo                 2021-08-06  1752   * @range:	   Defrag options including range and flags.
fe90d1614439a8 Qu Wenruo                 2021-08-06  1753   * @newer_than:	   Minimal transid to defrag
fe90d1614439a8 Qu Wenruo                 2021-08-06  1754   * @max_to_defrag: Max number of sectors to be defragged, if 0, the whole inode
fe90d1614439a8 Qu Wenruo                 2021-08-06  1755   *		   will be defragged.
fe90d1614439a8 Qu Wenruo                 2021-08-06  1756   */
fe90d1614439a8 Qu Wenruo                 2021-08-06  1757  int btrfs_defrag_file(struct inode *inode, struct file_ra_state *ra,
4cb5300bc839b8 Chris Mason               2011-05-24  1758  		      struct btrfs_ioctl_defrag_range_args *range,
4cb5300bc839b8 Chris Mason               2011-05-24  1759  		      u64 newer_than, unsigned long max_to_defrag)
4cb5300bc839b8 Chris Mason               2011-05-24  1760  {
0b246afa62b0cf Jeff Mahoney              2016-06-22  1761  	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1762  	unsigned long sectors_defragged = 0;
151a31b25e5c94 Li Zefan                  2011-09-02  1763  	u64 isize = i_size_read(inode);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1764  	u64 cur;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1765  	u64 last_byte;
1e2ef46d89ee41 David Sterba              2017-07-17  1766  	bool do_compress = range->flags & BTRFS_DEFRAG_RANGE_COMPRESS;
fe90d1614439a8 Qu Wenruo                 2021-08-06  1767  	bool ra_allocated = false;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1768  	int compress_type = BTRFS_COMPRESS_ZLIB;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1769  	int ret;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1770  	u32 extent_thresh = range->extent_thresh;
4cb5300bc839b8 Chris Mason               2011-05-24  1771  
0abd5b17249ea5 Liu Bo                    2013-04-16  1772  	if (isize == 0)
0abd5b17249ea5 Liu Bo                    2013-04-16  1773  		return 0;
0abd5b17249ea5 Liu Bo                    2013-04-16  1774  
0abd5b17249ea5 Liu Bo                    2013-04-16  1775  	if (range->start >= isize)
0abd5b17249ea5 Liu Bo                    2013-04-16  1776  		return -EINVAL;
1a419d85a76853 Li Zefan                  2010-10-25  1777  
1e2ef46d89ee41 David Sterba              2017-07-17  1778  	if (do_compress) {
ce96b7ffd11e26 Chengguang Xu             2019-10-10  1779  		if (range->compress_type >= BTRFS_NR_COMPRESS_TYPES)
1a419d85a76853 Li Zefan                  2010-10-25  1780  			return -EINVAL;
1a419d85a76853 Li Zefan                  2010-10-25  1781  		if (range->compress_type)
1a419d85a76853 Li Zefan                  2010-10-25  1782  			compress_type = range->compress_type;
1a419d85a76853 Li Zefan                  2010-10-25  1783  	}
f46b5a66b3316e Christoph Hellwig         2008-06-11  1784  
0abd5b17249ea5 Liu Bo                    2013-04-16  1785  	if (extent_thresh == 0)
ee22184b53c823 Byongho Lee               2015-12-15  1786  		extent_thresh = SZ_256K;
940100a4a7b78b Chris Mason               2010-03-10  1787  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1788  	if (range->start + range->len > range->start) {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1789  		/* Got a specific range */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1790  		last_byte = min(isize, range->start + range->len) - 1;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1791  	} else {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1792  		/* Defrag until file end */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1793  		last_byte = isize - 1;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1794  	}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1795  
4cb5300bc839b8 Chris Mason               2011-05-24  1796  	/*
fe90d1614439a8 Qu Wenruo                 2021-08-06  1797  	 * If we were not given a ra, allocate a readahead context. As
0a52d108089f33 David Sterba              2017-06-22  1798  	 * readahead is just an optimization, defrag will work without it so
0a52d108089f33 David Sterba              2017-06-22  1799  	 * we don't error out.
4cb5300bc839b8 Chris Mason               2011-05-24  1800  	 */
fe90d1614439a8 Qu Wenruo                 2021-08-06  1801  	if (!ra) {
fe90d1614439a8 Qu Wenruo                 2021-08-06  1802  		ra_allocated = true;
63e727ecd238be David Sterba              2017-06-22  1803  		ra = kzalloc(sizeof(*ra), GFP_KERNEL);
0a52d108089f33 David Sterba              2017-06-22  1804  		if (ra)
4cb5300bc839b8 Chris Mason               2011-05-24  1805  			file_ra_state_init(ra, inode->i_mapping);
4cb5300bc839b8 Chris Mason               2011-05-24  1806  	}
4cb5300bc839b8 Chris Mason               2011-05-24  1807  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1808  	/* Align the range */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1809  	cur = round_down(range->start, fs_info->sectorsize);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1810  	last_byte = round_up(last_byte, fs_info->sectorsize) - 1;
4cb5300bc839b8 Chris Mason               2011-05-24  1811  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1812  	while (cur < last_byte) {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1813  		u64 cluster_end;
1e701a3292e25a Chris Mason               2010-03-11  1814  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1815  		/* The cluster size 256K should always be page aligned */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1816  		BUILD_BUG_ON(!IS_ALIGNED(CLUSTER_SIZE, PAGE_SIZE));
008873eafbc77d Li Zefan                  2011-09-02  1817  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1818  		/* We want the cluster ends@page boundary when possible */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1819  		cluster_end = (((cur >> PAGE_SHIFT) +
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1820  			       (SZ_256K >> PAGE_SHIFT)) << PAGE_SHIFT) - 1;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1821  		cluster_end = min(cluster_end, last_byte);
940100a4a7b78b Chris Mason               2010-03-10  1822  
64708539cd23b3 Josef Bacik               2021-02-10  1823  		btrfs_inode_lock(inode, 0);
eede2bf34f4fa8 Omar Sandoval             2016-11-03  1824  		if (IS_SWAPFILE(inode)) {
eede2bf34f4fa8 Omar Sandoval             2016-11-03  1825  			ret = -ETXTBSY;
64708539cd23b3 Josef Bacik               2021-02-10  1826  			btrfs_inode_unlock(inode, 0);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1827  			break;
ecb8bea87d05fd Liu Bo                    2012-03-29  1828  		}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1829  		if (!(inode->i_sb->s_flags & SB_ACTIVE)) {
64708539cd23b3 Josef Bacik               2021-02-10  1830  			btrfs_inode_unlock(inode, 0);
4cb5300bc839b8 Chris Mason               2011-05-24  1831  			break;
3eaa2885276fd6 Chris Mason               2008-07-24  1832  		}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1833  		if (do_compress)
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1834  			BTRFS_I(inode)->defrag_compress = compress_type;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1835  		ret = defrag_one_cluster(BTRFS_I(inode), ra, cur,
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1836  				cluster_end + 1 - cur, extent_thresh,
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1837  				newer_than, do_compress,
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1838  				&sectors_defragged, max_to_defrag);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1839  		btrfs_inode_unlock(inode, 0);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1840  		if (ret < 0)
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1841  			break;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1842  		cur = cluster_end + 1;
4cb5300bc839b8 Chris Mason               2011-05-24  1843  	}
f46b5a66b3316e Christoph Hellwig         2008-06-11  1844  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1845  	if (ra_allocated)
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1846  		kfree(ra);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1847  	if (sectors_defragged) {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1848  		/*
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1849  		 * We have defragged some sectors, for compression case
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1850  		 * they need to be written back immediately.
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1851  		 */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1852  		if (range->flags & BTRFS_DEFRAG_RANGE_START_IO) {
1e701a3292e25a Chris Mason               2010-03-11  1853  			filemap_flush(inode->i_mapping);
dec8ef90552f7b Filipe Manana             2014-03-01  1854  			if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
dec8ef90552f7b Filipe Manana             2014-03-01  1855  				     &BTRFS_I(inode)->runtime_flags))
1e701a3292e25a Chris Mason               2010-03-11  1856  				filemap_flush(inode->i_mapping);
dec8ef90552f7b Filipe Manana             2014-03-01  1857  		}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1858  		if (range->compress_type == BTRFS_COMPRESS_LZO)
0b246afa62b0cf Jeff Mahoney              2016-06-22  1859  			btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1860  		else if (range->compress_type == BTRFS_COMPRESS_ZSTD)
5c1aab1dd5445e Nick Terrell              2017-08-09  1861  			btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1862  		ret = sectors_defragged;
1a419d85a76853 Li Zefan                  2010-10-25  1863  	}
1e2ef46d89ee41 David Sterba              2017-07-17  1864  	if (do_compress) {
64708539cd23b3 Josef Bacik               2021-02-10  1865  		btrfs_inode_lock(inode, 0);
eec63c65dcbeb1 David Sterba              2017-07-17  1866  		BTRFS_I(inode)->defrag_compress = BTRFS_COMPRESS_NONE;
64708539cd23b3 Josef Bacik               2021-02-10  1867  		btrfs_inode_unlock(inode, 0);
633085c79c84c3 Filipe David Borba Manana 2013-08-16  1868  	}
940100a4a7b78b Chris Mason               2010-03-10 @1869  	return ret;
f46b5a66b3316e Christoph Hellwig         2008-06-11  1870  }
f46b5a66b3316e Christoph Hellwig         2008-06-11  1871  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 32948 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild-all@lists.01.org
Subject: Re: [PATCH v5 09/11] btrfs: defrag: use defrag_one_cluster() to implement btrfs_defrag_file()
Date: Mon, 09 Aug 2021 14:32:27 +0300	[thread overview]
Message-ID: <202108070109.1tqb3qPy-lkp@intel.com> (raw)
In-Reply-To: <20210806081242.257996-10-wqu@suse.com>

[-- Attachment #1: Type: text/plain, Size: 10810 bytes --]

Hi Qu,

url:    https://github.com/0day-ci/linux/commits/Qu-Wenruo/btrfs-defrag-rework-to-support-sector-perfect-defrag/20210806-161501
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
config: h8300-randconfig-m031-20210804 (attached as .config)
compiler: h8300-linux-gcc (GCC) 10.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/btrfs/ioctl.c:1869 btrfs_defrag_file() error: uninitialized symbol 'ret'.

vim +/ret +1869 fs/btrfs/ioctl.c

fe90d1614439a8 Qu Wenruo                 2021-08-06  1757  int btrfs_defrag_file(struct inode *inode, struct file_ra_state *ra,
4cb5300bc839b8 Chris Mason               2011-05-24  1758  		      struct btrfs_ioctl_defrag_range_args *range,
4cb5300bc839b8 Chris Mason               2011-05-24  1759  		      u64 newer_than, unsigned long max_to_defrag)
4cb5300bc839b8 Chris Mason               2011-05-24  1760  {
0b246afa62b0cf Jeff Mahoney              2016-06-22  1761  	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1762  	unsigned long sectors_defragged = 0;
151a31b25e5c94 Li Zefan                  2011-09-02  1763  	u64 isize = i_size_read(inode);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1764  	u64 cur;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1765  	u64 last_byte;
1e2ef46d89ee41 David Sterba              2017-07-17  1766  	bool do_compress = range->flags & BTRFS_DEFRAG_RANGE_COMPRESS;
fe90d1614439a8 Qu Wenruo                 2021-08-06  1767  	bool ra_allocated = false;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1768  	int compress_type = BTRFS_COMPRESS_ZLIB;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1769  	int ret;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1770  	u32 extent_thresh = range->extent_thresh;
4cb5300bc839b8 Chris Mason               2011-05-24  1771  
0abd5b17249ea5 Liu Bo                    2013-04-16  1772  	if (isize == 0)
0abd5b17249ea5 Liu Bo                    2013-04-16  1773  		return 0;
0abd5b17249ea5 Liu Bo                    2013-04-16  1774  
0abd5b17249ea5 Liu Bo                    2013-04-16  1775  	if (range->start >= isize)
0abd5b17249ea5 Liu Bo                    2013-04-16  1776  		return -EINVAL;
1a419d85a76853 Li Zefan                  2010-10-25  1777  
1e2ef46d89ee41 David Sterba              2017-07-17  1778  	if (do_compress) {
ce96b7ffd11e26 Chengguang Xu             2019-10-10  1779  		if (range->compress_type >= BTRFS_NR_COMPRESS_TYPES)
1a419d85a76853 Li Zefan                  2010-10-25  1780  			return -EINVAL;
1a419d85a76853 Li Zefan                  2010-10-25  1781  		if (range->compress_type)
1a419d85a76853 Li Zefan                  2010-10-25  1782  			compress_type = range->compress_type;
1a419d85a76853 Li Zefan                  2010-10-25  1783  	}
f46b5a66b3316e Christoph Hellwig         2008-06-11  1784  
0abd5b17249ea5 Liu Bo                    2013-04-16  1785  	if (extent_thresh == 0)
ee22184b53c823 Byongho Lee               2015-12-15  1786  		extent_thresh = SZ_256K;
940100a4a7b78b Chris Mason               2010-03-10  1787  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1788  	if (range->start + range->len > range->start) {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1789  		/* Got a specific range */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1790  		last_byte = min(isize, range->start + range->len) - 1;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1791  	} else {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1792  		/* Defrag until file end */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1793  		last_byte = isize - 1;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1794  	}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1795  
4cb5300bc839b8 Chris Mason               2011-05-24  1796  	/*
fe90d1614439a8 Qu Wenruo                 2021-08-06  1797  	 * If we were not given a ra, allocate a readahead context. As
0a52d108089f33 David Sterba              2017-06-22  1798  	 * readahead is just an optimization, defrag will work without it so
0a52d108089f33 David Sterba              2017-06-22  1799  	 * we don't error out.
4cb5300bc839b8 Chris Mason               2011-05-24  1800  	 */
fe90d1614439a8 Qu Wenruo                 2021-08-06  1801  	if (!ra) {
fe90d1614439a8 Qu Wenruo                 2021-08-06  1802  		ra_allocated = true;
63e727ecd238be David Sterba              2017-06-22  1803  		ra = kzalloc(sizeof(*ra), GFP_KERNEL);
0a52d108089f33 David Sterba              2017-06-22  1804  		if (ra)
4cb5300bc839b8 Chris Mason               2011-05-24  1805  			file_ra_state_init(ra, inode->i_mapping);
4cb5300bc839b8 Chris Mason               2011-05-24  1806  	}
4cb5300bc839b8 Chris Mason               2011-05-24  1807  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1808  	/* Align the range */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1809  	cur = round_down(range->start, fs_info->sectorsize);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1810  	last_byte = round_up(last_byte, fs_info->sectorsize) - 1;
4cb5300bc839b8 Chris Mason               2011-05-24  1811  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1812  	while (cur < last_byte) {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1813  		u64 cluster_end;
1e701a3292e25a Chris Mason               2010-03-11  1814  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1815  		/* The cluster size 256K should always be page aligned */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1816  		BUILD_BUG_ON(!IS_ALIGNED(CLUSTER_SIZE, PAGE_SIZE));
008873eafbc77d Li Zefan                  2011-09-02  1817  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1818  		/* We want the cluster ends@page boundary when possible */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1819  		cluster_end = (((cur >> PAGE_SHIFT) +
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1820  			       (SZ_256K >> PAGE_SHIFT)) << PAGE_SHIFT) - 1;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1821  		cluster_end = min(cluster_end, last_byte);
940100a4a7b78b Chris Mason               2010-03-10  1822  
64708539cd23b3 Josef Bacik               2021-02-10  1823  		btrfs_inode_lock(inode, 0);
eede2bf34f4fa8 Omar Sandoval             2016-11-03  1824  		if (IS_SWAPFILE(inode)) {
eede2bf34f4fa8 Omar Sandoval             2016-11-03  1825  			ret = -ETXTBSY;
64708539cd23b3 Josef Bacik               2021-02-10  1826  			btrfs_inode_unlock(inode, 0);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1827  			break;
ecb8bea87d05fd Liu Bo                    2012-03-29  1828  		}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1829  		if (!(inode->i_sb->s_flags & SB_ACTIVE)) {
64708539cd23b3 Josef Bacik               2021-02-10  1830  			btrfs_inode_unlock(inode, 0);
4cb5300bc839b8 Chris Mason               2011-05-24  1831  			break;

Can we hit this break statement on the first iteration through the loop?

3eaa2885276fd6 Chris Mason               2008-07-24  1832  		}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1833  		if (do_compress)
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1834  			BTRFS_I(inode)->defrag_compress = compress_type;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1835  		ret = defrag_one_cluster(BTRFS_I(inode), ra, cur,
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1836  				cluster_end + 1 - cur, extent_thresh,
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1837  				newer_than, do_compress,
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1838  				&sectors_defragged, max_to_defrag);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1839  		btrfs_inode_unlock(inode, 0);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1840  		if (ret < 0)
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1841  			break;
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1842  		cur = cluster_end + 1;
4cb5300bc839b8 Chris Mason               2011-05-24  1843  	}
f46b5a66b3316e Christoph Hellwig         2008-06-11  1844  
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1845  	if (ra_allocated)
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1846  		kfree(ra);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1847  	if (sectors_defragged) {
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1848  		/*
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1849  		 * We have defragged some sectors, for compression case
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1850  		 * they need to be written back immediately.
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1851  		 */
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1852  		if (range->flags & BTRFS_DEFRAG_RANGE_START_IO) {
1e701a3292e25a Chris Mason               2010-03-11  1853  			filemap_flush(inode->i_mapping);
dec8ef90552f7b Filipe Manana             2014-03-01  1854  			if (test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,
dec8ef90552f7b Filipe Manana             2014-03-01  1855  				     &BTRFS_I(inode)->runtime_flags))
1e701a3292e25a Chris Mason               2010-03-11  1856  				filemap_flush(inode->i_mapping);
dec8ef90552f7b Filipe Manana             2014-03-01  1857  		}
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1858  		if (range->compress_type == BTRFS_COMPRESS_LZO)
0b246afa62b0cf Jeff Mahoney              2016-06-22  1859  			btrfs_set_fs_incompat(fs_info, COMPRESS_LZO);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1860  		else if (range->compress_type == BTRFS_COMPRESS_ZSTD)
5c1aab1dd5445e Nick Terrell              2017-08-09  1861  			btrfs_set_fs_incompat(fs_info, COMPRESS_ZSTD);
d0b928ff1ed56a Qu Wenruo                 2021-08-06  1862  		ret = sectors_defragged;
1a419d85a76853 Li Zefan                  2010-10-25  1863  	}
1e2ef46d89ee41 David Sterba              2017-07-17  1864  	if (do_compress) {
64708539cd23b3 Josef Bacik               2021-02-10  1865  		btrfs_inode_lock(inode, 0);
eec63c65dcbeb1 David Sterba              2017-07-17  1866  		BTRFS_I(inode)->defrag_compress = BTRFS_COMPRESS_NONE;
64708539cd23b3 Josef Bacik               2021-02-10  1867  		btrfs_inode_unlock(inode, 0);
633085c79c84c3 Filipe David Borba Manana 2013-08-16  1868  	}
940100a4a7b78b Chris Mason               2010-03-10 @1869  	return ret;
f46b5a66b3316e Christoph Hellwig         2008-06-11  1870  }

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

       reply	other threads:[~2021-08-09 11:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06 18:01 kernel test robot [this message]
2021-08-09 11:32 ` [PATCH v5 09/11] btrfs: defrag: use defrag_one_cluster() to implement btrfs_defrag_file() Dan Carpenter
2021-08-09 11:32 ` Dan Carpenter
2021-08-09 12:13 ` Qu Wenruo
2021-08-09 12:13   ` Qu Wenruo
2021-08-10  6:19   ` Qu Wenruo
2021-08-10  6:19     ` Qu Wenruo
  -- strict thread matches above, loose matches on Subject: below --
2021-08-07 10:05 kernel test robot
2021-08-06  8:12 [PATCH v5 00/11] btrfs: defrag: rework to support sector perfect defrag Qu Wenruo
2021-08-06  8:12 ` [PATCH v5 01/11] btrfs: defrag: pass file_ra_state instead of file for btrfs_defrag_file() Qu Wenruo
2021-08-06  8:12 ` [PATCH v5 02/11] btrfs: defrag: also check PagePrivate for subpage cases in cluster_pages_for_defrag() Qu Wenruo
2021-08-06  8:12 ` [PATCH v5 03/11] btrfs: defrag: replace hard coded PAGE_SIZE to sectorsize Qu Wenruo
2021-08-06  8:12 ` [PATCH v5 04/11] btrfs: defrag: extract the page preparation code into one helper Qu Wenruo
2021-08-23 19:04   ` David Sterba
2021-08-06  8:12 ` [PATCH v5 05/11] btrfs: defrag: introduce a new helper to collect target file extents Qu Wenruo
2021-08-23 19:08   ` David Sterba
2021-08-06  8:12 ` [PATCH v5 06/11] btrfs: defrag: introduce a helper to defrag a continuous prepared range Qu Wenruo
2021-08-06  8:12 ` [PATCH v5 07/11] btrfs: defrag: introduce a helper to defrag a range Qu Wenruo
2021-08-23 19:21   ` David Sterba
2021-08-06  8:12 ` [PATCH v5 08/11] btrfs: defrag: introduce a new helper to defrag one cluster Qu Wenruo
2021-08-23 19:27   ` David Sterba
2021-08-06  8:12 ` [PATCH v5 09/11] btrfs: defrag: use defrag_one_cluster() to implement btrfs_defrag_file() Qu Wenruo
2021-08-06  8:12 ` [PATCH v5 10/11] btrfs: defrag: remove the old infrastructure Qu Wenruo
2021-08-06  8:12 ` [PATCH v5 11/11] btrfs: defrag: enable defrag for subpage case Qu Wenruo
2021-08-23 19:43 ` [PATCH v5 00/11] btrfs: defrag: rework to support sector perfect defrag David Sterba
2021-08-27  9:18   ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202108070109.1tqb3qPy-lkp@intel.com \
    --to=dan.carpenter@oracle.com \
    --cc=kbuild-all@lists.01.org \
    --cc=kbuild@lists.01.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.