mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
o Added two new functions get_child [Andrew Clausen] and get_node. I think
this makes 'high()' a bit more understandable.
This commit is contained in:
parent
52ffc15ffc
commit
297a047fb4
@ -64,10 +64,10 @@ static offset_t high(struct dm_table *t, int l, int n)
|
||||
return (offset_t) -1;
|
||||
|
||||
if (l == t->depth - 1)
|
||||
return t->index[l][((n + 1) * KEYS_PER_NODE) - 1];
|
||||
return get_node(t, l, n)[KEYS_PER_NODE - 1];
|
||||
|
||||
l++;
|
||||
n = (n + 1) * CHILD_PER_NODE - 1;
|
||||
n = get_child(n, CHILDREN_PER_NODE - 1);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@ -82,12 +82,14 @@ static int setup_btree_index(int l, struct dm_table *t)
|
||||
int n, c, cn;
|
||||
|
||||
for (n = 0, cn = 0; n < t->counts[l]; n++) {
|
||||
offset_t *k = t->index[l] + (n * KEYS_PER_NODE);
|
||||
offset_t *node = get_node(t, l, n);
|
||||
|
||||
for (c = 0; c < KEYS_PER_NODE; c++)
|
||||
k[c] = high(t, l + 1, cn++);
|
||||
cn++; /* one extra for the child that's
|
||||
greater than all keys */
|
||||
node[c] = high(t, l + 1, cn++);
|
||||
|
||||
/* one extra for the child that's greater
|
||||
than all keys in the node */
|
||||
cn++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -313,7 +315,7 @@ int dm_table_complete(struct dm_table *t)
|
||||
|
||||
/* how many indexes will the btree have ? */
|
||||
leaf_nodes = div_up(t->num_targets, KEYS_PER_NODE);
|
||||
t->depth = 1 + int_log(leaf_nodes, CHILD_PER_NODE);
|
||||
t->depth = 1 + int_log(leaf_nodes, CHILDREN_PER_NODE);
|
||||
|
||||
/* leaf layer has already been set up */
|
||||
t->counts[t->depth - 1] = leaf_nodes;
|
||||
@ -321,7 +323,7 @@ int dm_table_complete(struct dm_table *t)
|
||||
|
||||
/* set up internal nodes, bottom-up */
|
||||
for (i = t->depth - 2; i >= 0; i--) {
|
||||
t->counts[i] = div_up(t->counts[i + 1], CHILD_PER_NODE);
|
||||
t->counts[i] = div_up(t->counts[i + 1], CHILDREN_PER_NODE);
|
||||
t->index[i] = vmalloc(NODE_SIZE * t->counts[i]);
|
||||
setup_btree_index(i, t);
|
||||
}
|
||||
|
@ -338,19 +338,19 @@ static inline int __map_buffer(struct mapped_device *md,
|
||||
*/
|
||||
static inline int __find_node(struct dm_table *t, struct buffer_head *bh)
|
||||
{
|
||||
int i = 0, l, r = 0;
|
||||
int l, n = 0, k = 0;
|
||||
offset_t *node;
|
||||
|
||||
for (l = 0; l < t->depth; l++) {
|
||||
r = (CHILD_PER_NODE * r) + i;
|
||||
node = t->index[l] + (r * KEYS_PER_NODE);
|
||||
n = get_child(n, k);
|
||||
node = get_node(t, l, n);
|
||||
|
||||
for (i = 0; i < KEYS_PER_NODE; i++)
|
||||
if (node[i] >= bh->b_rsector)
|
||||
for (k = 0; k < KEYS_PER_NODE; k++)
|
||||
if (node[k] >= bh->b_rsector)
|
||||
break;
|
||||
}
|
||||
|
||||
return (KEYS_PER_NODE * r) + i;
|
||||
return (KEYS_PER_NODE * n) + k;
|
||||
}
|
||||
|
||||
static int request(request_queue_t *q, int rw, struct buffer_head *bh)
|
||||
|
@ -134,7 +134,7 @@
|
||||
#define MAX_DEPTH 16
|
||||
#define NODE_SIZE L1_CACHE_BYTES
|
||||
#define KEYS_PER_NODE (NODE_SIZE / sizeof(offset_t))
|
||||
#define CHILD_PER_NODE (KEYS_PER_NODE + 1)
|
||||
#define CHILDREN_PER_NODE (KEYS_PER_NODE + 1)
|
||||
#define DM_NAME_LEN 64
|
||||
|
||||
enum {
|
||||
@ -263,6 +263,23 @@ int dm_fs_remove(struct mapped_device *md);
|
||||
|
||||
#define WARN(f, x...) printk(KERN_WARNING "device-mapper: " f "\n" , ## x)
|
||||
|
||||
/*
|
||||
* calculate the index of the child node of the
|
||||
* n'th node k'th key.
|
||||
*/
|
||||
static inline int get_child(int n, int k)
|
||||
{
|
||||
return (n * CHILDREN_PER_NODE) + k;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the n'th node of level l from table t.
|
||||
*/
|
||||
static inline offset_t *get_node(struct dm_table *t, int l, int n)
|
||||
{
|
||||
return t->index[l] + (n * KEYS_PER_NODE);
|
||||
}
|
||||
|
||||
static inline int is_active(struct mapped_device *md)
|
||||
{
|
||||
return test_bit(DM_ACTIVE, &md->state);
|
||||
|
Loading…
Reference in New Issue
Block a user