]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
ceph: add __ceph_get_caps helper support
authorXiubo Li <xiubli@redhat.com>
Fri, 5 Nov 2021 14:22:12 +0000 (22:22 +0800)
committerJeff Layton <jlayton@kernel.org>
Tue, 31 May 2022 15:50:00 +0000 (11:50 -0400)
Break out the guts of ceph_get_caps into a helper that takes an inode
and ceph_file_info instead of a file pointer.

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

index 489ca530fc5ba9cf7c5ad5f4a3c571777ba623ae..be20a4f91865ef682bca808f9878b212108e2466 100644 (file)
@@ -2971,10 +2971,9 @@ int ceph_try_get_caps(struct inode *inode, int need, int want,
  * due to a small max_size, make sure we check_max_size (and possibly
  * ask the mds) so we don't get hung up indefinitely.
  */
-int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *got)
+int __ceph_get_caps(struct inode *inode, struct ceph_file_info *fi, int need,
+                   int want, loff_t endoff, int *got)
 {
-       struct ceph_file_info *fi = filp->private_data;
-       struct inode *inode = file_inode(filp);
        struct ceph_inode_info *ci = ceph_inode(inode);
        struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
        int ret, _got, flags;
@@ -2983,7 +2982,7 @@ int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *got
        if (ret < 0)
                return ret;
 
-       if ((fi->fmode & CEPH_FILE_MODE_WR) &&
+       if (fi && (fi->fmode & CEPH_FILE_MODE_WR) &&
            fi->filp_gen != READ_ONCE(fsc->filp_gen))
                return -EBADF;
 
@@ -2991,7 +2990,7 @@ int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *got
 
        while (true) {
                flags &= CEPH_FILE_MODE_MASK;
-               if (atomic_read(&fi->num_locks))
+               if (fi && atomic_read(&fi->num_locks))
                        flags |= CHECK_FILELOCK;
                _got = 0;
                ret = try_get_cap_refs(inode, need, want, endoff,
@@ -3036,7 +3035,7 @@ int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *got
                                continue;
                }
 
-               if ((fi->fmode & CEPH_FILE_MODE_WR) &&
+               if (fi && (fi->fmode & CEPH_FILE_MODE_WR) &&
                    fi->filp_gen != READ_ONCE(fsc->filp_gen)) {
                        if (ret >= 0 && _got)
                                ceph_put_cap_refs(ci, _got);
@@ -3099,6 +3098,14 @@ int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *got
        return 0;
 }
 
+int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *got)
+{
+       struct ceph_file_info *fi = filp->private_data;
+       struct inode *inode = file_inode(filp);
+
+       return __ceph_get_caps(inode, fi, need, want, endoff, got);
+}
+
 /*
  * Take cap refs.  Caller must already know we hold at least one ref
  * on the caps in question or we don't know this is safe.
index c23342df462d431ba91b788b83a15bfe17f65fcd..cdde9dcc23c2dc6acbbf660bc6bc783f58c2db2f 100644 (file)
@@ -1239,6 +1239,8 @@ extern int ceph_encode_dentry_release(void **p, struct dentry *dn,
                                      struct inode *dir,
                                      int mds, int drop, int unless);
 
+extern int __ceph_get_caps(struct inode *inode, struct ceph_file_info *fi,
+                          int need, int want, loff_t endoff, int *got);
 extern int ceph_get_caps(struct file *filp, int need, int want,
                         loff_t endoff, int *got);
 extern int ceph_try_get_caps(struct inode *inode,