iPXE
Macros | Functions
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. 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 44 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 46 of file xenbus.c.

◆ ETIMEDOUT_INITIALISING

#define ETIMEDOUT_INITIALISING   __einfo_error ( EINFO_ETIMEDOUT_INITIALISING )

Definition at line 49 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 51 of file xenbus.c.

◆ ETIMEDOUT_INITWAIT

#define ETIMEDOUT_INITWAIT   __einfo_error ( EINFO_ETIMEDOUT_INITWAIT )

Definition at line 54 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 56 of file xenbus.c.

◆ ETIMEDOUT_INITIALISED

#define ETIMEDOUT_INITIALISED   __einfo_error ( EINFO_ETIMEDOUT_INITIALISED )

Definition at line 59 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 61 of file xenbus.c.

◆ ETIMEDOUT_CONNECTED

#define ETIMEDOUT_CONNECTED   __einfo_error ( EINFO_ETIMEDOUT_CONNECTED )

Definition at line 64 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 66 of file xenbus.c.

◆ ETIMEDOUT_CLOSING

#define ETIMEDOUT_CLOSING   __einfo_error ( EINFO_ETIMEDOUT_CLOSING )

Definition at line 69 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 71 of file xenbus.c.

◆ ETIMEDOUT_CLOSED

#define ETIMEDOUT_CLOSED   __einfo_error ( EINFO_ETIMEDOUT_CLOSED )

Definition at line 74 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 76 of file xenbus.c.

◆ ETIMEDOUT_RECONFIGURING

#define ETIMEDOUT_RECONFIGURING   __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURING )

Definition at line 79 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 81 of file xenbus.c.

◆ ETIMEDOUT_RECONFIGURED

#define ETIMEDOUT_RECONFIGURED   __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURED )

Definition at line 84 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 86 of file xenbus.c.

◆ ETIMEDOUT_STATE

#define ETIMEDOUT_STATE (   state)
Value:
#define ETIMEDOUT_INITWAIT
Definition: xenbus.c:54
uint8_t state
State.
Definition: eth_slow.h:47
#define ETIMEDOUT_INITIALISED
Definition: xenbus.c:59
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define ETIMEDOUT_RECONFIGURING
Definition: xenbus.c:79
#define ETIMEDOUT_RECONFIGURED
Definition: xenbus.c:84
#define ETIMEDOUT_CONNECTED
Definition: xenbus.c:64
#define ETIMEDOUT_INITIALISING
Definition: xenbus.c:49
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition: errno.h:225
#define ETIMEDOUT_UNKNOWN
Definition: xenbus.c:44
#define ETIMEDOUT_CLOSING
Definition: xenbus.c:69
#define ETIMEDOUT_CLOSED
Definition: xenbus.c:74

Definition at line 89 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 97 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 106 of file xenbus.c.

106  {
107  int rc;
108 
109  /* Attempt to set state */
110  if ( ( rc = xenstore_write_num ( xendev->xen, state, xendev->key,
111  "state", NULL ) ) != 0 ) {
112  DBGC ( xendev, "XENBUS %s could not set state=\"%d\": %s\n",
113  xendev->key, state, strerror ( rc ) );
114  return rc;
115  }
116 
117  return 0;
118 }
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:321
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 126 of file xenbus.c.

126  {
127  unsigned long state;
128  int rc;
129 
130  /* Attempt to get backend state */
131  if ( ( rc = xenstore_read_num ( xendev->xen, &state, xendev->backend,
132  "state", NULL ) ) != 0 ) {
133  DBGC ( xendev, "XENBUS %s could not read %s/state: %s\n",
134  xendev->key, xendev->backend, strerror ( rc ) );
135  return rc;
136  }
137 
138  return state;
139 }
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:321
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 148 of file xenbus.c.

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

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

195  {
196  struct xen_driver *xendrv;
197 
198  for_each_table_entry ( xendrv, XEN_DRIVERS ) {
199  if ( strcmp ( xendrv->type, type ) == 0 )
200  return xendrv;
201  }
202  return NULL;
203 }
#define XEN_DRIVERS
Xen device driver table.
Definition: xenbus.h:55
uint32_t type
Operating system type.
Definition: ena.h:12
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:385
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
A Xen device driver.
Definition: xenbus.h:36
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

216  {
217  const char *type = driver->type;
218  struct xen_device *xendev;
219  size_t key_len;
220  int rc;
221 
222  /* Allocate and initialise structure */
223  key_len = ( 7 /* "device/" */ + strlen ( type ) + 1 /* "/" */ +
224  strlen ( instance ) + 1 /* NUL */ );
225  xendev = zalloc ( sizeof ( *xendev ) + key_len );
226  if ( ! xendev ) {
227  rc = -ENOMEM;
228  goto err_alloc;
229  }
230  snprintf ( xendev->dev.name, sizeof ( xendev->dev.name ), "%s/%s",
231  type, instance );
232  xendev->dev.desc.bus_type = BUS_TYPE_XEN;
233  INIT_LIST_HEAD ( &xendev->dev.children );
234  list_add_tail ( &xendev->dev.siblings, &parent->children );
235  xendev->dev.parent = parent;
236  xendev->xen = xen;
237  xendev->key = ( ( void * ) ( xendev + 1 ) );
238  snprintf ( xendev->key, key_len, "device/%s/%s", type, instance );
239  xendev->driver = driver;
240  xendev->dev.driver_name = driver->name;
241  DBGC ( xendev, "XENBUS %s has driver \"%s\"\n", xendev->key,
242  xendev->driver->name );
243 
244  /* Read backend key */
245  if ( ( rc = xenstore_read ( xen, &xendev->backend, xendev->key,
246  "backend", NULL ) ) != 0 ) {
247  DBGC ( xendev, "XENBUS %s could not read backend: %s\n",
248  xendev->key, strerror ( rc ) );
249  goto err_read_backend;
250  }
251 
252  /* Read backend domain ID */
253  if ( ( rc = xenstore_read_num ( xen, &xendev->backend_id, xendev->key,
254  "backend-id", NULL ) ) != 0 ) {
255  DBGC ( xendev, "XENBUS %s could not read backend-id: %s\n",
256  xendev->key, strerror ( rc ) );
257  goto err_read_backend_id;
258  }
259  DBGC ( xendev, "XENBUS %s backend=\"%s\" in domain %ld\n",
260  xendev->key, xendev->backend, xendev->backend_id );
261 
262  /* Probe driver */
263  if ( ( rc = xendev->driver->probe ( xendev ) ) != 0 ) {
264  DBGC ( xendev, "XENBUS could not probe %s: %s\n",
265  xendev->key, strerror ( rc ) );
266  goto err_probe;
267  }
268 
269  return 0;
270 
271  xendev->driver->remove ( xendev );
272  err_probe:
273  err_read_backend_id:
274  free ( xendev->backend );
275  err_read_backend:
276  list_del ( &xendev->dev.siblings );
277  free ( xendev );
278  err_alloc:
279  return rc;
280 }
char * backend
Backend XenStore key.
Definition: xenbus.h:26
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:78
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:88
#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:80
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:661
struct list_head siblings
Devices on the same bus.
Definition: device.h:84
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:243
#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:86
char * key
XenStore key.
Definition: xenbus.h:24
struct device_description desc
Device description.
Definition: device.h:82
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:321
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 287 of file xenbus.c.

287  {
288 
289  /* Remove device */
290  xendev->driver->remove ( xendev );
291  free ( xendev->backend );
292  list_del ( &xendev->dev.siblings );
293  free ( xendev );
294 }
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:84
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 304 of file xenbus.c.

305  {
306  struct xen_driver *driver;
307  char *children;
308  char *child;
309  size_t len;
310  int rc;
311 
312  /* Look for a driver */
313  driver = xenbus_find_driver ( type );
314  if ( ! driver ) {
315  DBGC ( xen, "XENBUS has no driver for \"%s\" devices\n", type );
316  /* Not a fatal error */
317  rc = 0;
318  goto err_no_driver;
319  }
320 
321  /* Get children of this key */
322  if ( ( rc = xenstore_directory ( xen, &children, &len, "device",
323  type, NULL ) ) != 0 ) {
324  DBGC ( xen, "XENBUS could not list \"%s\" devices: %s\n",
325  type, strerror ( rc ) );
326  goto err_directory;
327  }
328 
329  /* Probe each child */
330  for ( child = children ; child < ( children + len ) ;
331  child += ( strlen ( child ) + 1 /* NUL */ ) ) {
332  if ( ( rc = xenbus_probe_device ( xen, parent, child,
333  driver ) ) != 0 )
334  goto err_probe_device;
335  }
336 
337  free ( children );
338  return 0;
339 
340  err_probe_device:
341  free ( children );
342  err_directory:
343  err_no_driver:
344  return rc;
345 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
#define DBGC(...)
Definition: compiler.h:505
char unsigned long const char unsigned long char ** children
Definition: xenstore.h:25
ring len
Length.
Definition: dwmac.h:231
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:195
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:243
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:214
A Xen device driver.
Definition: xenbus.h:36
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

354  {
355  char *types;
356  char *type;
357  size_t len;
358  int rc;
359 
360  /* Get children of "device" key */
361  if ( ( rc = xenstore_directory ( xen, &types, &len, "device",
362  NULL ) ) != 0 ) {
363  DBGC ( xen, "XENBUS could not list device types: %s\n",
364  strerror ( rc ) );
365  goto err_directory;
366  }
367 
368  /* Probe each child type */
369  for ( type = types ; type < ( types + len ) ;
370  type += ( strlen ( type ) + 1 /* NUL */ ) ) {
371  if ( ( rc = xenbus_probe_type ( xen, parent, type ) ) != 0 )
372  goto err_probe_type;
373  }
374 
375  free ( types );
376  return 0;
377 
378  xenbus_remove ( xen, parent );
379  err_probe_type:
380  free ( types );
381  err_directory:
382  return rc;
383 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
#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:304
ring len
Length.
Definition: dwmac.h:231
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:243
void xenbus_remove(struct xen_hypervisor *xen __unused, struct device *parent)
Remove Xen bus.
Definition: xenbus.c:391
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

392  {
393  struct xen_device *xendev;
394  struct xen_device *tmp;
395 
396  /* Remove devices */
397  list_for_each_entry_safe ( xendev, tmp, &parent->children,
398  dev.siblings ) {
399  xenbus_remove_device ( xendev );
400  }
401 }
unsigned long tmp
Definition: linux_pci.h:64
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:458
struct list_head siblings
Devices on the same bus.
Definition: device.h:84
struct list_head children
Devices attached to this device.
Definition: device.h:86
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:287

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