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/liblustreapi.h>
26 #include <lnet/lnetctl.h>
29 #define MAX_LOV_UUID_COUNT 1000
34 #define lov_uuid lov.uuid
35 #define lov_name lov.name
37 /* Returns bytes read on success and a negative value on failure.
38 * If zero bytes are read it will be treated as failure as such
39 * zero cannot be returned from this function.
41 int read_proc_entry(char *proc_path, char *buf, int len)
47 fd = open(proc_path, O_RDONLY);
49 llapi_err(LLAPI_MSG_ERROR, "open('%s') failed: %s\n",
54 rc = read(fd, buf, len - 1);
56 llapi_err(LLAPI_MSG_ERROR, "read('%s') failed: %s\n",proc_path);
59 llapi_err(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO,
60 "read('%s') zero bytes\n", proc_path);
62 } else if (/* rc > 0 && */ buf[rc - 1] == '\n') {
63 buf[rc - 1] = '\0'; /* Remove trailing newline */
70 int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1,
71 struct lov_user_md *lum_file2)
73 int stripe_count = 0, min_stripe_count = 0, def_stripe_count = 1;
75 int stripe_offset = -1;
78 char lov_path[PATH_MAX];
79 char tmp_path[PATH_MAX];
83 fp = popen("\\ls -d /proc/fs/lustre/lov/*clilov* | head -1", "r");
85 llapi_err(LLAPI_MSG_ERROR,
86 "open(lustre/lov/*clilov*) failed: %s\n");
89 if (fscanf(fp, "%s", lov_path) < 1) {
90 llapi_err(LLAPI_MSG_ERROR,
91 "read(lustre/lov/*clilov*) failed: %s\n");
97 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripecount",
99 if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0)
101 def_stripe_count = (short)atoi(buf);
103 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/numobd", lov_path);
104 if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0)
106 ost_count = atoi(buf);
108 if (lum_dir == NULL) {
109 stripe_count = def_stripe_count;
110 min_stripe_count = -1;
112 stripe_count = (signed short)lum_dir->lmm_stripe_count;
113 printf("dir stripe %d, ", stripe_count);
114 min_stripe_count = 1;
117 printf("default stripe %d, ost count %d\n",
118 def_stripe_count, ost_count);
120 if (stripe_count == 0) {
121 min_stripe_count = -1;
125 stripe_count = (stripe_count > 0 && stripe_count <= ost_count) ?
126 stripe_count : ost_count;
127 min_stripe_count = min_stripe_count > 0 ? stripe_count :
128 ((stripe_count + 1) / 2);
130 if (lum_file1->lmm_stripe_count != stripe_count ||
131 lum_file1->lmm_stripe_count < min_stripe_count) {
132 llapi_err(LLAPI_MSG_ERROR, "file1 stripe count %d != dir %d\n",
133 lum_file1->lmm_stripe_count, stripe_count);
137 if (lum_file1->lmm_stripe_count < stripe_count)
138 llapi_err(LLAPI_MSG_WARN, "warning: file1 used fewer stripes"
139 " %d < dir %d (likely due to bug 4900)\n",
140 lum_file1->lmm_stripe_count, stripe_count);
143 stripe_size = (int)lum_dir->lmm_stripe_size;
144 if (stripe_size == 0) {
145 snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripesize",
147 if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0)
150 stripe_size = atoi(buf);
153 if (lum_file1->lmm_stripe_size != stripe_size) {
154 llapi_err(LLAPI_MSG_ERROR, "file1 stripe size %d != dir %d\n",
155 lum_file1->lmm_stripe_size, stripe_size);
160 stripe_offset = (short int)lum_dir->lmm_stripe_offset;
161 if (stripe_offset != -1) {
162 for (i = 0; i < stripe_count; i++)
163 if (lum_file1->lmm_objects[i].l_ost_idx !=
164 (stripe_offset + i) % ost_count) {
165 llapi_err(LLAPI_MSG_WARN,
166 "warning: file1 non-sequential "
167 "stripe[%d] %d != %d\n", i,
168 lum_file1->lmm_objects[i].l_ost_idx,
169 (stripe_offset + i) % ost_count);
171 } else if (lum_file2 != NULL) {
172 int next, idx, stripe = stripe_count - 1;
173 next = (lum_file1->lmm_objects[stripe].l_ost_idx + 1) %
175 idx = lum_file2->lmm_objects[0].l_ost_idx;
177 llapi_err(LLAPI_MSG_WARN, "warning: non-sequential "
178 "file1 stripe[%d] %d != file2 stripe[0] %d\n",
179 stripe, lum_file1->lmm_objects[stripe].l_ost_idx,
187 int main(int argc, char **argv)
190 struct lov_user_md *lum_dir, *lum_file1 = NULL, *lum_file2 = NULL;
195 llapi_err(LLAPI_MSG_ERROR,
196 "Usage: %s <dirname> <filename1> [filename2]\n",
201 dir = opendir(argv[1]);
204 llapi_err(LLAPI_MSG_ERROR,
205 "error: %s opendir failed\n", argv[1]);
209 lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT);
210 if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) {
212 llapi_err(LLAPI_MSG_ERROR, "error: can't allocate %d bytes "
213 "for dir EA", lum_size);
217 rc = llapi_file_get_stripe(argv[1], lum_dir);
219 if (errno == ENODATA) {
224 llapi_err(LLAPI_MSG_ERROR,
225 "error: can't get EA for %s\n", argv[1]);
230 /* XXX should be llapi_lov_getname() */
231 rc = llapi_file_get_lov_uuid(argv[1], &lov_uuid);
234 llapi_err(LLAPI_MSG_ERROR, "error: can't get lov name for %s\n",
239 if ((lum_file1 = (struct lov_user_md *)malloc(lum_size)) == NULL) {
241 llapi_err(LLAPI_MSG_ERROR,
242 "error: can't allocate %d bytes for EA\n", lum_size);
246 rc = llapi_file_get_stripe(argv[2], lum_file1);
249 llapi_err(LLAPI_MSG_ERROR,
250 "error: unable to get EA for %s\n", argv[2]);
255 lum_file2 = (struct lov_user_md *)malloc(lum_size);
256 if (lum_file2 == NULL) {
258 llapi_err(LLAPI_MSG_ERROR, "error: can't allocate %d "
259 "bytes for file2 EA\n", lum_size);
263 rc = llapi_file_get_stripe(argv[3], lum_file2);
266 llapi_err(LLAPI_MSG_ERROR,
267 "error: can't get EA for %s\n", argv[3]);
272 rc = compare(lum_dir, lum_file1, lum_file2);
278 if (lum_file1 != NULL)
280 if (lum_file2 != NULL)