1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * ll_dirstripe_verify <dir> <file>:
5 * - to verify if the file has the same lov_user_md setting as the parent dir.
6 * - if dir's offset is set -1, ll_dirstripe_verify <dir> <file1> <file2>
7 * is used to further verify if file1 and file2's obdidx is continuous.
14 #include <sys/ioctl.h>
20 #include <liblustre.h>
22 #include <lustre_lib.h>
23 #include <lustre/lustre_user.h>
26 #include <lnet/lnetctl.h>
29 #define MAX_LOV_UUID_COUNT 1000
31 /* Returns bytes read on success and a negative value on failure.
32 * If zero bytes are read it will be treated as failure as such
33 * zero cannot be returned from this function.
35 int read_proc_entry(char *proc_path, char *buf, int len)
41 fd = open(proc_path, O_RDONLY);
43 fprintf(stderr, "open('%s') failed: %s\n",
44 proc_path, strerror(errno));
48 rc = read(fd, buf, len - 1);
50 fprintf(stderr, "read('%s') failed: %s\n",
51 proc_path, strerror(errno));
54 fprintf(stderr, "read('%s') zero bytes\n", proc_path);
56 } else if (/* rc > 0 && */ buf[rc - 1] == '\n') {
57 buf[rc - 1] = '\0'; /* Remove trailing newline */
64 int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
65 struct lov_user_md *lum_file2)
69 int stripe_offset = -1;
72 char lov_path[PATH_MAX];
73 char tmp_path[PATH_MAX];
77 fp = popen("\\ls -d /proc/fs/lustre/lov/*lov* | head -1", "r");
79 fprintf(stderr, "open(lustre/lov/*lov*) failed: %s\n",
83 if (fscanf(fp, "%s", lov_path) < 1) {
84 fprintf(stderr, "read(lustre/lov/*lov*) failed: %s\n",
91 if (lum_dir == NULL) {
92 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripecount",
94 if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0)
97 stripe_count = atoi(buf);
99 stripe_count = (int)lum_dir->lmm_stripe_count;
101 if (stripe_count == 0)
104 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/numobd", lov_path);
105 if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0)
108 ost_count = atoi(buf);
109 stripe_count = stripe_count > 0 ? stripe_count : ost_count;
111 if (lum_file1->lmm_stripe_count != stripe_count) {
112 fprintf(stderr, "file1 stripe count %d != dir %d\n",
113 lum_file1->lmm_stripe_count, stripe_count);
118 stripe_size = (int)lum_dir->lmm_stripe_size;
119 if (stripe_size == 0) {
120 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripesize",
122 if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0)
125 stripe_size = atoi(buf);
128 if (lum_file1->lmm_stripe_size != stripe_size) {
129 fprintf(stderr, "file1 stripe size %d != dir %d\n",
130 lum_file1->lmm_stripe_size, stripe_size);
135 stripe_offset = (short int)lum_dir->lmm_stripe_offset;
136 if (stripe_offset != -1) {
137 for (i = 0; i < stripe_count; i++)
138 if (lum_file1->lmm_objects[i].l_ost_idx !=
139 (stripe_offset + i) % ost_count) {
140 fprintf(stderr, "warning: file1 non-sequential "
141 "stripe[%d] %d != %d\n", i,
142 lum_file1->lmm_objects[i].l_ost_idx,
143 (stripe_offset + i) % ost_count);
145 } else if (lum_file2 != NULL) {
146 int next, idx, stripe = stripe_count - 1;
147 next = (lum_file1->lmm_objects[stripe].l_ost_idx + 1) %
149 idx = lum_file2->lmm_objects[0].l_ost_idx;
151 fprintf(stderr, "warning: non-sequential "
152 "file1 stripe[%d] %d != file2 stripe[0] %d\n",
154 lum_file1->lmm_objects[stripe].l_ost_idx, idx);
161 int main(int argc, char **argv)
164 struct lov_user_md *lum_dir, *lum_file1 = NULL, *lum_file2 = NULL;
170 fprintf(stderr, "Usage: %s <dirname> <filename1> [filename2]\n",
175 dir = opendir(argv[1]);
177 fprintf(stderr, "%s opendir failed: %s\n", argv[1],
182 lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT);
183 if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) {
184 fprintf(stderr, "unable to allocate memory for ioctl's");
188 rc = ioctl(dirfd(dir), LL_IOC_LOV_GETSTRIPE, lum_dir);
190 if (errno == ENODATA) {
199 if ((lum_file1 = (struct lov_user_md *)malloc(lum_size)) == NULL) {
200 fprintf(stderr, "unable to allocate memory for ioctl's");
205 fname = strrchr(argv[2], '/');
206 fname = (fname == NULL ? argv[2] : fname + 1);
208 strncpy((char *)lum_file1, fname, lum_size);
209 rc = ioctl(dirfd(dir), IOC_MDC_GETFILESTRIPE, lum_file1);
216 lum_file2 = (struct lov_user_md *)malloc(lum_size);
217 if (lum_file2 == NULL) {
219 "unable to allocate memory for ioctl's");
224 fname = strrchr(argv[3], '/');
225 fname = (fname == NULL ? argv[3] : fname + 1);
226 strncpy((char *)lum_file2, fname, lum_size);
227 rc = ioctl(dirfd(dir), IOC_MDC_GETFILESTRIPE, lum_file2);
234 rc = compare(lum_dir, lum_file1, lum_file2);
239 if (lum_file1 != NULL)
241 if (lum_file2 != NULL)