1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/utils/lr_reader.c
38 * Author: Nathan Rutman <nathan@clusterfs.com>
40 /* Safely read the last_rcvd file from a device */
52 #include <sys/types.h>
54 #include <sys/mount.h>
59 #include <lustre_disk.h>
60 #include <lustre_ver.h>
62 int run_command(char *cmd)
64 char log[] = "/tmp/mkfs_logXXXXXX";
68 if ((fd = mkstemp(log)) >= 0) {
75 /* Can't use popen because we need the rv of the command */
82 while (fgets(buf, sizeof(buf), fp) != NULL) {
96 int main(int argc, char *const argv[])
98 char tmpdir[] = "/tmp/dirXXXXXX";
101 char *progname, *dev;
102 struct lr_server_data lsd;
106 if ((argc < 2) || (argv[argc - 1][0] == '-')) {
107 printf("Usage: %s devicename\n", argv[0]);
108 printf("Read and print the last_rcvd file from a device\n");
109 printf("(safe for mounted devices)\n");
114 dev = argv[argc - 1];
116 /* Make a temporary directory to hold Lustre data files. */
117 if (!mkdtemp(tmpdir)) {
118 fprintf(stderr, "%s: Can't create temporary directory %s: %s\n",
119 progname, tmpdir, strerror(errno));
123 memset(cmd, 0, sizeof(cmd));
125 "debugfs -c -R 'dump /%s %s/%s' %s",
126 LAST_RCVD, tmpdir, LAST_RCVD, dev);
128 ret = run_command(cmd);
130 fprintf(stderr, "%s: Unable to dump %s file\n",
131 progname, LAST_RCVD);
135 sprintf(filepnm, "%s/%s", tmpdir, LAST_RCVD);
136 filep = fopen(filepnm, "r");
138 fprintf(stderr, "%s: Unable to read old data\n",
144 printf("Reading %s\n", LAST_RCVD);
145 ret = fread(&lsd, 1, sizeof(lsd), filep);
146 if (ret < sizeof(lsd)) {
147 fprintf(stderr, "%s: Short read (%d of %d)\n",
148 progname, ret, (int)sizeof(lsd));
149 ret = -ferror(filep);
155 __u8 lsd_uuid[40]; /* server UUID */
156 __u64 lsd_last_transno; /* last completed transaction ID */
157 __u64 lsd_compat14; /* reserved - compat with old last_rcvd */
158 __u64 lsd_mount_count; /* incarnation number */
159 __u32 lsd_feature_compat; /* compatible feature flags */
160 __u32 lsd_feature_rocompat;/* read-only compatible feature flags */
161 __u32 lsd_feature_incompat;/* incompatible feature flags */
162 __u32 lsd_server_size; /* size of server data area */
163 __u32 lsd_client_start; /* start of per-client data area */
164 __u16 lsd_client_size; /* size of per-client data area */
165 __u16 lsd_subdir_count; /* number of subdirectories for objects */
166 __u64 lsd_catalog_oid; /* recovery catalog object id */
167 __u32 lsd_catalog_ogen; /* recovery catalog inode generation */
168 __u8 lsd_peeruuid[40]; /* UUID of MDS associated with this OST */
169 __u32 lsd_ost_index; /* index number of OST in LOV */
170 __u32 lsd_mdt_index; /* index number of MDT in LMV */
171 __u8 lsd_padding[LR_SERVER_SIZE - 148];
174 printf("UUID %s\n", lsd.lsd_uuid);
175 printf("Feature compat=%#x\n", lsd.lsd_feature_compat);
176 printf("Feature incompat=%#x\n", lsd.lsd_feature_incompat);
177 printf("Feature rocompat=%#x\n", lsd.lsd_feature_rocompat);
178 printf("Last transaction %llu\n", (long long)lsd.lsd_last_transno);
179 printf("ost index %u\n", lsd.lsd_ost_index);
180 printf("mdt index %u\n", lsd.lsd_mdt_index);
182 if ((lsd.lsd_feature_compat & OBD_COMPAT_OST) ||
183 (lsd.lsd_feature_incompat & OBD_INCOMPAT_OST)) {
184 printf("OST, index %d\n", lsd.lsd_ost_index);
185 } else if ((lsd.lsd_feature_compat & OBD_COMPAT_MDT) ||
186 (lsd.lsd_feature_incompat & OBD_INCOMPAT_MDT)) {
187 /* We must co-locate so mgs can see old logs.
188 If user doesn't want this, they can copy the old
189 logs manually and re-tunefs. */
190 printf("MDS, index %d\n", lsd.lsd_mdt_index);
192 /* If neither is set, we're pre-1.4.6, make a guess. */
193 /* Construct debugfs command line. */
194 memset(cmd, 0, sizeof(cmd));
196 "debugfs -c -R 'rdump /%s %s' %s",
197 MDT_LOGS_DIR, tmpdir, dev);
201 sprintf(filepnm, "%s/%s", tmpdir, MDT_LOGS_DIR);
202 if (lsd.lsd_ost_index > 0) {
203 printf("non-flagged OST, index %d\n",
206 /* If there's a LOGS dir, it's an MDT */
207 if ((ret = access(filepnm, F_OK)) == 0) {
208 /* Old MDT's are always index 0
210 printf("non-flagged MDS, index 0\n");
212 printf("non-flagged OST, index unknown\n");
221 memset(cmd, 0, sizeof(cmd));
222 sprintf(cmd, "rm -rf %s", tmpdir);