Skip to contentSkip to conversation

kdbus: name registry cleanup patches

PATCH New Daniel Mack 1 participant 5 messages Aug 7, 2015 Kselftest

lore
Share & tools
lore
#0 lore raw

cover kdbus: name registry cleanup patches

Hi Greg,

Here are some patches for kdbus-next David and I prepared:

* The first one cleans up the name registry code and brings the name queuing logic in sync with what the DBus spec requires. We were off in some small details concerning flags updates of already queued names.

* The second one adds two more return flags in the name queuing logic, so userspace has better ways of knowing what effect a name acquisition call had.

* Number three is a small cleanup that makes sure we never return negative return codes from ioctls if we modified any internal state. This is a rule all other command dispatchers follow as well.

* The last one adds more selftests for the name registry, covering the newly added flags.

None of these patches is critical, and everything has been running well on our machines for a while.

Thanks,
Daniel

Daniel Mack (1):
kdbus: selftests: add more name registry tests

David Herrmann (3):
kdbus: restructure name-registry to follow dbus-spec
kdbus: inform caller about exact updates on NAME_ACQUIRE
kdbus: never return <0 from ioctls if we changed state

 include/uapi/linux/kdbus.h                 |   4 +
 ipc/kdbus/connection.c                     |  53 +-
 ipc/kdbus/connection.h                     |   9 +-
 ipc/kdbus/metadata.c                       |  21 +-
 ipc/kdbus/names.c                          | 762 ++++++++++++++++-------------
 ipc/kdbus/names.h                          |  55 ++-
 tools/testing/selftests/kdbus/kdbus-test.c |   6 +
 tools/testing/selftests/kdbus/kdbus-test.h |   1 +
 tools/testing/selftests/kdbus/test-chat.c  |   6 +-
 tools/testing/selftests/kdbus/test-names.c | 140 ++++--
 10 files changed, 633 insertions(+), 424 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH 1/4 kdbus: restructure name-registry to follow dbus-spec

From: David Herrmann <[email protected]>

The DBus Specification [1] is pretty clear about how name-acquisition, queueing and releasing must work. Most of it's peculiarities nobody relies on, but we better comply to them to at least allow proper backwards compatibility via bus-proxy.

In particular, this means we don't implement the following details:
* NameAcquire must update the stored flags of a name-owner if it is already queued or owns the name.
* Only KDBUS_NAME_QUEUE and KDBUS_NAME_ALLOW_REPLACEMENT are stored flags of name owners. Everything else is only used during command execution and/or as reply flags.
* NameAcquire on an already queued owner must not change the position in the queue.
* KDBUS_NAME_REPLACE_EXISTING for already queued ownes *jumps* the queue if the primary owner has ALLOW_REPLACEMENT set.
* If a primary owner is replaced by someone else, they must retain their stored name-flags.
* If a primary owner is replaced by someone else, they must be placed at second position in the queue, if queuing is requested.

In dbus-daemon the name-owner queue is a single queue. That is, the primary owner of a name is not special, instead, it simply is the first queued owner. This explains most of the peculiarities of the NameAcquire behavior and makes it much easier to implement them.

Hence, this patch rewrites the name-registry to follow the lead:
* *ANY* name owner is now represented by a "struct kdbus_name_owner" objects, regardless whether they're queued, activators or primary.
* All name-ownerships are linked in a *single* list on each connection. This gets rid of redundant conn->queued_names_list and conn->activator_of.
* Limits and control functions always apply to 'struct kdbus_name_owner' now, instead of 'struct kdbus_name_entry'. This solves some issues where name-ownership was properly limited, but name-queueing was not.
* Activators are now correctly updated regarding KDBUS_NAME_IN_QUEUE depending whether they own the name or not.
* owner->flags is now kept clean. Only real requested flags are stored, any operation-flags are cleared.
* Special handling of activators is kept to a minimum. This really allows us to treat them more like real queued owners that allow replacement, than something special.

With this in place, we follow the dbus-spec regarding behavior of name-acquisition perfectly. Hence, the bus-proxy can properly implement backwards-compatibility to dbus1.

[1] http://dbus.freedesktop.org/doc/dbus-specification.html

---
 ipc/kdbus/connection.c |  53 ++--
 ipc/kdbus/connection.h |   9 +-
 ipc/kdbus/metadata.c   |  21 +-
 ipc/kdbus/names.c      | 749 +++++++++++++++++++++++++++----------------------
 ipc/kdbus/names.h      |  55 +++-
 5 files changed, 496 insertions(+), 391 deletions(-)
ipc/kdbus/connection.c +28 -25
index aa3296e..ef63d65 100644
@@ -129,9 +129,7 @@ static struct kdbus_conn *kdbus_conn_new(struct kdbus_ep *ep,
 #endif
 	mutex_init(&conn->lock);
 	INIT_LIST_HEAD(&conn->names_list);
-	INIT_LIST_HEAD(&conn->names_queue_list);
 	INIT_LIST_HEAD(&conn->reply_list);
-	atomic_set(&conn->name_count, 0);
 	atomic_set(&conn->request_count, 0);
 	atomic_set(&conn->lost_count, 0);
 	INIT_DELAYED_WORK(&conn->work, kdbus_reply_list_scan_work);
@@ -284,7 +282,6 @@ static void __kdbus_conn_free(struct kref *kref)
 	WARN_ON(delayed_work_pending(&conn->work));
 	WARN_ON(!list_empty(&conn->queue.msg_list));
 	WARN_ON(!list_empty(&conn->names_list));
-	WARN_ON(!list_empty(&conn->names_queue_list));
 	WARN_ON(!list_empty(&conn->reply_list));
 
 	if (conn->user) {
@@ -618,12 +615,13 @@ int kdbus_conn_disconnect(struct kdbus_conn *conn, bool ensure_queue_empty)
  */
 bool kdbus_conn_has_name(struct kdbus_conn *conn, const char *name)
 {
-	struct kdbus_name_entry *e;
+	struct kdbus_name_owner *owner;
 
 	lockdep_assert_held(&conn->ep->bus->name_registry->rwlock);
 
-	list_for_each_entry(e, &conn->names_list, conn_entry)
-		if (strcmp(e->name, name) == 0)
+	list_for_each_entry(owner, &conn->names_list, conn_entry)
+		if (!(owner->flags & KDBUS_NAME_IN_QUEUE) &&
+		    !strcmp(name, owner->name->name))
 			return true;
 
 	return false;
@@ -1052,6 +1050,7 @@ static int kdbus_pin_dst(struct kdbus_bus *bus,
 			 struct kdbus_conn **out_dst)
 {
 	const struct kdbus_msg *msg = staging->msg;
+	struct kdbus_name_owner *owner = NULL;
 	struct kdbus_name_entry *name = NULL;
 	struct kdbus_conn *dst = NULL;
 	int ret;
@@ -1070,7 +1069,9 @@ static int kdbus_pin_dst(struct kdbus_bus *bus,
 	} else {
 		name = kdbus_name_lookup_unlocked(bus->name_registry,
 						  staging->dst_name);
-		if (!name)
+		if (name)
+			owner = kdbus_name_get_owner(name);
+		if (!owner)
 			return -ESRCH;
 
 		/*
@@ -1082,19 +1083,14 @@ static int kdbus_pin_dst(struct kdbus_bus *bus,
 		 * owns the given name.
 		 */
 		if (msg->dst_id != KDBUS_DST_ID_NAME &&
-		    msg->dst_id != name->conn->id)
+		    msg->dst_id != owner->conn->id)
 			return -EREMCHG;
 
-		if (!name->conn && name->activator)
-			dst = kdbus_conn_ref(name->activator);
-		else
-			dst = kdbus_conn_ref(name->conn);
-
 		if ((msg->flags & KDBUS_MSG_NO_AUTO_START) &&
-		    kdbus_conn_is_activator(dst)) {
-			ret = -EADDRNOTAVAIL;
-			goto error;
-		}
+		    kdbus_conn_is_activator(owner->conn))
+			return -EADDRNOTAVAIL;
+
+		dst = kdbus_conn_ref(owner->conn);
 	}
 
 	*out_name = name;
@@ -1383,7 +1379,7 @@ static bool kdbus_conn_policy_query_all(struct kdbus_conn *conn,
 					struct kdbus_conn *whom,
 					unsigned int access)
 {
-	struct kdbus_name_entry *ne;
+	struct kdbus_name_owner *owner;
 	bool pass = false;
 	int res;
 
@@ -1392,10 +1388,14 @@ static bool kdbus_conn_policy_query_all(struct kdbus_conn *conn,
 	down_read(&db->entries_rwlock);
 	mutex_lock(&whom->lock);
 
-	list_for_each_entry(ne, &whom->names_list, conn_entry) {
-		res = kdbus_policy_query_unlocked(db, conn_creds ? : conn->cred,
-						  ne->name,
-						  kdbus_strhash(ne->name));
+	list_for_each_entry(owner, &whom->names_list, conn_entry) {
+		if (owner->flags & KDBUS_NAME_IN_QUEUE)
+			continue;
+
+		res = kdbus_policy_query_unlocked(db,
+					conn_creds ? : conn->cred,
+					owner->name->name,
+					kdbus_strhash(owner->name->name));
 		if (res >= (int)access) {
 			pass = true;
 			break;
@@ -1713,6 +1713,7 @@ int kdbus_cmd_conn_info(struct kdbus_conn *conn, void __user *argp)
 	struct kdbus_meta_conn *conn_meta = NULL;
 	struct kdbus_pool_slice *slice = NULL;
 	struct kdbus_name_entry *entry = NULL;
+	struct kdbus_name_owner *owner = NULL;
 	struct kdbus_conn *owner_conn = NULL;
 	struct kdbus_item *meta_items = NULL;
 	struct kdbus_info info = {};
@@ -1749,15 +1750,17 @@ int kdbus_cmd_conn_info(struct kdbus_conn *conn, void __user *argp)
 
 	if (name) {
 		entry = kdbus_name_lookup_unlocked(bus->name_registry, name);
-		if (!entry || !entry->conn ||
+		if (entry)
+			owner = kdbus_name_get_owner(entry);
+		if (!owner ||
 		    !kdbus_conn_policy_see_name(conn, current_cred(), name) ||
-		    (cmd->id != 0 && entry->conn->id != cmd->id)) {
+		    (cmd->id != 0 && owner->conn->id != cmd->id)) {
 			/* pretend a name doesn't exist if you cannot see it */
 			ret = -ESRCH;
 			goto exit;
 		}
 
-		owner_conn = kdbus_conn_ref(entry->conn);
+		owner_conn = kdbus_conn_ref(owner->conn);
 	} else if (cmd->id > 0) {
 		owner_conn = kdbus_bus_find_conn_by_id(bus, cmd->id);
 		if (!owner_conn || !kdbus_conn_policy_see(conn, current_cred(),
ipc/kdbus/connection.h +3 -6
index 8e0180a..1ad0820 100644
@@ -30,6 +30,7 @@
 					 KDBUS_HELLO_POLICY_HOLDER | \
 					 KDBUS_HELLO_MONITOR)
 
+struct kdbus_name_entry;
 struct kdbus_quota;
 struct kdbus_staging;
 
@@ -61,7 +62,6 @@ struct kdbus_staging;
  * @cred:		The credentials of the connection at creation time
  * @pid:		Pid at creation time
  * @root_path:		Root path at creation time
- * @name_count:		Number of owned well-known names
  * @request_count:	Number of pending requests issued by this
  *			connection that are waiting for replies from
  *			other peers
@@ -70,9 +70,8 @@ struct kdbus_staging;
  * @queue:		The message queue associated with this connection
  * @quota:		Array of per-user quota indexed by user->id
  * @n_quota:		Number of elements in quota array
- * @activator_of:	Well-known name entry this connection acts as an
  * @names_list:		List of well-known names
- * @names_queue_list:	Well-known names this connection waits for
+ * @name_count:		Number of owned well-known names
  * @privileged:		Whether this connection is privileged on the domain
  * @owner:		Owned by the same user as the bus owner
  */
@@ -102,7 +101,6 @@ struct kdbus_conn {
 	const struct cred *cred;
 	struct pid *pid;
 	struct path root_path;
-	atomic_t name_count;
 	atomic_t request_count;
 	atomic_t lost_count;
 	wait_queue_head_t wait;
@@ -112,9 +110,8 @@ struct kdbus_conn {
 	unsigned int n_quota;
 
 	/* protected by registry->rwlock */
-	struct kdbus_name_entry *activator_of;
 	struct list_head names_list;
-	struct list_head names_queue_list;
+	unsigned int name_count;
 
 	bool privileged:1;
 	bool owner:1;
ipc/kdbus/metadata.c +13 -8
index d4973a9..71ca475 100644
@@ -603,7 +603,7 @@ static void kdbus_meta_conn_collect_timestamp(struct kdbus_meta_conn *mc,
 static int kdbus_meta_conn_collect_names(struct kdbus_meta_conn *mc,
 					 struct kdbus_conn *conn)
 {
-	const struct kdbus_name_entry *e;
+	const struct kdbus_name_owner *owner;
 	struct kdbus_item *item;
 	size_t slen, size;
 
@@ -611,9 +611,11 @@ static int kdbus_meta_conn_collect_names(struct kdbus_meta_conn *mc,
 
 	size = 0;
 	/* open-code length calculation to avoid final padding */
-	list_for_each_entry(e, &conn->names_list, conn_entry)
-		size = KDBUS_ALIGN8(size) + KDBUS_ITEM_HEADER_SIZE +
-			sizeof(struct kdbus_name) + strlen(e->name) + 1;
+	list_for_each_entry(owner, &conn->names_list, conn_entry)
+		if (!(owner->flags & KDBUS_NAME_IN_QUEUE))
+			size = KDBUS_ALIGN8(size) + KDBUS_ITEM_HEADER_SIZE +
+				sizeof(struct kdbus_name) +
+				strlen(owner->name->name) + 1;
 
 	if (!size)
 		return 0;
@@ -626,12 +628,15 @@ static int kdbus_meta_conn_collect_names(struct kdbus_meta_conn *mc,
 	mc->owned_names_items = item;
 	mc->owned_names_size = size;
 
-	list_for_each_entry(e, &conn->names_list, conn_entry) {
-		slen = strlen(e->name) + 1;
+	list_for_each_entry(owner, &conn->names_list, conn_entry) {
+		if (owner->flags & KDBUS_NAME_IN_QUEUE)
+			continue;
+
+		slen = strlen(owner->name->name) + 1;
 		kdbus_item_set(item, KDBUS_ITEM_OWNED_NAME, NULL,
 			       sizeof(struct kdbus_name) + slen);
-		item->name.flags = e->flags;
-		memcpy(item->name.name, e->name, slen);
+		item->name.flags = owner->flags;
+		memcpy(item->name.name, owner->name->name, slen);
 		item = KDBUS_ITEM_NEXT(item);
 	}
 
ipc/kdbus/names.c +409 -340

922 lines not on this page · raw message

ipc/kdbus/names.h +43 -12

80 lines not on this page · raw message

Signature · 1 line
2.4.3
#2 lore raw

PATCH 2/4 kdbus: inform caller about exact updates on NAME_ACQUIRE

In reply to Daniel Mack

From: David Herrmann <[email protected]>

This adds two new return flags for KDBUS_CMD_NAME_ACQUIRE:

* The KDBUS_NAME_PRIMARY flag is set for a name if, and only if, the connection is currently the primary owner of a name. It is thus the negation of KDBUS_NAME_IN_QUEUE, but is required to distinguish the case from the situation where the connection is neither queued nor the primary owner of a name.
Additionally, this flag is included in name listings and events.

* The KDBUS_NAME_ACQUIRED flag is exclusively used as return flag for KDBUS_CMD_NAME_ACQUIRE to let the caller know whether _this_ exact call actually queued the connection on the name. If the flag is not set, the connection was either already queued and only the flags were updated, or the connection is not queued at all.

This information was previously available to the caller via error-codes from KDBUS_CMD_NAME_ACQUIRE. However, in some situations we actually modify kernel state but return an error. This is considered bad style and we really need to avoid this. Hence, these two new flags allow us to avoid returning errors, but still inform the caller about the exact conditions of the execution.

---
 include/uapi/linux/kdbus.h |  4 ++++
 ipc/kdbus/names.c          | 38 ++++++++++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 10 deletions(-)
include/uapi/linux/kdbus.h +4 -0
index ecffc6b..4fc44cb 100644
@@ -854,6 +854,8 @@ enum kdbus_make_flags {
  * @KDBUS_NAME_QUEUE:			Name should be queued if busy
  * @KDBUS_NAME_IN_QUEUE:		Name is queued
  * @KDBUS_NAME_ACTIVATOR:		Name is owned by a activator connection
+ * @KDBUS_NAME_PRIMARY:			Primary owner of the name
+ * @KDBUS_NAME_ACQUIRED:		Name was acquired/queued _now_
  */
 enum kdbus_name_flags {
 	KDBUS_NAME_REPLACE_EXISTING	= 1ULL <<  0,
@@ -861,6 +863,8 @@ enum kdbus_name_flags {
 	KDBUS_NAME_QUEUE		= 1ULL <<  2,
 	KDBUS_NAME_IN_QUEUE		= 1ULL <<  3,
 	KDBUS_NAME_ACTIVATOR		= 1ULL <<  4,
+	KDBUS_NAME_PRIMARY		= 1ULL <<  5,
+	KDBUS_NAME_ACQUIRED		= 1ULL <<  6,
 };
 
 /**
ipc/kdbus/names.c +28 -10
index 7a6e61c..a47ee54 100644
@@ -211,7 +211,8 @@ kdbus_name_lookup_unlocked(struct kdbus_name_registry *reg, const char *name)
 	return kdbus_name_entry_find(reg, kdbus_strhash(name), name);
 }
 
-static int kdbus_name_become_activator(struct kdbus_name_owner *owner)
+static int kdbus_name_become_activator(struct kdbus_name_owner *owner,
+				       u64 *return_flags)
 {
 	if (kdbus_name_owner_is_used(owner))
 		return -EALREADY;
@@ -221,23 +222,30 @@ static int kdbus_name_become_activator(struct kdbus_name_owner *owner)
 	owner->name->activator = owner;
 	owner->flags |= KDBUS_NAME_ACTIVATOR;
 
-	if (kdbus_name_entry_first(owner->name))
+	if (kdbus_name_entry_first(owner->name)) {
 		owner->flags |= KDBUS_NAME_IN_QUEUE;
-	else
+	} else {
+		owner->flags |= KDBUS_NAME_PRIMARY;
 		kdbus_notify_name_change(owner->conn->ep->bus,
 					 KDBUS_ITEM_NAME_ADD,
 					 0, owner->conn->id,
 					 0, owner->flags,
 					 owner->name->name);
+	}
+
+	if (return_flags)
+		*return_flags = owner->flags | KDBUS_NAME_ACQUIRED;
 
 	return 0;
 }
 
-static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags)
+static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags,
+			     u64 *return_flags)
 {
 	struct kdbus_name_owner *primary, *activator;
 	struct kdbus_name_entry *name;
 	struct kdbus_bus *bus;
+	u64 nflags = 0;
 	int ret = 0;
 
 	name = owner->name;
@@ -259,6 +267,8 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags)
 		 */
 
 		list_add(&owner->name_entry, &name->queue);
+		owner->flags |= KDBUS_NAME_PRIMARY;
+		nflags |= KDBUS_NAME_ACQUIRED;
 
 		/* move messages to new owner on activation */
 		if (activator) {
@@ -268,6 +278,7 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags)
 					activator->conn->id, owner->conn->id,
 					activator->flags, owner->flags,
 					name->name);
+			activator->flags &= ~KDBUS_NAME_PRIMARY;
 			activator->flags |= KDBUS_NAME_IN_QUEUE;
 		} else {
 			kdbus_notify_name_change(bus, KDBUS_ITEM_NAME_ADD,
@@ -283,6 +294,7 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags)
 		 * For compatibility, we have to return -EALREADY.
 		 */
 
+		owner->flags |= KDBUS_NAME_PRIMARY;
 		ret = -EALREADY;
 
 	} else if ((primary->flags & KDBUS_NAME_ALLOW_REPLACEMENT) &&
@@ -295,6 +307,8 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags)
 
 		list_del_init(&owner->name_entry);
 		list_add(&owner->name_entry, &name->queue);
+		owner->flags |= KDBUS_NAME_PRIMARY;
+		nflags |= KDBUS_NAME_ACQUIRED;
 
 		kdbus_notify_name_change(bus, KDBUS_ITEM_NAME_CHANGE,
 					 primary->conn->id, owner->conn->id,
@@ -303,6 +317,7 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags)
 
 		/* requeue old primary, or drop if queueing not wanted */
 		if (primary->flags & KDBUS_NAME_QUEUE) {
+			primary->flags &= ~KDBUS_NAME_PRIMARY;
 			primary->flags |= KDBUS_NAME_IN_QUEUE;
 		} else {
 			list_del_init(&primary->name_entry);
@@ -317,8 +332,10 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags)
 		 */
 
 		owner->flags |= KDBUS_NAME_IN_QUEUE;
-		if (!kdbus_name_owner_is_used(owner))
+		if (!kdbus_name_owner_is_used(owner)) {
 			list_add_tail(&owner->name_entry, &name->queue);
+			nflags |= KDBUS_NAME_ACQUIRED;
+		}
 	} else if (kdbus_name_owner_is_used(owner)) {
 		/*
 		 * Already queued on name, but re-queueing was not requested.
@@ -337,6 +354,9 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags)
 		ret = -EEXIST;
 	}
 
+	if (return_flags)
+		*return_flags = owner->flags | nflags;
+
 	return ret;
 }
 
@@ -392,15 +412,12 @@ int kdbus_name_acquire(struct kdbus_name_registry *reg,
 	}
 
 	if (flags & KDBUS_NAME_ACTIVATOR)
-		ret = kdbus_name_become_activator(owner);
+		ret = kdbus_name_become_activator(owner, return_flags);
 	else
-		ret = kdbus_name_update(owner, flags);
+		ret = kdbus_name_update(owner, flags, return_flags);
 	if (ret < 0)
 		goto exit;
 
-	if (return_flags)
-		*return_flags = owner->flags;
-
 exit:
 	if (owner && !kdbus_name_owner_is_used(owner))
 		kdbus_name_owner_free(owner);
@@ -431,6 +448,7 @@ static void kdbus_name_release_unlocked(struct kdbus_name_owner *owner)
 		if (next) {
 			/* hand to next in queue */
 			next->flags &= ~KDBUS_NAME_IN_QUEUE;
+			next->flags |= KDBUS_NAME_PRIMARY;
 			if (next == name->activator)
 				kdbus_conn_move_messages(next->conn,
 							 owner->conn,
Signature · 1 line
2.4.3
#3 lore raw

PATCH 3/4 kdbus: never return <0 from ioctls if we changed state

In reply to Daniel Mack

From: David Herrmann <[email protected]>

If an ioctl() returns <0, user-space should be safe to assume it had no effect on the state of any object. This might not be always possible, but in kdbus we adhered to this rule. But there's one exception, namely KDBUS_CMD_NAME_ACQUIRE. This call used to fail with -EALREADY if we owned a name and tried to acquire it again. However, regardless whether the name was already owned, the name-flags are updated according to the newly provided flags. Hence, we change the state of name-ownership, but might still return an error.

This patch changes behavior and now returns 0 in those cases. User-space still gets the same information (via return_flags), but will no longer be told that the call failed. The tests reflect that and simply check for KDBUS_NAME_ACQUIRED in 'return_flags'.

---
 ipc/kdbus/names.c                          | 3 ---
 tools/testing/selftests/kdbus/test-chat.c  | 6 ++++--
 tools/testing/selftests/kdbus/test-names.c | 4 ----
 3 files changed, 4 insertions(+), 9 deletions(-)
ipc/kdbus/names.c +0 -3
index a47ee54..bf44ca3 100644
@@ -291,11 +291,9 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags,
 		/*
 		 * Already the primary owner of the name, flags were already
 		 * updated. Nothing to do.
-		 * For compatibility, we have to return -EALREADY.
 		 */
 
 		owner->flags |= KDBUS_NAME_PRIMARY;
-		ret = -EALREADY;
 
 	} else if ((primary->flags & KDBUS_NAME_ALLOW_REPLACEMENT) &&
 		   (flags & KDBUS_NAME_REPLACE_EXISTING)) {
@@ -344,7 +342,6 @@ static int kdbus_name_update(struct kdbus_name_owner *owner, u64 flags,
 		 */
 
 		list_del_init(&owner->name_entry);
-		ret = -EEXIST;
 	} else {
 		/*
 		 * Name is already claimed and queueing is not requested.
tools/testing/selftests/kdbus/test-chat.c +4 -2
index 71a92d8..41e5b53 100644
@@ -41,8 +41,10 @@ int kdbus_test_chat(struct kdbus_test_env *env)
 	ret = kdbus_name_acquire(conn_a, "foo.bar.double", NULL);
 	ASSERT_RETURN(ret == 0);
 
-	ret = kdbus_name_acquire(conn_a, "foo.bar.double", NULL);
-	ASSERT_RETURN(ret == -EALREADY);
+	flags = 0;
+	ret = kdbus_name_acquire(conn_a, "foo.bar.double", &flags);
+	ASSERT_RETURN(ret == 0);
+	ASSERT_RETURN(!(flags & KDBUS_NAME_ACQUIRED));
 
 	ret = kdbus_name_release(conn_a, "foo.bar.double");
 	ASSERT_RETURN(ret == 0);
tools/testing/selftests/kdbus/test-names.c +0 -4
index fd4ac5a..9217465 100644
@@ -143,10 +143,6 @@ int kdbus_test_name_conflict(struct kdbus_test_env *env)
 	ret = conn_is_name_owner(env->conn, name);
 	ASSERT_RETURN(ret == 0);
 
-	/* check that we can't acquire it again from the 1st connection */
-	ret = kdbus_name_acquire(env->conn, name, NULL);
-	ASSERT_RETURN(ret == -EALREADY);
-
 	/* check that we also can't acquire it again from the 2nd connection */
 	ret = kdbus_name_acquire(conn, name, NULL);
 	ASSERT_RETURN(ret == -EEXIST);
Signature · 1 line
2.4.3
#4 lore raw

PATCH 4/4 kdbus: selftests: add more name registry tests

In reply to Daniel Mack

Add some more code for testing the name registry state. This can now be used to track the state of queued names and per-name queing settings.

Also add new tests to check the newly added KDBUS_NAME_PRIMARY and KDBUS_NAME_ACQUIRED flags and name takeovers.

---
 tools/testing/selftests/kdbus/kdbus-test.c |   6 ++
 tools/testing/selftests/kdbus/kdbus-test.h |   1 +
 tools/testing/selftests/kdbus/test-names.c | 133 +++++++++++++++++++++++------
 3 files changed, 112 insertions(+), 28 deletions(-)
tools/testing/selftests/kdbus/kdbus-test.c +6 -0
index db732e5..db57381 100644
@@ -118,6 +118,12 @@ static const struct kdbus_test tests[] = {
 		.flags	= TEST_CREATE_BUS | TEST_CREATE_CONN,
 	},
 	{
+		.name	= "name-takeover",
+		.desc	= "takeover of names",
+		.func	= kdbus_test_name_takeover,
+		.flags	= TEST_CREATE_BUS | TEST_CREATE_CONN,
+	},
+	{
 		.name	= "message-basic",
 		.desc	= "basic message handling",
 		.func	= kdbus_test_message_basic,
tools/testing/selftests/kdbus/kdbus-test.h +1 -0
index a5c6ae8..ee937f9 100644
@@ -72,6 +72,7 @@ int kdbus_test_monitor(struct kdbus_test_env *env);
 int kdbus_test_name_basic(struct kdbus_test_env *env);
 int kdbus_test_name_conflict(struct kdbus_test_env *env);
 int kdbus_test_name_queue(struct kdbus_test_env *env);
+int kdbus_test_name_takeover(struct kdbus_test_env *env);
 int kdbus_test_policy(struct kdbus_test_env *env);
 int kdbus_test_policy_ns(struct kdbus_test_env *env);
 int kdbus_test_policy_priv(struct kdbus_test_env *env);
tools/testing/selftests/kdbus/test-names.c +105 -28

207 lines not on this page · raw message

Signature · 1 line
2.4.3