source: mainline/uspace/srv/bd/vbd/vbd.c@ 22fb7ab

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 22fb7ab was 22fb7ab, checked in by Jiri Svoboda <jiri@…>, 10 years ago

Delegate disks to volsrv and labels to vbd.

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[1356f85a]1/*
2 * Copyright (c) 2015 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[22fb7ab]29/** @addtogroup vbd
[1356f85a]30 * @{
31 */
32/**
33 * @file
34 */
35
36#include <async.h>
37#include <errno.h>
38#include <io/log.h>
39#include <ipc/services.h>
[22fb7ab]40#include <ipc/vbd.h>
[1356f85a]41#include <loc.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <task.h>
45
[22fb7ab]46#include "types/vbd.h"
47
[1356f85a]48#define NAME "vbd"
49
50static void vbd_client_conn(ipc_callid_t, ipc_call_t *, void *);
51
52static int vbd_init(void)
53{
54 int rc;
[22fb7ab]55 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_init()");
[1356f85a]56
57 async_set_client_connection(vbd_client_conn);
58
59 rc = loc_server_register(NAME);
60 if (rc != EOK) {
61 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server (%d).", rc);
62 return EEXIST;
63 }
64
65 service_id_t sid;
66 rc = loc_service_register(SERVICE_NAME_VBD, &sid);
67 if (rc != EOK) {
68 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
69 return EEXIST;
70 }
71
72 return EOK;
73}
74
[22fb7ab]75static int vbd_disk_add(service_id_t sid)
76{
77 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_add(%zu)", sid);
78 return EOK;
79}
80
81static int vbd_disk_remove(service_id_t sid)
82{
83 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_remove(%zu)", sid);
84 return EOK;
85}
86
87static int vbd_disk_info(service_id_t sid, vbd_disk_info_t *info)
88{
89 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info(%zu)", sid);
90 info->ltype = lt_mbr;
91 return EOK;
92}
93
94static int vbd_label_create(service_id_t sid, label_type_t ltype)
95{
96 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_label_create(%zu, %d)", sid,
97 ltype);
98 return EOK;
99}
100
101static int vbd_label_delete(service_id_t sid, label_type_t ltype)
102{
103 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_label_delete(%zu, %d)", sid,
104 ltype);
105 return EOK;
106}
107
108static void vbd_disk_add_srv(ipc_callid_t iid, ipc_call_t *icall)
109{
110 service_id_t disk_sid;
111 int rc;
112
113 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_add_srv()");
114
115 disk_sid = IPC_GET_ARG1(*icall);
116 rc = vbd_disk_add(disk_sid);
117 async_answer_0(iid, (sysarg_t) rc);
118}
119
120static void vbd_disk_remove_srv(ipc_callid_t iid, ipc_call_t *icall)
121{
122 service_id_t disk_sid;
123 int rc;
124
125 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_remove_srv()");
126
127 disk_sid = IPC_GET_ARG1(*icall);
128 rc = vbd_disk_remove(disk_sid);
129 async_answer_0(iid, (sysarg_t) rc);
130}
131
132static void vbd_disk_info_srv(ipc_callid_t iid, ipc_call_t *icall)
133{
134 service_id_t disk_sid;
135 vbd_disk_info_t dinfo;
136 int rc;
137
138 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info_srv()");
139
140 disk_sid = IPC_GET_ARG1(*icall);
141 rc = vbd_disk_info(disk_sid, &dinfo);
142 async_answer_1(iid, (sysarg_t)rc, (sysarg_t)dinfo.ltype);
143}
144
145static void vbd_label_create_srv(ipc_callid_t iid, ipc_call_t *icall)
146{
147 service_id_t disk_sid;
148 label_type_t ltype;
149 int rc;
150
151 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_label_create_srv()");
152
153 disk_sid = IPC_GET_ARG1(*icall);
154 ltype = IPC_GET_ARG2(*icall);
155 rc = vbd_label_create(disk_sid, ltype);
156 async_answer_0(iid, (sysarg_t) rc);
157}
158
159static void vbd_label_delete_srv(ipc_callid_t iid, ipc_call_t *icall)
160{
161 service_id_t disk_sid;
162 label_type_t ltype;
163 int rc;
164
165 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_label_delete_srv()");
166
167 disk_sid = IPC_GET_ARG1(*icall);
168 ltype = IPC_GET_ARG2(*icall);
169 rc = vbd_label_delete(disk_sid, ltype);
170 async_answer_0(iid, (sysarg_t) rc);
171}
[1356f85a]172
173static void vbd_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
174{
[22fb7ab]175 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_client_conn()");
[1356f85a]176
177 /* Accept the connection */
178 async_answer_0(iid, EOK);
179
180 while (true) {
181 ipc_call_t call;
182 ipc_callid_t callid = async_get_call(&call);
183 sysarg_t method = IPC_GET_IMETHOD(call);
184
185 if (!method) {
186 /* The other side has hung up */
187 async_answer_0(callid, EOK);
188 return;
189 }
190
191 switch (method) {
[22fb7ab]192 case VBD_DISK_ADD:
193 vbd_disk_add_srv(callid, &call);
194 break;
195 case VBD_DISK_REMOVE:
196 vbd_disk_remove_srv(callid, &call);
197 break;
198 case VBD_DISK_INFO:
199 vbd_disk_info_srv(callid, &call);
200 break;
201 case VBD_LABEL_CREATE:
202 vbd_label_create_srv(callid, &call);
203 break;
204 case VBD_LABEL_DELETE:
205 vbd_label_delete_srv(callid, &call);
206 break;
[1356f85a]207 default:
208 async_answer_0(callid, EINVAL);
209 }
210 }
211}
212
213int main(int argc, char *argv[])
214{
215 int rc;
216
217 printf("%s: Virtual Block Device service\n", NAME);
218
219 if (log_init(NAME) != EOK) {
220 printf(NAME ": Failed to initialize logging.\n");
221 return 1;
222 }
223
224 rc = vbd_init();
225 if (rc != EOK)
226 return 1;
227
228 printf(NAME ": Accepting connections.\n");
229 task_retval(0);
230 async_manager();
231
232 return 0;
233}
234
235/** @}
236 */
Note: See TracBrowser for help on using the repository browser.