Re: init scripts problems ?

"Peter T. Breuer" <[email protected]> Mon, 5 Dec 2005 16:42:18 +0100 (MET)
Newsgroups gmane.linux.enbd.general
Message-ID <[email protected]>
"Also sprach ptb:"
> I'll provide that openers patch in a moment.


Here it is (seriously untested).  It's an alternative to the other
patch I gave you, but both together should have no problems.

What it does is up the device openers count by one extra the first time
a daemon is attached to the device.  This means that no matter how many
daemons die thereafter, the openers count is alays positive.

This stops the kernel from doing its dastardly acts whenever it thinks
somebody has closed the device for the last time (such as flushing to
the device, which is kinda difficult now there is no daemon ...),
because there will be no "last opener" as far as the kernel knows.

The second hunk goes the extra mile and decrements the extra count when
the reset() function is run, which is probably at a cold day in hell,
or when the module is removed (whichever comes sooner). I didn't check
- it's the only other place the nslot count is changed. I don't know
offhand what user actions evoke it ... as far as I can see, one has to
echo "reset=1" to nbdinfo and that's it.


--- enbd_base.c.oboe	Sun Dec  4 21:27:35 2005
+++ enbd_base.c	Mon Dec  5 15:58:55 2005
@@ -2794,7 +2799,18 @@
 
 	if (islot >= lo->nslot) {
 		lo->nslot = islot + 1;
-		ENBD_INFO ("increased socket count to %d\n", lo->nslot);
+		ENBD_INFO ("increased socket count on nd%s to %d\n",
+                        lo->devnam, lo->nslot);
+                if (lo->nslot == 1) {
+                        if (lo->inode && lo->inode->i_bdev) {
+		                ENBD_INFO ("upping openers count on nd%s\n",
+                                        lo->devnam);
+                                lo->inode->i_bdev->bd_openers++;
+                        } else {
+	                        ENBD_ALERT ("missing inode(%p) or bd on nd%s\n",
+                                   lo->inode, lo->devnam);
+                        }
+                }
 	}
 
 	lo->harderror = 0;
@@ -4981,13 +5032,20 @@
         }
         atomic_clear_mask(ENBD_ENABLED, &lo->flags);
         atomic_clear_mask(ENBD_VALIDATED, &lo->flags);
+        ENBD_INFO("set INVALID on nd%s\n", lo->devnam);
         // PTB clear SIGNED suggested by Dag Sverre Seljebotn */
         atomic_clear_mask(ENBD_SIGNED, &lo->flags);
         lo->nslot = 0;
+        if (lo->inode && lo->inode->i_bdev) {
+	        ENBD_INFO ("downing openers count on nd%s\n", lo->devnam);
+                                lo->inode->i_bdev->bd_openers--;
+        } else {
+	        ENBD_ALERT ("missing inode (%p) or bdev on nd%s\n",
+                        lo->inode, lo->devnam);
+        }
         write_unlock(&lo->meta_lock);
-        ENBD_ALERT("set INVALID on nd%s\n", lo->devnam);
         //__invalidate_device(lo->inode->i_bdev, 0);
-        ENBD_ALERT ("reset device nd%s\n", lo->devnam);
+        ENBD_INFO ("reset device nd%s\n", lo->devnam);
 }
 
 static int


Peter