10 #include <sys/ioctl.h>
11 #include <sys/types.h>
14 #include <liblustre.h>
15 #include <linux/obd.h>
16 #include <linux/lustre_lib.h>
17 #include <linux/lustre_lite.h>
18 #include <linux/obd_lov.h>
20 /* XXX Max obds per lov currently hardcoded to 1000 in lov/lov_obd.c */
21 #define MAX_LOV_UUID_COUNT 1000
22 #define OBD_NOT_FOUND (-1)
25 struct option longOpts[] = {
29 {"verbose", 0, 0, 'v'},
34 char * shortOpts = "ho:qv";
35 char * usageMsg = "[ --obd <obd uuid> | --query ] <dir|file> ...";
37 int max_ost_count = MAX_LOV_UUID_COUNT;
38 struct obd_uuid * obduuid;
41 struct obd_uuid * uuids;
42 struct obd_ioctl_data data;
46 struct lov_mds_md *lmm;
50 void usage(FILE *stream);
51 void errMsg(char *fmt, ...);
52 void processPath(const char *path);
55 main (int argc, char **argv) {
58 cmd = basename(argv[0]);
60 while ((c = getopt_long(argc, argv, shortOpts, longOpts, NULL)) != -1) {
64 errMsg("obd '%s' already specified: '%s'.",
69 obduuid = (struct obd_uuid *)optarg;
84 errMsg("Internal error. Valid '%s' unrecognized.",
102 processPath(argv[optind]);
103 } while (++optind < argc);
111 int datalen, desclen;
113 datalen = size_round(sizeof(data));
114 desclen = size_round(sizeof(desc));
115 uuidslen = size_round(max_ost_count * sizeof(*uuids));
116 cfglen = datalen + desclen + uuidslen;
117 lmmlen = lov_mds_md_size(max_ost_count);
123 /* XXX max ioctl buffer size currently hardcoded to 8192 */
125 int nuuids, remaining, nluoinfos;
128 nuuids = (buflen - datalen - desclen) / sizeof(*uuids);
129 uuidslen = size_round(nuuids * sizeof(*uuids));
130 remaining = nuuids * sizeof(*uuids);
131 if (uuidslen > remaining)
133 nluoinfos = (buflen - sizeof(*lmm)) / sizeof(*lmm->lmm_objects);
134 if (nuuids > nluoinfos)
135 max_ost_count = nluoinfos;
137 max_ost_count = nuuids;
139 cfglen = datalen + desclen + uuidslen;
140 lmmlen = lov_mds_md_size(max_ost_count);
143 if ((buf = malloc(buflen)) == NULL) {
144 errMsg("Unable to allocate %d bytes of memory for ioctl's.",
149 lmm = (struct lov_mds_md *)buf;
150 uuids = (struct obd_uuid *)buf;
156 fprintf(stream, "usage: %s %s\n", cmd, usageMsg);
160 errMsg(char *fmt, ...)
164 fprintf(stderr, "%s: ", cmd);
166 vfprintf(stderr, fmt, args);
168 fprintf(stderr, "\n");
172 processPath(const char *path)
179 struct obd_uuid *uuidp;
181 if (query || verbose && !obduuid) {
182 printf("%s\n", path);
185 if ((fd = open(path, O_RDONLY | O_LOV_DELAY_CREATE)) < 0) {
186 errMsg("open \"%.20s\" failed.", path);
191 memset(&data, 0, sizeof(data));
192 data.ioc_inllen1 = sizeof(desc);
193 data.ioc_inlbuf1 = (char *)&desc;
194 data.ioc_inllen2 = uuidslen;
195 data.ioc_inlbuf2 = (char *)uuids;
197 memset(&desc, 0, sizeof(desc));
198 desc.ld_tgt_count = max_ost_count;
200 if (obd_ioctl_pack(&data, &buf, buflen)) {
201 errMsg("internal buffering error.");
205 rc = ioctl(fd, OBD_IOC_LOV_GET_CONFIG, buf);
207 if (errno == ENOTTY) {
209 printf("Not a regular file or not Lustre file.\n\n");
213 errMsg("OBD_IOC_LOV_GET_CONFIG ioctl failed: %d.", errno);
218 if (obd_ioctl_unpack(&data, buf, buflen)) {
219 errMsg("Invalid reply from ioctl.");
223 obdcount = desc.ld_tgt_count;
227 obdindex = OBD_NOT_FOUND;
230 for (i = 0, uuidp = uuids; i < obdcount; i++, uuidp++) {
231 if (strncmp((const char *)obduuid, (const char *)uuidp,
232 sizeof(*uuidp)) == 0) {
237 if (obdindex == OBD_NOT_FOUND)
239 } else if (query || verbose) {
241 for (i = 0, uuidp = uuids; i < obdcount; i++, uuidp++)
242 printf("%4d: %s\n", i, (char *)uuidp);
245 memset((void *)buf, 0, buflen);
246 lmm->lmm_magic = LOV_MAGIC;
247 lmm->lmm_ost_count = max_ost_count;
249 rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, (void *)lmm);
251 if (errno == ENODATA) {
253 printf("Has no stripe information.\n\n");
257 errMsg("LL_IOC_LOV_GETSTRIPE ioctl failed. %d", errno);
265 if (obduuid && lmm->lmm_objects[obdindex].l_object_id)
266 printf("%s\n", path);
269 printf("lmm_magic: 0x%x\n", lmm->lmm_magic);
270 printf("lmm_object_id: "LPX64"\n", lmm->lmm_object_id);
271 printf("lmm_stripe_offset: %u\n", (int)lmm->lmm_stripe_offset);
272 printf("lmm_stripe_count: %u\n", (int)lmm->lmm_stripe_count);
273 printf("lmm_stripe_size: %u\n", (int)lmm->lmm_stripe_size);
274 printf("lmm_ost_count: %u\n", lmm->lmm_ost_count);
275 printf("lmm_stripe_pattern: %d\n", lmm->lmm_magic & 0xf);
278 if (query || verbose) {
280 int ost = lmm->lmm_stripe_offset;
283 for (i = 0; i < lmm->lmm_ost_count; i++, ost++) {
284 ost %= lmm->lmm_ost_count;
285 if ((oid = lmm->lmm_objects[ost].l_object_id)) {
287 printf("\tobdidx\t objid\n");
290 printf("\t%6u\t%8llu%s\n",
291 ost, oid, obdindex == ost ? " *" : "");