vm: change NO_MEM to a more impossible value
[minix.git] / servers / ds / main.c
blobb2ec89e564c906f6bd184c9abeb3a7d0836438c2
1 /* Data Store Server.
2 * This service implements a little publish/subscribe data store that is
3 * crucial for the system's fault tolerance. Components that require state
4 * can store it here, for later retrieval, e.g., after a crash and subsequent
5 * restart by the reincarnation server.
6 *
7 * Created:
8 * Oct 19, 2005 by Jorrit N. Herder
9 */
11 #include "inc.h" /* include master header file */
12 #include <minix/endpoint.h>
14 /* Allocate space for the global variables. */
15 static endpoint_t who_e; /* caller's proc number */
16 static int callnr; /* system call number */
18 /* Declare some local functions. */
19 static void get_work(message *m_ptr);
20 static void reply(endpoint_t whom, message *m_ptr);
22 /* SEF functions and variables. */
23 static void sef_local_startup(void);
25 /*===========================================================================*
26 * main *
27 *===========================================================================*/
28 int main(int argc, char **argv)
30 /* This is the main routine of this service. The main loop consists of
31 * three major activities: getting new work, processing the work, and
32 * sending the reply. The loop never terminates, unless a panic occurs.
34 message m;
35 int result;
37 /* SEF local startup. */
38 env_setargs(argc, argv);
39 sef_local_startup();
41 /* Main loop - get work and do it, forever. */
42 while (TRUE) {
44 /* Wait for incoming message, sets 'callnr' and 'who'. */
45 get_work(&m);
47 if (is_notify(callnr)) {
48 printf("DS: warning, got illegal notify from: %d\n", m.m_source);
49 result = EINVAL;
50 goto send_reply;
53 switch (callnr) {
54 case DS_PUBLISH:
55 result = do_publish(&m);
56 break;
57 case DS_RETRIEVE:
58 result = do_retrieve(&m);
59 break;
60 case DS_RETRIEVE_LABEL:
61 result = do_retrieve_label(&m);
62 break;
63 case DS_DELETE:
64 result = do_delete(&m);
65 break;
66 case DS_SUBSCRIBE:
67 result = do_subscribe(&m);
68 break;
69 case DS_CHECK:
70 result = do_check(&m);
71 break;
72 case DS_SNAPSHOT:
73 result = do_snapshot(&m);
74 break;
75 case COMMON_GETSYSINFO:
76 result = do_getsysinfo(&m);
77 break;
78 default:
79 printf("DS: warning, got illegal request from %d\n", m.m_source);
80 result = EINVAL;
83 send_reply:
84 /* Finally send reply message, unless disabled. */
85 if (result != EDONTREPLY) {
86 m.m_type = result; /* build reply message */
87 reply(who_e, &m); /* send it away */
90 return(OK); /* shouldn't come here */
93 /*===========================================================================*
94 * sef_local_startup *
95 *===========================================================================*/
96 static void sef_local_startup()
98 /* Register init callbacks. */
99 sef_setcb_init_fresh(sef_cb_init_fresh);
100 sef_setcb_init_restart(sef_cb_init_fail);
102 /* No live update support for now. */
104 /* Let SEF perform startup. */
105 sef_startup();
108 /*===========================================================================*
109 * get_work *
110 *===========================================================================*/
111 static void get_work(
112 message *m_ptr /* message buffer */
115 int status = sef_receive(ANY, m_ptr); /* blocks until message arrives */
116 if (OK != status)
117 panic("failed to receive message!: %d", status);
118 who_e = m_ptr->m_source; /* message arrived! set sender */
119 callnr = m_ptr->m_type; /* set function call number */
122 /*===========================================================================*
123 * reply *
124 *===========================================================================*/
125 static void reply(
126 endpoint_t who_e, /* destination */
127 message *m_ptr /* message buffer */
130 int s = send(who_e, m_ptr); /* send the message */
131 if (OK != s)
132 printf("DS: unable to send reply to %d: %d\n", who_e, s);