1 /*
2     Domain communications for Xen Store Daemon.
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 
19 #ifndef _XENSTORED_DOMAIN_H
20 #define _XENSTORED_DOMAIN_H
21 
22 void handle_event(void);
23 
24 /* domid, mfn, eventchn, path */
25 int do_introduce(struct connection *conn, struct buffered_data *in);
26 
27 /* domid */
28 int do_is_domain_introduced(struct connection *conn, struct buffered_data *in);
29 
30 /* domid */
31 int do_release(struct connection *conn, struct buffered_data *in);
32 
33 /* domid */
34 int do_resume(struct connection *conn, struct buffered_data *in);
35 
36 /* domid, target */
37 int do_set_target(struct connection *conn, struct buffered_data *in);
38 
39 /* domid */
40 int do_get_domain_path(struct connection *conn, struct buffered_data *in);
41 
42 /* Allow guest to reset all watches */
43 int do_reset_watches(struct connection *conn, struct buffered_data *in);
44 
45 void domain_init(void);
46 
47 /* Returns the implicit path of a connection (only domains have this) */
48 const char *get_implicit_path(const struct connection *conn);
49 
50 /* Read existing connection information from store. */
51 void restore_existing_connections(void);
52 
53 /* Can connection attached to domain read/write. */
54 bool domain_can_read(struct connection *conn);
55 bool domain_can_write(struct connection *conn);
56 
57 bool domain_is_unprivileged(struct connection *conn);
58 
59 /* Remove node permissions for no longer existing domains. */
60 int domain_adjust_node_perms(struct node *node);
61 
62 /* Quota manipulation */
63 void domain_entry_inc(struct connection *conn, struct node *);
64 void domain_entry_dec(struct connection *conn, struct node *);
65 int domain_entry_fix(unsigned int domid, int num, bool update);
66 int domain_entry(struct connection *conn);
67 void domain_watch_inc(struct connection *conn);
68 void domain_watch_dec(struct connection *conn);
69 int domain_watch(struct connection *conn);
70 
71 /* Special node permission handling. */
72 int set_perms_special(struct connection *conn, const char *name,
73 		      struct node_perms *perms);
74 bool check_perms_special(const char *name, struct connection *conn);
75 
76 /* Write rate limiting */
77 
78 #define WRL_FACTOR   1000 /* for fixed-point arithmetic */
79 #define WRL_RATE      200
80 #define WRL_DBURST     10
81 #define WRL_GBURST   1000
82 #define WRL_NEWDOMS     5
83 #define WRL_LOGEVERY  120 /* seconds */
84 
85 struct wrl_timestampt {
86 	time_t sec;
87 	int msec;
88 };
89 
90 extern long wrl_ntransactions;
91 
92 void wrl_gettime_now(struct wrl_timestampt *now_ts);
93 void wrl_domain_new(struct domain *domain);
94 void wrl_domain_destroy(struct domain *domain);
95 void wrl_credit_update(struct domain *domain, struct wrl_timestampt now);
96 void wrl_check_timeout(struct domain *domain,
97                        struct wrl_timestampt now,
98                        int *ptimeout);
99 void wrl_log_periodic(struct wrl_timestampt now);
100 void wrl_apply_debit_direct(struct connection *conn);
101 void wrl_apply_debit_trans_commit(struct connection *conn);
102 
103 #endif /* _XENSTORED_DOMAIN_H */
104