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)
 
 FILE_SECBOOT (PERMITTED)
 
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 45 of file xenbus.c.

◆ EINFO_ETIMEDOUT_UNKNOWN

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

Definition at line 47 of file xenbus.c.

◆ ETIMEDOUT_INITIALISING

#define ETIMEDOUT_INITIALISING   __einfo_error ( EINFO_ETIMEDOUT_INITIALISING )

Definition at line 50 of file xenbus.c.

◆ EINFO_ETIMEDOUT_INITIALISING

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

Definition at line 52 of file xenbus.c.

◆ ETIMEDOUT_INITWAIT

#define ETIMEDOUT_INITWAIT   __einfo_error ( EINFO_ETIMEDOUT_INITWAIT )

Definition at line 55 of file xenbus.c.

◆ EINFO_ETIMEDOUT_INITWAIT

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

Definition at line 57 of file xenbus.c.

◆ ETIMEDOUT_INITIALISED

#define ETIMEDOUT_INITIALISED   __einfo_error ( EINFO_ETIMEDOUT_INITIALISED )

Definition at line 60 of file xenbus.c.

◆ EINFO_ETIMEDOUT_INITIALISED

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

Definition at line 62 of file xenbus.c.

◆ ETIMEDOUT_CONNECTED

#define ETIMEDOUT_CONNECTED   __einfo_error ( EINFO_ETIMEDOUT_CONNECTED )

Definition at line 65 of file xenbus.c.

◆ EINFO_ETIMEDOUT_CONNECTED

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

Definition at line 67 of file xenbus.c.

◆ ETIMEDOUT_CLOSING

#define ETIMEDOUT_CLOSING   __einfo_error ( EINFO_ETIMEDOUT_CLOSING )

Definition at line 70 of file xenbus.c.

◆ EINFO_ETIMEDOUT_CLOSING

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

Definition at line 72 of file xenbus.c.

◆ ETIMEDOUT_CLOSED

#define ETIMEDOUT_CLOSED   __einfo_error ( EINFO_ETIMEDOUT_CLOSED )

Definition at line 75 of file xenbus.c.

◆ EINFO_ETIMEDOUT_CLOSED

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

Definition at line 77 of file xenbus.c.

◆ ETIMEDOUT_RECONFIGURING

#define ETIMEDOUT_RECONFIGURING   __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURING )

Definition at line 80 of file xenbus.c.

◆ EINFO_ETIMEDOUT_RECONFIGURING

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

Definition at line 82 of file xenbus.c.

◆ ETIMEDOUT_RECONFIGURED

#define ETIMEDOUT_RECONFIGURED   __einfo_error ( EINFO_ETIMEDOUT_RECONFIGURED )

Definition at line 85 of file xenbus.c.

◆ EINFO_ETIMEDOUT_RECONFIGURED

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

Definition at line 87 of file xenbus.c.

◆ ETIMEDOUT_STATE

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

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

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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t state
State.
Definition: eth_slow.h:48
#define DBGC(...)
Definition: compiler.h:505
int xenstore_write_num(struct xen_hypervisor *xen, unsigned long num,...)
Write XenStore numeric value.
Definition: xenstore.c:461
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
char * key
XenStore key.
Definition: xenbus.h:25
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct xen_hypervisor * xen
Xen hypervisor.
Definition: xenbus.h:23

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 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
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t state
State.
Definition: eth_slow.h:48
#define DBGC(...)
Definition: compiler.h:505
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
int xenstore_read_num(struct xen_hypervisor *xen, unsigned long *num,...)
Read XenStore numeric value.
Definition: xenstore.c:391
char * key
XenStore key.
Definition: xenbus.h:25
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct xen_hypervisor * xen
Xen hypervisor.
Definition: xenbus.h:23

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 }
char * backend
Backend XenStore key.
Definition: xenbus.h:27
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t state
State.
Definition: eth_slow.h:48
#define DBGC(...)
Definition: compiler.h:505
static int started
"startup() has been called" flag
Definition: init.c:38
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
#define ETIMEDOUT_STATE(state)
Definition: xenbus.c:90
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:98
char * key
XenStore key.
Definition: xenbus.h:25
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

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

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

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 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 }
char * backend
Backend XenStore key.
Definition: xenbus.h:27
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:79
const char * type
Device type.
Definition: xenbus.h:41
int xenstore_read(struct xen_hypervisor *xen, char **value,...)
Read XenStore value.
Definition: xenstore.c:372
struct device * parent
Bus device.
Definition: device.h:89
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
A Xen device.
Definition: xenbus.h:19
#define ENOMEM
Not enough space.
Definition: errno.h:535
struct xen_driver * driver
Driver.
Definition: xenbus.h:31
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:94
const char * name
Name.
Definition: xenbus.h:39
const char * driver_name
Driver name.
Definition: device.h:81
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
struct list_head siblings
Devices on the same bus.
Definition: device.h:85
unsigned long backend_id
Backend domain ID.
Definition: xenbus.h:29
int xenstore_read_num(struct xen_hypervisor *xen, unsigned long *num,...)
Read XenStore numeric value.
Definition: xenstore.c:391
size_t strlen(const char *src)
Get length of string.
Definition: string.c:244
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
int(* probe)(struct xen_device *xendev)
Probe device.
Definition: xenbus.h:47
unsigned int bus_type
Bus type.
Definition: device.h:25
void(* remove)(struct xen_device *xendev)
Remove device.
Definition: xenbus.h:52
struct list_head children
Devices attached to this device.
Definition: device.h:87
char * key
XenStore key.
Definition: xenbus.h:25
struct device_description desc
Device description.
Definition: device.h:83
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383
struct device dev
Generic iPXE device.
Definition: xenbus.h:21
#define BUS_TYPE_XEN
Xen bus type.
Definition: device.h:65
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct xen_hypervisor * xen
Xen hypervisor.
Definition: xenbus.h:23

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 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 }
char * backend
Backend XenStore key.
Definition: xenbus.h:27
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
struct xen_driver * driver
Driver.
Definition: xenbus.h:31
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
struct list_head siblings
Devices on the same bus.
Definition: device.h:85
void(* remove)(struct xen_device *xendev)
Remove device.
Definition: xenbus.h:52
struct device dev
Generic iPXE device.
Definition: xenbus.h:21

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 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 }
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:26
ring len
Length.
Definition: dwmac.h:231
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
static struct xen_driver * xenbus_find_driver(const char *type)
Find driver for Xen device.
Definition: xenbus.c:196
int xenstore_directory(struct xen_hypervisor *xen, char **children, size_t *len,...)
Read XenStore directory.
Definition: xenstore.c:504
size_t strlen(const char *src)
Get length of string.
Definition: string.c:244
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
A Xen device driver.
Definition: xenbus.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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 }
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:305
ring len
Length.
Definition: dwmac.h:231
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
int xenstore_directory(struct xen_hypervisor *xen, char **children, size_t *len,...)
Read XenStore directory.
Definition: xenstore.c:504
size_t strlen(const char *src)
Get length of string.
Definition: string.c:244
void xenbus_remove(struct xen_hypervisor *xen __unused, struct device *parent)
Remove Xen bus.
Definition: xenbus.c:392
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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
A Xen device.
Definition: xenbus.h:19
#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
struct list_head siblings
Devices on the same bus.
Definition: device.h:85
struct list_head children
Devices attached to this device.
Definition: device.h:87
struct device dev
Generic iPXE device.
Definition: xenbus.h:21
static void xenbus_remove_device(struct xen_device *xendev)
Remove Xen device.
Definition: xenbus.c:288

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