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

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 65 of file xenstore.c.

66  {
67  struct xenstore_domain_interface *intf = xen->store.intf;
68  XENSTORE_RING_IDX prod = readl ( &intf->req_prod );
71  const char *bytes = data;
72  size_t offset;
73  size_t fill;
74 
75  DBGCP ( intf, "XENSTORE raw request:\n" );
76  DBGCP_HDA ( intf, MASK_XENSTORE_IDX ( prod ), data, len );
77 
78  /* Write one byte at a time */
79  for ( offset = 0 ; offset < len ; offset++ ) {
80 
81  /* Wait for space to become available */
82  while ( 1 ) {
83  cons = readl ( &intf->req_cons );
84  fill = ( prod - cons );
85  if ( fill < XENSTORE_RING_SIZE )
86  break;
87  DBGC2 ( xen, "." );
88  cpu_nap();
89  rmb();
90  }
91 
92  /* Write byte */
93  idx = MASK_XENSTORE_IDX ( prod++ );
94  writeb ( bytes[offset], &intf->req[idx] );
95  }
96 
97  /* Update producer counter */
98  wmb();
99  writel ( prod, &intf->req_prod );
100  wmb();
101 }
wmb()
uint32_t XENSTORE_RING_IDX
Definition: xs_wire.h:106
char req[XENSTORE_RING_SIZE]
Definition: xs_wire.h:109
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:545
ring len
Length.
Definition: dwmac.h:231
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
uint16_t cons
Consumer index.
Definition: ena.h:22
XENSTORE_RING_IDX req_prod
Definition: xs_wire.h:111
struct xenstore_domain_interface * intf
XenStore domain interface.
Definition: xen.h:45
#define DBGC2(...)
Definition: compiler.h:522
void cpu_nap(void)
Sleep with interrupts enabled until next CPU interrupt.
XENSTORE_RING_IDX req_cons
Definition: xs_wire.h:111
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct xen_store store
XenStore.
Definition: xen.h:59
#define DBGCP(...)
Definition: compiler.h:539
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
#define MASK_XENSTORE_IDX(idx)
Definition: xs_wire.h:107
uint8_t bytes[64]
Definition: ib_mad.h:17
#define XENSTORE_RING_SIZE
Definition: xs_wire.h:105
static int fill
Definition: string.h:209

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 109 of file xenstore.c.

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

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 122 of file xenstore.c.

123  {
124  struct xenstore_domain_interface *intf = xen->store.intf;
125  XENSTORE_RING_IDX cons = readl ( &intf->rsp_cons );
126  XENSTORE_RING_IDX prod;
127  XENSTORE_RING_IDX idx;
128  char *bytes = data;
129  size_t offset;
130  size_t fill;
131 
132  DBGCP ( intf, "XENSTORE raw response:\n" );
133 
134  /* Read one byte at a time */
135  for ( offset = 0 ; offset < len ; offset++ ) {
136 
137  /* Wait for data to be ready */
138  while ( 1 ) {
139  prod = readl ( &intf->rsp_prod );
140  fill = ( prod - cons );
141  if ( fill > 0 )
142  break;
143  DBGC2 ( xen, "." );
144  cpu_nap();
145  rmb();
146  }
147 
148  /* Read byte */
149  idx = MASK_XENSTORE_IDX ( cons++ );
150  if ( data )
151  bytes[offset] = readb ( &intf->rsp[idx] );
152  }
153  if ( data )
154  DBGCP_HDA ( intf, MASK_XENSTORE_IDX ( cons - len ), data, len );
155 
156  /* Update consumer counter */
157  writel ( cons, &intf->rsp_cons );
158  wmb();
159 }
wmb()
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
uint32_t XENSTORE_RING_IDX
Definition: xs_wire.h:106
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:112
#define DBGCP_HDA(...)
Definition: compiler.h:540
#define rmb()
Definition: io.h:545
ring len
Length.
Definition: dwmac.h:231
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
uint16_t cons
Consumer index.
Definition: ena.h:22
XENSTORE_RING_IDX rsp_prod
Definition: xs_wire.h:112
struct xenstore_domain_interface * intf
XenStore domain interface.
Definition: xen.h:45
#define DBGC2(...)
Definition: compiler.h:522
void cpu_nap(void)
Sleep with interrupts enabled until next CPU interrupt.
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct xen_store store
XenStore.
Definition: xen.h:59
#define DBGCP(...)
Definition: compiler.h:539
char rsp[XENSTORE_RING_SIZE]
Definition: xs_wire.h:110
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
#define MASK_XENSTORE_IDX(idx)
Definition: xs_wire.h:107
uint8_t bytes[64]
Definition: ib_mad.h:17
static int fill
Definition: string.h:209

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 171 of file xenstore.c.

173  {
174  struct xsd_sockmsg msg;
175  struct evtchn_send event;
176  const char *string;
177  va_list tmp;
178  int xenrc;
179  int rc;
180 
181  /* Construct message header */
182  msg.type = type;
183  msg.req_id = req_id;
184  msg.tx_id = 0;
185  msg.len = 0;
186  DBGC2 ( xen, "XENSTORE request ID %d type %d ", req_id, type );
187 
188  /* Calculate total length */
189  va_copy ( tmp, key );
190  while ( ( string = va_arg ( tmp, const char * ) ) != NULL ) {
191  DBGC2 ( xen, "%s%s", ( msg.len ? "/" : "" ), string );
192  msg.len += ( strlen ( string ) + 1 /* '/' or NUL */ );
193  }
194  va_end ( tmp );
195  if ( value ) {
196  DBGC2 ( xen, " = \"%s\"", value );
197  msg.len += strlen ( value );
198  }
199  DBGC2 ( xen, "\n" );
200 
201  /* Send message */
202  xenstore_send ( xen, &msg, sizeof ( msg ) );
203  string = va_arg ( key, const char * );
204  assert ( string != NULL );
205  xenstore_send_string ( xen, string );
206  while ( ( string = va_arg ( key, const char * ) ) != NULL ) {
207  xenstore_send_string ( xen, "/" );
208  xenstore_send_string ( xen, string );
209  }
210  xenstore_send ( xen, "", 1 ); /* Separating NUL */
211  if ( value )
212  xenstore_send_string ( xen, value );
213 
214  /* Notify the back end */
215  event.port = xen->store.port;
216  if ( ( xenrc = xenevent_send ( xen, &event ) ) != 0 ) {
217  rc = -EXEN ( xenrc );
218  DBGC ( xen, "XENSTORE could not notify back end: %s\n",
219  strerror ( rc ) );
220  return rc;
221  }
222 
223  return 0;
224 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:10
void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: message.c:62
uint32_t type
Operating system type.
Definition: ena.h:12
#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:65
uint32_t string
Definition: multiboot.h:14
#define va_copy(dest, src)
Definition: stdarg.h:11
#define EXEN(xenrc)
Convert a Xen status code to an iPXE status code.
Definition: xen.h:87
unsigned long tmp
Definition: linux_pci.h:65
#define va_arg(ap, type)
Definition: stdarg.h:9
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:79
evtchn_port_t port
Event channel.
Definition: xen.h:47
size_t strlen(const char *src)
Get length of string.
Definition: string.c:244
#define DBGC2(...)
Definition: compiler.h:522
__builtin_va_list va_list
Definition: stdarg.h:7
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:109
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
union @391 key
Sense key.
Definition: scsi.h:18

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 240 of file xenstore.c.

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

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 314 of file xenstore.c.

316  {
317  char *response_value;
318  size_t response_len;
319  int rc;
320 
321  /* Send request */
322  if ( ( rc = xenstore_request ( xen, type, ++xenstore_req_id,
323  request, key ) ) != 0 )
324  return rc;
325 
326  /* Receive response */
327  if ( ( rc = xenstore_response ( xen, xenstore_req_id, &response_value,
328  &response_len ) ) != 0 )
329  return rc;
330 
331  /* Return response, if applicable */
332  if ( response ) {
333  *response = response_value;
334  } else {
335  free ( response_value );
336  }
337  if ( len )
338  *len = response_len;
339 
340  return 0;
341 }
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:240
uint32_t type
Operating system type.
Definition: ena.h:12
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:171
ring len
Length.
Definition: dwmac.h:231
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
union @391 key
Sense key.
Definition: scsi.h:18
static uint32_t xenstore_req_id
Request identifier.
Definition: xenstore.c:56

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

355  {
356 
357  return xenstore_message ( xen, XS_READ, value, NULL, NULL, key );
358 }
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:314
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
union @391 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 372 of file xenstore.c.

372  {
373  va_list key;
374  int rc;
375 
376  va_start ( key, value );
377  rc = xenstore_vread ( xen, value, key );
378  va_end ( key );
379  return rc;
380 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:10
static int xenstore_vread(struct xen_hypervisor *xen, char **value, va_list key)
Read XenStore value.
Definition: xenstore.c:354
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
__builtin_va_list va_list
Definition: stdarg.h:7
#define va_start(ap, last)
Definition: stdarg.h:8
union @391 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 391 of file xenstore.c.

391  {
392  va_list key;
393  char *value;
394  char *endp;
395  int rc;
396 
397  /* Try to read text value */
398  va_start ( key, num );
399  rc = xenstore_vread ( xen, &value, key );
400  va_end ( key );
401  if ( rc != 0 )
402  goto err_read;
403 
404  /* Try to parse as numeric value */
405  *num = strtoul ( value, &endp, 10 );
406  if ( ( *value == '\0' ) || ( *endp != '\0' ) ) {
407  DBGC ( xen, "XENSTORE found invalid numeric value \"%s\"\n",
408  value );
409  rc = -EINVAL;
410  goto err_strtoul;
411  }
412 
413  err_strtoul:
414  free ( value );
415  err_read:
416  return rc;
417 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:10
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:485
#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:354
uint32_t num
Definition: multiboot.h:12
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
__builtin_va_list va_list
Definition: stdarg.h:7
#define va_start(ap, last)
Definition: stdarg.h:8
union @391 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 427 of file xenstore.c.

428  {
429 
430  return xenstore_message ( xen, XS_WRITE, NULL, NULL, value, key );
431 }
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:314
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
union @391 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 442 of file xenstore.c.

442  {
443  va_list key;
444  int rc;
445 
446  va_start ( key, value );
447  rc = xenstore_vwrite ( xen, value, key );
448  va_end ( key );
449  return rc;
450 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:10
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:427
__builtin_va_list va_list
Definition: stdarg.h:7
#define va_start(ap, last)
Definition: stdarg.h:8
union @391 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 461 of file xenstore.c.

461  {
462  char value[ 21 /* "18446744073709551615" + NUL */ ];
463  va_list key;
464  int rc;
465 
466  /* Construct value */
467  snprintf ( value, sizeof ( value ), "%ld", num );
468 
469  /* Write value */
470  va_start ( key, num );
471  rc = xenstore_vwrite ( xen, value, key );
472  va_end ( key );
473  return rc;
474 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:10
uint32_t num
Definition: multiboot.h:12
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:427
__builtin_va_list va_list
Definition: stdarg.h:7
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383
#define va_start(ap, last)
Definition: stdarg.h:8
union @391 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 484 of file xenstore.c.

484  {
485  va_list key;
486  int rc;
487 
488  va_start ( key, xen );
489  rc = xenstore_message ( xen, XS_RM, NULL, NULL, NULL, key );
490  va_end ( key );
491  return rc;
492 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:10
Definition: xs_wire.h:31
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:314
__builtin_va_list va_list
Definition: stdarg.h:7
#define va_start(ap, last)
Definition: stdarg.h:8
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
union @391 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 504 of file xenstore.c.

505  {
506  va_list key;
507  int rc;
508 
509  va_start ( key, len );
511  va_end ( key );
512  return rc;
513 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:10
char unsigned long const char unsigned long char ** children
Definition: xenstore.h:26
ring len
Length.
Definition: dwmac.h:231
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:314
__builtin_va_list va_list
Definition: stdarg.h:7
#define va_start(ap, last)
Definition: stdarg.h:8
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
union @391 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 521 of file xenstore.c.

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

Referenced by xenstore_message().