Changeset 3d14a45 in rtems for cpukit/libblock
- Timestamp:
- 01/21/07 18:25:31 (17 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- 6200dc9
- Parents:
- bc2083c1
- Location:
- cpukit/libblock
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/libblock/Makefile.am
rbc2083c1 r3d14a45 9 9 noinst_LIBRARIES = libblock.a 10 10 libblock_a_SOURCES = src/bdbuf.c src/blkdev.c src/diskdevs.c src/ramdisk.c \ 11 src/ide_part_table.c include/rtems/bdbuf.h include/rtems/blkdev.h \ 11 src/ide_part_table.c src/show_bdbuf.c \ 12 include/rtems/bdbuf.h include/rtems/blkdev.h \ 12 13 include/rtems/diskdevs.h include/rtems/ramdisk.h \ 13 14 include/rtems/ide_part_table.h -
cpukit/libblock/include/rtems/bdbuf.h
rbc2083c1 r3d14a45 9 9 * Author: Victor V. Vengerov <vvv@oktet.ru> 10 10 * 11 * @(#) $Id$11 * @(#) bdbuf.h,v 1.9 2005/02/02 00:06:18 joel Exp 12 12 */ 13 13 … … 75 75 76 76 77 /* 78 * the following data structures are internal to the bdbuf layer, 79 * but it is convenient to have them visible from the outside for inspection 80 */ 81 /* 82 * The groups of the blocks with the same size are collected in the 83 * bd_pool. Note that a several of the buffer's groups with the 84 * same size can exists. 85 */ 86 typedef struct bdbuf_pool 87 { 88 bdbuf_buffer *tree; /* Buffer descriptor lookup AVL tree root */ 89 90 Chain_Control free; /* Free buffers list */ 91 Chain_Control lru; /* Last recently used list */ 92 93 int blksize; /* The size of the blocks (in bytes) */ 94 int nblks; /* Number of blocks in this pool */ 95 rtems_id bufget_sema; /* Buffer obtain counting semaphore */ 96 void *mallocd_bufs; /* Pointer to the malloc'd buffer memory, 97 or NULL, if buffer memory provided in 98 buffer configuration */ 99 bdbuf_buffer *bdbufs; /* Pointer to table of buffer descriptors 100 allocated for this buffer pool. */ 101 } bdbuf_pool; 102 103 /* Buffering layer context definition */ 104 struct bdbuf_context { 105 bdbuf_pool *pool; /* Table of buffer pools */ 106 int npools; /* Number of entries in pool table */ 107 108 Chain_Control mod; /* Modified buffers list */ 109 rtems_id flush_sema; /* Buffer flush semaphore; counting 110 semaphore; incremented when buffer 111 flushed to the disk; decremented when 112 buffer modified */ 113 rtems_id swapout_task; /* Swapout task ID */ 114 }; 115 /* 116 * the context of the buffering layer, visible for inspection 117 */ 118 extern struct bdbuf_context rtems_bdbuf_ctx; 77 119 78 120 /* bdbuf_config structure describes block configuration (size, -
cpukit/libblock/src/bdbuf.c
rbc2083c1 r3d14a45 8 8 * Alexander Kukuta <kam@oktet.ru> 9 9 * 10 * @(#) $Id$10 * @(#) bdbuf.c,v 1.14 2004/04/17 08:15:17 ralf Exp 11 11 */ 12 12 … … 57 57 static rtems_status_code bdbuf_release(bdbuf_buffer *bd_buf); 58 58 /* 59 * The groups of the blocks with the same size are collected in the60 * bd_pool. Note that a several of the buffer's groups with the61 * same size can exists.62 */63 typedef struct bdbuf_pool64 {65 bdbuf_buffer *tree; /* Buffer descriptor lookup AVL tree root */66 67 Chain_Control free; /* Free buffers list */68 Chain_Control lru; /* Last recently used list */69 70 int blksize; /* The size of the blocks (in bytes) */71 int nblks; /* Number of blocks in this pool */72 rtems_id bufget_sema; /* Buffer obtain counting semaphore */73 void *mallocd_bufs; /* Pointer to the malloc'd buffer memory,74 or NULL, if buffer memory provided in75 buffer configuration */76 bdbuf_buffer *bdbufs; /* Pointer to table of buffer descriptors77 allocated for this buffer pool. */78 } bdbuf_pool;79 80 /* Buffering layer context definition */81 struct bdbuf_context {82 bdbuf_pool *pool; /* Table of buffer pools */83 int npools; /* Number of entries in pool table */84 85 Chain_Control mod; /* Modified buffers list */86 rtems_id flush_sema; /* Buffer flush semaphore; counting87 semaphore; incremented when buffer88 flushed to the disk; decremented when89 buffer modified */90 rtems_id swapout_task; /* Swapout task ID */91 };92 /*93 59 * maximum number of blocks that might be chained together to one 94 60 * write driver call … … 109 75 } blkdev_request1; 110 76 111 /* The staticcontext of buffering layer */112 st atic struct bdbuf_context bd_ctx;77 /* The context of buffering layer */ 78 struct bdbuf_context rtems_bdbuf_ctx; 113 79 114 80 #define SAFE … … 712 678 bdbuf_initialize_pool(rtems_bdbuf_config *config, int pool) 713 679 { 714 bdbuf_pool *p = bd_ctx.pool + pool;680 bdbuf_pool *p = rtems_bdbuf_ctx.pool + pool; 715 681 unsigned char *bufs; 716 682 bdbuf_buffer *b; … … 788 754 bdbuf_release_pool(rtems_bdpool_id pool) 789 755 { 790 bdbuf_pool *p = bd_ctx.pool + pool;756 bdbuf_pool *p = rtems_bdbuf_ctx.pool + pool; 791 757 rtems_semaphore_delete(p->bufget_sema); 792 758 free(p->bdbufs); … … 819 785 return RTEMS_INVALID_SIZE; 820 786 821 bd_ctx.npools = size;787 rtems_bdbuf_ctx.npools = size; 822 788 823 789 /* 824 790 * Allocate memory for buffer pool descriptors 825 791 */ 826 bd_ctx.pool = calloc(size, sizeof(bdbuf_pool));827 if ( bd_ctx.pool == NULL)792 rtems_bdbuf_ctx.pool = calloc(size, sizeof(bdbuf_pool)); 793 if (rtems_bdbuf_ctx.pool == NULL) 828 794 { 829 795 return RTEMS_NO_MEMORY; 830 796 } 831 797 832 Chain_Initialize_empty(& bd_ctx.mod);798 Chain_Initialize_empty(&rtems_bdbuf_ctx.mod); 833 799 834 800 /* Initialize buffer pools and roll out if something failed */ … … 852 818 RTEMS_FIFO | RTEMS_COUNTING_SEMAPHORE | RTEMS_NO_INHERIT_PRIORITY | 853 819 RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL, 0, 854 & bd_ctx.flush_sema);820 &rtems_bdbuf_ctx.flush_sema); 855 821 if (rc != RTEMS_SUCCESSFUL) 856 822 { 857 823 for (i = 0; i < size; i++) 858 824 bdbuf_release_pool(i); 859 free( bd_ctx.pool);825 free(rtems_bdbuf_ctx.pool); 860 826 return rc; 861 827 } … … 870 836 RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, 871 837 RTEMS_DEFAULT_ATTRIBUTES, 872 & bd_ctx.swapout_task);838 &rtems_bdbuf_ctx.swapout_task); 873 839 if (rc != RTEMS_SUCCESSFUL) 874 840 { 875 rtems_semaphore_delete( bd_ctx.flush_sema);841 rtems_semaphore_delete(rtems_bdbuf_ctx.flush_sema); 876 842 for (i = 0; i < size; i++) 877 843 bdbuf_release_pool(i); 878 free( bd_ctx.pool);844 free(rtems_bdbuf_ctx.pool); 879 845 return rc; 880 846 } 881 847 882 rc = rtems_task_start( bd_ctx.swapout_task, bdbuf_swapout_task, 0);848 rc = rtems_task_start(rtems_bdbuf_ctx.swapout_task, bdbuf_swapout_task, 0); 883 849 if (rc != RTEMS_SUCCESSFUL) 884 850 { 885 rtems_task_delete( bd_ctx.swapout_task);886 rtems_semaphore_delete( bd_ctx.flush_sema);851 rtems_task_delete(rtems_bdbuf_ctx.swapout_task); 852 rtems_semaphore_delete(rtems_bdbuf_ctx.flush_sema); 887 853 for (i = 0; i < size; i++) 888 854 bdbuf_release_pool(i); 889 free( bd_ctx.pool);855 free(rtems_bdbuf_ctx.pool); 890 856 return rc; 891 857 } … … 934 900 935 901 device = dd->dev; 936 bd_pool = bd_ctx.pool + dd->pool;902 bd_pool = rtems_bdbuf_ctx.pool + dd->pool; 937 903 blksize = dd->block_size; 938 904 … … 1022 988 if (bd_buf->modified) 1023 989 { 1024 rc = rtems_semaphore_obtain( bd_ctx.flush_sema,990 rc = rtems_semaphore_obtain(rtems_bdbuf_ctx.flush_sema, 1025 991 RTEMS_NO_WAIT, 0); 1026 992 } … … 1477 1443 return RTEMS_INTERNAL_ERROR; 1478 1444 1479 bd_pool = bd_ctx.pool + bd_buf->pool;1445 bd_pool = rtems_bdbuf_ctx.pool + bd_buf->pool; 1480 1446 1481 1447 bd_buf->use_count--; … … 1488 1454 /* Buffer was modified. Insert buffer to the modified buffers 1489 1455 * list and initiate flushing. */ 1490 Chain_Append(& bd_ctx.mod, &bd_buf->link);1456 Chain_Append(&rtems_bdbuf_ctx.mod, &bd_buf->link); 1491 1457 1492 1458 /* Release the flush_sema */ 1493 rc = rtems_semaphore_release( bd_ctx.flush_sema);1459 rc = rtems_semaphore_release(rtems_bdbuf_ctx.flush_sema); 1494 1460 } 1495 1461 else … … 1660 1626 return RTEMS_INVALID_ID; 1661 1627 1662 pool = bd_ctx.pool + dd->pool;1628 pool = rtems_bdbuf_ctx.pool + dd->pool; 1663 1629 1664 1630 DISABLE_PREEMPTION(key); … … 1719 1685 */ 1720 1686 if (nxt_bd_buf == NULL) { 1721 rc = rtems_semaphore_obtain( bd_ctx.flush_sema,1687 rc = rtems_semaphore_obtain(rtems_bdbuf_ctx.flush_sema, 1722 1688 (req.req.count == 0) 1723 1689 ? RTEMS_WAIT … … 1725 1691 0); 1726 1692 if (rc == RTEMS_SUCCESSFUL) { 1727 nxt_bd_buf = (bdbuf_buffer *)Chain_Get(& bd_ctx.mod);1693 nxt_bd_buf = (bdbuf_buffer *)Chain_Get(&rtems_bdbuf_ctx.mod); 1728 1694 if (nxt_bd_buf != NULL) { 1729 1695 nxt_bd_buf->in_progress = TRUE; … … 1765 1731 */ 1766 1732 if (bd_buf != NULL) { 1767 bd_pool = bd_ctx.pool + bd_buf->pool;1733 bd_pool = rtems_bdbuf_ctx.pool + bd_buf->pool; 1768 1734 if (req.req.count == 0) { 1769 1735 /* … … 1819 1785 if (bd_buf->modified) 1820 1786 { 1821 Chain_Append(& bd_ctx.mod, &bd_buf->link);1822 rc = rtems_semaphore_release( bd_ctx.flush_sema);1787 Chain_Append(&rtems_bdbuf_ctx.mod, &bd_buf->link); 1788 rc = rtems_semaphore_release(rtems_bdbuf_ctx.flush_sema); 1823 1789 } 1824 1790 else … … 1861 1827 return RTEMS_INVALID_SIZE; 1862 1828 1863 for (i = 0, p = bd_ctx.pool; i < bd_ctx.npools; i++, p++)1829 for (i = 0, p = rtems_bdbuf_ctx.pool; i < rtems_bdbuf_ctx.npools; i++, p++) 1864 1830 { 1865 1831 if ((p->blksize >= block_size) && … … 1904 1870 int *blocks) 1905 1871 { 1906 if (pool >= bd_ctx.npools)1872 if (pool >= rtems_bdbuf_ctx.npools) 1907 1873 return RTEMS_INVALID_NUMBER; 1908 1874 1909 1875 if (block_size != NULL) 1910 1876 { 1911 *block_size = bd_ctx.pool[pool].blksize;1877 *block_size = rtems_bdbuf_ctx.pool[pool].blksize; 1912 1878 } 1913 1879 1914 1880 if (blocks != NULL) 1915 1881 { 1916 *blocks = bd_ctx.pool[pool].nblks;1882 *blocks = rtems_bdbuf_ctx.pool[pool].nblks; 1917 1883 } 1918 1884
Note: See TracChangeset
for help on using the changeset viewer.