![]() |
|
|||
0001 /* 0002 * Copyright (C) 2011-2017 Red Hat, Inc. 0003 * 0004 * This file is released under the GPL. 0005 */ 0006 0007 #ifndef DM_BIO_PRISON_V2_H 0008 #define DM_BIO_PRISON_V2_H 0009 0010 #include "persistent-data/dm-block-manager.h" /* FIXME: for dm_block_t */ 0011 #include "dm-thin-metadata.h" /* FIXME: for dm_thin_id */ 0012 0013 #include <linux/bio.h> 0014 #include <linux/rbtree.h> 0015 #include <linux/workqueue.h> 0016 0017 /*----------------------------------------------------------------*/ 0018 0019 int dm_bio_prison_init_v2(void); 0020 void dm_bio_prison_exit_v2(void); 0021 0022 /* 0023 * Sometimes we can't deal with a bio straight away. We put them in prison 0024 * where they can't cause any mischief. Bios are put in a cell identified 0025 * by a key, multiple bios can be in the same cell. When the cell is 0026 * subsequently unlocked the bios become available. 0027 */ 0028 struct dm_bio_prison_v2; 0029 0030 /* 0031 * Keys define a range of blocks within either a virtual or physical 0032 * device. 0033 */ 0034 struct dm_cell_key_v2 { 0035 int virtual; 0036 dm_thin_id dev; 0037 dm_block_t block_begin, block_end; 0038 }; 0039 0040 /* 0041 * Treat this as opaque, only in header so callers can manage allocation 0042 * themselves. 0043 */ 0044 struct dm_bio_prison_cell_v2 { 0045 // FIXME: pack these 0046 bool exclusive_lock; 0047 unsigned exclusive_level; 0048 unsigned shared_count; 0049 struct work_struct *quiesce_continuation; 0050 0051 struct rb_node node; 0052 struct dm_cell_key_v2 key; 0053 struct bio_list bios; 0054 }; 0055 0056 struct dm_bio_prison_v2 *dm_bio_prison_create_v2(struct workqueue_struct *wq); 0057 void dm_bio_prison_destroy_v2(struct dm_bio_prison_v2 *prison); 0058 0059 /* 0060 * These two functions just wrap a mempool. This is a transitory step: 0061 * Eventually all bio prison clients should manage their own cell memory. 0062 * 0063 * Like mempool_alloc(), dm_bio_prison_alloc_cell_v2() can only fail if called 0064 * in interrupt context or passed GFP_NOWAIT. 0065 */ 0066 struct dm_bio_prison_cell_v2 *dm_bio_prison_alloc_cell_v2(struct dm_bio_prison_v2 *prison, 0067 gfp_t gfp); 0068 void dm_bio_prison_free_cell_v2(struct dm_bio_prison_v2 *prison, 0069 struct dm_bio_prison_cell_v2 *cell); 0070 0071 /* 0072 * Shared locks have a bio associated with them. 0073 * 0074 * If the lock is granted the caller can continue to use the bio, and must 0075 * call dm_cell_put_v2() to drop the reference count when finished using it. 0076 * 0077 * If the lock cannot be granted then the bio will be tracked within the 0078 * cell, and later given to the holder of the exclusive lock. 0079 * 0080 * See dm_cell_lock_v2() for discussion of the lock_level parameter. 0081 * 0082 * Compare *cell_result with cell_prealloc to see if the prealloc was used. 0083 * If cell_prealloc was used then inmate wasn't added to it. 0084 * 0085 * Returns true if the lock is granted. 0086 */ 0087 bool dm_cell_get_v2(struct dm_bio_prison_v2 *prison, 0088 struct dm_cell_key_v2 *key, 0089 unsigned lock_level, 0090 struct bio *inmate, 0091 struct dm_bio_prison_cell_v2 *cell_prealloc, 0092 struct dm_bio_prison_cell_v2 **cell_result); 0093 0094 /* 0095 * Decrement the shared reference count for the lock. Returns true if 0096 * returning ownership of the cell (ie. you should free it). 0097 */ 0098 bool dm_cell_put_v2(struct dm_bio_prison_v2 *prison, 0099 struct dm_bio_prison_cell_v2 *cell); 0100 0101 /* 0102 * Locks a cell. No associated bio. Exclusive locks get priority. These 0103 * locks constrain whether the io locks are granted according to level. 0104 * 0105 * Shared locks will still be granted if the lock_level is > (not = to) the 0106 * exclusive lock level. 0107 * 0108 * If an _exclusive_ lock is already held then -EBUSY is returned. 0109 * 0110 * Return values: 0111 * < 0 - error 0112 * 0 - locked; no quiescing needed 0113 * 1 - locked; quiescing needed 0114 */ 0115 int dm_cell_lock_v2(struct dm_bio_prison_v2 *prison, 0116 struct dm_cell_key_v2 *key, 0117 unsigned lock_level, 0118 struct dm_bio_prison_cell_v2 *cell_prealloc, 0119 struct dm_bio_prison_cell_v2 **cell_result); 0120 0121 void dm_cell_quiesce_v2(struct dm_bio_prison_v2 *prison, 0122 struct dm_bio_prison_cell_v2 *cell, 0123 struct work_struct *continuation); 0124 0125 /* 0126 * Promotes an _exclusive_ lock to a higher lock level. 0127 * 0128 * Return values: 0129 * < 0 - error 0130 * 0 - promoted; no quiescing needed 0131 * 1 - promoted; quiescing needed 0132 */ 0133 int dm_cell_lock_promote_v2(struct dm_bio_prison_v2 *prison, 0134 struct dm_bio_prison_cell_v2 *cell, 0135 unsigned new_lock_level); 0136 0137 /* 0138 * Adds any held bios to the bio list. 0139 * 0140 * There may be shared locks still held at this point even if you quiesced 0141 * (ie. different lock levels). 0142 * 0143 * Returns true if returning ownership of the cell (ie. you should free 0144 * it). 0145 */ 0146 bool dm_cell_unlock_v2(struct dm_bio_prison_v2 *prison, 0147 struct dm_bio_prison_cell_v2 *cell, 0148 struct bio_list *bios); 0149 0150 /*----------------------------------------------------------------*/ 0151 0152 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |