domain: add kdbus_domain_user_assign_id() to assign IDs to domain users
authorDjalal Harouni <tixxdz@opendz.org>
Wed, 30 Jul 2014 20:11:52 +0000 (21:11 +0100)
committerKay Sievers <kay@vrfy.org>
Thu, 31 Jul 2014 14:29:51 +0000 (16:29 +0200)
Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
domain.c

index c4912faa9a46f2d1cc0ec27964944ce054c1aa75..af9d9863991b5f03ca3ab376b2c87173872aff42 100644 (file)
--- a/domain.c
+++ b/domain.c
@@ -418,6 +418,39 @@ int kdbus_domain_make_user(struct kdbus_cmd_make *cmd, char **name)
        return 0;
 }
 
+/**
+ * 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