Changes in uspace/lib/block/block.c [dd8b6a8:b7adc22] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/block.c
rdd8b6a8 rb7adc22 40 40 #include <ipc/services.h> 41 41 #include <errno.h> 42 #include <sys/mman.h> 42 43 #include <async.h> 43 44 #include <as.h> … … 55 56 #include "block.h" 56 57 57 #define MAX_WRITE_RETRIES 1058 59 58 /** Lock protecting the device connection list */ 60 59 static FIBRIL_MUTEX_INITIALIZE(dcl_lock); … … 81 80 void *bb_buf; 82 81 aoff64_t bb_addr; 83 aoff64_t pblocks; /**< Number of physical blocks */84 82 size_t pblock_size; /**< Physical block size. */ 85 83 cache_t *cache; … … 106 104 107 105 static int devcon_add(service_id_t service_id, async_sess_t *sess, 108 size_t bsize, aoff64_t dev_size,bd_t *bd)106 size_t bsize, bd_t *bd) 109 107 { 110 108 devcon_t *devcon; … … 121 119 devcon->bb_addr = 0; 122 120 devcon->pblock_size = bsize; 123 devcon->pblocks = dev_size;124 121 devcon->cache = NULL; 125 122 … … 168 165 return rc; 169 166 } 170 171 aoff64_t dev_size; 172 rc = bd_get_num_blocks(bd, &dev_size); 167 168 rc = devcon_add(service_id, sess, bsize, bd); 173 169 if (rc != EOK) { 174 170 bd_close(bd); … … 177 173 } 178 174 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 175 return EOK; 187 176 } … … 194 183 if (devcon->cache) 195 184 (void) block_cache_fini(service_id); 196 197 (void)bd_sync_cache(devcon->bd, 0, 0);198 185 199 186 devcon_remove(devcon); … … 363 350 fibril_mutex_initialize(&b->lock); 364 351 b->refcnt = 1; 365 b->write_failures = 0;366 352 b->dirty = false; 367 353 b->toxic = false; … … 388 374 block_t *b; 389 375 link_t *link; 390 aoff64_t p_ba; 376 391 377 int rc; 392 378 … … 397 383 398 384 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 385 411 386 retry: … … 484 459 * another block next time. 485 460 */ 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 461 fibril_mutex_unlock(&b->lock); 462 goto retry; 463 } 499 464 b->dirty = false; 500 465 if (!fibril_mutex_trylock(&cache->lock)) { … … 613 578 rc = write_blocks(devcon, block->pba, cache->blocks_cluster, 614 579 block->data, block->size); 615 if (rc == EOK)616 block->write_failures = 0;617 580 block->dirty = false; 618 581 } … … 640 603 */ 641 604 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 } 605 fibril_mutex_unlock(&block->lock); 606 fibril_mutex_unlock(&cache->lock); 607 goto retry; 654 608 } 655 609 /* … … 817 771 devcon_t *devcon = devcon_search(service_id); 818 772 assert(devcon); 819 773 820 774 return bd_get_num_blocks(devcon->bd, nblocks); 821 775 } … … 879 833 * 880 834 * @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) 835 * @return NULL on failure. 836 * 837 */ 838 toc_block_t *block_get_toc(service_id_t service_id, uint8_t session) 886 839 { 887 840 devcon_t *devcon = devcon_search(service_id); 888 889 assert(devcon); 890 return bd_read_toc(devcon->bd, session, buf, bufsize); 841 toc_block_t *toc = NULL; 842 int rc; 843 844 assert(devcon); 845 846 toc = (toc_block_t *) malloc(sizeof(toc_block_t)); 847 if (toc == NULL) 848 return NULL; 849 850 rc = bd_read_toc(devcon->bd, session, toc, sizeof(toc_block_t)); 851 if (rc != EOK) { 852 free(toc); 853 return NULL; 854 } 855 856 return toc; 891 857 } 892 858
Note:
See TracChangeset
for help on using the changeset viewer.