Changeset 99c23405 in mainline for uspace/srv/bd/vbd/disk.c


Ignore:
Timestamp:
2015-07-04T15:18:06Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
603c1d1f
Parents:
6bc542b
Message:

Persistent partition table modification when creating or deleting partition.

File:
1 edited

Legend:

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

    r6bc542b r99c23405  
    112112}
    113113
     114/** Add partition to our inventory based on liblabel partition structure */
    114115static int vbds_part_add(vbds_disk_t *disk, label_part_t *lpart,
    115116    vbds_part_t **rpart)
     
    119120        label_part_info_t lpinfo;
    120121        char *name;
    121         int pno;
    122122        int rc;
    123123
     
    132132
    133133        /* XXX Proper service name */
    134         pno = list_count(&disk->parts);
    135         rc = asprintf(&name, "%sp%u", disk->svc_name, pno);
     134        rc = asprintf(&name, "%sp%u", disk->svc_name, lpart->index);
    136135        if (rc < 0) {
    137136                log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory.");
     
    166165        if (rpart != NULL)
    167166                *rpart = part;
     167        return EOK;
     168}
     169
     170/** Remove partition from our inventory leaving only the underlying liblabel
     171 * partition structure.
     172 */
     173static int vbds_part_remove(vbds_part_t *part, label_part_t **rlpart)
     174{
     175        label_part_t *lpart;
     176        int rc;
     177
     178        log_msg(LOG_DEFAULT, LVL_NOTE, "vbds_part_remove(%p)", part);
     179
     180        lpart = part->lpart;
     181
     182        if (part->open_cnt > 0)
     183                return EBUSY;
     184
     185        rc = loc_service_unregister((service_id_t)part->id);
     186        if (rc != EOK)
     187                return EIO;
     188
     189        list_remove(&part->ldisk);
     190        list_remove(&part->lparts);
     191        free(part);
     192
     193        if (rlpart != NULL)
     194                *rlpart = lpart;
    168195        return EOK;
    169196}
     
    442469{
    443470        vbds_part_t *part;
     471        vbds_disk_t *disk;
     472        label_part_t *lpart;
    444473        int rc;
    445474
     
    448477                return rc;
    449478
    450         rc = label_part_destroy(part->lpart);
    451         if (rc != EOK)
    452                 return rc;
    453 
    454         list_remove(&part->ldisk);
    455         list_remove(&part->lparts);
    456         free(part);
     479        disk = part->disk;
     480
     481        rc = vbds_part_remove(part, &lpart);
     482        if (rc != EOK)
     483                return rc;
     484
     485        rc = label_part_destroy(lpart);
     486        if (rc != EOK) {
     487                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed deleting partition");
     488
     489                /* Try rolling back */
     490                rc = vbds_part_add(disk, lpart, NULL);
     491                if (rc != EOK)
     492                        log_msg(LOG_DEFAULT, LVL_ERROR, "Failed rolling back.");
     493
     494                return EIO;
     495        }
     496
    457497        return EOK;
    458498}
Note: See TracChangeset for help on using the changeset viewer.