+ obd->md_stats = NULL;
+ 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 = (struct obd_export*)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;
+}
+
+void lprocfs_exp_print_uuid(void *obj, void *cb_data)
+{
+ struct obd_export *exp = (struct obd_export *)obj;
+ 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));
+}
+
+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);
+ lustre_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
+ lprocfs_exp_print_uuid, &cb_data);
+ return (*cb_data.len);
+}
+
+void lprocfs_exp_print_hash(void *obj, void *cb_data)
+{
+ struct exp_uuid_cb_data *data = cb_data;
+ struct obd_export *exp = obj;
+ lustre_hash_t *lh;
+
+ lh = exp->exp_lock_hash;
+ if (lh) {
+ if (!*data->len)
+ *data->len += lustre_hash_debug_header(data->page,
+ data->count);
+
+ *data->len += lustre_hash_debug_str(lh, data->page + *data->len,
+ data->count);
+ }
+}
+
+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);
+
+ lustre_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);
+
+void lprocfs_nid_stats_clear_write_cb(void *obj, void *data)
+{
+ struct nid_stat *stat = obj;
+ int i;
+ ENTRY;
+ /* object has only hash + iterate_all references.
+ * add/delete blocked by hash bucket lock */
+ CDEBUG(D_INFO,"refcnt %d\n", stat->nid_exp_ref_count);
+ if (stat->nid_exp_ref_count == 2) {
+ hlist_del_init(&stat->nid_hash);
+ stat->nid_exp_ref_count--;
+ spin_lock(&stat->nid_obd->obd_nid_lock);
+ list_move(&stat->nid_list, data);
+ spin_unlock(&stat->nid_obd->obd_nid_lock);
+ EXIT;
+ return;
+ }
+ /* 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]);
+ }
+ EXIT;
+ return;
+}
+
+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);
+
+ lustre_hash_for_each(obd->obd_nid_stats_hash,
+ lprocfs_nid_stats_clear_write_cb, &free_list);
+
+ while (!list_empty(&free_list)) {
+ client_stat = list_entry(free_list.next, struct nid_stat, nid_list);
+ 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 *newnid)
+{
+ struct nid_stat *new_stat, *old_stat;
+ struct nid_stat_uuid *new_ns_uuid;
+ struct obd_device *obd = NULL;
+ cfs_proc_dir_entry_t *entry;
+ 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);
+
+ OBD_ALLOC_PTR(new_ns_uuid);
+ if (new_ns_uuid == NULL) {
+ OBD_FREE_PTR(new_stat);
+ RETURN(-ENOMEM);
+ }
+ CFS_INIT_LIST_HEAD(&new_ns_uuid->ns_uuid_list);
+ strncpy(new_ns_uuid->ns_uuid.uuid, exp->exp_client_uuid.uuid,
+ sizeof(struct obd_uuid));
+
+ CFS_INIT_LIST_HEAD(&new_stat->nid_uuid_list);
+ new_stat->nid = *nid;
+ new_stat->nid_obd = exp->exp_obd;
+ new_stat->nid_exp_ref_count = 1; /* live in hash after destroy export */
+
+ /* protect competitive add to list, not need locking on destroy */
+ spin_lock(&obd->obd_nid_lock);
+ list_add(&new_stat->nid_list, &obd->obd_nid_stats);
+ spin_unlock(&obd->obd_nid_lock);
+
+ old_stat = lustre_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), 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) {
+ struct nid_stat_uuid *tmp_uuid;
+ int found = 0;
+
+ exp->exp_nid_stats = old_stat;
+ /* We need to decrement the refcount if the uuid was
+ * already in our list */
+ spin_lock(&obd->obd_nid_lock);
+ list_for_each_entry(tmp_uuid, &old_stat->nid_uuid_list,
+ ns_uuid_list) {
+ if (tmp_uuid && obd_uuid_equals(&tmp_uuid->ns_uuid,
+ &exp->exp_client_uuid)){
+ found = 1;
+ --old_stat->nid_exp_ref_count;
+ break;
+ }
+ }
+
+ if (!found)
+ list_add(&new_ns_uuid->ns_uuid_list,
+ &old_stat->nid_uuid_list);
+ else
+ OBD_FREE_PTR(new_ns_uuid);
+
+ spin_unlock(&obd->obd_nid_lock);
+
+ GOTO(destroy_new, rc = -EALREADY);
+ }
+ /* not found - create */
+ new_stat->nid_proc = lprocfs_register(libcfs_nid2str(*nid),
+ obd->obd_proc_exports_entry,
+ NULL, NULL);
+ if (new_stat->nid_proc == NULL) {
+ CERROR("Error making export directory for nid %s\n",
+ libcfs_nid2str(*nid));
+ GOTO(destroy_new_ns, rc = -ENOMEM);
+ }
+
+ /* Add in uuid to our nid_stats list */
+ spin_lock(&obd->obd_nid_lock);
+ list_add(&new_ns_uuid->ns_uuid_list, &new_stat->nid_uuid_list);
+ spin_unlock(&obd->obd_nid_lock);
+
+ entry = lprocfs_add_simple(new_stat->nid_proc, "uuid",
+ lprocfs_exp_rd_uuid, NULL, new_stat, NULL);
+ if (IS_ERR(entry)) {
+ CWARN("Error adding the NID stats file\n");
+ rc = PTR_ERR(entry);
+ GOTO(destroy_new_ns, rc);
+ }
+
+ entry = lprocfs_add_simple(new_stat->nid_proc, "hash",
+ lprocfs_exp_rd_hash, NULL, new_stat, NULL);
+ if (IS_ERR(entry)) {
+ CWARN("Error adding the hash file\n");
+ lprocfs_remove(&new_stat->nid_proc);
+ rc = PTR_ERR(entry);
+ GOTO(destroy_new_ns, rc);
+ }
+
+ exp->exp_nid_stats = new_stat;
+ *newnid = 1;
+ RETURN(rc);
+
+destroy_new_ns:
+ lustre_hash_del(obd->obd_nid_stats_hash, nid, &new_stat->nid_hash);
+ OBD_FREE_PTR(new_ns_uuid);
+
+destroy_new:
+ spin_lock(&obd->obd_nid_lock);
+ list_del(&new_stat->nid_list);
+ spin_unlock(&obd->obd_nid_lock);
+ OBD_FREE_PTR(new_stat);
+ RETURN(rc);
+}
+
+int lprocfs_exp_cleanup(struct obd_export *exp)
+{
+ struct nid_stat *stat = exp->exp_nid_stats;
+ struct nid_stat_uuid *cursor, *tmp;
+ int found = 0;
+
+ if(!stat || !exp->exp_obd)
+ RETURN(0);
+
+ spin_lock(&exp->exp_obd->obd_nid_lock);
+ list_for_each_entry_safe(cursor, tmp,
+ &stat->nid_uuid_list,
+ ns_uuid_list) {
+ if (cursor && obd_uuid_equals(&cursor->ns_uuid,
+ &exp->exp_client_uuid)) {
+ found = 1;
+ list_del(&cursor->ns_uuid_list);
+ OBD_FREE_PTR(cursor);
+ break;
+ }