[Devel] [PATCH rh7] venetstat: Add ioctl interface via VE cgroup
Cyrill Gorcunov
gorcunov at virtuozzo.com
Thu Jun 18 09:13:10 PDT 2015
Here we add a special file into ve cgroup named
"venet_acct_ioctl" which would emulate old ioctls.
The write action into this file should pass
struct vz_tc_cg_req as an argument so that
it get unpacked into argument and command
for ioctl call and execute it.
https://jira.sw.ru/browse/PSBM-32277
Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
CC: Andrey Vagin <avagin at virtuozzo.com>
CC: Vladimir Davydov <vdavydov at virtuozzo.com>
CC: Konstantin Khorenko <khorenko at virtuozzo.com>
CC: Pavel Emelyanov <xemul at virtuozzo.com>
---
Guys, take a look please, would such ioctl wrap do a trick
and be suitable for userspace?
include/uapi/linux/vzctl_netstat.h | 5 +++++
kernel/ve/vznetstat/vznetstat.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
Index: linux-pcs7.git/include/uapi/linux/vzctl_netstat.h
===================================================================
--- linux-pcs7.git.orig/include/uapi/linux/vzctl_netstat.h
+++ linux-pcs7.git/include/uapi/linux/vzctl_netstat.h
@@ -16,6 +16,11 @@
typedef unsigned int envid_t;
#endif
+struct vz_tc_cg_req {
+ __u32 cmd;
+ __u64 arg;
+};
+
/*
* Traffic accouting management ioctl
*/
Index: linux-pcs7.git/kernel/ve/vznetstat/vznetstat.c
===================================================================
--- linux-pcs7.git.orig/kernel/ve/vznetstat/vznetstat.c
+++ linux-pcs7.git/kernel/ve/vznetstat/vznetstat.c
@@ -21,6 +21,7 @@
#include <net/ip.h>
#include <linux/in6.h>
#include <linux/module.h>
+#include <linux/cgroup.h>
#include <linux/ve.h>
#include <linux/venet.h>
@@ -974,6 +975,33 @@ static struct file_operations proc_venet
.release = seq_release,
};
+static ssize_t cg_acct_write(struct cgroup *cgrp, struct cftype *cft,
+ struct file *file,
+ const char __user *buf,
+ size_t nbytes, loff_t *ppos)
+{
+ struct vz_tc_cg_req req;
+ int ret;
+
+ if (nbytes != sizeof(req))
+ return -EINVAL;
+
+ if (copy_from_user(&req, buf, sizeof(req)))
+ return -EFAULT;
+
+ ret = venet_acct_ioctl(NULL, req.cmd, req.arg);
+
+ return ret ?: sizeof(req);
+}
+
+static struct cftype ve_cft_stat[] = {
+ {
+ .name = "venet_acct_ioctl",
+ .flags = CFTYPE_NOT_ON_ROOT,
+ .write = cg_acct_write,
+ },
+};
+
/*
* ---------------------------------------------------------------------------
* Initialization
@@ -1002,12 +1030,14 @@ int __init venetstat_init(void)
printk(KERN_WARNING "VENET: can't make venetstat_v6 proc entry\n");
#endif
+ WARN_ON(cgroup_add_cftypes(&ve_subsys, ve_cft_stat));
vzioctl_register(&tc_ioctl_info);
return 0;
}
void __exit venetstat_exit(void)
{
+ WARN_ON(cgroup_rm_cftypes(&ve_subsys, ve_cft_stat));
vzioctl_unregister(&tc_ioctl_info);
venet_acct_destroy_all_stat();
More information about the Devel
mailing list