From patchwork Thu Aug 25 13:31:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 599996 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 317DDC04AA5 for ; Thu, 25 Aug 2022 13:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242808AbiHYNcb (ORCPT ); Thu, 25 Aug 2022 09:32:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242786AbiHYNcE (ORCPT ); Thu, 25 Aug 2022 09:32:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6496B56FE for ; Thu, 25 Aug 2022 06:31:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D369DB829C3 for ; Thu, 25 Aug 2022 13:31:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26C03C433D7; Thu, 25 Aug 2022 13:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661434306; bh=fbp+a2YYfz1QheitGR3a0gPXflgkrdQuN5YQXw5EBEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nPQNJbZh3AOTZE6pCciZazxKOZvdnbVxsn1rNPmNybceW7u0tVFDWKn0zv+l9ER4L wjBG588lrs7bi7rORZDFjNyF0V5MWm6nksqezLExqvm6FqskQk5qgo/495g8uN4VL6 84DQNIkfvmXJaLmkmQy6zvYD/3e17YPeW/9qe33NfM5UAeA+ItLBLePl7ozpH5qR1C R33TBtxbVFZD7neTr72AbVMvCsj5G67x0yUsNa2tqM24cWOXPg/wP381IkUqw9Nx3M mNSqYSIrMypS5sZQ2krh1LFZXmx3chQmD/FP+yKXaQv9G2XYrZ7RcEP5vih2P8vqxf 9obz6cJaywacA== From: Jeff Layton To: xiubli@redhat.com, idryomov@gmail.com Cc: lhenriques@suse.de, ceph-devel@vger.kernel.org Subject: [PATCH v15 17/29] ceph: align data in pages in ceph_sync_write Date: Thu, 25 Aug 2022 09:31:20 -0400 Message-Id: <20220825133132.153657-18-jlayton@kernel.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220825133132.153657-1-jlayton@kernel.org> References: <20220825133132.153657-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Encrypted files will need to be dealt with in block-sized chunks and once we do that, the way that ceph_sync_write aligns the data in the bounce buffer won't be acceptable. Change it to align the data the same way it would be aligned in the pagecache. Reviewed-by: Xiubo Li Signed-off-by: Jeff Layton --- fs/ceph/file.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 2444854dc805..bfba2e17cd0a 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1572,6 +1572,7 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos, bool check_caps = false; struct timespec64 mtime = current_time(inode); size_t count = iov_iter_count(from); + size_t off; if (ceph_snap(file_inode(file)) != CEPH_NOSNAP) return -EROFS; @@ -1609,12 +1610,7 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos, break; } - /* - * write from beginning of first page, - * regardless of io alignment - */ - num_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT; - + num_pages = calc_pages_for(pos, len); pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL); if (IS_ERR(pages)) { ret = PTR_ERR(pages); @@ -1622,9 +1618,12 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos, } left = len; + off = offset_in_page(pos); for (n = 0; n < num_pages; n++) { - size_t plen = min_t(size_t, left, PAGE_SIZE); - ret = copy_page_from_iter(pages[n], 0, plen, from); + size_t plen = min_t(size_t, left, PAGE_SIZE - off); + + ret = copy_page_from_iter(pages[n], off, plen, from); + off = 0; if (ret != plen) { ret = -EFAULT; break; @@ -1639,8 +1638,9 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos, req->r_inode = inode; - osd_req_op_extent_osd_data_pages(req, 0, pages, len, 0, - false, true); + osd_req_op_extent_osd_data_pages(req, 0, pages, len, + offset_in_page(pos), + false, true); req->r_mtime = mtime; ceph_osdc_start_request(&fsc->client->osdc, req);