xref: /minix/minix/drivers/system/log/liveupdate.c (revision 9f988b79)
1 #include "log.h"
2 
3 /* State management variables. */
4 #define NR_DEVS     1   /* number of minor devices */
5 EXTERN struct logdevice logdevices[NR_DEVS];
6 
7 /* State management helpers. */
8 static int is_read_pending;
9 static int is_select_callback_pending;
10 static void load_state_info(void)
11 {
12   int i, found_pending;
13   struct logdevice *log;
14 
15   /* Check if reads or select callbacks are pending. */
16   is_read_pending = FALSE;
17   is_select_callback_pending = FALSE;
18   found_pending = FALSE;
19   for (i = 0; i < NR_DEVS && !found_pending; i++) {
20       log = &logdevices[i];
21       if(log->log_source != NONE) {
22           is_read_pending = TRUE;
23       }
24       if(log->log_selected) {
25           is_select_callback_pending = TRUE;
26       }
27 
28       found_pending = (is_read_pending && is_select_callback_pending);
29   }
30 }
31 
32 /* Custom states definition. */
33 #define LOG_STATE_SELECT_PROTOCOL_FREE  (SEF_LU_STATE_CUSTOM_BASE + 0)
34 #define LOG_STATE_IS_CUSTOM(s)  ((s) == LOG_STATE_SELECT_PROTOCOL_FREE)
35 
36 /*===========================================================================*
37  *       			 sef_cb_lu_prepare 	 	             *
38  *===========================================================================*/
39 int sef_cb_lu_prepare(int state)
40 {
41   int is_ready;
42 
43   /* Load state information. */
44   load_state_info();
45 
46   /* Check if we are ready for the target state. */
47   is_ready = FALSE;
48   switch(state) {
49       /* Standard states. */
50       case SEF_LU_STATE_REQUEST_FREE:
51           is_ready = (!is_read_pending);
52       break;
53 
54       case SEF_LU_STATE_PROTOCOL_FREE:
55           is_ready = (!is_read_pending && !is_select_callback_pending);
56       break;
57 
58       /* Custom states. */
59       case LOG_STATE_SELECT_PROTOCOL_FREE:
60           is_ready = (!is_select_callback_pending);
61       break;
62   }
63 
64   /* Tell SEF if we are ready. */
65   return is_ready ? OK : ENOTREADY;
66 }
67 
68 /*===========================================================================*
69  *      		  sef_cb_lu_state_isvalid		             *
70  *===========================================================================*/
71 int sef_cb_lu_state_isvalid(int state, int UNUSED(flags))
72 {
73   return SEF_LU_STATE_IS_STANDARD(state) || LOG_STATE_IS_CUSTOM(state);
74 }
75 
76 /*===========================================================================*
77  *      		   sef_cb_lu_state_dump         	             *
78  *===========================================================================*/
79 void sef_cb_lu_state_dump(int state)
80 {
81   /* Load state information. */
82   load_state_info();
83 
84   sef_lu_dprint("log: live update state = %d\n", state);
85   sef_lu_dprint("log: is_read_pending = %d\n", is_read_pending);
86   sef_lu_dprint("log: is_select_callback_pending = %d\n",
87       is_select_callback_pending);
88 
89   sef_lu_dprint("log: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
90       SEF_LU_STATE_WORK_FREE, TRUE);
91   sef_lu_dprint("log: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
92       SEF_LU_STATE_REQUEST_FREE, (!is_read_pending));
93   sef_lu_dprint("log: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
94       SEF_LU_STATE_PROTOCOL_FREE, (!is_read_pending
95       && !is_select_callback_pending));
96   sef_lu_dprint("log: LOG_STATE_SELECT_PROTOCOL_FREE(%d) reached = %d\n",
97       LOG_STATE_SELECT_PROTOCOL_FREE, (!is_select_callback_pending));
98 }
99 
100