Advertisement
gusibsd

0001-r294205-blkback-add-support-for-hotplug-scripts.patch

Feb 23rd, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 KB | None | 0 0
  1. From acd8f51fc654fdcd8c5b220d743063bedf61704b Mon Sep 17 00:00:00 2001
  2. From: Roger Pau Monne <roger.pau@citrix.com>
  3. Date: Thu, 21 May 2015 19:06:09 +0200
  4. Subject: [PATCH] blkback: add support for hotplug scripts
  5.  
  6. Hotplug scripts are needed in order to use fancy disk configurations in xl,
  7. like iSCSI disks. The job of hotplug scripts is to locally attach the disk
  8. and present it to blkback as a block device or a regular file.
  9.  
  10. This change introduces a new xenstore node in the blkback hierarchy, called
  11. "path". This is a straigh replacement for the "params" node, which was used
  12. before.
  13.  
  14. Hotplug scripts will need to read the "params" node, perform whatever
  15. actions are necessary and then write the "path" node. The hotplug script is
  16. also in charge of detaching the disk once the domain has been shutdown.
  17.  
  18. Sponsored by: Citrix Systems R&D
  19. ---
  20. sys/dev/xen/blkback/blkback.c | 196 +++++++++++++++++++++++++-----------------
  21. 1 file changed, 118 insertions(+), 78 deletions(-)
  22.  
  23. diff --git a/sys/dev/xen/blkback/blkback.c b/sys/dev/xen/blkback/blkback.c
  24. index a97314b..aef5af1 100644
  25. --- a/sys/dev/xen/blkback/blkback.c
  26. +++ b/sys/dev/xen/blkback/blkback.c
  27. @@ -802,6 +802,9 @@ struct xbb_softc {
  28.  
  29. /** How many times we have run out of request structures */
  30. uint64_t request_shortages;
  31. +
  32. + /** Watch to wait for hotplug script execution */
  33. + struct xs_watch hotplug_watch;
  34. };
  35.  
  36. /*---------------------------- Request Processing ----------------------------*/
  37. @@ -3310,7 +3313,7 @@ xbb_connect(struct xbb_softc *xbb)
  38. {
  39. int error;
  40.  
  41. - if (xenbus_get_state(xbb->dev) == XenbusStateConnected)
  42. + if (xenbus_get_state(xbb->dev) != XenbusStateInitialised)
  43. return;
  44.  
  45. if (xbb_collect_frontend_info(xbb) != 0)
  46. @@ -3587,61 +3590,23 @@ xbb_setup_sysctl(struct xbb_softc *xbb)
  47. "communication channel pages (negotiated)");
  48. }
  49.  
  50. -/**
  51. - * Attach to a XenBus device that has been claimed by our probe routine.
  52. - *
  53. - * \param dev NewBus device object representing this Xen Block Back instance.
  54. - *
  55. - * \return 0 for success, errno codes for failure.
  56. - */
  57. -static int
  58. -xbb_attach(device_t dev)
  59. +static void
  60. +xbb_attach_disk(struct xs_watch *watch, const char **vec, unsigned int len)
  61. {
  62. + device_t dev;
  63. struct xbb_softc *xbb;
  64. int error;
  65. - u_int max_ring_page_order;
  66.  
  67. - DPRINTF("Attaching to %s\n", xenbus_get_node(dev));
  68. -
  69. - /*
  70. - * Basic initialization.
  71. - * After this block it is safe to call xbb_detach()
  72. - * to clean up any allocated data for this instance.
  73. - */
  74. + dev = (device_t) watch->callback_data;
  75. xbb = device_get_softc(dev);
  76. - xbb->dev = dev;
  77. - xbb->otherend_id = xenbus_get_otherend_id(dev);
  78. - TASK_INIT(&xbb->io_task, /*priority*/0, xbb_run_queue, xbb);
  79. - mtx_init(&xbb->lock, device_get_nameunit(dev), NULL, MTX_DEF);
  80.  
  81. - /*
  82. - * Publish protocol capabilities for consumption by the
  83. - * front-end.
  84. - */
  85. - error = xs_printf(XST_NIL, xenbus_get_node(xbb->dev),
  86. - "feature-barrier", "1");
  87. - if (error) {
  88. - xbb_attach_failed(xbb, error, "writing %s/feature-barrier",
  89. - xenbus_get_node(xbb->dev));
  90. - return (error);
  91. - }
  92. -
  93. - error = xs_printf(XST_NIL, xenbus_get_node(xbb->dev),
  94. - "feature-flush-cache", "1");
  95. - if (error) {
  96. - xbb_attach_failed(xbb, error, "writing %s/feature-flush-cache",
  97. - xenbus_get_node(xbb->dev));
  98. - return (error);
  99. - }
  100. + error = xs_gather(XST_NIL, xenbus_get_node(dev), "path", NULL,
  101. + &xbb->dev_name, NULL);
  102. + if (error != 0)
  103. + return;
  104.  
  105. - max_ring_page_order = flsl(XBB_MAX_RING_PAGES) - 1;
  106. - error = xs_printf(XST_NIL, xenbus_get_node(xbb->dev),
  107. - "max-ring-page-order", "%u", max_ring_page_order);
  108. - if (error) {
  109. - xbb_attach_failed(xbb, error, "writing %s/max-ring-page-order",
  110. - xenbus_get_node(xbb->dev));
  111. - return (error);
  112. - }
  113. + xs_unregister_watch(watch);
  114. + free(watch->node, M_XENBLOCKBACK);
  115.  
  116. /* Collect physical device information. */
  117. error = xs_gather(XST_NIL, xenbus_get_otherend_path(xbb->dev),
  118. @@ -3652,12 +3617,11 @@ xbb_attach(device_t dev)
  119.  
  120. error = xs_gather(XST_NIL, xenbus_get_node(dev),
  121. "mode", NULL, &xbb->dev_mode,
  122. - "params", NULL, &xbb->dev_name,
  123. NULL);
  124. if (error != 0) {
  125. xbb_attach_failed(xbb, error, "reading backend fields at %s",
  126. xenbus_get_node(dev));
  127. - return (ENXIO);
  128. + return;
  129. }
  130.  
  131. /* Parse fopen style mode flags. */
  132. @@ -3668,13 +3632,11 @@ xbb_attach(device_t dev)
  133. * Verify the physical device is present and can support
  134. * the desired I/O mode.
  135. */
  136. - DROP_GIANT();
  137. error = xbb_open_backend(xbb);
  138. - PICKUP_GIANT();
  139. if (error != 0) {
  140. xbb_attach_failed(xbb, error, "Unable to open %s",
  141. xbb->dev_name);
  142. - return (ENXIO);
  143. + return;
  144. }
  145.  
  146. /* Use devstat(9) for recording statistics. */
  147. @@ -3706,7 +3668,7 @@ xbb_attach(device_t dev)
  148. /*contxt*/&xbb->io_taskqueue);
  149. if (xbb->io_taskqueue == NULL) {
  150. xbb_attach_failed(xbb, error, "Unable to create taskqueue");
  151. - return (ENOMEM);
  152. + return;
  153. }
  154.  
  155. taskqueue_start_threads(&xbb->io_taskqueue,
  156. @@ -3721,10 +3683,88 @@ xbb_attach(device_t dev)
  157. if (error) {
  158. xbb_attach_failed(xbb, error, "writing %s/hotplug-status",
  159. xenbus_get_node(xbb->dev));
  160. - return (error);
  161. + return;
  162. }
  163.  
  164. /* Tell the front end that we are ready to connect. */
  165. + xenbus_set_state(dev, XenbusStateInitialised);
  166. +}
  167. +
  168. +/**
  169. + * Attach to a XenBus device that has been claimed by our probe routine.
  170. + *
  171. + * \param dev NewBus device object representing this Xen Block Back instance.
  172. + *
  173. + * \return 0 for success, errno codes for failure.
  174. + */
  175. +static int
  176. +xbb_attach(device_t dev)
  177. +{
  178. + struct xbb_softc *xbb;
  179. + int error;
  180. + u_int max_ring_page_order;
  181. + struct sbuf *watch_path;
  182. +
  183. + DPRINTF("Attaching to %s\n", xenbus_get_node(dev));
  184. +
  185. + /*
  186. + * Basic initialization.
  187. + * After this block it is safe to call xbb_detach()
  188. + * to clean up any allocated data for this instance.
  189. + */
  190. + xbb = device_get_softc(dev);
  191. + xbb->dev = dev;
  192. + xbb->otherend_id = xenbus_get_otherend_id(dev);
  193. + TASK_INIT(&xbb->io_task, /*priority*/0, xbb_run_queue, xbb);
  194. + mtx_init(&xbb->lock, device_get_nameunit(dev), NULL, MTX_DEF);
  195. +
  196. + /*
  197. + * Publish protocol capabilities for consumption by the
  198. + * front-end.
  199. + */
  200. + error = xs_printf(XST_NIL, xenbus_get_node(xbb->dev),
  201. + "feature-barrier", "1");
  202. + if (error) {
  203. + xbb_attach_failed(xbb, error, "writing %s/feature-barrier",
  204. + xenbus_get_node(xbb->dev));
  205. + return (error);
  206. + }
  207. +
  208. + error = xs_printf(XST_NIL, xenbus_get_node(xbb->dev),
  209. + "feature-flush-cache", "1");
  210. + if (error) {
  211. + xbb_attach_failed(xbb, error, "writing %s/feature-flush-cache",
  212. + xenbus_get_node(xbb->dev));
  213. + return (error);
  214. + }
  215. +
  216. + max_ring_page_order = flsl(XBB_MAX_RING_PAGES) - 1;
  217. + error = xs_printf(XST_NIL, xenbus_get_node(xbb->dev),
  218. + "max-ring-page-order", "%u", max_ring_page_order);
  219. + if (error) {
  220. + xbb_attach_failed(xbb, error, "writing %s/max-ring-page-order",
  221. + xenbus_get_node(xbb->dev));
  222. + return (error);
  223. + }
  224. +
  225. + /*
  226. + * We need to wait for hotplug script execution before
  227. + * moving forward.
  228. + */
  229. + watch_path = xs_join(xenbus_get_node(xbb->dev), "path");
  230. + xbb->hotplug_watch.callback_data = (uintptr_t)dev;
  231. + xbb->hotplug_watch.callback = xbb_attach_disk;
  232. + xbb->hotplug_watch.node = strdup(sbuf_data(watch_path), M_XENBLOCKBACK);
  233. + sbuf_delete(watch_path);
  234. + error = xs_register_watch(&xbb->hotplug_watch);
  235. + if (error != 0) {
  236. + xbb_attach_failed(xbb, error, "failed to create watch on %s",
  237. + xbb->hotplug_watch.node);
  238. + free(xbb->hotplug_watch.node, M_XENBLOCKBACK);
  239. + return (error);
  240. + }
  241. +
  242. + /* Tell the toolstack blkback has attached. */
  243. xenbus_set_state(dev, XenbusStateInitWait);
  244.  
  245. return (0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement