![]() |
|
|||
0001 /* 0002 * Copyright (C) 2009-2011 Red Hat, Inc. 0003 * 0004 * Author: Mikulas Patocka <mpatocka@redhat.com> 0005 * 0006 * This file is released under the GPL. 0007 */ 0008 0009 #ifndef _LINUX_DM_BUFIO_H 0010 #define _LINUX_DM_BUFIO_H 0011 0012 #include <linux/blkdev.h> 0013 #include <linux/types.h> 0014 0015 /*----------------------------------------------------------------*/ 0016 0017 struct dm_bufio_client; 0018 struct dm_buffer; 0019 0020 /* 0021 * Flags for dm_bufio_client_create 0022 */ 0023 #define DM_BUFIO_CLIENT_NO_SLEEP 0x1 0024 0025 /* 0026 * Create a buffered IO cache on a given device 0027 */ 0028 struct dm_bufio_client * 0029 dm_bufio_client_create(struct block_device *bdev, unsigned block_size, 0030 unsigned reserved_buffers, unsigned aux_size, 0031 void (*alloc_callback)(struct dm_buffer *), 0032 void (*write_callback)(struct dm_buffer *), 0033 unsigned int flags); 0034 0035 /* 0036 * Release a buffered IO cache. 0037 */ 0038 void dm_bufio_client_destroy(struct dm_bufio_client *c); 0039 0040 /* 0041 * Set the sector range. 0042 * When this function is called, there must be no I/O in progress on the bufio 0043 * client. 0044 */ 0045 void dm_bufio_set_sector_offset(struct dm_bufio_client *c, sector_t start); 0046 0047 /* 0048 * WARNING: to avoid deadlocks, these conditions are observed: 0049 * 0050 * - At most one thread can hold at most "reserved_buffers" simultaneously. 0051 * - Each other threads can hold at most one buffer. 0052 * - Threads which call only dm_bufio_get can hold unlimited number of 0053 * buffers. 0054 */ 0055 0056 /* 0057 * Read a given block from disk. Returns pointer to data. Returns a 0058 * pointer to dm_buffer that can be used to release the buffer or to make 0059 * it dirty. 0060 */ 0061 void *dm_bufio_read(struct dm_bufio_client *c, sector_t block, 0062 struct dm_buffer **bp); 0063 0064 /* 0065 * Like dm_bufio_read, but return buffer from cache, don't read 0066 * it. If the buffer is not in the cache, return NULL. 0067 */ 0068 void *dm_bufio_get(struct dm_bufio_client *c, sector_t block, 0069 struct dm_buffer **bp); 0070 0071 /* 0072 * Like dm_bufio_read, but don't read anything from the disk. It is 0073 * expected that the caller initializes the buffer and marks it dirty. 0074 */ 0075 void *dm_bufio_new(struct dm_bufio_client *c, sector_t block, 0076 struct dm_buffer **bp); 0077 0078 /* 0079 * Prefetch the specified blocks to the cache. 0080 * The function starts to read the blocks and returns without waiting for 0081 * I/O to finish. 0082 */ 0083 void dm_bufio_prefetch(struct dm_bufio_client *c, 0084 sector_t block, unsigned n_blocks); 0085 0086 /* 0087 * Release a reference obtained with dm_bufio_{read,get,new}. The data 0088 * pointer and dm_buffer pointer is no longer valid after this call. 0089 */ 0090 void dm_bufio_release(struct dm_buffer *b); 0091 0092 /* 0093 * Mark a buffer dirty. It should be called after the buffer is modified. 0094 * 0095 * In case of memory pressure, the buffer may be written after 0096 * dm_bufio_mark_buffer_dirty, but before dm_bufio_write_dirty_buffers. So 0097 * dm_bufio_write_dirty_buffers guarantees that the buffer is on-disk but 0098 * the actual writing may occur earlier. 0099 */ 0100 void dm_bufio_mark_buffer_dirty(struct dm_buffer *b); 0101 0102 /* 0103 * Mark a part of the buffer dirty. 0104 * 0105 * The specified part of the buffer is scheduled to be written. dm-bufio may 0106 * write the specified part of the buffer or it may write a larger superset. 0107 */ 0108 void dm_bufio_mark_partial_buffer_dirty(struct dm_buffer *b, 0109 unsigned start, unsigned end); 0110 0111 /* 0112 * Initiate writing of dirty buffers, without waiting for completion. 0113 */ 0114 void dm_bufio_write_dirty_buffers_async(struct dm_bufio_client *c); 0115 0116 /* 0117 * Write all dirty buffers. Guarantees that all dirty buffers created prior 0118 * to this call are on disk when this call exits. 0119 */ 0120 int dm_bufio_write_dirty_buffers(struct dm_bufio_client *c); 0121 0122 /* 0123 * Send an empty write barrier to the device to flush hardware disk cache. 0124 */ 0125 int dm_bufio_issue_flush(struct dm_bufio_client *c); 0126 0127 /* 0128 * Send a discard request to the underlying device. 0129 */ 0130 int dm_bufio_issue_discard(struct dm_bufio_client *c, sector_t block, sector_t count); 0131 0132 /* 0133 * Like dm_bufio_release but also move the buffer to the new 0134 * block. dm_bufio_write_dirty_buffers is needed to commit the new block. 0135 */ 0136 void dm_bufio_release_move(struct dm_buffer *b, sector_t new_block); 0137 0138 /* 0139 * Free the given buffer. 0140 * This is just a hint, if the buffer is in use or dirty, this function 0141 * does nothing. 0142 */ 0143 void dm_bufio_forget(struct dm_bufio_client *c, sector_t block); 0144 0145 /* 0146 * Free the given range of buffers. 0147 * This is just a hint, if the buffer is in use or dirty, this function 0148 * does nothing. 0149 */ 0150 void dm_bufio_forget_buffers(struct dm_bufio_client *c, sector_t block, sector_t n_blocks); 0151 0152 /* 0153 * Set the minimum number of buffers before cleanup happens. 0154 */ 0155 void dm_bufio_set_minimum_buffers(struct dm_bufio_client *c, unsigned n); 0156 0157 unsigned dm_bufio_get_block_size(struct dm_bufio_client *c); 0158 sector_t dm_bufio_get_device_size(struct dm_bufio_client *c); 0159 struct dm_io_client *dm_bufio_get_dm_io_client(struct dm_bufio_client *c); 0160 sector_t dm_bufio_get_block_number(struct dm_buffer *b); 0161 void *dm_bufio_get_block_data(struct dm_buffer *b); 0162 void *dm_bufio_get_aux_data(struct dm_buffer *b); 0163 struct dm_bufio_client *dm_bufio_get_client(struct dm_buffer *b); 0164 0165 /*----------------------------------------------------------------*/ 0166 0167 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |