Home | History | Annotate | Line # | Download | only in ckckp
      1 /*	$NetBSD: ckckp.c,v 1.6 2008/04/28 20:23:06 martin Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Konrad E. Schroder <perseant (at) hhhh.org>.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <err.h>
     33 #include <fcntl.h>
     34 #include <stdio.h>
     35 #include <stdlib.h>
     36 #include <sys/param.h>
     37 #include <sys/mount.h>
     38 #include <ufs/ufs/dinode.h>
     39 #include <ufs/lfs/lfs.h>
     40 
     41 int main(int argc, char **argv)
     42 {
     43 	int fd, e, sno;
     44 	char cmd[BUFSIZ], s[BUFSIZ];
     45 	FILE *pp;
     46 	int dowait = 1;
     47 
     48 	if (argc < 5)
     49 		errx(1, "usage: %s <fs-root> <raw-dev> <save-filename> "
     50 		     "<work-filename>\n", argv[0]);
     51 
     52 	fd = open(argv[1], 0, 0);
     53 	if (fd < 0)
     54 		err(1, argv[1]);
     55 
     56 	/* Give the writer a head start */
     57 	sleep(5);
     58 
     59 	/* Loop forever calling LFCNWRAP{STOP,GO} */
     60 	sno = 0;
     61 	while(1) {
     62 		printf("Waiting until fs wraps\n");
     63 		fcntl(fd, LFCNWRAPSTOP, &dowait);
     64 
     65 		/*
     66 		 * When the fcntl exits, the wrap is about to occur (but
     67 		 * is waiting for the signal to go).  Call our mass-check
     68 		 * script, and if all is well, continue.  The output
     69 		 * of the script should end with a line that begins with a
     70 		 * numeric code: zero for okay, nonzero for a failure.
     71 		 */
     72 		printf("Verifying all checkpoints from s/n %d\n", sno);
     73 		sprintf(cmd, "./check-all %s %s %s %d", argv[2], argv[3],
     74 			argv[4], sno);
     75 		pp = popen(cmd, "r");
     76 		s[0] = '\0';
     77 		while(fgets(s, BUFSIZ, pp) != NULL)
     78 			printf("  %s", s);
     79 		if (s[0] == '\0') {
     80 			printf("No checkpoints found or script exited\n");
     81 			return 0;
     82 		}
     83 		sscanf(s, "%d %d", &e, &sno);
     84 		if (e) {
     85 			printf("Script exited with error code %d\n", e);
     86 			return 1;
     87 		}
     88 		pclose(pp);
     89 
     90 		++sno;
     91 		printf("Waiting until fs continues\n");
     92 		fcntl(fd, LFCNWRAPGO, &dowait);
     93 	}
     94 
     95 	return 0;
     96 }
     97