dm-table.c (db58316892a5e9034efe718d4c1630788db7528f) | dm-table.c (83d5e5b0af907d46d241a86d9e44003b3f0accbd) |
---|---|
1/* 2 * Copyright (C) 2001 Sistina Software (UK) Limited. 3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. 4 * 5 * This file is released under the GPL. 6 */ 7 8#include "dm.h" --- 12 unchanged lines hidden (view full) --- 21 22#define DM_MSG_PREFIX "table" 23 24#define MAX_DEPTH 16 25#define NODE_SIZE L1_CACHE_BYTES 26#define KEYS_PER_NODE (NODE_SIZE / sizeof(sector_t)) 27#define CHILDREN_PER_NODE (KEYS_PER_NODE + 1) 28 | 1/* 2 * Copyright (C) 2001 Sistina Software (UK) Limited. 3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. 4 * 5 * This file is released under the GPL. 6 */ 7 8#include "dm.h" --- 12 unchanged lines hidden (view full) --- 21 22#define DM_MSG_PREFIX "table" 23 24#define MAX_DEPTH 16 25#define NODE_SIZE L1_CACHE_BYTES 26#define KEYS_PER_NODE (NODE_SIZE / sizeof(sector_t)) 27#define CHILDREN_PER_NODE (KEYS_PER_NODE + 1) 28 |
29/* 30 * The table has always exactly one reference from either mapped_device->map 31 * or hash_cell->new_map. This reference is not counted in table->holders. 32 * A pair of dm_create_table/dm_destroy_table functions is used for table 33 * creation/destruction. 34 * 35 * Temporary references from the other code increase table->holders. A pair 36 * of dm_table_get/dm_table_put functions is used to manipulate it. 37 * 38 * When the table is about to be destroyed, we wait for table->holders to 39 * drop to zero. 40 */ 41 | |
42struct dm_table { 43 struct mapped_device *md; | 29struct dm_table { 30 struct mapped_device *md; |
44 atomic_t holders; | |
45 unsigned type; 46 47 /* btree table */ 48 unsigned int depth; 49 unsigned int counts[MAX_DEPTH]; /* in nodes */ 50 sector_t *index[MAX_DEPTH]; 51 52 unsigned int num_targets; --- 150 unchanged lines hidden (view full) --- 203{ 204 struct dm_table *t = kzalloc(sizeof(*t), GFP_KERNEL); 205 206 if (!t) 207 return -ENOMEM; 208 209 INIT_LIST_HEAD(&t->devices); 210 INIT_LIST_HEAD(&t->target_callbacks); | 31 unsigned type; 32 33 /* btree table */ 34 unsigned int depth; 35 unsigned int counts[MAX_DEPTH]; /* in nodes */ 36 sector_t *index[MAX_DEPTH]; 37 38 unsigned int num_targets; --- 150 unchanged lines hidden (view full) --- 189{ 190 struct dm_table *t = kzalloc(sizeof(*t), GFP_KERNEL); 191 192 if (!t) 193 return -ENOMEM; 194 195 INIT_LIST_HEAD(&t->devices); 196 INIT_LIST_HEAD(&t->target_callbacks); |
211 atomic_set(&t->holders, 0); | |
212 213 if (!num_targets) 214 num_targets = KEYS_PER_NODE; 215 216 num_targets = dm_round_up(num_targets, KEYS_PER_NODE); 217 218 if (alloc_targets(t, num_targets)) { 219 kfree(t); --- 21 unchanged lines hidden (view full) --- 241 242void dm_table_destroy(struct dm_table *t) 243{ 244 unsigned int i; 245 246 if (!t) 247 return; 248 | 197 198 if (!num_targets) 199 num_targets = KEYS_PER_NODE; 200 201 num_targets = dm_round_up(num_targets, KEYS_PER_NODE); 202 203 if (alloc_targets(t, num_targets)) { 204 kfree(t); --- 21 unchanged lines hidden (view full) --- 226 227void dm_table_destroy(struct dm_table *t) 228{ 229 unsigned int i; 230 231 if (!t) 232 return; 233 |
249 while (atomic_read(&t->holders)) 250 msleep(1); 251 smp_mb(); 252 | |
253 /* free the indexes */ 254 if (t->depth >= 2) 255 vfree(t->index[t->depth - 2]); 256 257 /* free the targets */ 258 for (i = 0; i < t->num_targets; i++) { 259 struct dm_target *tgt = t->targets + i; 260 --- 8 unchanged lines hidden (view full) --- 269 /* free the device list */ 270 free_devices(&t->devices); 271 272 dm_free_md_mempools(t->mempools); 273 274 kfree(t); 275} 276 | 234 /* free the indexes */ 235 if (t->depth >= 2) 236 vfree(t->index[t->depth - 2]); 237 238 /* free the targets */ 239 for (i = 0; i < t->num_targets; i++) { 240 struct dm_target *tgt = t->targets + i; 241 --- 8 unchanged lines hidden (view full) --- 250 /* free the device list */ 251 free_devices(&t->devices); 252 253 dm_free_md_mempools(t->mempools); 254 255 kfree(t); 256} 257 |
277void dm_table_get(struct dm_table *t) 278{ 279 atomic_inc(&t->holders); 280} 281EXPORT_SYMBOL(dm_table_get); 282 283void dm_table_put(struct dm_table *t) 284{ 285 if (!t) 286 return; 287 288 smp_mb__before_atomic_dec(); 289 atomic_dec(&t->holders); 290} 291EXPORT_SYMBOL(dm_table_put); 292 | |
293/* 294 * Checks to see if we need to extend highs or targets. 295 */ 296static inline int check_space(struct dm_table *t) 297{ 298 if (t->num_targets >= t->num_allocated) 299 return alloc_targets(t, t->num_allocated * 2); 300 --- 1371 unchanged lines hidden --- | 258/* 259 * Checks to see if we need to extend highs or targets. 260 */ 261static inline int check_space(struct dm_table *t) 262{ 263 if (t->num_targets >= t->num_allocated) 264 return alloc_targets(t, t->num_allocated * 2); 265 --- 1371 unchanged lines hidden --- |