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 <portals/ptlctl.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)
60 char lov_path[PATH_MAX];
61 char tmp_path[PATH_MAX];
64 if (read_proc_entry("/proc/fs/lustre/llite/fs0/lov/common_name",
65 buf, sizeof(buf)) <= 0)
68 snprintf(lov_path, sizeof(lov_path) - 1, "/proc/fs/lustre/lov/%s", buf);
70 stripe_count = (int)lum_dir->lmm_stripe_count;
71 if (stripe_count == 0) {
72 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripecount", lov_path);
73 if (read_proc_entry(tmp_path, buf, sizeof(buf)) <= 0)
76 stripe_count = atoi(buf);
79 stripe_size = (int)lum_dir->lmm_stripe_size;
80 if (stripe_size == 0) {
81 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripesize", lov_path);
82 if (read_proc_entry(tmp_path, buf, sizeof(buf)) <= 0)
85 stripe_size = atoi(buf);
88 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/numobd", lov_path);
89 if (read_proc_entry(tmp_path, buf, sizeof(buf)) <= 0)
92 ost_count = atoi(buf);
93 stripe_count = stripe_count ? stripe_count : ost_count;
95 if ((lum_file1->lmm_stripe_count != stripe_count) ||
96 (lum_file1->lmm_stripe_size != stripe_size))
99 stripe_offset = (short int)lum_dir->lmm_stripe_offset;
100 if (stripe_offset != -1) {
101 for (i = 0; i < stripe_count; i++)
102 if (lum_file1->lmm_objects[i].l_ost_idx !=
103 (stripe_offset + i) % ost_count)
105 } else if (lum_file2 != NULL) {
107 next = (lum_file1->lmm_objects[stripe_count-1].l_ost_idx + 1)
109 idx = lum_file2->lmm_objects[0].l_ost_idx;
117 int main(int argc, char **argv)
120 struct lov_user_md *lum_dir, *lum_file1 = NULL, *lum_file2 = NULL;
126 fprintf(stderr, "Usage: %s <dirname> <filename1> [filename2]\n",
131 dir = opendir(argv[1]);
133 fprintf(stderr, "%s opendir failed\n", argv[1]);
137 lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT);
138 if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) {
139 fprintf(stderr, "unable to allocate memory for ioctl's");
143 rc = ioctl(dirfd(dir), LL_IOC_LOV_GETSTRIPE, lum_dir);
145 if (errno == ENODATA) {
146 lum_dir->lmm_stripe_size = 0;
147 lum_dir->lmm_stripe_count = 0;
148 lum_dir->lmm_stripe_offset = -1;
155 if ((lum_file1 = (struct lov_user_md *)malloc(lum_size)) == NULL) {
156 fprintf(stderr, "unable to allocate memory for ioctl's");
161 fname = strrchr(argv[2], '/');
163 strncpy((char *)lum_file1, fname, lum_size);
164 rc = ioctl(dirfd(dir), IOC_MDC_GETSTRIPE, lum_file1);
171 lum_file2 = (struct lov_user_md *)malloc(lum_size);
172 if (lum_file2 == NULL) {
174 "unable to allocate memory for ioctl's");
179 fname = strrchr(argv[3], '/');
181 strncpy((char *)lum_file2, fname, lum_size);
182 rc = ioctl(dirfd(dir), IOC_MDC_GETSTRIPE, lum_file2);
189 rc = compare(lum_dir, lum_file1, lum_file2);
194 if (lum_file1 != NULL)
196 if (lum_file2 != NULL)