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