[Devel] [PATCH RHEL7 COMMIT] fs/fuse kio: create sysfs stat directory

Konstantin Khorenko khorenko at virtuozzo.com
Tue May 21 18:47:41 MSK 2019


The commit is pushed to "branch-rh7-3.10.0-957.12.2.vz7.96.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.12.2.vz7.96.1
------>
commit 517b9b03f85cd31cfc4ff4e148b23fb52d49995e
Author: Pavel Butsykin <pbutsykin at virtuozzo.com>
Date:   Tue May 21 18:47:39 2019 +0300

    fs/fuse kio: create sysfs stat directory
    
    This patch implements the interfaces for initialize/finalize kio stat subsystem
    and adds the creation of stat directory. The sysfs directory will be created
    separately for each point.
    
    Signed-off-by: Pavel Butsykin <pbutsykin at virtuozzo.com>
    
    =====================
    Patchset description:
    
    Statistics for vstorage kernel fast-path
    
    Vstorage provides plenty of statistics information via 'vstorage -c cl mnt-top',
    but when it comes kernel fast-path, it doesn't work. All because mnt-top
    command collects information from .vstorage.info directory, where vstorage-mount
    provides a lot of different statistical information in the form of files, but
    it was not implemented for for fast-path.
    
    This patch-set is aimed to implementation of the support of some statistics
    inforamtion files from .vstorage.info:
      cs_stats
      fstat
      fstat_lat
      iostat
      requests
    Which will be located at "/sys/fs/fuse/connections/*mnt_id*/kio_stat/". This
    will be enough to maintain vstorage mnt-top command for fast-path mount points.
    
    https://pmc.acronis.com/browse/VSTOR-20979
    
    Pavel Butsykin (15):
      fs/fuse: add conn_ctl to fuse_conn struct
      fs/fuse kio: create sysfs stat directory
      fs/fuse kio: implement iostat
      fs/fuse kio: make common interface pcs_kio_file_list() for listing kio files
      fs/fuse kio: make common interface pcs_kio_req_list() for listing kio reqs
      fs/fuse kio: add retry counter for kio requests
      fs/fuse kio: implement pcs_strerror()
      fs/fuse kio: implement requests statistics
      fs/fuse kio: implement fstat statistics info
      fs/fuse kio: implement fstat_lat statistics info
      fs/fuse kio: remove useless pcs_cs initialization
      fs/fuse kio: implement cs statistics accounting
      fs/fuse kio: convert rpc state id to string
      fs/fuse kio: implement cs_stats statistics info
      fs/fuse kio: add locked cs_get_avg_in_flight()
---
 fs/fuse/Makefile                   |  3 +-
 fs/fuse/control.c                  |  3 +-
 fs/fuse/inode.c                    |  1 +
 fs/fuse/kio/pcs/fuse_stat.c        | 83 ++++++++++++++++++++++++++++++++++++++
 fs/fuse/kio/pcs/fuse_stat.h        | 11 +++++
 fs/fuse/kio/pcs/pcs_cluster_core.c |  3 ++
 fs/fuse/kio/pcs/pcs_req.h          |  2 +
 7 files changed, 104 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile
index 3eb06648da2c..87f655c596e6 100644
--- a/fs/fuse/Makefile
+++ b/fs/fuse/Makefile
@@ -24,6 +24,7 @@ fuse_kio_pcs-objs := kio/pcs/pcs_fuse_kdirect.o \
 	kio/pcs/pcs_cluster.o \
 	kio/pcs/pcs_cluster_core.o \
 	kio/pcs/pcs_cs.o \
-	kio/pcs/fuse_io.o
+	kio/pcs/fuse_io.o \
+	kio/pcs/fuse_stat.o
 
 fuse-objs := dev.o dir.o file.o inode.o control.o
diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index 5ea8ab2165cf..e9734d597419 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.c
@@ -18,7 +18,8 @@
  * This is non-NULL when the single instance of the control filesystem
  * exists.  Protected by fuse_mutex
  */
-static struct super_block *fuse_control_sb;
+struct super_block *fuse_control_sb;
+EXPORT_SYMBOL_GPL(fuse_control_sb);
 
 static struct fuse_conn *fuse_ctl_file_conn_get(struct file *file)
 {
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 25f6e0ceac37..ff3fbc0a779b 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -31,6 +31,7 @@ static struct kmem_cache *fuse_inode_cachep;
 static LIST_HEAD(fuse_kios_list);
 struct list_head fuse_conn_list;
 DEFINE_MUTEX(fuse_mutex);
+EXPORT_SYMBOL_GPL(fuse_mutex);
 
 static int fuse_ve_odirect;
 
diff --git a/fs/fuse/kio/pcs/fuse_stat.c b/fs/fuse/kio/pcs/fuse_stat.c
new file mode 100644
index 000000000000..da8428ebe600
--- /dev/null
+++ b/fs/fuse/kio/pcs/fuse_stat.c
@@ -0,0 +1,83 @@
+#include <net/sock.h>
+#include <linux/types.h>
+
+#include "fuse_stat.h"
+#include "pcs_cluster.h"
+
+extern struct super_block *fuse_control_sb;
+
+static struct dentry *fuse_kio_add_dentry(struct dentry *parent,
+					  struct fuse_conn *fc,
+					  const char *name,
+					  int mode, int nlink,
+					  const struct inode_operations *iop,
+					  const struct file_operations *fop,
+					  void *ctx)
+{
+	struct inode *inode;
+	struct dentry *dentry = d_alloc_name(parent, name);
+
+	if (!dentry)
+		return NULL;
+
+	inode = new_inode(fc->sb);
+	if (!inode) {
+		dput(dentry);
+		return NULL;
+	}
+
+	inode->i_ino = get_next_ino();
+	inode->i_mode = mode;
+	inode->i_uid = fc->user_id;
+	inode->i_gid = fc->group_id;
+	inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
+	if (iop)
+		inode->i_op = iop;
+	inode->i_fop = fop;
+	set_nlink(inode, nlink);
+	inode->i_private = ctx;
+	d_add(dentry, inode);
+
+	return dentry;
+}
+
+static void fuse_kio_rm_dentry(struct dentry *dentry)
+{
+	d_inode(dentry)->i_private = NULL;
+	d_drop(dentry);
+	dput(dentry);
+}
+
+void pcs_fuse_stat_init(struct pcs_fuse_stat *stat)
+{
+	struct fuse_conn *fc =
+		container_of(stat, struct pcs_fuse_cluster, cc.stat)->fc;
+
+	mutex_lock(&fuse_mutex);
+	if (!fuse_control_sb)
+		goto out;
+
+	stat->kio_stat = fuse_kio_add_dentry(fc->conn_ctl, fc, "kio_stat",
+					     S_IFDIR | S_IXUSR, 2,
+					     &simple_dir_inode_operations,
+					     &simple_dir_operations, fc);
+	if (!stat->kio_stat) {
+		pr_err("kio: can't create kio stat directory");
+		goto out;
+	}
+
+	/* Stat initialize */
+out:
+	mutex_unlock(&fuse_mutex);
+}
+
+void pcs_fuse_stat_fini(struct pcs_fuse_stat *stat)
+{
+	if (!stat->kio_stat)
+		return;
+
+	mutex_lock(&fuse_mutex);
+	if (fuse_control_sb)
+		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
new file mode 100644
index 000000000000..14687ffd83f2
--- /dev/null
+++ b/fs/fuse/kio/pcs/fuse_stat.h
@@ -0,0 +1,11 @@
+#ifndef _FUSE_STAT_H_
+#define _FUSE_STAT_H_ 1
+
+struct pcs_fuse_stat {
+	struct dentry *kio_stat;
+};
+
+void pcs_fuse_stat_init(struct pcs_fuse_stat *stat);
+void pcs_fuse_stat_fini(struct pcs_fuse_stat *stat);
+
+#endif /* _FUSE_STAT_H_ */
\ No newline at end of file
diff --git a/fs/fuse/kio/pcs/pcs_cluster_core.c b/fs/fuse/kio/pcs/pcs_cluster_core.c
index 053325f94de9..010d6588c99b 100644
--- a/fs/fuse/kio/pcs/pcs_cluster_core.c
+++ b/fs/fuse/kio/pcs/pcs_cluster_core.c
@@ -151,6 +151,8 @@ int pcs_cc_init(struct pcs_cluster_core *cc, struct workqueue_struct *wq,
 	 * pcs_srandomdev(&cc->rng);
 	 */
 
+	pcs_fuse_stat_init(&cc->stat);
+
 	memset(&cc->cfg,   0, sizeof(cc->cfg));
 	memset(&cc->op,	   0, sizeof(cc->op));
 
@@ -176,6 +178,7 @@ void pcs_cc_fini(struct pcs_cluster_core *cc)
 	pcs_csset_fini(&cc->css);
 	pcs_mapset_fini(&cc->maps);
 	pcs_rpc_engine_fini(&cc->eng);
+	pcs_fuse_stat_fini(&cc->stat);
 
 	BUG_ON(!list_empty(&cc->completion_queue));
 	BUG_ON(!list_empty(&cc->work_queue));
diff --git a/fs/fuse/kio/pcs/pcs_req.h b/fs/fuse/kio/pcs/pcs_req.h
index 604402de173d..c32177603130 100644
--- a/fs/fuse/kio/pcs/pcs_req.h
+++ b/fs/fuse/kio/pcs/pcs_req.h
@@ -8,6 +8,7 @@
 #include "pcs_cs_prot.h"
 #include "pcs_rpc.h"
 #include "pcs_cs.h"
+#include "fuse_stat.h"
 
 ///////////////////////////
 
@@ -207,6 +208,7 @@ struct pcs_cluster_core
 ////	struct pcs_ratelimit	rlim;		/* Rate limiter */
 ////	struct pcs_rng		rng;
 	/* <SKIP */
+	struct pcs_fuse_stat	stat;
 
 	struct {
 		struct pcs_clnt_config	def;



More information about the Devel mailing list