Simplify cnfs.c

Alex Kiernan alexk at demon.net
Fri Jan 19 17:58:27 UTC 2001


I've spent the last three days chasing what's we think's turned out to
be a Solaris 8 kernel bug, but along the way I simplified cnfs to use
less mixed write/mmap (the problem at one point we thought was a page
aliasing problem).

This patch removes the dual mmap/write stuff for the header/bitmap &
just uses mmap. AFAICT this shouldn't cause regression on other
platforms as you need mmap to work to get cnfs anyway.

Ultimately the patch adds no real value though...

Index: cnfs.c
===================================================================
RCS file: /upstream-repositories/inn-cvs.isc.org/inn/storage/cnfs/cnfs.c,v
retrieving revision 1.80
diff -u -r1.80 cnfs.c
--- cnfs.c	2001/01/04 06:01:34	1.80
+++ cnfs.c	2001/01/19 09:14:56
@@ -233,13 +233,12 @@
 
   if (!cycbuff->needflush)
     return TRUE;
-  memset(&rpx, 0, sizeof(CYCBUFFEXTERN));
-  if (cycbuff->bitfield == NULL) {
-    if (CNFSseek(cycbuff->fd, (CYCBUFF_OFF_T) 0, SEEK_SET) < 0) {
-      syslog(L_ERROR, "CNFSflushhead: magic CNFSseek failed: %m");
-      return FALSE;
-    }
+  if (!SMopenmode) {
+    syslog(L_ERROR, "%s: CNFSflushhead: attempted flush whilst read only",
+      LocalLogName);
+    return FALSE;
   }
+  memset(&rpx, 0, sizeof(CYCBUFFEXTERN));
   if (cycbuff->magicver == 3) {
     cycbuff->updated = time(NULL);
     strncpy(rpx.magic, CNFS_MAGICV3, strlen(CNFS_MAGICV3));
@@ -257,21 +256,14 @@
     } else {
 	strncpy(rpx.currentbuff, "FALSE", CNFSMASIZ);
     }
-    if (cycbuff->bitfield == NULL) {
-      if ((b = write(cycbuff->fd, &rpx, sizeof(CYCBUFFEXTERN))) != sizeof(CYCBUFFEXTERN)) {
-	syslog(L_ERROR, "%s: CNFSflushhead: write failed (%d bytes): %m", LocalLogName, b);
-	return FALSE;
-      }
-    } else {
-      memcpy(cycbuff->bitfield, &rpx, sizeof(CYCBUFFEXTERN));
+    memcpy(cycbuff->bitfield, &rpx, sizeof(CYCBUFFEXTERN));
 #ifdef MMAP_NEEDS_MSYNC
 # ifdef HAVE_MSYNC_3_ARG
-      msync(cycbuff->bitfield, cycbuff->minartoffset, MS_ASYNC);
+    msync(cycbuff->bitfield, cycbuff->minartoffset, MS_ASYNC);
 # else
-      msync(cycbuff->bitfield, cycbuff->minartoffset);
+    msync(cycbuff->bitfield, cycbuff->minartoffset);
 # endif
 #endif
-    }
     cycbuff->needflush = FALSE;
   } else {
     syslog(L_ERROR, "%s: CNFSflushhead: bogus magicver for %s: %d",
@@ -300,20 +292,7 @@
     CYCBUFFEXTERN	rpx;
     char		buf[64];
 
-    if (cycbuff->bitfield == NULL) {
-	if (CNFSseek(cycbuff->fd, (CYCBUFF_OFF_T) 0, SEEK_SET) < 0) {
-	    syslog(L_ERROR, "CNFSReadFreeAndCycle: magic lseek failed: %m");
-	    SMseterror(SMERR_UNDEFINED, NULL);
-	    return;
-	}
-	if (read(cycbuff->fd, &rpx, sizeof(CYCBUFFEXTERN)) != sizeof(rpx)) {
-	    syslog(L_ERROR, "CNFSReadFreeAndCycle: magic read failed: %m");
-	    SMseterror(SMERR_UNDEFINED, NULL);
-	    return;
-	}
-    } else {
-	memcpy(&rpx, cycbuff->bitfield, sizeof(CYCBUFFEXTERN));
-    }
+    memcpy(&rpx, cycbuff->bitfield, sizeof(CYCBUFFEXTERN));
     /* Sanity checks are not needed since CNFSinit_disks() has already done. */
     buf[CNFSLASIZ] = '\0';
     strncpy(buf, rpx.freea, CNFSLASIZ);
@@ -531,7 +510,7 @@
 
 static bool CNFSinit_disks(CYCBUFF *cycbuff) {
   char		buf[64];
-  CYCBUFFEXTERN	rpx;
+  CYCBUFFEXTERN	*rpx;
   int		fd, bytes;
   CYCBUFF_OFF_T	tmpo;
   bool		oneshot;
@@ -562,18 +541,15 @@
 	    close_on_exec(fd, true);
 	    cycbuff->fd = fd;
 	}
-    }
-    if ((tmpo = CNFSseek(cycbuff->fd, (CYCBUFF_OFF_T) 0, SEEK_SET)) < 0) {
-	syslog(L_ERROR, "%s: pre-magic read lseek failed: %m", LocalLogName);
-	return FALSE;
-    }
-    if ((bytes = read(cycbuff->fd, &rpx, sizeof(CYCBUFFEXTERN))) != sizeof(rpx)) {
-	syslog(L_ERROR, "%s: read magic failed %d bytes: %m", LocalLogName, bytes);
-	return FALSE;
     }
-    if (CNFSseek(cycbuff->fd, tmpo, SEEK_SET) != tmpo) {
-	syslog(L_ERROR, "%s: post-magic read lseek to 0x%s failed: %m",
-	       LocalLogName, CNFSofft2hex(tmpo, FALSE));
+    errno = 0;
+    cycbuff->bitfield = mmap((caddr_t) 0, cycbuff->minartoffset,
+			     SMopenmode ? (PROT_READ | PROT_WRITE) : PROT_READ,
+			     MAP_SHARED, fd, (off_t) 0);
+    if (cycbuff->bitfield == MAP_FAILED || errno != 0) {
+	syslog(L_ERROR,
+	       "%s: CNFSinitdisks: mmap for %s offset %d len %d failed: %m",
+	       LocalLogName, cycbuff->path, 0, cycbuff->minartoffset);
 	return FALSE;
     }
 
@@ -581,19 +557,19 @@
     ** Much of this checking from previous revisions is (probably) bogus
     ** & buggy & particularly icky & unupdated.  Use at your own risk.  :-)
     */
-
-    if (strncmp(rpx.magic, CNFS_MAGICV3, strlen(CNFS_MAGICV3)) == 0) {
+    rpx = (CYCBUFFEXTERN *)cycbuff->bitfield;
+    if (strncmp(rpx->magic, CNFS_MAGICV3, strlen(CNFS_MAGICV3)) == 0) {
 	cycbuff->magicver = 3;
-	if (strncmp(rpx.name, cycbuff->name, CNFSNASIZ) != 0) {
+	if (strncmp(rpx->name, cycbuff->name, CNFSNASIZ) != 0) {
 	    syslog(L_ERROR, "%s: Mismatch 3: read %s for cycbuff %s", LocalLogName,
-		   rpx.name, cycbuff->name);
+		   rpx->name, cycbuff->name);
 	    return FALSE;
 	}
-	if (strncmp(rpx.path, cycbuff->path, CNFSPASIZ) != 0) {
+	if (strncmp(rpx->path, cycbuff->path, CNFSPASIZ) != 0) {
 	    syslog(L_ERROR, "%s: Path mismatch: read %s for cycbuff %s",
-		   LocalLogName, rpx.path, cycbuff->path);
+		   LocalLogName, rpx->path, cycbuff->path);
 	} 
-	strncpy(buf, rpx.lena, CNFSLASIZ);
+	strncpy(buf, rpx->lena, CNFSLASIZ);
 	buf[CNFSLASIZ] = '\0';
 	tmpo = CNFShex2offt(buf);
 	if (tmpo != cycbuff->len) {
@@ -602,18 +578,18 @@
 	    return FALSE;
 	}
 	buf[CNFSLASIZ] = '\0';
-	strncpy(buf, rpx.freea, CNFSLASIZ);
+	strncpy(buf, rpx->freea, CNFSLASIZ);
 	cycbuff->free = CNFShex2offt(buf);
 	buf[CNFSLASIZ] = '\0';
-	strncpy(buf, rpx.updateda, CNFSLASIZ);
+	strncpy(buf, rpx->updateda, CNFSLASIZ);
 	cycbuff->updated = CNFShex2offt(buf);
 	buf[CNFSLASIZ] = '\0';
-	strncpy(buf, rpx.cyclenuma, CNFSLASIZ);
+	strncpy(buf, rpx->cyclenuma, CNFSLASIZ);
 	cycbuff->cyclenum = CNFShex2offt(buf);
-	strncpy(cycbuff->metaname, rpx.metaname, CNFSLASIZ);
-	strncpy(buf, rpx.orderinmeta, CNFSLASIZ);
+	strncpy(cycbuff->metaname, rpx->metaname, CNFSLASIZ);
+	strncpy(buf, rpx->orderinmeta, CNFSLASIZ);
 	cycbuff->order = CNFShex2offt(buf);
-	if (strncmp(rpx.currentbuff, "TRUE", CNFSMASIZ) == 0) {
+	if (strncmp(rpx->currentbuff, "TRUE", CNFSMASIZ) == 0) {
 	    cycbuff->currentbuff = TRUE;
 	} else
 	    cycbuff->currentbuff = FALSE;
@@ -630,16 +606,6 @@
 	cycbuff->needflush = TRUE;
 	if (!CNFSflushhead(cycbuff))
 	    return FALSE;
-    }
-    errno = 0;
-    fd = cycbuff->fd;
-    if ((cycbuff->bitfield =
-	 mmap((caddr_t) 0, cycbuff->minartoffset, SMopenmode ? (PROT_READ | PROT_WRITE) : PROT_READ,
-	      MAP_SHARED, fd, (off_t) 0)) == MAP_FAILED || errno != 0) {
-	syslog(L_ERROR,
-	       "%s: CNFSinitdisks: mmap for %s offset %d len %d failed: %m",
-	       LocalLogName, cycbuff->path, 0, cycbuff->minartoffset);
-	return FALSE;
     }
     if (oneshot)
       break;


-- 
Alex Kiernan, Principal Engineer, Development, Thus PLC



More information about the inn-workers mailing list