[1356f85a] | 1 | /*
|
---|
[4c6fd56] | 2 | * Copyright (c) 2023 Jiri Svoboda
|
---|
[1356f85a] | 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>
|
---|
[c1694b6b] | 38 | #include <str_error.h>
|
---|
[1356f85a] | 39 | #include <io/log.h>
|
---|
| 40 | #include <ipc/services.h>
|
---|
[22fb7ab] | 41 | #include <ipc/vol.h>
|
---|
[1356f85a] | 42 | #include <loc.h>
|
---|
[0ecfc62] | 43 | #include <macros.h>
|
---|
[1356f85a] | 44 | #include <stdio.h>
|
---|
| 45 | #include <stdlib.h>
|
---|
| 46 | #include <task.h>
|
---|
[edebb4a1] | 47 | #include <types/vol.h>
|
---|
[1356f85a] | 48 |
|
---|
[9c2c7d2] | 49 | #include "mkfs.h"
|
---|
[372df8f] | 50 | #include "part.h"
|
---|
[64ffd83] | 51 | #include "volume.h"
|
---|
[1356f85a] | 52 |
|
---|
| 53 | #define NAME "volsrv"
|
---|
| 54 |
|
---|
[df8eaba] | 55 | const char *vol_cfg_file = "/cfg/volsrv.sif";
|
---|
[1dcba91] | 56 |
|
---|
[984a9ba] | 57 | static void vol_client_conn(ipc_call_t *, void *);
|
---|
[1356f85a] | 58 |
|
---|
[b7fd2a0] | 59 | static errno_t vol_init(void)
|
---|
[1356f85a] | 60 | {
|
---|
[b7fd2a0] | 61 | errno_t rc;
|
---|
[64ffd83] | 62 | vol_volumes_t *volumes = NULL;
|
---|
[e89a06a] | 63 | vol_parts_t *parts = NULL;
|
---|
[4c6fd56] | 64 | loc_srv_t *srv = NULL;
|
---|
[e89a06a] | 65 |
|
---|
[1356f85a] | 66 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_init()");
|
---|
| 67 |
|
---|
[1dcba91] | 68 | rc = vol_volumes_create(vol_cfg_file, &volumes);
|
---|
[64ffd83] | 69 | if (rc != EOK)
|
---|
| 70 | goto error;
|
---|
| 71 |
|
---|
| 72 | rc = vol_parts_create(volumes, &parts);
|
---|
[22fb7ab] | 73 | if (rc != EOK)
|
---|
[e89a06a] | 74 | goto error;
|
---|
[22fb7ab] | 75 |
|
---|
[e89a06a] | 76 | rc = vol_part_discovery_start(parts);
|
---|
[1356f85a] | 77 | if (rc != EOK)
|
---|
[e89a06a] | 78 | goto error;
|
---|
[1356f85a] | 79 |
|
---|
[e89a06a] | 80 | async_set_fallback_port_handler(vol_client_conn, parts);
|
---|
[1356f85a] | 81 |
|
---|
[4c6fd56] | 82 | rc = loc_server_register(NAME, &srv);
|
---|
[1356f85a] | 83 | if (rc != EOK) {
|
---|
[c1694b6b] | 84 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
|
---|
[e89a06a] | 85 | rc = EEXIST;
|
---|
[1356f85a] | 86 | }
|
---|
| 87 |
|
---|
| 88 | service_id_t sid;
|
---|
[4c6fd56] | 89 | rc = loc_service_register(srv, SERVICE_NAME_VOLSRV, &sid);
|
---|
[1356f85a] | 90 | if (rc != EOK) {
|
---|
[c1694b6b] | 91 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
|
---|
[e89a06a] | 92 | rc = EEXIST;
|
---|
| 93 | goto error;
|
---|
[1356f85a] | 94 | }
|
---|
| 95 |
|
---|
| 96 | return EOK;
|
---|
[e89a06a] | 97 | error:
|
---|
[4c6fd56] | 98 | if (srv != NULL)
|
---|
| 99 | loc_server_unregister(srv);
|
---|
[64ffd83] | 100 | vol_volumes_destroy(volumes);
|
---|
[e89a06a] | 101 | vol_parts_destroy(parts);
|
---|
| 102 | return rc;
|
---|
[1356f85a] | 103 | }
|
---|
| 104 |
|
---|
[e89a06a] | 105 | static void vol_get_parts_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[22fb7ab] | 106 | {
|
---|
[984a9ba] | 107 | ipc_call_t call;
|
---|
[22fb7ab] | 108 | size_t size;
|
---|
| 109 | size_t act_size;
|
---|
[b7fd2a0] | 110 | errno_t rc;
|
---|
[22fb7ab] | 111 |
|
---|
[984a9ba] | 112 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 113 | async_answer_0(&call, EREFUSED);
|
---|
| 114 | async_answer_0(icall, EREFUSED);
|
---|
[22fb7ab] | 115 | return;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | service_id_t *id_buf = (service_id_t *) malloc(size);
|
---|
| 119 | if (id_buf == NULL) {
|
---|
[984a9ba] | 120 | async_answer_0(&call, ENOMEM);
|
---|
| 121 | async_answer_0(icall, ENOMEM);
|
---|
[22fb7ab] | 122 | return;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[e89a06a] | 125 | rc = vol_part_get_ids(parts, id_buf, size, &act_size);
|
---|
[22fb7ab] | 126 | if (rc != EOK) {
|
---|
[984a9ba] | 127 | async_answer_0(&call, rc);
|
---|
| 128 | async_answer_0(icall, rc);
|
---|
[22fb7ab] | 129 | return;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[984a9ba] | 132 | errno_t retval = async_data_read_finalize(&call, id_buf, size);
|
---|
[22fb7ab] | 133 | free(id_buf);
|
---|
| 134 |
|
---|
[984a9ba] | 135 | async_answer_1(icall, retval, act_size);
|
---|
[22fb7ab] | 136 | }
|
---|
| 137 |
|
---|
[e89a06a] | 138 | static void vol_part_add_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[edebb4a1] | 139 | {
|
---|
| 140 | service_id_t sid;
|
---|
[b7fd2a0] | 141 | errno_t rc;
|
---|
[edebb4a1] | 142 |
|
---|
[fafb8e5] | 143 | sid = ipc_get_arg1(icall);
|
---|
[edebb4a1] | 144 |
|
---|
[64ffd83] | 145 | rc = vol_part_add_part(parts, sid);
|
---|
[edebb4a1] | 146 | if (rc != EOK) {
|
---|
[984a9ba] | 147 | async_answer_0(icall, rc);
|
---|
[edebb4a1] | 148 | return;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[984a9ba] | 151 | async_answer_0(icall, EOK);
|
---|
[edebb4a1] | 152 | }
|
---|
| 153 |
|
---|
[e89a06a] | 154 | static void vol_part_info_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[22fb7ab] | 155 | {
|
---|
| 156 | service_id_t sid;
|
---|
[372df8f] | 157 | vol_part_t *part;
|
---|
| 158 | vol_part_info_t pinfo;
|
---|
[b7fd2a0] | 159 | errno_t rc;
|
---|
[22fb7ab] | 160 |
|
---|
[fafb8e5] | 161 | sid = ipc_get_arg1(icall);
|
---|
[55f8c6e7] | 162 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_info_srv(%zu)",
|
---|
[edebb4a1] | 163 | sid);
|
---|
[e89a06a] | 164 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
---|
[22fb7ab] | 165 | if (rc != EOK) {
|
---|
[984a9ba] | 166 | async_answer_0(icall, ENOENT);
|
---|
[22fb7ab] | 167 | return;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[372df8f] | 170 | rc = vol_part_get_info(part, &pinfo);
|
---|
[b7a4d06] | 171 | if (rc != EOK) {
|
---|
[984a9ba] | 172 | async_answer_0(icall, EIO);
|
---|
[1a9174e] | 173 | goto error;
|
---|
[b7a4d06] | 174 | }
|
---|
| 175 |
|
---|
[984a9ba] | 176 | ipc_call_t call;
|
---|
[0ecfc62] | 177 | size_t size;
|
---|
[984a9ba] | 178 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 179 | async_answer_0(&call, EREFUSED);
|
---|
| 180 | async_answer_0(icall, EREFUSED);
|
---|
[1a9174e] | 181 | goto error;
|
---|
[0ecfc62] | 182 | }
|
---|
| 183 |
|
---|
| 184 | if (size != sizeof(vol_part_info_t)) {
|
---|
[984a9ba] | 185 | async_answer_0(&call, EINVAL);
|
---|
| 186 | async_answer_0(icall, EINVAL);
|
---|
[1a9174e] | 187 | goto error;
|
---|
[0ecfc62] | 188 | }
|
---|
| 189 |
|
---|
[984a9ba] | 190 | rc = async_data_read_finalize(&call, &pinfo,
|
---|
[0ecfc62] | 191 | min(size, sizeof(pinfo)));
|
---|
| 192 | if (rc != EOK) {
|
---|
[984a9ba] | 193 | async_answer_0(&call, rc);
|
---|
| 194 | async_answer_0(icall, rc);
|
---|
[1a9174e] | 195 | goto error;
|
---|
[0ecfc62] | 196 | }
|
---|
| 197 |
|
---|
[984a9ba] | 198 | async_answer_0(icall, EOK);
|
---|
[1a9174e] | 199 | error:
|
---|
| 200 | vol_part_del_ref(part);
|
---|
[22fb7ab] | 201 | }
|
---|
| 202 |
|
---|
[e89a06a] | 203 | static void vol_part_eject_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[72c72d4] | 204 | {
|
---|
| 205 | service_id_t sid;
|
---|
| 206 | vol_part_t *part;
|
---|
| 207 | errno_t rc;
|
---|
| 208 |
|
---|
[fafb8e5] | 209 | sid = ipc_get_arg1(icall);
|
---|
[72c72d4] | 210 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_eject_srv(%zu)", sid);
|
---|
| 211 |
|
---|
[e89a06a] | 212 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
---|
[72c72d4] | 213 | if (rc != EOK) {
|
---|
[984a9ba] | 214 | async_answer_0(icall, ENOENT);
|
---|
[f0f8787] | 215 | return;
|
---|
[72c72d4] | 216 | }
|
---|
| 217 |
|
---|
| 218 | rc = vol_part_eject_part(part);
|
---|
| 219 | if (rc != EOK) {
|
---|
[984a9ba] | 220 | async_answer_0(icall, EIO);
|
---|
[1a9174e] | 221 | goto error;
|
---|
[72c72d4] | 222 | }
|
---|
| 223 |
|
---|
[984a9ba] | 224 | async_answer_0(icall, EOK);
|
---|
[1a9174e] | 225 | error:
|
---|
| 226 | vol_part_del_ref(part);
|
---|
[72c72d4] | 227 | }
|
---|
| 228 |
|
---|
[f0f8787] | 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 |
|
---|
[fafb8e5] | 235 | sid = ipc_get_arg1(icall);
|
---|
[f0f8787] | 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 |
|
---|
[b82985e] | 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 |
|
---|
[9e45a41] | 261 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_insert_by_path_srv()");
|
---|
[b82985e] | 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 |
|
---|
[e89a06a] | 293 | static void vol_part_empty_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[22fb7ab] | 294 | {
|
---|
| 295 | service_id_t sid;
|
---|
[372df8f] | 296 | vol_part_t *part;
|
---|
[b7fd2a0] | 297 | errno_t rc;
|
---|
[22fb7ab] | 298 |
|
---|
[fafb8e5] | 299 | sid = ipc_get_arg1(icall);
|
---|
[55f8c6e7] | 300 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_empty_srv(%zu)", sid);
|
---|
[22fb7ab] | 301 |
|
---|
[e89a06a] | 302 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
---|
[22fb7ab] | 303 | if (rc != EOK) {
|
---|
[984a9ba] | 304 | async_answer_0(icall, ENOENT);
|
---|
[22fb7ab] | 305 | return;
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[372df8f] | 308 | rc = vol_part_empty_part(part);
|
---|
[603c1d1f] | 309 | if (rc != EOK) {
|
---|
[984a9ba] | 310 | async_answer_0(icall, EIO);
|
---|
[1a9174e] | 311 | goto error;
|
---|
[603c1d1f] | 312 | }
|
---|
[22fb7ab] | 313 |
|
---|
[984a9ba] | 314 | async_answer_0(icall, EOK);
|
---|
[1a9174e] | 315 | error:
|
---|
| 316 | vol_part_del_ref(part);
|
---|
[22fb7ab] | 317 | }
|
---|
[1356f85a] | 318 |
|
---|
[e89a06a] | 319 | static void vol_part_get_lsupp_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[9c2c7d2] | 320 | {
|
---|
| 321 | vol_fstype_t fstype;
|
---|
| 322 | vol_label_supp_t vlsupp;
|
---|
[b7fd2a0] | 323 | errno_t rc;
|
---|
[9c2c7d2] | 324 |
|
---|
[fafb8e5] | 325 | fstype = ipc_get_arg1(icall);
|
---|
[9c2c7d2] | 326 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_get_lsupp_srv(%u)",
|
---|
| 327 | fstype);
|
---|
| 328 |
|
---|
| 329 | volsrv_part_get_lsupp(fstype, &vlsupp);
|
---|
| 330 |
|
---|
[984a9ba] | 331 | ipc_call_t call;
|
---|
[9c2c7d2] | 332 | size_t size;
|
---|
[984a9ba] | 333 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 334 | async_answer_0(&call, EREFUSED);
|
---|
| 335 | async_answer_0(icall, EREFUSED);
|
---|
[9c2c7d2] | 336 | return;
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | if (size != sizeof(vol_label_supp_t)) {
|
---|
[984a9ba] | 340 | async_answer_0(&call, EINVAL);
|
---|
| 341 | async_answer_0(icall, EINVAL);
|
---|
[9c2c7d2] | 342 | return;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
[984a9ba] | 345 | rc = async_data_read_finalize(&call, &vlsupp,
|
---|
[9c2c7d2] | 346 | min(size, sizeof(vlsupp)));
|
---|
| 347 | if (rc != EOK) {
|
---|
[984a9ba] | 348 | async_answer_0(&call, rc);
|
---|
| 349 | async_answer_0(icall, rc);
|
---|
[9c2c7d2] | 350 | return;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
[984a9ba] | 353 | async_answer_0(icall, EOK);
|
---|
[9c2c7d2] | 354 | }
|
---|
| 355 |
|
---|
[e89a06a] | 356 | static void vol_part_mkfs_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[44fe800] | 357 | {
|
---|
| 358 | service_id_t sid;
|
---|
| 359 | vol_part_t *part;
|
---|
| 360 | vol_fstype_t fstype;
|
---|
[2d78d88] | 361 | char *label = NULL;
|
---|
| 362 | char *mountp = NULL;
|
---|
[b7fd2a0] | 363 | errno_t rc;
|
---|
[44fe800] | 364 |
|
---|
[9e45a41] | 365 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_srv()");
|
---|
[5f36841] | 366 |
|
---|
[fafb8e5] | 367 | sid = ipc_get_arg1(icall);
|
---|
| 368 | fstype = ipc_get_arg2(icall);
|
---|
[44fe800] | 369 |
|
---|
[9c2c7d2] | 370 | rc = async_data_write_accept((void **)&label, true, 0, VOL_LABEL_MAXLEN,
|
---|
| 371 | 0, NULL);
|
---|
| 372 | if (rc != EOK) {
|
---|
[984a9ba] | 373 | async_answer_0(icall, rc);
|
---|
[2d78d88] | 374 | goto error;
|
---|
[9c2c7d2] | 375 | }
|
---|
| 376 |
|
---|
[5f36841] | 377 | if (label != NULL) {
|
---|
[9e45a41] | 378 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_srv: label='%s'",
|
---|
[5f36841] | 379 | label);
|
---|
| 380 | }
|
---|
[9c2c7d2] | 381 |
|
---|
[64ffd83] | 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);
|
---|
[2d78d88] | 386 | goto error;
|
---|
[64ffd83] | 387 | }
|
---|
| 388 |
|
---|
| 389 | if (mountp != NULL) {
|
---|
[9e45a41] | 390 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_srv: mountp='%s'",
|
---|
[64ffd83] | 391 | mountp);
|
---|
| 392 | }
|
---|
| 393 |
|
---|
[e89a06a] | 394 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
---|
[44fe800] | 395 | if (rc != EOK) {
|
---|
[984a9ba] | 396 | async_answer_0(icall, ENOENT);
|
---|
[2d78d88] | 397 | goto error;
|
---|
[44fe800] | 398 | }
|
---|
| 399 |
|
---|
[64ffd83] | 400 | rc = vol_part_mkfs_part(part, fstype, label, mountp);
|
---|
[44fe800] | 401 | if (rc != EOK) {
|
---|
[2d78d88] | 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)
|
---|
[9c2c7d2] | 414 | free(label);
|
---|
[2d78d88] | 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 |
|
---|
[9e45a41] | 427 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_set_mountp_srv()");
|
---|
[2d78d88] | 428 |
|
---|
[fafb8e5] | 429 | sid = ipc_get_arg1(icall);
|
---|
[2d78d88] | 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) {
|
---|
[9e45a41] | 439 | log_msg(LOG_DEFAULT, LVL_DEBUG,
|
---|
[2d78d88] | 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);
|
---|
[984a9ba] | 453 | async_answer_0(icall, rc);
|
---|
[1a9174e] | 454 | vol_part_del_ref(part);
|
---|
[44fe800] | 455 | return;
|
---|
| 456 | }
|
---|
| 457 |
|
---|
[2d78d88] | 458 | free(mountp);
|
---|
[984a9ba] | 459 | async_answer_0(icall, EOK);
|
---|
[44fe800] | 460 | }
|
---|
| 461 |
|
---|
[63c1dd5] | 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 |
|
---|
[9e45a41] | 469 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_get_volumes_srv()");
|
---|
[63c1dd5] | 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 |
|
---|
[fafb8e5] | 504 | vid.id = ipc_get_arg1(icall);
|
---|
[63c1dd5] | 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 |
|
---|
[984a9ba] | 549 | static void vol_client_conn(ipc_call_t *icall, void *arg)
|
---|
[1356f85a] | 550 | {
|
---|
[e89a06a] | 551 | vol_parts_t *parts = (vol_parts_t *) arg;
|
---|
| 552 |
|
---|
[1356f85a] | 553 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_client_conn()");
|
---|
| 554 |
|
---|
| 555 | /* Accept the connection */
|
---|
[beb83c1] | 556 | async_accept_0(icall);
|
---|
[1356f85a] | 557 |
|
---|
| 558 | while (true) {
|
---|
| 559 | ipc_call_t call;
|
---|
[984a9ba] | 560 | async_get_call(&call);
|
---|
[fafb8e5] | 561 | sysarg_t method = ipc_get_imethod(&call);
|
---|
[1356f85a] | 562 |
|
---|
| 563 | if (!method) {
|
---|
| 564 | /* The other side has hung up */
|
---|
[984a9ba] | 565 | async_answer_0(&call, EOK);
|
---|
[1356f85a] | 566 | return;
|
---|
| 567 | }
|
---|
| 568 |
|
---|
| 569 | switch (method) {
|
---|
[372df8f] | 570 | case VOL_GET_PARTS:
|
---|
[e89a06a] | 571 | vol_get_parts_srv(parts, &call);
|
---|
[22fb7ab] | 572 | break;
|
---|
[edebb4a1] | 573 | case VOL_PART_ADD:
|
---|
[e89a06a] | 574 | vol_part_add_srv(parts, &call);
|
---|
[edebb4a1] | 575 | break;
|
---|
[372df8f] | 576 | case VOL_PART_INFO:
|
---|
[e89a06a] | 577 | vol_part_info_srv(parts, &call);
|
---|
[22fb7ab] | 578 | break;
|
---|
[72c72d4] | 579 | case VOL_PART_EJECT:
|
---|
[e89a06a] | 580 | vol_part_eject_srv(parts, &call);
|
---|
[72c72d4] | 581 | break;
|
---|
[372df8f] | 582 | case VOL_PART_EMPTY:
|
---|
[e89a06a] | 583 | vol_part_empty_srv(parts, &call);
|
---|
[22fb7ab] | 584 | break;
|
---|
[f0f8787] | 585 | case VOL_PART_INSERT:
|
---|
| 586 | vol_part_insert_srv(parts, &call);
|
---|
| 587 | break;
|
---|
[b82985e] | 588 | case VOL_PART_INSERT_BY_PATH:
|
---|
| 589 | vol_part_insert_by_path_srv(parts, &call);
|
---|
| 590 | break;
|
---|
[9c2c7d2] | 591 | case VOL_PART_LSUPP:
|
---|
[e89a06a] | 592 | vol_part_get_lsupp_srv(parts, &call);
|
---|
[9c2c7d2] | 593 | break;
|
---|
[44fe800] | 594 | case VOL_PART_MKFS:
|
---|
[e89a06a] | 595 | vol_part_mkfs_srv(parts, &call);
|
---|
[44fe800] | 596 | break;
|
---|
[2d78d88] | 597 | case VOL_PART_SET_MOUNTP:
|
---|
| 598 | vol_part_set_mountp_srv(parts, &call);
|
---|
| 599 | break;
|
---|
[63c1dd5] | 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;
|
---|
[1356f85a] | 606 | default:
|
---|
[984a9ba] | 607 | async_answer_0(&call, EINVAL);
|
---|
[1356f85a] | 608 | }
|
---|
| 609 | }
|
---|
| 610 | }
|
---|
| 611 |
|
---|
| 612 | int main(int argc, char *argv[])
|
---|
| 613 | {
|
---|
[b7fd2a0] | 614 | errno_t rc;
|
---|
[1356f85a] | 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 | */
|
---|