Re: [PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-10-25 Thread Zach Brown

Matthew Wilcox wrote:
> Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
> All callers then check the return value and break out of their loops.

This won't work because "sync" kiocbs are a nasty hack that don't follow
the (also nasty) refcounting patterns of the aio core.

-EIOCBRETRY means that aio_{read,write}() has taken on the "IO" kiocb
reference and has ensured that call kick_iocb() will be called in the
future.

Usually kick_iocb() would queue the kiocb to have its ki_retry method
called by the kernel aio threads while holding that reference.  But
"sync" kiocbs are on-stack and aren't reference counted.  kick_iocb() magic:

/* sync iocbs are easy: they can only ever be executing from a

 * single context. */
if (is_sync_kiocb(iocb)) {
kiocbSetKicked(iocb);
wake_up_process(iocb->ki_obj.tsk);

return;

}

So, with this patch, if we catch a signal and return from
wait_on_retry_sync_kiocb() and return from do_sync_{read,write}() then
that on-stack sync kiocb is going to be long gone when kick_iocb() goes
to work with it.

So the first step would be to make sync kiocbs real refcounted
structures so that kick_iocb() could find that the sync submitter has
disappeared.

But then we have to worry about leaving retrying operations in flight
after the sync submitter has returned from their system call.  They
might be VERY SURPRISED to find that a read() implemented with
do_sync_read() is still writing into their userspace pointer after the
syscall was interrupted by a signal.

This leads us to the possibility of working with the ki_cancel method to
stop a pending operation if a signal is caught from a sync submitter.
In practice, nothing sets ki_cancel.

And finally, this code will not be run in a solely mainline kernel.  The
only thing in mainline that returns -EIOCBRETRY is the goofy usb gadget.
 It has both ->{read,write} and ->aio_{read,write} file op methods so
vfs_{read,write}() will never call do_sync_{read,write}().  Sure,
out-of-tree aio providers (SDP?) might get caught up in this.

(Ha ha!  Welcome to fs/aio.c!)

So I'm not sure where to go with this.  It's a mess, but it doesn't seem
like anything is using it.  A significant clean up of the retry and
cancelation support in fs/aio.c is in flight.  Maybe we can revisit this
once that settles down.

- z
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-10-25 Thread Zach Brown

Matthew Wilcox wrote:
 Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
 All callers then check the return value and break out of their loops.

This won't work because sync kiocbs are a nasty hack that don't follow
the (also nasty) refcounting patterns of the aio core.

-EIOCBRETRY means that aio_{read,write}() has taken on the IO kiocb
reference and has ensured that call kick_iocb() will be called in the
future.

Usually kick_iocb() would queue the kiocb to have its ki_retry method
called by the kernel aio threads while holding that reference.  But
sync kiocbs are on-stack and aren't reference counted.  kick_iocb() magic:

/* sync iocbs are easy: they can only ever be executing from a

 * single context. */
if (is_sync_kiocb(iocb)) {
kiocbSetKicked(iocb);
wake_up_process(iocb-ki_obj.tsk);

return;

}

So, with this patch, if we catch a signal and return from
wait_on_retry_sync_kiocb() and return from do_sync_{read,write}() then
that on-stack sync kiocb is going to be long gone when kick_iocb() goes
to work with it.

So the first step would be to make sync kiocbs real refcounted
structures so that kick_iocb() could find that the sync submitter has
disappeared.

But then we have to worry about leaving retrying operations in flight
after the sync submitter has returned from their system call.  They
might be VERY SURPRISED to find that a read() implemented with
do_sync_read() is still writing into their userspace pointer after the
syscall was interrupted by a signal.

This leads us to the possibility of working with the ki_cancel method to
stop a pending operation if a signal is caught from a sync submitter.
In practice, nothing sets ki_cancel.

And finally, this code will not be run in a solely mainline kernel.  The
only thing in mainline that returns -EIOCBRETRY is the goofy usb gadget.
 It has both -{read,write} and -aio_{read,write} file op methods so
vfs_{read,write}() will never call do_sync_{read,write}().  Sure,
out-of-tree aio providers (SDP?) might get caught up in this.

(Ha ha!  Welcome to fs/aio.c!)

So I'm not sure where to go with this.  It's a mess, but it doesn't seem
like anything is using it.  A significant clean up of the retry and
cancelation support in fs/aio.c is in flight.  Maybe we can revisit this
once that settles down.

- z
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-10-24 Thread Nick Piggin
On Friday 19 October 2007 08:26, Matthew Wilcox wrote:
> Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
> All callers then check the return value and break out of their loops.
>
> Signed-off-by: Matthew Wilcox <[EMAIL PROTECTED]>
> ---
>  fs/read_write.c |   17 -
>  1 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/fs/read_write.c b/fs/read_write.c
> index 124693e..3196a3b 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -218,14 +218,15 @@ Einval:
>   return -EINVAL;
>  }
>
> -static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
> +static int wait_on_retry_sync_kiocb(struct kiocb *iocb)
>  {
> - set_current_state(TASK_UNINTERRUPTIBLE);
> + set_current_state(TASK_KILLABLE);
>   if (!kiocbIsKicked(iocb))
>   schedule();
>   else
>   kiocbClearKicked(iocb);
>   __set_current_state(TASK_RUNNING);
> + return fatal_signal_pending(current) ? -EINTR : 0;

Although the EINTR never gets to userspace anyway, is there a good
reason why the last patch for do_generic_mapping_read doesn't pass
back -EINTR?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-10-24 Thread Andrew Morton
On Wed, 24 Oct 2007 08:24:58 -0400 Matthew Wilcox <[EMAIL PROTECTED]> wrote:

> Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
> All callers then check the return value and break out of their loops.
> 

Let's cc the AIO list on AIO patches, please.

> ---
>  fs/read_write.c |   17 -
>  1 files changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/read_write.c b/fs/read_write.c
> index 124693e..3196a3b 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -218,14 +218,15 @@ Einval:
>   return -EINVAL;
>  }
>  
> -static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
> +static int wait_on_retry_sync_kiocb(struct kiocb *iocb)
>  {
> - set_current_state(TASK_UNINTERRUPTIBLE);
> + set_current_state(TASK_KILLABLE);
>   if (!kiocbIsKicked(iocb))
>   schedule();
>   else
>   kiocbClearKicked(iocb);
>   __set_current_state(TASK_RUNNING);
> + return fatal_signal_pending(current) ? -EINTR : 0;
>  }
>  
>  ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t 
> *ppos)
> @@ -242,7 +243,9 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, 
> size_t len, loff_t *pp
>   ret = filp->f_op->aio_read(, , 1, kiocb.ki_pos);
>   if (ret != -EIOCBRETRY)
>   break;
> - wait_on_retry_sync_kiocb();
> + ret = wait_on_retry_sync_kiocb();
> + if (ret)
> + break;
>   }
>  
>   if (-EIOCBQUEUED == ret)
> @@ -300,7 +303,9 @@ ssize_t do_sync_write(struct file *filp, const char 
> __user *buf, size_t len, lof
>   ret = filp->f_op->aio_write(, , 1, kiocb.ki_pos);
>   if (ret != -EIOCBRETRY)
>   break;
> - wait_on_retry_sync_kiocb();
> + ret = wait_on_retry_sync_kiocb();
> + if (ret)
> + break;
>   }
>  
>   if (-EIOCBQUEUED == ret)
> @@ -466,7 +471,9 @@ ssize_t do_sync_readv_writev(struct file *filp, const 
> struct iovec *iov,
>   ret = fn(, iov, nr_segs, kiocb.ki_pos);
>   if (ret != -EIOCBRETRY)
>   break;
> - wait_on_retry_sync_kiocb();
> + ret = wait_on_retry_sync_kiocb();
> + if (ret)
> + break;
>   }
>  
>   if (ret == -EIOCBQUEUED)
> -- 
> 1.4.4.2
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-10-24 Thread Matthew Wilcox
Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
All callers then check the return value and break out of their loops.

Signed-off-by: Matthew Wilcox <[EMAIL PROTECTED]>
---
 fs/read_write.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 124693e..3196a3b 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -218,14 +218,15 @@ Einval:
return -EINVAL;
 }
 
-static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
+static int wait_on_retry_sync_kiocb(struct kiocb *iocb)
 {
-   set_current_state(TASK_UNINTERRUPTIBLE);
+   set_current_state(TASK_KILLABLE);
if (!kiocbIsKicked(iocb))
schedule();
else
kiocbClearKicked(iocb);
__set_current_state(TASK_RUNNING);
+   return fatal_signal_pending(current) ? -EINTR : 0;
 }
 
 ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t 
*ppos)
@@ -242,7 +243,9 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, 
size_t len, loff_t *pp
ret = filp->f_op->aio_read(, , 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb();
+   ret = wait_on_retry_sync_kiocb();
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -300,7 +303,9 @@ ssize_t do_sync_write(struct file *filp, const char __user 
*buf, size_t len, lof
ret = filp->f_op->aio_write(, , 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb();
+   ret = wait_on_retry_sync_kiocb();
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -466,7 +471,9 @@ ssize_t do_sync_readv_writev(struct file *filp, const 
struct iovec *iov,
ret = fn(, iov, nr_segs, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb();
+   ret = wait_on_retry_sync_kiocb();
+   if (ret)
+   break;
}
 
if (ret == -EIOCBQUEUED)
-- 
1.4.4.2

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-10-24 Thread Andrew Morton
On Wed, 24 Oct 2007 08:24:58 -0400 Matthew Wilcox [EMAIL PROTECTED] wrote:

 Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
 All callers then check the return value and break out of their loops.
 

Let's cc the AIO list on AIO patches, please.

 ---
  fs/read_write.c |   17 -
  1 files changed, 12 insertions(+), 5 deletions(-)
 
 diff --git a/fs/read_write.c b/fs/read_write.c
 index 124693e..3196a3b 100644
 --- a/fs/read_write.c
 +++ b/fs/read_write.c
 @@ -218,14 +218,15 @@ Einval:
   return -EINVAL;
  }
  
 -static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
 +static int wait_on_retry_sync_kiocb(struct kiocb *iocb)
  {
 - set_current_state(TASK_UNINTERRUPTIBLE);
 + set_current_state(TASK_KILLABLE);
   if (!kiocbIsKicked(iocb))
   schedule();
   else
   kiocbClearKicked(iocb);
   __set_current_state(TASK_RUNNING);
 + return fatal_signal_pending(current) ? -EINTR : 0;
  }
  
  ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t 
 *ppos)
 @@ -242,7 +243,9 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, 
 size_t len, loff_t *pp
   ret = filp-f_op-aio_read(kiocb, iov, 1, kiocb.ki_pos);
   if (ret != -EIOCBRETRY)
   break;
 - wait_on_retry_sync_kiocb(kiocb);
 + ret = wait_on_retry_sync_kiocb(kiocb);
 + if (ret)
 + break;
   }
  
   if (-EIOCBQUEUED == ret)
 @@ -300,7 +303,9 @@ ssize_t do_sync_write(struct file *filp, const char 
 __user *buf, size_t len, lof
   ret = filp-f_op-aio_write(kiocb, iov, 1, kiocb.ki_pos);
   if (ret != -EIOCBRETRY)
   break;
 - wait_on_retry_sync_kiocb(kiocb);
 + ret = wait_on_retry_sync_kiocb(kiocb);
 + if (ret)
 + break;
   }
  
   if (-EIOCBQUEUED == ret)
 @@ -466,7 +471,9 @@ ssize_t do_sync_readv_writev(struct file *filp, const 
 struct iovec *iov,
   ret = fn(kiocb, iov, nr_segs, kiocb.ki_pos);
   if (ret != -EIOCBRETRY)
   break;
 - wait_on_retry_sync_kiocb(kiocb);
 + ret = wait_on_retry_sync_kiocb(kiocb);
 + if (ret)
 + break;
   }
  
   if (ret == -EIOCBQUEUED)
 -- 
 1.4.4.2
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-10-24 Thread Nick Piggin
On Friday 19 October 2007 08:26, Matthew Wilcox wrote:
 Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
 All callers then check the return value and break out of their loops.

 Signed-off-by: Matthew Wilcox [EMAIL PROTECTED]
 ---
  fs/read_write.c |   17 -
  1 files changed, 12 insertions(+), 5 deletions(-)

 diff --git a/fs/read_write.c b/fs/read_write.c
 index 124693e..3196a3b 100644
 --- a/fs/read_write.c
 +++ b/fs/read_write.c
 @@ -218,14 +218,15 @@ Einval:
   return -EINVAL;
  }

 -static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
 +static int wait_on_retry_sync_kiocb(struct kiocb *iocb)
  {
 - set_current_state(TASK_UNINTERRUPTIBLE);
 + set_current_state(TASK_KILLABLE);
   if (!kiocbIsKicked(iocb))
   schedule();
   else
   kiocbClearKicked(iocb);
   __set_current_state(TASK_RUNNING);
 + return fatal_signal_pending(current) ? -EINTR : 0;

Although the EINTR never gets to userspace anyway, is there a good
reason why the last patch for do_generic_mapping_read doesn't pass
back -EINTR?
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-10-24 Thread Matthew Wilcox
Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
All callers then check the return value and break out of their loops.

Signed-off-by: Matthew Wilcox [EMAIL PROTECTED]
---
 fs/read_write.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 124693e..3196a3b 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -218,14 +218,15 @@ Einval:
return -EINVAL;
 }
 
-static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
+static int wait_on_retry_sync_kiocb(struct kiocb *iocb)
 {
-   set_current_state(TASK_UNINTERRUPTIBLE);
+   set_current_state(TASK_KILLABLE);
if (!kiocbIsKicked(iocb))
schedule();
else
kiocbClearKicked(iocb);
__set_current_state(TASK_RUNNING);
+   return fatal_signal_pending(current) ? -EINTR : 0;
 }
 
 ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t 
*ppos)
@@ -242,7 +243,9 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, 
size_t len, loff_t *pp
ret = filp-f_op-aio_read(kiocb, iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb(kiocb);
+   ret = wait_on_retry_sync_kiocb(kiocb);
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -300,7 +303,9 @@ ssize_t do_sync_write(struct file *filp, const char __user 
*buf, size_t len, lof
ret = filp-f_op-aio_write(kiocb, iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb(kiocb);
+   ret = wait_on_retry_sync_kiocb(kiocb);
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -466,7 +471,9 @@ ssize_t do_sync_readv_writev(struct file *filp, const 
struct iovec *iov,
ret = fn(kiocb, iov, nr_segs, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb(kiocb);
+   ret = wait_on_retry_sync_kiocb(kiocb);
+   if (ret)
+   break;
}
 
if (ret == -EIOCBQUEUED)
-- 
1.4.4.2

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-10-18 Thread Matthew Wilcox
Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
All callers then check the return value and break out of their loops.

Signed-off-by: Matthew Wilcox <[EMAIL PROTECTED]>
---
 fs/read_write.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 124693e..3196a3b 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -218,14 +218,15 @@ Einval:
return -EINVAL;
 }
 
-static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
+static int wait_on_retry_sync_kiocb(struct kiocb *iocb)
 {
-   set_current_state(TASK_UNINTERRUPTIBLE);
+   set_current_state(TASK_KILLABLE);
if (!kiocbIsKicked(iocb))
schedule();
else
kiocbClearKicked(iocb);
__set_current_state(TASK_RUNNING);
+   return fatal_signal_pending(current) ? -EINTR : 0;
 }
 
 ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t 
*ppos)
@@ -242,7 +243,9 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, 
size_t len, loff_t *pp
ret = filp->f_op->aio_read(, , 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb();
+   ret = wait_on_retry_sync_kiocb();
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -300,7 +303,9 @@ ssize_t do_sync_write(struct file *filp, const char __user 
*buf, size_t len, lof
ret = filp->f_op->aio_write(, , 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb();
+   ret = wait_on_retry_sync_kiocb();
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -466,7 +471,9 @@ ssize_t do_sync_readv_writev(struct file *filp, const 
struct iovec *iov,
ret = fn(, iov, nr_segs, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb();
+   ret = wait_on_retry_sync_kiocb();
+   if (ret)
+   break;
}
 
if (ret == -EIOCBQUEUED)
-- 
1.4.4.2

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-10-18 Thread Matthew Wilcox
Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
All callers then check the return value and break out of their loops.

Signed-off-by: Matthew Wilcox [EMAIL PROTECTED]
---
 fs/read_write.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 124693e..3196a3b 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -218,14 +218,15 @@ Einval:
return -EINVAL;
 }
 
-static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
+static int wait_on_retry_sync_kiocb(struct kiocb *iocb)
 {
-   set_current_state(TASK_UNINTERRUPTIBLE);
+   set_current_state(TASK_KILLABLE);
if (!kiocbIsKicked(iocb))
schedule();
else
kiocbClearKicked(iocb);
__set_current_state(TASK_RUNNING);
+   return fatal_signal_pending(current) ? -EINTR : 0;
 }
 
 ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t 
*ppos)
@@ -242,7 +243,9 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, 
size_t len, loff_t *pp
ret = filp-f_op-aio_read(kiocb, iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb(kiocb);
+   ret = wait_on_retry_sync_kiocb(kiocb);
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -300,7 +303,9 @@ ssize_t do_sync_write(struct file *filp, const char __user 
*buf, size_t len, lof
ret = filp-f_op-aio_write(kiocb, iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb(kiocb);
+   ret = wait_on_retry_sync_kiocb(kiocb);
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -466,7 +471,9 @@ ssize_t do_sync_readv_writev(struct file *filp, const 
struct iovec *iov,
ret = fn(kiocb, iov, nr_segs, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb(kiocb);
+   ret = wait_on_retry_sync_kiocb(kiocb);
+   if (ret)
+   break;
}
 
if (ret == -EIOCBQUEUED)
-- 
1.4.4.2

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-09-01 Thread Matthew Wilcox
Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
All callers then check the return value and break out of their loops.

Signed-off-by: Matthew Wilcox <[EMAIL PROTECTED]>
---
 fs/read_write.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 507ddff..b1a52d5 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -218,14 +218,15 @@ Einval:
return -EINVAL;
 }
 
-static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
+static int wait_on_retry_sync_kiocb(struct kiocb *iocb)
 {
-   set_current_state(TASK_UNINTERRUPTIBLE);
+   set_current_state(TASK_KILLABLE);
if (!kiocbIsKicked(iocb))
schedule();
else
kiocbClearKicked(iocb);
__set_current_state(TASK_RUNNING);
+   return fatal_signal_pending(current) ? -EINTR : 0;
 }
 
 ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t 
*ppos)
@@ -242,7 +243,9 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, 
size_t len, loff_t *pp
ret = filp->f_op->aio_read(, , 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb();
+   ret = wait_on_retry_sync_kiocb();
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -300,7 +303,9 @@ ssize_t do_sync_write(struct file *filp, const char __user 
*buf, size_t len, lof
ret = filp->f_op->aio_write(, , 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb();
+   ret = wait_on_retry_sync_kiocb();
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -466,7 +471,9 @@ ssize_t do_sync_readv_writev(struct file *filp, const 
struct iovec *iov,
ret = fn(, iov, nr_segs, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb();
+   ret = wait_on_retry_sync_kiocb();
+   if (ret)
+   break;
}
 
if (ret == -EIOCBQUEUED)
-- 
1.4.4.2

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 5/5] Make wait_on_retry_sync_kiocb killable

2007-09-01 Thread Matthew Wilcox
Use TASK_KILLABLE to allow wait_on_retry_sync_kiocb to return -EINTR.
All callers then check the return value and break out of their loops.

Signed-off-by: Matthew Wilcox [EMAIL PROTECTED]
---
 fs/read_write.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 507ddff..b1a52d5 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -218,14 +218,15 @@ Einval:
return -EINVAL;
 }
 
-static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
+static int wait_on_retry_sync_kiocb(struct kiocb *iocb)
 {
-   set_current_state(TASK_UNINTERRUPTIBLE);
+   set_current_state(TASK_KILLABLE);
if (!kiocbIsKicked(iocb))
schedule();
else
kiocbClearKicked(iocb);
__set_current_state(TASK_RUNNING);
+   return fatal_signal_pending(current) ? -EINTR : 0;
 }
 
 ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t 
*ppos)
@@ -242,7 +243,9 @@ ssize_t do_sync_read(struct file *filp, char __user *buf, 
size_t len, loff_t *pp
ret = filp-f_op-aio_read(kiocb, iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb(kiocb);
+   ret = wait_on_retry_sync_kiocb(kiocb);
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -300,7 +303,9 @@ ssize_t do_sync_write(struct file *filp, const char __user 
*buf, size_t len, lof
ret = filp-f_op-aio_write(kiocb, iov, 1, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb(kiocb);
+   ret = wait_on_retry_sync_kiocb(kiocb);
+   if (ret)
+   break;
}
 
if (-EIOCBQUEUED == ret)
@@ -466,7 +471,9 @@ ssize_t do_sync_readv_writev(struct file *filp, const 
struct iovec *iov,
ret = fn(kiocb, iov, nr_segs, kiocb.ki_pos);
if (ret != -EIOCBRETRY)
break;
-   wait_on_retry_sync_kiocb(kiocb);
+   ret = wait_on_retry_sync_kiocb(kiocb);
+   if (ret)
+   break;
}
 
if (ret == -EIOCBQUEUED)
-- 
1.4.4.2

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/