1 /* This file implements SEF hooks for live update of multithreaded block
5 #include <minix/drivers.h>
6 #include <minix/blockdriver_mt.h>
10 /*===========================================================================*
12 *===========================================================================*/
13 static int sef_cb_lu_prepare(int state
)
15 /* This function is called to decide whether we can enter the given live
16 * update state, and to prepare for such an update. If we are requested to
17 * update to a request-free or protocol-free state, make sure there is no work
18 * pending or being processed, and shut down all worker threads.
22 case SEF_LU_STATE_REQUEST_FREE
:
23 case SEF_LU_STATE_PROTOCOL_FREE
:
24 if (!blockdriver_mt_is_idle()) {
25 printf("libblockdriver(%d): not idle, blocking update\n",
30 blockdriver_mt_suspend();
38 /*===========================================================================*
39 * sef_cb_lu_state_changed *
40 *===========================================================================*/
41 static void sef_cb_lu_state_changed(int old_state
, int state
)
43 /* This function is called in the old driver instance when the state changes.
44 * We use it to resume normal operation after a failed live update.
47 if (state
!= SEF_LU_STATE_NULL
)
51 case SEF_LU_STATE_REQUEST_FREE
:
52 case SEF_LU_STATE_PROTOCOL_FREE
:
53 blockdriver_mt_resume();
57 /*===========================================================================*
59 *===========================================================================*/
60 static int sef_cb_init_lu(int type
, sef_init_info_t
*info
)
62 /* This function is called in the new driver instance during a live update.
66 /* Perform regular state transfer. */
67 if ((r
= SEF_CB_INIT_LU_DEFAULT(type
, info
)) != OK
)
70 /* Recreate worker threads, if necessary. */
71 switch (info
->prepare_state
) {
72 case SEF_LU_STATE_REQUEST_FREE
:
73 case SEF_LU_STATE_PROTOCOL_FREE
:
74 blockdriver_mt_resume();
80 /*===========================================================================*
81 * blockdriver_mt_support_lu *
82 *===========================================================================*/
83 void blockdriver_mt_support_lu(void)
85 /* Enable suppor for live update of this driver. To be called before
89 /* Register live update callbacks. */
90 sef_setcb_init_lu(sef_cb_init_lu
);
91 sef_setcb_lu_prepare(sef_cb_lu_prepare
);
92 sef_setcb_lu_state_changed(sef_cb_lu_state_changed
);
93 sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid_standard
);