[systemd-devel] [PATCH 1/7] domain: add __kdbus_domain_user_account() to account and link users

Djalal Harouni tixxdz at opendz.org
Wed Jul 23 14:19:05 PDT 2014


Add __kdbus_domain_user_account() to account and link users into a
domain.

Signed-off-by: Djalal Harouni <tixxdz at opendz.org>
---
 domain.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/domain.c b/domain.c
index c4912fa..a321f31 100644
--- a/domain.c
+++ b/domain.c
@@ -419,6 +419,38 @@ int kdbus_domain_make_user(struct kdbus_cmd_make *cmd, char **name)
 }
 
 /**
+ * __kdbus_domain_user_account() - account a kdbus_domain_user object
+ *				   into the specified domain
+ * @domain:		The domain of the user
+ * @user		The kdbus_domain_user object of the user
+ *
+ * Returns 0 on success, -ENOMEM on failure.
+ *
+ * Caller must have the domain lock held and must ensure that the
+ * domain was not disconnected.
+ */
+int __kdbus_domain_user_account(struct kdbus_domain *domain,
+				struct kdbus_domain_user *user)
+{
+	int ret;
+
+	/*
+	 * Allocate the smallest possible index for this user; used
+	 * in arrays for accounting user quota in receiver queues.
+	 */
+	ret = idr_alloc(&domain->user_idr, user, 1, 0, GFP_KERNEL);
+	if (ret < 0)
+		return ret;
+
+	user->idr = ret;
+
+	/* UID hash map */
+	hash_add(domain->user_hash, &user->hentry, __kuid_val(user->uid));
+
+	return 0;
+}
+
+/**
  * kdbus_domain_user_find_or_new() - get a kdbus_domain_user object in a domain
  * @domain:		The domain
  * @uid:		The uid of the user; INVALID_UID for an anonymous
-- 
1.9.3



More information about the systemd-devel mailing list