| 1 | /*
|
|---|
| 2 | * Copyright (c) 2023 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 volsrv
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file Volume service
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <async.h>
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 | #include <str_error.h>
|
|---|
| 39 | #include <io/log.h>
|
|---|
| 40 | #include <ipc/services.h>
|
|---|
| 41 | #include <ipc/vol.h>
|
|---|
| 42 | #include <loc.h>
|
|---|
| 43 | #include <macros.h>
|
|---|
| 44 | #include <stdio.h>
|
|---|
| 45 | #include <stdlib.h>
|
|---|
| 46 | #include <task.h>
|
|---|
| 47 | #include <types/vol.h>
|
|---|
| 48 |
|
|---|
| 49 | #include "mkfs.h"
|
|---|
| 50 | #include "part.h"
|
|---|
| 51 | #include "volume.h"
|
|---|
| 52 |
|
|---|
| 53 | #define NAME "volsrv"
|
|---|
| 54 |
|
|---|
| 55 | const char *vol_cfg_file = "/cfg/volsrv.sif";
|
|---|
| 56 |
|
|---|
| 57 | static void vol_client_conn(ipc_call_t *, void *);
|
|---|
| 58 |
|
|---|
| 59 | static errno_t vol_init(void)
|
|---|
| 60 | {
|
|---|
| 61 | errno_t rc;
|
|---|
| 62 | vol_volumes_t *volumes = NULL;
|
|---|
| 63 | vol_parts_t *parts = NULL;
|
|---|
| 64 | loc_srv_t *srv = NULL;
|
|---|
| 65 |
|
|---|
| 66 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_init()");
|
|---|
| 67 |
|
|---|
| 68 | rc = vol_volumes_create(vol_cfg_file, &volumes);
|
|---|
| 69 | if (rc != EOK)
|
|---|
| 70 | goto error;
|
|---|
| 71 |
|
|---|
| 72 | rc = vol_parts_create(volumes, &parts);
|
|---|
| 73 | if (rc != EOK)
|
|---|
| 74 | goto error;
|
|---|
| 75 |
|
|---|
| 76 | rc = vol_part_discovery_start(parts);
|
|---|
| 77 | if (rc != EOK)
|
|---|
| 78 | goto error;
|
|---|
| 79 |
|
|---|
| 80 | async_set_fallback_port_handler(vol_client_conn, parts);
|
|---|
| 81 |
|
|---|
| 82 | rc = loc_server_register(NAME, &srv);
|
|---|
| 83 | if (rc != EOK) {
|
|---|
| 84 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
|
|---|
| 85 | rc = EEXIST;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | service_id_t sid;
|
|---|
| 89 | rc = loc_service_register(srv, SERVICE_NAME_VOLSRV, &sid);
|
|---|
| 90 | if (rc != EOK) {
|
|---|
| 91 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
|
|---|
| 92 | rc = EEXIST;
|
|---|
| 93 | goto error;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | return EOK;
|
|---|
| 97 | error:
|
|---|
| 98 | if (srv != NULL)
|
|---|
| 99 | loc_server_unregister(srv);
|
|---|
| 100 | vol_volumes_destroy(volumes);
|
|---|
| 101 | vol_parts_destroy(parts);
|
|---|
| 102 | return rc;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | static void vol_get_parts_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 106 | {
|
|---|
| 107 | ipc_call_t call;
|
|---|
| 108 | size_t size;
|
|---|
| 109 | size_t act_size;
|
|---|
| 110 | errno_t rc;
|
|---|
| 111 |
|
|---|
| 112 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 113 | async_answer_0(&call, EREFUSED);
|
|---|
| 114 | async_answer_0(icall, EREFUSED);
|
|---|
| 115 | return;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | service_id_t *id_buf = (service_id_t *) malloc(size);
|
|---|
| 119 | if (id_buf == NULL) {
|
|---|
| 120 | async_answer_0(&call, ENOMEM);
|
|---|
| 121 | async_answer_0(icall, ENOMEM);
|
|---|
| 122 | return;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | rc = vol_part_get_ids(parts, id_buf, size, &act_size);
|
|---|
| 126 | if (rc != EOK) {
|
|---|
| 127 | async_answer_0(&call, rc);
|
|---|
| 128 | async_answer_0(icall, rc);
|
|---|
| 129 | return;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | errno_t retval = async_data_read_finalize(&call, id_buf, size);
|
|---|
| 133 | free(id_buf);
|
|---|
| 134 |
|
|---|
| 135 | async_answer_1(icall, retval, act_size);
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | static void vol_part_add_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 139 | {
|
|---|
| 140 | service_id_t sid;
|
|---|
| 141 | errno_t rc;
|
|---|
| 142 |
|
|---|
| 143 | sid = ipc_get_arg1(icall);
|
|---|
| 144 |
|
|---|
| 145 | rc = vol_part_add_part(parts, sid);
|
|---|
| 146 | if (rc != EOK) {
|
|---|
| 147 | async_answer_0(icall, rc);
|
|---|
| 148 | return;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | async_answer_0(icall, EOK);
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | static void vol_part_info_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 155 | {
|
|---|
| 156 | service_id_t sid;
|
|---|
| 157 | vol_part_t *part;
|
|---|
| 158 | vol_part_info_t pinfo;
|
|---|
| 159 | errno_t rc;
|
|---|
| 160 |
|
|---|
| 161 | sid = ipc_get_arg1(icall);
|
|---|
| 162 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_info_srv(%zu)",
|
|---|
| 163 | sid);
|
|---|
| 164 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
|---|
| 165 | if (rc != EOK) {
|
|---|
| 166 | async_answer_0(icall, ENOENT);
|
|---|
| 167 | return;
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | rc = vol_part_get_info(part, &pinfo);
|
|---|
| 171 | if (rc != EOK) {
|
|---|
| 172 | async_answer_0(icall, EIO);
|
|---|
| 173 | goto error;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | ipc_call_t call;
|
|---|
| 177 | size_t size;
|
|---|
| 178 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 179 | async_answer_0(&call, EREFUSED);
|
|---|
| 180 | async_answer_0(icall, EREFUSED);
|
|---|
| 181 | goto error;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | if (size != sizeof(vol_part_info_t)) {
|
|---|
| 185 | async_answer_0(&call, EINVAL);
|
|---|
| 186 | async_answer_0(icall, EINVAL);
|
|---|
| 187 | goto error;
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | rc = async_data_read_finalize(&call, &pinfo,
|
|---|
| 191 | min(size, sizeof(pinfo)));
|
|---|
| 192 | if (rc != EOK) {
|
|---|
| 193 | async_answer_0(&call, rc);
|
|---|
| 194 | async_answer_0(icall, rc);
|
|---|
| 195 | goto error;
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | async_answer_0(icall, EOK);
|
|---|
| 199 | error:
|
|---|
| 200 | vol_part_del_ref(part);
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | static void vol_part_eject_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 204 | {
|
|---|
| 205 | service_id_t sid;
|
|---|
| 206 | vol_part_t *part;
|
|---|
| 207 | errno_t rc;
|
|---|
| 208 |
|
|---|
| 209 | sid = ipc_get_arg1(icall);
|
|---|
| 210 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_eject_srv(%zu)", sid);
|
|---|
| 211 |
|
|---|
| 212 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
|---|
| 213 | if (rc != EOK) {
|
|---|
| 214 | async_answer_0(icall, ENOENT);
|
|---|
| 215 | return;
|
|---|
| 216 | }
|
|---|
| 217 |
|
|---|
| 218 | rc = vol_part_eject_part(part);
|
|---|
| 219 | if (rc != EOK) {
|
|---|
| 220 | async_answer_0(icall, EIO);
|
|---|
| 221 | goto error;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | async_answer_0(icall, EOK);
|
|---|
| 225 | error:
|
|---|
| 226 | vol_part_del_ref(part);
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | static void vol_part_insert_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 230 | {
|
|---|
| 231 | service_id_t sid;
|
|---|
| 232 | vol_part_t *part;
|
|---|
| 233 | errno_t rc;
|
|---|
| 234 |
|
|---|
| 235 | sid = ipc_get_arg1(icall);
|
|---|
| 236 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_insert_srv(%zu)", sid);
|
|---|
| 237 |
|
|---|
| 238 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
|---|
| 239 | if (rc != EOK) {
|
|---|
| 240 | async_answer_0(icall, ENOENT);
|
|---|
| 241 | return;
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | rc = vol_part_insert_part(part);
|
|---|
| 245 | if (rc != EOK) {
|
|---|
| 246 | async_answer_0(icall, EIO);
|
|---|
| 247 | goto error;
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | async_answer_0(icall, EOK);
|
|---|
| 251 | error:
|
|---|
| 252 | vol_part_del_ref(part);
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | static void vol_part_insert_by_path_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 256 | {
|
|---|
| 257 | vol_part_t *part;
|
|---|
| 258 | char *path = NULL;
|
|---|
| 259 | errno_t rc;
|
|---|
| 260 |
|
|---|
| 261 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_insert_by_path_srv()");
|
|---|
| 262 |
|
|---|
| 263 | rc = async_data_write_accept((void **)&path, true, 0, VOL_MOUNTP_MAXLEN,
|
|---|
| 264 | 0, NULL);
|
|---|
| 265 | if (rc != EOK) {
|
|---|
| 266 | async_answer_0(icall, rc);
|
|---|
| 267 | goto error;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | rc = vol_part_find_by_path_ref(parts, path, &part);
|
|---|
| 271 | if (rc != EOK) {
|
|---|
| 272 | async_answer_0(icall, ENOENT);
|
|---|
| 273 | goto error;
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | rc = vol_part_insert_part(part);
|
|---|
| 277 | if (rc != EOK) {
|
|---|
| 278 | async_answer_0(icall, rc);
|
|---|
| 279 | vol_part_del_ref(part);
|
|---|
| 280 | goto error;
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | free(path);
|
|---|
| 284 | vol_part_del_ref(part);
|
|---|
| 285 | async_answer_0(icall, EOK);
|
|---|
| 286 |
|
|---|
| 287 | return;
|
|---|
| 288 | error:
|
|---|
| 289 | if (path != NULL)
|
|---|
| 290 | free(path);
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | static void vol_part_empty_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 294 | {
|
|---|
| 295 | service_id_t sid;
|
|---|
| 296 | vol_part_t *part;
|
|---|
| 297 | errno_t rc;
|
|---|
| 298 |
|
|---|
| 299 | sid = ipc_get_arg1(icall);
|
|---|
| 300 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_empty_srv(%zu)", sid);
|
|---|
| 301 |
|
|---|
| 302 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
|---|
| 303 | if (rc != EOK) {
|
|---|
| 304 | async_answer_0(icall, ENOENT);
|
|---|
| 305 | return;
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | rc = vol_part_empty_part(part);
|
|---|
| 309 | if (rc != EOK) {
|
|---|
| 310 | async_answer_0(icall, EIO);
|
|---|
| 311 | goto error;
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | async_answer_0(icall, EOK);
|
|---|
| 315 | error:
|
|---|
| 316 | vol_part_del_ref(part);
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | static void vol_part_get_lsupp_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 320 | {
|
|---|
| 321 | vol_fstype_t fstype;
|
|---|
| 322 | vol_label_supp_t vlsupp;
|
|---|
| 323 | errno_t rc;
|
|---|
| 324 |
|
|---|
| 325 | fstype = ipc_get_arg1(icall);
|
|---|
| 326 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_get_lsupp_srv(%u)",
|
|---|
| 327 | fstype);
|
|---|
| 328 |
|
|---|
| 329 | volsrv_part_get_lsupp(fstype, &vlsupp);
|
|---|
| 330 |
|
|---|
| 331 | ipc_call_t call;
|
|---|
| 332 | size_t size;
|
|---|
| 333 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 334 | async_answer_0(&call, EREFUSED);
|
|---|
| 335 | async_answer_0(icall, EREFUSED);
|
|---|
| 336 | return;
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 | if (size != sizeof(vol_label_supp_t)) {
|
|---|
| 340 | async_answer_0(&call, EINVAL);
|
|---|
| 341 | async_answer_0(icall, EINVAL);
|
|---|
| 342 | return;
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | rc = async_data_read_finalize(&call, &vlsupp,
|
|---|
| 346 | min(size, sizeof(vlsupp)));
|
|---|
| 347 | if (rc != EOK) {
|
|---|
| 348 | async_answer_0(&call, rc);
|
|---|
| 349 | async_answer_0(icall, rc);
|
|---|
| 350 | return;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | async_answer_0(icall, EOK);
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | static void vol_part_mkfs_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 357 | {
|
|---|
| 358 | service_id_t sid;
|
|---|
| 359 | vol_part_t *part;
|
|---|
| 360 | vol_fstype_t fstype;
|
|---|
| 361 | char *label = NULL;
|
|---|
| 362 | char *mountp = NULL;
|
|---|
| 363 | errno_t rc;
|
|---|
| 364 |
|
|---|
| 365 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_srv()");
|
|---|
| 366 |
|
|---|
| 367 | sid = ipc_get_arg1(icall);
|
|---|
| 368 | fstype = ipc_get_arg2(icall);
|
|---|
| 369 |
|
|---|
| 370 | rc = async_data_write_accept((void **)&label, true, 0, VOL_LABEL_MAXLEN,
|
|---|
| 371 | 0, NULL);
|
|---|
| 372 | if (rc != EOK) {
|
|---|
| 373 | async_answer_0(icall, rc);
|
|---|
| 374 | goto error;
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 | if (label != NULL) {
|
|---|
| 378 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_srv: label='%s'",
|
|---|
| 379 | label);
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | rc = async_data_write_accept((void **)&mountp, true, 0, VOL_MOUNTP_MAXLEN,
|
|---|
| 383 | 0, NULL);
|
|---|
| 384 | if (rc != EOK) {
|
|---|
| 385 | async_answer_0(icall, rc);
|
|---|
| 386 | goto error;
|
|---|
| 387 | }
|
|---|
| 388 |
|
|---|
| 389 | if (mountp != NULL) {
|
|---|
| 390 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_srv: mountp='%s'",
|
|---|
| 391 | mountp);
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
|---|
| 395 | if (rc != EOK) {
|
|---|
| 396 | async_answer_0(icall, ENOENT);
|
|---|
| 397 | goto error;
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 | rc = vol_part_mkfs_part(part, fstype, label, mountp);
|
|---|
| 401 | if (rc != EOK) {
|
|---|
| 402 | async_answer_0(icall, rc);
|
|---|
| 403 | vol_part_del_ref(part);
|
|---|
| 404 | goto error;
|
|---|
| 405 | }
|
|---|
| 406 |
|
|---|
| 407 | free(label);
|
|---|
| 408 | free(mountp);
|
|---|
| 409 | async_answer_0(icall, EOK);
|
|---|
| 410 |
|
|---|
| 411 | return;
|
|---|
| 412 | error:
|
|---|
| 413 | if (label != NULL)
|
|---|
| 414 | free(label);
|
|---|
| 415 | if (mountp != NULL)
|
|---|
| 416 | free(mountp);
|
|---|
| 417 | }
|
|---|
| 418 |
|
|---|
| 419 | static void vol_part_set_mountp_srv(vol_parts_t *parts,
|
|---|
| 420 | ipc_call_t *icall)
|
|---|
| 421 | {
|
|---|
| 422 | service_id_t sid;
|
|---|
| 423 | vol_part_t *part;
|
|---|
| 424 | char *mountp;
|
|---|
| 425 | errno_t rc;
|
|---|
| 426 |
|
|---|
| 427 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_set_mountp_srv()");
|
|---|
| 428 |
|
|---|
| 429 | sid = ipc_get_arg1(icall);
|
|---|
| 430 |
|
|---|
| 431 | rc = async_data_write_accept((void **)&mountp, true, 0,
|
|---|
| 432 | VOL_MOUNTP_MAXLEN, 0, NULL);
|
|---|
| 433 | if (rc != EOK) {
|
|---|
| 434 | async_answer_0(icall, rc);
|
|---|
| 435 | return;
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | if (mountp != NULL) {
|
|---|
| 439 | log_msg(LOG_DEFAULT, LVL_DEBUG,
|
|---|
| 440 | "vol_part_set_mountp_srv: mountp='%s'", mountp);
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
|---|
| 444 | if (rc != EOK) {
|
|---|
| 445 | free(mountp);
|
|---|
| 446 | async_answer_0(icall, ENOENT);
|
|---|
| 447 | return;
|
|---|
| 448 | }
|
|---|
| 449 |
|
|---|
| 450 | rc = vol_part_set_mountp_part(part, mountp);
|
|---|
| 451 | if (rc != EOK) {
|
|---|
| 452 | free(mountp);
|
|---|
| 453 | async_answer_0(icall, rc);
|
|---|
| 454 | vol_part_del_ref(part);
|
|---|
| 455 | return;
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | free(mountp);
|
|---|
| 459 | async_answer_0(icall, EOK);
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 | static void vol_get_volumes_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 463 | {
|
|---|
| 464 | ipc_call_t call;
|
|---|
| 465 | size_t size;
|
|---|
| 466 | size_t act_size;
|
|---|
| 467 | errno_t rc;
|
|---|
| 468 |
|
|---|
| 469 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_get_volumes_srv()");
|
|---|
| 470 |
|
|---|
| 471 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 472 | async_answer_0(&call, EREFUSED);
|
|---|
| 473 | async_answer_0(icall, EREFUSED);
|
|---|
| 474 | return;
|
|---|
| 475 | }
|
|---|
| 476 |
|
|---|
| 477 | volume_id_t *id_buf = (volume_id_t *) malloc(size);
|
|---|
| 478 | if (id_buf == NULL) {
|
|---|
| 479 | async_answer_0(&call, ENOMEM);
|
|---|
| 480 | async_answer_0(icall, ENOMEM);
|
|---|
| 481 | return;
|
|---|
| 482 | }
|
|---|
| 483 |
|
|---|
| 484 | rc = vol_get_ids(parts->volumes, id_buf, size, &act_size);
|
|---|
| 485 | if (rc != EOK) {
|
|---|
| 486 | async_answer_0(&call, rc);
|
|---|
| 487 | async_answer_0(icall, rc);
|
|---|
| 488 | return;
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | errno_t retval = async_data_read_finalize(&call, id_buf, size);
|
|---|
| 492 | free(id_buf);
|
|---|
| 493 |
|
|---|
| 494 | async_answer_1(icall, retval, act_size);
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | static void vol_info_srv(vol_parts_t *parts, ipc_call_t *icall)
|
|---|
| 498 | {
|
|---|
| 499 | volume_id_t vid;
|
|---|
| 500 | vol_volume_t *volume;
|
|---|
| 501 | vol_info_t vinfo;
|
|---|
| 502 | errno_t rc;
|
|---|
| 503 |
|
|---|
| 504 | vid.id = ipc_get_arg1(icall);
|
|---|
| 505 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_info_srv(%zu)", vid.id);
|
|---|
| 506 |
|
|---|
| 507 | rc = vol_volume_find_by_id_ref(parts->volumes, vid, &volume);
|
|---|
| 508 | if (rc != EOK) {
|
|---|
| 509 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_info_srv: volume %zu not found",
|
|---|
| 510 | vid.id);
|
|---|
| 511 | async_answer_0(icall, ENOENT);
|
|---|
| 512 | return;
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_info_srv: vol_volume_get_info");
|
|---|
| 516 | rc = vol_volume_get_info(volume, &vinfo);
|
|---|
| 517 | if (rc != EOK) {
|
|---|
| 518 | async_answer_0(icall, EIO);
|
|---|
| 519 | goto error;
|
|---|
| 520 | }
|
|---|
| 521 |
|
|---|
| 522 | ipc_call_t call;
|
|---|
| 523 | size_t size;
|
|---|
| 524 | if (!async_data_read_receive(&call, &size)) {
|
|---|
| 525 | async_answer_0(&call, EREFUSED);
|
|---|
| 526 | async_answer_0(icall, EREFUSED);
|
|---|
| 527 | goto error;
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | if (size != sizeof(vol_info_t)) {
|
|---|
| 531 | async_answer_0(&call, EINVAL);
|
|---|
| 532 | async_answer_0(icall, EINVAL);
|
|---|
| 533 | goto error;
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | rc = async_data_read_finalize(&call, &vinfo,
|
|---|
| 537 | min(size, sizeof(vinfo)));
|
|---|
| 538 | if (rc != EOK) {
|
|---|
| 539 | async_answer_0(&call, rc);
|
|---|
| 540 | async_answer_0(icall, rc);
|
|---|
| 541 | goto error;
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | async_answer_0(icall, EOK);
|
|---|
| 545 | error:
|
|---|
| 546 | vol_volume_del_ref(volume);
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| 549 | static void vol_client_conn(ipc_call_t *icall, void *arg)
|
|---|
| 550 | {
|
|---|
| 551 | vol_parts_t *parts = (vol_parts_t *) arg;
|
|---|
| 552 |
|
|---|
| 553 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_client_conn()");
|
|---|
| 554 |
|
|---|
| 555 | /* Accept the connection */
|
|---|
| 556 | async_accept_0(icall);
|
|---|
| 557 |
|
|---|
| 558 | while (true) {
|
|---|
| 559 | ipc_call_t call;
|
|---|
| 560 | async_get_call(&call);
|
|---|
| 561 | sysarg_t method = ipc_get_imethod(&call);
|
|---|
| 562 |
|
|---|
| 563 | if (!method) {
|
|---|
| 564 | /* The other side has hung up */
|
|---|
| 565 | async_answer_0(&call, EOK);
|
|---|
| 566 | return;
|
|---|
| 567 | }
|
|---|
| 568 |
|
|---|
| 569 | switch (method) {
|
|---|
| 570 | case VOL_GET_PARTS:
|
|---|
| 571 | vol_get_parts_srv(parts, &call);
|
|---|
| 572 | break;
|
|---|
| 573 | case VOL_PART_ADD:
|
|---|
| 574 | vol_part_add_srv(parts, &call);
|
|---|
| 575 | break;
|
|---|
| 576 | case VOL_PART_INFO:
|
|---|
| 577 | vol_part_info_srv(parts, &call);
|
|---|
| 578 | break;
|
|---|
| 579 | case VOL_PART_EJECT:
|
|---|
| 580 | vol_part_eject_srv(parts, &call);
|
|---|
| 581 | break;
|
|---|
| 582 | case VOL_PART_EMPTY:
|
|---|
| 583 | vol_part_empty_srv(parts, &call);
|
|---|
| 584 | break;
|
|---|
| 585 | case VOL_PART_INSERT:
|
|---|
| 586 | vol_part_insert_srv(parts, &call);
|
|---|
| 587 | break;
|
|---|
| 588 | case VOL_PART_INSERT_BY_PATH:
|
|---|
| 589 | vol_part_insert_by_path_srv(parts, &call);
|
|---|
| 590 | break;
|
|---|
| 591 | case VOL_PART_LSUPP:
|
|---|
| 592 | vol_part_get_lsupp_srv(parts, &call);
|
|---|
| 593 | break;
|
|---|
| 594 | case VOL_PART_MKFS:
|
|---|
| 595 | vol_part_mkfs_srv(parts, &call);
|
|---|
| 596 | break;
|
|---|
| 597 | case VOL_PART_SET_MOUNTP:
|
|---|
| 598 | vol_part_set_mountp_srv(parts, &call);
|
|---|
| 599 | break;
|
|---|
| 600 | case VOL_GET_VOLUMES:
|
|---|
| 601 | vol_get_volumes_srv(parts, &call);
|
|---|
| 602 | break;
|
|---|
| 603 | case VOL_INFO:
|
|---|
| 604 | vol_info_srv(parts, &call);
|
|---|
| 605 | break;
|
|---|
| 606 | default:
|
|---|
| 607 | async_answer_0(&call, EINVAL);
|
|---|
| 608 | }
|
|---|
| 609 | }
|
|---|
| 610 | }
|
|---|
| 611 |
|
|---|
| 612 | int main(int argc, char *argv[])
|
|---|
| 613 | {
|
|---|
| 614 | errno_t rc;
|
|---|
| 615 |
|
|---|
| 616 | printf("%s: Volume service\n", NAME);
|
|---|
| 617 |
|
|---|
| 618 | if (log_init(NAME) != EOK) {
|
|---|
| 619 | printf(NAME ": Failed to initialize logging.\n");
|
|---|
| 620 | return 1;
|
|---|
| 621 | }
|
|---|
| 622 |
|
|---|
| 623 | rc = vol_init();
|
|---|
| 624 | if (rc != EOK)
|
|---|
| 625 | return 1;
|
|---|
| 626 |
|
|---|
| 627 | printf(NAME ": Accepting connections.\n");
|
|---|
| 628 | task_retval(0);
|
|---|
| 629 | async_manager();
|
|---|
| 630 |
|
|---|
| 631 | return 0;
|
|---|
| 632 | }
|
|---|
| 633 |
|
|---|
| 634 | /** @}
|
|---|
| 635 | */
|
|---|