Changeset 3d35386 in mainline
- Timestamp:
- 2014-07-28T20:10:01Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c1f26834
- Parents:
- 7eb6c96
- Location:
- uspace/lib/block
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/block.c
r7eb6c96 r3d35386 55 55 #include "block.h" 56 56 57 #define MAX_WRITE_RETRIES 10 58 57 59 /** Lock protecting the device connection list */ 58 60 static FIBRIL_MUTEX_INITIALIZE(dcl_lock); … … 79 81 void *bb_buf; 80 82 aoff64_t bb_addr; 83 aoff64_t pblocks; /**< Number of physical blocks */ 81 84 size_t pblock_size; /**< Physical block size. */ 82 85 cache_t *cache; … … 103 106 104 107 static int devcon_add(service_id_t service_id, async_sess_t *sess, 105 size_t bsize, bd_t *bd)108 size_t bsize, aoff64_t dev_size, bd_t *bd) 106 109 { 107 110 devcon_t *devcon; … … 118 121 devcon->bb_addr = 0; 119 122 devcon->pblock_size = bsize; 123 devcon->pblocks = dev_size; 120 124 devcon->cache = NULL; 121 125 … … 164 168 return rc; 165 169 } 166 167 rc = devcon_add(service_id, sess, bsize, bd); 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); 168 180 if (rc != EOK) { 169 181 bd_close(bd); … … 349 361 fibril_mutex_initialize(&b->lock); 350 362 b->refcnt = 1; 363 b->write_failures = 0; 351 364 b->dirty = false; 352 365 b->toxic = false; … … 373 386 block_t *b; 374 387 link_t *link; 375 388 aoff64_t p_ba; 376 389 int rc; 377 390 … … 382 395 383 396 cache = devcon->cache; 397 398 /* Check whether the logical block (or part of it) is beyond 399 * 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 384 408 385 409 retry: … … 458 482 * another block next time. 459 483 */ 460 fibril_mutex_unlock(&b->lock); 461 goto retry; 462 } 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 463 497 b->dirty = false; 464 498 if (!fibril_mutex_trylock(&cache->lock)) { … … 577 611 rc = write_blocks(devcon, block->pba, cache->blocks_cluster, 578 612 block->data, block->size); 613 if (rc == EOK) 614 block->write_failures = 0; 579 615 block->dirty = false; 580 616 } … … 602 638 */ 603 639 block->refcnt++; 604 fibril_mutex_unlock(&block->lock);605 640 fibril_mutex_unlock(&cache->lock); 606 goto retry; 641 642 if (block->write_failures < MAX_WRITE_RETRIES) { 643 block->write_failures++; 644 fibril_mutex_unlock(&block->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 } 607 652 } 608 653 /* … … 770 815 devcon_t *devcon = devcon_search(service_id); 771 816 assert(devcon); 772 817 773 818 return bd_get_num_blocks(devcon->bd, nblocks); 774 819 } -
uspace/lib/block/block.h
r7eb6c96 r3d35386 81 81 /** Size of the block. */ 82 82 size_t size; 83 /** Number of write failures. */ 84 int write_failures; 83 85 /** Link for placing the block into the free block list. */ 84 86 link_t free_link;
Note:
See TracChangeset
for help on using the changeset viewer.