Skip to contentSkip to conversation

ceph: skip reading from Rados if pos exceeds i_size

PATCH In review Xiubo Li 2 participants 3 messages Apr 21, 2022 – Apr 22, 2022 Ceph client

lore
Share & tools
lore

Xiubo Li

author
#0 lore raw

PATCH 1/1 ceph: skip reading from Rados if pos exceeds i_size

Since we have held the Fr capibility it's safe to skip reading from Rados if the ki_pos is larger than or euqals to the file size.

---
 fs/ceph/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/file.c +3 -1
index 6c9e837aa1d3..330e42b3afec 100644
@@ -1614,7 +1614,9 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
 		return ret;
 	}
 
-	if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 ||
+	if (unlikely(iocb->ki_pos >= i_size_read(inode))) {
+		ret = 0;
+	} else if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 ||
 	    (iocb->ki_flags & IOCB_DIRECT) ||
 	    (fi->flags & CEPH_F_SYNC)) {
 
Signature · 1 line
2.36.0.rc1
#1 lore raw
Quoted 3 lines · Xiubo Li

Since we have held the Fr capibility it's safe to skip reading from Rados if the ki_pos is larger than or euqals to the file size.

I'm not sure this is correct, based on the patch description. If you're in a mixed mode where there are writers and readers, they can all have Frw and extend the file size by issuing rados writes up to the max_size without updating each other. The client needs to have Fs before it can rely on knowing the file size, so we should check that before skipping a read, right?
-Greg

Quoted 24 lines
---
 fs/ceph/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/file.c +3 -2
index 6c9e837aa1d3..330e42b3afec 100644
@@ -1614,7 +1614,9 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
                return ret;
        }
 
-       if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 ||
+       if (unlikely(iocb->ki_pos >= i_size_read(inode))) {
+               ret = 0;
+       } else if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 ||
            (iocb->ki_flags & IOCB_DIRECT) ||
            (fi->flags & CEPH_F_SYNC)) {
 
--

2.36.0.rc1

author
#2 lore raw
Quoted 9 lines · Gregory Farnum
Quoted 2 lines · Xiubo Li

Since we have held the Fr capibility it's safe to skip reading from Rados if the ki_pos is larger than or euqals to the file size.

I'm not sure this is correct, based on the patch description. If you're in a mixed mode where there are writers and readers, they can all have Frw and extend the file size by issuing rados writes up to the max_size without updating each other. The client needs to have Fs before it can rely on knowing the file size, so we should check that before skipping a read, right?

There still need some other fixes in kclient, that is fixing the __ceph_should_report_size() to report the size to the MDS when the i_size changed and dirty the Fw caps before check_caps() for each write.  Then the MDS Locker code will issue new caps to all the clients.

While I think there still has a gap with this fixing. Because the readers may need a little time to get the notification and to update the new file size.

For now I will drop this change.

-- Xiubo

Quoted 25 lines

-Greg

Quoted 23 lines
---
  fs/ceph/file.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
fs/ceph/file.c +3 -2
index 6c9e837aa1d3..330e42b3afec 100644
@@ -1614,7 +1614,9 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
                 return ret;
         }
 
-       if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 ||
+       if (unlikely(iocb->ki_pos >= i_size_read(inode))) {
+               ret = 0;
+       } else if ((got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) == 0 ||
             (iocb->ki_flags & IOCB_DIRECT) ||
             (fi->flags & CEPH_F_SYNC)) {
 
--

2.36.0.rc1