[4/5] ceph: simplify two mount_timeout sites
diff mbox

Message ID 1432211706-10473-5-git-send-email-idryomov@gmail.com
State New
Headers show

Commit Message

Ilya Dryomov May 21, 2015, 12:35 p.m. UTC
No need to bifurcate wait now that we've got ceph_timeout_jiffies().

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
 fs/ceph/dir.c        | 14 ++++----------
 fs/ceph/mds_client.c | 18 ++++++++++--------
 2 files changed, 14 insertions(+), 18 deletions(-)

Comments

Alex Elder May 21, 2015, 1:39 p.m. UTC | #1
On 05/21/2015 07:35 AM, Ilya Dryomov wrote:
> No need to bifurcate wait now that we've got ceph_timeout_jiffies().

Looks good.

Reviewed-by: Alex Elder <elder@linaro.org>

> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
> ---
>  fs/ceph/dir.c        | 14 ++++----------
>  fs/ceph/mds_client.c | 18 ++++++++++--------
>  2 files changed, 14 insertions(+), 18 deletions(-)
> 
> diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
> index 173dd4b58c71..3dec27e36417 100644
> --- a/fs/ceph/dir.c
> +++ b/fs/ceph/dir.c
> @@ -1257,17 +1257,11 @@ static int ceph_dir_fsync(struct file *file, loff_t start, loff_t end,
>  
>  		dout("dir_fsync %p wait on tid %llu (until %llu)\n",
>  		     inode, req->r_tid, last_tid);
> -		if (req->r_timeout) {
> -			unsigned long time_left = wait_for_completion_timeout(
> -					&req->r_safe_completion,
> +		ret = !wait_for_completion_timeout(&req->r_safe_completion,
>  					ceph_timeout_jiffies(req->r_timeout));
> -			if (time_left > 0)
> -				ret = 0;
> -			else
> -				ret = -EIO;  /* timed out */
> -		} else {
> -			wait_for_completion(&req->r_safe_completion);
> -		}
> +		if (ret)
> +			ret = -EIO;  /* timed out */
> +
>  		ceph_mdsc_put_request(req);
>  
>  		spin_lock(&ci->i_unsafe_lock);
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index 0b0e0a9a81c0..5be2d287a26c 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -2266,16 +2266,18 @@ int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
>  	/* wait */
>  	mutex_unlock(&mdsc->mutex);
>  	dout("do_request waiting\n");
> -	if (req->r_timeout) {
> -		err = (long)wait_for_completion_killable_timeout(
> -					&req->r_completion,
> -					ceph_timeout_jiffies(req->r_timeout));
> -		if (err == 0)
> -			err = -EIO;
> -	} else if (req->r_wait_for_completion) {
> +	if (!req->r_timeout && req->r_wait_for_completion) {
>  		err = req->r_wait_for_completion(mdsc, req);
>  	} else {
> -		err = wait_for_completion_killable(&req->r_completion);
> +		long timeleft = wait_for_completion_killable_timeout(
> +					&req->r_completion,
> +					ceph_timeout_jiffies(req->r_timeout));
> +		if (timeleft > 0)
> +			err = 0;
> +		else if (!timeleft)
> +			err = -EIO;  /* timed out */
> +		else
> +			err = timeleft;  /* killed */
>  	}
>  	dout("do_request waited, got %d\n", err);
>  	mutex_lock(&mdsc->mutex);
> 

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yan, Zheng May 21, 2015, 1:45 p.m. UTC | #2
On Thu, May 21, 2015 at 8:35 PM, Ilya Dryomov <idryomov@gmail.com> wrote:
> No need to bifurcate wait now that we've got ceph_timeout_jiffies().
>
> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
> ---
>  fs/ceph/dir.c        | 14 ++++----------
>  fs/ceph/mds_client.c | 18 ++++++++++--------
>  2 files changed, 14 insertions(+), 18 deletions(-)
>
> diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
> index 173dd4b58c71..3dec27e36417 100644
> --- a/fs/ceph/dir.c
> +++ b/fs/ceph/dir.c
> @@ -1257,17 +1257,11 @@ static int ceph_dir_fsync(struct file *file, loff_t start, loff_t end,
>
>                 dout("dir_fsync %p wait on tid %llu (until %llu)\n",
>                      inode, req->r_tid, last_tid);
> -               if (req->r_timeout) {
> -                       unsigned long time_left = wait_for_completion_timeout(
> -                                       &req->r_safe_completion,
> +               ret = !wait_for_completion_timeout(&req->r_safe_completion,
>                                         ceph_timeout_jiffies(req->r_timeout));
> -                       if (time_left > 0)
> -                               ret = 0;
> -                       else
> -                               ret = -EIO;  /* timed out */
> -               } else {
> -                       wait_for_completion(&req->r_safe_completion);
> -               }
> +               if (ret)
> +                       ret = -EIO;  /* timed out */
> +
>                 ceph_mdsc_put_request(req);
>
>                 spin_lock(&ci->i_unsafe_lock);
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index 0b0e0a9a81c0..5be2d287a26c 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -2266,16 +2266,18 @@ int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
>         /* wait */
>         mutex_unlock(&mdsc->mutex);
>         dout("do_request waiting\n");
> -       if (req->r_timeout) {
> -               err = (long)wait_for_completion_killable_timeout(
> -                                       &req->r_completion,
> -                                       ceph_timeout_jiffies(req->r_timeout));
> -               if (err == 0)
> -                       err = -EIO;
> -       } else if (req->r_wait_for_completion) {
> +       if (!req->r_timeout && req->r_wait_for_completion) {
>                 err = req->r_wait_for_completion(mdsc, req);
>         } else {
> -               err = wait_for_completion_killable(&req->r_completion);
> +               long timeleft = wait_for_completion_killable_timeout(
> +                                       &req->r_completion,
> +                                       ceph_timeout_jiffies(req->r_timeout));
> +               if (timeleft > 0)
> +                       err = 0;
> +               else if (!timeleft)
> +                       err = -EIO;  /* timed out */
> +               else
> +                       err = timeleft;  /* killed */
>         }
>         dout("do_request waited, got %d\n", err);
>         mutex_lock(&mdsc->mutex);
> --
> 1.9.3
>

Reviewed-by: Yan, Zheng <zyan@redhat.com>


> --
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 173dd4b58c71..3dec27e36417 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -1257,17 +1257,11 @@  static int ceph_dir_fsync(struct file *file, loff_t start, loff_t end,
 
 		dout("dir_fsync %p wait on tid %llu (until %llu)\n",
 		     inode, req->r_tid, last_tid);
-		if (req->r_timeout) {
-			unsigned long time_left = wait_for_completion_timeout(
-					&req->r_safe_completion,
+		ret = !wait_for_completion_timeout(&req->r_safe_completion,
 					ceph_timeout_jiffies(req->r_timeout));
-			if (time_left > 0)
-				ret = 0;
-			else
-				ret = -EIO;  /* timed out */
-		} else {
-			wait_for_completion(&req->r_safe_completion);
-		}
+		if (ret)
+			ret = -EIO;  /* timed out */
+
 		ceph_mdsc_put_request(req);
 
 		spin_lock(&ci->i_unsafe_lock);
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 0b0e0a9a81c0..5be2d287a26c 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -2266,16 +2266,18 @@  int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
 	/* wait */
 	mutex_unlock(&mdsc->mutex);
 	dout("do_request waiting\n");
-	if (req->r_timeout) {
-		err = (long)wait_for_completion_killable_timeout(
-					&req->r_completion,
-					ceph_timeout_jiffies(req->r_timeout));
-		if (err == 0)
-			err = -EIO;
-	} else if (req->r_wait_for_completion) {
+	if (!req->r_timeout && req->r_wait_for_completion) {
 		err = req->r_wait_for_completion(mdsc, req);
 	} else {
-		err = wait_for_completion_killable(&req->r_completion);
+		long timeleft = wait_for_completion_killable_timeout(
+					&req->r_completion,
+					ceph_timeout_jiffies(req->r_timeout));
+		if (timeleft > 0)
+			err = 0;
+		else if (!timeleft)
+			err = -EIO;  /* timed out */
+		else
+			err = timeleft;  /* killed */
 	}
 	dout("do_request waited, got %d\n", err);
 	mutex_lock(&mdsc->mutex);