iPXE
Macros | Functions
xenbus.c File Reference

Xen device bus. More...

#include <stdio.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. More...
 

Functions

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

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 43 of file xenbus.c.

◆ EINFO_ETIMEDOUT_UNKNOWN

#define EINFO_ETIMEDOUT_UNKNOWN
Value:
"Unknown" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 45 of file xenbus.c.

◆ ETIMEDOUT_INITIALISING

#define ETIMEDOUT_INITIALISING   __einfo_error ( EINFO_ETIMEDOUT_INITIALISING )

Definition at line 48 of file xenbus.c.

◆ EINFO_ETIMEDOUT_INITIALISING

#define EINFO_ETIMEDOUT_INITIALISING
Value:
"Initialising" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 50 of file xenbus.c.

◆ ETIMEDOUT_INITWAIT

#define ETIMEDOUT_INITWAIT   __einfo_error ( EINFO_ETIMEDOUT_INITWAIT )

Definition at line 53 of file xenbus.c.

◆ EINFO_ETIMEDOUT_INITWAIT

#define EINFO_ETIMEDOUT_INITWAIT
Value:
"InitWait" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 55 of file xenbus.c.

◆ ETIMEDOUT_INITIALISED

#define ETIMEDOUT_INITIALISED   __einfo_error ( EINFO_ETIMEDOUT_INITIALISED )

Definition at line 58 of file xenbus.c.

◆ EINFO_ETIMEDOUT_INITIALISED

#define EINFO_ETIMEDOUT_INITIALISED
Value:
"Initialised" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 60 of file xenbus.c.

◆ ETIMEDOUT_CONNECTED

#define ETIMEDOUT_CONNECTED   __einfo_error ( EINFO_ETIMEDOUT_CONNECTED )

Definition at line 63 of file xenbus.c.

◆ EINFO_ETIMEDOUT_CONNECTED

#define EINFO_ETIMEDOUT_CONNECTED
Value:
"Connected" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 65 of file xenbus.c.

◆ ETIMEDOUT_CLOSING

#define ETIMEDOUT_CLOSING   __einfo_error ( EINFO_ETIMEDOUT_CLOSING )

Definition at line 68 of file xenbus.c.

◆ EINFO_ETIMEDOUT_CLOSING

#define EINFO_ETIMEDOUT_CLOSING
Value:
"Closing" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 70 of file xenbus.c.

◆ ETIMEDOUT_CLOSED

#define ETIMEDOUT_CLOSED   __einfo_error ( EINFO_ETIMEDOUT_CLOSED )

Definition at line 73 of file xenbus.c.

◆ EINFO_ETIMEDOUT_CLOSED

#define EINFO_ETIMEDOUT_CLOSED
Value:
"Closed" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 75 of file xenbus.c.

◆ ETIMEDOUT_RECONFIGURING

#define ETIMEDOUT_RECONFIGURING   __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURING )

Definition at line 78 of file xenbus.c.

◆ EINFO_ETIMEDOUT_RECONFIGURING

#define EINFO_ETIMEDOUT_RECONFIGURING
Value:
"Reconfiguring" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 80 of file xenbus.c.

◆ ETIMEDOUT_RECONFIGURED

#define ETIMEDOUT_RECONFIGURED   __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURED )

Definition at line 83 of file xenbus.c.

◆ EINFO_ETIMEDOUT_RECONFIGURED

#define EINFO_ETIMEDOUT_RECONFIGURED
Value:
"Reconfigured" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 85 of file xenbus.c.

◆ ETIMEDOUT_STATE

#define ETIMEDOUT_STATE (   state)
Value:
#define ETIMEDOUT_INITWAIT
Definition: xenbus.c:53
uint8_t state
State.
Definition: eth_slow.h:47
#define ETIMEDOUT_INITIALISED
Definition: xenbus.c:58
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define ETIMEDOUT_RECONFIGURING
Definition: xenbus.c:78
#define ETIMEDOUT_RECONFIGURED
Definition: xenbus.c:83
#define ETIMEDOUT_CONNECTED
Definition: xenbus.c:63
#define ETIMEDOUT_INITIALISING
Definition: xenbus.c:48
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition: errno.h:225
#define ETIMEDOUT_UNKNOWN
Definition: xenbus.c:43
#define ETIMEDOUT_CLOSING
Definition: xenbus.c:68
#define ETIMEDOUT_CLOSED
Definition: xenbus.c:73

Definition at line 88 of file xenbus.c.

◆ 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 96 of file xenbus.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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 105 of file xenbus.c.

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

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

Referenced by netfront_open(), and netfront_reset().

◆ 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 125 of file xenbus.c.

125  {
126  unsigned long state;
127  int rc;
128 
129  /* Attempt to get backend state */
130  if ( ( rc = xenstore_read_num ( xendev->xen, &state, xendev->backend,
131  "state", NULL ) ) != 0 ) {
132  DBGC ( xendev, "XENBUS %s could not read %s/state: %s\n",
133  xendev->key, xendev->backend, strerror ( rc ) );
134  return rc;
135  }
136 
137  return state;
138 }
char * backend
Backend XenStore key.
Definition: xenbus.h:26
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t state
State.
Definition: eth_slow.h:47
#define DBGC(...)
Definition: compiler.h:505
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int xenstore_read_num(struct xen_hypervisor *xen, unsigned long *num,...)
Read XenStore numeric value.
Definition: xenstore.c:390
char * key
XenStore key.
Definition: xenbus.h:24
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct xen_hypervisor * xen
Xen hypervisor.
Definition: xenbus.h:22

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 147 of file xenbus.c.

147  {
148  unsigned long started = currticks();
149  unsigned long elapsed;
150  unsigned int attempts = 0;
151  int current_state;
152  int rc;
153 
154  /* Wait for backend to reach this state */
155  do {
156 
157  /* Get current backend state */
158  current_state = xenbus_backend_state ( xendev );
159  if ( current_state < 0 ) {
160  rc = current_state;
161  return rc;
162  }
163  if ( current_state == state )
164  return 0;
165 
166  /* Allow time for backend to react */
167  cpu_nap();
168 
169  /* XenStore is a very slow interface; any fixed delay
170  * time would be dwarfed by the XenStore access time.
171  * We therefore use wall clock to time out this
172  * operation.
173  */
174  elapsed = ( currticks() - started );
175  attempts++;
176 
177  } while ( elapsed < XENBUS_BACKEND_TIMEOUT );
178 
179  /* Construct status code from current backend state */
180  rc = -ETIMEDOUT_STATE ( current_state );
181  DBGC ( xendev, "XENBUS %s timed out after %d attempts waiting for "
182  "%s/state=\"%d\": %s\n", xendev->key, attempts, xendev->backend,
183  state, strerror ( rc ) );
184 
185  return rc;
186 }
char * backend
Backend XenStore key.
Definition: xenbus.h:26
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t state
State.
Definition: eth_slow.h:47
#define DBGC(...)
Definition: compiler.h:505
static int started
"startup() has been called" flag
Definition: init.c:37
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define ETIMEDOUT_STATE(state)
Definition: xenbus.c:88
void cpu_nap(void)
Sleep until next CPU interrupt.
#define XENBUS_BACKEND_TIMEOUT
Maximum time to wait for backend to reach a given state, in ticks.
Definition: xenbus.c:96
char * key
XenStore key.
Definition: xenbus.h:24
unsigned long currticks(void)
Get current system time in ticks.
Definition: timer.c:42
int xenbus_backend_state(struct xen_device *xendev)
Get backend state.
Definition: xenbus.c:125

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()

static 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 194 of file xenbus.c.

194  {
195  struct xen_driver *xendrv;
196 
197  for_each_table_entry ( xendrv, XEN_DRIVERS ) {
198  if ( strcmp ( xendrv->type, type ) == 0 )
199  return xendrv;
200  }
201  return NULL;
202 }
#define XEN_DRIVERS
Xen device driver table.
Definition: xenbus.h:55
uint8_t type
Type.
Definition: ena.h:16
const char * type
Device type.
Definition: xenbus.h:40
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:172
A Xen device driver.
Definition: xenbus.h:36
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Referenced by xenbus_probe_type().

◆ xenbus_probe_device()

static 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 213 of file xenbus.c.

215  {
216  const char *type = driver->type;
217  struct xen_device *xendev;
218  size_t key_len;
219  int rc;
220 
221  /* Allocate and initialise structure */
222  key_len = ( 7 /* "device/" */ + strlen ( type ) + 1 /* "/" */ +
223  strlen ( instance ) + 1 /* NUL */ );
224  xendev = zalloc ( sizeof ( *xendev ) + key_len );
225  if ( ! xendev ) {
226  rc = -ENOMEM;
227  goto err_alloc;
228  }
229  snprintf ( xendev->dev.name, sizeof ( xendev->dev.name ), "%s/%s",
230  type, instance );
231  xendev->dev.desc.bus_type = BUS_TYPE_XEN;
232  INIT_LIST_HEAD ( &xendev->dev.children );
233  list_add_tail ( &xendev->dev.siblings, &parent->children );
234  xendev->dev.parent = parent;
235  xendev->xen = xen;
236  xendev->key = ( ( void * ) ( xendev + 1 ) );
237  snprintf ( xendev->key, key_len, "device/%s/%s", type, instance );
238  xendev->driver = driver;
239  xendev->dev.driver_name = driver->name;
240  DBGC ( xendev, "XENBUS %s has driver \"%s\"\n", xendev->key,
241  xendev->driver->name );
242 
243  /* Read backend key */
244  if ( ( rc = xenstore_read ( xen, &xendev->backend, xendev->key,
245  "backend", NULL ) ) != 0 ) {
246  DBGC ( xendev, "XENBUS %s could not read backend: %s\n",
247  xendev->key, strerror ( rc ) );
248  goto err_read_backend;
249  }
250 
251  /* Read backend domain ID */
252  if ( ( rc = xenstore_read_num ( xen, &xendev->backend_id, xendev->key,
253  "backend-id", NULL ) ) != 0 ) {
254  DBGC ( xendev, "XENBUS %s could not read backend-id: %s\n",
255  xendev->key, strerror ( rc ) );
256  goto err_read_backend_id;
257  }
258  DBGC ( xendev, "XENBUS %s backend=\"%s\" in domain %ld\n",
259  xendev->key, xendev->backend, xendev->backend_id );
260 
261  /* Probe driver */
262  if ( ( rc = xendev->driver->probe ( xendev ) ) != 0 ) {
263  DBGC ( xendev, "XENBUS could not probe %s: %s\n",
264  xendev->key, strerror ( rc ) );
265  goto err_probe;
266  }
267 
268  return 0;
269 
270  xendev->driver->remove ( xendev );
271  err_probe:
272  err_read_backend_id:
273  free ( xendev->backend );
274  err_read_backend:
275  list_del ( &xendev->dev.siblings );
276  free ( xendev );
277  err_alloc:
278  return rc;
279 }
char * backend
Backend XenStore key.
Definition: xenbus.h:26
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t type
Type.
Definition: ena.h:16
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:75
const char * type
Device type.
Definition: xenbus.h:40
int xenstore_read(struct xen_hypervisor *xen, char **value,...)
Read XenStore value.
Definition: xenstore.c:371
struct device * parent
Bus device.
Definition: device.h:85
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
A Xen device.
Definition: xenbus.h:18
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct xen_driver * driver
Driver.
Definition: xenbus.h:30
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
const char * name
Name.
Definition: xenbus.h:38
const char * driver_name
Driver name.
Definition: device.h:77
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
unsigned long backend_id
Backend domain ID.
Definition: xenbus.h:28
int xenstore_read_num(struct xen_hypervisor *xen, unsigned long *num,...)
Read XenStore numeric value.
Definition: xenstore.c:390
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
int(* probe)(struct xen_device *xendev)
Probe device.
Definition: xenbus.h:46
unsigned int bus_type
Bus type.
Definition: device.h:24
void(* remove)(struct xen_device *xendev)
Remove device.
Definition: xenbus.h:51
struct list_head children
Devices attached to this device.
Definition: device.h:83
char * key
XenStore key.
Definition: xenbus.h:24
struct device_description desc
Device description.
Definition: device.h:79
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
struct device dev
Generic iPXE device.
Definition: xenbus.h:20
#define BUS_TYPE_XEN
Xen bus type.
Definition: device.h:64
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct xen_hypervisor * xen
Xen hypervisor.
Definition: xenbus.h:22

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, xen_driver::name, device::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()

static void xenbus_remove_device ( struct xen_device xendev)
static

Remove Xen device.

Parameters
xendevXen device

Definition at line 286 of file xenbus.c.

286  {
287 
288  /* Remove device */
289  xendev->driver->remove ( xendev );
290  free ( xendev->backend );
291  list_del ( &xendev->dev.siblings );
292  free ( xendev );
293 }
char * backend
Backend XenStore key.
Definition: xenbus.h:26
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct xen_driver * driver
Driver.
Definition: xenbus.h:30
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
void(* remove)(struct xen_device *xendev)
Remove device.
Definition: xenbus.h:51
struct device dev
Generic iPXE device.
Definition: xenbus.h:20

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()

static 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 303 of file xenbus.c.

304  {
305  struct xen_driver *driver;
306  char *children;
307  char *child;
308  size_t len;
309  int rc;
310 
311  /* Look for a driver */
312  driver = xenbus_find_driver ( type );
313  if ( ! driver ) {
314  DBGC ( xen, "XENBUS has no driver for \"%s\" devices\n", type );
315  /* Not a fatal error */
316  rc = 0;
317  goto err_no_driver;
318  }
319 
320  /* Get children of this key */
321  if ( ( rc = xenstore_directory ( xen, &children, &len, "device",
322  type, NULL ) ) != 0 ) {
323  DBGC ( xen, "XENBUS could not list \"%s\" devices: %s\n",
324  type, strerror ( rc ) );
325  goto err_directory;
326  }
327 
328  /* Probe each child */
329  for ( child = children ; child < ( children + len ) ;
330  child += ( strlen ( child ) + 1 /* NUL */ ) ) {
331  if ( ( rc = xenbus_probe_device ( xen, parent, child,
332  driver ) ) != 0 )
333  goto err_probe_device;
334  }
335 
336  free ( children );
337  return 0;
338 
339  err_probe_device:
340  free ( children );
341  err_directory:
342  err_no_driver:
343  return rc;
344 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t type
Type.
Definition: ena.h:16
#define DBGC(...)
Definition: compiler.h:505
char unsigned long const char unsigned long char ** children
Definition: xenstore.h:25
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static struct xen_driver * xenbus_find_driver(const char *type)
Find driver for Xen device.
Definition: xenbus.c:194
int xenstore_directory(struct xen_hypervisor *xen, char **children, size_t *len,...)
Read XenStore directory.
Definition: xenstore.c:503
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
uint32_t len
Length.
Definition: ena.h:14
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:213
A Xen device driver.
Definition: xenbus.h:36
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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 353 of file xenbus.c.

353  {
354  char *types;
355  char *type;
356  size_t len;
357  int rc;
358 
359  /* Get children of "device" key */
360  if ( ( rc = xenstore_directory ( xen, &types, &len, "device",
361  NULL ) ) != 0 ) {
362  DBGC ( xen, "XENBUS could not list device types: %s\n",
363  strerror ( rc ) );
364  goto err_directory;
365  }
366 
367  /* Probe each child type */
368  for ( type = types ; type < ( types + len ) ;
369  type += ( strlen ( type ) + 1 /* NUL */ ) ) {
370  if ( ( rc = xenbus_probe_type ( xen, parent, type ) ) != 0 )
371  goto err_probe_type;
372  }
373 
374  free ( types );
375  return 0;
376 
377  xenbus_remove ( xen, parent );
378  err_probe_type:
379  free ( types );
380  err_directory:
381  return rc;
382 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t type
Type.
Definition: ena.h:16
#define DBGC(...)
Definition: compiler.h:505
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:303
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
int xenstore_directory(struct xen_hypervisor *xen, char **children, size_t *len,...)
Read XenStore directory.
Definition: xenstore.c:503
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
uint32_t len
Length.
Definition: ena.h:14
void xenbus_remove(struct xen_hypervisor *xen __unused, struct device *parent)
Remove Xen bus.
Definition: xenbus.c:390
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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 390 of file xenbus.c.

391  {
392  struct xen_device *xendev;
393  struct xen_device *tmp;
394 
395  /* Remove devices */
396  list_for_each_entry_safe ( xendev, tmp, &parent->children,
397  dev.siblings ) {
398  xenbus_remove_device ( xendev );
399  }
400 }
A Xen device.
Definition: xenbus.h:18
#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:447
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
uint8_t * tmp
Definition: entropy.h:156
struct list_head children
Devices attached to this device.
Definition: device.h:83
struct device dev
Generic iPXE device.
Definition: xenbus.h:20
static void xenbus_remove_device(struct xen_device *xendev)
Remove Xen device.
Definition: xenbus.c:286

References 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().