/* * Copyright (C) 2001 Sistina Software (UK) Limited. * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. * * This file is released under the GPL. */#include"dm.h"#include<linux/module.h>#include<linux/vmalloc.h>#include<linux/blkdev.h>#include<linux/namei.h>#include<linux/ctype.h>#include<linux/string.h>#include<linux/slab.h>#include<linux/interrupt.h>#include<linux/mutex.h>#include<linux/delay.h>#include<asm/atomic.h>#define DM_MSG_PREFIX "table"#define MAX_DEPTH 16#define NODE_SIZE L1_CACHE_BYTES#define KEYS_PER_NODE (NODE_SIZE / sizeof(sector_t))#define CHILDREN_PER_NODE (KEYS_PER_NODE + 1)/* * The table has always exactly one reference from either mapped_device->map * or hash_cell->new_map. This reference is not counted in table->holders. * A pair of dm_create_table/dm_destroy_table functions is used for table * creation/destruction. * * Temporary references from the other code increase table->holders. A pair * of dm_table_get/dm_table_put functions is used to manipulate it. * * When the table is about to be destroyed, we wait for table->holders to * drop to zero. */structdm_table{structmapped_device*md;atomic_tholders;unsignedtype;/* btree table */unsignedintdepth;unsignedintcounts[MAX_DEPTH];/* in nodes */sector_t*index[MAX_DEPTH];unsignedintnum_targets;unsignedintnum_allocated;sector_t*highs;structdm_target*targets;unsigneddiscards_supported:1;unsignedintegrity_supported:1;/* * Indicates the rw permissions for the new logical * device. This should be a combination of FMODE_READ * and FMODE_WRITE. */fmode_tmode;/* a list of devices used by this table */structlist_headdevices;/* events get handed up using this callback */void(*event_fn)(void*);void*event_context;structdm_md_mempools*mempools;structlist_headtarget_callbacks;};/* * Similar to ceiling(log_size(n)) */staticunsignedintint_log(unsignedintn,unsignedintbase){intresult=0;while(n>1){n=dm_div_up(n,base);result++;}returnresult;