Changes in uspace/lib/block/block.c [4e00f87:f9b2cb4c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/block.c
r4e00f87 rf9b2cb4c 37 37 */ 38 38 39 #include "../../srv/vfs/vfs.h"40 39 #include <ipc/loc.h> 41 40 #include <ipc/services.h> 42 41 #include <errno.h> 43 #include <sys/mman.h>44 42 #include <async.h> 45 43 #include <as.h> … … 57 55 #include "block.h" 58 56 57 #define MAX_WRITE_RETRIES 10 58 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 */ 83 84 size_t pblock_size; /**< Physical block size. */ 84 85 cache_t *cache; … … 93 94 fibril_mutex_lock(&dcl_lock); 94 95 95 list_foreach(dcl, cur) { 96 devcon_t *devcon = list_get_instance(cur, devcon_t, link); 96 list_foreach(dcl, link, devcon_t, devcon) { 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, bd_t *bd)108 size_t bsize, aoff64_t dev_size, 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; 123 124 devcon->cache = NULL; 124 125 125 126 fibril_mutex_lock(&dcl_lock); 126 list_foreach(dcl, cur) { 127 devcon_t *d = list_get_instance(cur, devcon_t, link); 127 list_foreach(dcl, link, devcon_t, d) { 128 128 if (d->service_id == service_id) { 129 129 fibril_mutex_unlock(&dcl_lock); … … 144 144 } 145 145 146 int block_init(exch_mgmt_t mgmt, service_id_t service_id, 147 size_t comm_size) 146 int block_init(service_id_t service_id, size_t comm_size) 148 147 { 149 148 bd_t *bd; 150 149 151 async_sess_t *sess = loc_service_connect( mgmt, service_id,150 async_sess_t *sess = loc_service_connect(service_id, INTERFACE_BLOCK, 152 151 IPC_FLAG_BLOCKING); 153 152 if (!sess) { … … 168 167 return rc; 169 168 } 170 171 rc = devcon_add(service_id, sess, bsize, bd); 169 170 aoff64_t dev_size; 171 rc = bd_get_num_blocks(bd, &dev_size); 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 178 185 return EOK; 179 186 } … … 186 193 if (devcon->cache) 187 194 (void) block_cache_fini(service_id); 195 196 (void)bd_sync_cache(devcon->bd, 0, 0); 188 197 189 198 devcon_remove(devcon); … … 353 362 fibril_mutex_initialize(&b->lock); 354 363 b->refcnt = 1; 364 b->write_failures = 0; 355 365 b->dirty = false; 356 366 b->toxic = false; … … 377 387 block_t *b; 378 388 link_t *link; 379 389 aoff64_t p_ba; 380 390 int rc; 381 391 … … 386 396 387 397 cache = devcon->cache; 398 399 /* Check whether the logical block (or part of it) is beyond 400 * 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 388 409 389 410 retry: … … 462 483 * another block next time. 463 484 */ 464 fibril_mutex_unlock(&b->lock); 465 goto retry; 466 } 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 467 498 b->dirty = false; 468 499 if (!fibril_mutex_trylock(&cache->lock)) { … … 581 612 rc = write_blocks(devcon, block->pba, cache->blocks_cluster, 582 613 block->data, block->size); 614 if (rc == EOK) 615 block->write_failures = 0; 583 616 block->dirty = false; 584 617 } … … 606 639 */ 607 640 block->refcnt++; 608 fibril_mutex_unlock(&block->lock); 609 fibril_mutex_unlock(&cache->lock); 610 goto retry; 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 } 611 653 } 612 654 /* … … 774 816 devcon_t *devcon = devcon_search(service_id); 775 817 assert(devcon); 776 818 777 819 return bd_get_num_blocks(devcon->bd, nblocks); 778 820 } … … 836 878 * 837 879 * @return Allocated TOC structure. 838 * @return NULL on failure. 839 * 840 */ 841 toc_block_t *block_get_toc(service_id_t service_id, uint8_t session) 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) 842 885 { 843 886 devcon_t *devcon = devcon_search(service_id); 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; 887 888 assert(devcon); 889 return bd_read_toc(devcon->bd, session, buf, bufsize); 860 890 } 861 891
Note:
See TracChangeset
for help on using the changeset viewer.