Changeset 28ed0d9 in mainline for uspace/lib/c/generic/vbd.c


Ignore:
Timestamp:
2015-06-27T19:50:12Z (9 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
78d50bd
Parents:
22fb7ab
Message:

VBD client API, liblabel API, pass partition creation/deletion through to VBD.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/vbd.c

    r22fb7ab r28ed0d9  
    3737#include <ipc/vbd.h>
    3838#include <loc.h>
     39#include <mem.h>
    3940#include <stdlib.h>
    4041#include <types/label.h>
     
    153154}
    154155
     156/** Get list of IDs into a buffer of fixed size.
     157 *
     158 * @param vbd      Virtual Block Device
     159 * @param method   IPC method
     160 * @param arg1     First argument
     161 * @param id_buf   Buffer to store IDs
     162 * @param buf_size Buffer size
     163 * @param act_size Place to store actual size of complete data.
     164 *
     165 * @return EOK on success or negative error code.
     166 */
     167static int vbd_get_ids_once(vbd_t *vbd, sysarg_t method, sysarg_t arg1,
     168    sysarg_t *id_buf, size_t buf_size, size_t *act_size)
     169{
     170        async_exch_t *exch = async_exchange_begin(vbd->sess);
     171
     172        ipc_call_t answer;
     173        aid_t req = async_send_1(exch, method, arg1, &answer);
     174        int rc = async_data_read_start(exch, id_buf, buf_size);
     175
     176        async_exchange_end(exch);
     177
     178        if (rc != EOK) {
     179                async_forget(req);
     180                return rc;
     181        }
     182
     183        sysarg_t retval;
     184        async_wait_for(req, &retval);
     185
     186        if (retval != EOK) {
     187                return retval;
     188        }
     189
     190        *act_size = IPC_GET_ARG1(answer);
     191        return EOK;
     192}
     193
     194/** Get list of IDs.
     195 *
     196 * Returns an allocated array of service IDs.
     197 *
     198 * @param vbd    Virtual Block Device
     199 * @param method IPC method
     200 * @param arg1   IPC argument 1
     201 * @param data   Place to store pointer to array of IDs
     202 * @param count  Place to store number of IDs
     203 * @return       EOK on success or negative error code
     204 */
     205static int vbd_get_ids_internal(vbd_t *vbd, sysarg_t method, sysarg_t arg1,
     206    sysarg_t **data, size_t *count)
     207{
     208        *data = NULL;
     209        *count = 0;
     210
     211        size_t act_size = 0;
     212        int rc = vbd_get_ids_once(vbd, method, arg1, NULL, 0, &act_size);
     213        if (rc != EOK)
     214                return rc;
     215
     216        size_t alloc_size = act_size;
     217        service_id_t *ids = malloc(alloc_size);
     218        if (ids == NULL)
     219                return ENOMEM;
     220
     221        while (true) {
     222                rc = vbd_get_ids_once(vbd, method, arg1, ids, alloc_size,
     223                    &act_size);
     224                if (rc != EOK)
     225                        return rc;
     226
     227                if (act_size <= alloc_size)
     228                        break;
     229
     230                alloc_size = act_size;
     231                ids = realloc(ids, alloc_size);
     232                if (ids == NULL)
     233                        return ENOMEM;
     234        }
     235
     236        *count = act_size / sizeof(service_id_t);
     237        *data = ids;
     238        return EOK;
     239}
     240
     241/** Get list of disks as array of service IDs.
     242 *
     243 * @param vbd   Virtual Block Device
     244 * @param data  Place to store pointer to array
     245 * @param count Place to store length of array (number of entries)
     246 *
     247 * @return EOK on success or negative error code
     248 */
     249int vbd_label_get_parts(vbd_t *vbd, service_id_t disk,
     250    service_id_t **data, size_t *count)
     251{
     252        return vbd_get_ids_internal(vbd, VBD_LABEL_GET_PARTS, disk,
     253            data, count);
     254}
     255
     256int vbd_part_get_info(vbd_t *vbd, vbd_part_id_t part, vbd_part_info_t *pinfo)
     257{
     258        async_exch_t *exch;
     259        int retval;
     260
     261        exch = async_exchange_begin(vbd->sess);
     262        retval = async_req_1_0(exch, VBD_PART_GET_INFO, part);
     263        async_exchange_end(exch);
     264
     265        if (retval != EOK)
     266                return EIO;
     267
     268        return EOK;
     269}
     270
     271int vbd_part_create(vbd_t *vbd, service_id_t disk, vbd_part_spec_t *pspec,
     272    vbd_part_id_t *rpart)
     273{
     274        async_exch_t *exch;
     275        sysarg_t part;
     276        int retval;
     277
     278        exch = async_exchange_begin(vbd->sess);
     279        retval = async_req_1_1(exch, VBD_PART_CREATE, disk, &part);
     280        async_exchange_end(exch);
     281
     282        if (retval != EOK)
     283                return EIO;
     284
     285        *rpart = (vbd_part_id_t)part;
     286        return EOK;
     287}
     288
     289int vbd_part_delete(vbd_t *vbd, vbd_part_id_t part)
     290{
     291        async_exch_t *exch;
     292        int retval;
     293
     294        exch = async_exchange_begin(vbd->sess);
     295        retval = async_req_1_0(exch, VBD_PART_DELETE, part);
     296        async_exchange_end(exch);
     297
     298        if (retval != EOK)
     299                return EIO;
     300
     301        return EOK;
     302}
     303
     304void vbd_pspec_init(vbd_part_spec_t *pspec)
     305{
     306        memset(pspec, 0, sizeof(vbd_part_spec_t));
     307}
     308
    155309/** @}
    156310 */
Note: See TracChangeset for help on using the changeset viewer.