[Devel] [PATCH 08/15] fs/fuse kio: implement requests statistics info

Pavel Butsykin pbutsykin at virtuozzo.com
Fri May 17 16:20:41 MSK 2019


This statistic shows information about all inflight kio requests.
Made by analogy with .vstorage.info/requests statistics of user-mod client.

example:
READ             13       0            0/0     0     Success          /fio_test/randasyncread_jobs24_4k.1.0
READ             4        0            0/0     0     Success          /fio_test/randasyncread_jobs24_4k.0.0

Signed-off-by: Pavel Butsykin <pbutsykin at virtuozzo.com>
---
 fs/fuse/kio/pcs/fuse_stat.c | 82 +++++++++++++++++++++++++++++++++++++++++++++
 fs/fuse/kio/pcs/fuse_stat.h |  1 +
 2 files changed, 83 insertions(+)

diff --git a/fs/fuse/kio/pcs/fuse_stat.c b/fs/fuse/kio/pcs/fuse_stat.c
index aa8e70fc9fd6..1b3af5137d14 100644
--- a/fs/fuse/kio/pcs/fuse_stat.c
+++ b/fs/fuse/kio/pcs/fuse_stat.c
@@ -8,6 +8,25 @@
 extern struct super_block *fuse_control_sb;
 
 
+static const char *fuse_kio_op_name(unsigned opcode)
+{
+	switch (opcode) {
+		case FUSE_READ:
+			return "READ";
+		case FUSE_WRITE:
+			return "WRITE";
+		case FUSE_FSYNC:
+			return "FSYNC";
+		case FUSE_FLUSH:
+			return "FLUSH";
+		case FUSE_FALLOCATE:
+			return "FALLOCATE";
+		default:
+			break;
+	}
+	return "UNKNOWN";
+}
+
 static inline void fuse_val_stat_update(struct fuse_val_stat *s, u64 val)
 {
 	if (!s->events)
@@ -65,6 +84,64 @@ static inline unsigned long long fuse_val_cnt_events(struct fuse_val_cnt const*
 #define CNT_TOTAL(c)  fuse_val_cnt_total(&(c))
 #define CNT_EVENTS(c) fuse_val_cnt_events(&(c))
 
+
+static void fuse_kio_stat_req_itr(struct fuse_file *ff, struct fuse_req *req,
+				  void *ctx)
+{
+	struct seq_file *m = ctx;
+	struct pcs_fuse_req *r = pcs_req_from_fuse(req);
+	struct pcs_int_request *ireq = &r->exec.ireq;
+
+	seq_printf(m, "%-16s ", fuse_kio_op_name(req->in.h.opcode));
+	seq_printf(m, "%-8llu %-8llu ", ktime_to_ms(ktime_sub(ktime_get(), ireq->ts)), req->in.h.unique);
+	seq_printf(m, "%5u/%-5u %-5u ", 0, atomic_read(&r->exec.ctl.retry_cnt), r->exec.ctl.last_err.value);
+	seq_printf(m, "%-16s ", pcs_strerror(r->exec.ctl.last_err.value));
+	seq_dentry(m, ff->ff_dentry, "");
+	seq_putc(m, '\n');
+}
+
+static int pcs_fuse_requests_show(struct seq_file *m, void *v)
+{
+	struct inode *inode = m->private;
+	struct pcs_fuse_stat *stat;
+	struct fuse_conn *fc;
+
+	if (!inode)
+		return 0;
+
+	mutex_lock(&fuse_mutex);
+	stat = inode->i_private;
+	if (!stat) {
+		mutex_unlock(&fuse_mutex);
+		return 0;
+	}
+
+	seq_printf(m, "# type duration(msec)     id      stage/retry  errno status           path\n");
+
+	fc = container_of(stat, struct pcs_fuse_cluster, cc.stat)->fc;
+	if (fc) {
+		spin_lock(&fc->lock);
+		pcs_kio_req_list(fc, fuse_kio_stat_req_itr, m);
+		spin_unlock(&fc->lock);
+	}
+	mutex_unlock(&fuse_mutex);
+
+	return 0;
+}
+
+static int pcs_fuse_requests_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, pcs_fuse_requests_show, inode);
+}
+
+static const struct file_operations pcs_fuse_requests_ops = {
+	.owner   = THIS_MODULE,
+	.open    = pcs_fuse_requests_open,
+	.read    = seq_read,
+	.llseek	 = seq_lseek,
+	.release = single_release,
+};
+
 static int pcs_fuse_iostat_show(struct seq_file *m, void *v)
 {
 	struct inode *inode = m->private;
@@ -237,6 +314,9 @@ void pcs_fuse_stat_init(struct pcs_fuse_stat *stat)
 					   S_IFREG | S_IRUSR, 1, NULL,
 					   &pcs_fuse_iostat_ops, stat);
 
+	stat->requests = fuse_kio_add_dentry(stat->kio_stat, fc, "requests",
+					     S_IFREG | S_IRUSR, 1, NULL,
+					     &pcs_fuse_requests_ops, stat);
 out:
 	mutex_unlock(&fuse_mutex);
 }
@@ -250,6 +330,8 @@ void pcs_fuse_stat_fini(struct pcs_fuse_stat *stat)
 	if (fuse_control_sb) {
 		if (stat->iostat)
 			fuse_kio_rm_dentry(stat->iostat);
+		if (stat->requests)
+			fuse_kio_rm_dentry(stat->requests);
 		fuse_kio_rm_dentry(stat->kio_stat);
 	}
 	mutex_unlock(&fuse_mutex);
diff --git a/fs/fuse/kio/pcs/fuse_stat.h b/fs/fuse/kio/pcs/fuse_stat.h
index d25a4c2c4bd7..a6f3a7abe456 100644
--- a/fs/fuse/kio/pcs/fuse_stat.h
+++ b/fs/fuse/kio/pcs/fuse_stat.h
@@ -29,6 +29,7 @@ struct pcs_fuse_stat {
 
 	struct dentry *kio_stat;
 	struct dentry *iostat;
+	struct dentry *requests;
 };
 
 void pcs_fuse_stat_init(struct pcs_fuse_stat *stat);
-- 
2.15.1



More information about the Devel mailing list