int compare(struct obd_uuid *puuid, struct lov_user_md *lum_dir, struct lov_user_md *lum_file1, struct lov_user_md *lum_file2) { int stripe_count = 0, min_stripe_count = 0, def_stripe_count = 1; int stripe_size = 0; int stripe_offset = -1; int ost_count; char buf[128]; glob_t path; int i; if (cfs_get_param_paths(&path, "lov/%s/stripecount", puuid->uuid) != 0) return 2; if (read_proc_entry(path.gl_pathv[0], buf, sizeof(buf)) < 0) { cfs_free_param_data(&path); return 5; } cfs_free_param_data(&path); def_stripe_count = (short)atoi(buf); if (cfs_get_param_paths(&path, "lov/%s/numobd", puuid->uuid) != 0) return 2; if (read_proc_entry(path.gl_pathv[0], buf, sizeof(buf)) < 0) { cfs_free_param_data(&path); return 6; } cfs_free_param_data(&path); ost_count = atoi(buf); if (lum_dir == NULL) { stripe_count = def_stripe_count; min_stripe_count = -1; } else { stripe_count = (signed short)lum_dir->lmm_stripe_count; printf("dir stripe %d, ", stripe_count); min_stripe_count = 1; } printf("default stripe %d, ost count %d\n", def_stripe_count, ost_count); if (stripe_count == 0) { min_stripe_count = -1; stripe_count = 1; } stripe_count = (stripe_count > 0 && stripe_count <= ost_count) ? stripe_count : ost_count; min_stripe_count = min_stripe_count > 0 ? stripe_count : ((stripe_count + 1) / 2); if (lum_file1->lmm_stripe_count != stripe_count || lum_file1->lmm_stripe_count < min_stripe_count) { llapi_err_noerrno(LLAPI_MSG_ERROR, "file1 stripe count %d != dir %d\n", lum_file1->lmm_stripe_count, stripe_count); return 7; } if (lum_file1->lmm_stripe_count < stripe_count) llapi_err_noerrno(LLAPI_MSG_WARN, "warning: file1 used fewer stripes" " %d < dir %d (likely due to bug 4900)\n", lum_file1->lmm_stripe_count, stripe_count); if (lum_dir != NULL) stripe_size = (int)lum_dir->lmm_stripe_size; if (stripe_size == 0) { if (cfs_get_param_paths(&path, "lov/%s/stripesize", puuid->uuid) != 0) return 2; if (read_proc_entry(path.gl_pathv[0], buf, sizeof(buf)) < 0) { cfs_free_param_data(&path); return 5; } cfs_free_param_data(&path); stripe_size = atoi(buf); } if (lum_file1->lmm_stripe_size != stripe_size) { llapi_err_noerrno(LLAPI_MSG_ERROR, "file1 stripe size %d != dir %d\n", lum_file1->lmm_stripe_size, stripe_size); return 8; } if (lum_dir != NULL) stripe_offset = (short int)lum_dir->lmm_stripe_offset; if (stripe_offset != -1) { for (i = 0; i < stripe_count; i++) if (lum_file1->lmm_objects[i].l_ost_idx != (stripe_offset + i) % ost_count) { llapi_err_noerrno(LLAPI_MSG_WARN, "warning: file1 non-sequential " "stripe[%d] %d != %d\n", i, lum_file1->lmm_objects[i].l_ost_idx, (stripe_offset + i) % ost_count); } } else if (lum_file2 != NULL) { int next, idx, stripe = stripe_count - 1; next = (lum_file1->lmm_objects[stripe].l_ost_idx + 1) % ost_count; idx = lum_file2->lmm_objects[0].l_ost_idx; if (idx != next) { llapi_err_noerrno(LLAPI_MSG_WARN, "warning: non-sequential " "file1 stripe[%d] %d != file2 stripe[0] %d\n", stripe, lum_file1->lmm_objects[stripe].l_ost_idx, idx); } } return 0; }
int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1, struct lov_user_md *lum_file2) { int stripe_count = 0, min_stripe_count = 0, def_stripe_count = 1; int stripe_size = 0; int stripe_offset = -1; int ost_count; char buf[128]; char lov_path[PATH_MAX]; char tmp_path[PATH_MAX]; int i; FILE *fp; fp = popen("\\ls -d /proc/fs/lustre/lov/*clilov* | head -1", "r"); if (!fp) { llapi_err(LLAPI_MSG_ERROR, "open(lustre/lov/*clilov*) failed: %s\n"); return 2; } if (fscanf(fp, "%s", lov_path) < 1) { llapi_err(LLAPI_MSG_ERROR, "read(lustre/lov/*clilov*) failed: %s\n"); pclose(fp); return 3; } pclose(fp); snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripecount", lov_path); if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0) return 5; def_stripe_count = (short)atoi(buf); snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/numobd", lov_path); if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0) return 6; ost_count = atoi(buf); if (lum_dir == NULL) { stripe_count = def_stripe_count; min_stripe_count = -1; } else { stripe_count = (signed short)lum_dir->lmm_stripe_count; printf("dir stripe %d, ", stripe_count); min_stripe_count = 1; } printf("default stripe %d, ost count %d\n", def_stripe_count, ost_count); if (stripe_count == 0) { min_stripe_count = -1; stripe_count = 1; } stripe_count = (stripe_count > 0 && stripe_count <= ost_count) ? stripe_count : ost_count; min_stripe_count = min_stripe_count > 0 ? stripe_count : ((stripe_count + 1) / 2); if (lum_file1->lmm_stripe_count != stripe_count || lum_file1->lmm_stripe_count < min_stripe_count) { llapi_err(LLAPI_MSG_ERROR, "file1 stripe count %d != dir %d\n", lum_file1->lmm_stripe_count, stripe_count); return 7; } if (lum_file1->lmm_stripe_count < stripe_count) llapi_err(LLAPI_MSG_WARN, "warning: file1 used fewer stripes" " %d < dir %d (likely due to bug 4900)\n", lum_file1->lmm_stripe_count, stripe_count); if (lum_dir != NULL) stripe_size = (int)lum_dir->lmm_stripe_size; if (stripe_size == 0) { snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripesize", lov_path); if (read_proc_entry(tmp_path, buf, sizeof(buf)) < 0) return 5; stripe_size = atoi(buf); } if (lum_file1->lmm_stripe_size != stripe_size) { llapi_err(LLAPI_MSG_ERROR, "file1 stripe size %d != dir %d\n", lum_file1->lmm_stripe_size, stripe_size); return 8; } if (lum_dir != NULL) stripe_offset = (short int)lum_dir->lmm_stripe_offset; if (stripe_offset != -1) { for (i = 0; i < stripe_count; i++) if (lum_file1->lmm_objects[i].l_ost_idx != (stripe_offset + i) % ost_count) { llapi_err(LLAPI_MSG_WARN, "warning: file1 non-sequential " "stripe[%d] %d != %d\n", i, lum_file1->lmm_objects[i].l_ost_idx, (stripe_offset + i) % ost_count); } } else if (lum_file2 != NULL) { int next, idx, stripe = stripe_count - 1; next = (lum_file1->lmm_objects[stripe].l_ost_idx + 1) % ost_count; idx = lum_file2->lmm_objects[0].l_ost_idx; if (idx != next) { llapi_err(LLAPI_MSG_WARN, "warning: non-sequential " "file1 stripe[%d] %d != file2 stripe[0] %d\n", stripe, lum_file1->lmm_objects[stripe].l_ost_idx, idx); } } return 0; }