+ int rc, fd;
+
+ memset(buf, 0, len);
+
+ fd = open(proc_path, O_RDONLY);
+ if (fd < 0) {
+ llapi_error(LLAPI_MSG_ERROR, -errno, "cannot open '%s'",
+ proc_path);
+ return -2;
+ }
+
+ rc = read(fd, buf, len - 1);
+ if (rc < 0) {
+ llapi_error(LLAPI_MSG_ERROR, -errno,
+ "error reading from '%s'", proc_path);
+ rc = -3;
+ } else if (rc == 0) {
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "read zero bytes from '%s'", proc_path);
+ rc = -4;
+ } else if (buf[rc - 1] == '\n') {
+ buf[rc - 1] = '\0'; /* Remove trailing newline */
+ }
+
+ close(fd);
+
+ return rc;
+}
+
+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) {
+ 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)
+ 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)
+ 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) {
+ 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;