+ obd->md_stats = NULL;
+ obd->md_cntr_base = 0;
+ lprocfs_free_stats(&stats);
+ }
+}
+
+void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
+{
+ lprocfs_counter_init(ldlm_stats,
+ LDLM_ENQUEUE - LDLM_FIRST_OPC,
+ 0, "ldlm_enqueue", "reqs");
+ lprocfs_counter_init(ldlm_stats,
+ LDLM_CONVERT - LDLM_FIRST_OPC,
+ 0, "ldlm_convert", "reqs");
+ lprocfs_counter_init(ldlm_stats,
+ LDLM_CANCEL - LDLM_FIRST_OPC,
+ 0, "ldlm_cancel", "reqs");
+ lprocfs_counter_init(ldlm_stats,
+ LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
+ 0, "ldlm_bl_callback", "reqs");
+ lprocfs_counter_init(ldlm_stats,
+ LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
+ 0, "ldlm_cp_callback", "reqs");
+ lprocfs_counter_init(ldlm_stats,
+ LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
+ 0, "ldlm_gl_callback", "reqs");
+}
+
+int lprocfs_exp_rd_nid(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ struct obd_export *exp = data;
+ LASSERT(exp != NULL);
+ *eof = 1;
+ return snprintf(page, count, "%s\n", obd_export_nid2str(exp));
+}
+
+struct exp_uuid_cb_data {
+ char *page;
+ int count;
+ int *eof;
+ int *len;
+};
+
+static void
+lprocfs_exp_rd_cb_data_init(struct exp_uuid_cb_data *cb_data, char *page,
+ int count, int *eof, int *len)
+{
+ cb_data->page = page;
+ cb_data->count = count;
+ cb_data->eof = eof;
+ cb_data->len = len;
+}
+
+int lprocfs_exp_print_uuid(cfs_hash_t *hs, cfs_hash_bd_t *bd,
+ cfs_hlist_node_t *hnode, void *cb_data)
+
+{
+ struct obd_export *exp = cfs_hash_object(hs, hnode);
+ struct exp_uuid_cb_data *data = (struct exp_uuid_cb_data *)cb_data;
+
+ if (exp->exp_nid_stats)
+ *data->len += snprintf((data->page + *data->len),
+ data->count, "%s\n",
+ obd_uuid2str(&exp->exp_client_uuid));
+ return 0;
+}
+
+int lprocfs_exp_rd_uuid(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ struct nid_stat *stats = (struct nid_stat *)data;
+ struct exp_uuid_cb_data cb_data;
+ struct obd_device *obd = stats->nid_obd;
+ int len = 0;
+
+ *eof = 1;
+ page[0] = '\0';
+ lprocfs_exp_rd_cb_data_init(&cb_data, page, count, eof, &len);
+ cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
+ lprocfs_exp_print_uuid, &cb_data);
+ return (*cb_data.len);
+}
+
+int lprocfs_exp_print_hash(cfs_hash_t *hs, cfs_hash_bd_t *bd,
+ cfs_hlist_node_t *hnode, void *cb_data)
+
+{
+ struct exp_uuid_cb_data *data = cb_data;
+ struct obd_export *exp = cfs_hash_object(hs, hnode);
+
+ if (exp->exp_lock_hash != NULL) {
+ if (!*data->len) {
+ *data->len += cfs_hash_debug_header(data->page,
+ data->count);
+ }
+ *data->len += cfs_hash_debug_str(hs, data->page + *data->len,
+ data->count);
+ }
+
+ return 0;
+}
+
+int lprocfs_exp_rd_hash(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ struct nid_stat *stats = (struct nid_stat *)data;
+ struct exp_uuid_cb_data cb_data;
+ struct obd_device *obd = stats->nid_obd;
+ int len = 0;
+
+ *eof = 1;
+ page[0] = '\0';
+ lprocfs_exp_rd_cb_data_init(&cb_data, page, count, eof, &len);
+
+ cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
+ lprocfs_exp_print_hash, &cb_data);
+ return (*cb_data.len);
+}
+
+int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ *eof = 1;
+ return snprintf(page, count, "%s\n",
+ "Write into this file to clear all nid stats and "
+ "stale nid entries");
+}
+EXPORT_SYMBOL(lprocfs_nid_stats_clear_read);
+
+int lprocfs_nid_stats_clear_write_cb(void *obj, void *data)
+{
+ struct nid_stat *stat = obj;
+ int i;
+ ENTRY;
+
+ CDEBUG(D_INFO,"refcnt %d\n", cfs_atomic_read(&stat->nid_exp_ref_count));
+ if (cfs_atomic_read(&stat->nid_exp_ref_count) == 1) {
+ /* object has only hash references. */
+ cfs_spin_lock(&stat->nid_obd->obd_nid_lock);
+ cfs_list_move(&stat->nid_list, data);
+ cfs_spin_unlock(&stat->nid_obd->obd_nid_lock);
+ RETURN(1);
+ }
+ /* we has reference to object - only clear data*/
+ if (stat->nid_stats)
+ lprocfs_clear_stats(stat->nid_stats);
+
+ if (stat->nid_brw_stats) {
+ for (i = 0; i < BRW_LAST; i++)
+ lprocfs_oh_clear(&stat->nid_brw_stats->hist[i]);
+ }
+ RETURN(0);
+}
+
+int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+ struct obd_device *obd = (struct obd_device *)data;
+ struct nid_stat *client_stat;
+ CFS_LIST_HEAD(free_list);
+
+ cfs_hash_cond_del(obd->obd_nid_stats_hash,
+ lprocfs_nid_stats_clear_write_cb, &free_list);
+
+ while (!cfs_list_empty(&free_list)) {
+ client_stat = cfs_list_entry(free_list.next, struct nid_stat,
+ nid_list);
+ cfs_list_del_init(&client_stat->nid_list);
+ lprocfs_free_client_stats(client_stat);
+ }
+
+ return count;
+}
+EXPORT_SYMBOL(lprocfs_nid_stats_clear_write);
+
+int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int reconnect,
+ int *newnid)
+{
+ struct nid_stat *new_stat, *old_stat;
+ struct obd_device *obd = NULL;
+ cfs_proc_dir_entry_t *entry;
+ char *buffer = NULL;
+ int rc = 0;
+ ENTRY;
+
+ *newnid = 0;
+
+ if (!exp || !exp->exp_obd || !exp->exp_obd->obd_proc_exports_entry ||
+ !exp->exp_obd->obd_nid_stats_hash)
+ RETURN(-EINVAL);
+
+ /* not test against zero because eric say:
+ * You may only test nid against another nid, or LNET_NID_ANY.
+ * Anything else is nonsense.*/
+ if (!nid || *nid == LNET_NID_ANY)
+ RETURN(0);
+
+ obd = exp->exp_obd;
+
+ CDEBUG(D_CONFIG, "using hash %p\n", obd->obd_nid_stats_hash);
+
+ OBD_ALLOC_PTR(new_stat);
+ if (new_stat == NULL)
+ RETURN(-ENOMEM);
+
+ new_stat->nid = *nid;
+ new_stat->nid_obd = exp->exp_obd;
+ /* we need set default refcount to 1 to balance obd_disconnect */
+ cfs_atomic_set(&new_stat->nid_exp_ref_count, 1);
+
+ old_stat = cfs_hash_findadd_unique(obd->obd_nid_stats_hash,
+ nid, &new_stat->nid_hash);
+ CDEBUG(D_INFO, "Found stats %p for nid %s - ref %d\n",
+ old_stat, libcfs_nid2str(*nid),
+ cfs_atomic_read(&new_stat->nid_exp_ref_count));
+
+ /* Return -EALREADY here so that we know that the /proc
+ * entry already has been created */
+ if (old_stat != new_stat) {
+ /* if this connects to the existing export of same nid,
+ * we need to release old stats for obd_disconnect won't
+ * balance the reference gotten in "cfs_hash_findadd_uinque" */
+ if (reconnect && exp->exp_nid_stats)
+ nidstat_putref(old_stat);
+
+ exp->exp_nid_stats = old_stat;
+ GOTO(destroy_new, rc = -EALREADY);
+ }
+ /* not found - create */
+ OBD_ALLOC(buffer, LNET_NIDSTR_SIZE);
+ if (buffer == NULL)
+ GOTO(destroy_new, rc = -ENOMEM);
+
+ memcpy(buffer, libcfs_nid2str(*nid), LNET_NIDSTR_SIZE);
+ new_stat->nid_proc = lprocfs_register(buffer,
+ obd->obd_proc_exports_entry,
+ NULL, NULL);
+ OBD_FREE(buffer, LNET_NIDSTR_SIZE);
+
+ if (new_stat->nid_proc == NULL) {
+ CERROR("Error making export directory for nid %s\n",
+ libcfs_nid2str(*nid));
+ GOTO(destroy_new_ns, rc = -ENOMEM);