mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									a452bc0636
								
							
						
					
					
						commit
						1199d7da2d
					
				
					 1 changed files with 30 additions and 46 deletions
				
			
		| 
						 | 
					@ -2525,9 +2525,14 @@ static void __take_cap_refs(struct ceph_inode_info *ci, int got,
 | 
				
			||||||
 * to (when applicable), and check against max_size here as well.
 | 
					 * to (when applicable), and check against max_size here as well.
 | 
				
			||||||
 * Note that caller is responsible for ensuring max_size increases are
 | 
					 * Note that caller is responsible for ensuring max_size increases are
 | 
				
			||||||
 * requested from the MDS.
 | 
					 * requested from the MDS.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Returns 0 if caps were not able to be acquired (yet), a 1 if they were,
 | 
				
			||||||
 | 
					 * or a negative error code.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * FIXME: how does a 0 return differ from -EAGAIN?
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
 | 
					static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
			    loff_t endoff, bool nonblock, int *got, int *err)
 | 
								    loff_t endoff, bool nonblock, int *got)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct inode *inode = &ci->vfs_inode;
 | 
						struct inode *inode = &ci->vfs_inode;
 | 
				
			||||||
	struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
 | 
						struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
 | 
				
			||||||
| 
						 | 
					@ -2547,8 +2552,7 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
	if ((file_wanted & need) != need) {
 | 
						if ((file_wanted & need) != need) {
 | 
				
			||||||
		dout("try_get_cap_refs need %s file_wanted %s, EBADF\n",
 | 
							dout("try_get_cap_refs need %s file_wanted %s, EBADF\n",
 | 
				
			||||||
		     ceph_cap_string(need), ceph_cap_string(file_wanted));
 | 
							     ceph_cap_string(need), ceph_cap_string(file_wanted));
 | 
				
			||||||
		*err = -EBADF;
 | 
							ret = -EBADF;
 | 
				
			||||||
		ret = 1;
 | 
					 | 
				
			||||||
		goto out_unlock;
 | 
							goto out_unlock;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2569,10 +2573,8 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
		if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) {
 | 
							if (endoff >= 0 && endoff > (loff_t)ci->i_max_size) {
 | 
				
			||||||
			dout("get_cap_refs %p endoff %llu > maxsize %llu\n",
 | 
								dout("get_cap_refs %p endoff %llu > maxsize %llu\n",
 | 
				
			||||||
			     inode, endoff, ci->i_max_size);
 | 
								     inode, endoff, ci->i_max_size);
 | 
				
			||||||
			if (endoff > ci->i_requested_max_size) {
 | 
								if (endoff > ci->i_requested_max_size)
 | 
				
			||||||
				*err = -EAGAIN;
 | 
									ret = -EAGAIN;
 | 
				
			||||||
				ret = 1;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			goto out_unlock;
 | 
								goto out_unlock;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
| 
						 | 
					@ -2607,8 +2609,7 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
					 * task isn't in TASK_RUNNING state
 | 
										 * task isn't in TASK_RUNNING state
 | 
				
			||||||
					 */
 | 
										 */
 | 
				
			||||||
					if (nonblock) {
 | 
										if (nonblock) {
 | 
				
			||||||
						*err = -EAGAIN;
 | 
											ret = -EAGAIN;
 | 
				
			||||||
						ret = 1;
 | 
					 | 
				
			||||||
						goto out_unlock;
 | 
											goto out_unlock;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2637,8 +2638,7 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
		if (session_readonly) {
 | 
							if (session_readonly) {
 | 
				
			||||||
			dout("get_cap_refs %p needed %s but mds%d readonly\n",
 | 
								dout("get_cap_refs %p needed %s but mds%d readonly\n",
 | 
				
			||||||
			     inode, ceph_cap_string(need), ci->i_auth_cap->mds);
 | 
								     inode, ceph_cap_string(need), ci->i_auth_cap->mds);
 | 
				
			||||||
			*err = -EROFS;
 | 
								ret = -EROFS;
 | 
				
			||||||
			ret = 1;
 | 
					 | 
				
			||||||
			goto out_unlock;
 | 
								goto out_unlock;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2647,16 +2647,14 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
			if (READ_ONCE(mdsc->fsc->mount_state) ==
 | 
								if (READ_ONCE(mdsc->fsc->mount_state) ==
 | 
				
			||||||
			    CEPH_MOUNT_SHUTDOWN) {
 | 
								    CEPH_MOUNT_SHUTDOWN) {
 | 
				
			||||||
				dout("get_cap_refs %p forced umount\n", inode);
 | 
									dout("get_cap_refs %p forced umount\n", inode);
 | 
				
			||||||
				*err = -EIO;
 | 
									ret = -EIO;
 | 
				
			||||||
				ret = 1;
 | 
					 | 
				
			||||||
				goto out_unlock;
 | 
									goto out_unlock;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			mds_wanted = __ceph_caps_mds_wanted(ci, false);
 | 
								mds_wanted = __ceph_caps_mds_wanted(ci, false);
 | 
				
			||||||
			if (need & ~(mds_wanted & need)) {
 | 
								if (need & ~(mds_wanted & need)) {
 | 
				
			||||||
				dout("get_cap_refs %p caps were dropped"
 | 
									dout("get_cap_refs %p caps were dropped"
 | 
				
			||||||
				     " (session killed?)\n", inode);
 | 
									     " (session killed?)\n", inode);
 | 
				
			||||||
				*err = -ESTALE;
 | 
									ret = -ESTALE;
 | 
				
			||||||
				ret = 1;
 | 
					 | 
				
			||||||
				goto out_unlock;
 | 
									goto out_unlock;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (!(file_wanted & ~mds_wanted))
 | 
								if (!(file_wanted & ~mds_wanted))
 | 
				
			||||||
| 
						 | 
					@ -2707,7 +2705,7 @@ static void check_max_size(struct inode *inode, loff_t endoff)
 | 
				
			||||||
int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want,
 | 
					int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
		      bool nonblock, int *got)
 | 
							      bool nonblock, int *got)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret, err = 0;
 | 
						int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	BUG_ON(need & ~CEPH_CAP_FILE_RD);
 | 
						BUG_ON(need & ~CEPH_CAP_FILE_RD);
 | 
				
			||||||
	BUG_ON(want & ~(CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO|CEPH_CAP_FILE_SHARED));
 | 
						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,
 | 
				
			||||||
	if (ret < 0)
 | 
						if (ret < 0)
 | 
				
			||||||
		return ret;
 | 
							return ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = try_get_cap_refs(ci, need, want, 0, nonblock, got, &err);
 | 
						ret = try_get_cap_refs(ci, need, want, 0, nonblock, got);
 | 
				
			||||||
	if (ret) {
 | 
						return ret == -EAGAIN ? 0 : ret;
 | 
				
			||||||
		if (err == -EAGAIN) {
 | 
					 | 
				
			||||||
			ret = 0;
 | 
					 | 
				
			||||||
		} else if (err < 0) {
 | 
					 | 
				
			||||||
			ret = err;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return ret;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
| 
						 | 
					@ -2734,7 +2725,7 @@ int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
 | 
					int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
		  loff_t endoff, int *got, struct page **pinned_page)
 | 
							  loff_t endoff, int *got, struct page **pinned_page)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int _got, ret, err = 0;
 | 
						int _got, ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = ceph_pool_perm_check(ci, need);
 | 
						ret = ceph_pool_perm_check(ci, need);
 | 
				
			||||||
	if (ret < 0)
 | 
						if (ret < 0)
 | 
				
			||||||
| 
						 | 
					@ -2744,21 +2735,19 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
		if (endoff > 0)
 | 
							if (endoff > 0)
 | 
				
			||||||
			check_max_size(&ci->vfs_inode, endoff);
 | 
								check_max_size(&ci->vfs_inode, endoff);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		err = 0;
 | 
					 | 
				
			||||||
		_got = 0;
 | 
							_got = 0;
 | 
				
			||||||
		ret = try_get_cap_refs(ci, need, want, endoff,
 | 
							ret = try_get_cap_refs(ci, need, want, endoff,
 | 
				
			||||||
				       false, &_got, &err);
 | 
									       false, &_got);
 | 
				
			||||||
		if (ret) {
 | 
							if (ret == -EAGAIN) {
 | 
				
			||||||
			if (err == -EAGAIN)
 | 
					 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
			if (err < 0)
 | 
							} else if (!ret) {
 | 
				
			||||||
				ret = err;
 | 
								int err;
 | 
				
			||||||
		} else {
 | 
					
 | 
				
			||||||
			DEFINE_WAIT_FUNC(wait, woken_wake_function);
 | 
								DEFINE_WAIT_FUNC(wait, woken_wake_function);
 | 
				
			||||||
			add_wait_queue(&ci->i_cap_wq, &wait);
 | 
								add_wait_queue(&ci->i_cap_wq, &wait);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			while (!try_get_cap_refs(ci, need, want, endoff,
 | 
								while (!(err = try_get_cap_refs(ci, need, want, endoff,
 | 
				
			||||||
						 true, &_got, &err)) {
 | 
												true, &_got))) {
 | 
				
			||||||
				if (signal_pending(current)) {
 | 
									if (signal_pending(current)) {
 | 
				
			||||||
					ret = -ERESTARTSYS;
 | 
										ret = -ERESTARTSYS;
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
| 
						 | 
					@ -2767,19 +2756,14 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			remove_wait_queue(&ci->i_cap_wq, &wait);
 | 
								remove_wait_queue(&ci->i_cap_wq, &wait);
 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (err == -EAGAIN)
 | 
								if (err == -EAGAIN)
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			if (err < 0)
 | 
					 | 
				
			||||||
				ret = err;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (ret < 0) {
 | 
							if (ret == -ESTALE) {
 | 
				
			||||||
			if (err == -ESTALE) {
 | 
					 | 
				
			||||||
			/* session was killed, try renew caps */
 | 
								/* session was killed, try renew caps */
 | 
				
			||||||
			ret = ceph_renew_caps(&ci->vfs_inode);
 | 
								ret = ceph_renew_caps(&ci->vfs_inode);
 | 
				
			||||||
			if (ret == 0)
 | 
								if (ret == 0)
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return ret;
 | 
								return ret;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue