+ if (conn && obd->u.cli.cl_import) {
+ rc = snprintf(page, count, "%s\n",
+ conn->c_remote_uuid.uuid);
+ } else {
+ rc = snprintf(page, count, "%s\n", "<none>");
+ }
+
+ LPROCFS_CLIMP_EXIT(obd);
+ return rc;
+}
+
+/** add up per-cpu counters */
+void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
+ struct lprocfs_counter *cnt)
+{
+ unsigned int num_cpu;
+ struct lprocfs_counter t;
+ struct lprocfs_counter *percpu_cntr;
+ int centry, i;
+
+ memset(cnt, 0, sizeof(*cnt));
+
+ if (stats == NULL) {
+ /* set count to 1 to avoid divide-by-zero errs in callers */
+ cnt->lc_count = 1;
+ return;
+ }
+
+ cnt->lc_min = LC_MIN_INIT;
+
+ if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
+ num_cpu = 1;
+ else
+ num_cpu = cfs_num_possible_cpus();
+
+ for (i = 0; i < num_cpu; i++) {
+ percpu_cntr = &(stats->ls_percpu[i])->lp_cntr[idx];
+
+ do {
+ centry = cfs_atomic_read(&percpu_cntr-> \
+ lc_cntl.la_entry);
+ t.lc_count = percpu_cntr->lc_count;
+ t.lc_sum = percpu_cntr->lc_sum;
+ t.lc_min = percpu_cntr->lc_min;
+ t.lc_max = percpu_cntr->lc_max;
+ t.lc_sumsquare = percpu_cntr->lc_sumsquare;
+ } while (centry != cfs_atomic_read(&percpu_cntr->lc_cntl. \
+ la_entry) &&
+ centry != cfs_atomic_read(&percpu_cntr->lc_cntl. \
+ la_exit));
+ cnt->lc_count += t.lc_count;
+ cnt->lc_sum += t.lc_sum;
+ if (t.lc_min < cnt->lc_min)
+ cnt->lc_min = t.lc_min;
+ if (t.lc_max > cnt->lc_max)
+ cnt->lc_max = t.lc_max;
+ cnt->lc_sumsquare += t.lc_sumsquare;
+ }
+
+ cnt->lc_units = stats->ls_percpu[0]->lp_cntr[idx].lc_units;
+}
+
+/**
+ * Append a space separated list of current set flags to str.
+ */
+#define flag2str(flag) \
+ if (imp->imp_##flag && max - len > 0) \
+ len += snprintf(str + len, max - len, "%s" #flag, len ? ", " : "");
+static int obd_import_flags2str(struct obd_import *imp, char *str, int max)
+{
+ int len = 0;
+
+ if (imp->imp_obd->obd_no_recov)
+ len += snprintf(str, max - len, "no_recov");
+
+ flag2str(invalid);
+ flag2str(deactive);
+ flag2str(replayable);
+ flag2str(pingable);
+ return len;
+}
+#undef flags2str
+
+static const char *obd_connect_names[] = {
+ "read_only",
+ "lov_index",
+ "unused",
+ "write_grant",
+ "server_lock",
+ "version",
+ "request_portal",
+ "acl",
+ "xattr",
+ "create_on_write",
+ "truncate_lock",
+ "initial_transno",
+ "inode_bit_locks",
+ "join_file(obsolete)",
+ "getattr_by_fid",
+ "no_oh_for_devices",
+ "remote_client",
+ "remote_client_by_force",
+ "max_byte_per_rpc",
+ "64bit_qdata",
+ "mds_capability",
+ "oss_capability",
+ "early_lock_cancel",
+ "som",
+ "adaptive_timeouts",
+ "lru_resize",
+ "mds_mds_connection",
+ "real_conn",
+ "change_qunit_size",
+ "alt_checksum_algorithm",
+ "fid_is_enabled",
+ "version_recovery",
+ "pools",
+ "grant_shrink",
+ "skip_orphan",
+ "large_ea",
+ "full20",
+ "layout_lock",
+ NULL
+};
+
+static int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep)
+{
+ __u64 mask = 1;
+ int i, ret = 0;
+
+ for (i = 0; obd_connect_names[i] != NULL; i++, mask <<= 1) {
+ if (flags & mask)
+ ret += snprintf(page + ret, count - ret, "%s%s",
+ ret ? sep : "", obd_connect_names[i]);
+ }
+ if (flags & ~(mask - 1))
+ ret += snprintf(page + ret, count - ret,
+ "%sunknown flags "LPX64,
+ ret ? sep : "", flags & ~(mask - 1));
+ return ret;
+}
+
+int lprocfs_rd_import(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ struct lprocfs_counter ret;
+ struct obd_device *obd = (struct obd_device *)data;
+ struct obd_import *imp;
+ struct obd_import_conn *conn;
+ int i, j, k, rw = 0;
+
+ LASSERT(obd != NULL);
+ LPROCFS_CLIMP_CHECK(obd);
+ imp = obd->u.cli.cl_import;
+ *eof = 1;
+
+ i = snprintf(page, count,
+ "import:\n"
+ " name: %s\n"
+ " target: %s\n"
+ " state: %s\n"
+ " connect_flags: [",
+ obd->obd_name,
+ obd2cli_tgt(obd),
+ ptlrpc_import_state_name(imp->imp_state));
+ i += obd_connect_flags2str(page + i, count - i,
+ imp->imp_connect_data.ocd_connect_flags,
+ ", ");
+ i += snprintf(page + i, count - i,
+ "]\n"
+ " import_flags: [");
+ i += obd_import_flags2str(imp, page + i, count - i);
+
+ i += snprintf(page + i, count - i,
+ "]\n"
+ " connection:\n"
+ " failover_nids: [");
+ cfs_spin_lock(&imp->imp_lock);
+ j = 0;
+ cfs_list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
+ i += snprintf(page + i, count - i, "%s%s", j ? ", " : "",
+ libcfs_nid2str(conn->oic_conn->c_peer.nid));
+ j++;
+ }
+ cfs_spin_unlock(&imp->imp_lock);
+ i += snprintf(page + i, count - i,
+ "]\n"
+ " current_connection: %s\n"
+ " connection_attempts: %u\n"
+ " generation: %u\n"
+ " in-progress_invalidations: %u\n",
+ libcfs_nid2str(imp->imp_connection->c_peer.nid),
+ imp->imp_conn_cnt,
+ imp->imp_generation,
+ cfs_atomic_read(&imp->imp_inval_count));
+
+ lprocfs_stats_collect(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR, &ret);
+ if (ret.lc_count != 0) {
+ /* first argument to do_div MUST be __u64 */
+ __u64 sum = ret.lc_sum;
+ do_div(sum, ret.lc_count);
+ ret.lc_sum = sum;
+ } else
+ ret.lc_sum = 0;
+ i += snprintf(page + i, count - i,
+ " rpcs:\n"
+ " inflight: %u\n"
+ " unregistering: %u\n"
+ " timeouts: %u\n"
+ " avg_waittime: "LPU64" %s\n",
+ cfs_atomic_read(&imp->imp_inflight),
+ cfs_atomic_read(&imp->imp_unregistering),
+ cfs_atomic_read(&imp->imp_timeouts),
+ ret.lc_sum, ret.lc_units);
+
+ k = 0;
+ for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
+ if (imp->imp_at.iat_portal[j] == 0)
+ break;
+ k = max_t(unsigned int, k,
+ at_get(&imp->imp_at.iat_service_estimate[j]));
+ }
+ i += snprintf(page + i, count - i,
+ " service_estimates:\n"
+ " services: %u sec\n"
+ " network: %u sec\n",
+ k,
+ at_get(&imp->imp_at.iat_net_latency));
+
+ i += snprintf(page + i, count - i,
+ " transactions:\n"
+ " last_replay: "LPU64"\n"
+ " peer_committed: "LPU64"\n"
+ " last_checked: "LPU64"\n",
+ imp->imp_last_replay_transno,
+ imp->imp_peer_committed_transno,
+ imp->imp_last_transno_checked);
+
+ /* avg data rates */
+ for (rw = 0; rw <= 1; rw++) {
+ lprocfs_stats_collect(obd->obd_svc_stats,
+ PTLRPC_LAST_CNTR + BRW_READ_BYTES + rw,
+ &ret);
+ if (ret.lc_sum > 0 && ret.lc_count > 0) {
+ /* first argument to do_div MUST be __u64 */
+ __u64 sum = ret.lc_sum;
+ do_div(sum, ret.lc_count);
+ ret.lc_sum = sum;
+ i += snprintf(page + i, count - i,
+ " %s_data_averages:\n"
+ " bytes_per_rpc: "LPU64"\n",
+ rw ? "write" : "read",
+ ret.lc_sum);
+ }
+ k = (int)ret.lc_sum;
+ j = opcode_offset(OST_READ + rw) + EXTRA_MAX_OPCODES;
+ lprocfs_stats_collect(obd->obd_svc_stats, j, &ret);
+ if (ret.lc_sum > 0 && ret.lc_count != 0) {
+ /* first argument to do_div MUST be __u64 */
+ __u64 sum = ret.lc_sum;
+ do_div(sum, ret.lc_count);
+ ret.lc_sum = sum;
+ i += snprintf(page + i, count - i,
+ " %s_per_rpc: "LPU64"\n",
+ ret.lc_units, ret.lc_sum);
+ j = (int)ret.lc_sum;
+ if (j > 0)
+ i += snprintf(page + i, count - i,
+ " MB_per_sec: %u.%.02u\n",
+ k / j, (100 * k / j) % 100);
+ }
+ }
+
+ LPROCFS_CLIMP_EXIT(obd);
+ return i;
+}
+
+int lprocfs_rd_state(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ struct obd_device *obd = (struct obd_device *)data;
+ struct obd_import *imp;
+ int i, j, k;
+
+ LASSERT(obd != NULL);
+ LPROCFS_CLIMP_CHECK(obd);
+ imp = obd->u.cli.cl_import;
+ *eof = 1;
+
+ i = snprintf(page, count, "current_state: %s\n",
+ ptlrpc_import_state_name(imp->imp_state));
+ i += snprintf(page + i, count - i,
+ "state_history:\n");
+ k = imp->imp_state_hist_idx;
+ for (j = 0; j < IMP_STATE_HIST_LEN; j++) {
+ struct import_state_hist *ish =
+ &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
+ if (ish->ish_state == 0)
+ continue;
+ i += snprintf(page + i, count - i, " - ["CFS_TIME_T", %s]\n",
+ ish->ish_time,
+ ptlrpc_import_state_name(ish->ish_state));
+ }
+
+ LPROCFS_CLIMP_EXIT(obd);
+ return i;
+}
+
+int lprocfs_at_hist_helper(char *page, int count, int rc,
+ struct adaptive_timeout *at)
+{
+ int i;
+ for (i = 0; i < AT_BINS; i++)
+ rc += snprintf(page + rc, count - rc, "%3u ", at->at_hist[i]);
+ rc += snprintf(page + rc, count - rc, "\n");
+ return rc;
+}
+
+/* See also ptlrpc_lprocfs_rd_timeouts */
+int lprocfs_rd_timeouts(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ struct obd_device *obd = (struct obd_device *)data;
+ struct obd_import *imp;
+ unsigned int cur, worst;
+ time_t now, worstt;
+ struct dhms ts;
+ int i, rc = 0;
+
+ LASSERT(obd != NULL);
+ LPROCFS_CLIMP_CHECK(obd);
+ imp = obd->u.cli.cl_import;
+ *eof = 1;
+
+ now = cfs_time_current_sec();
+
+ /* Some network health info for kicks */
+ s2dhms(&ts, now - imp->imp_last_reply_time);
+ rc += snprintf(page + rc, count - rc,
+ "%-10s : %ld, "DHMS_FMT" ago\n",
+ "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
+
+ cur = at_get(&imp->imp_at.iat_net_latency);
+ worst = imp->imp_at.iat_net_latency.at_worst_ever;
+ worstt = imp->imp_at.iat_net_latency.at_worst_time;
+ s2dhms(&ts, now - worstt);
+ rc += snprintf(page + rc, count - rc,
+ "%-10s : cur %3u worst %3u (at %ld, "DHMS_FMT" ago) ",
+ "network", cur, worst, worstt, DHMS_VARS(&ts));
+ rc = lprocfs_at_hist_helper(page, count, rc,
+ &imp->imp_at.iat_net_latency);
+
+ for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
+ if (imp->imp_at.iat_portal[i] == 0)
+ break;
+ cur = at_get(&imp->imp_at.iat_service_estimate[i]);
+ worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
+ worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
+ s2dhms(&ts, now - worstt);
+ rc += snprintf(page + rc, count - rc,
+ "portal %-2d : cur %3u worst %3u (at %ld, "
+ DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
+ cur, worst, worstt, DHMS_VARS(&ts));
+ rc = lprocfs_at_hist_helper(page, count, rc,
+ &imp->imp_at.iat_service_estimate[i]);
+ }
+
+ LPROCFS_CLIMP_EXIT(obd);
+ return rc;
+}
+
+int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ struct obd_device *obd = data;
+ __u64 flags;
+ int ret = 0;
+
+ LPROCFS_CLIMP_CHECK(obd);
+ flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
+ ret = snprintf(page, count, "flags="LPX64"\n", flags);
+ ret += obd_connect_flags2str(page + ret, count - ret, flags, "\n");
+ ret += snprintf(page + ret, count - ret, "\n");
+ LPROCFS_CLIMP_EXIT(obd);
+ return ret;
+}
+EXPORT_SYMBOL(lprocfs_rd_connect_flags);
+
+int lprocfs_rd_num_exports(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ struct obd_device *obd = data;
+
+ LASSERT(obd != NULL);
+ *eof = 1;
+ return snprintf(page, count, "%u\n", obd->obd_num_exports);