![]() |
|
|||
0001 /* 0002 * Copyright (C) 2011 Red Hat, Inc. 0003 * 0004 * This file is released under the GPL. 0005 */ 0006 0007 #ifndef _LINUX_DM_BLOCK_MANAGER_H 0008 #define _LINUX_DM_BLOCK_MANAGER_H 0009 0010 #include <linux/types.h> 0011 #include <linux/blkdev.h> 0012 0013 /*----------------------------------------------------------------*/ 0014 0015 /* 0016 * Block number. 0017 */ 0018 typedef uint64_t dm_block_t; 0019 struct dm_block; 0020 0021 dm_block_t dm_block_location(struct dm_block *b); 0022 void *dm_block_data(struct dm_block *b); 0023 0024 /*----------------------------------------------------------------*/ 0025 0026 /* 0027 * @name should be a unique identifier for the block manager, no longer 0028 * than 32 chars. 0029 * 0030 * @max_held_per_thread should be the maximum number of locks, read or 0031 * write, that an individual thread holds at any one time. 0032 */ 0033 struct dm_block_manager; 0034 struct dm_block_manager *dm_block_manager_create( 0035 struct block_device *bdev, unsigned block_size, 0036 unsigned max_held_per_thread); 0037 void dm_block_manager_destroy(struct dm_block_manager *bm); 0038 0039 unsigned dm_bm_block_size(struct dm_block_manager *bm); 0040 dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm); 0041 0042 /*----------------------------------------------------------------*/ 0043 0044 /* 0045 * The validator allows the caller to verify newly-read data and modify 0046 * the data just before writing, e.g. to calculate checksums. It's 0047 * important to be consistent with your use of validators. The only time 0048 * you can change validators is if you call dm_bm_write_lock_zero. 0049 */ 0050 struct dm_block_validator { 0051 const char *name; 0052 void (*prepare_for_write)(struct dm_block_validator *v, struct dm_block *b, size_t block_size); 0053 0054 /* 0055 * Return 0 if the checksum is valid or < 0 on error. 0056 */ 0057 int (*check)(struct dm_block_validator *v, struct dm_block *b, size_t block_size); 0058 }; 0059 0060 /*----------------------------------------------------------------*/ 0061 0062 /* 0063 * You can have multiple concurrent readers or a single writer holding a 0064 * block lock. 0065 */ 0066 0067 /* 0068 * dm_bm_lock() locks a block and returns through @result a pointer to 0069 * memory that holds a copy of that block. If you have write-locked the 0070 * block then any changes you make to memory pointed to by @result will be 0071 * written back to the disk sometime after dm_bm_unlock is called. 0072 */ 0073 int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b, 0074 struct dm_block_validator *v, 0075 struct dm_block **result); 0076 0077 int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b, 0078 struct dm_block_validator *v, 0079 struct dm_block **result); 0080 0081 /* 0082 * The *_try_lock variants return -EWOULDBLOCK if the block isn't 0083 * available immediately. 0084 */ 0085 int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b, 0086 struct dm_block_validator *v, 0087 struct dm_block **result); 0088 0089 /* 0090 * Use dm_bm_write_lock_zero() when you know you're going to 0091 * overwrite the block completely. It saves a disk read. 0092 */ 0093 int dm_bm_write_lock_zero(struct dm_block_manager *bm, dm_block_t b, 0094 struct dm_block_validator *v, 0095 struct dm_block **result); 0096 0097 void dm_bm_unlock(struct dm_block *b); 0098 0099 /* 0100 * It's a common idiom to have a superblock that should be committed last. 0101 * 0102 * @superblock should be write-locked on entry. It will be unlocked during 0103 * this function. All dirty blocks are guaranteed to be written and flushed 0104 * before the superblock. 0105 * 0106 * This method always blocks. 0107 */ 0108 int dm_bm_flush(struct dm_block_manager *bm); 0109 0110 /* 0111 * Request data is prefetched into the cache. 0112 */ 0113 void dm_bm_prefetch(struct dm_block_manager *bm, dm_block_t b); 0114 0115 /* 0116 * Switches the bm to a read only mode. Once read-only mode 0117 * has been entered the following functions will return -EPERM. 0118 * 0119 * dm_bm_write_lock 0120 * dm_bm_write_lock_zero 0121 * dm_bm_flush_and_unlock 0122 * 0123 * Additionally you should not use dm_bm_unlock_move, however no error will 0124 * be returned if you do. 0125 */ 0126 bool dm_bm_is_read_only(struct dm_block_manager *bm); 0127 void dm_bm_set_read_only(struct dm_block_manager *bm); 0128 void dm_bm_set_read_write(struct dm_block_manager *bm); 0129 0130 u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor); 0131 0132 /*----------------------------------------------------------------*/ 0133 0134 #endif /* _LINUX_DM_BLOCK_MANAGER_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |