iPXE
Functions | Variables
xenstore.c File Reference

XenStore interface. More...

#include <stdint.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ipxe/io.h>
#include <ipxe/nap.h>
#include <ipxe/malloc.h>
#include <ipxe/xen.h>
#include <ipxe/xenevent.h>
#include <ipxe/xenstore.h>
#include <xen/io/xs_wire.h>
#include <errno.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void xenstore_send (struct xen_hypervisor *xen, const void *data, size_t len)
 Send XenStore request raw data. More...
 
static void xenstore_send_string (struct xen_hypervisor *xen, const char *string)
 Send XenStore request string (excluding terminating NUL) More...
 
static void xenstore_recv (struct xen_hypervisor *xen, void *data, size_t len)
 Receive XenStore response raw data. More...
 
static int xenstore_request (struct xen_hypervisor *xen, enum xsd_sockmsg_type type, uint32_t req_id, const char *value, va_list key)
 Send XenStore request. More...
 
static int xenstore_response (struct xen_hypervisor *xen, uint32_t req_id, char **value, size_t *len)
 Receive XenStore response. More...
 
static int xenstore_message (struct xen_hypervisor *xen, enum xsd_sockmsg_type type, char **response, size_t *len, const char *request, va_list key)
 Issue a XenStore message. More...
 
static int xenstore_vread (struct xen_hypervisor *xen, char **value, va_list key)
 Read XenStore value. More...
 
int xenstore_read (struct xen_hypervisor *xen, char **value,...)
 Read XenStore value. More...
 
int xenstore_read_num (struct xen_hypervisor *xen, unsigned long *num,...)
 Read XenStore numeric value. More...
 
static int xenstore_vwrite (struct xen_hypervisor *xen, const char *value, va_list key)
 Write XenStore value. More...
 
int xenstore_write (struct xen_hypervisor *xen, const char *value,...)
 Write XenStore value. More...
 
int xenstore_write_num (struct xen_hypervisor *xen, unsigned long num,...)
 Write XenStore numeric value. More...
 
int xenstore_rm (struct xen_hypervisor *xen,...)
 Delete XenStore value. More...
 
int xenstore_directory (struct xen_hypervisor *xen, char **children, size_t *len,...)
 Read XenStore directory. More...
 
void xenstore_dump (struct xen_hypervisor *xen, const char *key)
 Dump XenStore directory contents (for debugging) More...
 

Variables

static uint32_t xenstore_req_id
 Request identifier. More...
 

Detailed Description

XenStore interface.

Definition in file xenstore.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ xenstore_send()

static void xenstore_send ( struct xen_hypervisor xen,
const void *  data,
size_t  len 
)
static

Send XenStore request raw data.

Parameters
xenXen hypervisor
dataData buffer
lenLength of data

Definition at line 64 of file xenstore.c.

65  {
66  struct xenstore_domain_interface *intf = xen->store.intf;
67  XENSTORE_RING_IDX prod = readl ( &intf->req_prod );
70  const char *bytes = data;
71  size_t offset = 0;
72  size_t fill;
73 
74  DBGCP ( intf, "XENSTORE raw request:\n" );
75  DBGCP_HDA ( intf, MASK_XENSTORE_IDX ( prod ), data, len );
76 
77  /* Write one byte at a time */
78  while ( offset < len ) {
79 
80  /* Wait for space to become available */
81  while ( 1 ) {
82  cons = readl ( &intf->req_cons );
83  fill = ( prod - cons );
84  if ( fill < XENSTORE_RING_SIZE )
85  break;
86  DBGC2 ( xen, "." );
87  cpu_nap();
88  rmb();
89  }
90 
91  /* Write byte */
92  idx = MASK_XENSTORE_IDX ( prod++ );
93  writeb ( bytes[offset++], &intf->req[idx] );
94  }
95 
96  /* Update producer counter */
97  wmb();
98  writel ( prod, &intf->req_prod );
99  wmb();
100 }
wmb()
uint32_t XENSTORE_RING_IDX
Definition: xs_wire.h:114
char req[XENSTORE_RING_SIZE]
Definition: xs_wire.h:117
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
#define DBGCP_HDA(...)
Definition: compiler.h:540
#define rmb()
Definition: io.h:484
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
uint16_t cons
Consumer index.
Definition: ena.h:22
XENSTORE_RING_IDX req_prod
Definition: xs_wire.h:119
struct xenstore_domain_interface * intf
XenStore domain interface.
Definition: xen.h:45
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
void cpu_nap(void)
Sleep until next CPU interrupt.
XENSTORE_RING_IDX req_cons
Definition: xs_wire.h:119
uint8_t fill
Length pair.
Definition: deflate.h:12
struct xen_store store
XenStore.
Definition: xen.h:59
#define DBGCP(...)
Definition: compiler.h:539
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define MASK_XENSTORE_IDX(idx)
Definition: xs_wire.h:115
uint8_t bytes[64]
Definition: ib_mad.h:16
#define XENSTORE_RING_SIZE
Definition: xs_wire.h:113

References bytes, cons, cpu_nap(), data, DBGC2, DBGCP, DBGCP_HDA, fill, xen_store::intf, len, MASK_XENSTORE_IDX, offset, readl(), xenstore_domain_interface::req, xenstore_domain_interface::req_cons, xenstore_domain_interface::req_prod, rmb, xen_hypervisor::store, wmb(), writeb(), writel(), and XENSTORE_RING_SIZE.

Referenced by xenstore_request(), and xenstore_send_string().

◆ xenstore_send_string()

static void xenstore_send_string ( struct xen_hypervisor xen,
const char *  string 
)
static

Send XenStore request string (excluding terminating NUL)

Parameters
xenXen hypervisor
stringString

Definition at line 108 of file xenstore.c.

109  {
110 
111  xenstore_send ( xen, string, strlen ( string ) );
112 }
static void xenstore_send(struct xen_hypervisor *xen, const void *data, size_t len)
Send XenStore request raw data.
Definition: xenstore.c:64
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228

References strlen(), and xenstore_send().

Referenced by xenstore_request().

◆ xenstore_recv()

static void xenstore_recv ( struct xen_hypervisor xen,
void *  data,
size_t  len 
)
static

Receive XenStore response raw data.

Parameters
xenXen hypervisor
dataData buffer, or NULL to discard data
lenLength of data

Definition at line 121 of file xenstore.c.

122  {
123  struct xenstore_domain_interface *intf = xen->store.intf;
124  XENSTORE_RING_IDX cons = readl ( &intf->rsp_cons );
125  XENSTORE_RING_IDX prod;
126  XENSTORE_RING_IDX idx;
127  char *bytes = data;
128  size_t offset = 0;
129  size_t fill;
130 
131  DBGCP ( intf, "XENSTORE raw response:\n" );
132 
133  /* Read one byte at a time */
134  while ( offset < len ) {
135 
136  /* Wait for data to be ready */
137  while ( 1 ) {
138  prod = readl ( &intf->rsp_prod );
139  fill = ( prod - cons );
140  if ( fill > 0 )
141  break;
142  DBGC2 ( xen, "." );
143  cpu_nap();
144  rmb();
145  }
146 
147  /* Read byte */
148  idx = MASK_XENSTORE_IDX ( cons++ );
149  if ( data )
150  bytes[offset++] = readb ( &intf->rsp[idx] );
151  }
152  if ( data )
153  DBGCP_HDA ( intf, MASK_XENSTORE_IDX ( cons - len ), data, len );
154 
155  /* Update consumer counter */
156  writel ( cons, &intf->rsp_cons );
157  wmb();
158 }
wmb()
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
uint32_t XENSTORE_RING_IDX
Definition: xs_wire.h:114
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
XENSTORE_RING_IDX rsp_cons
Definition: xs_wire.h:120
#define DBGCP_HDA(...)
Definition: compiler.h:540
#define rmb()
Definition: io.h:484
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
uint16_t cons
Consumer index.
Definition: ena.h:22
XENSTORE_RING_IDX rsp_prod
Definition: xs_wire.h:120
struct xenstore_domain_interface * intf
XenStore domain interface.
Definition: xen.h:45
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
void cpu_nap(void)
Sleep until next CPU interrupt.
uint8_t fill
Length pair.
Definition: deflate.h:12
struct xen_store store
XenStore.
Definition: xen.h:59
#define DBGCP(...)
Definition: compiler.h:539
char rsp[XENSTORE_RING_SIZE]
Definition: xs_wire.h:118
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define MASK_XENSTORE_IDX(idx)
Definition: xs_wire.h:115
uint8_t bytes[64]
Definition: ib_mad.h:16

References bytes, cons, cpu_nap(), data, DBGC2, DBGCP, DBGCP_HDA, fill, xen_store::intf, len, MASK_XENSTORE_IDX, offset, readb(), readl(), rmb, xenstore_domain_interface::rsp, xenstore_domain_interface::rsp_cons, xenstore_domain_interface::rsp_prod, xen_hypervisor::store, wmb(), and writel().

Referenced by xenstore_response().

◆ xenstore_request()

static int xenstore_request ( struct xen_hypervisor xen,
enum xsd_sockmsg_type  type,
uint32_t  req_id,
const char *  value,
va_list  key 
)
static

Send XenStore request.

Parameters
xenXen hypervisor
typeMessage type
req_idRequest ID
valueValue, or NULL to omit
keyKey path components
Return values
rcReturn status code

Definition at line 170 of file xenstore.c.

172  {
173  struct xsd_sockmsg msg;
174  struct evtchn_send event;
175  const char *string;
176  va_list tmp;
177  int xenrc;
178  int rc;
179 
180  /* Construct message header */
181  msg.type = type;
182  msg.req_id = req_id;
183  msg.tx_id = 0;
184  msg.len = 0;
185  DBGC2 ( xen, "XENSTORE request ID %d type %d ", req_id, type );
186 
187  /* Calculate total length */
188  va_copy ( tmp, key );
189  while ( ( string = va_arg ( tmp, const char * ) ) != NULL ) {
190  DBGC2 ( xen, "%s%s", ( msg.len ? "/" : "" ), string );
191  msg.len += ( strlen ( string ) + 1 /* '/' or NUL */ );
192  }
193  va_end ( tmp );
194  if ( value ) {
195  DBGC2 ( xen, " = \"%s\"", value );
196  msg.len += strlen ( value );
197  }
198  DBGC2 ( xen, "\n" );
199 
200  /* Send message */
201  xenstore_send ( xen, &msg, sizeof ( msg ) );
202  string = va_arg ( key, const char * );
203  assert ( string != NULL );
204  xenstore_send_string ( xen, string );
205  while ( ( string = va_arg ( key, const char * ) ) != NULL ) {
206  xenstore_send_string ( xen, "/" );
207  xenstore_send_string ( xen, string );
208  }
209  xenstore_send ( xen, "", 1 ); /* Separating NUL */
210  if ( value )
211  xenstore_send_string ( xen, value );
212 
213  /* Notify the back end */
214  event.port = xen->store.port;
215  if ( ( xenrc = xenevent_send ( xen, &event ) ) != 0 ) {
216  rc = -EXEN ( xenrc );
217  DBGC ( xen, "XENSTORE could not notify back end: %s\n",
218  strerror ( rc ) );
219  return rc;
220  }
221 
222  return 0;
223 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
uint8_t type
Type.
Definition: ena.h:16
#define DBGC(...)
Definition: compiler.h:505
static void xenstore_send(struct xen_hypervisor *xen, const void *data, size_t len)
Send XenStore request raw data.
Definition: xenstore.c:64
uint32_t string
Definition: multiboot.h:14
#define va_copy(dest, src)
Definition: stdarg.h:10
#define EXEN(xenrc)
Convert a Xen status code to an iPXE status code.
Definition: xen.h:87
#define va_arg(ap, type)
Definition: stdarg.h:8
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint8_t * tmp
Definition: entropy.h:156
evtchn_port_t port
Event channel.
Definition: xen.h:47
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
#define DBGC2(...)
Definition: compiler.h:522
__builtin_va_list va_list
Definition: stdarg.h:6
struct xen_store store
XenStore.
Definition: xen.h:59
static void xenstore_send_string(struct xen_hypervisor *xen, const char *string)
Send XenStore request string (excluding terminating NUL)
Definition: xenstore.c:108
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union @376 key
Sense key.
Definition: scsi.h:18
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References assert(), DBGC, DBGC2, EXEN, key, msg(), NULL, xen_store::port, rc, xen_hypervisor::store, strerror(), string, strlen(), tmp, type, va_arg, va_copy, va_end, value, xenstore_send(), and xenstore_send_string().

Referenced by xenstore_message().

◆ xenstore_response()

static int xenstore_response ( struct xen_hypervisor xen,
uint32_t  req_id,
char **  value,
size_t len 
)
static

Receive XenStore response.

Parameters
xenXen hypervisor
req_idRequest ID
valueValue to fill in
lenLength to fill in
Return values
rcReturn status code

The caller is responsible for eventually calling free() on the returned value. Note that the value may comprise multiple NUL-terminated strings concatenated together. A terminating NUL will always be appended to the returned value.

Definition at line 239 of file xenstore.c.

240  {
241  struct xsd_sockmsg msg;
242  char *string;
243  int rc;
244 
245  /* Wait for response to become available */
246  while ( ! xenevent_pending ( xen, xen->store.port ) )
247  cpu_nap();
248 
249  /* Receive message header */
250  xenstore_recv ( xen, &msg, sizeof ( msg ) );
251  *len = msg.len;
252 
253  /* Allocate space for response */
254  *value = zalloc ( msg.len + 1 /* terminating NUL */ );
255 
256  /* Receive data. Do this even if allocation failed, or if the
257  * request ID was incorrect, to avoid leaving data in the
258  * ring.
259  */
260  xenstore_recv ( xen, *value, msg.len );
261 
262  /* Validate request ID */
263  if ( msg.req_id != req_id ) {
264  DBGC ( xen, "XENSTORE response ID mismatch (got %d, expected "
265  "%d)\n", msg.req_id, req_id );
266  rc = -EPROTO;
267  goto err_req_id;
268  }
269 
270  /* Check for allocation failure */
271  if ( ! *value ) {
272  DBGC ( xen, "XENSTORE could not allocate %d bytes for "
273  "response\n", msg.len );
274  rc = -ENOMEM;
275  goto err_alloc;
276  }
277 
278  /* Check for explicit errors */
279  if ( msg.type == XS_ERROR ) {
280  DBGC ( xen, "XENSTORE response error \"%s\"\n", *value );
281  rc = -EIO;
282  goto err_explicit;
283  }
284 
285  DBGC2 ( xen, "XENSTORE response ID %d\n", req_id );
286  if ( DBG_EXTRA ) {
287  for ( string = *value ; string < ( *value + msg.len ) ;
288  string += ( strlen ( string ) + 1 /* NUL */ ) ) {
289  DBGC2 ( xen, " - \"%s\"\n", string );
290  }
291  }
292  return 0;
293 
294  err_explicit:
295  err_alloc:
296  err_req_id:
297  free ( *value );
298  *value = NULL;
299  return rc;
300 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void xenstore_recv(struct xen_hypervisor *xen, void *data, size_t len)
Receive XenStore response raw data.
Definition: xenstore.c:121
#define DBGC(...)
Definition: compiler.h:505
uint32_t string
Definition: multiboot.h:14
uint32_t req_id
Definition: xs_wire.h:96
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define EPROTO
Protocol error.
Definition: errno.h:624
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
evtchn_port_t port
Event channel.
Definition: xen.h:47
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
void cpu_nap(void)
Sleep until next CPU interrupt.
#define EIO
Input/output error.
Definition: errno.h:433
struct xen_store store
XenStore.
Definition: xen.h:59
#define DBG_EXTRA
Definition: compiler.h:319
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285

References cpu_nap(), DBG_EXTRA, DBGC, DBGC2, EIO, ENOMEM, EPROTO, free, len, msg(), NULL, xen_store::port, rc, xsd_sockmsg::req_id, xen_hypervisor::store, string, strlen(), value, xenstore_recv(), XS_ERROR, and zalloc().

Referenced by xenstore_message().

◆ xenstore_message()

static int xenstore_message ( struct xen_hypervisor xen,
enum xsd_sockmsg_type  type,
char **  response,
size_t len,
const char *  request,
va_list  key 
)
static

Issue a XenStore message.

Parameters
xenXen hypervisor
typeMessage type
responseResponse value to fill in, or NULL to discard
lenResponse length to fill in, or NULL to ignore
requestRequest value, or NULL to omit
keyKey path components
Return values
rcReturn status code

Definition at line 313 of file xenstore.c.

315  {
316  char *response_value;
317  size_t response_len;
318  int rc;
319 
320  /* Send request */
321  if ( ( rc = xenstore_request ( xen, type, ++xenstore_req_id,
322  request, key ) ) != 0 )
323  return rc;
324 
325  /* Receive response */
326  if ( ( rc = xenstore_response ( xen, xenstore_req_id, &response_value,
327  &response_len ) ) != 0 )
328  return rc;
329 
330  /* Return response, if applicable */
331  if ( response ) {
332  *response = response_value;
333  } else {
334  free ( response_value );
335  }
336  if ( len )
337  *len = response_len;
338 
339  return 0;
340 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int xenstore_response(struct xen_hypervisor *xen, uint32_t req_id, char **value, size_t *len)
Receive XenStore response.
Definition: xenstore.c:239
uint8_t type
Type.
Definition: ena.h:16
static int xenstore_request(struct xen_hypervisor *xen, enum xsd_sockmsg_type type, uint32_t req_id, const char *value, va_list key)
Send XenStore request.
Definition: xenstore.c:170
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
uint32_t len
Length.
Definition: ena.h:14
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
union @376 key
Sense key.
Definition: scsi.h:18
static uint32_t xenstore_req_id
Request identifier.
Definition: xenstore.c:55

References free, key, len, rc, request, type, xenstore_req_id, xenstore_request(), and xenstore_response().

Referenced by xenstore_directory(), xenstore_rm(), xenstore_vread(), and xenstore_vwrite().

◆ xenstore_vread()

static int xenstore_vread ( struct xen_hypervisor xen,
char **  value,
va_list  key 
)
static

Read XenStore value.

Parameters
xenXen hypervisor
valueValue to fill in
keyKey path components
Return values
rcReturn status code

On a successful return, the caller is responsible for calling free() on the returned value.

Definition at line 353 of file xenstore.c.

354  {
355 
356  return xenstore_message ( xen, XS_READ, value, NULL, NULL, key );
357 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static int xenstore_message(struct xen_hypervisor *xen, enum xsd_sockmsg_type type, char **response, size_t *len, const char *request, va_list key)
Issue a XenStore message.
Definition: xenstore.c:313
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union @376 key
Sense key.
Definition: scsi.h:18

References key, NULL, value, xenstore_message(), and XS_READ.

Referenced by xenstore_read(), and xenstore_read_num().

◆ xenstore_read()

int xenstore_read ( struct xen_hypervisor xen,
char **  value,
  ... 
)

Read XenStore value.

Parameters
xenXen hypervisor
valueValue to fill in
...Key path components
Return values
rcReturn status code

On a successful return, the caller is responsible for calling free() on the returned value.

Definition at line 371 of file xenstore.c.

371  {
372  va_list key;
373  int rc;
374 
375  va_start ( key, value );
376  rc = xenstore_vread ( xen, value, key );
377  va_end ( key );
378  return rc;
379 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
static int xenstore_vread(struct xen_hypervisor *xen, char **value, va_list key)
Read XenStore value.
Definition: xenstore.c:353
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
__builtin_va_list va_list
Definition: stdarg.h:6
#define va_start(ap, last)
Definition: stdarg.h:7
union @376 key
Sense key.
Definition: scsi.h:18

References key, rc, va_end, va_start, value, and xenstore_vread().

Referenced by hvm_map_xenstore(), netfront_read_mac(), xenbus_probe_device(), and xenstore_dump().

◆ xenstore_read_num()

int xenstore_read_num ( struct xen_hypervisor xen,
unsigned long *  num,
  ... 
)

Read XenStore numeric value.

Parameters
xenXen hypervisor
numNumeric value to fill in
...Key path components
Return values
rcReturn status code

Definition at line 390 of file xenstore.c.

390  {
391  va_list key;
392  char *value;
393  char *endp;
394  int rc;
395 
396  /* Try to read text value */
397  va_start ( key, num );
398  rc = xenstore_vread ( xen, &value, key );
399  va_end ( key );
400  if ( rc != 0 )
401  goto err_read;
402 
403  /* Try to parse as numeric value */
404  *num = strtoul ( value, &endp, 10 );
405  if ( ( *value == '\0' ) || ( *endp != '\0' ) ) {
406  DBGC ( xen, "XENSTORE found invalid numeric value \"%s\"\n",
407  value );
408  rc = -EINVAL;
409  goto err_strtoul;
410  }
411 
412  err_strtoul:
413  free ( value );
414  err_read:
415  return rc;
416 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:456
#define DBGC(...)
Definition: compiler.h:505
static int xenstore_vread(struct xen_hypervisor *xen, char **value, va_list key)
Read XenStore value.
Definition: xenstore.c:353
char unsigned long * num
Definition: xenstore.h:17
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
__builtin_va_list va_list
Definition: stdarg.h:6
#define va_start(ap, last)
Definition: stdarg.h:7
union @376 key
Sense key.
Definition: scsi.h:18

References DBGC, EINVAL, free, key, num, rc, strtoul(), va_end, va_start, value, and xenstore_vread().

Referenced by xenbus_backend_state(), and xenbus_probe_device().

◆ xenstore_vwrite()

static int xenstore_vwrite ( struct xen_hypervisor xen,
const char *  value,
va_list  key 
)
static

Write XenStore value.

Parameters
xenXen hypervisor
valueValue
keyKey path components
Return values
rcReturn status code

Definition at line 426 of file xenstore.c.

427  {
428 
429  return xenstore_message ( xen, XS_WRITE, NULL, NULL, value, key );
430 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static int xenstore_message(struct xen_hypervisor *xen, enum xsd_sockmsg_type type, char **response, size_t *len, const char *request, va_list key)
Issue a XenStore message.
Definition: xenstore.c:313
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union @376 key
Sense key.
Definition: scsi.h:18

References key, NULL, value, xenstore_message(), and XS_WRITE.

Referenced by xenstore_write(), and xenstore_write_num().

◆ xenstore_write()

int xenstore_write ( struct xen_hypervisor xen,
const char *  value,
  ... 
)

Write XenStore value.

Parameters
xenXen hypervisor
valueValue
...Key path components
Return values
rcReturn status code

Definition at line 441 of file xenstore.c.

441  {
442  va_list key;
443  int rc;
444 
445  va_start ( key, value );
446  rc = xenstore_vwrite ( xen, value, key );
447  va_end ( key );
448  return rc;
449 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static int xenstore_vwrite(struct xen_hypervisor *xen, const char *value, va_list key)
Write XenStore value.
Definition: xenstore.c:426
__builtin_va_list va_list
Definition: stdarg.h:6
#define va_start(ap, last)
Definition: stdarg.h:7
union @376 key
Sense key.
Definition: scsi.h:18

References key, rc, va_end, va_start, value, and xenstore_vwrite().

◆ xenstore_write_num()

int xenstore_write_num ( struct xen_hypervisor xen,
unsigned long  num,
  ... 
)

Write XenStore numeric value.

Parameters
xenXen hypervisor
numNumeric value
...Key path components
Return values
rcReturn status code

Definition at line 460 of file xenstore.c.

460  {
461  char value[ 21 /* "18446744073709551615" + NUL */ ];
462  va_list key;
463  int rc;
464 
465  /* Construct value */
466  snprintf ( value, sizeof ( value ), "%ld", num );
467 
468  /* Write value */
469  va_start ( key, num );
470  rc = xenstore_vwrite ( xen, value, key );
471  va_end ( key );
472  return rc;
473 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
char unsigned long * num
Definition: xenstore.h:17
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static int xenstore_vwrite(struct xen_hypervisor *xen, const char *value, va_list key)
Write XenStore value.
Definition: xenstore.c:426
__builtin_va_list va_list
Definition: stdarg.h:6
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
#define va_start(ap, last)
Definition: stdarg.h:7
union @376 key
Sense key.
Definition: scsi.h:18

References key, num, rc, snprintf(), va_end, va_start, value, and xenstore_vwrite().

Referenced by netfront_write_num(), and xenbus_set_state().

◆ xenstore_rm()

int xenstore_rm ( struct xen_hypervisor xen,
  ... 
)

Delete XenStore value.

Parameters
xenXen hypervisor
...Key path components
Return values
rcReturn status code

Definition at line 483 of file xenstore.c.

483  {
484  va_list key;
485  int rc;
486 
487  va_start ( key, xen );
488  rc = xenstore_message ( xen, XS_RM, NULL, NULL, NULL, key );
489  va_end ( key );
490  return rc;
491 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
Definition: xs_wire.h:46
static int xenstore_message(struct xen_hypervisor *xen, enum xsd_sockmsg_type type, char **response, size_t *len, const char *request, va_list key)
Issue a XenStore message.
Definition: xenstore.c:313
__builtin_va_list va_list
Definition: stdarg.h:6
#define va_start(ap, last)
Definition: stdarg.h:7
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union @376 key
Sense key.
Definition: scsi.h:18

References key, NULL, rc, va_end, va_start, xenstore_message(), and XS_RM.

Referenced by netfront_rm().

◆ xenstore_directory()

int xenstore_directory ( struct xen_hypervisor xen,
char **  children,
size_t len,
  ... 
)

Read XenStore directory.

Parameters
xenXen hypervisor
childrenChild key names to fill in
lenLength of child key names to fill in
...Key path components
Return values
rcReturn status code

Definition at line 503 of file xenstore.c.

504  {
505  va_list key;
506  int rc;
507 
508  va_start ( key, len );
510  va_end ( key );
511  return rc;
512 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
char unsigned long const char unsigned long char ** children
Definition: xenstore.h:25
static int xenstore_message(struct xen_hypervisor *xen, enum xsd_sockmsg_type type, char **response, size_t *len, const char *request, va_list key)
Issue a XenStore message.
Definition: xenstore.c:313
uint32_t len
Length.
Definition: ena.h:14
__builtin_va_list va_list
Definition: stdarg.h:6
#define va_start(ap, last)
Definition: stdarg.h:7
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union @376 key
Sense key.
Definition: scsi.h:18

References children, key, len, NULL, rc, va_end, va_start, xenstore_message(), and XS_DIRECTORY.

Referenced by xenbus_probe(), xenbus_probe_type(), and xenstore_dump().

◆ xenstore_dump()

void xenstore_dump ( struct xen_hypervisor xen,
const char *  key 
)

Dump XenStore directory contents (for debugging)

Parameters
xenXen hypervisor
keyKey

Definition at line 520 of file xenstore.c.

520  {
521  char *value;
522  char *children;
523  char *child;
524  char *child_key;
525  size_t len;
526  int rc;
527 
528  /* Try to dump current key as a value */
529  if ( ( rc = xenstore_read ( xen, &value, key, NULL ) ) == 0 ) {
530  DBGC ( xen, "%s = \"%s\"\n", key, value );
531  free ( value );
532  }
533 
534  /* Try to recurse into each child in turn */
535  if ( ( rc = xenstore_directory ( xen, &children, &len, key,
536  NULL ) ) == 0 ) {
537  for ( child = children ; child < ( children + len ) ;
538  child += ( strlen ( child ) + 1 /* NUL */ ) ) {
539 
540  /* Construct child key */
541  if ( asprintf ( &child_key, "%s/%s", key, child ) < 0 ){
542  DBGC ( xen, "XENSTORE could not allocate child "
543  "key \"%s/%s\"\n", key, child );
544  rc = -ENOMEM;
545  break;
546  }
547 
548  /* Recurse into child key, continuing on error */
549  xenstore_dump ( xen, child_key );
550  free ( child_key );
551  }
552  free ( children );
553  }
554 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
int xenstore_read(struct xen_hypervisor *xen, char **value,...)
Read XenStore value.
Definition: xenstore.c:371
#define ENOMEM
Not enough space.
Definition: errno.h:534
char unsigned long const char unsigned long char ** children
Definition: xenstore.h:25
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
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
int asprintf(char **strp, const char *fmt,...)
Write a formatted string to newly allocated memory.
Definition: asprintf.c:41
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
void xenstore_dump(struct xen_hypervisor *xen, const char *key)
Dump XenStore directory contents (for debugging)
Definition: xenstore.c:520
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union @376 key
Sense key.
Definition: scsi.h:18

References asprintf(), children, DBGC, ENOMEM, free, key, len, NULL, rc, strlen(), value, xenstore_directory(), xenstore_dump(), and xenstore_read().

Referenced by xenstore_dump().

Variable Documentation

◆ xenstore_req_id

uint32_t xenstore_req_id
static

Request identifier.

Definition at line 55 of file xenstore.c.

Referenced by xenstore_message().