Debian Codegraph @

tools/xenstored/minios.c

raw
1 /*
2 Simple prototype Xen Store Daemon providing simple tree-like database.
3 Copyright (C) 2005 Rusty Russell IBM Corporation
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include <sys/types.h>
19 #include <sys/mman.h>
20 #include <syslog.h>
21 #include "talloc.h"
22 #include "core.h"
23 #include "utils.h"
24 #include <xen/grant_table.h>
25 #include <mini-os/lib.h>
26 #include <mini-os/9pfront.h>
27 #include <mini-os/sched.h>
28 #include <mini-os/xenbus.h>
29 #include <mini-os/xmalloc.h>
30
31 #define P9_STATE_PATH "device/9pfs/0/state"
32
33 static void *p9_device;
34
35 void finish_daemonize(void)
36 {
37 }
38
39 struct connection *add_socket_connection(int fd)
40 {
41 barf("socket based connection without sockets");
42 }
43
44 evtchn_port_t get_xenbus_evtchn(void)
45 {
46 return dom0_event;
47 }
48
49 void *xenbus_map(void)
50 {
51 return xengnttab_map_grant_ref(*xgt_handle, xenbus_master_domid(),
52 GNTTAB_RESERVED_XENSTORE, PROT_READ|PROT_WRITE);
53 }
54
55 void unmap_xenbus(void *interface)
56 {
57 xengnttab_unmap(*xgt_handle, interface, 1);
58 }
59
60 void early_init(bool live_update, bool dofork, const char *pidfile)
61 {
62 stub_domid = get_domid();
63 if (stub_domid == DOMID_INVALID)
64 barf("could not get own domid");
65 }
66
67 void late_init(bool live_update)
68 {
69 }
70
71 void set_special_fds(void)
72 {
73 }
74
75 void handle_special_fds(void)
76 {
77 }
78
79 int get_socket_fd(void)
80 {
81 return -1;
82 }
83
84 void set_socket_fd(int fd)
85 {
86 }
87
88 static void mount_thread(void *p)
89 {
90 xenbus_event_queue events = NULL;
91 char *err;
92 char *dummy;
93
94 err = xenbus_watch_path_token(XBT_NIL, P9_STATE_PATH, "9pfs", &events);
95 if (err) {
96 log("error \"%s\" when setting watch on \"%s\"\n", err,
97 P9_STATE_PATH);
98 free(err);
99 return;
100 }
101
102 for (;;) {
103 xenbus_wait_for_watch(&events);
104
105 /*
106 * We only care for existence of the state node.
107 * State changes are handled in init_9pfront().
108 */
109 err = xenbus_read(XBT_NIL, P9_STATE_PATH, &dummy);
110 if (!err)
111 break;
112 free(err);
113 }
114
115 free(dummy);
116
117 err = xenbus_unwatch_path_token(XBT_NIL, P9_STATE_PATH, "9pfs");
118 if (err) {
119 log("error \"%s\" when unwatching \"%s\", leaking watch\n",
120 err, P9_STATE_PATH);
121 free(err);
122 }
123
124 p9_device = init_9pfront(0, XENSTORE_LIB_DIR);
125
126 /* Start logging if selected. */
127 reopen_log();
128 }
129
130 void mount_9pfs(void)
131 {
132 create_thread("mount-9pfs", mount_thread, NULL);
133 }
134
135 const char *xenstore_rundir(void)
136 {
137 return XENSTORE_LIB_DIR;
138 }