summaryrefslogtreecommitdiffstats
path: root/fs/read_write.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-11-02 12:33:08 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-11-02 12:33:08 -0400
commitc2aa1a444cab2c673650ada80a7dffc4345ce2e6 (patch)
tree3efb7e2213cabd174780b021a8dab2cea0b03386 /fs/read_write.c
parentb69f9e17a57a50bc34d88975afce4425086e525d (diff)
parentbf4a1fcf0bc18d52cf0fce6571d6f327ab5eaf22 (diff)
Merge tag 'xfs-4.20-merge-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull vfs dedup fixes from Dave Chinner: "This reworks the vfs data cloning infrastructure. We discovered many issues with these interfaces late in the 4.19 cycle - the worst of them (data corruption, setuid stripping) were fixed for XFS in 4.19-rc8, but a larger rework of the infrastructure fixing all the problems was needed. That rework is the contents of this pull request. Rework the vfs_clone_file_range and vfs_dedupe_file_range infrastructure to use a common .remap_file_range method and supply generic bounds and sanity checking functions that are shared with the data write path. The current VFS infrastructure has problems with rlimit, LFS file sizes, file time stamps, maximum filesystem file sizes, stripping setuid bits, etc and so they are addressed in these commits. We also introduce the ability for the ->remap_file_range methods to return short clones so that clones for vfs_copy_file_range() don't get rejected if the entire range can't be cloned. It also allows filesystems to sliently skip deduplication of partial EOF blocks if they are not capable of doing so without requiring errors to be thrown to userspace. Existing filesystems are converted to user the new remap_file_range method, and both XFS and ocfs2 are modified to make use of the new generic checking infrastructure" * tag 'xfs-4.20-merge-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: (28 commits) xfs: remove [cm]time update from reflink calls xfs: remove xfs_reflink_remap_range xfs: remove redundant remap partial EOF block checks xfs: support returning partial reflink results xfs: clean up xfs_reflink_remap_blocks call site xfs: fix pagecache truncation prior to reflink ocfs2: remove ocfs2_reflink_remap_range ocfs2: support partial clone range and dedupe range ocfs2: fix pagecache truncation prior to reflink ocfs2: truncate page cache for clone destination file before remapping vfs: clean up generic_remap_file_range_prep return value vfs: hide file range comparison function vfs: enable remap callers that can handle short operations vfs: plumb remap flags through the vfs dedupe functions vfs: plumb remap flags through the vfs clone functions vfs: make remap_file_range functions take and return bytes completed vfs: remap helper should update destination inode metadata vfs: pass remap flags to generic_remap_checks vfs: pass remap flags to generic_remap_file_range_prep vfs: combine the clone and dedupe into a single remap_file_range ...
Diffstat (limited to 'fs/read_write.c')
-rw-r--r--fs/read_write.c405
1 files changed, 226 insertions, 179 deletions
diff --git a/fs/read_write.c b/fs/read_write.c
index 5a2ee488c5d2..bfcb4ced5664 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1587,11 +1587,15 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
1587 * Try cloning first, this is supported by more file systems, and 1587 * Try cloning first, this is supported by more file systems, and
1588 * more efficient if both clone and copy are supported (e.g. NFS). 1588 * more efficient if both clone and copy are supported (e.g. NFS).
1589 */ 1589 */
1590 if (file_in->f_op->clone_file_range) { 1590 if (file_in->f_op->remap_file_range) {
1591 ret = file_in->f_op->clone_file_range(file_in, pos_in, 1591 loff_t cloned;
1592 file_out, pos_out, len); 1592
1593 if (ret == 0) { 1593 cloned = file_in->f_op->remap_file_range(file_in, pos_in,
1594 ret = len; 1594 file_out, pos_out,
1595 min_t(loff_t, MAX_RW_COUNT, len),
1596 REMAP_FILE_CAN_SHORTEN);
1597 if (cloned > 0) {
1598 ret = cloned;
1595 goto done; 1599 goto done;
1596 } 1600 }
1597 } 1601 }
@@ -1685,11 +1689,12 @@ out2:
1685 return ret; 1689 return ret;
1686} 1690}
1687 1691
1688static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write) 1692static int remap_verify_area(struct file *file, loff_t pos, loff_t len,
1693 bool write)
1689{ 1694{
1690 struct inode *inode = file_inode(file); 1695 struct inode *inode = file_inode(file);
1691 1696
1692 if (unlikely(pos < 0)) 1697 if (unlikely(pos < 0 || len < 0))
1693 return -EINVAL; 1698 return -EINVAL;
1694 1699
1695 if (unlikely((loff_t) (pos + len) < 0)) 1700 if (unlikely((loff_t) (pos + len) < 0))
@@ -1707,22 +1712,150 @@ static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write)
1707 1712
1708 return security_file_permission(file, write ? MAY_WRITE : MAY_READ); 1713 return security_file_permission(file, write ? MAY_WRITE : MAY_READ);
1709} 1714}
1715/*
1716 * Ensure that we don't remap a partial EOF block in the middle of something
1717 * else. Assume that the offsets have already been checked for block
1718 * alignment.
1719 *
1720 * For deduplication we always scale down to the previous block because we
1721 * can't meaningfully compare post-EOF contents.
1722 *
1723 * For clone we only link a partial EOF block above the destination file's EOF.
1724 *
1725 * Shorten the request if possible.
1726 */
1727static int generic_remap_check_len(struct inode *inode_in,
1728 struct inode *inode_out,
1729 loff_t pos_out,
1730 loff_t *len,
1731 unsigned int remap_flags)
1732{
1733 u64 blkmask = i_blocksize(inode_in) - 1;
1734 loff_t new_len = *len;
1735
1736 if ((*len & blkmask) == 0)
1737 return 0;
1738
1739 if ((remap_flags & REMAP_FILE_DEDUP) ||
1740 pos_out + *len < i_size_read(inode_out))
1741 new_len &= ~blkmask;
1742
1743 if (new_len == *len)
1744 return 0;
1745
1746 if (remap_flags & REMAP_FILE_CAN_SHORTEN) {
1747 *len = new_len;
1748 return 0;
1749 }
1750
1751 return (remap_flags & REMAP_FILE_DEDUP) ? -EBADE : -EINVAL;
1752}
1753
1754/*
1755 * Read a page's worth of file data into the page cache. Return the page
1756 * locked.
1757 */
1758static struct page *vfs_dedupe_get_page(struct inode *inode, loff_t offset)
1759{
1760 struct page *page;
1761
1762 page = read_mapping_page(inode->i_mapping, offset >> PAGE_SHIFT, NULL);
1763 if (IS_ERR(page))
1764 return page;
1765 if (!PageUptodate(page)) {
1766 put_page(page);
1767 return ERR_PTR(-EIO);
1768 }
1769 lock_page(page);
1770 return page;
1771}
1772
1773/*
1774 * Compare extents of two files to see if they are the same.
1775 * Caller must have locked both inodes to prevent write races.
1776 */
1777static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
1778 struct inode *dest, loff_t destoff,
1779 loff_t len, bool *is_same)
1780{
1781 loff_t src_poff;
1782 loff_t dest_poff;
1783 void *src_addr;
1784 void *dest_addr;
1785 struct page *src_page;
1786 struct page *dest_page;
1787 loff_t cmp_len;
1788 bool same;
1789 int error;
1790
1791 error = -EINVAL;
1792 same = true;
1793 while (len) {
1794 src_poff = srcoff & (PAGE_SIZE - 1);
1795 dest_poff = destoff & (PAGE_SIZE - 1);
1796 cmp_len = min(PAGE_SIZE - src_poff,
1797 PAGE_SIZE - dest_poff);
1798 cmp_len = min(cmp_len, len);
1799 if (cmp_len <= 0)
1800 goto out_error;
1801
1802 src_page = vfs_dedupe_get_page(src, srcoff);
1803 if (IS_ERR(src_page)) {
1804 error = PTR_ERR(src_page);
1805 goto out_error;
1806 }
1807 dest_page = vfs_dedupe_get_page(dest, destoff);
1808 if (IS_ERR(dest_page)) {
1809 error = PTR_ERR(dest_page);
1810 unlock_page(src_page);
1811 put_page(src_page);
1812 goto out_error;
1813 }
1814 src_addr = kmap_atomic(src_page);
1815 dest_addr = kmap_atomic(dest_page);
1816
1817 flush_dcache_page(src_page);
1818 flush_dcache_page(dest_page);
1819
1820 if (memcmp(src_addr + src_poff, dest_addr + dest_poff, cmp_len))
1821 same = false;
1822
1823 kunmap_atomic(dest_addr);
1824 kunmap_atomic(src_addr);
1825 unlock_page(dest_page);
1826 unlock_page(src_page);
1827 put_page(dest_page);
1828 put_page(src_page);
1829
1830 if (!same)
1831 break;
1832
1833 srcoff += cmp_len;
1834 destoff += cmp_len;
1835 len -= cmp_len;
1836 }
1837
1838 *is_same = same;
1839 return 0;
1840
1841out_error:
1842 return error;
1843}
1710 1844
1711/* 1845/*
1712 * Check that the two inodes are eligible for cloning, the ranges make 1846 * Check that the two inodes are eligible for cloning, the ranges make
1713 * sense, and then flush all dirty data. Caller must ensure that the 1847 * sense, and then flush all dirty data. Caller must ensure that the
1714 * inodes have been locked against any other modifications. 1848 * inodes have been locked against any other modifications.
1715 * 1849 *
1716 * Returns: 0 for "nothing to clone", 1 for "something to clone", or 1850 * If there's an error, then the usual negative error code is returned.
1717 * the usual negative error code. 1851 * Otherwise returns 0 with *len set to the request length.
1718 */ 1852 */
1719int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in, 1853int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
1720 struct inode *inode_out, loff_t pos_out, 1854 struct file *file_out, loff_t pos_out,
1721 u64 *len, bool is_dedupe) 1855 loff_t *len, unsigned int remap_flags)
1722{ 1856{
1723 loff_t bs = inode_out->i_sb->s_blocksize; 1857 struct inode *inode_in = file_inode(file_in);
1724 loff_t blen; 1858 struct inode *inode_out = file_inode(file_out);
1725 loff_t isize;
1726 bool same_inode = (inode_in == inode_out); 1859 bool same_inode = (inode_in == inode_out);
1727 int ret; 1860 int ret;
1728 1861
@@ -1739,50 +1872,24 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,
1739 if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode)) 1872 if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
1740 return -EINVAL; 1873 return -EINVAL;
1741 1874
1742 /* Are we going all the way to the end? */
1743 isize = i_size_read(inode_in);
1744 if (isize == 0)
1745 return 0;
1746
1747 /* Zero length dedupe exits immediately; reflink goes to EOF. */ 1875 /* Zero length dedupe exits immediately; reflink goes to EOF. */
1748 if (*len == 0) { 1876 if (*len == 0) {
1749 if (is_dedupe || pos_in == isize) 1877 loff_t isize = i_size_read(inode_in);
1878
1879 if ((remap_flags & REMAP_FILE_DEDUP) || pos_in == isize)
1750 return 0; 1880 return 0;
1751 if (pos_in > isize) 1881 if (pos_in > isize)
1752 return -EINVAL; 1882 return -EINVAL;
1753 *len = isize - pos_in; 1883 *len = isize - pos_in;
1884 if (*len == 0)
1885 return 0;
1754 } 1886 }
1755 1887
1756 /* Ensure offsets don't wrap and the input is inside i_size */ 1888 /* Check that we don't violate system file offset limits. */
1757 if (pos_in + *len < pos_in || pos_out + *len < pos_out || 1889 ret = generic_remap_checks(file_in, pos_in, file_out, pos_out, len,
1758 pos_in + *len > isize) 1890 remap_flags);
1759 return -EINVAL; 1891 if (ret)
1760 1892 return ret;
1761 /* Don't allow dedupe past EOF in the dest file */
1762 if (is_dedupe) {
1763 loff_t disize;
1764
1765 disize = i_size_read(inode_out);
1766 if (pos_out >= disize || pos_out + *len > disize)
1767 return -EINVAL;
1768 }
1769
1770 /* If we're linking to EOF, continue to the block boundary. */
1771 if (pos_in + *len == isize)
1772 blen = ALIGN(isize, bs) - pos_in;
1773 else
1774 blen = *len;
1775
1776 /* Only reflink if we're aligned to block boundaries */
1777 if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_in + blen, bs) ||
1778 !IS_ALIGNED(pos_out, bs) || !IS_ALIGNED(pos_out + blen, bs))
1779 return -EINVAL;
1780
1781 /* Don't allow overlapped reflink within the same file */
1782 if (same_inode) {
1783 if (pos_out + blen > pos_in && pos_out < pos_in + blen)
1784 return -EINVAL;
1785 }
1786 1893
1787 /* Wait for the completion of any pending IOs on both files */ 1894 /* Wait for the completion of any pending IOs on both files */
1788 inode_dio_wait(inode_in); 1895 inode_dio_wait(inode_in);
@@ -1802,7 +1909,7 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,
1802 /* 1909 /*
1803 * Check that the extents are the same. 1910 * Check that the extents are the same.
1804 */ 1911 */
1805 if (is_dedupe) { 1912 if (remap_flags & REMAP_FILE_DEDUP) {
1806 bool is_same = false; 1913 bool is_same = false;
1807 1914
1808 ret = vfs_dedupe_file_range_compare(inode_in, pos_in, 1915 ret = vfs_dedupe_file_range_compare(inode_in, pos_in,
@@ -1813,16 +1920,43 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,
1813 return -EBADE; 1920 return -EBADE;
1814 } 1921 }
1815 1922
1816 return 1; 1923 ret = generic_remap_check_len(inode_in, inode_out, pos_out, len,
1924 remap_flags);
1925 if (ret)
1926 return ret;
1927
1928 /* If can't alter the file contents, we're done. */
1929 if (!(remap_flags & REMAP_FILE_DEDUP)) {
1930 /* Update the timestamps, since we can alter file contents. */
1931 if (!(file_out->f_mode & FMODE_NOCMTIME)) {
1932 ret = file_update_time(file_out);
1933 if (ret)
1934 return ret;
1935 }
1936
1937 /*
1938 * Clear the security bits if the process is not being run by
1939 * root. This keeps people from modifying setuid and setgid
1940 * binaries.
1941 */
1942 ret = file_remove_privs(file_out);
1943 if (ret)
1944 return ret;
1945 }
1946
1947 return 0;
1817} 1948}
1818EXPORT_SYMBOL(vfs_clone_file_prep_inodes); 1949EXPORT_SYMBOL(generic_remap_file_range_prep);
1819 1950
1820int do_clone_file_range(struct file *file_in, loff_t pos_in, 1951loff_t do_clone_file_range(struct file *file_in, loff_t pos_in,
1821 struct file *file_out, loff_t pos_out, u64 len) 1952 struct file *file_out, loff_t pos_out,
1953 loff_t len, unsigned int remap_flags)
1822{ 1954{
1823 struct inode *inode_in = file_inode(file_in); 1955 struct inode *inode_in = file_inode(file_in);
1824 struct inode *inode_out = file_inode(file_out); 1956 struct inode *inode_out = file_inode(file_out);
1825 int ret; 1957 loff_t ret;
1958
1959 WARN_ON_ONCE(remap_flags);
1826 1960
1827 if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode)) 1961 if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
1828 return -EISDIR; 1962 return -EISDIR;
@@ -1842,140 +1976,43 @@ int do_clone_file_range(struct file *file_in, loff_t pos_in,
1842 (file_out->f_flags & O_APPEND)) 1976 (file_out->f_flags & O_APPEND))
1843 return -EBADF; 1977 return -EBADF;
1844 1978
1845 if (!file_in->f_op->clone_file_range) 1979 if (!file_in->f_op->remap_file_range)
1846 return -EOPNOTSUPP; 1980 return -EOPNOTSUPP;
1847 1981
1848 ret = clone_verify_area(file_in, pos_in, len, false); 1982 ret = remap_verify_area(file_in, pos_in, len, false);
1849 if (ret) 1983 if (ret)
1850 return ret; 1984 return ret;
1851 1985
1852 ret = clone_verify_area(file_out, pos_out, len, true); 1986 ret = remap_verify_area(file_out, pos_out, len, true);
1853 if (ret) 1987 if (ret)
1854 return ret; 1988 return ret;
1855 1989
1856 if (pos_in + len > i_size_read(inode_in)) 1990 ret = file_in->f_op->remap_file_range(file_in, pos_in,
1857 return -EINVAL; 1991 file_out, pos_out, len, remap_flags);
1858 1992 if (ret < 0)
1859 ret = file_in->f_op->clone_file_range(file_in, pos_in, 1993 return ret;
1860 file_out, pos_out, len);
1861 if (!ret) {
1862 fsnotify_access(file_in);
1863 fsnotify_modify(file_out);
1864 }
1865 1994
1995 fsnotify_access(file_in);
1996 fsnotify_modify(file_out);
1866 return ret; 1997 return ret;
1867} 1998}
1868EXPORT_SYMBOL(do_clone_file_range); 1999EXPORT_SYMBOL(do_clone_file_range);
1869 2000
1870int vfs_clone_file_range(struct file *file_in, loff_t pos_in, 2001loff_t vfs_clone_file_range(struct file *file_in, loff_t pos_in,
1871 struct file *file_out, loff_t pos_out, u64 len) 2002 struct file *file_out, loff_t pos_out,
2003 loff_t len, unsigned int remap_flags)
1872{ 2004{
1873 int ret; 2005 loff_t ret;
1874 2006
1875 file_start_write(file_out); 2007 file_start_write(file_out);
1876 ret = do_clone_file_range(file_in, pos_in, file_out, pos_out, len); 2008 ret = do_clone_file_range(file_in, pos_in, file_out, pos_out, len,
2009 remap_flags);
1877 file_end_write(file_out); 2010 file_end_write(file_out);
1878 2011
1879 return ret; 2012 return ret;
1880} 2013}
1881EXPORT_SYMBOL(vfs_clone_file_range); 2014EXPORT_SYMBOL(vfs_clone_file_range);
1882 2015
1883/*
1884 * Read a page's worth of file data into the page cache. Return the page
1885 * locked.
1886 */
1887static struct page *vfs_dedupe_get_page(struct inode *inode, loff_t offset)
1888{
1889 struct address_space *mapping;
1890 struct page *page;
1891 pgoff_t n;
1892
1893 n = offset >> PAGE_SHIFT;
1894 mapping = inode->i_mapping;
1895 page = read_mapping_page(mapping, n, NULL);
1896 if (IS_ERR(page))
1897 return page;
1898 if (!PageUptodate(page)) {
1899 put_page(page);
1900 return ERR_PTR(-EIO);
1901 }
1902 lock_page(page);
1903 return page;
1904}
1905
1906/*
1907 * Compare extents of two files to see if they are the same.
1908 * Caller must have locked both inodes to prevent write races.
1909 */
1910int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
1911 struct inode *dest, loff_t destoff,
1912 loff_t len, bool *is_same)
1913{
1914 loff_t src_poff;
1915 loff_t dest_poff;
1916 void *src_addr;
1917 void *dest_addr;
1918 struct page *src_page;
1919 struct page *dest_page;
1920 loff_t cmp_len;
1921 bool same;
1922 int error;
1923
1924 error = -EINVAL;
1925 same = true;
1926 while (len) {
1927 src_poff = srcoff & (PAGE_SIZE - 1);
1928 dest_poff = destoff & (PAGE_SIZE - 1);
1929 cmp_len = min(PAGE_SIZE - src_poff,
1930 PAGE_SIZE - dest_poff);
1931 cmp_len = min(cmp_len, len);
1932 if (cmp_len <= 0)
1933 goto out_error;
1934
1935 src_page = vfs_dedupe_get_page(src, srcoff);
1936 if (IS_ERR(src_page)) {
1937 error = PTR_ERR(src_page);
1938 goto out_error;
1939 }
1940 dest_page = vfs_dedupe_get_page(dest, destoff);
1941 if (IS_ERR(dest_page)) {
1942 error = PTR_ERR(dest_page);
1943 unlock_page(src_page);
1944 put_page(src_page);
1945 goto out_error;
1946 }
1947 src_addr = kmap_atomic(src_page);
1948 dest_addr = kmap_atomic(dest_page);
1949
1950 flush_dcache_page(src_page);
1951 flush_dcache_page(dest_page);
1952
1953 if (memcmp(src_addr + src_poff, dest_addr + dest_poff, cmp_len))
1954 same = false;
1955
1956 kunmap_atomic(dest_addr);
1957 kunmap_atomic(src_addr);
1958 unlock_page(dest_page);
1959 unlock_page(src_page);
1960 put_page(dest_page);
1961 put_page(src_page);
1962
1963 if (!same)
1964 break;
1965
1966 srcoff += cmp_len;
1967 destoff += cmp_len;
1968 len -= cmp_len;
1969 }
1970
1971 *is_same = same;
1972 return 0;
1973
1974out_error:
1975 return error;
1976}
1977EXPORT_SYMBOL(vfs_dedupe_file_range_compare);
1978
1979/* Check whether we are allowed to dedupe the destination file */ 2016/* Check whether we are allowed to dedupe the destination file */
1980static bool allow_file_dedupe(struct file *file) 2017static bool allow_file_dedupe(struct file *file)
1981{ 2018{
@@ -1990,16 +2027,20 @@ static bool allow_file_dedupe(struct file *file)
1990 return false; 2027 return false;
1991} 2028}
1992 2029
1993int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, 2030loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos,
1994 struct file *dst_file, loff_t dst_pos, u64 len) 2031 struct file *dst_file, loff_t dst_pos,
2032 loff_t len, unsigned int remap_flags)
1995{ 2033{
1996 s64 ret; 2034 loff_t ret;
2035
2036 WARN_ON_ONCE(remap_flags & ~(REMAP_FILE_DEDUP |
2037 REMAP_FILE_CAN_SHORTEN));
1997 2038
1998 ret = mnt_want_write_file(dst_file); 2039 ret = mnt_want_write_file(dst_file);
1999 if (ret) 2040 if (ret)
2000 return ret; 2041 return ret;
2001 2042
2002 ret = clone_verify_area(dst_file, dst_pos, len, true); 2043 ret = remap_verify_area(dst_file, dst_pos, len, true);
2003 if (ret < 0) 2044 if (ret < 0)
2004 goto out_drop_write; 2045 goto out_drop_write;
2005 2046
@@ -2016,11 +2057,16 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos,
2016 goto out_drop_write; 2057 goto out_drop_write;
2017 2058
2018 ret = -EINVAL; 2059 ret = -EINVAL;
2019 if (!dst_file->f_op->dedupe_file_range) 2060 if (!dst_file->f_op->remap_file_range)
2020 goto out_drop_write; 2061 goto out_drop_write;
2021 2062
2022 ret = dst_file->f_op->dedupe_file_range(src_file, src_pos, 2063 if (len == 0) {
2023 dst_file, dst_pos, len); 2064 ret = 0;
2065 goto out_drop_write;
2066 }
2067
2068 ret = dst_file->f_op->remap_file_range(src_file, src_pos, dst_file,
2069 dst_pos, len, remap_flags | REMAP_FILE_DEDUP);
2024out_drop_write: 2070out_drop_write:
2025 mnt_drop_write_file(dst_file); 2071 mnt_drop_write_file(dst_file);
2026 2072
@@ -2037,7 +2083,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same)
2037 int i; 2083 int i;
2038 int ret; 2084 int ret;
2039 u16 count = same->dest_count; 2085 u16 count = same->dest_count;
2040 int deduped; 2086 loff_t deduped;
2041 2087
2042 if (!(file->f_mode & FMODE_READ)) 2088 if (!(file->f_mode & FMODE_READ))
2043 return -EINVAL; 2089 return -EINVAL;
@@ -2056,7 +2102,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same)
2056 if (!S_ISREG(src->i_mode)) 2102 if (!S_ISREG(src->i_mode))
2057 goto out; 2103 goto out;
2058 2104
2059 ret = clone_verify_area(file, off, len, false); 2105 ret = remap_verify_area(file, off, len, false);
2060 if (ret < 0) 2106 if (ret < 0)
2061 goto out; 2107 goto out;
2062 ret = 0; 2108 ret = 0;
@@ -2088,7 +2134,8 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same)
2088 } 2134 }
2089 2135
2090 deduped = vfs_dedupe_file_range_one(file, off, dst_file, 2136 deduped = vfs_dedupe_file_range_one(file, off, dst_file,
2091 info->dest_offset, len); 2137 info->dest_offset, len,
2138 REMAP_FILE_CAN_SHORTEN);
2092 if (deduped == -EBADE) 2139 if (deduped == -EBADE)
2093 info->status = FILE_DEDUPE_RANGE_DIFFERS; 2140 info->status = FILE_DEDUPE_RANGE_DIFFERS;
2094 else if (deduped < 0) 2141 else if (deduped < 0)