(clean): clean universal binary intermediate steps, too
[arla.git] / arlad / dump_state.c
blob9f5176acb2baf2ca5da8514926bd769da901e7ac
1 /*
2 * Copyright (c) 2001 - 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
35 * Dump arla disk storage
38 #include "arla_local.h"
39 #include <getarg.h>
40 #include <version.h>
41 RCSID("$Id$");
43 static char *prefix = ARLACACHEDIR;
44 static char *fcache_file;
45 static char *volcache_file;
46 static int local_version_flag;
47 static int local_verbose_flag;
48 static int local_help_flag;
50 static int
51 print_fcache_entry(struct fcache_store *st, void *ptr)
53 printf("Fid: %s %d.%d.%d %02x/%02x\n", st->cell,
54 st->fid.Volume, st->fid.Vnode, st->fid.Unique,
55 (st->index >> 8) & 0xff, st->index & 0xff );
56 if (local_verbose_flag)
57 printf("Length: accounted: %ld fetched: %ld\n",
58 (long)st->length, (long)st->fetched_length);
59 return 0;
62 static void
63 print_vol(nvldbentry *e, const char *str, int32_t flags, int type)
65 if (e->flags & flags)
66 printf (" %s: %d", str, e->volumeId[type]);
69 static int
70 print_volcache_entry(struct volcache_store *st, void *ptr)
72 printf("Volume: %s %s\n", st->cell, st->entry.name);
73 printf("volume-id:");
74 print_vol(&st->entry, "RW", VLF_RWEXISTS, RWVOL);
75 print_vol(&st->entry, "RO", VLF_ROEXISTS, ROVOL);
76 print_vol(&st->entry, "BU", VLF_BOEXISTS, BACKVOL);
77 printf("\n");
78 return 0;
81 static struct getargs args[] = {
82 {"prefix", 'p', arg_string, &prefix,
83 "prefix to arla cache dir", "dir"},
84 {"verbose", 'v', arg_flag, &local_verbose_flag,
85 NULL, NULL},
86 {"version", 0, arg_flag, &local_version_flag,
87 NULL, NULL},
88 {"help", 0, arg_flag, &local_help_flag,
89 NULL, NULL}
92 static void
93 usage (int ret)
95 arg_printusage (args, sizeof(args)/sizeof(*args), NULL, "");
96 exit (ret);
99 int
100 main(int argc, char **argv)
102 int optind = 0;
103 int ret;
105 setprogname (argv[0]);
107 if (getarg (args, sizeof(args)/sizeof(*args), argc, argv, &optind))
108 usage (1);
110 if (local_version_flag) {
111 print_version(NULL);
112 exit(0);
115 if (fcache_file == NULL)
116 asprintf(&fcache_file, "%s/fcache", prefix);
118 printf("fcache:\n");
119 ret = state_recover_fcache(fcache_file, print_fcache_entry, NULL);
120 if (ret)
121 warn("failed with %d to dump fcache state (%s)", ret, fcache_file);
123 if (volcache_file == NULL)
124 asprintf(&volcache_file, "%s/volcache", prefix);
126 printf("volcache\n");
127 ret = state_recover_volcache(volcache_file, print_volcache_entry, NULL);
128 if (ret)
129 warn("failed with %d to dump volcache state (%s)", ret, volcache_file);
131 return 0;