Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / obdclass / lprocfs_status.c
index 79eb987..8787a3e 100644 (file)
@@ -255,7 +255,7 @@ struct file_operations lprocfs_evict_client_fops = {
 EXPORT_SYMBOL(lprocfs_evict_client_fops);
 
 /**
- * Add /proc entrys.
+ * Add /proc entries.
  *
  * \param root [in]  The parent proc entry on which new entry will be added.
  * \param list [in]  Array of proc entries to be added.
@@ -641,6 +641,73 @@ int lprocfs_rd_conn_uuid(char *page, char **start, off_t off, int count,
         return rc;
 }
 
+#define flag2str(flag) \
+        if (imp->imp_##flag && max - len > 0) \
+                len += snprintf(str + len, max - len, " " #flag);
+        
+/**
+ * Append a space separated list of current set flags to str.
+ */
+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);
+        flag2str(recon_bk);
+        flag2str(last_recon);
+        return len;
+}
+#undef flags2str
+
+int lprocfs_rd_import(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;
+        char *imp_state_name = NULL;
+        int rc = 0;
+
+        LASSERT(obd != NULL);
+        LPROCFS_CLIMP_CHECK(obd);
+        imp = obd->u.cli.cl_import;
+        imp_state_name = ptlrpc_import_state_name(imp->imp_state);
+        *eof = 1;
+
+        rc = snprintf(page, count, 
+                      "import: %s\n"
+                      "    target: %s@%s\n"
+                      "    state: %s\n"
+                      "    inflight: %u\n"
+                      "    conn_cnt: %u\n"
+                      "    generation: %u\n"
+                      "    inval_cnt: %u\n"
+                      "    last_replay_transno: "LPU64"\n"
+                      "    peer_committed_transno: "LPU64"\n"
+                      "    last_trasno_checked: "LPU64"\n"
+                      "    flags:",
+                      obd->obd_name,
+                      obd2cli_tgt(obd), imp->imp_connection->c_remote_uuid.uuid,
+                      imp_state_name,
+                      atomic_read(&imp->imp_inflight),
+                      imp->imp_conn_cnt,
+                      imp->imp_generation,
+                      atomic_read(&imp->imp_inval_count),
+                      imp->imp_last_replay_transno,
+                      imp->imp_peer_committed_transno,
+                      imp->imp_last_transno_checked);
+        rc += obd_import_flags2str(imp, page + rc, count - rc);
+        rc += snprintf(page+rc, count - rc, "\n");
+        LPROCFS_CLIMP_EXIT(obd);
+        return rc;
+}
+
 int lprocfs_at_hist_helper(char *page, int count, int rc,
                            struct adaptive_timeout *at)
 {
@@ -836,9 +903,12 @@ static void lprocfs_free_client_stats(struct nid_stat *client_stat)
                 lprocfs_free_stats(&client_stat->nid_stats);
 
         if (client_stat->nid_brw_stats)
-                OBD_FREE(client_stat->nid_brw_stats, sizeof(struct brw_stats));
+                OBD_FREE_PTR(client_stat->nid_brw_stats);
 
-        OBD_FREE(client_stat, sizeof(*client_stat));
+        if (client_stat->nid_ldlm_stats)
+                lprocfs_free_stats(&client_stat->nid_ldlm_stats);
+
+        OBD_FREE_PTR(client_stat);
         return;
 
 }
@@ -997,7 +1067,7 @@ static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
        struct lprocfs_stats *stats = p->private;
        struct lprocfs_counter  *cntr = v;
        struct lprocfs_counter  t, ret = { .lc_min = LC_MIN_INIT };
-       int i, idx, rc;
+       int i, idx, rc = 0;
        unsigned int num_cpu;
 
        if (cntr == &(stats->ls_percpu[0])->lp_cntr[0]) {
@@ -1038,6 +1108,9 @@ static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
                ret.lc_sumsquare += t.lc_sumsquare;
        }
 
+       if (ret.lc_count == 0)
+               goto out;
+
        rc = seq_printf(p, "%-25s "LPD64" samples [%s]", cntr->lc_name,
                        ret.lc_count, cntr->lc_units);
        if (rc < 0)
@@ -1196,7 +1269,6 @@ void lprocfs_init_ops_stats(int num_private_stats, struct lprocfs_stats *stats)
         LPROCFS_OBD_OP_INIT(num_private_stats, stats, change_cbdata);
         LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel);
         LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel_unused);
-        LPROCFS_OBD_OP_INIT(num_private_stats, stats, join_lru);
         LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_export);
         LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy_export);
         LPROCFS_OBD_OP_INIT(num_private_stats, stats, extent_calc);
@@ -1284,7 +1356,7 @@ int lprocfs_alloc_md_stats(struct obd_device *obd,
         LASSERT(obd->obd_proc_entry != NULL);
         LASSERT(obd->md_cntr_base == 0);
 
-        num_stats = 1 + MD_COUNTER_OFFSET(get_remote_perm) +
+        num_stats = 1 + MD_COUNTER_OFFSET(revalidate_lock) +
                     num_private_stats;
         stats = lprocfs_alloc_stats(num_stats, 0);
         if (stats == NULL)
@@ -1349,6 +1421,28 @@ void lprocfs_free_md_stats(struct obd_device *obd)
         }
 }
 
+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)
 {
@@ -1450,17 +1544,16 @@ 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) {
+        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_del_init(&stat->nid_list);
+                list_move(&stat->nid_list, data);
                 spin_unlock(&stat->nid_obd->obd_nid_lock);
-                list_add(&stat->nid_list, data);
                 EXIT;
                 return;
         }
@@ -1498,10 +1591,11 @@ EXPORT_SYMBOL(lprocfs_nid_stats_clear_write);
 
 int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
 {
-        int rc = 0;
-        struct nid_stat *tmp = NULL, *tmp1;
+        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;
@@ -1510,9 +1604,9 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
             !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.*/
+        /* 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);
 
@@ -1520,75 +1614,144 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
 
         CDEBUG(D_CONFIG, "using hash %p\n", obd->obd_nid_stats_hash);
 
-        OBD_ALLOC(tmp, sizeof(struct nid_stat));
-        if (tmp == NULL)
+        OBD_ALLOC_PTR(new_stat);
+        if (new_stat == NULL)
                 RETURN(-ENOMEM);
 
-        tmp->nid = *nid;
-        tmp->nid_obd = exp->exp_obd;
-        tmp->nid_exp_ref_count = 1; /* need live in hash after destroy export */
+        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(&tmp->nid_list, &obd->obd_nid_stats);
+        list_add(&new_stat->nid_list, &obd->obd_nid_stats);
         spin_unlock(&obd->obd_nid_lock);
 
-        tmp1 = lustre_hash_findadd_unique(obd->obd_nid_stats_hash,
-                                          nid, &tmp->nid_hash);
+        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",
-               tmp1, libcfs_nid2str(*nid), tmp->nid_exp_ref_count);
+               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 (tmp1 != tmp) {
-                exp->exp_nid_stats = tmp1;
-                GOTO(destroy_new, rc = 0);
+                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 */
-        tmp->nid_proc = lprocfs_register(libcfs_nid2str(*nid),
-                                         obd->obd_proc_exports_entry, NULL, NULL);
-        if (!tmp->nid_proc) {
-                CERROR("Error making export directory for"
-                       " nid %s\n", libcfs_nid2str(*nid));
-                lustre_hash_del(obd->obd_nid_stats_hash, nid, &tmp->nid_hash);
-                GOTO(destroy_new, rc = -ENOMEM);
+        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);
         }
 
-        entry = lprocfs_add_simple(tmp->nid_proc, "uuid",
-                                   lprocfs_exp_rd_uuid, NULL, tmp, NULL);
+        /* 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 uuid file\n");
+                CWARN("Error adding the NID stats file\n");
                 rc = PTR_ERR(entry);
+                GOTO(destroy_new_ns, rc);
         }
 
-        entry = lprocfs_add_simple(tmp->nid_proc, "hash",
-                                lprocfs_exp_rd_hash, NULL, tmp, NULL);
+        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 = tmp;
+        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(&tmp->nid_list);
+        list_del(&new_stat->nid_list);
         spin_unlock(&obd->obd_nid_lock);
-        OBD_FREE(tmp, sizeof(struct nid_stat));
+        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)
+        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;
+                }
+        }
+        spin_unlock(&exp->exp_obd->obd_nid_lock);
+        if (!found)
+                CERROR("obd_export's client uuid %s are not found in its "
+                       "nid_stats list\n", exp->exp_client_uuid.uuid);
+
         stat->nid_exp_ref_count--;
         CDEBUG(D_INFO, "Put stat %p - %d\n", stat, stat->nid_exp_ref_count);
 
         exp->exp_nid_stats = NULL;
+        lprocfs_free_md_stats(exp->exp_obd);
+
         return 0;
 }
 
@@ -1986,7 +2149,9 @@ EXPORT_SYMBOL(lprocfs_free_stats);
 EXPORT_SYMBOL(lprocfs_clear_stats);
 EXPORT_SYMBOL(lprocfs_register_stats);
 EXPORT_SYMBOL(lprocfs_init_ops_stats);
+EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
 EXPORT_SYMBOL(lprocfs_alloc_obd_stats);
+EXPORT_SYMBOL(lprocfs_alloc_md_stats);
 EXPORT_SYMBOL(lprocfs_free_obd_stats);
 EXPORT_SYMBOL(lprocfs_exp_setup);
 EXPORT_SYMBOL(lprocfs_exp_cleanup);
@@ -2004,6 +2169,7 @@ EXPORT_SYMBOL(lprocfs_rd_conn_uuid);
 EXPORT_SYMBOL(lprocfs_rd_num_exports);
 EXPORT_SYMBOL(lprocfs_rd_numrefs);
 EXPORT_SYMBOL(lprocfs_at_hist_helper);
+EXPORT_SYMBOL(lprocfs_rd_import);
 EXPORT_SYMBOL(lprocfs_rd_timeouts);
 EXPORT_SYMBOL(lprocfs_rd_blksize);
 EXPORT_SYMBOL(lprocfs_rd_kbytestotal);