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>
21 #include <linux/obd.h>
22 #include <linux/lustre_lib.h>
23 #include <lustre/lustre_user.h>
24 #include <linux/obd_lov.h>
26 #include <lnet/lnetctl.h>
29 #define MAX_LOV_UUID_COUNT 1000
31 int read_proc_entry(char *proc_path, char *buf, int len)
35 if ((fd = open(proc_path, O_RDONLY)) == -1) {
36 fprintf(stderr, "open('%s') failed: %s\n",
37 proc_path, strerror(errno));
39 } else if ((rcnt = read(fd, buf, len)) <= 0) {
40 fprintf(stderr, "read('%s') failed: %s\n",
41 proc_path, strerror(errno));
52 int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
53 struct lov_user_md *lum_file2)
57 int stripe_offset = -1;
60 char lov_path[PATH_MAX];
61 char tmp_path[PATH_MAX];
64 rc = read_proc_entry("/proc/fs/lustre/llite/fs0/lov/common_name",
65 buf, sizeof(buf)) <= 0;
69 snprintf(lov_path, sizeof(lov_path) - 1, "/proc/fs/lustre/lov/%s", buf);
71 if (lum_dir == NULL) {
72 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripecount",
74 if (read_proc_entry(tmp_path, buf, sizeof(buf)) <= 0)
77 stripe_count = atoi(buf);
79 stripe_count = (int)lum_dir->lmm_stripe_count;
81 if (stripe_count == 0)
84 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/numobd", lov_path);
85 if (read_proc_entry(tmp_path, buf, sizeof(buf)) <= 0)
88 ost_count = atoi(buf);
89 stripe_count = stripe_count > 0 ? stripe_count : ost_count;
91 if (lum_file1->lmm_stripe_count != stripe_count) {
92 fprintf(stderr, "file1 stripe count %d != dir %d\n",
93 lum_file1->lmm_stripe_count, stripe_count);
98 stripe_size = (int)lum_dir->lmm_stripe_size;
99 if (stripe_size == 0) {
100 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripesize",
102 if (read_proc_entry(tmp_path, buf, sizeof(buf)) <= 0)
105 stripe_size = atoi(buf);
108 if (lum_file1->lmm_stripe_size != stripe_size) {
109 fprintf(stderr, "file1 stripe size %d != dir %d\n",
110 lum_file1->lmm_stripe_size, stripe_size);
115 stripe_offset = (short int)lum_dir->lmm_stripe_offset;
116 if (stripe_offset != -1) {
117 for (i = 0; i < stripe_count; i++)
118 if (lum_file1->lmm_objects[i].l_ost_idx !=
119 (stripe_offset + i) % ost_count) {
120 fprintf(stderr, "warning: file1 non-sequential "
121 "stripe[%d] %d != %d\n", i,
122 lum_file1->lmm_objects[i].l_ost_idx,
123 (stripe_offset + i) % ost_count);
125 } else if (lum_file2 != NULL) {
126 int next, idx, stripe = stripe_count - 1;
127 next = (lum_file1->lmm_objects[stripe].l_ost_idx + 1) %
129 idx = lum_file2->lmm_objects[0].l_ost_idx;
131 fprintf(stderr, "warning: non-sequential "
132 "file1 stripe[%d] %d != file2 stripe[0] %d\n",
134 lum_file1->lmm_objects[stripe].l_ost_idx, idx);
141 int main(int argc, char **argv)
144 struct lov_user_md *lum_dir, *lum_file1 = NULL, *lum_file2 = NULL;
150 fprintf(stderr, "Usage: %s <dirname> <filename1> [filename2]\n",
155 dir = opendir(argv[1]);
157 fprintf(stderr, "%s opendir failed\n", argv[1]);
161 lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT);
162 if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) {
163 fprintf(stderr, "unable to allocate memory for ioctl's");
167 rc = ioctl(dirfd(dir), LL_IOC_LOV_GETSTRIPE, lum_dir);
169 if (errno == ENODATA) {
178 if ((lum_file1 = (struct lov_user_md *)malloc(lum_size)) == NULL) {
179 fprintf(stderr, "unable to allocate memory for ioctl's");
184 fname = strrchr(argv[2], '/');
186 strncpy((char *)lum_file1, fname, lum_size);
187 rc = ioctl(dirfd(dir), IOC_MDC_GETSTRIPE, lum_file1);
194 lum_file2 = (struct lov_user_md *)malloc(lum_size);
195 if (lum_file2 == NULL) {
197 "unable to allocate memory for ioctl's");
202 fname = strrchr(argv[3], '/');
204 strncpy((char *)lum_file2, fname, lum_size);
205 rc = ioctl(dirfd(dir), IOC_MDC_GETSTRIPE, lum_file2);
212 rc = compare(lum_dir, lum_file1, lum_file2);
217 if (lum_file1 != NULL)
219 if (lum_file2 != NULL)