Changeset 6bc542b in mainline for uspace/srv


Ignore:
Timestamp:
2015-07-02T21:53:12Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
99c23405
Parents:
6a0d4ce2
Message:

Allocate and create partition with libfdisk (except actual modification of on-disk label).

Location:
uspace/srv/bd/vbd
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/vbd/disk.c

    r6a0d4ce2 r6bc542b  
    112112}
    113113
    114 static int vbds_part_add(vbds_disk_t *disk, label_part_t *lpart)
     114static int vbds_part_add(vbds_disk_t *disk, label_part_t *lpart,
     115    vbds_part_t **rpart)
    115116{
    116117        vbds_part_t *part;
     
    163164        list_append(&part->lparts, &vbds_parts);
    164165
     166        if (rpart != NULL)
     167                *rpart = part;
    165168        return EOK;
    166169}
     
    230233        part = label_part_first(label);
    231234        while (part != NULL) {
    232                 rc = vbds_part_add(disk, part);
     235                rc = vbds_part_add(disk, part, NULL);
    233236                if (rc != EOK) {
    234237                        log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding partitio "
     
    389392}
    390393
    391 int vbds_part_create(service_id_t sid, vbds_part_id_t *rpart)
     394int vbds_part_create(service_id_t sid, vbd_part_spec_t *pspec,
     395    vbds_part_id_t *rpart)
    392396{
    393397        vbds_disk_t *disk;
    394398        vbds_part_t *part;
    395         label_part_spec_t pspec;
     399        label_part_spec_t lpspec;
    396400        label_part_t *lpart;
    397401        int rc;
    398 
    399         part = calloc(1, sizeof(vbds_part_t));
    400         if (part == NULL)
    401                 return ENOMEM;
    402402
    403403        rc = vbds_disk_by_svcid(sid, &disk);
     
    408408        }
    409409
    410         label_pspec_init(&pspec);
    411         rc = label_part_create(disk->label, &pspec, &lpart);
     410        label_pspec_init(&lpspec);
     411        lpspec.index = pspec->index;
     412        lpspec.block0 = pspec->block0;
     413        lpspec.nblocks = pspec->nblocks;
     414        lpspec.ptype = pspec->ptype;
     415
     416        rc = label_part_create(disk->label, &lpspec, &lpart);
    412417        if (rc != EOK) {
    413418                log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating partition.");
     
    415420        }
    416421
    417         rc = vbds_part_add(disk, lpart);
     422        rc = vbds_part_add(disk, lpart, &part);
    418423        if (rc != EOK) {
    419424                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed while creating "
     
    427432        }
    428433
     434        if (rpart != NULL)
     435                *rpart = part->id;
    429436        return EOK;
    430437error:
    431         free(part);
    432438        return rc;
    433439}
  • uspace/srv/bd/vbd/disk.h

    r6a0d4ce2 r6bc542b  
    5050extern int vbds_label_delete(service_id_t);
    5151extern int vbds_part_get_info(vbds_part_id_t, vbd_part_info_t *);
    52 extern int vbds_part_create(service_id_t, vbds_part_id_t *);
     52extern int vbds_part_create(service_id_t, vbd_part_spec_t *,vbds_part_id_t *);
    5353extern int vbds_part_delete(vbds_part_id_t);
    5454extern void vbds_bd_conn(ipc_callid_t, ipc_call_t *, void *);
  • uspace/srv/bd/vbd/vbd.c

    r6a0d4ce2 r6bc542b  
    115115        rc = vbds_disk_info(disk_sid, &dinfo);
    116116        if (rc != EOK) {
    117                 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() call failed");
    118                 async_answer_0(iid, rc);
    119                 return;
    120         }
    121 
    122         log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() data_read_receive");
     117                async_answer_0(iid, rc);
     118                return;
     119        }
     120
    123121        ipc_callid_t callid;
    124122        size_t size;
    125123        if (!async_data_read_receive(&callid, &size)) {
    126                 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() failed");
    127124                async_answer_0(callid, EREFUSED);
    128125                async_answer_0(iid, EREFUSED);
     
    130127        }
    131128
    132         log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() check size");
    133129        if (size != sizeof(vbds_disk_info_t)) {
    134                 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() wrong size");
    135130                async_answer_0(callid, EINVAL);
    136131                async_answer_0(iid, EINVAL);
     
    138133        }
    139134
    140         log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() data_read_finalize");
    141135        rc = async_data_read_finalize(callid, &dinfo,
    142136            min(size, sizeof(dinfo)));
     
    147141        }
    148142
    149         log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() reply EOK");
    150143        async_answer_0(iid, EOK);
    151144}
     
    234227{
    235228        service_id_t disk_sid;
     229        vbd_part_spec_t pspec;
    236230        vbds_part_id_t part;
    237231        int rc;
     
    240234
    241235        disk_sid = IPC_GET_ARG1(*icall);
    242         rc = vbds_part_create(disk_sid, &part);
     236
     237        ipc_callid_t callid;
     238        size_t size;
     239        if (!async_data_write_receive(&callid, &size)) {
     240                async_answer_0(callid, EREFUSED);
     241                async_answer_0(iid, EREFUSED);
     242                return;
     243        }
     244
     245        if (size != sizeof(vbd_part_spec_t)) {
     246                async_answer_0(callid, EINVAL);
     247                async_answer_0(iid, EINVAL);
     248                return;
     249        }
     250
     251        rc = async_data_write_finalize(callid, &pspec, sizeof(vbd_part_spec_t));
     252        if (rc != EOK) {
     253                async_answer_0(callid, rc);
     254                async_answer_0(iid, rc);
     255                return;
     256        }
     257
     258        rc = vbds_part_create(disk_sid, &pspec, &part);
     259        if (rc != EOK) {
     260                async_answer_0(iid, rc);
     261                return;
     262        }
     263
    243264        async_answer_1(iid, (sysarg_t)rc, (sysarg_t)part);
    244265}
Note: See TracChangeset for help on using the changeset viewer.