[systemd-devel] [PATCH v2 1/7] domain: add kdbus_domain_user_assign_id() to assign IDs to domain users
Djalal Harouni
tixxdz at opendz.org
Wed Jul 30 13:11:52 PDT 2014
Signed-off-by: Djalal Harouni <tixxdz at opendz.org>
---
domain.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/domain.c b/domain.c
index c4912fa..af9d986 100644
--- a/domain.c
+++ b/domain.c
@@ -419,6 +419,39 @@ int kdbus_domain_make_user(struct kdbus_cmd_make *cmd, char **name)
}
/**
+ * kdbus_domain_user_assign_id() - allocate ID and assign in it to the
+ * domain user
+ * @domain: The domain of the user
+ * @user The kdbus_domain_user object of the user
+ *
+ * Returns 0 if ID in [0, INT_MAX] is successfully assigned to the
+ * domain user. Negative errno on failure.
+ *
+ * The user index is used in arrays for accounting user quota in
+ * receiver queues.
+ *
+ * Caller must have the domain lock held and must ensure that the
+ * domain was not disconnected.
+ */
+static int kdbus_domain_user_assign_id(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, 0, 0, GFP_KERNEL);
+ if (ret < 0)
+ return ret;
+
+ user->idr = ret;
+
+ 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