| 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 |
/* |
| 23 |
* All accounting data is stored in a per-domain array. |
| 24 |
* Depending on the account item there might be other scopes as well, like e.g. |
| 25 |
* a per transaction array. |
| 26 |
*/ |
| 27 |
enum accitem { |
| 28 |
ACC_NODES, |
| 29 |
ACC_REQ_N, /* Number of elements per request. */ |
| 30 |
ACC_TR_N = ACC_REQ_N, /* Number of elements per transaction. */ |
| 31 |
ACC_CHD_N = ACC_TR_N, /* max(ACC_REQ_N, ACC_TR_N), for changed dom. */ |
| 32 |
ACC_WATCH = ACC_TR_N, |
| 33 |
ACC_OUTST, |
| 34 |
ACC_MEM, |
| 35 |
ACC_TRANS, |
| 36 |
ACC_TRANSNODES, |
| 37 |
ACC_NPERM, |
| 38 |
ACC_PATHLEN, |
| 39 |
ACC_NODESZ, |
| 40 |
ACC_N, /* Number of elements per domain. */ |
| 41 |
}; |
| 42 |
|
| 43 |
struct quota { |
| 44 |
const char *name; |
| 45 |
const char *descr; |
| 46 |
unsigned int val; |
| 47 |
unsigned int max; |
| 48 |
}; |
| 49 |
|
| 50 |
extern struct quota hard_quotas[ACC_N]; |
| 51 |
extern struct quota soft_quotas[ACC_N]; |
| 52 |
|
| 53 |
void handle_event(void); |
| 54 |
|
| 55 |
void check_domains(void); |
| 56 |
|
| 57 |
/* domid, mfn, eventchn, path */ |
| 58 |
int do_introduce(const void *ctx, struct connection *conn, |
| 59 |
struct buffered_data *in); |
| 60 |
|
| 61 |
/* domid */ |
| 62 |
int do_is_domain_introduced(const void *ctx, struct connection *conn, |
| 63 |
struct buffered_data *in); |
| 64 |
|
| 65 |
/* domid */ |
| 66 |
int do_release(const void *ctx, struct connection *conn, |
| 67 |
struct buffered_data *in); |
| 68 |
|
| 69 |
/* domid */ |
| 70 |
int do_resume(const void *ctx, struct connection *conn, |
| 71 |
struct buffered_data *in); |
| 72 |
|
| 73 |
/* domid, target */ |
| 74 |
int do_set_target(const void *ctx, struct connection *conn, |
| 75 |
struct buffered_data *in); |
| 76 |
|
| 77 |
/* domid */ |
| 78 |
int do_get_domain_path(const void *ctx, struct connection *conn, |
| 79 |
struct buffered_data *in); |
| 80 |
|
| 81 |
/* Allow guest to reset all watches */ |
| 82 |
int do_reset_watches(const void *ctx, struct connection *conn, |
| 83 |
struct buffered_data *in); |
| 84 |
|
| 85 |
void domain_early_init(void); |
| 86 |
void domain_init(int evtfd); |
| 87 |
void dom0_init(void); |
| 88 |
void stubdom_init(void); |
| 89 |
void domain_deinit(void); |
| 90 |
void ignore_connection(struct connection *conn, unsigned int err); |
| 91 |
|
| 92 |
/* Returns the implicit path of a connection (only domains have this) */ |
| 93 |
const char *get_implicit_path(const struct connection *conn); |
| 94 |
|
| 95 |
/* |
| 96 |
* Remove node permissions for no longer existing domains. |
| 97 |
* In case of a change of permissions the related array is reallocated in |
| 98 |
* order to avoid a data base change when operating on a node directly |
| 99 |
* referencing the data base contents. |
| 100 |
*/ |
| 101 |
int domain_adjust_node_perms(struct node *node); |
| 102 |
|
| 103 |
int domain_alloc_permrefs(struct node_perms *perms); |
| 104 |
|
| 105 |
/* Quota manipulation */ |
| 106 |
int domain_nbentry_inc(struct connection *conn, unsigned int domid); |
| 107 |
int domain_nbentry_dec(struct connection *conn, unsigned int domid); |
| 108 |
int domain_nbentry_fix(unsigned int domid, int num, bool update); |
| 109 |
unsigned int domain_nbentry(struct connection *conn); |
| 110 |
int domain_memory_add(struct connection *conn, unsigned int domid, int mem, |
| 111 |
bool no_quota_check); |
| 112 |
|
| 113 |
/* |
| 114 |
* domain_memory_add_chk(): to be used when memory quota should be checked. |
| 115 |
* Not to be used when specifying a negative mem value, as lowering the used |
| 116 |
* memory should always be allowed. |
| 117 |
*/ |
| 118 |
static inline int domain_memory_add_chk(struct connection *conn, |
| 119 |
unsigned int domid, int mem) |
| 120 |
{ |
| 121 |
return domain_memory_add(conn, domid, mem, false); |
| 122 |
} |
| 123 |
|
| 124 |
/* |
| 125 |
* domain_memory_add_nochk(): to be used when memory quota should not be |
| 126 |
* checked, e.g. when lowering memory usage, or in an error case for undoing |
| 127 |
* a previous memory adjustment. |
| 128 |
*/ |
| 129 |
static inline void domain_memory_add_nochk(struct connection *conn, |
| 130 |
unsigned int domid, int mem) |
| 131 |
{ |
| 132 |
domain_memory_add(conn, domid, mem, true); |
| 133 |
} |
| 134 |
void domain_watch_inc(struct connection *conn); |
| 135 |
void domain_watch_dec(struct connection *conn); |
| 136 |
int domain_watch(struct connection *conn); |
| 137 |
void domain_outstanding_inc(struct connection *conn); |
| 138 |
void domain_outstanding_dec(struct connection *conn, unsigned int domid); |
| 139 |
void domain_transaction_inc(struct connection *conn); |
| 140 |
void domain_transaction_dec(struct connection *conn); |
| 141 |
unsigned int domain_transaction_get(struct connection *conn); |
| 142 |
int domain_get_quota(const void *ctx, struct connection *conn, |
| 143 |
unsigned int domid); |
| 144 |
|
| 145 |
/* |
| 146 |
* Update or check number of nodes per domain at the end of a transaction. |
| 147 |
* If "update" is true, "chk_quota" is ignored. |
| 148 |
*/ |
| 149 |
int acc_fix_domains(struct list_head *head, bool chk_quota, bool update); |
| 150 |
void acc_drop(struct connection *conn); |
| 151 |
void acc_commit(struct connection *conn); |
| 152 |
int domain_max_global_acc(const void *ctx, struct connection *conn); |
| 153 |
void domain_reset_global_acc(void); |
| 154 |
bool domain_max_chk(const struct connection *conn, enum accitem what, |
| 155 |
unsigned int val); |
| 156 |
|
| 157 |
extern long wrl_ntransactions; |
| 158 |
|
| 159 |
void wrl_check_timeout(struct domain *domain, uint64_t now, int *ptimeout); |
| 160 |
void wrl_log_periodic(uint64_t now); |
| 161 |
void wrl_apply_debit_direct(struct connection *conn); |
| 162 |
void wrl_apply_debit_trans_commit(struct connection *conn); |
| 163 |
|
| 164 |
const char *dump_state_connections(FILE *fp); |
| 165 |
|
| 166 |
void read_state_connection(const void *ctx, const void *state); |
| 167 |
|
| 168 |
struct hashtable *domain_check_acc_init(void); |
| 169 |
void domain_check_acc_add(const struct node *node, struct hashtable *domains); |
| 170 |
void domain_check_acc(struct hashtable *domains); |
| 171 |
|
| 172 |
#endif /* _XENSTORED_DOMAIN_H */ |