Changes in uspace/lib/block/block.c [dd8b6a8:2463df9] in mainline
- File:
-
- 1 edited
-
uspace/lib/block/block.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/block.c
rdd8b6a8 r2463df9 55 55 #include "block.h" 56 56 57 #define MAX_WRITE_RETRIES 1058 59 57 /** Lock protecting the device connection list */ 60 58 static FIBRIL_MUTEX_INITIALIZE(dcl_lock); … … 81 79 void *bb_buf; 82 80 aoff64_t bb_addr; 83 aoff64_t pblocks; /**< Number of physical blocks */84 81 size_t pblock_size; /**< Physical block size. */ 85 82 cache_t *cache; … … 106 103 107 104 static int devcon_add(service_id_t service_id, async_sess_t *sess, 108 size_t bsize, aoff64_t dev_size,bd_t *bd)105 size_t bsize, bd_t *bd) 109 106 { 110 107 devcon_t *devcon; … … 121 118 devcon->bb_addr = 0; 122 119 devcon->pblock_size = bsize; 123 devcon->pblocks = dev_size;124 120 devcon->cache = NULL; 125 121 … … 168 164 return rc; 169 165 } 170 171 aoff64_t dev_size; 172 rc = bd_get_num_blocks(bd, &dev_size); 166 167 rc = devcon_add(service_id, sess, bsize, bd); 173 168 if (rc != EOK) { 174 169 bd_close(bd); … … 177 172 } 178 173 179 rc = devcon_add(service_id, sess, bsize, dev_size, bd);180 if (rc != EOK) {181 bd_close(bd);182 async_hangup(sess);183 return rc;184 }185 186 174 return EOK; 187 175 } … … 194 182 if (devcon->cache) 195 183 (void) block_cache_fini(service_id); 196 197 (void)bd_sync_cache(devcon->bd, 0, 0);198 184 199 185 devcon_remove(devcon); … … 363 349 fibril_mutex_initialize(&b->lock); 364 350 b->refcnt = 1; 365 b->write_failures = 0;366 351 b->dirty = false; 367 352 b->toxic = false; … … 388 373 block_t *b; 389 374 link_t *link; 390 aoff64_t p_ba; 375 391 376 int rc; 392 377 … … 397 382 398 383 cache = devcon->cache; 399 400 /* Check whether the logical block (or part of it) is beyond401 * the end of the device or not.402 */403 p_ba = ba_ltop(devcon, ba);404 p_ba += cache->blocks_cluster;405 if (p_ba >= devcon->pblocks) {406 /* This request cannot be satisfied */407 return EIO;408 }409 410 384 411 385 retry: … … 484 458 * another block next time. 485 459 */ 486 if (b->write_failures < MAX_WRITE_RETRIES) { 487 b->write_failures++; 488 fibril_mutex_unlock(&b->lock); 489 goto retry; 490 } else { 491 printf("Too many errors writing block %" 492 PRIuOFF64 "from device handle %" PRIun "\n" 493 "SEVERE DATA LOSS POSSIBLE\n", 494 b->lba, devcon->service_id); 495 } 496 } else 497 b->write_failures = 0; 498 460 fibril_mutex_unlock(&b->lock); 461 goto retry; 462 } 499 463 b->dirty = false; 500 464 if (!fibril_mutex_trylock(&cache->lock)) { … … 613 577 rc = write_blocks(devcon, block->pba, cache->blocks_cluster, 614 578 block->data, block->size); 615 if (rc == EOK)616 block->write_failures = 0;617 579 block->dirty = false; 618 580 } … … 640 602 */ 641 603 block->refcnt++; 642 643 if (block->write_failures < MAX_WRITE_RETRIES) { 644 block->write_failures++; 645 fibril_mutex_unlock(&block->lock); 646 fibril_mutex_unlock(&cache->lock); 647 goto retry; 648 } else { 649 printf("Too many errors writing block %" 650 PRIuOFF64 "from device handle %" PRIun "\n" 651 "SEVERE DATA LOSS POSSIBLE\n", 652 block->lba, devcon->service_id); 653 } 604 fibril_mutex_unlock(&block->lock); 605 fibril_mutex_unlock(&cache->lock); 606 goto retry; 654 607 } 655 608 /* … … 817 770 devcon_t *devcon = devcon_search(service_id); 818 771 assert(devcon); 819 772 820 773 return bd_get_num_blocks(devcon->bd, nblocks); 821 774 } … … 879 832 * 880 833 * @return Allocated TOC structure. 881 * @return EOK on success or negative error code. 882 * 883 */ 884 int block_read_toc(service_id_t service_id, uint8_t session, void *buf, 885 size_t bufsize) 834 * @return NULL on failure. 835 * 836 */ 837 toc_block_t *block_get_toc(service_id_t service_id, uint8_t session) 886 838 { 887 839 devcon_t *devcon = devcon_search(service_id); 888 889 assert(devcon); 890 return bd_read_toc(devcon->bd, session, buf, bufsize); 840 toc_block_t *toc = NULL; 841 int rc; 842 843 assert(devcon); 844 845 toc = (toc_block_t *) malloc(sizeof(toc_block_t)); 846 if (toc == NULL) 847 return NULL; 848 849 rc = bd_read_toc(devcon->bd, session, toc, sizeof(toc_block_t)); 850 if (rc != EOK) { 851 free(toc); 852 return NULL; 853 } 854 855 return toc; 891 856 } 892 857
Note:
See TracChangeset
for help on using the changeset viewer.
