ia64/xen-unstable

view tools/xenstore/xenstored_core.h @ 5867:932fc8a1b38d

# HG changeset patch
# User Rusty Russell <rusty@rustcorp.com.au>
# Node ID a92163adedcfcff0d05c965d09da747f3c8aa13e
# Parent 63ab20781afa311300f3a8e832744292014ea7f6

Remove ill-conceived concept of watches blocking reply on connection which did write/mkdir/rm/setperm etc.
This causes deadlocks in real life, and I can't see a sane way of avoiding them: it is reasonable for someone to ignore watch notifications while doing other actions, and that means that we can do other writes. These writes can block pending other watchers; if one of these is the process blocked awaiting our ack, we deadlock.

diff -r 63ab20781afa -r a92163adedcf tools/xenstore/xenstored_core.c
author cl349@firebug.cl.cam.ac.uk
date Tue Jul 26 13:11:01 2005 +0000 (2005-07-26)
parents a83ac0806d6b
children 99366b44c421
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 struct connection
51 {
52 struct list_head list;
54 /* The file descriptor we came in on. */
55 int fd;
57 /* Who am I? 0 for socket connections. */
58 domid_t id;
60 /* Are we blocked waiting for a transaction to end? Contains node. */
61 char *blocked;
63 /* Is this a read-only connection? */
64 bool can_write;
66 /* Are we waiting for a watch event ack? */
67 bool waiting_for_ack;
69 /* Buffered incoming data. */
70 struct buffered_data *in;
72 /* Buffered output data */
73 struct buffered_data *out;
75 /* If we had a watch fire outgoing when we needed to reply... */
76 struct buffered_data *waiting_reply;
78 /* My transaction, if any. */
79 struct transaction *transaction;
81 /* The domain I'm associated with, if any. */
82 struct domain *domain;
84 /* Methods for communicating over this connection: write can be NULL */
85 connwritefn_t *write;
86 connreadfn_t *read;
87 };
89 /* Return length of string (including nul) at this offset. */
90 unsigned int get_string(const struct buffered_data *data,
91 unsigned int offset);
93 /* Break input into vectors, return the number, fill in up to num of them. */
94 unsigned int get_strings(struct buffered_data *data,
95 char *vec[], unsigned int num);
97 /* Is child node a child or equal to parent node? */
98 bool is_child(const char *child, const char *parent);
100 /* Create a new buffer with lifetime of context. */
101 struct buffered_data *new_buffer(void *ctx);
103 bool send_reply(struct connection *conn, enum xsd_sockmsg_type type,
104 const void *data, unsigned int len);
106 /* Some routines (write, mkdir, etc) just need a non-error return */
107 bool send_ack(struct connection *conn, enum xsd_sockmsg_type type);
109 /* Send an error: error is usually "errno". */
110 bool send_error(struct connection *conn, int error);
112 /* Canonicalize this path if possible. */
113 char *canonicalize(struct connection *conn, const char *node);
115 /* Check permissions on this node. */
116 bool check_node_perms(struct connection *conn, const char *node,
117 enum xs_perm_type perm);
119 /* Path to this node outside transaction. */
120 char *node_dir_outside_transaction(const char *node);
122 /* Fail due to excessive corruption, capitalist pigdogs! */
123 void __attribute__((noreturn)) corrupt(struct connection *conn,
124 const char *fmt, ...);
126 struct connection *new_connection(connwritefn_t *write, connreadfn_t *read);
128 void handle_input(struct connection *conn);
129 void handle_output(struct connection *conn);
131 /* Is this a valid node name? */
132 bool is_valid_nodename(const char *node);
134 /* Return a pointer to an open dir, self-closig and attached to pathname. */
135 DIR **talloc_opendir(const char *pathname);
137 /* Return a pointer to an fd, self-closing and attached to this pathname. */
138 int *talloc_open(const char *pathname, int flags, int mode);
140 /* Convenient talloc-style destructor for paths. */
141 int destroy_path(void *path);
143 /* Read entire contents of a talloced fd. */
144 void *read_all(int *fd, unsigned int *size);
146 /* Tracing infrastructure. */
147 void trace_create(const void *data, const char *type);
148 void trace_destroy(const void *data, const char *type);
149 void trace_watch_timeout(const struct connection *conn, const char *node, const char *token);
151 #endif /* _XENSTORED_CORE_H */