aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ceph
diff options
context:
space:
mode:
authorJeff Layton <jlayton@kernel.org>2019-04-02 15:58:05 -0400
committerIlya Dryomov <idryomov@gmail.com>2019-05-07 13:22:38 -0400
commit1199d7da2d29dac5e3983ea1078dbd4ab107e33f (patch)
tree38dae5f4e59d7dd8340ad76e185fad11d996bccd /fs/ceph
parenta452bc0636728b8c12632ae4b5f4ddf39cbe39c1 (diff)
ceph: simplify arguments and return semantics of try_get_cap_refs
The return of this function is rather complex. It can return 0 or 1, and in the case of a 1 return, the "err" pointer will be filled out. This necessitates a lot of copying of values. We can achieve the same effect by just returning 0, 1 or a negative error code, and drop the "err" argument from this function. Signed-off-by: Jeff Layton <jlayton@kernel.org> Reviewed-by: "Yan, Zheng" <zyan@redhat.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'fs/ceph')
-rw-r--r--fs/ceph/caps.c76
1 files changed, 30 insertions, 46 deletions
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 90090a56899e..9e0b464d374f 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -2525,9 +2525,14 @@ static void __take_cap_refs(struct ceph_inode_info *ci, int got,
2525 * to (when applicable), and check against max_size here as well. 2525 * to (when applicable), and check against max_size here as well.
2526 * Note that caller is responsible for ensuring max_size increases are 2526 * Note that caller is responsible for ensuring max_size increases are
2527 * requested from the MDS. 2527 * requested from the MDS.
2528 *
2529 * Returns 0 if caps were not able to be acquired (yet), a 1 if they were,
2530 * or a negative error code.
2531 *
2532 * FIXME: how does a 0 return differ from -EAGAIN?
2528 */ 2533 */
2529static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, 2534static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
2530 loff_t endoff, bool nonblock, int *got, int *err) 2535 loff_t endoff, bool nonblock, int *got)
2531{ 2536{
2532 struct inode *inode = &ci->vfs_inode; 2537 struct inode *inode = &ci->vfs_inode;
2533 struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; 2538 struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
@@ -2547,8 +2552,7 @@ again:
2547 if ((file_wanted & need) != need) { 2552 if ((file_wanted & need) != need) {
2548 dout("try_get_cap_refs need %s file_wanted %s, EBADF\n", 2553 dout("try_get_cap_refs need %s file_wanted %s, EBADF\n",
2549 ceph_cap_string(need), ceph_cap_string(file_wanted)); 2554 ceph_cap_string(need), ceph_cap_string(file_wanted));
2550 *err = -EBADF; 2555 ret = -EBADF;
2551 ret = 1;
2552 goto out_unlock; 2556 goto out_unlock;
2553 } 2557 }
2554 2558
@@ -2569,10 +2573,8 @@ again:
2569 if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) { 2573 if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) {
2570 dout("get_cap_refs %p endoff %llu > maxsize %llu\n", 2574 dout("get_cap_refs %p endoff %llu > maxsize %llu\n",
2571 inode, endoff, ci->i_max_size); 2575 inode, endoff, ci->i_max_size);
2572 if (endoff > ci->i_requested_max_size) { 2576 if (endoff > ci->i_requested_max_size)
2573 *err = -EAGAIN; 2577 ret = -EAGAIN;
2574 ret = 1;
2575 }
2576 goto out_unlock; 2578 goto out_unlock;
2577 } 2579 }
2578 /* 2580 /*
@@ -2607,8 +2609,7 @@ again:
2607 * task isn't in TASK_RUNNING state 2609 * task isn't in TASK_RUNNING state
2608 */ 2610 */
2609 if (nonblock) { 2611 if (nonblock) {
2610 *err = -EAGAIN; 2612 ret = -EAGAIN;
2611 ret = 1;
2612 goto out_unlock; 2613 goto out_unlock;
2613 } 2614 }
2614 2615
@@ -2637,8 +2638,7 @@ again:
2637 if (session_readonly) { 2638 if (session_readonly) {
2638 dout("get_cap_refs %p needed %s but mds%d readonly\n", 2639 dout("get_cap_refs %p needed %s but mds%d readonly\n",
2639 inode, ceph_cap_string(need), ci->i_auth_cap->mds); 2640 inode, ceph_cap_string(need), ci->i_auth_cap->mds);
2640 *err = -EROFS; 2641 ret = -EROFS;
2641 ret = 1;
2642 goto out_unlock; 2642 goto out_unlock;
2643 } 2643 }
2644 2644
@@ -2647,16 +2647,14 @@ again:
2647 if (READ_ONCE(mdsc->fsc->mount_state) == 2647 if (READ_ONCE(mdsc->fsc->mount_state) ==
2648 CEPH_MOUNT_SHUTDOWN) { 2648 CEPH_MOUNT_SHUTDOWN) {
2649 dout("get_cap_refs %p forced umount\n", inode); 2649 dout("get_cap_refs %p forced umount\n", inode);
2650 *err = -EIO; 2650 ret = -EIO;
2651 ret = 1;
2652 goto out_unlock; 2651 goto out_unlock;
2653 } 2652 }
2654 mds_wanted = __ceph_caps_mds_wanted(ci, false); 2653 mds_wanted = __ceph_caps_mds_wanted(ci, false);
2655 if (need & ~(mds_wanted & need)) { 2654 if (need & ~(mds_wanted & need)) {
2656 dout("get_cap_refs %p caps were dropped" 2655 dout("get_cap_refs %p caps were dropped"
2657 " (session killed?)\n", inode); 2656 " (session killed?)\n", inode);
2658 *err = -ESTALE; 2657 ret = -ESTALE;
2659 ret = 1;
2660 goto out_unlock; 2658 goto out_unlock;
2661 } 2659 }
2662 if (!(file_wanted & ~mds_wanted)) 2660 if (!(file_wanted & ~mds_wanted))
@@ -2707,7 +2705,7 @@ static void check_max_size(struct inode *inode, loff_t endoff)
2707int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want, 2705int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want,
2708 bool nonblock, int *got) 2706 bool nonblock, int *got)
2709{ 2707{
2710 int ret, err = 0; 2708 int ret;
2711 2709
2712 BUG_ON(need & ~CEPH_CAP_FILE_RD); 2710 BUG_ON(need & ~CEPH_CAP_FILE_RD);
2713 BUG_ON(want & ~(CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO|CEPH_CAP_FILE_SHARED)); 2711 BUG_ON(want & ~(CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO|CEPH_CAP_FILE_SHARED));
@@ -2715,15 +2713,8 @@ int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want,
2715 if (ret < 0) 2713 if (ret < 0)
2716 return ret; 2714 return ret;
2717 2715
2718 ret = try_get_cap_refs(ci, need, want, 0, nonblock, got, &err); 2716 ret = try_get_cap_refs(ci, need, want, 0, nonblock, got);
2719 if (ret) { 2717 return ret == -EAGAIN ? 0 : ret;
2720 if (err == -EAGAIN) {
2721 ret = 0;
2722 } else if (err < 0) {
2723 ret = err;
2724 }
2725 }
2726 return ret;
2727} 2718}
2728 2719
2729/* 2720/*
@@ -2734,7 +2725,7 @@ int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want,
2734int ceph_get_caps(struct ceph_inode_info *ci, int need, int want, 2725int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
2735 loff_t endoff, int *got, struct page **pinned_page) 2726 loff_t endoff, int *got, struct page **pinned_page)
2736{ 2727{
2737 int _got, ret, err = 0; 2728 int _got, ret;
2738 2729
2739 ret = ceph_pool_perm_check(ci, need); 2730 ret = ceph_pool_perm_check(ci, need);
2740 if (ret < 0) 2731 if (ret < 0)
@@ -2744,21 +2735,19 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
2744 if (endoff > 0) 2735 if (endoff > 0)
2745 check_max_size(&ci->vfs_inode, endoff); 2736 check_max_size(&ci->vfs_inode, endoff);
2746 2737
2747 err = 0;
2748 _got = 0; 2738 _got = 0;
2749 ret = try_get_cap_refs(ci, need, want, endoff, 2739 ret = try_get_cap_refs(ci, need, want, endoff,
2750 false, &_got, &err); 2740 false, &_got);
2751 if (ret) { 2741 if (ret == -EAGAIN) {
2752 if (err == -EAGAIN) 2742 continue;
2753 continue; 2743 } else if (!ret) {
2754 if (err < 0) 2744 int err;
2755 ret = err; 2745
2756 } else {
2757 DEFINE_WAIT_FUNC(wait, woken_wake_function); 2746 DEFINE_WAIT_FUNC(wait, woken_wake_function);
2758 add_wait_queue(&ci->i_cap_wq, &wait); 2747 add_wait_queue(&ci->i_cap_wq, &wait);
2759 2748
2760 while (!try_get_cap_refs(ci, need, want, endoff, 2749 while (!(err = try_get_cap_refs(ci, need, want, endoff,
2761 true, &_got, &err)) { 2750 true, &_got))) {
2762 if (signal_pending(current)) { 2751 if (signal_pending(current)) {
2763 ret = -ERESTARTSYS; 2752 ret = -ERESTARTSYS;
2764 break; 2753 break;
@@ -2767,19 +2756,14 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
2767 } 2756 }
2768 2757
2769 remove_wait_queue(&ci->i_cap_wq, &wait); 2758 remove_wait_queue(&ci->i_cap_wq, &wait);
2770
2771 if (err == -EAGAIN) 2759 if (err == -EAGAIN)
2772 continue; 2760 continue;
2773 if (err < 0)
2774 ret = err;
2775 } 2761 }
2776 if (ret < 0) { 2762 if (ret == -ESTALE) {
2777 if (err == -ESTALE) { 2763 /* session was killed, try renew caps */
2778 /* session was killed, try renew caps */ 2764 ret = ceph_renew_caps(&ci->vfs_inode);
2779 ret = ceph_renew_caps(&ci->vfs_inode); 2765 if (ret == 0)
2780 if (ret == 0) 2766 continue;
2781 continue;
2782 }
2783 return ret; 2767 return ret;
2784 } 2768 }
2785 2769