linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Tyler Hicks <code@tyhicks.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	ecryptfs@vger.kernel.org, Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH 05/10] ecryptfs: Convert ecryptfs_write() to use a folio
Date: Thu, 17 Oct 2024 16:17:00 +0100	[thread overview]
Message-ID: <20241017151709.2713048-6-willy@infradead.org> (raw)
In-Reply-To: <20241017151709.2713048-1-willy@infradead.org>

Remove ecryptfs_get_locked_page() and call read_mapping_folio()
directly.  Use the folio throught this function.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/ecryptfs/ecryptfs_kernel.h |  1 -
 fs/ecryptfs/mmap.c            | 16 ----------------
 fs/ecryptfs/read_write.c      | 25 +++++++++++++------------
 3 files changed, 13 insertions(+), 29 deletions(-)

diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index 43f1b5ff987d..f04aa24f6bcd 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -662,7 +662,6 @@ int ecryptfs_read_lower_page_segment(struct folio *folio_for_ecryptfs,
 				     pgoff_t page_index,
 				     size_t offset_in_page, size_t size,
 				     struct inode *ecryptfs_inode);
-struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index);
 int ecryptfs_parse_packet_length(unsigned char *data, size_t *size,
 				 size_t *length_size);
 int ecryptfs_write_packet_length(char *dest, size_t size,
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index b7ef0bf563bd..ad535bf9d2f9 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -22,22 +22,6 @@
 #include <linux/unaligned.h>
 #include "ecryptfs_kernel.h"
 
-/*
- * ecryptfs_get_locked_page
- *
- * Get one page from cache or lower f/s, return error otherwise.
- *
- * Returns locked and up-to-date page (if ok), with increased
- * refcnt.
- */
-struct page *ecryptfs_get_locked_page(struct inode *inode, loff_t index)
-{
-	struct page *page = read_mapping_page(inode->i_mapping, index, NULL);
-	if (!IS_ERR(page))
-		lock_page(page);
-	return page;
-}
-
 /*
  * This is where we encrypt the data and pass the encrypted data to
  * the lower filesystem.  In OpenPGP-compatible mode, we operate on
diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
index 251e9f6c6972..cddfdfced879 100644
--- a/fs/ecryptfs/read_write.c
+++ b/fs/ecryptfs/read_write.c
@@ -93,7 +93,6 @@ int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode,
 int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset,
 		   size_t size)
 {
-	struct page *ecryptfs_page;
 	struct ecryptfs_crypt_stat *crypt_stat;
 	char *ecryptfs_page_virt;
 	loff_t ecryptfs_file_size = i_size_read(ecryptfs_inode);
@@ -111,6 +110,7 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset,
 	else
 		pos = offset;
 	while (pos < (offset + size)) {
+		struct folio *ecryptfs_folio;
 		pgoff_t ecryptfs_page_idx = (pos >> PAGE_SHIFT);
 		size_t start_offset_in_page = (pos & ~PAGE_MASK);
 		size_t num_bytes = (PAGE_SIZE - start_offset_in_page);
@@ -130,17 +130,18 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset,
 			if (num_bytes > total_remaining_zeros)
 				num_bytes = total_remaining_zeros;
 		}
-		ecryptfs_page = ecryptfs_get_locked_page(ecryptfs_inode,
-							 ecryptfs_page_idx);
-		if (IS_ERR(ecryptfs_page)) {
-			rc = PTR_ERR(ecryptfs_page);
+		ecryptfs_folio = read_mapping_folio(ecryptfs_inode->i_mapping,
+				ecryptfs_page_idx, NULL);
+		if (IS_ERR(ecryptfs_folio)) {
+			rc = PTR_ERR(ecryptfs_folio);
 			printk(KERN_ERR "%s: Error getting page at "
 			       "index [%ld] from eCryptfs inode "
 			       "mapping; rc = [%d]\n", __func__,
 			       ecryptfs_page_idx, rc);
 			goto out;
 		}
-		ecryptfs_page_virt = kmap_local_page(ecryptfs_page);
+		folio_lock(ecryptfs_folio);
+		ecryptfs_page_virt = kmap_local_folio(ecryptfs_folio, 0);
 
 		/*
 		 * pos: where we're now writing, offset: where the request was
@@ -164,17 +165,17 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset,
 			data_offset += num_bytes;
 		}
 		kunmap_local(ecryptfs_page_virt);
-		flush_dcache_page(ecryptfs_page);
-		SetPageUptodate(ecryptfs_page);
-		unlock_page(ecryptfs_page);
+		flush_dcache_folio(ecryptfs_folio);
+		folio_mark_uptodate(ecryptfs_folio);
+		folio_unlock(ecryptfs_folio);
 		if (crypt_stat->flags & ECRYPTFS_ENCRYPTED)
-			rc = ecryptfs_encrypt_page(ecryptfs_page);
+			rc = ecryptfs_encrypt_page(&ecryptfs_folio->page);
 		else
 			rc = ecryptfs_write_lower_page_segment(ecryptfs_inode,
-						ecryptfs_page,
+						&ecryptfs_folio->page,
 						start_offset_in_page,
 						data_offset);
-		put_page(ecryptfs_page);
+		folio_put(ecryptfs_folio);
 		if (rc) {
 			printk(KERN_ERR "%s: Error encrypting "
 			       "page; rc = [%d]\n", __func__, rc);
-- 
2.43.0


  parent reply	other threads:[~2024-10-17 15:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17 15:16 [PATCH 00/10] Convert ecryptfs to use folios Matthew Wilcox (Oracle)
2024-10-17 15:16 ` [PATCH 01/10] ecryptfs: Convert ecryptfs_writepage() to ecryptfs_writepages() Matthew Wilcox (Oracle)
2024-10-18  6:23   ` Pankaj Raghav (Samsung)
2024-10-25 17:56     ` Matthew Wilcox
2024-10-17 15:16 ` [PATCH 02/10] ecryptfs: Use a folio throughout ecryptfs_read_folio() Matthew Wilcox (Oracle)
2024-10-18  6:21   ` Pankaj Raghav (Samsung)
2024-10-25 18:50     ` Matthew Wilcox
2024-10-17 15:16 ` [PATCH 03/10] ecryptfs: Convert ecryptfs_copy_up_encrypted_with_header() to take a folio Matthew Wilcox (Oracle)
2024-10-18  3:43   ` kernel test robot
2024-10-18  6:33   ` Pankaj Raghav (Samsung)
2024-10-17 15:16 ` [PATCH 04/10] ecryptfs: Convert ecryptfs_read_lower_page_segment() " Matthew Wilcox (Oracle)
2024-10-17 15:17 ` Matthew Wilcox (Oracle) [this message]
2024-10-18  8:07   ` [PATCH 05/10] ecryptfs: Convert ecryptfs_write() to use " Pankaj Raghav (Samsung)
2024-10-17 15:17 ` [PATCH 06/10] ecryptfs: Convert ecryptfs_write_lower_page_segment() to take " Matthew Wilcox (Oracle)
2024-10-17 15:17 ` [PATCH 07/10] ecryptfs: Convert ecryptfs_encrypt_page() " Matthew Wilcox (Oracle)
2024-10-18  5:06   ` kernel test robot
2024-10-17 15:17 ` [PATCH 08/10] ecryptfs: Convert ecryptfs_decrypt_page() " Matthew Wilcox (Oracle)
2024-10-18  6:39   ` kernel test robot
2024-10-17 15:17 ` [PATCH 09/10] ecryptfs: Convert lower_offset_for_page() " Matthew Wilcox (Oracle)
2024-10-17 15:17 ` [PATCH 10/10] ecryptfs: Pass the folio index to crypt_extent() Matthew Wilcox (Oracle)

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=20241017151709.2713048-6-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=brauner@kernel.org \
    --cc=code@tyhicks.com \
    --cc=ecryptfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).