1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

o There were some alignment problems with pool-debug which I've resolved

by allocating the data block with an additional dbg_malloc.

o  Added an assertion to check that no one is requesting alternate
   alignment for memory allocated from pool.  I can't see us needing this
   for LVM2.
This commit is contained in:
Joe Thornber 2002-01-28 09:16:09 +00:00
parent 154ca4b837
commit 4b2ec1929a
2 changed files with 23 additions and 7 deletions

View File

@ -267,7 +267,7 @@ struct logical_volume *lv_create(struct format_instance *fi,
struct volume_group *vg, struct volume_group *vg,
struct list *acceptable_pvs); struct list *acceptable_pvs);
int lv_reduce(struct format_instance *fi, int lv_reduce(struct format_instance *fi,
struct logical_volume *lv, uint32_t extents); struct logical_volume *lv, uint32_t extents);
int lv_extend(struct format_instance *fi, int lv_extend(struct format_instance *fi,

View File

@ -13,7 +13,7 @@
struct block { struct block {
struct block *next; struct block *next;
size_t size; size_t size;
char data[0]; void *data;
}; };
struct pool { struct pool {
@ -49,6 +49,7 @@ static void _free_blocks(struct block *b)
while (b) { while (b) {
n = b->next; n = b->next;
dbg_free(b->data);
dbg_free(b); dbg_free(b);
b = n; b = n;
} }
@ -76,12 +77,27 @@ static void _append_block(struct pool *p, struct block *b)
static struct block *_new_block(size_t s, unsigned alignment) static struct block *_new_block(size_t s, unsigned alignment)
{ {
static char *_oom = "Out of memory";
/* FIXME: I'm currently ignoring the alignment arg. */ /* FIXME: I'm currently ignoring the alignment arg. */
size_t len = sizeof(struct block) + s; size_t len = sizeof(struct block) + s;
struct block *b = dbg_malloc(len); struct block *b = dbg_malloc(len);
/*
* Too lazy to implement alignment for debug version, and
* I don't think LVM will use anything but default
* align.
*/
assert(alignment == DEFAULT_ALIGNMENT);
if (!b) { if (!b) {
log_err("Out of memory. Requested %u bytes.", len); log_err(_oom);
return NULL;
}
if (!(b->data = dbg_malloc(s))) {
log_err(_oom);
dbg_free(b);
return NULL; return NULL;
} }
@ -99,7 +115,7 @@ void *pool_alloc_aligned(struct pool *p, size_t s, unsigned alignment)
return NULL; return NULL;
_append_block(p, b); _append_block(p, b);
return &b->data[0]; return b->data;
} }
void pool_empty(struct pool *p) void pool_empty(struct pool *p)
@ -113,7 +129,7 @@ void pool_free(struct pool *p, void *ptr)
struct block *b, *prev = NULL; struct block *b, *prev = NULL;
for (b = p->blocks; b; b = b->next) { for (b = p->blocks; b; b = b->next) {
if ((void *) &b->data[0] == ptr) if (b->data == ptr)
break; break;
prev = b; prev = b;
} }
@ -157,7 +173,7 @@ int pool_grow_object(struct pool *p, const void *buffer, size_t delta)
} }
if (p->object) { if (p->object) {
memcpy(&new->data, &p->object->data, p->object->size); memcpy(new->data, p->object->data, p->object->size);
dbg_free(p->object); dbg_free(p->object);
} }
p->object = new; p->object = new;
@ -172,7 +188,7 @@ void *pool_end_object(struct pool *p)
p->begun = 0; p->begun = 0;
p->object = NULL; p->object = NULL;
return &p->tail->data; return p->tail->data;
} }
void pool_abandon_object(struct pool *p) void pool_abandon_object(struct pool *p)