source: mainline/uspace/srv/bd/vbd/vbd.c@ 3faa03d

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

Implement partition block device interface in VBD based on data from liblabel.

  • Property mode set to 100644
File size: 6.7 KB
Line 
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
29/** @addtogroup vbd
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>
40#include <ipc/vbd.h>
41#include <loc.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <task.h>
45
46#include "disk.h"
47#include "types/vbd.h"
48
49#define NAME "vbd"
50
51static void vbds_client_conn(ipc_callid_t, ipc_call_t *, void *);
52
53static service_id_t ctl_sid;
54
55static int vbds_init(void)
56{
57 int rc;
58 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_init()");
59
60 vbds_disks_init();
61
62 async_set_client_connection(vbds_client_conn);
63
64 rc = loc_server_register(NAME);
65 if (rc != EOK) {
66 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server (%d).", rc);
67 return EEXIST;
68 }
69
70 rc = loc_service_register(SERVICE_NAME_VBD, &ctl_sid);
71 if (rc != EOK) {
72 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
73 return EEXIST;
74 }
75
76 return EOK;
77}
78
79
80static void vbds_disk_add_srv(ipc_callid_t iid, ipc_call_t *icall)
81{
82 service_id_t disk_sid;
83 int rc;
84
85 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_disk_add_srv()");
86
87 disk_sid = IPC_GET_ARG1(*icall);
88 rc = vbds_disk_add(disk_sid);
89 async_answer_0(iid, (sysarg_t) rc);
90}
91
92static void vbds_disk_remove_srv(ipc_callid_t iid, ipc_call_t *icall)
93{
94 service_id_t disk_sid;
95 int rc;
96
97 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_disk_remove_srv()");
98
99 disk_sid = IPC_GET_ARG1(*icall);
100 rc = vbds_disk_remove(disk_sid);
101 async_answer_0(iid, (sysarg_t) rc);
102}
103
104static void vbds_disk_info_srv(ipc_callid_t iid, ipc_call_t *icall)
105{
106 service_id_t disk_sid;
107 vbds_disk_info_t dinfo;
108 int rc;
109
110 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_disk_info_srv()");
111
112 disk_sid = IPC_GET_ARG1(*icall);
113 rc = vbds_disk_info(disk_sid, &dinfo);
114 async_answer_1(iid, (sysarg_t)rc, (sysarg_t)dinfo.ltype);
115}
116
117static void vbds_label_create_srv(ipc_callid_t iid, ipc_call_t *icall)
118{
119 service_id_t disk_sid;
120 label_type_t ltype;
121 int rc;
122
123 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_label_create_srv()");
124
125 disk_sid = IPC_GET_ARG1(*icall);
126 ltype = IPC_GET_ARG2(*icall);
127 rc = vbds_label_create(disk_sid, ltype);
128 async_answer_0(iid, (sysarg_t) rc);
129}
130
131static void vbds_label_delete_srv(ipc_callid_t iid, ipc_call_t *icall)
132{
133 service_id_t disk_sid;
134 int rc;
135
136 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_label_delete_srv()");
137
138 disk_sid = IPC_GET_ARG1(*icall);
139 rc = vbds_label_delete(disk_sid);
140 async_answer_0(iid, (sysarg_t) rc);
141}
142
143static void vbds_label_get_parts_srv(ipc_callid_t iid, ipc_call_t *icall)
144{
145// service_id_t disk_sid;
146// int rc;
147
148 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_label_get_parts_srv()");
149
150// disk_sid = IPC_GET_ARG1(*icall);
151// rc = vbds_label_delete(disk_sid);
152// async_answer_0(iid, (sysarg_t) rc);
153 async_answer_0(iid, ENOTSUP);
154}
155
156static void vbds_part_get_info_srv(ipc_callid_t iid, ipc_call_t *icall)
157{
158 vbds_part_id_t part;
159 vbds_part_info_t pinfo;
160 int rc;
161
162 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_part_get_info_srv()");
163
164 part = IPC_GET_ARG1(*icall);
165 rc = vbds_part_get_info(part, &pinfo);
166 async_answer_0(iid, (sysarg_t)rc);
167}
168
169static void vbds_part_create_srv(ipc_callid_t iid, ipc_call_t *icall)
170{
171 service_id_t disk_sid;
172 vbds_part_id_t part;
173 int rc;
174
175 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_part_create_srv()");
176
177 disk_sid = IPC_GET_ARG1(*icall);
178 rc = vbds_part_create(disk_sid, &part);
179 async_answer_1(iid, (sysarg_t)rc, (sysarg_t)part);
180}
181
182static void vbds_part_delete_srv(ipc_callid_t iid, ipc_call_t *icall)
183{
184 vbds_part_id_t part;
185 int rc;
186
187 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_part_delete_srv()");
188
189 part = IPC_GET_ARG1(*icall);
190 rc = vbds_part_delete(part);
191 async_answer_0(iid, (sysarg_t) rc);
192}
193
194static void vbds_ctl_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
195{
196 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_client_conn()");
197
198 /* Accept the connection */
199 async_answer_0(iid, EOK);
200
201 while (true) {
202 ipc_call_t call;
203 ipc_callid_t callid = async_get_call(&call);
204 sysarg_t method = IPC_GET_IMETHOD(call);
205
206 if (!method) {
207 /* The other side has hung up */
208 async_answer_0(callid, EOK);
209 return;
210 }
211
212 switch (method) {
213 case VBD_DISK_ADD:
214 vbds_disk_add_srv(callid, &call);
215 break;
216 case VBD_DISK_REMOVE:
217 vbds_disk_remove_srv(callid, &call);
218 break;
219 case VBD_DISK_INFO:
220 vbds_disk_info_srv(callid, &call);
221 break;
222 case VBD_LABEL_CREATE:
223 vbds_label_create_srv(callid, &call);
224 break;
225 case VBD_LABEL_DELETE:
226 vbds_label_delete_srv(callid, &call);
227 break;
228 case VBD_LABEL_GET_PARTS:
229 vbds_label_get_parts_srv(callid, &call);
230 break;
231 case VBD_PART_GET_INFO:
232 vbds_part_get_info_srv(callid, &call);
233 break;
234 case VBD_PART_CREATE:
235 vbds_part_create_srv(callid, &call);
236 break;
237 case VBD_PART_DELETE:
238 vbds_part_delete_srv(callid, &call);
239 break;
240 default:
241 async_answer_0(callid, EINVAL);
242 }
243 }
244}
245
246static void vbds_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
247{
248 service_id_t sid;
249
250 log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_client_conn()");
251
252 sid = (service_id_t)IPC_GET_ARG1(*icall);
253
254 if (sid == ctl_sid)
255 vbds_ctl_conn(iid, icall, arg);
256 else
257 vbds_bd_conn(iid, icall, arg);
258}
259
260int main(int argc, char *argv[])
261{
262 int rc;
263
264 printf("%s: Virtual Block Device service\n", NAME);
265
266 if (log_init(NAME) != EOK) {
267 printf(NAME ": Failed to initialize logging.\n");
268 return 1;
269 }
270
271 rc = vbds_init();
272 if (rc != EOK)
273 return 1;
274
275 printf(NAME ": Accepting connections.\n");
276 task_retval(0);
277 async_manager();
278
279 return 0;
280}
281
282/** @}
283 */
Note: See TracBrowser for help on using the repository browser.