1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2006 Cluster File Systems, Inc.
5 * Author: Nathan Rutman <nathan@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* Safely read the last_rcvd file from a device */
33 #include <sys/types.h>
35 #include <sys/mount.h>
40 #include <lustre_disk.h>
41 #include <lustre_ver.h>
43 int run_command(char *cmd)
45 char log[] = "/tmp/mkfs_logXXXXXX";
49 if ((fd = mkstemp(log)) >= 0) {
56 /* Can't use popen because we need the rv of the command */
63 while (fgets(buf, sizeof(buf), fp) != NULL) {
77 int main(int argc, char *const argv[])
79 char tmpdir[] = "/tmp/dirXXXXXX";
83 struct lr_server_data lsd;
87 if ((argc < 2) || (argv[argc - 1][0] == '-')) {
88 printf("Usage: %s devicename\n", argv[0]);
89 printf("Read and print the last_rcvd file from a device\n");
90 printf("(safe for mounted devices)\n");
97 /* Make a temporary directory to hold Lustre data files. */
98 if (!mkdtemp(tmpdir)) {
99 fprintf(stderr, "%s: Can't create temporary directory %s: %s\n",
100 progname, tmpdir, strerror(errno));
104 memset(cmd, 0, sizeof(cmd));
106 "debugfs -c -R 'dump /%s %s/%s' %s",
107 LAST_RCVD, tmpdir, LAST_RCVD, dev);
109 ret = run_command(cmd);
111 fprintf(stderr, "%s: Unable to dump %s file\n",
112 progname, LAST_RCVD);
116 sprintf(filepnm, "%s/%s", tmpdir, LAST_RCVD);
117 filep = fopen(filepnm, "r");
119 fprintf(stderr, "%s: Unable to read old data\n",
125 printf("Reading %s\n", LAST_RCVD);
126 ret = fread(&lsd, 1, sizeof(lsd), filep);
127 if (ret < sizeof(lsd)) {
128 fprintf(stderr, "%s: Short read (%d of %d)\n",
129 progname, ret, sizeof(lsd));
130 ret = -ferror(filep);
136 __u8 lsd_uuid[40]; /* server UUID */
137 __u64 lsd_last_transno; /* last completed transaction ID */
138 __u64 lsd_compat14; /* reserved - compat with old last_rcvd */
139 __u64 lsd_mount_count; /* incarnation number */
140 __u32 lsd_feature_compat; /* compatible feature flags */
141 __u32 lsd_feature_rocompat;/* read-only compatible feature flags */
142 __u32 lsd_feature_incompat;/* incompatible feature flags */
143 __u32 lsd_server_size; /* size of server data area */
144 __u32 lsd_client_start; /* start of per-client data area */
145 __u16 lsd_client_size; /* size of per-client data area */
146 __u16 lsd_subdir_count; /* number of subdirectories for objects */
147 __u64 lsd_catalog_oid; /* recovery catalog object id */
148 __u32 lsd_catalog_ogen; /* recovery catalog inode generation */
149 __u8 lsd_peeruuid[40]; /* UUID of MDS associated with this OST */
150 __u32 lsd_ost_index; /* index number of OST in LOV */
151 __u32 lsd_mdt_index; /* index number of MDT in LMV */
152 __u8 lsd_padding[LR_SERVER_SIZE - 148];
155 printf("UUID %s\n", lsd.lsd_uuid);
156 printf("Feature compat=%#x\n", lsd.lsd_feature_compat);
157 printf("Feature incompat=%#x\n", lsd.lsd_feature_incompat);
158 printf("Feature rocompat=%#x\n", lsd.lsd_feature_rocompat);
159 printf("Last transaction %llu\n", lsd.lsd_last_transno);
160 printf("ost index %u\n", lsd.lsd_ost_index);
161 printf("mdt index %u\n", lsd.lsd_mdt_index);
163 if ((lsd.lsd_feature_compat & OBD_COMPAT_OST) ||
164 (lsd.lsd_feature_incompat & OBD_INCOMPAT_OST)) {
165 printf("OST, index %d\n", lsd.lsd_ost_index);
166 } else if ((lsd.lsd_feature_compat & OBD_COMPAT_MDT) ||
167 (lsd.lsd_feature_incompat & OBD_INCOMPAT_MDT)) {
168 /* We must co-locate so mgs can see old logs.
169 If user doesn't want this, they can copy the old
170 logs manually and re-tunefs. */
171 printf("MDS, index %d\n", lsd.lsd_mdt_index);
173 /* If neither is set, we're pre-1.4.6, make a guess. */
174 /* Construct debugfs command line. */
175 memset(cmd, 0, sizeof(cmd));
177 "debugfs -c -R 'rdump /%s %s' %s",
178 MDT_LOGS_DIR, tmpdir, dev);
182 sprintf(filepnm, "%s/%s", tmpdir, MDT_LOGS_DIR);
183 if (lsd.lsd_ost_index > 0) {
184 printf("non-flagged OST, index %d\n",
187 /* If there's a LOGS dir, it's an MDT */
188 if ((ret = access(filepnm, F_OK)) == 0) {
189 /* Old MDT's are always index 0
191 printf("non-flagged MDS, index 0\n");
193 printf("non-flagged OST, index unknown\n");
202 memset(cmd, 0, sizeof(cmd));
203 sprintf(cmd, "rm -rf %s", tmpdir);