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.
13 #include <sys/ioctl.h>
19 #include <liblustre.h>
20 #include <linux/obd.h>
21 #include <linux/lustre_lib.h>
22 #include <lustre/lustre_user.h>
23 #include <linux/obd_lov.h>
25 #include <portals/ptlctl.h>
28 #define MAX_LOV_UUID_COUNT 1000
30 int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
31 struct lov_user_md *lum_file2)
41 stripe_count = (int)lum_dir->lmm_stripe_count;
42 if (stripe_count == 0) {
43 fd = open("/proc/fs/lustre/llite/fs0/lov/stripecount", O_RDONLY);
45 fprintf(stderr, "open proc file error: %s\n",
49 if (read(fd, buf, sizeof(buf)) == -1) {
50 fprintf(stderr, "read proc file error: %s\n",
56 stripe_count = atoi(buf);
57 stripe_count = stripe_count ? stripe_count : 1;
61 stripe_size = (int)lum_dir->lmm_stripe_size;
62 if (stripe_size == 0) {
63 fd = open("/proc/fs/lustre/llite/fs0/lov/stripesize", O_RDONLY);
65 fprintf(stderr, "open proc file error: %s\n",
69 if (read(fd, buf, sizeof(buf)) == -1) {
70 fprintf(stderr, "read proc file error: %s\n",
76 stripe_size = atoi(buf);
80 fd = open("/proc/fs/lustre/llite/fs0/lov/numobd", O_RDONLY);
82 fprintf(stderr, "open proc file error: %s\n",
86 if (read(fd, buf, sizeof(buf)) == -1) {
87 fprintf(stderr, "read proc file error: %s\n",
93 ost_count = atoi(buf);
96 if ((lum_file1->lmm_stripe_count != stripe_count) ||
97 (lum_file1->lmm_stripe_size != stripe_size))
102 stripe_offset = (short int)lum_dir->lmm_stripe_offset;
103 if (stripe_offset != -1) {
104 for (i = 0; i < stripe_count; i++)
105 if (lum_file1->lmm_objects[i].l_ost_idx !=
106 (stripe_offset + i) % ost_count)
108 } else if (lum_file2 != NULL) {
110 next = (lum_file1->lmm_objects[stripe_count-1].l_ost_idx + 1)
112 idx = lum_file2->lmm_objects[0].l_ost_idx;
120 int main(int argc, char **argv)
123 struct lov_user_md *lum_dir, *lum_file1 = NULL, *lum_file2 = NULL;
129 fprintf(stderr, "Usage: %s <dirname> <filename1> [filename2]\n",
134 dir = opendir(argv[1]);
136 fprintf(stderr, "%s opendir failed\n", argv[1]);
140 lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT);
141 if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) {
142 fprintf(stderr, "unable to allocate memory for ioctl's");
146 rc = ioctl(dirfd(dir), LL_IOC_LOV_GETSTRIPE, lum_dir);
148 if (errno == ENODATA) {
149 lum_dir->lmm_stripe_size = 0;
150 lum_dir->lmm_stripe_count = 0;
151 lum_dir->lmm_stripe_offset = -1;
158 if ((lum_file1 = (struct lov_user_md *)malloc(lum_size)) == NULL) {
159 fprintf(stderr, "unable to allocate memory for ioctl's");
164 fname = strrchr(argv[2], '/');
166 strncpy((char *)lum_file1, fname, lum_size);
167 rc = ioctl(dirfd(dir), IOC_MDC_GETSTRIPE, lum_file1);
174 if ((lum_file2 = (struct lov_user_md *)malloc(lum_size))
177 "unable to allocate memory for ioctl's");
182 fname = strrchr(argv[3], '/');
184 strncpy((char *)lum_file2, fname, lum_size);
185 rc = ioctl(dirfd(dir), IOC_MDC_GETSTRIPE, lum_file2);
192 rc = compare(lum_dir, lum_file1, lum_file2);
197 if (lum_file1 != NULL)
199 if (lum_file2 != NULL)