[Devel,RHEL7,COMMIT] connector: per-ve init and fini helpers introduced

Submitted by Konstantin Khorenko on Aug. 31, 2017, 2:40 p.m.

Details

Message ID 201708311440.v7VEeTKE014479@finist_ce7.work
State New
Series "proc connector: containerize on per-VE basis"
Headers show

Commit Message

Konstantin Khorenko Aug. 31, 2017, 2:40 p.m.
The commit is pushed to "branch-rh7-3.10.0-514.26.1.vz7.35.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.26.1.vz7.35.5
------>
commit 37c6a11416ce88290d381482e0b8bf568dc59e97
Author: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Date:   Thu Aug 31 17:40:29 2017 +0300

    connector: per-ve init and fini helpers introduced
    
    This helpers will be used later to initialize per-container connector.
    
    Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
    Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 drivers/connector/connector.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index 407fe52..f5484b2 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -259,15 +259,20 @@  static const struct file_operations cn_file_ops = {
 	.release = single_release
 };
 
-static int cn_init(void)
+static int cn_init_ve(struct ve_struct *ve)
 {
 	struct cn_dev *dev = get_cdev(get_ve0());
 	struct netlink_kernel_cfg cfg = {
 		.groups	= CN_NETLINK_USERS + 0xf,
 		.input	= cn_rx_skb,
 	};
+	struct net *net = ve->ve_netns;
+
+	ve->cn = kzalloc(sizeof(*ve->cn), GFP_KERNEL);
+	if (!ve->cn)
+		return -ENOMEM;
 
-	dev->nls = netlink_kernel_create(&init_net, NETLINK_CONNECTOR, &cfg);
+	dev->nls = netlink_kernel_create(net, NETLINK_CONNECTOR, &cfg);
 	if (!dev->nls)
 		return -EIO;
 
@@ -279,21 +284,35 @@  static int cn_init(void)
 
 	cn_already_initialized = 1;
 
-	proc_create("connector", S_IRUGO, init_net.proc_net, &cn_file_ops);
+	proc_create("connector", S_IRUGO, net->proc_net, &cn_file_ops);
 
 	return 0;
 }
 
-static void cn_fini(void)
+static void cn_fini_ve(struct ve_struct *ve)
 {
-	struct cn_dev *dev = get_cdev(get_ve0());
+	struct cn_dev *dev = get_cdev(ve);
+	struct net *net = ve->ve_netns;
 
 	cn_already_initialized = 0;
 
-	remove_proc_entry("connector", init_net.proc_net);
+	remove_proc_entry("connector", net->proc_net);
 
 	cn_queue_free_dev(dev->cbdev);
 	netlink_kernel_release(dev->nls);
+
+	kfree(ve->cn);
+	ve->cn = NULL;
+}
+
+static int cn_init(void)
+{
+	return cn_init_ve(get_ve0());
+}
+
+static void cn_fini(void)
+{
+	return cn_fini_ve(get_ve0());
 }
 
 subsys_initcall(cn_init);