xenbus.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef XENBUS_H__
  3. #define XENBUS_H__
  4. #include <xen/interface/xen.h>
  5. #include <xen/interface/io/xenbus.h>
  6. typedef unsigned long xenbus_transaction_t;
  7. #define XBT_NIL ((xenbus_transaction_t)0)
  8. extern u32 xenbus_evtchn;
  9. /* Initialize the XenBus system. */
  10. void init_xenbus(void);
  11. /* Finalize the XenBus system. */
  12. void fini_xenbus(void);
  13. /**
  14. * xenbus_read() - Read the value associated with a path.
  15. *
  16. * Returns a malloc'd error string on failure and sets *value to NULL.
  17. * On success, *value is set to a malloc'd copy of the value.
  18. */
  19. char *xenbus_read(xenbus_transaction_t xbt, const char *path, char **value);
  20. char *xenbus_wait_for_state_change(const char *path, XenbusState *state);
  21. char *xenbus_switch_state(xenbus_transaction_t xbt, const char *path,
  22. XenbusState state);
  23. /**
  24. * xenbus_write() - Associates a value with a path.
  25. *
  26. * Returns a malloc'd error string on failure.
  27. */
  28. char *xenbus_write(xenbus_transaction_t xbt, const char *path,
  29. const char *value);
  30. /**
  31. * xenbus_rm() - Removes the value associated with a path.
  32. *
  33. * Returns a malloc'd error string on failure.
  34. */
  35. char *xenbus_rm(xenbus_transaction_t xbt, const char *path);
  36. /**
  37. * xenbus_ls() - List the contents of a directory.
  38. *
  39. * Returns a malloc'd error string on failure and sets *contents to NULL.
  40. * On success, *contents is set to a malloc'd array of pointers to malloc'd
  41. * strings. The array is NULL terminated. May block.
  42. */
  43. char *xenbus_ls(xenbus_transaction_t xbt, const char *prefix, char ***contents);
  44. /**
  45. * xenbus_get_perms() - Reads permissions associated with a path.
  46. *
  47. * Returns a malloc'd error string on failure and sets *value to NULL.
  48. * On success, *value is set to a malloc'd copy of the value.
  49. */
  50. char *xenbus_get_perms(xenbus_transaction_t xbt, const char *path, char **value);
  51. /**
  52. * xenbus_set_perms() - Sets the permissions associated with a path.
  53. *
  54. * Returns a malloc'd error string on failure.
  55. */
  56. char *xenbus_set_perms(xenbus_transaction_t xbt, const char *path, domid_t dom,
  57. char perm);
  58. /**
  59. * xenbus_transaction_start() - Start a xenbus transaction.
  60. *
  61. * Returns the transaction in xbt on success or a malloc'd error string
  62. * otherwise.
  63. */
  64. char *xenbus_transaction_start(xenbus_transaction_t *xbt);
  65. /**
  66. * xenbus_transaction_end() - End a xenbus transaction.
  67. *
  68. * Returns a malloc'd error string if it fails. Abort says whether the
  69. * transaction should be aborted.
  70. * Returns 1 in *retry if the transaction should be retried.
  71. */
  72. char *xenbus_transaction_end(xenbus_transaction_t xbt, int abort,
  73. int *retry);
  74. /**
  75. * xenbus_read_integer() - Read path and parse it as an integer.
  76. *
  77. * Returns -1 on error.
  78. */
  79. int xenbus_read_integer(const char *path);
  80. /**
  81. * xenbus_read_uuid() - Read path and parse it as 16 byte uuid.
  82. *
  83. * Returns 1 if read and parsing were successful, 0 if not
  84. */
  85. int xenbus_read_uuid(const char *path, unsigned char uuid[16]);
  86. /**
  87. * xenbus_printf() - Contraction of snprintf and xenbus_write(path/node).
  88. */
  89. char *xenbus_printf(xenbus_transaction_t xbt,
  90. const char *node, const char *path,
  91. const char *fmt, ...)
  92. __attribute__((__format__(printf, 4, 5)));
  93. /**
  94. * xenbus_get_self_id() - Utility function to figure out our domain id
  95. */
  96. domid_t xenbus_get_self_id(void);
  97. #endif /* XENBUS_H__ */