Changes in uspace/lib/block/block.c [c1f26834:2463df9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/block.c
rc1f26834 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); 173 if (rc != EOK) { 174 bd_close(bd); 175 async_hangup(sess); 176 return rc; 177 } 178 179 rc = devcon_add(service_id, sess, bsize, dev_size, bd); 166 167 rc = devcon_add(service_id, sess, bsize, bd); 180 168 if (rc != EOK) { 181 169 bd_close(bd); … … 361 349 fibril_mutex_initialize(&b->lock); 362 350 b->refcnt = 1; 363 b->write_failures = 0;364 351 b->dirty = false; 365 352 b->toxic = false; … … 386 373 block_t *b; 387 374 link_t *link; 388 aoff64_t p_ba; 375 389 376 int rc; 390 377 … … 395 382 396 383 cache = devcon->cache; 397 398 /* Check whether the logical block (or part of it) is beyond399 * the end of the device or not.400 */401 p_ba = ba_ltop(devcon, ba);402 p_ba += cache->blocks_cluster;403 if (p_ba >= devcon->pblocks) {404 /* This request cannot be satisfied */405 return EIO;406 }407 408 384 409 385 retry: … … 482 458 * another block next time. 483 459 */ 484 if (b->write_failures < MAX_WRITE_RETRIES) { 485 b->write_failures++; 486 fibril_mutex_unlock(&b->lock); 487 goto retry; 488 } else { 489 printf("Too many errors writing block %" 490 PRIuOFF64 "from device handle %" PRIun "\n" 491 "SEVERE DATA LOSS POSSIBLE\n", 492 b->lba, devcon->service_id); 493 } 494 } else 495 b->write_failures = 0; 496 460 fibril_mutex_unlock(&b->lock); 461 goto retry; 462 } 497 463 b->dirty = false; 498 464 if (!fibril_mutex_trylock(&cache->lock)) { … … 611 577 rc = write_blocks(devcon, block->pba, cache->blocks_cluster, 612 578 block->data, block->size); 613 if (rc == EOK)614 block->write_failures = 0;615 579 block->dirty = false; 616 580 } … … 638 602 */ 639 603 block->refcnt++; 640 641 if (block->write_failures < MAX_WRITE_RETRIES) { 642 block->write_failures++; 643 fibril_mutex_unlock(&block->lock); 644 fibril_mutex_unlock(&cache->lock); 645 goto retry; 646 } else { 647 printf("Too many errors writing block %" 648 PRIuOFF64 "from device handle %" PRIun "\n" 649 "SEVERE DATA LOSS POSSIBLE\n", 650 block->lba, devcon->service_id); 651 } 604 fibril_mutex_unlock(&block->lock); 605 fibril_mutex_unlock(&cache->lock); 606 goto retry; 652 607 } 653 608 /* … … 815 770 devcon_t *devcon = devcon_search(service_id); 816 771 assert(devcon); 817 772 818 773 return bd_get_num_blocks(devcon->bd, nblocks); 819 774 }
Note:
See TracChangeset
for help on using the changeset viewer.