[Devel,v2,06/27] connector: per-ve helpers intoruduced

Submitted by Stanislav Kinsburskiy on Aug. 17, 2017, 1:59 p.m.

Details

Message ID 20170817135932.23505.84071.stgit@localhost.localdomain
State New
Series "proc connector: containerize on per-VE basis"
Headers show

Commit Message

Stanislav Kinsburskiy Aug. 17, 2017, 1:59 p.m.
This is precursor patch.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
---
 drivers/connector/connector.c |   48 ++++++++++++++++++++++++++++-------------
 include/linux/connector.h     |    7 ++++++
 2 files changed, 40 insertions(+), 15 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index bc2308a..bba667d 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -67,14 +67,14 @@  static struct cn_dev *get_cdev(struct ve_struct *ve)
 	return &ve->cn->cdev;
 }
 
-int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask)
+int cn_netlink_send_ve(struct ve_struct *ve, struct cn_msg *msg, u32 __group, gfp_t gfp_mask)
 {
 	struct cn_callback_entry *__cbq;
 	unsigned int size;
 	struct sk_buff *skb;
 	struct nlmsghdr *nlh;
 	struct cn_msg *data;
-	struct cn_dev *dev = get_cdev(get_ve0());
+	struct cn_dev *dev = get_cdev(ve);
 	u32 group = 0;
 	int found = 0;
 
@@ -119,6 +119,11 @@  int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask)
 
 	return netlink_broadcast(dev->nls, skb, 0, group, gfp_mask);
 }
+
+int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask)
+{
+	return cn_netlink_send_ve(get_ve0(), msg, __group, gfp_mask);
+}
 EXPORT_SYMBOL_GPL(cn_netlink_send);
 
 /*
@@ -183,18 +188,13 @@  static void cn_rx_skb(struct sk_buff *__skb)
 	}
 }
 
-/*
- * Callback add routing - adds callback with given ID and name.
- * If there is registered callback with the same ID it will not be added.
- *
- * May sleep.
- */
-int cn_add_callback(struct cb_id *id, const char *name,
-		    void (*callback)(struct cn_msg *,
-				     struct netlink_skb_parms *))
+int cn_add_callback_ve(struct ve_struct *ve,
+		       struct cb_id *id, const char *name,
+		       void (*callback)(struct cn_msg *,
+					struct netlink_skb_parms *))
 {
 	int err;
-	struct cn_dev *dev = get_cdev(get_ve0());
+	struct cn_dev *dev = get_cdev(ve);
 
 	if (!cn_already_initialized)
 		return -EAGAIN;
@@ -205,8 +205,28 @@  int cn_add_callback(struct cb_id *id, const char *name,
 
 	return 0;
 }
+
+/*
+ * Callback add routing - adds callback with given ID and name.
+ * If there is registered callback with the same ID it will not be added.
+ *
+ * May sleep.
+ */
+int cn_add_callback(struct cb_id *id, const char *name,
+		    void (*callback)(struct cn_msg *,
+				     struct netlink_skb_parms *))
+{
+	return cn_add_callback_ve(get_ve0(), id, name, callback);
+}
 EXPORT_SYMBOL_GPL(cn_add_callback);
 
+void cn_del_callback_ve(struct ve_struct *ve, struct cb_id *id)
+{
+	struct cn_dev *dev = get_cdev(ve);
+
+	cn_queue_del_callback(dev->cbdev, id);
+}
+
 /*
  * Callback remove routing - removes callback
  * with given ID.
@@ -217,9 +237,7 @@  EXPORT_SYMBOL_GPL(cn_add_callback);
  */
 void cn_del_callback(struct cb_id *id)
 {
-	struct cn_dev *dev = get_cdev(get_ve0());
-
-	cn_queue_del_callback(dev->cbdev, id);
+	cn_del_callback_ve(get_ve0(), id);
 }
 EXPORT_SYMBOL_GPL(cn_del_callback);
 
diff --git a/include/linux/connector.h b/include/linux/connector.h
index 9e05e28..8b44bf0 100644
--- a/include/linux/connector.h
+++ b/include/linux/connector.h
@@ -76,6 +76,13 @@  struct cn_private {
 
 };
 
+int cn_add_callback_ve(struct ve_struct *ve,
+		       struct cb_id *id, const char *name,
+		       void (*callback)(struct cn_msg *,
+					struct netlink_skb_parms *));
+void cn_del_callback_ve(struct ve_struct *ve, struct cb_id *id);
+int cn_netlink_send_ve(struct ve_struct *ve, struct cn_msg *, u32, gfp_t);
+
 int cn_add_callback(struct cb_id *id, const char *name,
 		    void (*callback)(struct cn_msg *, struct netlink_skb_parms *));
 void cn_del_callback(struct cb_id *);