[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Nbd] nbd-client hangs



On 5/30/06, Wouter Verhelst <wouter@...3...> wrote:
On Tue, May 30, 2006 at 05:45:11PM -0400, Mike Snitzer wrote:
> One way to reproduce this negotiation hang is to have the nbd-server
> export a loop device that hasn't been setup.  Surprisingly the
> nbd-server daemonize()s and responds with:

That's because the file name may change based on the client's IP
address. Search for "%s" in the manpage.

Yes, I fully intend to implement this in a saner way in 2.9. However,
your patch breaks such exports, so I can unfortunately not accept it.

I modified my patch to check if the specified export file contains
"%s" and if so the preemptive export verification is skipped.  Is the
attached patch acceptable?  Feel free to season to taste (especially
given that 2.9 is to be saner).

thanks,
Mike
diff -Naur nbd-2.8.4.orig/nbd-server.c nbd-2.8.4/nbd-server.c
--- nbd-2.8.4.orig/nbd-server.c	2006-02-28 05:07:56.000000000 -0500
+++ nbd-2.8.4/nbd-server.c	2006-05-30 22:10:57.000000000 -0400
@@ -899,12 +899,33 @@
 	struct sockaddr_in addrin;
 	struct sigaction sa;
 	int addrinlen = sizeof(addrin);
+	int fhandle;
 #ifndef sun
 	int yes=1;
 #else
 	char yes='1';
 #endif /* sun */
 
+	if (strstr(serve->exportname, "%s") == NULL) {
+		/**
+		 * verify the existence of the block device that
+		 * this server instance will export
+		 **/
+		DEBUG2( "Opening %s\n", serve->exportname );
+		if ((fhandle = open(serve->exportname,
+				    (serve->flags & F_READONLY) ? O_RDONLY : O_RDWR)) == -1) {
+			err("Could not open exported file: %m");
+		}
+		/**
+		 * if the exported file's size can't be detected	   
+		 * size_autodetect() will exit()... and export can be
+		 * considered invalid
+		 **/
+		size_autodetect(fhandle);
+		close(fhandle);
+	}	
+	daemonize(serve);
+	
 	if ((serve->socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
 		err("socket: %m");
 
@@ -1026,8 +1047,7 @@
           	set_peername(0,client);
           	serveconnection(client);
           	return 0;
-        }
-	daemonize(serve);
+        }	
 	setup_serve(serve);
 	serveloop(serve);
 	return 0 ;

Reply to: