+/*
+ * Print an obd device line with the ost_conn_uuid inserted, if the obd
+ * is an osc.
+ */
+static void print_obd_line(char *s)
+{
+ char buf[MAX_STRING_SIZE];
+ char obd_name[MAX_OBD_NAME];
+ FILE *fp = NULL;
+ char *ptr;
+
+ if (sscanf(s, " %*d %*s osc %s %*s %*d ", obd_name) == 0)
+ goto try_mdc;
+ snprintf(buf, sizeof(buf),
+ "/proc/fs/lustre/osc/%s/ost_conn_uuid", obd_name);
+ if ((fp = fopen(buf, "r")) == NULL)
+ goto try_mdc;
+ goto got_one;
+
+try_mdc:
+ if (sscanf(s, " %*d %*s mdc %s %*s %*d ", obd_name) == 0)
+ goto fail;
+ snprintf(buf, sizeof(buf),
+ "/proc/fs/lustre/mdc/%s/mds_conn_uuid", obd_name);
+ if ((fp = fopen(buf, "r")) == NULL)
+ goto fail;
+
+got_one:
+ fgets(buf, sizeof(buf), fp);
+ fclose(fp);
+
+ /* trim trailing newlines */
+ ptr = strrchr(buf, '\n');
+ if (ptr) *ptr = '\0';
+ ptr = strrchr(s, '\n');
+ if (ptr) *ptr = '\0';
+
+ printf("%s %s\n", s, buf);
+ return;
+
+fail:
+ printf("%s", s);
+ return;
+}
+