Skip to contentSkip to conversation

ceph: misc fix size truncate for fscrypt

PATCH In review Xiubo Li 2 participants 5 messages Apr 12, 2022 – Apr 18, 2022 Ceph client

lore
Share & tools
lore

Xiubo Li

author
#0 lore raw

v3 cover ceph: misc fix size truncate for fscrypt

Hi Jeff,

This series could be squashed into the same previous commit:

e90dc20d37a3 ceph: add truncate size handling support for fscrypt

V3:
- fix possible kunmaping random vaddr bug, thanks Luis.

V2:
- remove the filemap lock related patch.
- fix caps reference leakage

Xiubo Li (3):
ceph: flush small range instead of the whole map for truncate
ceph: fix caps reference leakage for fscrypt size truncating
ceph: fix possible kunmaping random vaddr

 fs/ceph/inode.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
Signature · 1 line
2.36.0.rc1
author
#1 lore raw

PATCH v3 1/3 ceph: flush small range instead of the whole map for truncate

---
 fs/ceph/inode.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/ceph/inode.c +7 -2
index fa0d3018d981..a5145a2b7228 100644
@@ -2274,8 +2274,13 @@ static int fill_fscrypt_truncate(struct inode *inode,
 	     ceph_cap_string(issued));
 
 	/* Try to writeback the dirty pagecaches */
-	if (issued & (CEPH_CAP_FILE_BUFFER))
-		filemap_write_and_wait(inode->i_mapping);
+	if (issued & (CEPH_CAP_FILE_BUFFER)) {
+		loff_t lend = orig_pos + CEPH_FSCRYPT_BLOCK_SHIFT - 1;
+		ret = filemap_write_and_wait_range(inode->i_mapping,
+						   orig_pos, lend);
+		if (ret < 0)
+			goto out;
+	}
 
 	page = __page_cache_alloc(GFP_KERNEL);
 	if (page == NULL) {
Signature · 1 line
2.36.0.rc1
author
#2 lore raw

PATCH v3 2/3 ceph: fix caps reference leakage for fscrypt size truncating

In reply to Xiubo Li
---
 fs/ceph/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/inode.c +1 -1
index a5145a2b7228..1c775a365b5e 100644
@@ -2300,7 +2300,6 @@ static int fill_fscrypt_truncate(struct inode *inode,
 
 	pos = orig_pos;
 	ret = __ceph_sync_read(inode, &pos, &iter, &retry_op, &objver);
-	ceph_put_cap_refs(ci, got);
 	if (ret < 0)
 		goto out;
 
@@ -2364,6 +2363,7 @@ static int fill_fscrypt_truncate(struct inode *inode,
 out:
 	dout("%s %p size dropping cap refs on %s\n", __func__,
 	     inode, ceph_cap_string(got));
+	ceph_put_cap_refs(ci, got);
 	kunmap_local(iov.iov_base);
 	if (page)
 		__free_pages(page, 0);
Signature · 1 line
2.36.0.rc1
author
#3 lore raw

PATCH v3 3/3 ceph: fix possible kunmaping random vaddr

In reply to Xiubo Li
---
 fs/ceph/inode.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ceph/inode.c +3 -2
index 1c775a365b5e..83f18b058d8c 100644
@@ -2253,7 +2253,7 @@ static int fill_fscrypt_truncate(struct inode *inode,
 	loff_t pos, orig_pos = round_down(attr->ia_size, CEPH_FSCRYPT_BLOCK_SIZE);
 	u64 block = orig_pos >> CEPH_FSCRYPT_BLOCK_SHIFT;
 	struct ceph_pagelist *pagelist = NULL;
-	struct kvec iov;
+	struct kvec iov = {0};
 	struct iov_iter iter;
 	struct page *page = NULL;
 	struct ceph_fscrypt_truncate_size_header header;
@@ -2364,7 +2364,8 @@ static int fill_fscrypt_truncate(struct inode *inode,
 	dout("%s %p size dropping cap refs on %s\n", __func__,
 	     inode, ceph_cap_string(got));
 	ceph_put_cap_refs(ci, got);
-	kunmap_local(iov.iov_base);
+	if (iov.iov_base)
+		kunmap_local(iov.iov_base);
 	if (page)
 		__free_pages(page, 0);
 	if (ret && pagelist)
Signature · 1 line
2.36.0.rc1
#4 lore raw
In reply to Xiubo Li
Quoted 16 lines · Xiubo Li

Hi Jeff,

This series could be squashed into the same previous commit:

e90dc20d37a3 ceph: add truncate size handling support for fscrypt

V3:
- fix possible kunmaping random vaddr bug, thanks Luis.

V2:
- remove the filemap lock related patch.
- fix caps reference leakage

Quoted 8 lines

Xiubo Li (3):
ceph: flush small range instead of the whole map for truncate
ceph: fix caps reference leakage for fscrypt size truncating
ceph: fix possible kunmaping random vaddr

 fs/ceph/inode.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

Thanks Xiubo, this all looks good. I'll merge them into wip-fscrypt soon.

Cheers!

Signature · 1 line
Jeff Layton <[email protected]>