Skip to contentSkip to conversation

no-fork option for tapdisk2 debugging

PATCH In review Philipp Hahn 2 participants 6 messages Jun 21, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 no-fork option for tapdisk2 debugging

Hello,

For debugging tapdisk2 it would be nice if forking into the background could be disabled by passing some command line argument. The attached patch adds such an option (-n).
The second patch re-indents four un-changed lines.
It would be nice if this could be included into the source core repository.

Sincerely
Philipp Hahn

Signature · 4 lines
Philipp Hahn           Open Source Software Engineer      [email protected]
Univention GmbH        Linux for Your Business        fon: +49 421 22 232- 0
Mary-Somerville-Str.1  D-28359 Bremen                 fax: +49 421 22 232-99
                                                   http://www.univention.de/

Add option to disable forking

To simplify running tapdisk2 from a debugger, add an opttion "-n" to disable foring into the background.

tools/blktap2/drivers/tapdisk2.c +12 -3
@@ -402,7 +402,7 @@ tapdisk2_wait_for_device(void)
 static void
 usage(const char *app, int err)
 {
-	fprintf(stderr, "usage: %s <-n file>\n", app);
+	fprintf(stderr, "usage: %s [-f] -n driver:file\n", app);
 	exit(err);
 }
 
@@ -411,10 +411,11 @@ main(int argc, char *argv[])
 {
 	int c;
 	char *params;
+	int do_fork = 1;
 
 	params = NULL;
 
-	while ((c = getopt(argc, argv, "n:s:h")) != -1) {
+	while ((c = getopt(argc, argv, "n:s:fh")) != -1) {
 		switch (c) {
 		case 'n':
 			params = optarg;
@@ -430,6 +431,9 @@ main(int argc, char *argv[])
 			exit(EXIT_FAILURE);
 #endif
 			break;
+		case 'f':
+			do_fork = 0;
+			break;
 		default:
 			usage(argv[0], EINVAL);
 		}
@@ -438,12 +442,17 @@ main(int argc, char *argv[])
 	if (!params || optind != argc)
 		usage(argv[0], EINVAL);
 
+	if (do_fork) {
 	if (pipe(channel) == -1) {
 		printf("pipe failed: %d\n", errno);
 		return errno;
 	}
+	} else {
+		channel[0] = dup(STDIN_FILENO);
+		channel[1] = dup(STDERR_FILENO);
+	}
 
-	switch (fork()) {
+	switch (do_fork ? fork() : 0) {
 	case -1:
 		printf("fork failed: %d\n", errno);
 		return errno;

Re-indent lines.

Re-indent lines after applying patch to add no-fork option.

tools/blktap2/drivers/tapdisk2.c +4 -4
@@ -443,10 +443,10 @@ main(int argc, char *argv[])
 		usage(argv[0], EINVAL);
 
 	if (do_fork) {
-	if (pipe(channel) == -1) {
-		printf("pipe failed: %d\n", errno);
-		return errno;
-	}
+		if (pipe(channel) == -1) {
+			printf("pipe failed: %d\n", errno);
+			return errno;
+		}
 	} else {
 		channel[0] = dup(STDIN_FILENO);
 		channel[1] = dup(STDERR_FILENO);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Philipp Hahn writes ("[Xen-devel] [PATCH] no-fork option for tapdisk2 debugging"):

Quoted 3 lines

For debugging tapdisk2 it would be nice if forking into the background could be disabled by passing some command line argument. The attached patch adds such an option (-n).

This seems reasonable.

Quoted 1 line

The second patch re-indents four un-changed lines.

That should be folded into the first patch, which otherwise leaves the indentation wrong.

Quoted 1 line

It would be nice if this could be included into the source core repository.

Also, you to add a Signed-off-by line to your patch to signify its copyright status (see below).

Thanks,
Ian.

Quoted 1 line

From Documentation/SubmittingPatches in the Linux kernel tree:

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or

(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.

#2 lore raw

Hello Ian,

Am Dienstag 21 Juni 2011 16:29:20 schrieb Ian Jackson:

Quoted 2 lines

That should be folded into the first patch, which otherwise leaves the indentation wrong.

Done. I submitted it as an extra patch only for simplifying review of the additional implementation.

Quoted 2 lines

Also, you to add a Signed-off-by line to your patch to signify its copyright status (see below).

The original patch already contained the Signed-off-line, since I knew you (or somebody else) would be asking for it ;-) If more is needed, please ask again.

Sincerely
Philipp Hahn

Signature · 4 lines
Philipp Hahn           Open Source Software Engineer      [email protected]
Univention GmbH        Linux for Your Business        fon: +49 421 22 232- 0
Mary-Somerville-Str.1  D-28359 Bremen                 fax: +49 421 22 232-99
                                                   http://www.univention.de/

no-fork option for tapdisk2 debugging.

To simplify running tapdisk2 from a debugger, add an opttion "-n" to disable foring into the background.

--
[v2] fold extra indention patch into patch.

tools/blktap2/drivers/tapdisk2.c +16 -7
@@ -402,7 +402,7 @@ tapdisk2_wait_for_device(void)
 static void
 usage(const char *app, int err)
 {
-	fprintf(stderr, "usage: %s <-n file>\n", app);
+	fprintf(stderr, "usage: %s [-f] -n driver:file\n", app);
 	exit(err);
 }
 
@@ -411,10 +411,11 @@ main(int argc, char *argv[])
 {
 	int c;
 	char *params;
+	int do_fork = 1;
 
 	params = NULL;
 
-	while ((c = getopt(argc, argv, "n:s:h")) != -1) {
+	while ((c = getopt(argc, argv, "n:s:fh")) != -1) {
 		switch (c) {
 		case 'n':
 			params = optarg;
@@ -430,6 +431,9 @@ main(int argc, char *argv[])
 			exit(EXIT_FAILURE);
 #endif
 			break;
+		case 'f':
+			do_fork = 0;
+			break;
 		default:
 			usage(argv[0], EINVAL);
 		}
@@ -438,12 +442,17 @@ main(int argc, char *argv[])
 	if (!params || optind != argc)
 		usage(argv[0], EINVAL);
 
-	if (pipe(channel) == -1) {
-		printf("pipe failed: %d\n", errno);
-		return errno;
-	}
+	if (do_fork) {
+		if (pipe(channel) == -1) {
+			printf("pipe failed: %d\n", errno);
+			return errno;
+		}
+	} else {
+		channel[0] = dup(STDIN_FILENO);
+		channel[1] = dup(STDERR_FILENO);
+	}
 
-	switch (fork()) {
+	switch (do_fork ? fork() : 0) {
 	case -1:
 		printf("fork failed: %d\n", errno);
 		return errno;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw

Philipp Hahn writes ("Re: [Xen-devel] [PATCH v2] no-fork option for tapdisk2 debugging"):

Quoted 6 lines

Am Dienstag 21 Juni 2011 16:29:20 schrieb Ian Jackson:

Quoted 2 lines

That should be folded into the first patch, which otherwise leaves the indentation wrong.

Done. I submitted it as an extra patch only for simplifying review of the additional implementation.

Thanks, but we have tools which can suppress whitespace changes when showing us diffs :-).

Quoted 6 lines
Quoted 2 lines

Also, you to add a Signed-off-by line to your patch to signify its copyright status (see below).

The original patch already contained the Signed-off-line, since I knew you (or somebody else) would be asking for it ;-) If more is needed, please ask again.

Sorry, I must have missed that.

But I'm afraid your patch doesn't apply cleanly to xen-unstable tip:

patching file tools/blktap2/drivers/tapdisk2.c
Hunk #1 FAILED at 402.
Hunk #2 FAILED at 411.
Hunk #3 succeeded at 72 (offset -359 lines).
Hunk #4 FAILED at 83.
3 out of 4 hunks FAILED -- saving rejects to file tools/blktap2/drivers/tapdisk2.c.rej

Ian.

#4 lore raw

Hello Ian,

Quoted 1 line · On Tuesday 21 June 2011 17:14:28 Ian Jackson wrote:

But I'm afraid your patch doesn't apply cleanly to xen-unstable tip:

Seems like someone other also missed that option and added it already. So me patch is mostly obsolete, but perhaps a little bit of documentation would be okay.

Sincerely
Philipp Hahn

Signature · 4 lines
Philipp Hahn           Open Source Software Engineer      [email protected]
Univention GmbH        Linux for Your Business        fon: +49 421 22 232- 0
Mary-Somerville-Str.1  D-28359 Bremen                 fax: +49 421 22 232-99
                                                   http://www.univention.de/

Document -D option for no-daemonize.

tools/blktap2/drivers/tapdisk2.c Tue Jun 21 17:35:58 2011 +0200 renamed from tools/blktap2/drivers/tapdisk2.c Fri Jun 17 08:08:13 2011 +0100 +1 -1
diff -r eca057e4475c tools/blktap2/drivers/tapdisk2.c
@@ -42,7 +42,7 @@
 static void
 usage(const char *app, int err)
 {
-       fprintf(stderr, "usage: %s <-u uuid> <-c control socket>\n", app);
+       fprintf(stderr, "usage: %s [-D] <-u uuid> <-c control socket>\n", app);
        exit(err);
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw

Philipp Hahn writes ("Re: [Xen-devel] [PATCH v2] no-fork option for tapdisk2 debugging"):

Quoted 6 lines · On Tuesday 21 June 2011 17:14:28 Ian Jackson wrote:
Quoted 1 line

But I'm afraid your patch doesn't apply cleanly to xen-unstable tip:

Seems like someone other also missed that option and added it already. So me patch is mostly obsolete, but perhaps a little bit of documentation would be okay.

Right, thanks, I have applied your patch. (I had to do this by hand because something in the Citrix email system mangled your tabs. Not your fault.)

Ian.