tree: https://github.com/ceph/ceph-client.git wip-fscrypt head: 9ab30a676da19ce5d83364306a03d643dd446aca commit: 6341655663fe166fd30acca6b4e692d2fafb02e5 [53/64] ceph: add read/modify/write to ceph_sync_write config: microblaze-randconfig-m031-20220524 (https://download.01.org/0day-ci/archive/20220525/202205250038.pULlmpTX-lkp@xxxxxxxxx/config) compiler: microblaze-linux-gcc (GCC) 11.3.0 If you fix the issue, kindly add following tag where applicable Reported-by: kernel test robot <lkp@xxxxxxxxx> Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx> New smatch warnings: fs/ceph/file.c:1896 ceph_sync_write() error: uninitialized symbol 'assert_ver'. Old smatch warnings: fs/ceph/file.c:146 iter_get_bvecs_alloc() warn: Please consider using kvcalloc instead of kvmalloc_array vim +/assert_ver +1896 fs/ceph/file.c 06fee30f6a31f10 Yan, Zheng 2014-07-28 1550 static ssize_t 5dda377cf0a6bd4 Yan, Zheng 2015-04-30 1551 ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos, 5dda377cf0a6bd4 Yan, Zheng 2015-04-30 1552 struct ceph_snap_context *snapc) e8344e668915a74 majianpeng 2013-09-12 1553 { e8344e668915a74 majianpeng 2013-09-12 1554 struct file *file = iocb->ki_filp; e8344e668915a74 majianpeng 2013-09-12 1555 struct inode *inode = file_inode(file); e8344e668915a74 majianpeng 2013-09-12 1556 struct ceph_inode_info *ci = ceph_inode(inode); e8344e668915a74 majianpeng 2013-09-12 1557 struct ceph_fs_client *fsc = ceph_inode_to_client(inode); 6341655663fe166 Jeff Layton 2021-01-27 1558 struct ceph_osd_client *osdc = &fsc->client->osdc; e8344e668915a74 majianpeng 2013-09-12 1559 struct ceph_osd_request *req; e8344e668915a74 majianpeng 2013-09-12 1560 struct page **pages; e8344e668915a74 majianpeng 2013-09-12 1561 u64 len; e8344e668915a74 majianpeng 2013-09-12 1562 int num_pages; e8344e668915a74 majianpeng 2013-09-12 1563 int written = 0; e8344e668915a74 majianpeng 2013-09-12 1564 int ret; efb0ca765ac6f49 Yan, Zheng 2017-05-22 1565 bool check_caps = false; fac02ddf910814c Arnd Bergmann 2018-07-13 1566 struct timespec64 mtime = current_time(inode); 4908b822b300d2d Al Viro 2014-04-03 1567 size_t count = iov_iter_count(from); e8344e668915a74 majianpeng 2013-09-12 1568 e8344e668915a74 majianpeng 2013-09-12 1569 if (ceph_snap(file_inode(file)) != CEPH_NOSNAP) e8344e668915a74 majianpeng 2013-09-12 1570 return -EROFS; e8344e668915a74 majianpeng 2013-09-12 1571 1c0a9c2d9783604 Yan, Zheng 2017-08-16 1572 dout("sync_write on file %p %lld~%u snapc %p seq %lld\n", 1c0a9c2d9783604 Yan, Zheng 2017-08-16 1573 file, pos, (unsigned)count, snapc, snapc->seq); e8344e668915a74 majianpeng 2013-09-12 1574 e450f4d1a5d633d zhengbin 2019-02-01 1575 ret = filemap_write_and_wait_range(inode->i_mapping, e450f4d1a5d633d zhengbin 2019-02-01 1576 pos, pos + count - 1); e8344e668915a74 majianpeng 2013-09-12 1577 if (ret < 0) e8344e668915a74 majianpeng 2013-09-12 1578 return ret; e8344e668915a74 majianpeng 2013-09-12 1579 400e1286c0ec3fd Jeff Layton 2021-12-07 1580 ceph_fscache_invalidate(inode, false); e8344e668915a74 majianpeng 2013-09-12 1581 ret = invalidate_inode_pages2_range(inode->i_mapping, 09cbfeaf1a5a67b Kirill A. Shutemov 2016-04-01 1582 pos >> PAGE_SHIFT, e450f4d1a5d633d zhengbin 2019-02-01 1583 (pos + count - 1) >> PAGE_SHIFT); e8344e668915a74 majianpeng 2013-09-12 1584 if (ret < 0) e8344e668915a74 majianpeng 2013-09-12 1585 dout("invalidate_inode_pages2_range returned %d\n", ret); e8344e668915a74 majianpeng 2013-09-12 1586 4908b822b300d2d Al Viro 2014-04-03 1587 while ((len = iov_iter_count(from)) > 0) { e8344e668915a74 majianpeng 2013-09-12 1588 size_t left; e8344e668915a74 majianpeng 2013-09-12 1589 int n; 6341655663fe166 Jeff Layton 2021-01-27 1590 u64 write_pos = pos; 6341655663fe166 Jeff Layton 2021-01-27 1591 u64 write_len = len; 6341655663fe166 Jeff Layton 2021-01-27 1592 u64 objnum, objoff; 6341655663fe166 Jeff Layton 2021-01-27 1593 u32 xlen; 6341655663fe166 Jeff Layton 2021-01-27 1594 u64 assert_ver; 6341655663fe166 Jeff Layton 2021-01-27 1595 bool rmw; 6341655663fe166 Jeff Layton 2021-01-27 1596 bool first, last; 6341655663fe166 Jeff Layton 2021-01-27 1597 struct iov_iter saved_iter = *from; 6341655663fe166 Jeff Layton 2021-01-27 1598 size_t off; e8344e668915a74 majianpeng 2013-09-12 1599 6341655663fe166 Jeff Layton 2021-01-27 1600 ceph_fscrypt_adjust_off_and_len(inode, &write_pos, &write_len); 6341655663fe166 Jeff Layton 2021-01-27 1601 6341655663fe166 Jeff Layton 2021-01-27 1602 /* clamp the length to the end of first object */ 6341655663fe166 Jeff Layton 2021-01-27 1603 ceph_calc_file_object_mapping(&ci->i_layout, write_pos, 6341655663fe166 Jeff Layton 2021-01-27 1604 write_len, &objnum, &objoff, 6341655663fe166 Jeff Layton 2021-01-27 1605 &xlen); 6341655663fe166 Jeff Layton 2021-01-27 1606 write_len = xlen; 6341655663fe166 Jeff Layton 2021-01-27 1607 6341655663fe166 Jeff Layton 2021-01-27 1608 /* adjust len downward if it goes beyond current object */ 6341655663fe166 Jeff Layton 2021-01-27 1609 if (pos + len > write_pos + write_len) 6341655663fe166 Jeff Layton 2021-01-27 1610 len = write_pos + write_len - pos; 6341655663fe166 Jeff Layton 2021-01-27 1611 6341655663fe166 Jeff Layton 2021-01-27 1612 /* 6341655663fe166 Jeff Layton 2021-01-27 1613 * If we had to adjust the length or position to align with a 6341655663fe166 Jeff Layton 2021-01-27 1614 * crypto block, then we must do a read/modify/write cycle. We 6341655663fe166 Jeff Layton 2021-01-27 1615 * use a version assertion to redrive the thing if something 6341655663fe166 Jeff Layton 2021-01-27 1616 * changes in between. 6341655663fe166 Jeff Layton 2021-01-27 1617 */ 6341655663fe166 Jeff Layton 2021-01-27 1618 first = pos != write_pos; 6341655663fe166 Jeff Layton 2021-01-27 1619 last = (pos + len) != (write_pos + write_len); 6341655663fe166 Jeff Layton 2021-01-27 1620 rmw = first || last; 6341655663fe166 Jeff Layton 2021-01-27 1621 6341655663fe166 Jeff Layton 2021-01-27 1622 dout("sync_write ino %llx %lld~%llu adjusted %lld~%llu -- %srmw\n", 6341655663fe166 Jeff Layton 2021-01-27 1623 ci->i_vino.ino, pos, len, write_pos, write_len, rmw ? "" : "no "); 6341655663fe166 Jeff Layton 2021-01-27 1624 6341655663fe166 Jeff Layton 2021-01-27 1625 /* 6341655663fe166 Jeff Layton 2021-01-27 1626 * The data is emplaced into the page as it would be if it were in 6341655663fe166 Jeff Layton 2021-01-27 1627 * an array of pagecache pages. 6341655663fe166 Jeff Layton 2021-01-27 1628 */ 6341655663fe166 Jeff Layton 2021-01-27 1629 num_pages = calc_pages_for(write_pos, write_len); 6341655663fe166 Jeff Layton 2021-01-27 1630 pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL); 6341655663fe166 Jeff Layton 2021-01-27 1631 if (IS_ERR(pages)) { 6341655663fe166 Jeff Layton 2021-01-27 1632 ret = PTR_ERR(pages); 6341655663fe166 Jeff Layton 2021-01-27 1633 break; 6341655663fe166 Jeff Layton 2021-01-27 1634 } 6341655663fe166 Jeff Layton 2021-01-27 1635 6341655663fe166 Jeff Layton 2021-01-27 1636 /* Do we need to preload the pages? */ 6341655663fe166 Jeff Layton 2021-01-27 1637 if (rmw) { "assert_ver" is only initialized when "rmw" is true. 6341655663fe166 Jeff Layton 2021-01-27 1638 u64 first_pos = write_pos; 6341655663fe166 Jeff Layton 2021-01-27 1639 u64 last_pos = (write_pos + write_len) - CEPH_FSCRYPT_BLOCK_SIZE; 6341655663fe166 Jeff Layton 2021-01-27 1640 u64 read_len = CEPH_FSCRYPT_BLOCK_SIZE; 6341655663fe166 Jeff Layton 2021-01-27 1641 struct ceph_osd_req_op *op; 6341655663fe166 Jeff Layton 2021-01-27 1642 6341655663fe166 Jeff Layton 2021-01-27 1643 /* We should only need to do this for encrypted inodes */ 6341655663fe166 Jeff Layton 2021-01-27 1644 WARN_ON_ONCE(!IS_ENCRYPTED(inode)); 6341655663fe166 Jeff Layton 2021-01-27 1645 6341655663fe166 Jeff Layton 2021-01-27 1646 /* No need to do two reads if first and last blocks are same */ 6341655663fe166 Jeff Layton 2021-01-27 1647 if (first && last_pos == first_pos) 6341655663fe166 Jeff Layton 2021-01-27 1648 last = false; 6341655663fe166 Jeff Layton 2021-01-27 1649 6341655663fe166 Jeff Layton 2021-01-27 1650 /* 6341655663fe166 Jeff Layton 2021-01-27 1651 * Allocate a read request for one or two extents, depending 6341655663fe166 Jeff Layton 2021-01-27 1652 * on how the request was aligned. 6341655663fe166 Jeff Layton 2021-01-27 1653 */ 6341655663fe166 Jeff Layton 2021-01-27 1654 req = ceph_osdc_new_request(osdc, &ci->i_layout, 6341655663fe166 Jeff Layton 2021-01-27 1655 ci->i_vino, first ? first_pos : last_pos, 6341655663fe166 Jeff Layton 2021-01-27 1656 &read_len, 0, (first && last) ? 2 : 1, 6341655663fe166 Jeff Layton 2021-01-27 1657 CEPH_OSD_OP_SPARSE_READ, CEPH_OSD_FLAG_READ, 6341655663fe166 Jeff Layton 2021-01-27 1658 NULL, ci->i_truncate_seq, 6341655663fe166 Jeff Layton 2021-01-27 1659 ci->i_truncate_size, false); e8344e668915a74 majianpeng 2013-09-12 1660 if (IS_ERR(req)) { 6341655663fe166 Jeff Layton 2021-01-27 1661 ceph_release_page_vector(pages, num_pages); e8344e668915a74 majianpeng 2013-09-12 1662 ret = PTR_ERR(req); eab87235c0f5979 Al Viro 2014-04-03 1663 break; e8344e668915a74 majianpeng 2013-09-12 1664 } e8344e668915a74 majianpeng 2013-09-12 1665 6341655663fe166 Jeff Layton 2021-01-27 1666 /* Something is misaligned! */ 6341655663fe166 Jeff Layton 2021-01-27 1667 if (read_len != CEPH_FSCRYPT_BLOCK_SIZE) { 6341655663fe166 Jeff Layton 2021-01-27 1668 ceph_osdc_put_request(req); 6341655663fe166 Jeff Layton 2021-01-27 1669 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1670 ret = -EIO; 6341655663fe166 Jeff Layton 2021-01-27 1671 break; 6341655663fe166 Jeff Layton 2021-01-27 1672 } 6341655663fe166 Jeff Layton 2021-01-27 1673 6341655663fe166 Jeff Layton 2021-01-27 1674 /* Add extent for first block? */ 6341655663fe166 Jeff Layton 2021-01-27 1675 op = &req->r_ops[0]; 6341655663fe166 Jeff Layton 2021-01-27 1676 6341655663fe166 Jeff Layton 2021-01-27 1677 if (first) { 6341655663fe166 Jeff Layton 2021-01-27 1678 osd_req_op_extent_osd_data_pages(req, 0, pages, 6341655663fe166 Jeff Layton 2021-01-27 1679 CEPH_FSCRYPT_BLOCK_SIZE, 6341655663fe166 Jeff Layton 2021-01-27 1680 offset_in_page(first_pos), 6341655663fe166 Jeff Layton 2021-01-27 1681 false, false); 6341655663fe166 Jeff Layton 2021-01-27 1682 /* We only expect a single extent here */ 6341655663fe166 Jeff Layton 2021-01-27 1683 ret = __ceph_alloc_sparse_ext_map(op, 1); 6341655663fe166 Jeff Layton 2021-01-27 1684 if (ret) { 6341655663fe166 Jeff Layton 2021-01-27 1685 ceph_osdc_put_request(req); 6341655663fe166 Jeff Layton 2021-01-27 1686 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1687 break; 6341655663fe166 Jeff Layton 2021-01-27 1688 } 6341655663fe166 Jeff Layton 2021-01-27 1689 } 6341655663fe166 Jeff Layton 2021-01-27 1690 6341655663fe166 Jeff Layton 2021-01-27 1691 /* Add extent for last block */ 6341655663fe166 Jeff Layton 2021-01-27 1692 if (last) { 6341655663fe166 Jeff Layton 2021-01-27 1693 /* Init the other extent if first extent has been used */ 6341655663fe166 Jeff Layton 2021-01-27 1694 if (first) { 6341655663fe166 Jeff Layton 2021-01-27 1695 op = &req->r_ops[1]; 6341655663fe166 Jeff Layton 2021-01-27 1696 osd_req_op_extent_init(req, 1, CEPH_OSD_OP_SPARSE_READ, 6341655663fe166 Jeff Layton 2021-01-27 1697 last_pos, CEPH_FSCRYPT_BLOCK_SIZE, 6341655663fe166 Jeff Layton 2021-01-27 1698 ci->i_truncate_size, 6341655663fe166 Jeff Layton 2021-01-27 1699 ci->i_truncate_seq); 6341655663fe166 Jeff Layton 2021-01-27 1700 } 6341655663fe166 Jeff Layton 2021-01-27 1701 6341655663fe166 Jeff Layton 2021-01-27 1702 ret = __ceph_alloc_sparse_ext_map(op, 1); 6341655663fe166 Jeff Layton 2021-01-27 1703 if (ret) { 6341655663fe166 Jeff Layton 2021-01-27 1704 ceph_osdc_put_request(req); 6341655663fe166 Jeff Layton 2021-01-27 1705 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1706 break; 6341655663fe166 Jeff Layton 2021-01-27 1707 } 6341655663fe166 Jeff Layton 2021-01-27 1708 6341655663fe166 Jeff Layton 2021-01-27 1709 osd_req_op_extent_osd_data_pages(req, first ? 1 : 0, 6341655663fe166 Jeff Layton 2021-01-27 1710 &pages[num_pages - 1], 6341655663fe166 Jeff Layton 2021-01-27 1711 CEPH_FSCRYPT_BLOCK_SIZE, 6341655663fe166 Jeff Layton 2021-01-27 1712 offset_in_page(last_pos), 6341655663fe166 Jeff Layton 2021-01-27 1713 false, false); 6341655663fe166 Jeff Layton 2021-01-27 1714 } 6341655663fe166 Jeff Layton 2021-01-27 1715 6341655663fe166 Jeff Layton 2021-01-27 1716 ret = ceph_osdc_start_request(osdc, req, false); 6341655663fe166 Jeff Layton 2021-01-27 1717 if (!ret) 6341655663fe166 Jeff Layton 2021-01-27 1718 ret = ceph_osdc_wait_request(osdc, req); 6341655663fe166 Jeff Layton 2021-01-27 1719 6341655663fe166 Jeff Layton 2021-01-27 1720 /* FIXME: length field is wrong if there are 2 extents */ 6341655663fe166 Jeff Layton 2021-01-27 1721 ceph_update_read_metrics(&fsc->mdsc->metric, 6341655663fe166 Jeff Layton 2021-01-27 1722 req->r_start_latency, 6341655663fe166 Jeff Layton 2021-01-27 1723 req->r_end_latency, 6341655663fe166 Jeff Layton 2021-01-27 1724 read_len, ret); 6341655663fe166 Jeff Layton 2021-01-27 1725 6341655663fe166 Jeff Layton 2021-01-27 1726 /* Ok if object is not already present */ 6341655663fe166 Jeff Layton 2021-01-27 1727 if (ret == -ENOENT) { 6341655663fe166 Jeff Layton 2021-01-27 1728 /* 6341655663fe166 Jeff Layton 2021-01-27 1729 * If there is no object, then we can't assert 6341655663fe166 Jeff Layton 2021-01-27 1730 * on its version. Set it to 0, and we'll use an 6341655663fe166 Jeff Layton 2021-01-27 1731 * exclusive create instead. 6341655663fe166 Jeff Layton 2021-01-27 1732 */ 6341655663fe166 Jeff Layton 2021-01-27 1733 ceph_osdc_put_request(req); 6341655663fe166 Jeff Layton 2021-01-27 1734 assert_ver = 0; 6341655663fe166 Jeff Layton 2021-01-27 1735 ret = 0; 6341655663fe166 Jeff Layton 2021-01-27 1736 6341655663fe166 Jeff Layton 2021-01-27 1737 /* 6341655663fe166 Jeff Layton 2021-01-27 1738 * zero out the soon-to-be uncopied parts of the 6341655663fe166 Jeff Layton 2021-01-27 1739 * first and last pages. 6341655663fe166 Jeff Layton 2021-01-27 1740 */ 6341655663fe166 Jeff Layton 2021-01-27 1741 if (first) 6341655663fe166 Jeff Layton 2021-01-27 1742 zero_user_segment(pages[0], 0, 6341655663fe166 Jeff Layton 2021-01-27 1743 offset_in_page(first_pos)); 6341655663fe166 Jeff Layton 2021-01-27 1744 if (last) 6341655663fe166 Jeff Layton 2021-01-27 1745 zero_user_segment(pages[num_pages - 1], 6341655663fe166 Jeff Layton 2021-01-27 1746 offset_in_page(last_pos), 6341655663fe166 Jeff Layton 2021-01-27 1747 PAGE_SIZE); 6341655663fe166 Jeff Layton 2021-01-27 1748 } else { 6341655663fe166 Jeff Layton 2021-01-27 1749 if (ret < 0) { 6341655663fe166 Jeff Layton 2021-01-27 1750 ceph_osdc_put_request(req); 6341655663fe166 Jeff Layton 2021-01-27 1751 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1752 break; 6341655663fe166 Jeff Layton 2021-01-27 1753 } 6341655663fe166 Jeff Layton 2021-01-27 1754 6341655663fe166 Jeff Layton 2021-01-27 1755 op = &req->r_ops[0]; 6341655663fe166 Jeff Layton 2021-01-27 1756 if (op->extent.sparse_ext_cnt == 0) { 6341655663fe166 Jeff Layton 2021-01-27 1757 if (first) 6341655663fe166 Jeff Layton 2021-01-27 1758 zero_user_segment(pages[0], 0, 6341655663fe166 Jeff Layton 2021-01-27 1759 offset_in_page(first_pos)); 6341655663fe166 Jeff Layton 2021-01-27 1760 else 6341655663fe166 Jeff Layton 2021-01-27 1761 zero_user_segment(pages[num_pages - 1], 6341655663fe166 Jeff Layton 2021-01-27 1762 offset_in_page(last_pos), 6341655663fe166 Jeff Layton 2021-01-27 1763 PAGE_SIZE); 6341655663fe166 Jeff Layton 2021-01-27 1764 } else if (op->extent.sparse_ext_cnt != 1 || 6341655663fe166 Jeff Layton 2021-01-27 1765 ceph_sparse_ext_map_end(op) != 6341655663fe166 Jeff Layton 2021-01-27 1766 CEPH_FSCRYPT_BLOCK_SIZE) { 6341655663fe166 Jeff Layton 2021-01-27 1767 ret = -EIO; 6341655663fe166 Jeff Layton 2021-01-27 1768 ceph_osdc_put_request(req); 6341655663fe166 Jeff Layton 2021-01-27 1769 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1770 break; 6341655663fe166 Jeff Layton 2021-01-27 1771 } 6341655663fe166 Jeff Layton 2021-01-27 1772 6341655663fe166 Jeff Layton 2021-01-27 1773 if (first && last) { 6341655663fe166 Jeff Layton 2021-01-27 1774 op = &req->r_ops[1]; 6341655663fe166 Jeff Layton 2021-01-27 1775 if (op->extent.sparse_ext_cnt == 0) { 6341655663fe166 Jeff Layton 2021-01-27 1776 zero_user_segment(pages[num_pages - 1], 6341655663fe166 Jeff Layton 2021-01-27 1777 offset_in_page(last_pos), 6341655663fe166 Jeff Layton 2021-01-27 1778 PAGE_SIZE); 6341655663fe166 Jeff Layton 2021-01-27 1779 } else if (op->extent.sparse_ext_cnt != 1 || 6341655663fe166 Jeff Layton 2021-01-27 1780 ceph_sparse_ext_map_end(op) != 6341655663fe166 Jeff Layton 2021-01-27 1781 CEPH_FSCRYPT_BLOCK_SIZE) { 6341655663fe166 Jeff Layton 2021-01-27 1782 ret = -EIO; 6341655663fe166 Jeff Layton 2021-01-27 1783 ceph_osdc_put_request(req); 6341655663fe166 Jeff Layton 2021-01-27 1784 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1785 break; 6341655663fe166 Jeff Layton 2021-01-27 1786 } 6341655663fe166 Jeff Layton 2021-01-27 1787 } 6341655663fe166 Jeff Layton 2021-01-27 1788 6341655663fe166 Jeff Layton 2021-01-27 1789 /* Grab assert version. It must be non-zero. */ 6341655663fe166 Jeff Layton 2021-01-27 1790 assert_ver = req->r_version; 6341655663fe166 Jeff Layton 2021-01-27 1791 WARN_ON_ONCE(ret > 0 && assert_ver == 0); 6341655663fe166 Jeff Layton 2021-01-27 1792 6341655663fe166 Jeff Layton 2021-01-27 1793 ceph_osdc_put_request(req); 6341655663fe166 Jeff Layton 2021-01-27 1794 if (first) { 6341655663fe166 Jeff Layton 2021-01-27 1795 ret = ceph_fscrypt_decrypt_block_inplace(inode, 6341655663fe166 Jeff Layton 2021-01-27 1796 pages[0], 6341655663fe166 Jeff Layton 2021-01-27 1797 CEPH_FSCRYPT_BLOCK_SIZE, 6341655663fe166 Jeff Layton 2021-01-27 1798 offset_in_page(first_pos), 6341655663fe166 Jeff Layton 2021-01-27 1799 first_pos >> CEPH_FSCRYPT_BLOCK_SHIFT); 6341655663fe166 Jeff Layton 2021-01-27 1800 if (ret < 0) { 6341655663fe166 Jeff Layton 2021-01-27 1801 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1802 break; 6341655663fe166 Jeff Layton 2021-01-27 1803 } 6341655663fe166 Jeff Layton 2021-01-27 1804 } 6341655663fe166 Jeff Layton 2021-01-27 1805 if (last) { 6341655663fe166 Jeff Layton 2021-01-27 1806 ret = ceph_fscrypt_decrypt_block_inplace(inode, 6341655663fe166 Jeff Layton 2021-01-27 1807 pages[num_pages - 1], 6341655663fe166 Jeff Layton 2021-01-27 1808 CEPH_FSCRYPT_BLOCK_SIZE, 6341655663fe166 Jeff Layton 2021-01-27 1809 offset_in_page(last_pos), 6341655663fe166 Jeff Layton 2021-01-27 1810 last_pos >> CEPH_FSCRYPT_BLOCK_SHIFT); 6341655663fe166 Jeff Layton 2021-01-27 1811 if (ret < 0) { 6341655663fe166 Jeff Layton 2021-01-27 1812 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1813 break; 6341655663fe166 Jeff Layton 2021-01-27 1814 } 6341655663fe166 Jeff Layton 2021-01-27 1815 } 6341655663fe166 Jeff Layton 2021-01-27 1816 } 124e68e74099090 Sage Weil 2009-10-06 1817 } e8344e668915a74 majianpeng 2013-09-12 1818 e8344e668915a74 majianpeng 2013-09-12 1819 left = len; 54f371cad7e715f Jeff Layton 2021-01-25 1820 off = offset_in_page(pos); e8344e668915a74 majianpeng 2013-09-12 1821 for (n = 0; n < num_pages; n++) { 54f371cad7e715f Jeff Layton 2021-01-25 1822 size_t plen = min_t(size_t, left, PAGE_SIZE - off); 54f371cad7e715f Jeff Layton 2021-01-25 1823 6341655663fe166 Jeff Layton 2021-01-27 1824 /* copy the data */ 54f371cad7e715f Jeff Layton 2021-01-25 1825 ret = copy_page_from_iter(pages[n], off, plen, from); e8344e668915a74 majianpeng 2013-09-12 1826 if (ret != plen) { e8344e668915a74 majianpeng 2013-09-12 1827 ret = -EFAULT; e8344e668915a74 majianpeng 2013-09-12 1828 break; e8344e668915a74 majianpeng 2013-09-12 1829 } 6341655663fe166 Jeff Layton 2021-01-27 1830 off = 0; e8344e668915a74 majianpeng 2013-09-12 1831 left -= ret; e8344e668915a74 majianpeng 2013-09-12 1832 } 6341655663fe166 Jeff Layton 2021-01-27 1833 if (ret < 0) { 6341655663fe166 Jeff Layton 2021-01-27 1834 dout("sync_write write failed with %d\n", ret); 6341655663fe166 Jeff Layton 2021-01-27 1835 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1836 break; 6341655663fe166 Jeff Layton 2021-01-27 1837 } e8344e668915a74 majianpeng 2013-09-12 1838 6341655663fe166 Jeff Layton 2021-01-27 1839 if (IS_ENCRYPTED(inode)) { 6341655663fe166 Jeff Layton 2021-01-27 1840 ret = ceph_fscrypt_encrypt_pages(inode, pages, 6341655663fe166 Jeff Layton 2021-01-27 1841 write_pos, write_len, 6341655663fe166 Jeff Layton 2021-01-27 1842 GFP_KERNEL); 124e68e74099090 Sage Weil 2009-10-06 1843 if (ret < 0) { 6341655663fe166 Jeff Layton 2021-01-27 1844 dout("encryption failed with %d\n", ret); 124e68e74099090 Sage Weil 2009-10-06 1845 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1846 break; 6341655663fe166 Jeff Layton 2021-01-27 1847 } 124e68e74099090 Sage Weil 2009-10-06 1848 } 124e68e74099090 Sage Weil 2009-10-06 1849 6341655663fe166 Jeff Layton 2021-01-27 1850 req = ceph_osdc_new_request(osdc, &ci->i_layout, 6341655663fe166 Jeff Layton 2021-01-27 1851 ci->i_vino, write_pos, &write_len, 6341655663fe166 Jeff Layton 2021-01-27 1852 rmw ? 1 : 0, rmw ? 2 : 1, 6341655663fe166 Jeff Layton 2021-01-27 1853 CEPH_OSD_OP_WRITE, 6341655663fe166 Jeff Layton 2021-01-27 1854 CEPH_OSD_FLAG_WRITE, 6341655663fe166 Jeff Layton 2021-01-27 1855 snapc, ci->i_truncate_seq, 6341655663fe166 Jeff Layton 2021-01-27 1856 ci->i_truncate_size, false); 6341655663fe166 Jeff Layton 2021-01-27 1857 if (IS_ERR(req)) { 6341655663fe166 Jeff Layton 2021-01-27 1858 ret = PTR_ERR(req); 6341655663fe166 Jeff Layton 2021-01-27 1859 ceph_release_page_vector(pages, num_pages); 6341655663fe166 Jeff Layton 2021-01-27 1860 break; 6341655663fe166 Jeff Layton 2021-01-27 1861 } 6341655663fe166 Jeff Layton 2021-01-27 1862 6341655663fe166 Jeff Layton 2021-01-27 1863 dout("sync_write write op %lld~%llu\n", write_pos, write_len); 6341655663fe166 Jeff Layton 2021-01-27 1864 osd_req_op_extent_osd_data_pages(req, rmw ? 1 : 0, pages, write_len, 6341655663fe166 Jeff Layton 2021-01-27 1865 offset_in_page(write_pos), false, 6341655663fe166 Jeff Layton 2021-01-27 1866 true); 26be88087ae8a04 Alex Elder 2013-04-15 1867 req->r_inode = inode; 6341655663fe166 Jeff Layton 2021-01-27 1868 req->r_mtime = mtime; e8344e668915a74 majianpeng 2013-09-12 1869 6341655663fe166 Jeff Layton 2021-01-27 1870 /* Set up the assertion */ 6341655663fe166 Jeff Layton 2021-01-27 1871 if (rmw) { 6341655663fe166 Jeff Layton 2021-01-27 1872 /* 6341655663fe166 Jeff Layton 2021-01-27 1873 * Set up the assertion. If we don't have a version number, 6341655663fe166 Jeff Layton 2021-01-27 1874 * then the object doesn't exist yet. Use an exclusive create 6341655663fe166 Jeff Layton 2021-01-27 1875 * instead of a version assertion in that case. 6341655663fe166 Jeff Layton 2021-01-27 1876 */ 6341655663fe166 Jeff Layton 2021-01-27 1877 if (assert_ver) { 6341655663fe166 Jeff Layton 2021-01-27 1878 osd_req_op_init(req, 0, CEPH_OSD_OP_ASSERT_VER, 0); 6341655663fe166 Jeff Layton 2021-01-27 1879 req->r_ops[0].assert_ver.ver = assert_ver; 6341655663fe166 Jeff Layton 2021-01-27 1880 } else { 6341655663fe166 Jeff Layton 2021-01-27 1881 osd_req_op_init(req, 0, CEPH_OSD_OP_CREATE, 6341655663fe166 Jeff Layton 2021-01-27 1882 CEPH_OSD_OP_FLAG_EXCL); 6341655663fe166 Jeff Layton 2021-01-27 1883 } 6341655663fe166 Jeff Layton 2021-01-27 1884 } 124e68e74099090 Sage Weil 2009-10-06 1885 6341655663fe166 Jeff Layton 2021-01-27 1886 ret = ceph_osdc_start_request(osdc, req, false); 26be88087ae8a04 Alex Elder 2013-04-15 1887 if (!ret) 6341655663fe166 Jeff Layton 2021-01-27 1888 ret = ceph_osdc_wait_request(osdc, req); 124e68e74099090 Sage Weil 2009-10-06 1889 8ae99ae2b40766a Xiubo Li 2021-03-22 1890 ceph_update_write_metrics(&fsc->mdsc->metric, req->r_start_latency, 903f4fec78dd05a Xiubo Li 2021-05-13 1891 req->r_end_latency, len, ret); 124e68e74099090 Sage Weil 2009-10-06 1892 ceph_osdc_put_request(req); 26544c623e741ac Jeff Layton 2017-04-04 1893 if (ret != 0) { 6341655663fe166 Jeff Layton 2021-01-27 1894 dout("sync_write osd write returned %d\n", ret); 6341655663fe166 Jeff Layton 2021-01-27 1895 /* Version changed! Must re-do the rmw cycle */ 6341655663fe166 Jeff Layton 2021-01-27 @1896 if ((assert_ver && (ret == -ERANGE || ret == -EOVERFLOW)) || How do we know "rmw" is true at this point? 6341655663fe166 Jeff Layton 2021-01-27 1897 (!assert_ver && ret == -EEXIST)) { 6341655663fe166 Jeff Layton 2021-01-27 1898 /* We should only ever see this on a rmw */ 6341655663fe166 Jeff Layton 2021-01-27 1899 WARN_ON_ONCE(!rmw); Although this WARN_ON() suggests that it *is* true... 6341655663fe166 Jeff Layton 2021-01-27 1900 6341655663fe166 Jeff Layton 2021-01-27 1901 /* The version should never go backward */ 6341655663fe166 Jeff Layton 2021-01-27 1902 WARN_ON_ONCE(ret == -EOVERFLOW); 6341655663fe166 Jeff Layton 2021-01-27 1903 6341655663fe166 Jeff Layton 2021-01-27 1904 *from = saved_iter; 6341655663fe166 Jeff Layton 2021-01-27 1905 6341655663fe166 Jeff Layton 2021-01-27 1906 /* FIXME: limit number of times we loop? */ 6341655663fe166 Jeff Layton 2021-01-27 1907 continue; 6341655663fe166 Jeff Layton 2021-01-27 1908 } 26544c623e741ac Jeff Layton 2017-04-04 1909 ceph_set_error_write(ci); 26544c623e741ac Jeff Layton 2017-04-04 1910 break; 26544c623e741ac Jeff Layton 2017-04-04 1911 } 26544c623e741ac Jeff Layton 2017-04-04 1912 ceph_clear_error_write(ci); 124e68e74099090 Sage Weil 2009-10-06 1913 pos += len; 124e68e74099090 Sage Weil 2009-10-06 1914 written += len; 6341655663fe166 Jeff Layton 2021-01-27 1915 dout("sync_write written %d\n", written); e8344e668915a74 majianpeng 2013-09-12 1916 if (pos > i_size_read(inode)) { 124e68e74099090 Sage Weil 2009-10-06 1917 check_caps = ceph_inode_set_size(inode, pos); 124e68e74099090 Sage Weil 2009-10-06 1918 if (check_caps) e8344e668915a74 majianpeng 2013-09-12 1919 ceph_check_caps(ceph_inode(inode), e8344e668915a74 majianpeng 2013-09-12 1920 CHECK_CAPS_AUTHONLY, 124e68e74099090 Sage Weil 2009-10-06 1921 NULL); e8344e668915a74 majianpeng 2013-09-12 1922 } 26544c623e741ac Jeff Layton 2017-04-04 1923 e8344e668915a74 majianpeng 2013-09-12 1924 } e8344e668915a74 majianpeng 2013-09-12 1925 e8344e668915a74 majianpeng 2013-09-12 1926 if (ret != -EOLDSNAPC && written > 0) { ee7289bfadda5f4 majianpeng 2013-08-21 1927 ret = written; e8344e668915a74 majianpeng 2013-09-12 1928 iocb->ki_pos = pos; 124e68e74099090 Sage Weil 2009-10-06 1929 } 6341655663fe166 Jeff Layton 2021-01-27 1930 dout("sync_write returning %d\n", ret); 124e68e74099090 Sage Weil 2009-10-06 1931 return ret; 124e68e74099090 Sage Weil 2009-10-06 1932 } -- 0-DAY CI Kernel Test Service https://01.org/lkp