ia64/xen-unstable

view tools/xenstore/xenstored_core.h @ 6946:e703abaf6e3d

Add behaviour to the remove methods to remove the transaction's path itself. This allows us to write Remove(path) to remove the specified path rather than having to slice the path ourselves.
author emellor@ewan
date Sun Sep 18 14:42:13 2005 +0100 (2005-09-18)
parents 3233e7ecfa9f
children 06d84bf87159
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"
32 struct buffered_data
33 {
34 /* Are we still doing the header? */
35 bool inhdr;
36 /* How far are we? */
37 unsigned int used;
38 union {
39 struct xsd_sockmsg msg;
40 char raw[sizeof(struct xsd_sockmsg)];
41 } hdr;
42 /* The actual data. */
43 char *buffer;
44 };
46 struct connection;
47 typedef int connwritefn_t(struct connection *, const void *, unsigned int);
48 typedef int connreadfn_t(struct connection *, void *, unsigned int);
50 enum state
51 {
52 /* Blocked by transaction. */
53 BLOCKED,
54 /* Doing action, not listening */
55 BUSY,
56 /* Completed */
57 OK,
58 };
60 struct connection
61 {
62 struct list_head list;
64 /* The file descriptor we came in on. */
65 int fd;
67 /* Who am I? 0 for socket connections. */
68 domid_t id;
70 /* Blocked on transaction? Busy? */
71 enum state state;
73 /* Node we are waiting for (if state == BLOCKED) */
74 char *blocked_by;
76 /* Is this a read-only connection? */
77 bool can_write;
79 /* Are we waiting for a watch event ack? */
80 struct watch *waiting_for_ack;
82 /* Buffered incoming data. */
83 struct buffered_data *in;
85 /* Buffered output data */
86 struct buffered_data *out;
88 /* If we had a watch fire outgoing when we needed to reply... */
89 struct buffered_data *waiting_reply;
91 /* My transaction, if any. */
92 struct transaction *transaction;
94 /* The domain I'm associated with, if any. */
95 struct domain *domain;
97 /* My watches. */
98 struct list_head watches;
100 /* Methods for communicating over this connection: write can be NULL */
101 connwritefn_t *write;
102 connreadfn_t *read;
103 };
104 extern struct list_head connections;
106 /* Return length of string (including nul) at this offset. */
107 unsigned int get_string(const struct buffered_data *data,
108 unsigned int offset);
110 /* Break input into vectors, return the number, fill in up to num of them. */
111 unsigned int get_strings(struct buffered_data *data,
112 char *vec[], unsigned int num);
114 /* Is child node a child or equal to parent node? */
115 bool is_child(const char *child, const char *parent);
117 /* Create a new buffer with lifetime of context. */
118 struct buffered_data *new_buffer(void *ctx);
120 void send_reply(struct connection *conn, enum xsd_sockmsg_type type,
121 const void *data, unsigned int len);
123 /* Some routines (write, mkdir, etc) just need a non-error return */
124 void send_ack(struct connection *conn, enum xsd_sockmsg_type type);
126 /* Send an error: error is usually "errno". */
127 void send_error(struct connection *conn, int error);
129 /* Canonicalize this path if possible. */
130 char *canonicalize(struct connection *conn, const char *node);
132 /* Check permissions on this node. */
133 bool check_node_perms(struct connection *conn, const char *node,
134 enum xs_perm_type perm);
136 /* Check if node is an event node. */
137 bool check_event_node(const char *node);
139 /* Path to this node outside transaction. */
140 char *node_dir_outside_transaction(const char *node);
142 /* Fail due to excessive corruption, capitalist pigdogs! */
143 void __attribute__((noreturn)) corrupt(struct connection *conn,
144 const char *fmt, ...);
146 struct connection *new_connection(connwritefn_t *write, connreadfn_t *read);
148 void handle_input(struct connection *conn);
149 void handle_output(struct connection *conn);
151 /* Is this a valid node name? */
152 bool is_valid_nodename(const char *node);
154 /* Return a pointer to an open dir, self-closig and attached to pathname. */
155 DIR **talloc_opendir(const char *pathname);
157 /* Return a pointer to an fd, self-closing and attached to this pathname. */
158 int *talloc_open(const char *pathname, int flags, int mode);
160 /* Convenient talloc-style destructor for paths. */
161 int destroy_path(void *path);
163 /* Read entire contents of a talloced fd. */
164 void *read_all(int *fd, unsigned int *size);
166 /* Tracing infrastructure. */
167 void trace_create(const void *data, const char *type);
168 void trace_destroy(const void *data, const char *type);
169 void trace_watch_timeout(const struct connection *conn, const char *node, const char *token);
170 void trace(const char *fmt, ...);
172 #endif /* _XENSTORED_CORE_H */