public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] xfsprogs: xfs_copy: use exit() to replace killall()
@ 2014-05-06  6:54 Junxiao Bi
  2014-05-06  7:57 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Junxiao Bi @ 2014-05-06  6:54 UTC (permalink / raw)
  To: xfs; +Cc: hch, joe.jin, junxiao.bi

Sending a SIGKILL signal to child thread will terminate the whole process,
xfs_copy will return an error value 137. This cause confuse for script to
know whether the copy successes.

Calling exit() in main thread can terminate the whole process and return the
right value. Replace killall()+abort() with exit(1) to match the old way
exit in error case. Also remove killall()+pthread_exit(NULL) since return 0
will be followed by an exit(0) to terminate the process.

Bug story from Chrisoph Hellwig:
Btw, I think the reason for this cruft is that xfs_copy was originally
written using the IRIX sproc interface, and the port to pthreads didn't
remove this gem:

http://marc.info/?l=linux-xfs&m=99535721110020&w=2

Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Joe jin <joe.jin@oracle.com>
Cc: Chrisoph Hellwig <hch@infradead.org>
---
 copy/xfs_copy.c |   30 +-----------------------------
 1 files changed, 1 insertions(+), 29 deletions(-)

diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index 39517da..39bb9d7 100644
--- a/copy/xfs_copy.c
+++ b/copy/xfs_copy.c
@@ -217,25 +217,6 @@ handle_error:
 }
 
 void
-killall(void)
-{
-	int i;
-
-	/* only the parent gets to kill things */
-
-	if (getpid() != parent_pid)
-		return;
-
-	for (i = 0; i < num_targets; i++)  {
-		if (target[i].state == ACTIVE)  {
-			/* kill up target threads */
-			pthread_kill(target[i].pid, SIGKILL);
-			pthread_mutex_unlock(&targ[i].wait);
-		}
-	}
-}
-
-void
 handler(int sig)
 {
 	pid_t	pid = getpid();
@@ -400,8 +381,7 @@ read_wbuf(int fd, wbuf *buf, xfs_mount_t *mp)
 	if (buf->length > buf->size)  {
 		do_warn(_("assert error:  buf->length = %d, buf->size = %d\n"),
 			buf->length, buf->size);
-		killall();
-		abort();
+		exit(1);
 	}
 
 	if ((res = read(fd, buf->data, buf->length)) < 0)  {
@@ -591,11 +571,6 @@ main(int argc, char **argv)
 
 	parent_pid = getpid();
 
-	if (atexit(killall))  {
-		do_log(_("%s: couldn't register atexit function.\n"), progname);
-		die_perror();
-	}
-
 	/* open up source -- is it a file? */
 
 	open_flags = O_RDONLY;
@@ -1154,9 +1129,6 @@ main(int argc, char **argv)
 	}
 
 	check_errors();
-	killall();
-	pthread_exit(NULL);
-	/*NOTREACHED*/
 	return 0;
 }
 
-- 
1.7.1

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH V2] xfsprogs: xfs_copy: use exit() to replace killall()
  2014-05-06  6:54 [PATCH V2] xfsprogs: xfs_copy: use exit() to replace killall() Junxiao Bi
@ 2014-05-06  7:57 ` Christoph Hellwig
  2014-05-06  8:00   ` Dave Chinner
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2014-05-06  7:57 UTC (permalink / raw)
  To: Junxiao Bi; +Cc: hch, joe.jin, xfs

On Tue, May 06, 2014 at 02:54:44PM +0800, Junxiao Bi wrote:
> Sending a SIGKILL signal to child thread will terminate the whole process,
> xfs_copy will return an error value 137. This cause confuse for script to
> know whether the copy successes.
> 
> Calling exit() in main thread can terminate the whole process and return the
> right value. Replace killall()+abort() with exit(1) to match the old way
> exit in error case. Also remove killall()+pthread_exit(NULL) since return 0
> will be followed by an exit(0) to terminate the process.
> 
> Bug story from Chrisoph Hellwig:
> Btw, I think the reason for this cruft is that xfs_copy was originally
> written using the IRIX sproc interface, and the port to pthreads didn't
> remove this gem:
> 
> http://marc.info/?l=linux-xfs&m=99535721110020&w=2
> 
> Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
> Cc: Joe jin <joe.jin@oracle.com>
> Cc: Chrisoph Hellwig <hch@infradead.org>

Looks good (except that you misspelled by name :))

Reviewed-by: Christoph Hellwig <hch@lst.de>

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V2] xfsprogs: xfs_copy: use exit() to replace killall()
  2014-05-06  7:57 ` Christoph Hellwig
@ 2014-05-06  8:00   ` Dave Chinner
  0 siblings, 0 replies; 3+ messages in thread
From: Dave Chinner @ 2014-05-06  8:00 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: xfs, joe.jin, Junxiao Bi

On Tue, May 06, 2014 at 12:57:42AM -0700, Christoph Hellwig wrote:
> On Tue, May 06, 2014 at 02:54:44PM +0800, Junxiao Bi wrote:
> > Sending a SIGKILL signal to child thread will terminate the whole process,
> > xfs_copy will return an error value 137. This cause confuse for script to
> > know whether the copy successes.
> > 
> > Calling exit() in main thread can terminate the whole process and return the
> > right value. Replace killall()+abort() with exit(1) to match the old way
> > exit in error case. Also remove killall()+pthread_exit(NULL) since return 0
> > will be followed by an exit(0) to terminate the process.
> > 
> > Bug story from Chrisoph Hellwig:
> > Btw, I think the reason for this cruft is that xfs_copy was originally
> > written using the IRIX sproc interface, and the port to pthreads didn't
> > remove this gem:
> > 
> > http://marc.info/?l=linux-xfs&m=99535721110020&w=2
> > 
> > Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
> > Cc: Joe jin <joe.jin@oracle.com>
> > Cc: Chrisoph Hellwig <hch@infradead.org>
> 
> Looks good (except that you misspelled by name :))
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

I can fix that ;)

I'll queue this up for after the 3.2.0 release.

Cheers,

Dave.

-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-05-06  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-06  6:54 [PATCH V2] xfsprogs: xfs_copy: use exit() to replace killall() Junxiao Bi
2014-05-06  7:57 ` Christoph Hellwig
2014-05-06  8:00   ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox