[5088] in Athena Bugs

home help back first fref pref prev next nref lref last post

RT savecore

daemon@ATHENA.MIT.EDU (John Carr)
Wed Jun 6 05:37:13 1990

To: bugs@ATHENA.MIT.EDU
Date: Wed, 06 Jun 90 05:36:57 EDT
From: John Carr <jfc@ATHENA.MIT.EDU>


This patch makes three fixes to the RT savecore.  The first is to use
statfs() to find the free space on the dump partition instead of
searching for a device in /dev/ from which a UFS superblock can be
read to find the free space.  This allows dumping to NFS or AFS, and
should be portable to the VAX savecore.  The second is a check of the
return value of close(); this may be important when dumping to a
remote file system.  The third is an optimization of the function
which checks to see if it is about to write a block which is 0. The C
code is designed to to make hc generate the best machine code for
a block compare against zero.


*** /source/bsd-4.3/rt/etc/savecore.c	Sat Oct 21 15:00:43 1989
--- savecore.c	Wed Jun  6 05:30:46 1990
***************
*** 35,47 ****
  #include <sys/param.h>
  #include <sys/dir.h>
  #include <sys/stat.h>
- #ifdef VFS
- #include <ufs/fs.h>
- #else
- #include <sys/fs.h>
- #endif VFS
  #include <sys/time.h>
  #include <sys/file.h>
  #include <sys/syslog.h>
  
  #define	DAY	(60L*60L*24L)
--- 19,27 ----
  #include <sys/param.h>
  #include <sys/dir.h>
  #include <sys/stat.h>
  #include <sys/time.h>
  #include <sys/file.h>
+ #include <sys/vfs.h>
  #include <sys/syslog.h>
  
  #define	DAY	(60L*60L*24L)
***************
*** 236,242 ****
      { X_TIME, X_DUMPSIZE, X_VERSION, X_PANICSTR, X_DUMPMAG, -1 };
  read_kmem()
  {
- 	register char *cp;
  	FILE *fp;
  	char *dump_sys;
  	int kmem, i;
--- 216,221 ----
***************
*** 364,374 ****
  check_space()
  {
  	struct stat dsb;
! 	register char *ddev;
! 	int dfd, spacefree;
! 	struct fs fs;
  
! 	if (stat(dirname, &dsb) < 0) {
  		int oerrno = errno;
  
  		perror(dirname);
--- 343,351 ----
  check_space()
  {
  	struct stat dsb;
! 	struct statfs fs;
  
! 	if (statfs(dirname, &dsb) < 0) {
  		int oerrno = errno;
  
  		perror(dirname);
***************
*** 376,393 ****
  		syslog(LOG_ERR, "%s: %m", dirname);
  		exit(1);
  	}
! 	ddev = find_dev(dsb.st_dev, S_IFBLK);
! 	dfd = Open(ddev, O_RDONLY);
! 	Lseek(dfd, (long)(SBLOCK * DEV_BSIZE), L_SET);
! 	Read(dfd, (char *)&fs, sizeof (fs));
! 	close(dfd);
!  	spacefree = freespace(&fs, fs.fs_minfree) * fs.fs_fsize / 1024;
!  	if (spacefree < read_number("minfree")) {
  		printf("Dump omitted, not enough space on device");
  		syslog(LOG_WARNING, "Dump omitted, not enough space on device");
  		return (0);
  	}
! 	if (freespace(&fs, fs.fs_minfree) < 0) {
  		printf("Dump performed, but free space threshold crossed");
  		syslog(LOG_WARNING,
  		    "Dump performed, but free space threshold crossed");
--- 353,364 ----
  		syslog(LOG_ERR, "%s: %m", dirname);
  		exit(1);
  	}
!  	if (fs.f_bavail < read_number("minfree")) {
  		printf("Dump omitted, not enough space on device");
  		syslog(LOG_WARNING, "Dump omitted, not enough space on device");
  		return (0);
  	}
! 	if (fs.f_bavail < 0) {
  		printf("Dump performed, but free space threshold crossed");
  		syslog(LOG_WARNING,
  		    "Dump performed, but free space threshold crossed");
***************
*** 465,472 ****
  		Write(ofd, cp, n);
  		dumpsize -= n/NBPG;
  	}
! 	close(ifd);
! 	close(ofd);
  	fp = fopen(path("bounds"), "w");
  	fprintf(fp, "%d\n", bounds+1);
  	fclose(fp);
--- 436,449 ----
  		Write(ofd, cp, n);
  		dumpsize -= n/NBPG;
  	}
! 	if(close(ifd) < 0 || close(ofd) < 0)
! 	  {
! 	    int oerrno = errno;
! 	    perror("close");
! 	    errno = oerrno;
! 	    syslog(LOG_ERR, "close: %m");
! 	    exit(1);
! 	  }
  	fp = fopen(path("bounds"), "w");
  	fprintf(fp, "%d\n", bounds+1);
  	fclose(fp);
***************
*** 564,572 ****
--- 541,551 ----
  	}
  }
  
+ #ifdef ibm032
  /*
   * test to see if a buffer is all zero and return 
   * flag for result
+  * strange looking code is to optimize for hc 2.1y + APC
   */
  iszero(buffer, count) 
  	register char *buffer;
***************
*** 573,584 ****
  	register int count;
  {
  	register int *ptr = (int *) buffer,
! 		*end = (int *) (buffer+count);
  	while (ptr < end)
  		{
! 		if (*ptr)
  			return(0);
- 		++ptr;
  		}
  	return(1);
  }
--- 552,567 ----
  	register int count;
  {
  	register int *ptr = (int *) buffer,
! 		*end = (int *) (buffer+count-1);
  	while (ptr < end)
  		{
! 		register int x = *ptr++;
! 		register int y = *ptr++;
! 		if (x || y)
  			return(0);
  		}
+ 	if(ptr == end && !*++ptr)
+ 		return 0;		
  	return(1);
  }
+ #endif

home help back first fref pref prev next nref lref last post