iPXE
xenbus.c File Reference

Xen device bus. More...

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/malloc.h>
#include <ipxe/device.h>
#include <ipxe/timer.h>
#include <ipxe/nap.h>
#include <ipxe/xen.h>
#include <ipxe/xenstore.h>
#include <ipxe/xenbus.h>

Go to the source code of this file.

Macros

#define ETIMEDOUT_UNKNOWN    __einfo_error ( EINFO_ETIMEDOUT_UNKNOWN )
#define EINFO_ETIMEDOUT_UNKNOWN
#define ETIMEDOUT_INITIALISING    __einfo_error ( EINFO_ETIMEDOUT_INITIALISING )
#define EINFO_ETIMEDOUT_INITIALISING
#define ETIMEDOUT_INITWAIT    __einfo_error ( EINFO_ETIMEDOUT_INITWAIT )
#define EINFO_ETIMEDOUT_INITWAIT
#define ETIMEDOUT_INITIALISED    __einfo_error ( EINFO_ETIMEDOUT_INITIALISED )
#define EINFO_ETIMEDOUT_INITIALISED
#define ETIMEDOUT_CONNECTED    __einfo_error ( EINFO_ETIMEDOUT_CONNECTED )
#define EINFO_ETIMEDOUT_CONNECTED
#define ETIMEDOUT_CLOSING    __einfo_error ( EINFO_ETIMEDOUT_CLOSING )
#define EINFO_ETIMEDOUT_CLOSING
#define ETIMEDOUT_CLOSED    __einfo_error ( EINFO_ETIMEDOUT_CLOSED )
#define EINFO_ETIMEDOUT_CLOSED
#define ETIMEDOUT_RECONFIGURING    __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURING )
#define EINFO_ETIMEDOUT_RECONFIGURING
#define ETIMEDOUT_RECONFIGURED    __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURED )
#define EINFO_ETIMEDOUT_RECONFIGURED
#define ETIMEDOUT_STATE(state)
#define XENBUS_BACKEND_TIMEOUT   ( 5 * TICKS_PER_SEC )
 Maximum time to wait for backend to reach a given state, in ticks.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int xenbus_set_state (struct xen_device *xendev, int state)
 Set device state.
int xenbus_backend_state (struct xen_device *xendev)
 Get backend state.
int xenbus_backend_wait (struct xen_device *xendev, int state)
 Wait for backend to reach a given state.
static struct xen_driverxenbus_find_driver (const char *type)
 Find driver for Xen device.
static int xenbus_probe_device (struct xen_hypervisor *xen, struct device *parent, const char *instance, struct xen_driver *driver)
 Probe Xen device.
static void xenbus_remove_device (struct xen_device *xendev)
 Remove Xen device.
static int xenbus_probe_type (struct xen_hypervisor *xen, struct device *parent, const char *type)
 Probe Xen devices of a given type.
int xenbus_probe (struct xen_hypervisor *xen, struct device *parent)
 Probe Xen bus.
void xenbus_remove (struct xen_hypervisor *xen __unused, struct device *parent)
 Remove Xen bus.
 REQUIRING_SYMBOL (xenbus_set_state)
 REQUIRE_OBJECT (hvm)

Detailed Description

Xen device bus.

Definition in file xenbus.c.

Macro Definition Documentation

◆ ETIMEDOUT_UNKNOWN

#define ETIMEDOUT_UNKNOWN    __einfo_error ( EINFO_ETIMEDOUT_UNKNOWN )

Definition at line 45 of file xenbus.c.

45#define ETIMEDOUT_UNKNOWN \
46 __einfo_error ( EINFO_ETIMEDOUT_UNKNOWN )

◆ EINFO_ETIMEDOUT_UNKNOWN

#define EINFO_ETIMEDOUT_UNKNOWN
Value:
"Unknown" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition errno.h:181
#define EINFO_ETIMEDOUT
Definition errno.h:671
@ XenbusStateUnknown
Definition xenbus.h:23

Definition at line 47 of file xenbus.c.

47#define EINFO_ETIMEDOUT_UNKNOWN \
48 __einfo_uniqify ( EINFO_ETIMEDOUT, XenbusStateUnknown, \
49 "Unknown" )

◆ ETIMEDOUT_INITIALISING

#define ETIMEDOUT_INITIALISING    __einfo_error ( EINFO_ETIMEDOUT_INITIALISING )

Definition at line 50 of file xenbus.c.

50#define ETIMEDOUT_INITIALISING \
51 __einfo_error ( EINFO_ETIMEDOUT_INITIALISING )

◆ EINFO_ETIMEDOUT_INITIALISING

#define EINFO_ETIMEDOUT_INITIALISING
Value:
"Initialising" )
@ XenbusStateInitialising
Definition xenbus.h:25

Definition at line 52 of file xenbus.c.

52#define EINFO_ETIMEDOUT_INITIALISING \
53 __einfo_uniqify ( EINFO_ETIMEDOUT, XenbusStateInitialising, \
54 "Initialising" )

◆ ETIMEDOUT_INITWAIT

#define ETIMEDOUT_INITWAIT    __einfo_error ( EINFO_ETIMEDOUT_INITWAIT )

Definition at line 55 of file xenbus.c.

55#define ETIMEDOUT_INITWAIT \
56 __einfo_error ( EINFO_ETIMEDOUT_INITWAIT )

◆ EINFO_ETIMEDOUT_INITWAIT

#define EINFO_ETIMEDOUT_INITWAIT
Value:
"InitWait" )
@ XenbusStateInitWait
Definition xenbus.h:31

Definition at line 57 of file xenbus.c.

57#define EINFO_ETIMEDOUT_INITWAIT \
58 __einfo_uniqify ( EINFO_ETIMEDOUT, XenbusStateInitWait, \
59 "InitWait" )

◆ ETIMEDOUT_INITIALISED

#define ETIMEDOUT_INITIALISED    __einfo_error ( EINFO_ETIMEDOUT_INITIALISED )

Definition at line 60 of file xenbus.c.

60#define ETIMEDOUT_INITIALISED \
61 __einfo_error ( EINFO_ETIMEDOUT_INITIALISED )

◆ EINFO_ETIMEDOUT_INITIALISED

#define EINFO_ETIMEDOUT_INITIALISED
Value:
"Initialised" )
@ XenbusStateInitialised
Definition xenbus.h:36

Definition at line 62 of file xenbus.c.

62#define EINFO_ETIMEDOUT_INITIALISED \
63 __einfo_uniqify ( EINFO_ETIMEDOUT, XenbusStateInitialised, \
64 "Initialised" )

◆ ETIMEDOUT_CONNECTED

#define ETIMEDOUT_CONNECTED    __einfo_error ( EINFO_ETIMEDOUT_CONNECTED )

Definition at line 65 of file xenbus.c.

65#define ETIMEDOUT_CONNECTED \
66 __einfo_error ( EINFO_ETIMEDOUT_CONNECTED )

◆ EINFO_ETIMEDOUT_CONNECTED

#define EINFO_ETIMEDOUT_CONNECTED
Value:
"Connected" )
@ XenbusStateConnected
Definition xenbus.h:38

Definition at line 67 of file xenbus.c.

67#define EINFO_ETIMEDOUT_CONNECTED \
68 __einfo_uniqify ( EINFO_ETIMEDOUT, XenbusStateConnected, \
69 "Connected" )

◆ ETIMEDOUT_CLOSING

#define ETIMEDOUT_CLOSING    __einfo_error ( EINFO_ETIMEDOUT_CLOSING )

Definition at line 70 of file xenbus.c.

70#define ETIMEDOUT_CLOSING \
71 __einfo_error ( EINFO_ETIMEDOUT_CLOSING )

◆ EINFO_ETIMEDOUT_CLOSING

#define EINFO_ETIMEDOUT_CLOSING
Value:
"Closing" )
@ XenbusStateClosing
Definition xenbus.h:43

Definition at line 72 of file xenbus.c.

72#define EINFO_ETIMEDOUT_CLOSING \
73 __einfo_uniqify ( EINFO_ETIMEDOUT, XenbusStateClosing, \
74 "Closing" )

◆ ETIMEDOUT_CLOSED

#define ETIMEDOUT_CLOSED    __einfo_error ( EINFO_ETIMEDOUT_CLOSED )

Definition at line 75 of file xenbus.c.

75#define ETIMEDOUT_CLOSED \
76 __einfo_error ( EINFO_ETIMEDOUT_CLOSED )

◆ EINFO_ETIMEDOUT_CLOSED

#define EINFO_ETIMEDOUT_CLOSED
Value:
"Closed" )
@ XenbusStateClosed
Definition xenbus.h:45

Definition at line 77 of file xenbus.c.

77#define EINFO_ETIMEDOUT_CLOSED \
78 __einfo_uniqify ( EINFO_ETIMEDOUT, XenbusStateClosed, \
79 "Closed" )

◆ ETIMEDOUT_RECONFIGURING

#define ETIMEDOUT_RECONFIGURING    __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURING )

Definition at line 80 of file xenbus.c.

80#define ETIMEDOUT_RECONFIGURING \
81 __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURING )

◆ EINFO_ETIMEDOUT_RECONFIGURING

#define EINFO_ETIMEDOUT_RECONFIGURING
Value:
"Reconfiguring" )
@ XenbusStateReconfiguring
Definition xenbus.h:50

Definition at line 82 of file xenbus.c.

82#define EINFO_ETIMEDOUT_RECONFIGURING \
83 __einfo_uniqify ( EINFO_ETIMEDOUT, XenbusStateReconfiguring, \
84 "Reconfiguring" )

◆ ETIMEDOUT_RECONFIGURED

#define ETIMEDOUT_RECONFIGURED    __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURED )

Definition at line 85 of file xenbus.c.

85#define ETIMEDOUT_RECONFIGURED \
86 __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURED )

◆ EINFO_ETIMEDOUT_RECONFIGURED

#define EINFO_ETIMEDOUT_RECONFIGURED
Value:
"Reconfigured" )
@ XenbusStateReconfigured
Definition xenbus.h:52

Definition at line 87 of file xenbus.c.

87#define EINFO_ETIMEDOUT_RECONFIGURED \
88 __einfo_uniqify ( EINFO_ETIMEDOUT, XenbusStateReconfigured, \
89 "Reconfigured" )

◆ ETIMEDOUT_STATE

#define ETIMEDOUT_STATE ( state)
Value:
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition errno.h:226
uint8_t state
State.
Definition eth_slow.h:36
#define ETIMEDOUT_CONNECTED
Definition xenbus.c:65
#define ETIMEDOUT_INITIALISED
Definition xenbus.c:60
#define ETIMEDOUT_INITWAIT
Definition xenbus.c:55
#define ETIMEDOUT_UNKNOWN
Definition xenbus.c:45
#define ETIMEDOUT_CLOSED
Definition xenbus.c:75
#define ETIMEDOUT_RECONFIGURING
Definition xenbus.c:80
#define ETIMEDOUT_RECONFIGURED
Definition xenbus.c:85
#define ETIMEDOUT_INITIALISING
Definition xenbus.c:50
#define ETIMEDOUT_CLOSING
Definition xenbus.c:70

Definition at line 90 of file xenbus.c.

90#define ETIMEDOUT_STATE( state ) \
91 EUNIQ ( EINFO_ETIMEDOUT, (state), ETIMEDOUT_UNKNOWN, \
92 ETIMEDOUT_INITIALISING, ETIMEDOUT_INITWAIT, \
93 ETIMEDOUT_INITIALISED, ETIMEDOUT_CONNECTED, \
94 ETIMEDOUT_CLOSING, ETIMEDOUT_CLOSED, \
95 ETIMEDOUT_RECONFIGURING, ETIMEDOUT_RECONFIGURED )

Referenced by xenbus_backend_wait().

◆ XENBUS_BACKEND_TIMEOUT

#define XENBUS_BACKEND_TIMEOUT   ( 5 * TICKS_PER_SEC )

Maximum time to wait for backend to reach a given state, in ticks.

Definition at line 98 of file xenbus.c.

Referenced by xenbus_backend_wait().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ xenbus_set_state()

int xenbus_set_state ( struct xen_device * xendev,
int state )

Set device state.

Parameters
xendevXen device
stateNew state
Return values
rcReturn status code

Definition at line 107 of file xenbus.c.

107 {
108 int rc;
109
110 /* Attempt to set state */
111 if ( ( rc = xenstore_write_num ( xendev->xen, state, xendev->key,
112 "state", NULL ) ) != 0 ) {
113 DBGC ( xendev, "XENBUS %s could not set state=\"%d\": %s\n",
114 xendev->key, state, strerror ( rc ) );
115 return rc;
116 }
117
118 return 0;
119}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define DBGC(...)
Definition compiler.h:505
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
char * key
XenStore key.
Definition xenbus.h:25
struct xen_hypervisor * xen
Xen hypervisor.
Definition xenbus.h:23
int xenstore_write_num(struct xen_hypervisor *xen, unsigned long num,...)
Write XenStore numeric value.
Definition xenstore.c:461

References DBGC, xen_device::key, NULL, rc, state, strerror(), xen_device::xen, and xenstore_write_num().

Referenced by netfront_open(), netfront_reset(), and REQUIRING_SYMBOL().

◆ xenbus_backend_state()

int xenbus_backend_state ( struct xen_device * xendev)

Get backend state.

Parameters
xendevXen device
Return values
stateBackend state, or negative error

Definition at line 127 of file xenbus.c.

127 {
128 unsigned long state;
129 int rc;
130
131 /* Attempt to get backend state */
132 if ( ( rc = xenstore_read_num ( xendev->xen, &state, xendev->backend,
133 "state", NULL ) ) != 0 ) {
134 DBGC ( xendev, "XENBUS %s could not read %s/state: %s\n",
135 xendev->key, xendev->backend, strerror ( rc ) );
136 return rc;
137 }
138
139 return state;
140}
char * backend
Backend XenStore key.
Definition xenbus.h:27
int xenstore_read_num(struct xen_hypervisor *xen, unsigned long *num,...)
Read XenStore numeric value.
Definition xenstore.c:391

References xen_device::backend, DBGC, xen_device::key, NULL, rc, state, strerror(), xen_device::xen, and xenstore_read_num().

Referenced by netfront_reset(), and xenbus_backend_wait().

◆ xenbus_backend_wait()

int xenbus_backend_wait ( struct xen_device * xendev,
int state )

Wait for backend to reach a given state.

Parameters
xendevXen device
stateDesired backend state
Return values
rcReturn status code

Definition at line 149 of file xenbus.c.

149 {
150 unsigned long started = currticks();
151 unsigned long elapsed;
152 unsigned int attempts = 0;
153 int current_state;
154 int rc;
155
156 /* Wait for backend to reach this state */
157 do {
158
159 /* Get current backend state */
160 current_state = xenbus_backend_state ( xendev );
161 if ( current_state < 0 ) {
162 rc = current_state;
163 return rc;
164 }
165 if ( current_state == state )
166 return 0;
167
168 /* Allow time for backend to react */
169 cpu_nap();
170
171 /* XenStore is a very slow interface; any fixed delay
172 * time would be dwarfed by the XenStore access time.
173 * We therefore use wall clock to time out this
174 * operation.
175 */
176 elapsed = ( currticks() - started );
177 attempts++;
178
179 } while ( elapsed < XENBUS_BACKEND_TIMEOUT );
180
181 /* Construct status code from current backend state */
182 rc = -ETIMEDOUT_STATE ( current_state );
183 DBGC ( xendev, "XENBUS %s timed out after %d attempts waiting for "
184 "%s/state=\"%d\": %s\n", xendev->key, attempts, xendev->backend,
185 state, strerror ( rc ) );
186
187 return rc;
188}
void cpu_nap(void)
Sleep with interrupts enabled until next CPU interrupt.
static int started
"startup() has been called" flag
Definition init.c:38
unsigned long currticks(void)
Get current system time in ticks.
Definition timer.c:43
int xenbus_backend_state(struct xen_device *xendev)
Get backend state.
Definition xenbus.c:127
#define XENBUS_BACKEND_TIMEOUT
Maximum time to wait for backend to reach a given state, in ticks.
Definition xenbus.c:98
#define ETIMEDOUT_STATE(state)
Definition xenbus.c:90

References xen_device::backend, cpu_nap(), currticks(), DBGC, ETIMEDOUT_STATE, xen_device::key, rc, started, state, strerror(), xenbus_backend_state(), and XENBUS_BACKEND_TIMEOUT.

Referenced by netfront_open(), and netfront_reset().

◆ xenbus_find_driver()

struct xen_driver * xenbus_find_driver ( const char * type)
static

Find driver for Xen device.

Parameters
typeDevice type
Return values
driverDriver, or NULL

Definition at line 196 of file xenbus.c.

196 {
197 struct xen_driver *xendrv;
198
200 if ( strcmp ( xendrv->type, type ) == 0 )
201 return xendrv;
202 }
203 return NULL;
204}
uint32_t type
Operating system type.
Definition ena.h:1
#define XEN_DRIVERS
Xen device driver table.
Definition xenbus.h:56
int strcmp(const char *first, const char *second)
Compare strings.
Definition string.c:174
A Xen device driver.
Definition xenbus.h:37
const char * type
Device type.
Definition xenbus.h:41
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

References for_each_table_entry, NULL, strcmp(), type, xen_driver::type, and XEN_DRIVERS.

Referenced by xenbus_probe_type().

◆ xenbus_probe_device()

int xenbus_probe_device ( struct xen_hypervisor * xen,
struct device * parent,
const char * instance,
struct xen_driver * driver )
static

Probe Xen device.

Parameters
xenXen hypervisor
parentParent device
instanceDevice instance
driverDevice driver
Return values
rcReturn status code

Definition at line 215 of file xenbus.c.

217 {
218 const char *type = driver->type;
219 struct xen_device *xendev;
220 size_t key_len;
221 int rc;
222
223 /* Allocate and initialise structure */
224 key_len = ( 7 /* "device/" */ + strlen ( type ) + 1 /* "/" */ +
225 strlen ( instance ) + 1 /* NUL */ );
226 xendev = zalloc ( sizeof ( *xendev ) + key_len );
227 if ( ! xendev ) {
228 rc = -ENOMEM;
229 goto err_alloc;
230 }
231 snprintf ( xendev->dev.name, sizeof ( xendev->dev.name ), "%s/%s",
232 type, instance );
233 xendev->dev.desc.bus_type = BUS_TYPE_XEN;
234 INIT_LIST_HEAD ( &xendev->dev.children );
235 list_add_tail ( &xendev->dev.siblings, &parent->children );
236 xendev->dev.parent = parent;
237 xendev->xen = xen;
238 xendev->key = ( ( void * ) ( xendev + 1 ) );
239 snprintf ( xendev->key, key_len, "device/%s/%s", type, instance );
240 xendev->driver = driver;
241 xendev->dev.driver_name = driver->name;
242 DBGC ( xendev, "XENBUS %s has driver \"%s\"\n", xendev->key,
243 xendev->driver->name );
244
245 /* Read backend key */
246 if ( ( rc = xenstore_read ( xen, &xendev->backend, xendev->key,
247 "backend", NULL ) ) != 0 ) {
248 DBGC ( xendev, "XENBUS %s could not read backend: %s\n",
249 xendev->key, strerror ( rc ) );
250 goto err_read_backend;
251 }
252
253 /* Read backend domain ID */
254 if ( ( rc = xenstore_read_num ( xen, &xendev->backend_id, xendev->key,
255 "backend-id", NULL ) ) != 0 ) {
256 DBGC ( xendev, "XENBUS %s could not read backend-id: %s\n",
257 xendev->key, strerror ( rc ) );
258 goto err_read_backend_id;
259 }
260 DBGC ( xendev, "XENBUS %s backend=\"%s\" in domain %ld\n",
261 xendev->key, xendev->backend, xendev->backend_id );
262
263 /* Probe driver */
264 if ( ( rc = xendev->driver->probe ( xendev ) ) != 0 ) {
265 DBGC ( xendev, "XENBUS could not probe %s: %s\n",
266 xendev->key, strerror ( rc ) );
267 goto err_probe;
268 }
269
270 return 0;
271
272 xendev->driver->remove ( xendev );
273 err_probe:
274 err_read_backend_id:
275 free ( xendev->backend );
276 err_read_backend:
277 list_del ( &xendev->dev.siblings );
278 free ( xendev );
279 err_alloc:
280 return rc;
281}
#define BUS_TYPE_XEN
Xen bus type.
Definition device.h:65
#define ENOMEM
Not enough space.
Definition errno.h:535
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
size_t strlen(const char *src)
Get length of string.
Definition string.c:244
unsigned int bus_type
Bus type.
Definition device.h:25
struct device_description desc
Device description.
Definition device.h:83
struct device * parent
Bus device.
Definition device.h:89
struct list_head children
Devices attached to this device.
Definition device.h:87
struct list_head siblings
Devices on the same bus.
Definition device.h:85
const char * driver_name
Driver name.
Definition device.h:81
char name[40]
Name.
Definition device.h:79
A Xen device.
Definition xenbus.h:19
struct xen_driver * driver
Driver.
Definition xenbus.h:31
unsigned long backend_id
Backend domain ID.
Definition xenbus.h:29
struct device dev
Generic iPXE device.
Definition xenbus.h:21
const char * name
Name.
Definition xenbus.h:39
void(* remove)(struct xen_device *xendev)
Remove device.
Definition xenbus.h:52
int(* probe)(struct xen_device *xendev)
Probe device.
Definition xenbus.h:47
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383
int xenstore_read(struct xen_hypervisor *xen, char **value,...)
Read XenStore value.
Definition xenstore.c:372

References xen_device::backend, xen_device::backend_id, device_description::bus_type, BUS_TYPE_XEN, device::children, DBGC, device::desc, xen_device::dev, xen_device::driver, device::driver_name, ENOMEM, free, INIT_LIST_HEAD, xen_device::key, list_add_tail, list_del, device::name, xen_driver::name, NULL, device::parent, xen_driver::probe, rc, xen_driver::remove, device::siblings, snprintf(), strerror(), strlen(), type, xen_driver::type, xen_device::xen, xenstore_read(), xenstore_read_num(), and zalloc().

Referenced by xenbus_probe_type().

◆ xenbus_remove_device()

void xenbus_remove_device ( struct xen_device * xendev)
static

Remove Xen device.

Parameters
xendevXen device

Definition at line 288 of file xenbus.c.

288 {
289
290 /* Remove device */
291 xendev->driver->remove ( xendev );
292 free ( xendev->backend );
293 list_del ( &xendev->dev.siblings );
294 free ( xendev );
295}

References xen_device::backend, xen_device::dev, xen_device::driver, free, list_del, xen_driver::remove, and device::siblings.

Referenced by xenbus_remove().

◆ xenbus_probe_type()

int xenbus_probe_type ( struct xen_hypervisor * xen,
struct device * parent,
const char * type )
static

Probe Xen devices of a given type.

Parameters
xenXen hypervisor
parentParent device
typeDevice type
Return values
rcReturn status code

Definition at line 305 of file xenbus.c.

306 {
307 struct xen_driver *driver;
308 char *children;
309 char *child;
310 size_t len;
311 int rc;
312
313 /* Look for a driver */
314 driver = xenbus_find_driver ( type );
315 if ( ! driver ) {
316 DBGC ( xen, "XENBUS has no driver for \"%s\" devices\n", type );
317 /* Not a fatal error */
318 rc = 0;
319 goto err_no_driver;
320 }
321
322 /* Get children of this key */
323 if ( ( rc = xenstore_directory ( xen, &children, &len, "device",
324 type, NULL ) ) != 0 ) {
325 DBGC ( xen, "XENBUS could not list \"%s\" devices: %s\n",
326 type, strerror ( rc ) );
327 goto err_directory;
328 }
329
330 /* Probe each child */
331 for ( child = children ; child < ( children + len ) ;
332 child += ( strlen ( child ) + 1 /* NUL */ ) ) {
333 if ( ( rc = xenbus_probe_device ( xen, parent, child,
334 driver ) ) != 0 )
335 goto err_probe_device;
336 }
337
338 free ( children );
339 return 0;
340
341 err_probe_device:
342 free ( children );
343 err_directory:
344 err_no_driver:
345 return rc;
346}
ring len
Length.
Definition dwmac.h:226
static struct xen_driver * xenbus_find_driver(const char *type)
Find driver for Xen device.
Definition xenbus.c:196
static int xenbus_probe_device(struct xen_hypervisor *xen, struct device *parent, const char *instance, struct xen_driver *driver)
Probe Xen device.
Definition xenbus.c:215
int xenstore_directory(struct xen_hypervisor *xen, char **children, size_t *len,...)
Read XenStore directory.
Definition xenstore.c:504
char unsigned long const char unsigned long char ** children
Definition xenstore.h:26

References children, DBGC, free, len, NULL, rc, strerror(), strlen(), type, xenbus_find_driver(), xenbus_probe_device(), and xenstore_directory().

Referenced by xenbus_probe().

◆ xenbus_probe()

int xenbus_probe ( struct xen_hypervisor * xen,
struct device * parent )

Probe Xen bus.

Parameters
xenXen hypervisor
parentParent device
Return values
rcReturn status code

Definition at line 355 of file xenbus.c.

355 {
356 char *types;
357 char *type;
358 size_t len;
359 int rc;
360
361 /* Get children of "device" key */
362 if ( ( rc = xenstore_directory ( xen, &types, &len, "device",
363 NULL ) ) != 0 ) {
364 DBGC ( xen, "XENBUS could not list device types: %s\n",
365 strerror ( rc ) );
366 goto err_directory;
367 }
368
369 /* Probe each child type */
370 for ( type = types ; type < ( types + len ) ;
371 type += ( strlen ( type ) + 1 /* NUL */ ) ) {
372 if ( ( rc = xenbus_probe_type ( xen, parent, type ) ) != 0 )
373 goto err_probe_type;
374 }
375
376 free ( types );
377 return 0;
378
379 xenbus_remove ( xen, parent );
380 err_probe_type:
381 free ( types );
382 err_directory:
383 return rc;
384}
void xenbus_remove(struct xen_hypervisor *xen __unused, struct device *parent)
Remove Xen bus.
Definition xenbus.c:392
static int xenbus_probe_type(struct xen_hypervisor *xen, struct device *parent, const char *type)
Probe Xen devices of a given type.
Definition xenbus.c:305

References DBGC, free, len, NULL, rc, strerror(), strlen(), type, xenbus_probe_type(), xenbus_remove(), and xenstore_directory().

Referenced by hvm_probe().

◆ xenbus_remove()

void xenbus_remove ( struct xen_hypervisor *xen __unused,
struct device * parent )

Remove Xen bus.

Parameters
xenXen hypervisor
parentParent device

Definition at line 392 of file xenbus.c.

393 {
394 struct xen_device *xendev;
395 struct xen_device *tmp;
396
397 /* Remove devices */
398 list_for_each_entry_safe ( xendev, tmp, &parent->children,
399 dev.siblings ) {
400 xenbus_remove_device ( xendev );
401 }
402}
unsigned long tmp
Definition linux_pci.h:65
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition list.h:459
static void xenbus_remove_device(struct xen_device *xendev)
Remove Xen device.
Definition xenbus.c:288

References __unused, device::children, xen_device::dev, list_for_each_entry_safe, device::siblings, tmp, and xenbus_remove_device().

Referenced by hvm_probe(), hvm_remove(), and xenbus_probe().

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( xenbus_set_state )

References xenbus_set_state().

◆ REQUIRE_OBJECT()

REQUIRE_OBJECT ( hvm )