connection: add function kdbus_conn_find_peer()
authorDjalal Harouni <tixxdz@opendz.org>
Mon, 31 Mar 2014 00:43:03 +0000 (01:43 +0100)
committerKay Sievers <kay@vrfy.org>
Mon, 31 Mar 2014 12:30:55 +0000 (14:30 +0200)
Use this function to find a connection peer with a given id.

The returned connection is on the same bus of the source connection
and it is ref'ed.

This allows to reduce code duplication and will make it easy to
read code and differentiate between messages that have a source
connection and other kernel generated messages.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
connection.c
connection.h

index e01e0ab0637977f86413a16f062248f2b702ffc2..97fde972bbd9967ed80db22633affabfef373be3 100644 (file)
@@ -1568,6 +1568,30 @@ bool kdbus_conn_active(const struct kdbus_conn *conn)
        return !conn->disconnected;
 }
 
+/**
+ * kdbus_conn_find_peer() - find a connection peer with a given id
+ * @conn_src:          The source connection
+ * @id:                 The 64-bit connection id of the destination
+ *
+ * Finds a connection peer with a given id. The returned connection
+ * is on the same bus of the source connection and it is ref'ed.
+ * Returns NULL if the peer can't be found.
+ *
+ * On success caller must ensure to unref the returned connection.
+ */
+struct kdbus_conn *kdbus_conn_find_peer(struct kdbus_conn *conn_src,
+                                       u64 id)
+{
+       struct kdbus_conn *conn_dst;
+       struct kdbus_bus *bus = conn_src->bus;
+
+       mutex_lock(&bus->lock);
+       conn_dst = kdbus_bus_find_conn_by_id(bus, id);
+       mutex_unlock(&bus->lock);
+
+       return conn_dst;
+}
+
 static void __kdbus_conn_free(struct kref *kref)
 {
        struct kdbus_conn *conn = container_of(kref, struct kdbus_conn, kref);
index 43a9b6191d36552ef1af6d63c9e7f6eff0310ed0..a91ea4c5b432c47eef566f243dc6d1f90647d91c 100644 (file)
@@ -106,6 +106,8 @@ struct kdbus_conn *kdbus_conn_ref(struct kdbus_conn *conn);
 struct kdbus_conn *kdbus_conn_unref(struct kdbus_conn *conn);
 int kdbus_conn_disconnect(struct kdbus_conn *conn, bool ensure_queue_empty);
 bool kdbus_conn_active(const struct kdbus_conn *conn);
+struct kdbus_conn *kdbus_conn_find_peer(struct kdbus_conn *conn_src,
+                                       u64 id);
 
 int kdbus_cmd_msg_recv(struct kdbus_conn *conn,
                       struct kdbus_cmd_recv *recv);