ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-xen/xenbus.h @ 6298:e8c2c3123ec6

Improve error paths and cleanup code.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Fri Aug 19 17:38:07 2005 +0000 (2005-08-19)
parents 47d49e8b8042
children 631cc5dc3e8a
line source
1 /******************************************************************************
2 * xenbus.h
3 *
4 * Talks to Xen Store to figure out what devices we have.
5 *
6 * Copyright (C) 2005 Rusty Russell, IBM Corporation
7 *
8 * This file may be distributed separately from the Linux kernel, or
9 * incorporated into other software packages, subject to the following license:
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this source file (the "Software"), to deal in the Software without
13 * restriction, including without limitation the rights to use, copy, modify,
14 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
15 * and to permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 * IN THE SOFTWARE.
28 */
30 #ifndef _ASM_XEN_XENBUS_H
31 #define _ASM_XEN_XENBUS_H
33 #include <linux/device.h>
34 #include <linux/notifier.h>
35 #include <asm/semaphore.h>
37 /* A xenbus device. */
38 struct xenbus_device {
39 char *devicetype;
40 char *nodename;
41 struct device dev;
42 int has_error;
43 void *data;
44 };
46 static inline struct xenbus_device *to_xenbus_device(struct device *dev)
47 {
48 return container_of(dev, struct xenbus_device, dev);
49 }
51 struct xenbus_device_id
52 {
53 /* .../device/<device_type>/<identifier> */
54 char devicetype[32]; /* General class of device. */
55 };
57 /* A xenbus driver. */
58 struct xenbus_driver {
59 char *name;
60 struct module *owner;
61 const struct xenbus_device_id *ids;
62 int (*probe)(struct xenbus_device *dev,
63 const struct xenbus_device_id *id);
64 int (*remove)(struct xenbus_device *dev);
65 int (*suspend)(struct xenbus_device *dev);
66 int (*resume)(struct xenbus_device *dev);
67 struct device_driver driver;
68 };
70 static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
71 {
72 return container_of(drv, struct xenbus_driver, driver);
73 }
75 int xenbus_register_device(struct xenbus_driver *drv);
76 int xenbus_register_backend(struct xenbus_driver *drv);
77 void xenbus_unregister_driver(struct xenbus_driver *drv);
79 /* Caller must hold this lock to call these functions: it's also held
80 * across watch callbacks. */
81 extern struct semaphore xenbus_lock;
83 char **xenbus_directory(const char *dir, const char *node, unsigned int *num);
84 void *xenbus_read(const char *dir, const char *node, unsigned int *len);
85 int xenbus_write(const char *dir, const char *node,
86 const char *string, int createflags);
87 int xenbus_mkdir(const char *dir, const char *node);
88 int xenbus_exists(const char *dir, const char *node);
89 int xenbus_rm(const char *dir, const char *node);
90 int xenbus_transaction_start(const char *subtree);
91 int xenbus_transaction_end(int abort);
93 /* Single read and scanf: returns -errno or num scanned if > 0. */
94 int xenbus_scanf(const char *dir, const char *node, const char *fmt, ...)
95 __attribute__((format(scanf, 3, 4)));
97 /* Single printf and write: returns -errno or 0. */
98 int xenbus_printf(const char *dir, const char *node, const char *fmt, ...)
99 __attribute__((format(printf, 3, 4)));
101 /* Generic read function: NULL-terminated triples of name,
102 * sprintf-style type string, and pointer. Returns 0 or errno.*/
103 int xenbus_gather(const char *dir, ...);
105 /* Report a (negative) errno into the store, with explanation. */
106 void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt,...);
108 /* Clear any error. */
109 void xenbus_dev_ok(struct xenbus_device *dev);
111 /* Register callback to watch this node. */
112 struct xenbus_watch
113 {
114 struct list_head list;
115 char *node;
116 void (*callback)(struct xenbus_watch *, const char *node);
117 };
119 /* notifer routines for when the xenstore comes up */
120 int register_xenstore_notifier(struct notifier_block *nb);
121 void unregister_xenstore_notifier(struct notifier_block *nb);
123 int register_xenbus_watch(struct xenbus_watch *watch);
124 void unregister_xenbus_watch(struct xenbus_watch *watch);
125 void reregister_xenbus_watches(void);
127 /* Called from xen core code. */
128 void xenbus_suspend(void);
129 void xenbus_resume(void);
131 #define XENBUS_IS_ERR_READ(str) ({ \
132 if (!IS_ERR(str) && strlen(str) == 0) { \
133 kfree(str); \
134 str = ERR_PTR(-ERANGE); \
135 } \
136 IS_ERR(str); \
137 })
139 #define XENBUS_EXIST_ERR(err) ((err) == -ENOENT || (err) == -ERANGE)
141 #endif /* _ASM_XEN_XENBUS_H */