]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
ceph: add __ceph_sync_read helper support
authorXiubo Li <xiubli@redhat.com>
Thu, 25 Aug 2022 13:31:12 +0000 (09:31 -0400)
committerXiubo Li <xiubli@redhat.com>
Fri, 26 Aug 2022 23:58:55 +0000 (07:58 +0800)
Turn the guts of ceph_sync_read into a new helper that takes an inode
and an offset instead of a kiocb struct, and make ceph_sync_read call
the helper as a wrapper.

Signed-off-by: Xiubo Li <xiubli@redhat.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
fs/ceph/file.c
fs/ceph/super.h

index 0dba7ec6744998781ff5dd7fc7c2c50397682b08..d21378eeb43b548f039724d650e6c382ff95602d 100644 (file)
@@ -951,22 +951,19 @@ enum {
  * If we get a short result from the OSD, check against i_size; we need to
  * only return a short read to the caller if we hit EOF.
  */
-static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,
-                             int *retry_op)
+ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,
+                        struct iov_iter *to, int *retry_op)
 {
-       struct file *file = iocb->ki_filp;
-       struct inode *inode = file_inode(file);
        struct ceph_inode_info *ci = ceph_inode(inode);
        struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
        struct ceph_osd_client *osdc = &fsc->client->osdc;
        ssize_t ret;
-       u64 off = iocb->ki_pos;
+       u64 off = *ki_pos;
        u64 len = iov_iter_count(to);
        u64 i_size = i_size_read(inode);
        bool sparse = ceph_test_mount_opt(fsc, SPARSEREAD);
 
-       dout("sync_read on file %p %llu~%u %s\n", file, off, (unsigned)len,
-            (file->f_flags & O_DIRECT) ? "O_DIRECT" : "");
+       dout("sync_read on inode %p %llx~%llx\n", inode, *ki_pos, len);
 
        if (!len)
                return 0;
@@ -1084,14 +1081,14 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,
                        break;
        }
 
-       if (off > iocb->ki_pos) {
+       if (off > *ki_pos) {
                if (off >= i_size) {
                        *retry_op = CHECK_EOF;
-                       ret = i_size - iocb->ki_pos;
-                       iocb->ki_pos = i_size;
+                       ret = i_size - *ki_pos;
+                       *ki_pos = i_size;
                } else {
-                       ret = off - iocb->ki_pos;
-                       iocb->ki_pos = off;
+                       ret = off - *ki_pos;
+                       *ki_pos = off;
                }
        }
 
@@ -1099,6 +1096,18 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,
        return ret;
 }
 
+static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,
+                             int *retry_op)
+{
+       struct file *file = iocb->ki_filp;
+       struct inode *inode = file_inode(file);
+
+       dout("sync_read on file %p %llx~%zx %s\n", file, iocb->ki_pos,
+            iov_iter_count(to), (file->f_flags & O_DIRECT) ? "O_DIRECT" : "");
+
+       return __ceph_sync_read(inode, &iocb->ki_pos, to, retry_op);
+}
+
 struct ceph_aio_request {
        struct kiocb *iocb;
        size_t total_len;
index 52a99e0aa796953fa57b85a5c20b07d76119b154..8b5095bd18abde5926f3d9be8e443febbcb77bff 100644 (file)
@@ -1276,6 +1276,8 @@ extern int ceph_renew_caps(struct inode *inode, int fmode);
 extern int ceph_open(struct inode *inode, struct file *file);
 extern int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
                            struct file *file, unsigned flags, umode_t mode);
+extern ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,
+                               struct iov_iter *to, int *retry_op);
 extern int ceph_release(struct inode *inode, struct file *filp);
 extern void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
                                  char *data, size_t len);