1 #define _XOPEN_SOURCE 500
12 #include <sys/ioctl.h>
13 #include <sys/types.h>
15 #include <linux/lustre_lib.h>
16 #include <linux/lustre_lite.h>
17 #include <linux/obd_lov.h>
19 #warning Max obds per lov currently hardcoded to 1000 in lov/lov_obd.c
20 #define MAX_LOV_UUID_COUNT 1000
21 #define OBD_NOT_FOUND ((__u32)-1)
24 struct option longOpts[] = {
28 {"verbose", 0, 0, 'v'},
33 char * shortOpts = "ho:qv";
34 char * usageMsg = "[ --obd <obd uuid> | --query ] <dir|file> ...";
36 int max_ost_count = MAX_LOV_UUID_COUNT;
42 struct obd_ioctl_data data;
47 struct lov_mds_md *lmm;
51 void usage(FILE *stream);
52 void errMsg(char *fmt, ...);
53 void processPath(char *path);
56 const struct stat *sp,
60 __u32 getobdindex(const char *path);
63 main (int argc, char **argv) {
66 cmd = basename(argv[0]);
68 while ((c = getopt_long(argc, argv, shortOpts, longOpts, NULL)) != -1) {
72 errMsg("obd '%s' already specified: '%s'.",
77 obduuid = (obd_uuid_t *)optarg;
92 errMsg("Internal error. Valid '%s' unrecognized.",
110 processPath(argv[optind]);
111 } while (++optind < argc);
119 int datalen, desclen;
121 datalen = size_round(sizeof(data));
122 desclen = size_round(sizeof(desc));
123 uuidslen = size_round(max_ost_count * sizeof(*uuids));
124 cfglen = datalen + desclen + uuidslen;
125 lmmlen = lov_mds_md_size(max_ost_count);
131 #warning max ioctl buffer size currently hardcoded to 8192
133 int nuuids, remaining, nluoinfos;
136 nuuids = (buflen - datalen - desclen) / sizeof(*uuids);
137 uuidslen = size_round(nuuids * sizeof(*uuids));
138 remaining = nuuids * sizeof(*uuids);
139 if (uuidslen > remaining)
141 nluoinfos = (buflen - sizeof(*lmm)) / sizeof(*lmm->lmm_objects);
142 if (nuuids > nluoinfos)
143 max_ost_count = nluoinfos;
145 max_ost_count = nuuids;
147 cfglen = datalen + desclen + uuidslen;
148 lmmlen = lov_mds_md_size(max_ost_count);
151 if ((buf = malloc(buflen)) == NULL) {
152 errMsg("Unable to allocate %d bytes of memory for ioctl's.",
157 lmm = (struct lov_mds_md *)buf;
158 uuids = (obd_uuid_t *)buf;
164 fprintf(stream, "usage: %s %s\n", cmd, usageMsg);
168 errMsg(char *fmt, ...)
172 fprintf(stderr, "%s: ", cmd);
174 vfprintf(stderr, fmt, args);
176 fprintf(stderr, "\n");
180 processPath(char *path)
182 obdindex = OBD_NOT_FOUND;
183 nftw((const char *)path, processFile, 128, FTW_PHYS|FTW_MOUNT);
187 processFile(const char *path, const struct stat *sp, int flag, struct FTW *ftwp)
197 if ((obdcount == 0) && (getobdindex(path) == OBD_NOT_FOUND)) {
198 /* terminate nftw walking this tree */
202 if ((fd = open(path, O_RDONLY)) < 0) {
203 errMsg("open \"%.20s\" failed.", path);
208 memset((void *)buf, 0, buflen);
209 lmm->lmm_magic = LOV_MAGIC;
210 lmm->lmm_ost_count = max_ost_count;
212 if ((rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, (void *)lmm)) < 0) {
213 errMsg("LL_IOC_LOV_GETSTRIPE ioctl failed.");
220 if (query || verbose)
221 printf("\n%s:\n", path);
224 printf("lmm_magic: 0x%x\n", lmm->lmm_magic);
225 printf("lmm_object_id: 0x%llx\n", lmm->lmm_object_id);
226 printf("lmm_stripe_offset: %d\n", lmm->lmm_stripe_offset);
227 printf("lmm_stripe_count: %d\n", lmm->lmm_stripe_count);
228 printf("lmm_ost_count: %d\n", lmm->lmm_ost_count);
229 printf("lmm_stripe_pattern: %d\n", lmm->lmm_stripe_pattern);
232 count = lmm->lmm_ost_count;
234 if (query || verbose) {
235 struct lov_object_id *loi;
238 loi = lmm->lmm_objects;
240 printf("obdidx\tobjid\n");
242 for (i = 0; i < count; i++, loi++)
243 if ((oid = loi->l_object_id))
244 printf("%6d\t%5lld\n", i, oid);
250 if (lmm->lmm_objects[obdindex].l_object_id)
251 printf("%s\n", path);
257 getobdindex(const char *path)
264 if ((fd = open(path, O_RDONLY)) < 0) {
265 errMsg("open \"%.20s\" failed.", path);
270 data.ioc_inllen1 = sizeof(desc);
271 data.ioc_inlbuf1 = (char *)&desc;
272 data.ioc_inllen2 = uuidslen;
273 data.ioc_inlbuf2 = (char *)uuids;
274 data.ioc_inllen3 = 0;
276 memset(&desc, 0, sizeof(desc));
277 desc.ld_tgt_count = max_ost_count;
279 if (obd_ioctl_pack(&data, &buf, buflen)) {
280 errMsg("internal buffering error.");
284 rc = ioctl(fd, OBD_IOC_LOV_GET_CONFIG, buf);
286 errMsg("OBD_IOC_LOV_GET_CONFIG ioctl failed: %d.", errno);
291 if (obd_ioctl_unpack(&data, buf, buflen)) {
292 errMsg("Invalid reply from ioctl.");
298 obdcount = desc.ld_tgt_count;
302 for (i = 0, uuidp = uuids; i < obdcount; i++, uuidp++)
303 printf("%4d: %s\n", i, (char *)uuidp);
308 for (i = 0, uuidp = uuids; i < obdcount; i++, uuidp++) {
309 rc = strncmp((const char *)obduuid, (const char *)uuidp,
317 if (obdindex == OBD_NOT_FOUND) {
318 errMsg("obd UUID '%s' not found.", obduuid);
319 return(OBD_NOT_FOUND);