Changes in uspace/lib/block/block.c [f9b2cb4c:4e00f87] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/block.c
rf9b2cb4c r4e00f87 37 37 */ 38 38 39 #include "../../srv/vfs/vfs.h" 39 40 #include <ipc/loc.h> 40 41 #include <ipc/services.h> 41 42 #include <errno.h> 43 #include <sys/mman.h> 42 44 #include <async.h> 43 45 #include <as.h> … … 55 57 #include "block.h" 56 58 57 #define MAX_WRITE_RETRIES 1058 59 59 /** Lock protecting the device connection list */ 60 60 static FIBRIL_MUTEX_INITIALIZE(dcl_lock); … … 81 81 void *bb_buf; 82 82 aoff64_t bb_addr; 83 aoff64_t pblocks; /**< Number of physical blocks */84 83 size_t pblock_size; /**< Physical block size. */ 85 84 cache_t *cache; … … 94 93 fibril_mutex_lock(&dcl_lock); 95 94 96 list_foreach(dcl, link, devcon_t, devcon) { 95 list_foreach(dcl, cur) { 96 devcon_t *devcon = list_get_instance(cur, devcon_t, link); 97 97 if (devcon->service_id == service_id) { 98 98 fibril_mutex_unlock(&dcl_lock); … … 106 106 107 107 static int devcon_add(service_id_t service_id, async_sess_t *sess, 108 size_t bsize, aoff64_t dev_size,bd_t *bd)108 size_t bsize, bd_t *bd) 109 109 { 110 110 devcon_t *devcon; … … 121 121 devcon->bb_addr = 0; 122 122 devcon->pblock_size = bsize; 123 devcon->pblocks = dev_size;124 123 devcon->cache = NULL; 125 124 126 125 fibril_mutex_lock(&dcl_lock); 127 list_foreach(dcl, link, devcon_t, d) { 126 list_foreach(dcl, cur) { 127 devcon_t *d = list_get_instance(cur, devcon_t, link); 128 128 if (d->service_id == service_id) { 129 129 fibril_mutex_unlock(&dcl_lock); … … 144 144 } 145 145 146 int block_init(service_id_t service_id, size_t comm_size) 146 int block_init(exch_mgmt_t mgmt, service_id_t service_id, 147 size_t comm_size) 147 148 { 148 149 bd_t *bd; 149 150 150 async_sess_t *sess = loc_service_connect( service_id, INTERFACE_BLOCK,151 async_sess_t *sess = loc_service_connect(mgmt, service_id, 151 152 IPC_FLAG_BLOCKING); 152 153 if (!sess) { … … 167 168 return rc; 168 169 } 169 170 aoff64_t dev_size; 171 rc = bd_get_num_blocks(bd, &dev_size); 170 171 rc = devcon_add(service_id, sess, bsize, bd); 172 172 if (rc != EOK) { 173 173 bd_close(bd); … … 176 176 } 177 177 178 rc = devcon_add(service_id, sess, bsize, dev_size, bd);179 if (rc != EOK) {180 bd_close(bd);181 async_hangup(sess);182 return rc;183 }184 185 178 return EOK; 186 179 } … … 193 186 if (devcon->cache) 194 187 (void) block_cache_fini(service_id); 195 196 (void)bd_sync_cache(devcon->bd, 0, 0);197 188 198 189 devcon_remove(devcon); … … 362 353 fibril_mutex_initialize(&b->lock); 363 354 b->refcnt = 1; 364 b->write_failures = 0;365 355 b->dirty = false; 366 356 b->toxic = false; … … 387 377 block_t *b; 388 378 link_t *link; 389 aoff64_t p_ba; 379 390 380 int rc; 391 381 … … 396 386 397 387 cache = devcon->cache; 398 399 /* Check whether the logical block (or part of it) is beyond400 * the end of the device or not.401 */402 p_ba = ba_ltop(devcon, ba);403 p_ba += cache->blocks_cluster;404 if (p_ba >= devcon->pblocks) {405 /* This request cannot be satisfied */406 return EIO;407 }408 409 388 410 389 retry: … … 483 462 * another block next time. 484 463 */ 485 if (b->write_failures < MAX_WRITE_RETRIES) { 486 b->write_failures++; 487 fibril_mutex_unlock(&b->lock); 488 goto retry; 489 } else { 490 printf("Too many errors writing block %" 491 PRIuOFF64 "from device handle %" PRIun "\n" 492 "SEVERE DATA LOSS POSSIBLE\n", 493 b->lba, devcon->service_id); 494 } 495 } else 496 b->write_failures = 0; 497 464 fibril_mutex_unlock(&b->lock); 465 goto retry; 466 } 498 467 b->dirty = false; 499 468 if (!fibril_mutex_trylock(&cache->lock)) { … … 612 581 rc = write_blocks(devcon, block->pba, cache->blocks_cluster, 613 582 block->data, block->size); 614 if (rc == EOK)615 block->write_failures = 0;616 583 block->dirty = false; 617 584 } … … 639 606 */ 640 607 block->refcnt++; 641 642 if (block->write_failures < MAX_WRITE_RETRIES) { 643 block->write_failures++; 644 fibril_mutex_unlock(&block->lock); 645 fibril_mutex_unlock(&cache->lock); 646 goto retry; 647 } else { 648 printf("Too many errors writing block %" 649 PRIuOFF64 "from device handle %" PRIun "\n" 650 "SEVERE DATA LOSS POSSIBLE\n", 651 block->lba, devcon->service_id); 652 } 608 fibril_mutex_unlock(&block->lock); 609 fibril_mutex_unlock(&cache->lock); 610 goto retry; 653 611 } 654 612 /* … … 816 774 devcon_t *devcon = devcon_search(service_id); 817 775 assert(devcon); 818 776 819 777 return bd_get_num_blocks(devcon->bd, nblocks); 820 778 } … … 878 836 * 879 837 * @return Allocated TOC structure. 880 * @return EOK on success or negative error code. 881 * 882 */ 883 int block_read_toc(service_id_t service_id, uint8_t session, void *buf, 884 size_t bufsize) 838 * @return NULL on failure. 839 * 840 */ 841 toc_block_t *block_get_toc(service_id_t service_id, uint8_t session) 885 842 { 886 843 devcon_t *devcon = devcon_search(service_id); 887 888 assert(devcon); 889 return bd_read_toc(devcon->bd, session, buf, bufsize); 844 toc_block_t *toc = NULL; 845 int rc; 846 847 assert(devcon); 848 849 toc = (toc_block_t *) malloc(sizeof(toc_block_t)); 850 if (toc == NULL) 851 return NULL; 852 853 rc = bd_read_toc(devcon->bd, session, toc, sizeof(toc_block_t)); 854 if (rc != EOK) { 855 free(toc); 856 return NULL; 857 } 858 859 return toc; 890 860 } 891 861
Note:
See TracChangeset
for help on using the changeset viewer.