kdbus: the driver, original and non-working
[platform/kernel/linux-exynos.git] / ipc / kdbus / main.c
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  *
8  * kdbus is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; either version 2.1 of the License, or (at
11  * your option) any later version.
12  */
13
14 #define pr_fmt(fmt)    KBUILD_MODNAME ": " fmt
15 #include <linux/fs.h>
16 #include <linux/init.h>
17 #include <linux/module.h>
18
19 #include "util.h"
20 #include "fs.h"
21 #include "handle.h"
22 #include "metadata.h"
23 #include "node.h"
24
25 /*
26  * This is a simplified outline of the internal kdbus object relations, for
27  * those interested in the inner life of the driver implementation.
28  *
29  * From a mount point's (domain's) perspective:
30  *
31  * struct kdbus_domain
32  *   |» struct kdbus_user *user (many, owned)
33  *   '» struct kdbus_node node (embedded)
34  *       |» struct kdbus_node children (many, referenced)
35  *       |» struct kdbus_node *parent (pinned)
36  *       '» struct kdbus_bus (many, pinned)
37  *           |» struct kdbus_node node (embedded)
38  *           '» struct kdbus_ep (many, pinned)
39  *               |» struct kdbus_node node (embedded)
40  *               |» struct kdbus_bus *bus (pinned)
41  *               |» struct kdbus_conn conn_list (many, pinned)
42  *               |   |» struct kdbus_ep *ep (pinned)
43  *               |   |» struct kdbus_name_entry *activator_of (owned)
44  *               |   |» struct kdbus_match_db *match_db (owned)
45  *               |   |» struct kdbus_meta *meta (owned)
46  *               |   |» struct kdbus_match_db *match_db (owned)
47  *               |   |    '» struct kdbus_match_entry (many, owned)
48  *               |   |
49  *               |   |» struct kdbus_pool *pool (owned)
50  *               |   |    '» struct kdbus_pool_slice *slices (many, owned)
51  *               |   |       '» struct kdbus_pool *pool (pinned)
52  *               |   |
53  *               |   |» struct kdbus_user *user (pinned)
54  *               |   `» struct kdbus_queue_entry entries (many, embedded)
55  *               |        |» struct kdbus_pool_slice *slice (pinned)
56  *               |        |» struct kdbus_conn_reply *reply (owned)
57  *               |        '» struct kdbus_user *user (pinned)
58  *               |
59  *               '» struct kdbus_user *user (pinned)
60  *                   '» struct kdbus_policy_db policy_db (embedded)
61  *                        |» struct kdbus_policy_db_entry (many, owned)
62  *                        |   |» struct kdbus_conn (pinned)
63  *                        |   '» struct kdbus_ep (pinned)
64  *                        |
65  *                        '» struct kdbus_policy_db_cache_entry (many, owned)
66  *                            '» struct kdbus_conn (pinned)
67  *
68  * For the life-time of a file descriptor derived from calling open() on a file
69  * inside the mount point:
70  *
71  * struct kdbus_handle
72  *  |» struct kdbus_meta *meta (owned)
73  *  |» struct kdbus_ep *ep (pinned)
74  *  |» struct kdbus_conn *conn (owned)
75  *  '» struct kdbus_ep *ep (owned)
76  */
77
78 /* kdbus mount-point /sys/fs/kdbus */
79 static struct kobject *kdbus_dir;
80
81 static int __init kdbus_init(void)
82 {
83         int ret;
84
85         kdbus_dir = kobject_create_and_add(KBUILD_MODNAME, fs_kobj);
86         if (!kdbus_dir)
87                 return -ENOMEM;
88
89         ret = kdbus_fs_init();
90         if (ret < 0) {
91                 pr_err("cannot register filesystem: %d\n", ret);
92                 goto exit_dir;
93         }
94
95         pr_info("initialized\n");
96         return 0;
97
98 exit_dir:
99         kobject_put(kdbus_dir);
100         return ret;
101 }
102
103 static void __exit kdbus_exit(void)
104 {
105         kdbus_fs_exit();
106         kobject_put(kdbus_dir);
107         ida_destroy(&kdbus_node_ida);
108 }
109
110 module_init(kdbus_init);
111 module_exit(kdbus_exit);
112 MODULE_LICENSE("GPL");
113 MODULE_DESCRIPTION("D-Bus, powerful, easy to use interprocess communication");
114 MODULE_ALIAS_FS(KBUILD_MODNAME "fs");