Whamcloud - gitweb
LU-13449 tgt: fix recovery timer comparisons
[fs/lustre-release.git] / lustre / obdclass / lprocfs_status_server.c
index f878de0..9c38196 100644 (file)
@@ -72,11 +72,6 @@ struct dentry *ldebugfs_add_symlink(const char *name, const char *target,
        va_end(ap);
 
        entry = debugfs_create_symlink(name, parent, dest);
-       if (IS_ERR_OR_NULL(entry)) {
-               CERROR("LdebugFS: Could not create symbolic link from %s to %s\n",
-                      name, dest);
-               entry = NULL;
-       }
 
        OBD_FREE(dest, MAX_STRING_SIZE + 1);
 no_entry:
@@ -149,15 +144,15 @@ EXPORT_SYMBOL(lprocfs_evict_client_seq_write);
 
 #undef BUFLEN
 
-int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
+ssize_t num_exports_show(struct kobject *kobj, struct attribute *attr,
+                        char *buf)
 {
-       struct obd_device *obd = data;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
 
-       LASSERT(obd != NULL);
-       seq_printf(m, "%u\n", obd->obd_num_exports);
-       return 0;
+       return scnprintf(buf, PAGE_SIZE, "%u\n", obd->obd_num_exports);
 }
-EXPORT_SYMBOL(lprocfs_num_exports_seq_show);
+EXPORT_SYMBOL(num_exports_show);
 
 static int obd_export_flags2str(struct obd_export *exp, struct seq_file *m)
 {
@@ -167,6 +162,7 @@ static int obd_export_flags2str(struct obd_export *exp, struct seq_file *m)
        flag2str(exp, in_recovery);
        flag2str(exp, disconnected);
        flag2str(exp, connecting);
+       flag2str(exp, no_recovery);
 
        return 0;
 }
@@ -258,7 +254,6 @@ static void lprocfs_free_client_stats(struct nid_stat *client_stat)
                lprocfs_free_stats(&client_stat->nid_ldlm_stats);
 
        OBD_FREE_PTR(client_stat);
-       return;
 }
 
 void lprocfs_free_per_client_stats(struct obd_device *obd)
@@ -328,6 +323,44 @@ static int lprocfs_exp_uuid_seq_show(struct seq_file *m, void *data)
 }
 LPROC_SEQ_FOPS_RO(lprocfs_exp_uuid);
 
+#define HASH_NAME_LEN  16
+
+static void ldebugfs_rhash_seq_show(const char *name, struct rhashtable *ht,
+                                   struct seq_file *m)
+{
+       unsigned int max_size = ht->p.max_size ? ht->p.max_size : UINT_MAX;
+       struct bucket_table *tbl;
+       int dist[8] = { 0, };
+       int maxdep = 0;
+       int i;
+
+       rcu_read_lock();
+       tbl = rht_dereference(ht->tbl, ht);
+       for (i = 0; i < tbl->size; i++) {
+               struct rhash_head *pos;
+               int count = 0;
+
+               rht_for_each(pos, tbl, i)
+                       count++;
+
+               if (count)
+                       maxdep = max(maxdep, count);
+
+               dist[min(fls(count), 7)]++;
+       }
+
+       seq_printf(m, "%-*s %5d %5d %10u %d.%03d 0.300 0.750 0x%03x %7d %7d %7d ",
+                  HASH_NAME_LEN, name, tbl->size, ht->p.min_size, max_size,
+                  atomic_read(&ht->nelems) / tbl->size,
+                  atomic_read(&ht->nelems) * 1000 / tbl->size,
+                  ht->p.automatic_shrinking, 0,
+                  atomic_read(&ht->nelems), maxdep);
+       rcu_read_unlock();
+
+       for (i = 0; i < 8; i++)
+               seq_printf(m, "%d%c",  dist[i], (i == 7) ? '\n' : '/');
+}
+
 static int
 lprocfs_exp_print_hash_seq(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                           struct hlist_node *hnode, void *cb_data)
@@ -384,6 +417,30 @@ int lprocfs_exp_replydata_seq_show(struct seq_file *m, void *data)
 }
 LPROC_SEQ_FOPS_RO(lprocfs_exp_replydata);
 
+int lprocfs_exp_print_fmd_count_seq(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                                   struct hlist_node *hnode, void *cb_data)
+
+{
+       struct obd_export *exp = cfs_hash_object(hs, hnode);
+       struct seq_file *m = cb_data;
+       struct tg_export_data *ted = &exp->exp_target_data;
+
+       seq_printf(m, "%d\n", ted->ted_fmd_count);
+
+       return 0;
+}
+
+int lprocfs_exp_fmd_count_seq_show(struct seq_file *m, void *data)
+{
+       struct nid_stat *stats = m->private;
+       struct obd_device *obd = stats->nid_obd;
+
+       cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
+                             lprocfs_exp_print_fmd_count_seq, m);
+       return 0;
+}
+LPROC_SEQ_FOPS_RO(lprocfs_exp_fmd_count);
+
 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
 {
        seq_puts(m, "Write into this file to clear all nid stats and stale nid entries\n");
@@ -418,9 +475,8 @@ lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
        struct seq_file *m = file->private_data;
        struct obd_device *obd = m->private;
        struct nid_stat *client_stat;
-       struct list_head free_list;
+       LIST_HEAD(free_list);
 
-       INIT_LIST_HEAD(&free_list);
        cfs_hash_cond_del(obd->obd_nid_stats_hash,
                          lprocfs_nid_stats_clear_write_cb, &free_list);
 
@@ -550,6 +606,15 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid)
                GOTO(destroy_new_ns, rc);
        }
 
+       entry = lprocfs_add_simple(new_stat->nid_proc, "fmd_count", new_stat,
+                                  &lprocfs_exp_fmd_count_fops);
+       if (IS_ERR(entry)) {
+               rc = PTR_ERR(entry);
+               CWARN("%s: error adding the fmd_count file: rc = %d\n",
+                     obd->obd_name, rc);
+               GOTO(destroy_new_ns, rc);
+       }
+
        spin_lock(&exp->exp_lock);
        exp->exp_nid_stats = new_stat;
        spin_unlock(&exp->exp_lock);
@@ -622,8 +687,12 @@ int lprocfs_hash_seq_show(struct seq_file *m, void *data)
        if (obd == NULL)
                return 0;
 
+       /* header for rhashtable state */
+       seq_printf(m, "%-*s   cur   min        max theta t-min t-max flags  rehash   count  maxdep distribution\n",
+                  HASH_NAME_LEN, "name");
+       ldebugfs_rhash_seq_show("UUID_HASH", &obd->obd_uuid_hash, m);
+
        cfs_hash_debug_header(m);
-       cfs_hash_debug_str(obd->obd_uuid_hash, m);
        cfs_hash_debug_str(obd->obd_nid_hash, m);
        cfs_hash_debug_str(obd->obd_nid_stats_hash, m);
        return 0;
@@ -638,7 +707,7 @@ int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data)
        LASSERT(obd != NULL);
 
        seq_printf(m, "status: ");
-       if (obd->obd_max_recoverable_clients == 0) {
+       if (atomic_read(&obd->obd_max_recoverable_clients) == 0) {
                seq_printf(m, "INACTIVE\n");
                goto out;
        }
@@ -647,16 +716,17 @@ int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data)
        if (obd->obd_recovering == 0) {
                seq_printf(m, "COMPLETE\n");
                seq_printf(m, "recovery_start: %lld\n",
-                          (s64)obd->obd_recovery_start);
+                          (s64)ktime_get_real_seconds() -
+                          (ktime_get_seconds() - obd->obd_recovery_start));
                seq_printf(m, "recovery_duration: %lld\n",
                           obd->obd_recovery_end ?
                           obd->obd_recovery_end - obd->obd_recovery_start :
-                          ktime_get_real_seconds() - obd->obd_recovery_start);
+                          ktime_get_seconds() - obd->obd_recovery_start);
                /* Number of clients that have completed recovery */
                seq_printf(m, "completed_clients: %d/%d\n",
-                          obd->obd_max_recoverable_clients -
+                          atomic_read(&obd->obd_max_recoverable_clients) -
                           obd->obd_stale_clients,
-                          obd->obd_max_recoverable_clients);
+                          atomic_read(&obd->obd_max_recoverable_clients));
                seq_printf(m, "replayed_requests: %d\n",
                           obd->obd_replayed_requests);
                seq_printf(m, "last_transno: %lld\n",
@@ -682,9 +752,11 @@ int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data)
                        seq_printf(m, "non-ready MDTs: %s\n",
                                   buf ? buf : "unknown (not enough RAM)");
                        seq_printf(m, "recovery_start: %lld\n",
-                                  (s64)obd->obd_recovery_start);
+                                  (s64)ktime_get_real_seconds() -
+                                  (ktime_get_seconds() -
+                                   obd->obd_recovery_start));
                        seq_printf(m, "time_waited: %lld\n",
-                                  (s64)(ktime_get_real_seconds() -
+                                  (s64)(ktime_get_seconds() -
                                         obd->obd_recovery_start));
                }
 
@@ -702,17 +774,18 @@ int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data)
        }
 
        seq_printf(m, "RECOVERING\n");
-       seq_printf(m, "recovery_start: %lld\n", (s64)obd->obd_recovery_start);
+       seq_printf(m, "recovery_start: %lld\n", (s64)ktime_get_real_seconds() -
+                  (ktime_get_seconds() - obd->obd_recovery_start));
        seq_printf(m, "time_remaining: %lld\n",
-                  ktime_get_real_seconds() >=
+                  ktime_get_seconds() >=
                   obd->obd_recovery_start +
                   obd->obd_recovery_timeout ? 0 :
                   (s64)(obd->obd_recovery_start +
                         obd->obd_recovery_timeout -
-                        ktime_get_real_seconds()));
+                        ktime_get_seconds()));
        seq_printf(m, "connected_clients: %d/%d\n",
                   atomic_read(&obd->obd_connected_clients),
-                  obd->obd_max_recoverable_clients);
+                  atomic_read(&obd->obd_max_recoverable_clients));
        /* Number of clients that have completed recovery */
        seq_printf(m, "req_replay_clients: %d\n",
                   atomic_read(&obd->obd_req_replay_clients));
@@ -732,27 +805,25 @@ out:
 }
 EXPORT_SYMBOL(lprocfs_recovery_status_seq_show);
 
-int lprocfs_ir_factor_seq_show(struct seq_file *m, void *data)
+ssize_t ir_factor_show(struct kobject *kobj, struct attribute *attr,
+                      char *buf)
 {
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
 
-       LASSERT(obd != NULL);
-       seq_printf(m, "%d\n", obd->obd_recovery_ir_factor);
-       return 0;
+       return scnprintf(buf, PAGE_SIZE, "%d\n", obd->obd_recovery_ir_factor);
 }
-EXPORT_SYMBOL(lprocfs_ir_factor_seq_show);
+EXPORT_SYMBOL(ir_factor_show);
 
-ssize_t
-lprocfs_ir_factor_seq_write(struct file *file, const char __user *buffer,
-                           size_t count, loff_t *off)
+ssize_t ir_factor_store(struct kobject *kobj, struct attribute *attr,
+                       const char *buffer, size_t count)
 {
-       struct seq_file *m = file->private_data;
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
        int val;
        int rc;
 
-       LASSERT(obd != NULL);
-       rc = kstrtoint_from_user(buffer, count, 10, &val);
+       rc = kstrtoint(buffer, 10, &val);
        if (rc)
                return rc;
 
@@ -762,7 +833,7 @@ lprocfs_ir_factor_seq_write(struct file *file, const char __user *buffer,
        obd->obd_recovery_ir_factor = val;
        return count;
 }
-EXPORT_SYMBOL(lprocfs_ir_factor_seq_write);
+EXPORT_SYMBOL(ir_factor_store);
 
 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data)
 {
@@ -793,76 +864,72 @@ lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
 }
 EXPORT_SYMBOL(lprocfs_checksum_dump_seq_write);
 
-int lprocfs_recovery_time_soft_seq_show(struct seq_file *m, void *data)
+ssize_t recovery_time_soft_show(struct kobject *kobj, struct attribute *attr,
+                               char *buf)
 {
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
 
-       LASSERT(obd != NULL);
-       seq_printf(m, "%llu\n", obd->obd_recovery_timeout);
-       return 0;
+       return scnprintf(buf, PAGE_SIZE, "%d\n", obd->obd_recovery_timeout);
 }
-EXPORT_SYMBOL(lprocfs_recovery_time_soft_seq_show);
+EXPORT_SYMBOL(recovery_time_soft_show);
 
-ssize_t
-lprocfs_recovery_time_soft_seq_write(struct file *file,
-                                    const char __user *buffer,
-                                    size_t count, loff_t *off)
+ssize_t recovery_time_soft_store(struct kobject *kobj,
+                                struct attribute *attr,
+                                const char *buffer, size_t count)
 {
-       struct seq_file *m = file->private_data;
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
        unsigned int val;
        int rc;
 
-       LASSERT(obd != NULL);
-       rc = kstrtouint_from_user(buffer, count, 0, &val);
+       rc = kstrtouint(buffer, 0, &val);
        if (rc)
                return rc;
 
        obd->obd_recovery_timeout = val;
        return count;
 }
-EXPORT_SYMBOL(lprocfs_recovery_time_soft_seq_write);
+EXPORT_SYMBOL(recovery_time_soft_store);
 
-int lprocfs_recovery_time_hard_seq_show(struct seq_file *m, void *data)
+ssize_t recovery_time_hard_show(struct kobject *kobj, struct attribute *attr,
+                               char *buf)
 {
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
 
-       LASSERT(obd != NULL);
-       seq_printf(m, "%lld\n", obd->obd_recovery_time_hard);
-       return 0;
+       return scnprintf(buf, PAGE_SIZE, "%d\n", obd->obd_recovery_time_hard);
 }
-EXPORT_SYMBOL(lprocfs_recovery_time_hard_seq_show);
+EXPORT_SYMBOL(recovery_time_hard_show);
 
-ssize_t
-lprocfs_recovery_time_hard_seq_write(struct file *file,
-                                    const char __user *buffer,
-                                    size_t count, loff_t *off)
+ssize_t recovery_time_hard_store(struct kobject *kobj,
+                                struct attribute *attr,
+                                const char *buffer, size_t count)
 {
-       struct seq_file *m = file->private_data;
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
        unsigned int val;
        int rc;
 
-       LASSERT(obd != NULL);
-       rc = kstrtouint_from_user(buffer, count, 0, &val);
+       rc = kstrtouint(buffer, 0, &val);
        if (rc)
                return rc;
 
        obd->obd_recovery_time_hard = val;
        return count;
 }
-EXPORT_SYMBOL(lprocfs_recovery_time_hard_seq_write);
+EXPORT_SYMBOL(recovery_time_hard_store);
 
-int lprocfs_target_instance_seq_show(struct seq_file *m, void *data)
+ssize_t instance_show(struct kobject *kobj, struct attribute *attr,
+                     char *buf)
 {
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
        struct obd_device_target *target = &obd->u.obt;
 
-       LASSERT(obd != NULL);
        LASSERT(target->obt_magic == OBT_MAGIC);
-       seq_printf(m, "%u\n", obd->u.obt.obt_instance);
-       return 0;
+       return scnprintf(buf, PAGE_SIZE, "%u\n", obd->u.obt.obt_instance);
 }
-EXPORT_SYMBOL(lprocfs_target_instance_seq_show);
+EXPORT_SYMBOL(instance_show);
 
 #endif /* CONFIG_PROC_FS*/