kernel/kdbus-provide-helper-to-collect-metadata.patch
2015-07-08 10:30:06 -04:00

196 lines
6.1 KiB
Diff

From: David Herrmann <dh.herrmann@gmail.com>
Date: Tue, 26 May 2015 09:59:02 +0200
Subject: [PATCH] kdbus: provide helper to collect metadata
Provide a new helper kdbus_kmsg_collect_metadata() which implements the
common task of collecting proc- and conn-metadata on a kmsg.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Acked-by: Daniel Mack <daniel@zonque.org>
---
ipc/kdbus/bus.c | 24 +++---------------------
ipc/kdbus/connection.c | 35 ++++-------------------------------
ipc/kdbus/message.c | 24 ++++++++++++++++++++++++
ipc/kdbus/message.h | 2 ++
4 files changed, 33 insertions(+), 52 deletions(-)
diff --git a/ipc/kdbus/bus.c b/ipc/kdbus/bus.c
index 9d0679eb59f6..9a0ecbc9df2f 100644
--- a/ipc/kdbus/bus.c
+++ b/ipc/kdbus/bus.c
@@ -285,8 +285,6 @@ void kdbus_bus_broadcast(struct kdbus_bus *bus,
continue;
if (conn_src) {
- u64 attach_flags;
-
/*
* Anyone can send broadcasts, as they have no
* destination. But a receiver needs TALK access to
@@ -295,19 +293,12 @@ void kdbus_bus_broadcast(struct kdbus_bus *bus,
if (!kdbus_conn_policy_talk(conn_dst, NULL, conn_src))
continue;
- attach_flags = kdbus_meta_calc_attach_flags(conn_src,
- conn_dst);
-
/*
* Keep sending messages even if we cannot acquire the
* requested metadata. It's up to the receiver to drop
* messages that lack expected metadata.
*/
- if (!conn_src->faked_meta)
- kdbus_meta_proc_collect(kmsg->proc_meta,
- attach_flags);
- kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, conn_src,
- attach_flags);
+ kdbus_kmsg_collect_metadata(kmsg, conn_src, conn_dst);
} else {
/*
* Check if there is a policy db that prevents the
@@ -359,17 +350,8 @@ void kdbus_bus_eavesdrop(struct kdbus_bus *bus,
* availability, anyway. So it's still better to send messages
* that lack data, than to skip it entirely.
*/
- if (conn_src) {
- u64 attach_flags;
-
- attach_flags = kdbus_meta_calc_attach_flags(conn_src,
- conn_dst);
- if (!conn_src->faked_meta)
- kdbus_meta_proc_collect(kmsg->proc_meta,
- attach_flags);
- kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, conn_src,
- attach_flags);
- }
+ if (conn_src)
+ kdbus_kmsg_collect_metadata(kmsg, conn_src, conn_dst);
ret = kdbus_conn_entry_insert(conn_src, conn_dst, kmsg, NULL);
if (ret < 0)
diff --git a/ipc/kdbus/connection.c b/ipc/kdbus/connection.c
index 272b991f36f4..cbfbf3847c24 100644
--- a/ipc/kdbus/connection.c
+++ b/ipc/kdbus/connection.c
@@ -1098,7 +1098,6 @@ static int kdbus_conn_reply(struct kdbus_conn *src, struct kdbus_kmsg *kmsg)
struct kdbus_reply *reply, *wake = NULL;
struct kdbus_conn *dst = NULL;
struct kdbus_bus *bus = src->ep->bus;
- u64 attach;
int ret;
if (WARN_ON(kmsg->msg.dst_id == KDBUS_DST_ID_BROADCAST) ||
@@ -1131,15 +1130,7 @@ static int kdbus_conn_reply(struct kdbus_conn *src, struct kdbus_kmsg *kmsg)
/* attach metadata */
- attach = kdbus_meta_calc_attach_flags(src, dst);
-
- if (!src->faked_meta) {
- ret = kdbus_meta_proc_collect(kmsg->proc_meta, attach);
- if (ret < 0)
- goto exit;
- }
-
- ret = kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, src, attach);
+ ret = kdbus_kmsg_collect_metadata(kmsg, src, dst);
if (ret < 0)
goto exit;
@@ -1167,7 +1158,6 @@ static struct kdbus_reply *kdbus_conn_call(struct kdbus_conn *src,
struct kdbus_reply *wait = NULL;
struct kdbus_conn *dst = NULL;
struct kdbus_bus *bus = src->ep->bus;
- u64 attach;
int ret;
if (WARN_ON(kmsg->msg.dst_id == KDBUS_DST_ID_BROADCAST) ||
@@ -1218,15 +1208,7 @@ static struct kdbus_reply *kdbus_conn_call(struct kdbus_conn *src,
/* attach metadata */
- attach = kdbus_meta_calc_attach_flags(src, dst);
-
- if (!src->faked_meta) {
- ret = kdbus_meta_proc_collect(kmsg->proc_meta, attach);
- if (ret < 0)
- goto exit;
- }
-
- ret = kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, src, attach);
+ ret = kdbus_kmsg_collect_metadata(kmsg, src, dst);
if (ret < 0)
goto exit;
@@ -1257,7 +1239,6 @@ static int kdbus_conn_unicast(struct kdbus_conn *src, struct kdbus_kmsg *kmsg)
struct kdbus_conn *dst = NULL;
struct kdbus_bus *bus = src->ep->bus;
bool is_signal = (kmsg->msg.flags & KDBUS_MSG_SIGNAL);
- u64 attach;
int ret = 0;
if (WARN_ON(kmsg->msg.dst_id == KDBUS_DST_ID_BROADCAST) ||
@@ -1296,16 +1277,8 @@ static int kdbus_conn_unicast(struct kdbus_conn *src, struct kdbus_kmsg *kmsg)
/* attach metadata */
- attach = kdbus_meta_calc_attach_flags(src, dst);
-
- if (!src->faked_meta) {
- ret = kdbus_meta_proc_collect(kmsg->proc_meta, attach);
- if (ret < 0 && !is_signal)
- goto exit;
- }
-
- ret = kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, src, attach);
- if (ret < 0 && !is_signal)
+ ret = kdbus_kmsg_collect_metadata(kmsg, src, dst);
+ if (ret < 0)
goto exit;
/* send message */
diff --git a/ipc/kdbus/message.c b/ipc/kdbus/message.c
index 80960756a329..066e816dfdea 100644
--- a/ipc/kdbus/message.c
+++ b/ipc/kdbus/message.c
@@ -614,3 +614,27 @@ exit_free:
kdbus_kmsg_free(m);
return ERR_PTR(ret);
}
+
+/**
+ * kdbus_kmsg_collect_metadata() - collect metadata
+ * @kmsg: message to collect metadata on
+ * @src: source connection of message
+ * @dst: destination connection of message
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int kdbus_kmsg_collect_metadata(struct kdbus_kmsg *kmsg, struct kdbus_conn *src,
+ struct kdbus_conn *dst)
+{
+ u64 attach;
+ int ret;
+
+ attach = kdbus_meta_calc_attach_flags(src, dst);
+ if (!src->faked_meta) {
+ ret = kdbus_meta_proc_collect(kmsg->proc_meta, attach);
+ if (ret < 0)
+ return ret;
+ }
+
+ return kdbus_meta_conn_collect(kmsg->conn_meta, kmsg, src, attach);
+}
diff --git a/ipc/kdbus/message.h b/ipc/kdbus/message.h
index af4775850235..cdaa65c4e6ae 100644
--- a/ipc/kdbus/message.h
+++ b/ipc/kdbus/message.h
@@ -129,5 +129,7 @@ struct kdbus_kmsg *kdbus_kmsg_new(struct kdbus_bus *bus, size_t extra_size);
struct kdbus_kmsg *kdbus_kmsg_new_from_cmd(struct kdbus_conn *conn,
struct kdbus_cmd_send *cmd_send);
void kdbus_kmsg_free(struct kdbus_kmsg *kmsg);
+int kdbus_kmsg_collect_metadata(struct kdbus_kmsg *kmsg, struct kdbus_conn *src,
+ struct kdbus_conn *dst);
#endif