Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Copyright (C) 2011 Red Hat, Inc.
  4 *
  5 * This file is released under the GPL.
  6 */
  7
  8#ifndef _LINUX_DM_BLOCK_MANAGER_H
  9#define _LINUX_DM_BLOCK_MANAGER_H
 10
 11#include <linux/types.h>
 12#include <linux/blkdev.h>
 13
 14/*----------------------------------------------------------------*/
 15
 16/*
 17 * Block number.
 18 */
 19typedef uint64_t dm_block_t;
 20struct dm_block;
 21
 22dm_block_t dm_block_location(struct dm_block *b);
 23void *dm_block_data(struct dm_block *b);
 24
 25/*----------------------------------------------------------------*/
 26
 27/*
 28 * @name should be a unique identifier for the block manager, no longer
 29 * than 32 chars.
 30 *
 31 * @max_held_per_thread should be the maximum number of locks, read or
 32 * write, that an individual thread holds at any one time.
 33 */
 34struct dm_block_manager;
 35struct dm_block_manager *dm_block_manager_create(
 36	struct block_device *bdev, unsigned int block_size,
 37	unsigned int max_held_per_thread);
 38void dm_block_manager_destroy(struct dm_block_manager *bm);
 39void dm_block_manager_reset(struct dm_block_manager *bm);
 40
 41unsigned int dm_bm_block_size(struct dm_block_manager *bm);
 42dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm);
 43
 44/*----------------------------------------------------------------*/
 45
 46/*
 47 * The validator allows the caller to verify newly-read data and modify
 48 * the data just before writing, e.g. to calculate checksums.  It's
 49 * important to be consistent with your use of validators.  The only time
 50 * you can change validators is if you call dm_bm_write_lock_zero.
 51 */
 52struct dm_block_validator {
 53	const char *name;
 54	void (*prepare_for_write)(struct dm_block_validator *v, struct dm_block *b, size_t block_size);
 
 55
 56	/*
 57	 * Return 0 if the checksum is valid or < 0 on error.
 58	 */
 59	int (*check)(struct dm_block_validator *v, struct dm_block *b, size_t block_size);
 
 60};
 61
 62/*----------------------------------------------------------------*/
 63
 64/*
 65 * You can have multiple concurrent readers or a single writer holding a
 66 * block lock.
 67 */
 68
 69/*
 70 * dm_bm_lock() locks a block and returns through @result a pointer to
 71 * memory that holds a copy of that block.  If you have write-locked the
 72 * block then any changes you make to memory pointed to by @result will be
 73 * written back to the disk sometime after dm_bm_unlock is called.
 74 */
 75int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
 76		    struct dm_block_validator *v,
 77		    struct dm_block **result);
 78
 79int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b,
 80		     struct dm_block_validator *v,
 81		     struct dm_block **result);
 82
 83/*
 84 * The *_try_lock variants return -EWOULDBLOCK if the block isn't
 85 * available immediately.
 86 */
 87int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b,
 88			struct dm_block_validator *v,
 89			struct dm_block **result);
 90
 91/*
 92 * Use dm_bm_write_lock_zero() when you know you're going to
 93 * overwrite the block completely.  It saves a disk read.
 94 */
 95int dm_bm_write_lock_zero(struct dm_block_manager *bm, dm_block_t b,
 96			  struct dm_block_validator *v,
 97			  struct dm_block **result);
 98
 99void dm_bm_unlock(struct dm_block *b);
100
101/*
102 * It's a common idiom to have a superblock that should be committed last.
103 *
104 * @superblock should be write-locked on entry. It will be unlocked during
105 * this function.  All dirty blocks are guaranteed to be written and flushed
106 * before the superblock.
107 *
108 * This method always blocks.
109 */
110int dm_bm_flush(struct dm_block_manager *bm);
111
112/*
113 * Request data is prefetched into the cache.
114 */
115void dm_bm_prefetch(struct dm_block_manager *bm, dm_block_t b);
116
117/*
118 * Switches the bm to a read only mode.  Once read-only mode
119 * has been entered the following functions will return -EPERM.
120 *
121 *   dm_bm_write_lock
122 *   dm_bm_write_lock_zero
123 *   dm_bm_flush_and_unlock
124 *
125 * Additionally you should not use dm_bm_unlock_move, however no error will
126 * be returned if you do.
127 */
128bool dm_bm_is_read_only(struct dm_block_manager *bm);
129void dm_bm_set_read_only(struct dm_block_manager *bm);
130void dm_bm_set_read_write(struct dm_block_manager *bm);
131
132u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor);
133
134/*----------------------------------------------------------------*/
135
136#endif	/* _LINUX_DM_BLOCK_MANAGER_H */
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Copyright (C) 2011 Red Hat, Inc.
  4 *
  5 * This file is released under the GPL.
  6 */
  7
  8#ifndef _LINUX_DM_BLOCK_MANAGER_H
  9#define _LINUX_DM_BLOCK_MANAGER_H
 10
 11#include <linux/types.h>
 12#include <linux/blkdev.h>
 13
 14/*----------------------------------------------------------------*/
 15
 16/*
 17 * Block number.
 18 */
 19typedef uint64_t dm_block_t;
 20struct dm_block;
 21
 22dm_block_t dm_block_location(struct dm_block *b);
 23void *dm_block_data(struct dm_block *b);
 24
 25/*----------------------------------------------------------------*/
 26
 27/*
 28 * @name should be a unique identifier for the block manager, no longer
 29 * than 32 chars.
 30 *
 31 * @max_held_per_thread should be the maximum number of locks, read or
 32 * write, that an individual thread holds at any one time.
 33 */
 34struct dm_block_manager;
 35struct dm_block_manager *dm_block_manager_create(
 36	struct block_device *bdev, unsigned int block_size,
 37	unsigned int max_held_per_thread);
 38void dm_block_manager_destroy(struct dm_block_manager *bm);
 39void dm_block_manager_reset(struct dm_block_manager *bm);
 40
 41unsigned int dm_bm_block_size(struct dm_block_manager *bm);
 42dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm);
 43
 44/*----------------------------------------------------------------*/
 45
 46/*
 47 * The validator allows the caller to verify newly-read data and modify
 48 * the data just before writing, e.g. to calculate checksums.  It's
 49 * important to be consistent with your use of validators.  The only time
 50 * you can change validators is if you call dm_bm_write_lock_zero.
 51 */
 52struct dm_block_validator {
 53	const char *name;
 54	void (*prepare_for_write)(const struct dm_block_validator *v,
 55				  struct dm_block *b, size_t block_size);
 56
 57	/*
 58	 * Return 0 if the checksum is valid or < 0 on error.
 59	 */
 60	int (*check)(const struct dm_block_validator *v,
 61		     struct dm_block *b, size_t block_size);
 62};
 63
 64/*----------------------------------------------------------------*/
 65
 66/*
 67 * You can have multiple concurrent readers or a single writer holding a
 68 * block lock.
 69 */
 70
 71/*
 72 * dm_bm_lock() locks a block and returns through @result a pointer to
 73 * memory that holds a copy of that block.  If you have write-locked the
 74 * block then any changes you make to memory pointed to by @result will be
 75 * written back to the disk sometime after dm_bm_unlock is called.
 76 */
 77int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
 78		    const struct dm_block_validator *v,
 79		    struct dm_block **result);
 80
 81int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b,
 82		     const struct dm_block_validator *v,
 83		     struct dm_block **result);
 84
 85/*
 86 * The *_try_lock variants return -EWOULDBLOCK if the block isn't
 87 * available immediately.
 88 */
 89int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b,
 90			const struct dm_block_validator *v,
 91			struct dm_block **result);
 92
 93/*
 94 * Use dm_bm_write_lock_zero() when you know you're going to
 95 * overwrite the block completely.  It saves a disk read.
 96 */
 97int dm_bm_write_lock_zero(struct dm_block_manager *bm, dm_block_t b,
 98			  const struct dm_block_validator *v,
 99			  struct dm_block **result);
100
101void dm_bm_unlock(struct dm_block *b);
102
103/*
104 * It's a common idiom to have a superblock that should be committed last.
105 *
106 * @superblock should be write-locked on entry. It will be unlocked during
107 * this function.  All dirty blocks are guaranteed to be written and flushed
108 * before the superblock.
109 *
110 * This method always blocks.
111 */
112int dm_bm_flush(struct dm_block_manager *bm);
113
114/*
115 * Request data is prefetched into the cache.
116 */
117void dm_bm_prefetch(struct dm_block_manager *bm, dm_block_t b);
118
119/*
120 * Switches the bm to a read only mode.  Once read-only mode
121 * has been entered the following functions will return -EPERM.
122 *
123 *   dm_bm_write_lock
124 *   dm_bm_write_lock_zero
125 *   dm_bm_flush_and_unlock
126 *
127 * Additionally you should not use dm_bm_unlock_move, however no error will
128 * be returned if you do.
129 */
130bool dm_bm_is_read_only(struct dm_block_manager *bm);
131void dm_bm_set_read_only(struct dm_block_manager *bm);
132void dm_bm_set_read_write(struct dm_block_manager *bm);
133
134u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor);
135
136/*----------------------------------------------------------------*/
137
138#endif	/* _LINUX_DM_BLOCK_MANAGER_H */