kdbus: the driver, original and non-working
[platform/kernel/linux-exynos.git] / ipc / kdbus / domain.h
1 /*
2  * Copyright (C) 2013-2015 Kay Sievers
3  * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4  * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org>
5  * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com>
6  * Copyright (C) 2013-2015 Linux Foundation
7  * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org>
8  *
9  * kdbus is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License as published by the
11  * Free Software Foundation; either version 2.1 of the License, or (at
12  * your option) any later version.
13  */
14
15 #ifndef __KDBUS_DOMAIN_H
16 #define __KDBUS_DOMAIN_H
17
18 #include <linux/fs.h>
19 #include <linux/idr.h>
20 #include <linux/kref.h>
21 #include <linux/user_namespace.h>
22
23 #include "node.h"
24
25 /**
26  * struct kdbus_domain - domain for buses
27  * @node:               Underlying API node
28  * @lock:               Domain data lock
29  * @last_id:            Last used object id
30  * @user_idr:           Set of all users indexed by UID
31  * @user_ida:           Set of all users to compute small indices
32  * @user_namespace:     User namespace, pinned at creation time
33  * @dentry:             Root dentry of VFS mount (don't use outside of kdbusfs)
34  */
35 struct kdbus_domain {
36         struct kdbus_node node;
37         struct mutex lock;
38         atomic64_t last_id;
39         struct idr user_idr;
40         struct ida user_ida;
41         struct user_namespace *user_namespace;
42         struct dentry *dentry;
43 };
44
45 /**
46  * struct kdbus_user - resource accounting for users
47  * @kref:               Reference counter
48  * @domain:             Domain of the user
49  * @id:                 Index of this user
50  * @uid:                UID of the user
51  * @buses:              Number of buses the user has created
52  * @connections:        Number of connections the user has created
53  */
54 struct kdbus_user {
55         struct kref kref;
56         struct kdbus_domain *domain;
57         unsigned int id;
58         kuid_t uid;
59         atomic_t buses;
60         atomic_t connections;
61 };
62
63 #define kdbus_domain_from_node(_node) \
64         container_of((_node), struct kdbus_domain, node)
65
66 struct kdbus_domain *kdbus_domain_new(unsigned int access);
67 struct kdbus_domain *kdbus_domain_ref(struct kdbus_domain *domain);
68 struct kdbus_domain *kdbus_domain_unref(struct kdbus_domain *domain);
69 int kdbus_domain_populate(struct kdbus_domain *domain, unsigned int access);
70
71 #define KDBUS_USER_KERNEL_ID 0 /* ID 0 is reserved for kernel accounting */
72
73 struct kdbus_user *kdbus_user_lookup(struct kdbus_domain *domain, kuid_t uid);
74 struct kdbus_user *kdbus_user_ref(struct kdbus_user *u);
75 struct kdbus_user *kdbus_user_unref(struct kdbus_user *u);
76
77 #endif