ia64/xen-unstable

view tools/xenstore/xenstored_core.h @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents ef9591d03fdd
children 93e27f7ca8a8 61b3b357d827 76a7a7aa27e4
line source
1 /*
2 Internal interfaces for Xen Store Daemon.
3 Copyright (C) 2005 Rusty Russell IBM Corporation
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.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
20 #ifndef _XENSTORED_CORE_H
21 #define _XENSTORED_CORE_H
23 #include <sys/types.h>
24 #include <dirent.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <errno.h>
28 #include "xs_lib.h"
29 #include "xenstored.h"
30 #include "list.h"
31 #include "tdb.h"
33 struct buffered_data
34 {
35 /* Are we still doing the header? */
36 bool inhdr;
37 /* How far are we? */
38 unsigned int used;
39 union {
40 struct xsd_sockmsg msg;
41 char raw[sizeof(struct xsd_sockmsg)];
42 } hdr;
43 /* The actual data. */
44 char *buffer;
45 };
47 struct connection;
48 typedef int connwritefn_t(struct connection *, const void *, unsigned int);
49 typedef int connreadfn_t(struct connection *, void *, unsigned int);
51 enum state
52 {
53 /* Doing action, not listening */
54 BUSY,
55 /* Completed */
56 OK,
57 };
59 struct connection
60 {
61 struct list_head list;
63 /* The file descriptor we came in on. */
64 int fd;
66 /* Who am I? 0 for socket connections. */
67 domid_t id;
69 /* Blocked on transaction? Busy? */
70 enum state state;
72 /* Is this a read-only connection? */
73 bool can_write;
75 /* Are we waiting for a watch event ack? */
76 struct watch *waiting_for_ack;
78 /* Buffered incoming data. */
79 struct buffered_data *in;
81 /* Buffered output data */
82 struct buffered_data *out;
84 /* If we had a watch fire outgoing when we needed to reply... */
85 struct buffered_data *waiting_reply;
87 /* My transaction, if any. */
88 struct transaction *transaction;
90 /* The domain I'm associated with, if any. */
91 struct domain *domain;
93 /* My watches. */
94 struct list_head watches;
96 /* Methods for communicating over this connection: write can be NULL */
97 connwritefn_t *write;
98 connreadfn_t *read;
99 };
100 extern struct list_head connections;
102 struct node {
103 const char *name;
105 /* Database I came from */
106 TDB_CONTEXT *tdb;
108 /* Parent (optional) */
109 struct node *parent;
111 /* Permissions. */
112 unsigned int num_perms;
113 struct xs_permissions *perms;
115 /* Contents. */
116 unsigned int datalen;
117 void *data;
119 /* Children, each nul-terminated. */
120 unsigned int childlen;
121 char *children;
122 };
124 /* Break input into vectors, return the number, fill in up to num of them. */
125 unsigned int get_strings(struct buffered_data *data,
126 char *vec[], unsigned int num);
128 /* Is child node a child or equal to parent node? */
129 bool is_child(const char *child, const char *parent);
131 void send_reply(struct connection *conn, enum xsd_sockmsg_type type,
132 const void *data, unsigned int len);
134 /* Some routines (write, mkdir, etc) just need a non-error return */
135 void send_ack(struct connection *conn, enum xsd_sockmsg_type type);
137 /* Send an error: error is usually "errno". */
138 void send_error(struct connection *conn, int error);
140 /* Canonicalize this path if possible. */
141 char *canonicalize(struct connection *conn, const char *node);
143 /* Check if node is an event node. */
144 bool check_event_node(const char *node);
146 /* Get this node, checking we have permissions. */
147 struct node *get_node(struct connection *conn,
148 const char *name,
149 enum xs_perm_type perm);
151 /* Get TDB context for this connection */
152 TDB_CONTEXT *tdb_context(struct connection *conn);
154 /* Destructor for tdbs: required for transaction code */
155 int destroy_tdb(void *_tdb);
157 /* Replace the tdb: required for transaction code */
158 bool replace_tdb(const char *newname, TDB_CONTEXT *newtdb);
160 /* Fail due to excessive corruption, capitalist pigdogs! */
161 void __attribute__((noreturn)) corrupt(struct connection *conn,
162 const char *fmt, ...);
164 struct connection *new_connection(connwritefn_t *write, connreadfn_t *read);
166 /* Is this a valid node name? */
167 bool is_valid_nodename(const char *node);
170 /* Tracing infrastructure. */
171 void trace_create(const void *data, const char *type);
172 void trace_destroy(const void *data, const char *type);
173 void trace_watch_timeout(const struct connection *conn, const char *node, const char *token);
174 void trace(const char *fmt, ...);
176 #endif /* _XENSTORED_CORE_H */