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

Re: losetup on boot-floppies



On Tue, 2002-03-12 at 14:35, Eduard Bloch wrote:
> In last days, I tried to find the reason for the ugly behaviour of the
> loop driver, see #135504. I tried to reuser the code from losetup.c,
> nothing did work. A loop device created by losetup can be attached and
> detached as usual, but if done from debootstrap, it works once, leaves a
> [loop0] zombie and on the next set_loop, the device is busy but not
> showed as active (or sometimes showed though) and cannot be removed.
> 
> My solution: we put losetup on the BFs and use system calls for setting
> loop devices. Any other ideas?

Hmm, that's very weird.

I suppose it might possibly be worth trying something like this, just to
see if it makes any difference.  Or maybe leave the other waitpid() in
too, and try adding a sleep between the sync() calls.  I dunno.

p.

Index: losetup.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/losetup.c,v
retrieving revision 1.8
diff -u -r1.8 losetup.c
--- losetup.c	2002/03/05 19:18:01	1.8
+++ losetup.c	2002/03/12 15:05:59
@@ -30,7 +30,7 @@
 
 /* Loop device setup stuff, swiped from busybox. */
 
-int del_loop(const char *device)
+int del_loop2(const char *device)
 {
     int fd;
     DEBUGMSG("Called del_loop for %s", device);
@@ -40,14 +40,13 @@
 	ERRMSG("del_loop failed opening device %s", device);
 	return( FALSE);
     }
-    /* reap any zombies that were created */
-    waitpid(-1, NULL, WNOHANG);
     if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
        /* sometimes, the kernel turns crazy. Sync some times and hope that filehandles will be released */
        sync();
        sync();
        if (ioctl(fd, LOOP_CLR_FD, 0) < 0) {
-	ERRMSG("del_loop ioctl got negative result doing LOOP_CLR_FD on device %s; this is probably not a big deal", device);
+	ERRMSG("del_loop ioctl got negative result (errno=%d) doing LOOP_CLR_FD on device %s; this is probably not a big deal", errno, device);
+	close(fd);
 	return( FALSE);
        }
     }
@@ -55,7 +54,7 @@
     return( TRUE);
 }
 
-int set_loop(const char *device, const char *file, int offset, int *loopro)
+int set_loop2(const char *device, const char *file, int offset, int *loopro)
 {
 	struct loop_info loopinfo;
 	int	fd, ffd, mode;
@@ -98,6 +97,32 @@
 	close(fd);
 	close(ffd);
 	return 0;
+}
+
+int set_loop(const char *device, const char *file, int offset, int *loopro)
+{
+  int pid = fork();
+  if (pid)
+  {
+    return waitpid(pid, NULL, 0);
+  }
+  else
+  {
+    exit(set_loop2(device));
+  }
+}
+
+int del_loop(const char *device)
+{
+  int pid = fork();
+  if (pid)
+  {
+    return waitpid(pid, NULL, 0);
+  }
+  else
+  {
+    exit(del_loop2(device));
+  }
 }
 
 char *find_unused_loop_device (void)



Reply to: