Changeset 6bc542b in mainline
- Timestamp:
- 2015-07-02T21:53:12Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 99c23405
- Parents:
- 6a0d4ce2
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vbd.c
r6a0d4ce2 r6bc542b 107 107 } 108 108 109 #include <io/log.h>110 109 /** Get disk information. */ 111 110 int vbd_disk_info(vbd_t *vbd, service_id_t sid, vbd_disk_info_t *vinfo) … … 115 114 ipc_call_t answer; 116 115 117 log_msg(LOG_DEFAULT, LVL_DEBUG, "vbd_disk_info() begin exchange");118 116 exch = async_exchange_begin(vbd->sess); 119 117 aid_t req = async_send_1(exch, VBD_DISK_INFO, sid, &answer); 120 log_msg(LOG_DEFAULT, LVL_DEBUG, "vbd_disk_info() read start");121 118 int rc = async_data_read_start(exch, vinfo, sizeof(vbd_disk_info_t)); 122 log_msg(LOG_DEFAULT, LVL_DEBUG, "vbd_disk_info() end exch");123 119 async_exchange_end(exch); 124 120 … … 128 124 } 129 125 130 log_msg(LOG_DEFAULT, LVL_DEBUG, "vbd_disk_info() wait fore req reply");131 126 async_wait_for(req, &retval); 132 127 if (retval != EOK) 133 128 return EIO; 134 129 135 log_msg(LOG_DEFAULT, LVL_DEBUG, "vbd_disk_info() done");136 130 return EOK; 137 131 } … … 293 287 { 294 288 async_exch_t *exch; 295 sysarg_t part; 289 sysarg_t retval; 290 ipc_call_t answer; 291 292 exch = async_exchange_begin(vbd->sess); 293 aid_t req = async_send_1(exch, VBD_PART_CREATE, disk, &answer); 294 int rc = async_data_write_start(exch, pspec, sizeof(vbd_part_spec_t)); 295 async_exchange_end(exch); 296 297 if (rc != EOK) { 298 async_forget(req); 299 return EIO; 300 } 301 302 async_wait_for(req, &retval); 303 if (retval != EOK) 304 return EIO; 305 306 *rpart = (vbd_part_id_t)IPC_GET_ARG1(answer); 307 return EOK; 308 309 } 310 311 int vbd_part_delete(vbd_t *vbd, vbd_part_id_t part) 312 { 313 async_exch_t *exch; 296 314 int retval; 297 315 298 316 exch = async_exchange_begin(vbd->sess); 299 retval = async_req_1_1(exch, VBD_PART_CREATE, disk, &part);300 async_exchange_end(exch);301 302 if (retval != EOK)303 return EIO;304 305 *rpart = (vbd_part_id_t)part;306 return EOK;307 }308 309 int vbd_part_delete(vbd_t *vbd, vbd_part_id_t part)310 {311 async_exch_t *exch;312 int retval;313 314 exch = async_exchange_begin(vbd->sess);315 317 retval = async_req_1_0(exch, VBD_PART_DELETE, part); 316 318 async_exchange_end(exch); -
uspace/lib/c/include/vbd.h
r6a0d4ce2 r6bc542b 59 59 } vbd_disk_info_t; 60 60 61 /** Specification of new partition */ 61 62 typedef struct { 63 /** Partition index */ 64 int index; 65 /** First block */ 66 aoff64_t block0; 67 /** Number of blocks */ 68 aoff64_t nblocks; 69 /** Partition type */ 70 uint64_t ptype; 62 71 } vbd_part_spec_t; 63 72 73 /** Partition info */ 64 74 typedef struct { 65 75 /** Partition index */ -
uspace/lib/fdisk/src/fdisk.c
r6a0d4ce2 r6bc542b 58 58 }; 59 59 60 static int fdisk_part_spec_prepare(fdisk_dev_t *, fdisk_part_spec_t *, 61 vbd_part_spec_t *); 62 60 63 static void fdisk_dev_info_delete(fdisk_dev_info_t *info) 61 64 { … … 497 500 int rc; 498 501 499 part = calloc(1, sizeof(fdisk_part_t)); 500 if (part == NULL) 501 return ENOMEM; 502 502 printf("fdisk_part_create()\n"); 503 504 rc = fdisk_part_spec_prepare(dev, pspec, &vpspec); 505 if (rc != EOK) 506 return EIO; 507 508 printf("fdisk_part_create() - call vbd_part_create\n"); 503 509 rc = vbd_part_create(dev->fdisk->vbd, dev->sid, &vpspec, &partid); 504 if (rc != EOK) { 505 free(part); 506 return EIO; 507 } 508 509 rc = fdisk_part_add(dev, partid, rpart); 510 if (rc != EOK) 511 return EIO; 512 513 printf("fdisk_part_create() - call fdisk_part_add\n"); 514 rc = fdisk_part_add(dev, partid, &part); 510 515 if (rc != EOK) { 511 516 /* Try rolling back */ … … 514 519 } 515 520 516 (*rpart)->fstype = pspec->fstype; 517 (*rpart)->capacity = pspec->capacity; 518 521 printf("fdisk_part_create() - done\n"); 522 part->fstype = pspec->fstype; 523 part->capacity = pspec->capacity; 524 525 if (rpart != NULL) 526 *rpart = part; 519 527 return EOK; 520 528 } … … 650 658 } 651 659 660 /** Get free partition index. */ 661 static int fdisk_part_get_free_idx(fdisk_dev_t *dev, int *rindex) 662 { 663 link_t *link; 664 fdisk_part_t *part; 665 int nidx; 666 667 link = list_first(&dev->parts_idx); 668 nidx = 1; 669 while (link != NULL) { 670 part = list_get_instance(link, fdisk_part_t, ldev_idx); 671 if (part->index > nidx) 672 break; 673 nidx = part->index; 674 link = list_next(link, &dev->parts_idx); 675 } 676 677 if (nidx > 4 /* XXXX actual number of slots*/) { 678 return ELIMIT; 679 } 680 681 *rindex = nidx; 682 return EOK; 683 } 684 685 /** Get free range of blocks. 686 * 687 * Get free range of blocks of at least the specified size (first fit). 688 */ 689 static int fdisk_part_get_free_range(fdisk_dev_t *dev, aoff64_t nblocks, 690 aoff64_t *rblock0, aoff64_t *rnblocks) 691 { 692 link_t *link; 693 fdisk_part_t *part; 694 uint64_t avail; 695 int nba; 696 697 link = list_first(&dev->parts_ba); 698 nba = dev->dinfo.ablock0; 699 while (link != NULL) { 700 part = list_get_instance(link, fdisk_part_t, ldev_ba); 701 if (part->block0 - nba >= nblocks) 702 break; 703 nba = part->block0 + part->nblocks; 704 link = list_next(link, &dev->parts_ba); 705 } 706 707 if (link != NULL) { 708 /* Free range before a partition */ 709 avail = part->block0 - nba; 710 } else { 711 /* Free range at the end */ 712 avail = dev->dinfo.ablock0 + dev->dinfo.anblocks - nba; 713 714 /* Verify that the range is large enough */ 715 if (avail < nblocks) 716 return ELIMIT; 717 } 718 719 *rblock0 = nba; 720 *rnblocks = avail; 721 return EOK; 722 } 723 724 /** Prepare new partition specification for VBD. */ 725 static int fdisk_part_spec_prepare(fdisk_dev_t *dev, fdisk_part_spec_t *pspec, 726 vbd_part_spec_t *vpspec) 727 { 728 uint64_t cbytes; 729 aoff64_t req_blocks; 730 aoff64_t fblock0; 731 aoff64_t fnblocks; 732 uint64_t block_size; 733 unsigned i; 734 int index; 735 int rc; 736 737 // pspec->fstype 738 printf("fdisk_part_spec_prepare()\n"); 739 block_size = dev->dinfo.block_size; 740 cbytes = pspec->capacity.value; 741 for (i = 0; i < pspec->capacity.cunit; i++) 742 cbytes = cbytes * 1000; 743 744 req_blocks = (cbytes + block_size - 1) / block_size; 745 746 rc = fdisk_part_get_free_idx(dev, &index); 747 if (rc != EOK) 748 return EIO; 749 750 rc = fdisk_part_get_free_range(dev, req_blocks, &fblock0, &fnblocks); 751 if (rc != EOK) 752 return EIO; 753 754 vpspec->index = index; 755 vpspec->block0 = fblock0; 756 vpspec->nblocks = req_blocks; 757 vpspec->ptype = 42; 758 return EOK; 759 } 760 652 761 /** @} 653 762 */ -
uspace/lib/label/include/types/liblabel.h
r6a0d4ce2 r6bc542b 98 98 /** Specification of new partition */ 99 99 struct label_part_spec { 100 /** Partition index */ 101 int index; 102 /** First block */ 103 aoff64_t block0; 104 /** Number of blocks */ 105 aoff64_t nblocks; 106 /** Partition type */ 107 uint64_t ptype; 100 108 }; 101 109 -
uspace/lib/label/src/gpt.c
r6a0d4ce2 r6bc542b 242 242 label_part_t **rpart) 243 243 { 244 return ENOTSUP; 244 label_part_t *part; 245 246 part = calloc(1, sizeof(label_part_t)); 247 if (part == NULL) 248 return ENOMEM; 249 250 /* XXX Verify index, block0, nblocks */ 251 252 part->index = pspec->index; 253 part->block0 = pspec->block0; 254 part->nblocks = pspec->nblocks; 255 256 /* XXX Modify partition table */ 257 258 part->label = label; 259 list_append(&part->llabel, &label->parts); 260 261 *rpart = part; 262 return EOK; 245 263 } 246 264 -
uspace/lib/label/src/mbr.c
r6a0d4ce2 r6bc542b 206 206 label_part_t **rpart) 207 207 { 208 return ENOTSUP; 208 label_part_t *part; 209 210 part = calloc(1, sizeof(label_part_t)); 211 if (part == NULL) 212 return ENOMEM; 213 214 part->index = pspec->index; 215 part->block0 = pspec->block0; 216 part->nblocks = pspec->nblocks; 217 218 part->label = label; 219 220 *rpart = part; 221 return EOK; 209 222 } 210 223 -
uspace/srv/bd/vbd/disk.c
r6a0d4ce2 r6bc542b 112 112 } 113 113 114 static int vbds_part_add(vbds_disk_t *disk, label_part_t *lpart) 114 static int vbds_part_add(vbds_disk_t *disk, label_part_t *lpart, 115 vbds_part_t **rpart) 115 116 { 116 117 vbds_part_t *part; … … 163 164 list_append(&part->lparts, &vbds_parts); 164 165 166 if (rpart != NULL) 167 *rpart = part; 165 168 return EOK; 166 169 } … … 230 233 part = label_part_first(label); 231 234 while (part != NULL) { 232 rc = vbds_part_add(disk, part );235 rc = vbds_part_add(disk, part, NULL); 233 236 if (rc != EOK) { 234 237 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed adding partitio " … … 389 392 } 390 393 391 int vbds_part_create(service_id_t sid, vbds_part_id_t *rpart) 394 int vbds_part_create(service_id_t sid, vbd_part_spec_t *pspec, 395 vbds_part_id_t *rpart) 392 396 { 393 397 vbds_disk_t *disk; 394 398 vbds_part_t *part; 395 label_part_spec_t pspec;399 label_part_spec_t lpspec; 396 400 label_part_t *lpart; 397 401 int rc; 398 399 part = calloc(1, sizeof(vbds_part_t));400 if (part == NULL)401 return ENOMEM;402 402 403 403 rc = vbds_disk_by_svcid(sid, &disk); … … 408 408 } 409 409 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); 412 417 if (rc != EOK) { 413 418 log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating partition."); … … 415 420 } 416 421 417 rc = vbds_part_add(disk, lpart );422 rc = vbds_part_add(disk, lpart, &part); 418 423 if (rc != EOK) { 419 424 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed while creating " … … 427 432 } 428 433 434 if (rpart != NULL) 435 *rpart = part->id; 429 436 return EOK; 430 437 error: 431 free(part);432 438 return rc; 433 439 } -
uspace/srv/bd/vbd/disk.h
r6a0d4ce2 r6bc542b 50 50 extern int vbds_label_delete(service_id_t); 51 51 extern int vbds_part_get_info(vbds_part_id_t, vbd_part_info_t *); 52 extern int vbds_part_create(service_id_t, vbd s_part_id_t *);52 extern int vbds_part_create(service_id_t, vbd_part_spec_t *,vbds_part_id_t *); 53 53 extern int vbds_part_delete(vbds_part_id_t); 54 54 extern void vbds_bd_conn(ipc_callid_t, ipc_call_t *, void *); -
uspace/srv/bd/vbd/vbd.c
r6a0d4ce2 r6bc542b 115 115 rc = vbds_disk_info(disk_sid, &dinfo); 116 116 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 123 121 ipc_callid_t callid; 124 122 size_t size; 125 123 if (!async_data_read_receive(&callid, &size)) { 126 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() failed");127 124 async_answer_0(callid, EREFUSED); 128 125 async_answer_0(iid, EREFUSED); … … 130 127 } 131 128 132 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() check size");133 129 if (size != sizeof(vbds_disk_info_t)) { 134 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() wrong size");135 130 async_answer_0(callid, EINVAL); 136 131 async_answer_0(iid, EINVAL); … … 138 133 } 139 134 140 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() data_read_finalize");141 135 rc = async_data_read_finalize(callid, &dinfo, 142 136 min(size, sizeof(dinfo))); … … 147 141 } 148 142 149 log_msg(LOG_DEFAULT, LVL_NOTE, "vbd_disk_info() reply EOK");150 143 async_answer_0(iid, EOK); 151 144 } … … 234 227 { 235 228 service_id_t disk_sid; 229 vbd_part_spec_t pspec; 236 230 vbds_part_id_t part; 237 231 int rc; … … 240 234 241 235 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 243 264 async_answer_1(iid, (sysarg_t)rc, (sysarg_t)part); 244 265 }
Note:
See TracChangeset
for help on using the changeset viewer.