Skip to contentSkip to conversation

ceph: skip copying the data extends the file EOF

PATCH In review [email protected] 3 participants 7 messages Mar 19, 2024 Ceph client

lore
Share & tools
lore
#0 lore raw

v3 cover ceph: skip copying the data extends the file EOF

From: Xiubo Li <[email protected]>

V3:
- Fixed incorrectly handling the left bug reported by Ilya.

V2:
- append a new patch to improve the getattr code

Xiubo Li (2):
ceph: skip copying the data extends the file EOF
ceph: set the correct mask for getattr reqeust for read

 fs/ceph/file.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/2 ceph: skip copying the data extends the file EOF

From: Xiubo Li <[email protected]>

If hits the EOF it will revise the return value to the i_size instead of the real length read, but it will advance the offset of iovc, then for the next try it may be incorrectly skipped.

This will just skip advancing the iovc's offset more than i_size.

URL: https://patchwork.kernel.org/project/ceph-devel/list/?series=819323

---
 fs/ceph/file.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
fs/ceph/file.c +13 -10
index 24a003eaa5e0..c35878427985 100644
@@ -1200,7 +1200,12 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,
 		}
 
 		idx = 0;
-		left = ret > 0 ? ret : 0;
+		if (ret <= 0)
+			left = 0;
+		else if (off + ret > i_size)
+			left = i_size - off;
+		else
+			left = ret;
 		while (left > 0) {
 			size_t plen, copied;
 
@@ -1229,15 +1234,13 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,
 	}
 
 	if (ret > 0) {
-		if (off > *ki_pos) {
-			if (off >= i_size) {
-				*retry_op = CHECK_EOF;
-				ret = i_size - *ki_pos;
-				*ki_pos = i_size;
-			} else {
-				ret = off - *ki_pos;
-				*ki_pos = off;
-			}
+		if (off >= i_size) {
+			*retry_op = CHECK_EOF;
+			ret = i_size - *ki_pos;
+			*ki_pos = i_size;
+		} else {
+			ret = off - *ki_pos;
+			*ki_pos = off;
 		}
 
 		if (last_objver)
Signature · 1 line
2.43.0
Reviewed-by Tested-by Tested-by on v3 1/2
#2 lore raw

Thanks Ilya for pointing this out.
I've tested the new patch and it looks good.

________________________________________
寄件者: [email protected] <[email protected]>
寄件日期: 2024年3月19日 上午 08:29
收件者: [email protected]
副本: [email protected]; [email protected]; [email protected]; [email protected]; Frank Hsiao 蕭法宣; Xiubo Li 主旨: [PATCH v3 1/2] ceph: skip copying the data extends the file EOF

From: Xiubo Li <[email protected]>

If hits the EOF it will revise the return value to the i_size instead of the real length read, but it will advance the offset of iovc, then for the next try it may be incorrectly skipped.

This will just skip advancing the iovc's offset more than i_size.

URL: https://patchwork.kernel.org/project/ceph-devel/list/?series=819323

---
 fs/ceph/file.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
fs/ceph/file.c +13 -10
index 24a003eaa5e0..c35878427985 100644
@@ -1200,7 +1200,12 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,
                }
 
                idx = 0;
-               left = ret > 0 ? ret : 0;
+               if (ret <= 0)
+                       left = 0;
+               else if (off + ret > i_size)
+                       left = i_size - off;
+               else
+                       left = ret;
                while (left > 0) {
                        size_t plen, copied;
 
@@ -1229,15 +1234,13 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,
        }
 
        if (ret > 0) {
-               if (off > *ki_pos) {
-                       if (off >= i_size) {
-                               *retry_op = CHECK_EOF;
-                               ret = i_size - *ki_pos;
-                               *ki_pos = i_size;
-                       } else {
-                               ret = off - *ki_pos;
-                               *ki_pos = off;
-                       }
+               if (off >= i_size) {
+                       *retry_op = CHECK_EOF;
+                       ret = i_size - *ki_pos;
+                       *ki_pos = i_size;
+               } else {
+                       ret = off - *ki_pos;
+                       *ki_pos = off;
                }
 
                if (last_objver)

--
2.43.0

#3 lore raw

PATCH v3 2/2 ceph: set the correct mask for getattr reqeust for read

In reply to [email protected]

From: Xiubo Li <[email protected]>

In case of hitting the file EOF the ceph_read_iter() needs to retrieve the file size from MDS, and the Fr caps is not a neccessary.

URL: https://patchwork.kernel.org/project/ceph-devel/list/?series=819323

---
 fs/ceph/file.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/ceph/file.c +5 -3
index c35878427985..a85f95c941fc 100644
@@ -2191,14 +2191,16 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
 		int statret;
 		struct page *page = NULL;
 		loff_t i_size;
+		int mask = CEPH_STAT_CAP_SIZE;
 		if (retry_op == READ_INLINE) {
 			page = __page_cache_alloc(GFP_KERNEL);
 			if (!page)
 				return -ENOMEM;
 		}
 
-		statret = __ceph_do_getattr(inode, page,
-					    CEPH_STAT_CAP_INLINE_DATA, !!page);
+		if (retry_op == READ_INLINE)
+			mask = CEPH_STAT_CAP_INLINE_DATA;
+		statret = __ceph_do_getattr(inode, page, mask, !!page);
 		if (statret < 0) {
 			if (page)
 				__free_page(page);
@@ -2239,7 +2241,7 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
 		/* hit EOF or hole? */
 		if (retry_op == CHECK_EOF && iocb->ki_pos < i_size &&
 		    ret < len) {
-			doutc(cl, "hit hole, ppos %lld < size %lld, reading more\n",
+			doutc(cl, "may hit hole, ppos %lld < size %lld, reading more\n",
 			      iocb->ki_pos, i_size);
 
 			read += ret;
Signature · 1 line
2.43.0
Reviewed-by Tested-by Tested-by on v3 2/2
#4 lore raw

回覆: [PATCH v3 2/2] ceph: set the correct mask for getattr reqeust for read

________________________________________
寄件者: [email protected] <[email protected]>
寄件日期: 2024年3月19日 上午 08:29
收件者: [email protected]
副本: [email protected]; [email protected]; [email protected]; [email protected]; Frank Hsiao 蕭法宣; Xiubo Li 主旨: [PATCH v3 2/2] ceph: set the correct mask for getattr reqeust for read

From: Xiubo Li <[email protected]>

In case of hitting the file EOF the ceph_read_iter() needs to retrieve the file size from MDS, and the Fr caps is not a neccessary.

URL: https://patchwork.kernel.org/project/ceph-devel/list/?series=819323

---
 fs/ceph/file.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/ceph/file.c +5 -3
index c35878427985..a85f95c941fc 100644
@@ -2191,14 +2191,16 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
                int statret;
                struct page *page = NULL;
                loff_t i_size;
+               int mask = CEPH_STAT_CAP_SIZE;
                if (retry_op == READ_INLINE) {
                        page = __page_cache_alloc(GFP_KERNEL);
                        if (!page)
                                return -ENOMEM;
                }
 
-               statret = __ceph_do_getattr(inode, page,
-                                           CEPH_STAT_CAP_INLINE_DATA, !!page);
+               if (retry_op == READ_INLINE)
+                       mask = CEPH_STAT_CAP_INLINE_DATA;
+               statret = __ceph_do_getattr(inode, page, mask, !!page);
                if (statret < 0) {
                        if (page)
                                __free_page(page);
@@ -2239,7 +2241,7 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
                /* hit EOF or hole? */
                if (retry_op == CHECK_EOF && iocb->ki_pos < i_size &&
                    ret < len) {
-                       doutc(cl, "hit hole, ppos %lld < size %lld, reading more\n",
+                       doutc(cl, "may hit hole, ppos %lld < size %lld, reading more\n",
                              iocb->ki_pos, i_size);
 
                        read += ret;

--
2.43.0

maintainer
#5 lore raw

Re: [PATCH v3 2/2] ceph: set the correct mask for getattr reqeust for read

In reply to [email protected]
Quoted 23 lines · On Tue, Mar 19, 2024 at 1:32 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

In case of hitting the file EOF the ceph_read_iter() needs to retrieve the file size from MDS, and the Fr caps is not a neccessary.

URL: https://patchwork.kernel.org/project/ceph-devel/list/?series=819323

---
 fs/ceph/file.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/ceph/file.c +1 -0
index c35878427985..a85f95c941fc 100644
@@ -2191,14 +2191,16 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
                int statret;
                struct page *page = NULL;
                loff_t i_size;
+               int mask = CEPH_STAT_CAP_SIZE;

fs/ceph/file.c static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) · line 2202

Quoted 10 lines
fs/ceph/file.c +2 -2
                if (retry_op == READ_INLINE) {
                        page = __page_cache_alloc(GFP_KERNEL);
                        if (!page)
                                return -ENOMEM;
                }
 
-               statret = __ceph_do_getattr(inode, page,
-                                           CEPH_STAT_CAP_INLINE_DATA, !!page);
+               if (retry_op == READ_INLINE)
+                       mask = CEPH_STAT_CAP_INLINE_DATA;

Hi Xiubo,

This introduces an additional retry_op == READ_INLINE branch right below an existing one. Should this be:

    int mask = CEPH_STAT_CAP_SIZE;
    if (retry_op == READ_INLINE) {
            page = __page_cache_alloc(GFP_KERNEL);
            if (!page)
                    return -ENOMEM;

            mask = CEPH_STAT_CAP_INLINE_DATA;
    }

Thanks,

Ilya

author
#6 lore raw

Re: [PATCH v3 2/2] ceph: set the correct mask for getattr reqeust for read

Quoted 38 lines · Ilya Dryomov
Quoted 22 lines · On Tue, Mar 19, 2024 at 1:32 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

In case of hitting the file EOF the ceph_read_iter() needs to retrieve the file size from MDS, and the Fr caps is not a neccessary.

URL: https://patchwork.kernel.org/project/ceph-devel/list/?series=819323

---
  fs/ceph/file.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
fs/ceph/file.c +1 -0
index c35878427985..a85f95c941fc 100644
@@ -2191,14 +2191,16 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
                 int statret;
                 struct page *page = NULL;
                 loff_t i_size;
+               int mask = CEPH_STAT_CAP_SIZE;

fs/ceph/file.c static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) · line 2202

Quoted 10 lines
fs/ceph/file.c +2 -2
                 if (retry_op == READ_INLINE) {
                         page = __page_cache_alloc(GFP_KERNEL);
                         if (!page)
                                 return -ENOMEM;
                 }
 
-               statret = __ceph_do_getattr(inode, page,
-                                           CEPH_STAT_CAP_INLINE_DATA, !!page);
+               if (retry_op == READ_INLINE)
+                       mask = CEPH_STAT_CAP_INLINE_DATA;

Hi Xiubo,

This introduces an additional retry_op == READ_INLINE branch right below an existing one. Should this be:

Quoted 8 lines
     int mask = CEPH_STAT_CAP_SIZE;
     if (retry_op == READ_INLINE) {
             page = __page_cache_alloc(GFP_KERNEL);
             if (!page)
                     return -ENOMEM;

             mask = CEPH_STAT_CAP_INLINE_DATA;
     }

Look good to me.

Thanks Ilya.

- Xiubo

Quoted 4 lines

Thanks,

Ilya