1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Use hash, bitset, malloc, pool from libdevmapper.

This commit is contained in:
Alasdair Kergon 2005-10-16 23:03:59 +00:00
parent a3f6b2ce79
commit 2262b32057
122 changed files with 949 additions and 2464 deletions

View File

@ -1,5 +1,7 @@
Version 2.02.00 -
===================================
Move mknodes into libdevmapper.
Move bitset, hash, pool and dbg_malloc into libdevmapper.
Version 2.01.15 - 16th October 2005
===================================

View File

@ -66,7 +66,6 @@
#include <errno.h>
#include "list.h"
#include "hash.h"
#include "locking.h"
#include "log.h"
#include "lvm-functions.h"

View File

@ -49,10 +49,8 @@
#include "clvmd-comms.h"
#include "lvm-functions.h"
#include "clvmd.h"
#include "hash.h"
#include "clvmd-gulm.h"
#include "libgulm.h"
#include "hash.h"
/* Hash list of nodes in the cluster */
static struct hash_table *node_hash;

View File

@ -41,7 +41,6 @@
#include "toolcontext.h"
#include "log.h"
#include "activate.h"
#include "hash.h"
#include "locking.h"
static struct cmd_context *cmd = NULL;
@ -330,7 +329,7 @@ int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
}
/* clean the pool for another command */
pool_empty(cmd->mem);
dm_pool_empty(cmd->mem);
DEBUGLOG("Command return is %d\n", status);
return status;

View File

@ -39,7 +39,6 @@
#include "clvmd-comms.h"
#include "clvmd.h"
#include "clvmd-gulm.h"
#include "hash.h"
#define DEFAULT_TCP_PORT 21064

View File

@ -6,9 +6,7 @@
../lib/commands/toolcontext.h
../lib/config/config.h
../lib/config/defaults.h
../lib/datastruct/bitset.h
../lib/datastruct/btree.h
../lib/datastruct/hash.h
../lib/datastruct/list.h
../lib/datastruct/lvm-types.h
../lib/datastruct/str_list.h
@ -34,9 +32,7 @@
../lib/metadata/metadata.h
../lib/metadata/pv_alloc.h
../lib/metadata/segtype.h
../lib/mm/dbg_malloc.h
../lib/mm/memlock.h
../lib/mm/pool.h
../lib/mm/xlate.h
../lib/misc/crc.h
../lib/misc/intl.h

View File

@ -37,9 +37,7 @@ SOURCES =\
cache/lvmcache.c \
commands/toolcontext.c \
config/config.c \
datastruct/bitset.c \
datastruct/btree.c \
datastruct/hash.c \
datastruct/str_list.c \
device/dev-cache.c \
device/dev-io.c \
@ -78,9 +76,7 @@ SOURCES =\
misc/crc.c \
misc/lvm-file.c \
misc/lvm-string.c \
mm/dbg_malloc.c \
mm/memlock.c \
mm/pool.c \
regex/matcher.c \
regex/parse_rx.c \
regex/ttree.c \

View File

@ -21,7 +21,6 @@
#include "fs.h"
#include "lvm-file.h"
#include "lvm-string.h"
#include "pool.h"
#include "toolcontext.h"
#include "dev_manager.h"
#include "str_list.h"
@ -762,7 +761,7 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
int r = 1;
if (!lv) {
r = dev_manager_mknodes();
r = dm_mknodes(NULL);
fs_unlock();
return r;
}

View File

@ -18,10 +18,6 @@
#include "metadata.h"
#ifdef DEVMAPPER_SUPPORT
# include <libdevmapper.h>
#endif
struct lvinfo {
int exists;
int suspended;

View File

@ -16,8 +16,6 @@
#include "lib.h"
#include "str_list.h"
#include "dev_manager.h"
#include "pool.h"
#include "hash.h"
#include "lvm-string.h"
#include "fs.h"
#include "defaults.h"
@ -27,7 +25,6 @@
#include "targets.h"
#include "config.h"
#include <libdevmapper.h>
#include <limits.h>
#include <dirent.h>
@ -113,7 +110,7 @@ struct dl_list {
static const char *stripe_filler = NULL;
struct dev_manager {
struct pool *mem;
struct dm_pool *mem;
struct cmd_context *cmd;
@ -144,7 +141,7 @@ struct dev_manager {
*/
struct list remove_list;
struct hash_table *layers;
struct dm_hash_table *layers;
};
/*
@ -165,7 +162,7 @@ static inline void _clear_flag(struct dev_layer *dl, int bit)
dl->flags &= ~(1 << bit);
}
static char *_build_dlid(struct pool *mem, const char *lvid, const char *layer)
static char *_build_dlid(struct dm_pool *mem, const char *lvid, const char *layer)
{
char *dlid;
size_t len;
@ -175,7 +172,7 @@ static char *_build_dlid(struct pool *mem, const char *lvid, const char *layer)
len = strlen(lvid) + strlen(layer) + 2;
if (!(dlid = pool_alloc(mem, len))) {
if (!(dlid = dm_pool_alloc(mem, len))) {
stack;
return NULL;
}
@ -211,7 +208,7 @@ static struct dm_task *_setup_task(const char *name, const char *uuid,
}
static int _info_run(const char *name, const char *uuid, struct dm_info *info,
int mknodes, int with_open_count, struct pool *mem,
int mknodes, int with_open_count, struct dm_pool *mem,
char **uuid_out)
{
int r = 0;
@ -245,7 +242,7 @@ static int _info_run(const char *name, const char *uuid, struct dm_info *info,
stack;
goto out;
}
*uuid_out = pool_strdup(mem, u);
*uuid_out = dm_pool_strdup(mem, u);
}
r = 1;
@ -256,7 +253,7 @@ static int _info_run(const char *name, const char *uuid, struct dm_info *info,
static int _info(const char *name, const char *uuid, int mknodes,
int with_open_count, struct dm_info *info,
struct pool *mem, char **uuid_out)
struct dm_pool *mem, char **uuid_out)
{
if (!mknodes && uuid && *uuid &&
_info_run(NULL, uuid, info, 0, with_open_count, mem, uuid_out) &&
@ -732,7 +729,7 @@ int build_dev_string(struct dev_manager *dm, char *dlid, char *devbuf,
{
struct dev_layer *dl;
if (!(dl = hash_lookup(dm->layers, dlid))) {
if (!(dl = dm_hash_lookup(dm->layers, dlid))) {
log_error("%s device layer %s missing from hash",
desc, dlid);
return 0;
@ -809,13 +806,13 @@ static int _emit_target(struct dev_manager *dm, struct dm_task *dmt,
int ret;
do {
if (!(params = dbg_malloc(paramsize))) {
if (!(params = dm_malloc(paramsize))) {
log_error("Insufficient space for target parameters.");
return 0;
}
ret = _emit_target_line(dm, dmt, seg, params, paramsize);
dbg_free(params);
dm_free(params);
if (!ret)
stack;
@ -936,15 +933,15 @@ static int _populate_snapshot(struct dev_manager *dm,
struct dev_manager *dev_manager_create(struct cmd_context *cmd,
const char *vg_name)
{
struct pool *mem;
struct dm_pool *mem;
struct dev_manager *dm;
if (!(mem = pool_create("dev_manager", 16 * 1024))) {
if (!(mem = dm_pool_create("dev_manager", 16 * 1024))) {
stack;
return NULL;
}
if (!(dm = pool_alloc(mem, sizeof(*dm)))) {
if (!(dm = dm_pool_alloc(mem, sizeof(*dm)))) {
stack;
goto bad;
}
@ -959,12 +956,12 @@ struct dev_manager *dev_manager_create(struct cmd_context *cmd,
}
dm->stripe_filler = stripe_filler;
if (!(dm->vg_name = pool_strdup(dm->mem, vg_name))) {
if (!(dm->vg_name = dm_pool_strdup(dm->mem, vg_name))) {
stack;
goto bad;
}
if (!(dm->layers = hash_create(32))) {
if (!(dm->layers = dm_hash_create(32))) {
stack;
goto bad;
}
@ -979,14 +976,14 @@ struct dev_manager *dev_manager_create(struct cmd_context *cmd,
return dm;
bad:
pool_destroy(mem);
dm_pool_destroy(mem);
return NULL;
}
void dev_manager_destroy(struct dev_manager *dm)
{
hash_destroy(dm->layers);
pool_destroy(dm->mem);
dm_hash_destroy(dm->layers);
dm_pool_destroy(dm->mem);
}
int dev_manager_info(struct dev_manager *dm, const struct logical_volume *lv,
@ -1038,7 +1035,7 @@ int dev_manager_snapshot_percent(struct dev_manager *dm,
return 0;
}
/* FIXME pool_free ? */
/* FIXME dm_pool_free ? */
/* If the snapshot isn't available, percent will be -1 */
return 1;
@ -1060,7 +1057,7 @@ int dev_manager_mirror_percent(struct dev_manager *dm,
return 0;
}
/* FIXME pool_free ? */
/* FIXME dm_pool_free ? */
log_debug("Getting device mirror status percentage for %s", name);
if (!(_percent(dm, name, lv->lvid.s, "mirror", wait, lv, percent,
@ -1078,7 +1075,7 @@ static struct dev_layer *_create_dev(struct dev_manager *dm, char *name,
struct dev_layer *dl;
char *uuid;
if (!(dl = pool_zalloc(dm->mem, sizeof(*dl)))) {
if (!(dl = dm_pool_zalloc(dm->mem, sizeof(*dl)))) {
stack;
return NULL;
}
@ -1099,7 +1096,7 @@ static struct dev_layer *_create_dev(struct dev_manager *dm, char *name,
list_init(&dl->pre_create);
list_init(&dl->pre_suspend);
if (!hash_insert(dm->layers, dl->dlid, dl)) {
if (!dm_hash_insert(dm->layers, dl->dlid, dl)) {
stack;
return NULL;
}
@ -1129,7 +1126,7 @@ static struct dev_layer *_create_layer(struct dev_manager *dm,
return NULL;
}
if (!(dl = hash_lookup(dm->layers, dlid)) &&
if (!(dl = dm_hash_lookup(dm->layers, dlid)) &&
!(dl = _create_dev(dm, name, dlid))) {
stack;
return NULL;
@ -1157,8 +1154,8 @@ static struct dev_layer *_lookup(struct dev_manager *dm,
return NULL;
}
dl = hash_lookup(dm->layers, dlid);
pool_free(dm->mem, dlid);
dl = dm_hash_lookup(dm->layers, dlid);
dm_pool_free(dm->mem, dlid);
return dl;
}
@ -1229,7 +1226,7 @@ static int _expand_vanilla(struct dev_manager *dm, struct logical_volume *lv,
/* add the dependency on the real device */
if (!str_list_add(dm->mem, &dl->pre_create,
pool_strdup(dm->mem, dlr->dlid))) {
dm_pool_strdup(dm->mem, dlr->dlid))) {
stack;
return 0;
}
@ -1266,7 +1263,7 @@ static int _expand_origin_real(struct dev_manager *dm,
/* add the dependency on the real device */
if (!str_list_add(dm->mem, &dl->pre_create,
pool_strdup(dm->mem, real_dlid))) {
dm_pool_strdup(dm->mem, real_dlid))) {
stack;
return 0;
}
@ -1327,7 +1324,7 @@ static int _expand_snapshot(struct dev_manager *dm, struct logical_volume *lv,
/* add the dependency on the cow device */
if (!str_list_add(dm->mem, &dl->pre_create,
pool_strdup(dm->mem, cow_dlid))) {
dm_pool_strdup(dm->mem, cow_dlid))) {
stack;
return 0;
}
@ -1382,11 +1379,11 @@ static int _expand_lv(struct dev_manager *dm, struct logical_volume *lv)
*/
static void _clear_marks(struct dev_manager *dm, int flag)
{
struct hash_node *hn;
struct dm_hash_node *hn;
struct dev_layer *dl;
hash_iterate(hn, dm->layers) {
dl = hash_get_data(dm->layers, hn);
dm_hash_iterate(hn, dm->layers) {
dl = dm_hash_get_data(dm->layers, hn);
_clear_flag(dl, flag);
}
}
@ -1404,7 +1401,7 @@ static int _trace_layer_marks(struct dev_manager *dm, struct dev_layer *dl,
list_iterate_items(strl, &dl->pre_create) {
dlid = strl->str;
if (!(dep = hash_lookup(dm->layers, dlid))) {
if (!(dep = dm_hash_lookup(dm->layers, dlid))) {
log_error("Couldn't find device layer '%s'.", dlid);
return 0;
}
@ -1432,11 +1429,11 @@ static int _trace_layer_marks(struct dev_manager *dm, struct dev_layer *dl,
*/
static int _trace_all_marks(struct dev_manager *dm, int flag)
{
struct hash_node *hn;
struct dm_hash_node *hn;
struct dev_layer *dl;
hash_iterate(hn, dm->layers) {
dl = hash_get_data(dm->layers, hn);
dm_hash_iterate(hn, dm->layers) {
dl = dm_hash_get_data(dm->layers, hn);
if (_get_flag(dl, flag) && !_trace_layer_marks(dm, dl, flag)) {
stack;
return 0;
@ -1484,7 +1481,7 @@ static int _suspend_parents(struct dev_manager *dm, struct dev_layer *dl)
list_iterate_items(strl, &dl->pre_suspend) {
dlid = strl->str;
if (!(dep = hash_lookup(dm->layers, dlid))) {
if (!(dep = dm_hash_lookup(dm->layers, dlid))) {
log_debug("_suspend_parents couldn't find device "
"layer '%s' - skipping.", dlid);
continue;
@ -1518,7 +1515,7 @@ static int _resume_with_deps(struct dev_manager *dm, struct dev_layer *dl)
list_iterate_items(strl, &dl->pre_create) {
dlid = strl->str;
if (!(dep = hash_lookup(dm->layers, dlid))) {
if (!(dep = dm_hash_lookup(dm->layers, dlid))) {
log_debug("_resume_with_deps couldn't find device "
"layer '%s' - skipping.", dlid);
continue;
@ -1564,7 +1561,7 @@ static int _create_rec(struct dev_manager *dm, struct dev_layer *dl)
list_iterate_items(strl, &dl->pre_create) {
dlid = strl->str;
if (!(dep = hash_lookup(dm->layers, dlid))) {
if (!(dep = dm_hash_lookup(dm->layers, dlid))) {
log_error("Couldn't find device layer '%s'.", dlid);
return 0;
}
@ -1637,18 +1634,18 @@ static int _build_all_layers(struct dev_manager *dm, struct volume_group *vg)
static int _fill_in_remove_list(struct dev_manager *dm)
{
struct hash_node *hn;
struct dm_hash_node *hn;
struct dev_layer *dl;
struct dl_list *dll;
hash_iterate(hn, dm->layers) {
dl = hash_get_data(dm->layers, hn);
dm_hash_iterate(hn, dm->layers) {
dl = dm_hash_get_data(dm->layers, hn);
if (_get_flag(dl, REMOVE))
_clear_flag(dl, ACTIVE);
if (!_get_flag(dl, ACTIVE)) {
dll = pool_alloc(dm->mem, sizeof(*dll));
dll = dm_pool_alloc(dm->mem, sizeof(*dll));
if (!dll) {
stack;
return 0;
@ -1664,19 +1661,19 @@ static int _fill_in_remove_list(struct dev_manager *dm)
static int _populate_pre_suspend_lists(struct dev_manager *dm)
{
struct hash_node *hn;
struct dm_hash_node *hn;
struct dev_layer *dl;
struct str_list *strl;
const char *dlid;
struct dev_layer *dep;
hash_iterate(hn, dm->layers) {
dl = hash_get_data(dm->layers, hn);
dm_hash_iterate(hn, dm->layers) {
dl = dm_hash_get_data(dm->layers, hn);
list_iterate_items(strl, &dl->pre_suspend) {
dlid = strl->str;
if (!(dep = hash_lookup(dm->layers, dlid))) {
if (!(dep = dm_hash_lookup(dm->layers, dlid))) {
log_debug("_populate_pre_suspend_lists: "
"Couldn't find device layer '%s' - "
"skipping.", dlid);
@ -1692,7 +1689,7 @@ static int _populate_pre_suspend_lists(struct dev_manager *dm)
list_iterate_items(strl, &dl->pre_create) {
dlid = strl->str;
if (!(dep = hash_lookup(dm->layers, dlid))) {
if (!(dep = dm_hash_lookup(dm->layers, dlid))) {
log_debug("_populate_pre_suspend_lists: "
"Couldn't find device layer '%s' - "
"skipping.", dlid);
@ -1753,7 +1750,7 @@ static int _remove_old_layers(struct dev_manager *dm)
*/
static int _execute(struct dev_manager *dm, struct volume_group *vg)
{
struct hash_node *hn;
struct dm_hash_node *hn;
struct dev_layer *dl;
if (!_build_all_layers(dm, vg)) {
@ -1801,8 +1798,8 @@ static int _execute(struct dev_manager *dm, struct volume_group *vg)
/*
* Now only top level devices will be unmarked.
*/
hash_iterate(hn, dm->layers) {
dl = hash_get_data(dm->layers, hn);
dm_hash_iterate(hn, dm->layers) {
dl = dm_hash_get_data(dm->layers, hn);
if (_get_flag(dl, ACTIVE) && _get_flag(dl, TOPLEVEL))
if (!_create_rec(dm, dl)) {
@ -1812,8 +1809,8 @@ static int _execute(struct dev_manager *dm, struct volume_group *vg)
}
/* Resume devices */
hash_iterate(hn, dm->layers) {
dl = hash_get_data(dm->layers, hn);
dm_hash_iterate(hn, dm->layers) {
dl = dm_hash_get_data(dm->layers, hn);
if (!_resume_with_deps(dm, dl)) {
stack;
@ -1857,7 +1854,7 @@ static int _add_existing_layer(struct dev_manager *dm, const char *name)
log_debug("Found existing layer '%s'", name);
if (!(copy = pool_strdup(dm->mem, name))) {
if (!(copy = dm_pool_strdup(dm->mem, name))) {
stack;
return 0;
}
@ -1907,12 +1904,12 @@ static int _scan_existing_devices(struct dev_manager *dm)
return r;
}
static int _add_lv(struct pool *mem,
static int _add_lv(struct dm_pool *mem,
struct list *head, struct logical_volume *lv)
{
struct lv_list *lvl;
if (!(lvl = pool_alloc(mem, sizeof(*lvl)))) {
if (!(lvl = dm_pool_alloc(mem, sizeof(*lvl)))) {
stack;
return 0;
}
@ -1923,7 +1920,7 @@ static int _add_lv(struct pool *mem,
return 1;
}
static int _add_lvs(struct pool *mem,
static int _add_lvs(struct dm_pool *mem,
struct list *head, struct logical_volume *origin)
{
struct lv_segment *snap_seg;
@ -2093,8 +2090,8 @@ static int _fill_in_active_list(struct dev_manager *dm, struct volume_group *vg)
return 0;
}
dl = hash_lookup(dm->layers, dlid);
pool_free(dm->mem, dlid);
dl = dm_hash_lookup(dm->layers, dlid);
dm_pool_free(dm->mem, dlid);
if (dl) {
log_debug("Found active lv %s%s", lvl->lv->name,
@ -2207,20 +2204,6 @@ int dev_manager_lv_rmnodes(const struct logical_volume *lv)
return fs_del_lv(lv);
}
int dev_manager_mknodes(void)
{
struct dm_task *dmt;
int r;
if (!(dmt = dm_task_create(DM_DEVICE_MKNODES)))
return 0;
r = dm_task_run(dmt);
dm_task_destroy(dmt);
return r;
}
void dev_manager_exit(void)
{
dm_lib_exit();

View File

@ -29,7 +29,6 @@
#include <unistd.h>
#include <limits.h>
#include <dirent.h>
#include <libdevmapper.h>
static int _mk_dir(const char *dev_dir, const char *vg_name)
{
@ -283,7 +282,7 @@ static int _stack_fs_op(fs_op_t type, const char *dev_dir, const char *vg_name,
strlen(dev) + strlen(old_lv_name) + 5;
char *pos;
if (!(fsp = dbg_malloc(sizeof(*fsp) + len))) {
if (!(fsp = dm_malloc(sizeof(*fsp) + len))) {
log_error("No space to stack fs operation");
return 0;
}
@ -312,7 +311,7 @@ static void _pop_fs_ops(void)
_do_fs_op(fsp->type, fsp->dev_dir, fsp->vg_name, fsp->lv_name,
fsp->dev, fsp->old_lv_name);
list_del(&fsp->list);
dbg_free(fsp);
dm_free(fsp);
}
}

99
lib/cache/lvmcache.c vendored
View File

@ -16,7 +16,6 @@
#include "lib.h"
#include "lvmcache.h"
#include "hash.h"
#include "toolcontext.h"
#include "dev-cache.h"
#include "metadata.h"
@ -24,10 +23,10 @@
#include "memlock.h"
#include "str_list.h"
static struct hash_table *_pvid_hash = NULL;
static struct hash_table *_vgid_hash = NULL;
static struct hash_table *_vgname_hash = NULL;
static struct hash_table *_lock_hash = NULL;
static struct dm_hash_table *_pvid_hash = NULL;
static struct dm_hash_table *_vgid_hash = NULL;
static struct dm_hash_table *_vgname_hash = NULL;
static struct dm_hash_table *_lock_hash = NULL;
static struct list _vginfos;
static int _has_scanned = 0;
static int _vgs_locked = 0;
@ -36,16 +35,16 @@ int lvmcache_init(void)
{
list_init(&_vginfos);
if (!(_vgname_hash = hash_create(128)))
if (!(_vgname_hash = dm_hash_create(128)))
return 0;
if (!(_vgid_hash = hash_create(128)))
if (!(_vgid_hash = dm_hash_create(128)))
return 0;
if (!(_pvid_hash = hash_create(128)))
if (!(_pvid_hash = dm_hash_create(128)))
return 0;
if (!(_lock_hash = hash_create(128)))
if (!(_lock_hash = dm_hash_create(128)))
return 0;
return 1;
@ -58,7 +57,7 @@ void lvmcache_lock_vgname(const char *vgname, int read_only)
return;
}
if (!hash_insert(_lock_hash, vgname, (void *) 1))
if (!dm_hash_insert(_lock_hash, vgname, (void *) 1))
log_error("Cache locking failure for %s", vgname);
_vgs_locked++;
@ -70,13 +69,13 @@ static int _vgname_is_locked(const char *vgname)
if (!_lock_hash)
return 0;
return hash_lookup(_lock_hash, vgname) ? 1 : 0;
return dm_hash_lookup(_lock_hash, vgname) ? 1 : 0;
}
void lvmcache_unlock_vgname(const char *vgname)
{
/* FIXME: Clear all CACHE_LOCKED flags in this vg */
hash_remove(_lock_hash, vgname);
dm_hash_remove(_lock_hash, vgname);
/* FIXME Do this per-VG */
if (!--_vgs_locked)
@ -95,7 +94,7 @@ struct lvmcache_vginfo *vginfo_from_vgname(const char *vgname)
if (!_vgname_hash)
return NULL;
if (!(vginfo = hash_lookup(_vgname_hash, vgname)))
if (!(vginfo = dm_hash_lookup(_vgname_hash, vgname)))
return NULL;
return vginfo;
@ -117,7 +116,7 @@ const struct format_type *fmt_from_vgname(const char *vgname)
* we check cached labels here. Unfortunately vginfo is volatile. */
list_init(&devs);
list_iterate_items(info, &vginfo->infos) {
devl = dbg_malloc(sizeof(*devl));
devl = dm_malloc(sizeof(*devl));
devl->dev = info->dev;
list_add(&devs, &devl->list);
}
@ -126,7 +125,7 @@ const struct format_type *fmt_from_vgname(const char *vgname)
devl = list_item(devh, struct device_list);
label_read(devl->dev, &label);
list_del(&devl->list);
dbg_free(devl);
dm_free(devl);
}
return vginfo->fmt;
@ -144,7 +143,7 @@ struct lvmcache_vginfo *vginfo_from_vgid(const char *vgid)
strncpy(&id[0], vgid, ID_LEN);
id[ID_LEN] = '\0';
if (!(vginfo = hash_lookup(_vgid_hash, id)))
if (!(vginfo = dm_hash_lookup(_vgid_hash, id)))
return NULL;
return vginfo;
@ -161,7 +160,7 @@ struct lvmcache_info *info_from_pvid(const char *pvid)
strncpy(&id[0], pvid, ID_LEN);
id[ID_LEN] = '\0';
if (!(info = hash_lookup(_pvid_hash, id)))
if (!(info = dm_hash_lookup(_pvid_hash, id)))
return NULL;
return info;
@ -177,7 +176,7 @@ static void _rescan_entry(struct lvmcache_info *info)
static int _scan_invalid(void)
{
hash_iter(_pvid_hash, (iterate_fn) _rescan_entry);
dm_hash_iter(_pvid_hash, (dm_hash_iterate_fn) _rescan_entry);
return 1;
}
@ -248,7 +247,7 @@ struct list *lvmcache_get_vgnames(struct cmd_context *cmd, int full_scan)
list_iterate_items(vgi, &_vginfos) {
if (!str_list_add(cmd->mem, vgnames,
pool_strdup(cmd->mem, vgi->vgname))) {
dm_pool_strdup(cmd->mem, vgi->vgname))) {
log_error("strlist allocation failed");
return NULL;
}
@ -307,13 +306,13 @@ static void _drop_vginfo(struct lvmcache_info *info)
}
if (info->vginfo && list_empty(&info->vginfo->infos)) {
hash_remove(_vgname_hash, info->vginfo->vgname);
dm_hash_remove(_vgname_hash, info->vginfo->vgname);
if (info->vginfo->vgname)
dbg_free(info->vginfo->vgname);
dm_free(info->vginfo->vgname);
if (*info->vginfo->vgid)
hash_remove(_vgid_hash, info->vginfo->vgid);
dm_hash_remove(_vgid_hash, info->vginfo->vgid);
list_del(&info->vginfo->list);
dbg_free(info->vginfo);
dm_free(info->vginfo);
}
info->vginfo = NULL;
@ -323,13 +322,13 @@ static void _drop_vginfo(struct lvmcache_info *info)
void lvmcache_del(struct lvmcache_info *info)
{
if (info->dev->pvid[0] && _pvid_hash)
hash_remove(_pvid_hash, info->dev->pvid);
dm_hash_remove(_pvid_hash, info->dev->pvid);
_drop_vginfo(info);
info->label->labeller->ops->destroy_label(info->label->labeller,
info->label);
dbg_free(info);
dm_free(info);
return;
} */
@ -339,10 +338,10 @@ static int _lvmcache_update_pvid(struct lvmcache_info *info, const char *pvid)
if (!strcmp(info->dev->pvid, pvid))
return 1;
if (*info->dev->pvid) {
hash_remove(_pvid_hash, info->dev->pvid);
dm_hash_remove(_pvid_hash, info->dev->pvid);
}
strncpy(info->dev->pvid, pvid, sizeof(info->dev->pvid));
if (!hash_insert(_pvid_hash, pvid, info)) {
if (!dm_hash_insert(_pvid_hash, pvid, info)) {
log_error("_lvmcache_update: pvid insertion failed: %s", pvid);
return 0;
}
@ -357,13 +356,13 @@ static int _lvmcache_update_vgid(struct lvmcache_info *info, const char *vgid)
return 1;
if (info->vginfo && *info->vginfo->vgid)
hash_remove(_vgid_hash, info->vginfo->vgid);
dm_hash_remove(_vgid_hash, info->vginfo->vgid);
if (!vgid)
return 1;
strncpy(info->vginfo->vgid, vgid, sizeof(info->vginfo->vgid));
info->vginfo->vgid[sizeof(info->vginfo->vgid) - 1] = '\0';
if (!hash_insert(_vgid_hash, info->vginfo->vgid, info->vginfo)) {
if (!dm_hash_insert(_vgid_hash, info->vginfo->vgid, info->vginfo)) {
log_error("_lvmcache_update: vgid hash insertion failed: %s",
info->vginfo->vgid);
return 0;
@ -391,22 +390,22 @@ int lvmcache_update_vgname(struct lvmcache_info *info, const char *vgname)
/* Get existing vginfo or create new one */
if (!(vginfo = vginfo_from_vgname(vgname))) {
if (!(vginfo = dbg_malloc(sizeof(*vginfo)))) {
if (!(vginfo = dm_malloc(sizeof(*vginfo)))) {
log_error("lvmcache_update_vgname: list alloc failed");
return 0;
}
memset(vginfo, 0, sizeof(*vginfo));
if (!(vginfo->vgname = dbg_strdup(vgname))) {
dbg_free(vginfo);
if (!(vginfo->vgname = dm_strdup(vgname))) {
dm_free(vginfo);
log_error("cache vgname alloc failed for %s", vgname);
return 0;
}
list_init(&vginfo->infos);
if (!hash_insert(_vgname_hash, vginfo->vgname, vginfo)) {
if (!dm_hash_insert(_vgname_hash, vginfo->vgname, vginfo)) {
log_error("cache_update: vg hash insertion failed: %s",
vginfo->vgname);
dbg_free(vginfo->vgname);
dbg_free(vginfo);
dm_free(vginfo->vgname);
dm_free(vginfo);
return 0;
}
/* Ensure orphans appear last on list_iterate */
@ -474,7 +473,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
stack;
return NULL;
}
if (!(info = dbg_malloc(sizeof(*info)))) {
if (!(info = dm_malloc(sizeof(*info)))) {
log_error("lvmcache_info allocation failed");
label_destroy(label);
return NULL;
@ -540,7 +539,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
if (!_lvmcache_update_pvid(info, pvid_s)) {
if (!existing) {
dbg_free(info);
dm_free(info);
label_destroy(label);
}
return NULL;
@ -548,9 +547,9 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
if (!lvmcache_update_vgname(info, vgname)) {
if (!existing) {
hash_remove(_pvid_hash, pvid_s);
dm_hash_remove(_pvid_hash, pvid_s);
strcpy(info->dev->pvid, "");
dbg_free(info);
dm_free(info);
label_destroy(label);
}
return NULL;
@ -569,14 +568,14 @@ static void _lvmcache_destroy_entry(struct lvmcache_info *info)
list_del(&info->list);
strcpy(info->dev->pvid, "");
label_destroy(info->label);
dbg_free(info);
dm_free(info);
}
static void _lvmcache_destroy_vgnamelist(struct lvmcache_vginfo *vginfo)
{
if (vginfo->vgname)
dbg_free(vginfo->vgname);
dbg_free(vginfo);
dm_free(vginfo->vgname);
dm_free(vginfo);
}
static void _lvmcache_destroy_lockname(int present)
@ -591,26 +590,26 @@ void lvmcache_destroy(void)
_has_scanned = 0;
if (_vgid_hash) {
hash_destroy(_vgid_hash);
dm_hash_destroy(_vgid_hash);
_vgid_hash = NULL;
}
if (_pvid_hash) {
hash_iter(_pvid_hash, (iterate_fn) _lvmcache_destroy_entry);
hash_destroy(_pvid_hash);
dm_hash_iter(_pvid_hash, (dm_hash_iterate_fn) _lvmcache_destroy_entry);
dm_hash_destroy(_pvid_hash);
_pvid_hash = NULL;
}
if (_vgname_hash) {
hash_iter(_vgname_hash,
(iterate_fn) _lvmcache_destroy_vgnamelist);
hash_destroy(_vgname_hash);
dm_hash_iter(_vgname_hash,
(dm_hash_iterate_fn) _lvmcache_destroy_vgnamelist);
dm_hash_destroy(_vgname_hash);
_vgname_hash = NULL;
}
if (_lock_hash) {
hash_iter(_lock_hash, (iterate_fn) _lvmcache_destroy_lockname);
hash_destroy(_lock_hash);
dm_hash_iter(_lock_hash, (dm_hash_iterate_fn) _lvmcache_destroy_lockname);
dm_hash_destroy(_lock_hash);
_lock_hash = NULL;
}

View File

@ -16,7 +16,6 @@
#include "lib.h"
#include "toolcontext.h"
#include "pool.h"
#include "metadata.h"
#include "defaults.h"
#include "lvm-string.h"
@ -213,7 +212,7 @@ static int _process_config(struct cmd_context *cmd)
static int _set_tag(struct cmd_context *cmd, const char *tag)
{
log_very_verbose("Setting host tag: %s", pool_strdup(cmd->libmem, tag));
log_very_verbose("Setting host tag: %s", dm_pool_strdup(cmd->libmem, tag));
if (!str_list_add(cmd->libmem, &cmd->tags, tag)) {
log_error("_set_tag: str_list_add %s failed", tag);
@ -323,7 +322,7 @@ static int _load_config_file(struct cmd_context *cmd, const char *tag)
return 0;
}
if (!(cfl = pool_alloc(cmd->libmem, sizeof(*cfl)))) {
if (!(cfl = dm_pool_alloc(cmd->libmem, sizeof(*cfl)))) {
log_error("config_tree_list allocation failed");
return 0;
}
@ -800,13 +799,13 @@ static int _init_hostname(struct cmd_context *cmd)
return 0;
}
if (!(cmd->hostname = pool_strdup(cmd->libmem, uts.nodename))) {
log_error("_init_hostname: pool_strdup failed");
if (!(cmd->hostname = dm_pool_strdup(cmd->libmem, uts.nodename))) {
log_error("_init_hostname: dm_pool_strdup failed");
return 0;
}
if (!(cmd->kernel_vsn = pool_strdup(cmd->libmem, uts.release))) {
log_error("_init_hostname: pool_strdup kernel_vsn failed");
if (!(cmd->kernel_vsn = dm_pool_strdup(cmd->libmem, uts.release))) {
log_error("_init_hostname: dm_pool_strdup kernel_vsn failed");
return 0;
}
@ -894,7 +893,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args)
init_syslog(DEFAULT_LOG_FACILITY);
if (!(cmd = dbg_malloc(sizeof(*cmd)))) {
if (!(cmd = dm_malloc(sizeof(*cmd)))) {
log_error("Failed to allocate command context");
return NULL;
}
@ -920,7 +919,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args)
goto error;
}
if (!(cmd->libmem = pool_create("library", 4 * 1024))) {
if (!(cmd->libmem = dm_pool_create("library", 4 * 1024))) {
log_error("Library memory pool creation failed");
return 0;
}
@ -951,7 +950,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args)
if (!_init_filters(cmd))
goto error;
if (!(cmd->mem = pool_create("command", 4 * 1024))) {
if (!(cmd->mem = dm_pool_create("command", 4 * 1024))) {
log_error("Command memory pool creation failed");
return 0;
}
@ -973,7 +972,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args)
return cmd;
error:
dbg_free(cmd);
dm_free(cmd);
return NULL;
}
@ -1085,15 +1084,15 @@ void destroy_toolcontext(struct cmd_context *cmd)
_destroy_segtypes(&cmd->segtypes);
_destroy_formats(&cmd->formats);
cmd->filter->destroy(cmd->filter);
pool_destroy(cmd->mem);
dm_pool_destroy(cmd->mem);
dev_cache_exit();
_destroy_tags(cmd);
_destroy_tag_configs(cmd);
pool_destroy(cmd->libmem);
dbg_free(cmd);
dm_pool_destroy(cmd->libmem);
dm_free(cmd);
release_log_memory();
dump_memory();
dm_dump_memory();
fin_log();
fin_syslog();

View File

@ -17,7 +17,6 @@
#define _LVM_TOOLCONTEXT_H
#include "dev-cache.h"
#include "pool.h"
#include <stdio.h>
#include <limits.h>
@ -50,8 +49,8 @@ struct backup_params;
/* FIXME Split into tool & library contexts */
/* command-instance-related variables needed by library */
struct cmd_context {
struct pool *libmem; /* For permanent config data */
struct pool *mem; /* Transient: Cleared between each command */
struct dm_pool *libmem; /* For permanent config data */
struct dm_pool *mem; /* Transient: Cleared between each command */
const struct format_type *fmt; /* Current format to use by default */
struct format_type *fmt_backup; /* Format to use for backups */

View File

@ -16,7 +16,6 @@
#include "lib.h"
#include "config.h"
#include "crc.h"
#include "pool.h"
#include "device.h"
#include "str_list.h"
#include "toolcontext.h"
@ -50,12 +49,12 @@ struct parser {
int fd; /* descriptor for file being parsed */
int line; /* line number we are on */
struct pool *mem;
struct dm_pool *mem;
};
struct cs {
struct config_tree cft;
struct pool *mem;
struct dm_pool *mem;
time_t timestamp;
char *filename;
int exists;
@ -99,16 +98,16 @@ static int _tok_match(const char *str, const char *b, const char *e)
struct config_tree *create_config_tree(const char *filename)
{
struct cs *c;
struct pool *mem = pool_create("config", 10 * 1024);
struct dm_pool *mem = dm_pool_create("config", 10 * 1024);
if (!mem) {
stack;
return 0;
}
if (!(c = pool_zalloc(mem, sizeof(*c)))) {
if (!(c = dm_pool_zalloc(mem, sizeof(*c)))) {
stack;
pool_destroy(mem);
dm_pool_destroy(mem);
return 0;
}
@ -117,13 +116,13 @@ struct config_tree *create_config_tree(const char *filename)
c->timestamp = 0;
c->exists = 0;
if (filename)
c->filename = pool_strdup(c->mem, filename);
c->filename = dm_pool_strdup(c->mem, filename);
return &c->cft;
}
void destroy_config_tree(struct config_tree *cft)
{
pool_destroy(((struct cs *) cft)->mem);
dm_pool_destroy(((struct cs *) cft)->mem);
}
int read_config_fd(struct config_tree *cft, struct device *dev,
@ -136,7 +135,7 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
int use_mmap = 1;
off_t mmap_offset = 0;
if (!(p = pool_alloc(c->mem, sizeof(*p)))) {
if (!(p = dm_pool_alloc(c->mem, sizeof(*p)))) {
stack;
return 0;
}
@ -157,7 +156,7 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
}
p->fb = p->fb + mmap_offset;
} else {
if (!(p->fb = dbg_malloc(size + size2))) {
if (!(p->fb = dm_malloc(size + size2))) {
stack;
return 0;
}
@ -197,7 +196,7 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
out:
if (!use_mmap)
dbg_free(p->fb);
dm_free(p->fb);
else {
/* unmap the file */
if (munmap((char *) (p->fb - mmap_offset), size + mmap_offset)) {
@ -688,14 +687,14 @@ static void _eat_space(struct parser *p)
*/
static struct config_value *_create_value(struct parser *p)
{
struct config_value *v = pool_alloc(p->mem, sizeof(*v));
struct config_value *v = dm_pool_alloc(p->mem, sizeof(*v));
memset(v, 0, sizeof(*v));
return v;
}
static struct config_node *_create_node(struct parser *p)
{
struct config_node *n = pool_alloc(p->mem, sizeof(*n));
struct config_node *n = dm_pool_alloc(p->mem, sizeof(*n));
memset(n, 0, sizeof(*n));
return n;
}
@ -703,7 +702,7 @@ static struct config_node *_create_node(struct parser *p)
static char *_dup_tok(struct parser *p)
{
size_t len = p->te - p->tb;
char *str = pool_alloc(p->mem, len + 1);
char *str = dm_pool_alloc(p->mem, len + 1);
if (!str) {
stack;
return 0;

View File

@ -16,6 +16,8 @@
#ifndef _LVM_CONFIG_H
#define _LVM_CONFIG_H
#include "lvm-types.h"
struct device;
struct cmd_context;

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lib.h"
#include "bitset.h"
/* FIXME: calculate this. */
#define INT_SHIFT 5
bitset_t bitset_create(struct pool *mem, unsigned num_bits)
{
unsigned n = (num_bits / BITS_PER_INT) + 2;
size_t size = sizeof(int) * n;
bitset_t bs;
if (mem)
bs = pool_zalloc(mem, size);
else
bs = dbg_malloc(size);
if (!bs)
return NULL;
*bs = num_bits;
if (!mem)
bit_clear_all(bs);
return bs;
}
void bitset_destroy(bitset_t bs)
{
dbg_free(bs);
}
void bit_union(bitset_t out, bitset_t in1, bitset_t in2)
{
int i;
for (i = (in1[0] / BITS_PER_INT) + 1; i; i--)
out[i] = in1[i] | in2[i];
}
/*
* FIXME: slow
*/
static inline int _test_word(uint32_t test, int bit)
{
while (bit < BITS_PER_INT) {
if (test & (0x1 << bit))
return bit;
bit++;
}
return -1;
}
int bit_get_next(bitset_t bs, int last_bit)
{
int bit, word;
uint32_t test;
last_bit++; /* otherwise we'll return the same bit again */
while (last_bit < bs[0]) {
word = last_bit >> INT_SHIFT;
test = bs[word + 1];
bit = last_bit & (BITS_PER_INT - 1);
if ((bit = _test_word(test, bit)) >= 0)
return (word * BITS_PER_INT) + bit;
last_bit = last_bit - (last_bit & (BITS_PER_INT - 1)) +
BITS_PER_INT;
}
return -1;
}
int bit_get_first(bitset_t bs)
{
return bit_get_next(bs, -1);
}

View File

@ -1,52 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LVM_BITSET_H
#define _LVM_BITSET_H
#include "pool.h"
#include <limits.h>
typedef uint32_t *bitset_t;
bitset_t bitset_create(struct pool *mem, unsigned num_bits);
void bitset_destroy(bitset_t bs);
void bit_union(bitset_t out, bitset_t in1, bitset_t in2);
int bit_get_first(bitset_t bs);
int bit_get_next(bitset_t bs, int last_bit);
#define BITS_PER_INT (sizeof(int) * CHAR_BIT)
#define bit(bs, i) \
(bs[(i / BITS_PER_INT) + 1] & (0x1 << (i & (BITS_PER_INT - 1))))
#define bit_set(bs, i) \
(bs[(i / BITS_PER_INT) + 1] |= (0x1 << (i & (BITS_PER_INT - 1))))
#define bit_clear(bs, i) \
(bs[(i / BITS_PER_INT) + 1] &= ~(0x1 << (i & (BITS_PER_INT - 1))))
#define bit_set_all(bs) \
memset(bs + 1, -1, ((*bs / BITS_PER_INT) + 1) * sizeof(int))
#define bit_clear_all(bs) \
memset(bs + 1, 0, ((*bs / BITS_PER_INT) + 1) * sizeof(int))
#define bit_copy(bs1, bs2) \
memcpy(bs1 + 1, bs2 + 1, ((*bs1 / BITS_PER_INT) + 1) * sizeof(int))
#endif

View File

@ -24,13 +24,13 @@ struct node {
};
struct btree {
struct pool *mem;
struct dm_pool *mem;
struct node *root;
};
struct btree *btree_create(struct pool *mem)
struct btree *btree_create(struct dm_pool *mem)
{
struct btree *t = pool_alloc(mem, sizeof(*t));
struct btree *t = dm_pool_alloc(mem, sizeof(*t));
if (t) {
t->mem = mem;
@ -86,7 +86,7 @@ int btree_insert(struct btree *t, uint32_t k, void *data)
struct node *p, **c = _lookup(&t->root, key, &p), *n;
if (!*c) {
if (!(n = pool_alloc(t->mem, sizeof(*n)))) {
if (!(n = dm_pool_alloc(t->mem, sizeof(*n)))) {
stack;
return 0;
}

View File

@ -16,11 +16,9 @@
#ifndef _LVM_BTREE_H
#define _LVM_BTREE_H
#include "pool.h"
struct btree;
struct btree *btree_create(struct pool *mem);
struct btree *btree_create(struct dm_pool *mem);
void *btree_lookup(struct btree *t, uint32_t k);
int btree_insert(struct btree *t, uint32_t k, void *data);

View File

@ -1,262 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lib.h"
#include "hash.h"
struct hash_node {
struct hash_node *next;
void *data;
int keylen;
char key[0];
};
struct hash_table {
int num_nodes;
int num_slots;
struct hash_node **slots;
};
/* Permutation of the Integers 0 through 255 */
static unsigned char _nums[] = {
1, 14, 110, 25, 97, 174, 132, 119, 138, 170, 125, 118, 27, 233, 140, 51,
87, 197, 177, 107, 234, 169, 56, 68, 30, 7, 173, 73, 188, 40, 36, 65,
49, 213, 104, 190, 57, 211, 148, 223, 48, 115, 15, 2, 67, 186, 210, 28,
12, 181, 103, 70, 22, 58, 75, 78, 183, 167, 238, 157, 124, 147, 172,
144,
176, 161, 141, 86, 60, 66, 128, 83, 156, 241, 79, 46, 168, 198, 41, 254,
178, 85, 253, 237, 250, 154, 133, 88, 35, 206, 95, 116, 252, 192, 54,
221,
102, 218, 255, 240, 82, 106, 158, 201, 61, 3, 89, 9, 42, 155, 159, 93,
166, 80, 50, 34, 175, 195, 100, 99, 26, 150, 16, 145, 4, 33, 8, 189,
121, 64, 77, 72, 208, 245, 130, 122, 143, 55, 105, 134, 29, 164, 185,
194,
193, 239, 101, 242, 5, 171, 126, 11, 74, 59, 137, 228, 108, 191, 232,
139,
6, 24, 81, 20, 127, 17, 91, 92, 251, 151, 225, 207, 21, 98, 113, 112,
84, 226, 18, 214, 199, 187, 13, 32, 94, 220, 224, 212, 247, 204, 196,
43,
249, 236, 45, 244, 111, 182, 153, 136, 129, 90, 217, 202, 19, 165, 231,
71,
230, 142, 96, 227, 62, 179, 246, 114, 162, 53, 160, 215, 205, 180, 47,
109,
44, 38, 31, 149, 135, 0, 216, 52, 63, 23, 37, 69, 39, 117, 146, 184,
163, 200, 222, 235, 248, 243, 219, 10, 152, 131, 123, 229, 203, 76, 120,
209
};
static struct hash_node *_create_node(const char *str, int len)
{
struct hash_node *n = dbg_malloc(sizeof(*n) + len);
if (n) {
memcpy(n->key, str, len);
n->keylen = len;
}
return n;
}
static unsigned _hash(const char *str, uint32_t len)
{
unsigned long h = 0, g, i;
for (i = 0; i < len; i++) {
h <<= 4;
h += _nums[(int) *str++];
g = h & ((unsigned long) 0xf << 16u);
if (g) {
h ^= g >> 16u;
h ^= g >> 5u;
}
}
return h;
}
struct hash_table *hash_create(unsigned size_hint)
{
size_t len;
unsigned new_size = 16u;
struct hash_table *hc = dbg_malloc(sizeof(*hc));
if (!hc) {
stack;
return 0;
}
memset(hc, 0, sizeof(*hc));
/* round size hint up to a power of two */
while (new_size < size_hint)
new_size = new_size << 1;
hc->num_slots = new_size;
len = sizeof(*(hc->slots)) * new_size;
if (!(hc->slots = dbg_malloc(len))) {
stack;
goto bad;
}
memset(hc->slots, 0, len);
return hc;
bad:
dbg_free(hc->slots);
dbg_free(hc);
return 0;
}
static void _free_nodes(struct hash_table *t)
{
struct hash_node *c, *n;
int i;
for (i = 0; i < t->num_slots; i++)
for (c = t->slots[i]; c; c = n) {
n = c->next;
dbg_free(c);
}
}
void hash_destroy(struct hash_table *t)
{
_free_nodes(t);
dbg_free(t->slots);
dbg_free(t);
}
static inline struct hash_node **_find(struct hash_table *t, const char *key,
uint32_t len)
{
unsigned h = _hash(key, len) & (t->num_slots - 1);
struct hash_node **c;
for (c = &t->slots[h]; *c; c = &((*c)->next))
if (!memcmp(key, (*c)->key, len))
break;
return c;
}
void *hash_lookup_binary(struct hash_table *t, const char *key,
uint32_t len)
{
struct hash_node **c = _find(t, key, len);
return *c ? (*c)->data : 0;
}
int hash_insert_binary(struct hash_table *t, const char *key,
uint32_t len, void *data)
{
struct hash_node **c = _find(t, key, len);
if (*c)
(*c)->data = data;
else {
struct hash_node *n = _create_node(key, len);
if (!n)
return 0;
n->data = data;
n->next = 0;
*c = n;
t->num_nodes++;
}
return 1;
}
void hash_remove_binary(struct hash_table *t, const char *key,
uint32_t len)
{
struct hash_node **c = _find(t, key, len);
if (*c) {
struct hash_node *old = *c;
*c = (*c)->next;
dbg_free(old);
t->num_nodes--;
}
}
void *hash_lookup(struct hash_table *t, const char *key)
{
return hash_lookup_binary(t, key, strlen(key) + 1);
}
int hash_insert(struct hash_table *t, const char *key, void *data)
{
return hash_insert_binary(t, key, strlen(key) + 1, data);
}
void hash_remove(struct hash_table *t, const char *key)
{
hash_remove_binary(t, key, strlen(key) + 1);
}
unsigned hash_get_num_entries(struct hash_table *t)
{
return t->num_nodes;
}
void hash_iter(struct hash_table *t, iterate_fn f)
{
struct hash_node *c;
int i;
for (i = 0; i < t->num_slots; i++)
for (c = t->slots[i]; c; c = c->next)
f(c->data);
}
void hash_wipe(struct hash_table *t)
{
_free_nodes(t);
memset(t->slots, 0, sizeof(struct hash_node *) * t->num_slots);
t->num_nodes = 0;
}
char *hash_get_key(struct hash_table *t, struct hash_node *n)
{
return n->key;
}
void *hash_get_data(struct hash_table *t, struct hash_node *n)
{
return n->data;
}
static struct hash_node *_next_slot(struct hash_table *t, unsigned s)
{
struct hash_node *c = NULL;
int i;
for (i = s; i < t->num_slots && !c; i++)
c = t->slots[i];
return c;
}
struct hash_node *hash_get_first(struct hash_table *t)
{
return _next_slot(t, 0);
}
struct hash_node *hash_get_next(struct hash_table *t, struct hash_node *n)
{
unsigned h = _hash(n->key, n->keylen) & (t->num_slots - 1);
return n->next ? n->next : _next_slot(t, h + 1);
}

View File

@ -1,49 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LVM_HASH_H
#define _LVM_HASH_H
struct hash_table;
struct hash_node;
typedef void (*iterate_fn) (void *data);
struct hash_table *hash_create(unsigned size_hint);
void hash_destroy(struct hash_table *t);
void hash_wipe(struct hash_table *t);
void *hash_lookup(struct hash_table *t, const char *key);
int hash_insert(struct hash_table *t, const char *key, void *data);
void hash_remove(struct hash_table *t, const char *key);
void *hash_lookup_binary(struct hash_table *t, const char *key, uint32_t len);
int hash_insert_binary(struct hash_table *t, const char *key, uint32_t len,
void *data);
void hash_remove_binary(struct hash_table *t, const char *key, uint32_t len);
unsigned hash_get_num_entries(struct hash_table *t);
void hash_iter(struct hash_table *t, iterate_fn f);
char *hash_get_key(struct hash_table *t, struct hash_node *n);
void *hash_get_data(struct hash_table *t, struct hash_node *n);
struct hash_node *hash_get_first(struct hash_table *t);
struct hash_node *hash_get_next(struct hash_table *t, struct hash_node *n);
#define hash_iterate(v, h) \
for (v = hash_get_first(h); v; \
v = hash_get_next(h, v))
#endif

View File

@ -202,6 +202,26 @@ static inline struct list *list_next(struct list *head, struct list *elem)
*/
#define list_iterate_items(v, head) list_iterate_items_gen(v, (head), list)
/*
* Walk a list, setting 'v' in turn to the containing structure of each item.
* The containing structure should be the same type as 'v'.
* The 'struct list' variable within the containing structure is 'field'.
* t must be defined as a temporary variable of the same type as v.
*/
#define list_iterate_items_gen_safe(v, t, head, field) \
for (v = list_struct_base((head)->n, typeof(*v), field), \
t = list_struct_base(v->field.n, typeof(*v), field); \
&v->field != (head); \
v = t, t = list_struct_base(v->field.n, typeof(*v), field))
/*
* Walk a list, setting 'v' in turn to the containing structure of each item.
* The containing structure should be the same type as 'v'.
* The list should be 'struct list list' within the containing structure.
* t must be defined as a temporary variable of the same type as v.
*/
#define list_iterate_items_safe(v, t, head) \
list_iterate_items_gen_safe(v, t, (head), list)
/*
* Walk a list backwards, setting 'v' in turn to the containing structure
* of each item.

View File

@ -16,11 +16,11 @@
#include "lib.h"
#include "str_list.h"
struct list *str_list_create(struct pool *mem)
struct list *str_list_create(struct dm_pool *mem)
{
struct list *sl;
if (!(sl = pool_alloc(mem, sizeof(struct list)))) {
if (!(sl = dm_pool_alloc(mem, sizeof(struct list)))) {
stack;
return NULL;
}
@ -30,7 +30,7 @@ struct list *str_list_create(struct pool *mem)
return sl;
}
int str_list_add(struct pool *mem, struct list *sll, const char *str)
int str_list_add(struct dm_pool *mem, struct list *sll, const char *str)
{
struct str_list *sln;
@ -43,7 +43,7 @@ int str_list_add(struct pool *mem, struct list *sll, const char *str)
if (str_list_match_item(sll, str))
return 1;
if (!(sln = pool_alloc(mem, sizeof(*sln)))) {
if (!(sln = dm_pool_alloc(mem, sizeof(*sln)))) {
stack;
return 0;
}
@ -66,7 +66,7 @@ int str_list_del(struct list *sll, const char *str)
return 1;
}
int str_list_dup(struct pool *mem, struct list *sllnew, struct list *sllold)
int str_list_dup(struct dm_pool *mem, struct list *sllnew, struct list *sllold)
{
struct str_list *sl;

View File

@ -16,14 +16,12 @@
#ifndef _LVM_STR_LIST_H
#define _LVM_STR_LIST_H
#include "pool.h"
struct list *str_list_create(struct pool *mem);
int str_list_add(struct pool *mem, struct list *sll, const char *str);
struct list *str_list_create(struct dm_pool *mem);
int str_list_add(struct dm_pool *mem, struct list *sll, const char *str);
int str_list_del(struct list *sll, const char *str);
int str_list_match_item(struct list *sll, const char *str);
int str_list_match_list(struct list *sll, struct list *sll2);
int str_list_lists_equal(struct list *sll, struct list *sll2);
int str_list_dup(struct pool *mem, struct list *sllnew, struct list *sllold);
int str_list_dup(struct dm_pool *mem, struct list *sllnew, struct list *sllold);
#endif

View File

@ -15,9 +15,6 @@
#include "lib.h"
#include "dev-cache.h"
#include "pool.h"
#include "hash.h"
#include "list.h"
#include "lvm-types.h"
#include "btree.h"
#include "filter.h"
@ -38,8 +35,8 @@ struct dir_list {
};
static struct {
struct pool *mem;
struct hash_table *names;
struct dm_pool *mem;
struct dm_hash_table *names;
struct btree *devices;
int has_scanned;
@ -48,9 +45,9 @@ static struct {
} _cache;
#define _alloc(x) pool_zalloc(_cache.mem, (x))
#define _free(x) pool_free(_cache.mem, (x))
#define _strdup(x) pool_strdup(_cache.mem, (x))
#define _alloc(x) dm_pool_zalloc(_cache.mem, (x))
#define _free(x) dm_pool_free(_cache.mem, (x))
#define _strdup(x) dm_pool_strdup(_cache.mem, (x))
static int _insert(const char *path, int rec);
@ -61,19 +58,19 @@ struct device *dev_create_file(const char *filename, struct device *dev,
if (allocate) {
if (use_malloc) {
if (!(dev = dbg_malloc(sizeof(*dev)))) {
if (!(dev = dm_malloc(sizeof(*dev)))) {
log_error("struct device allocation failed");
return NULL;
}
if (!(alias = dbg_malloc(sizeof(*alias)))) {
if (!(alias = dm_malloc(sizeof(*alias)))) {
log_error("struct str_list allocation failed");
dbg_free(dev);
dm_free(dev);
return NULL;
}
if (!(alias->str = dbg_strdup(filename))) {
if (!(alias->str = dm_strdup(filename))) {
log_error("filename strdup failed");
dbg_free(dev);
dbg_free(alias);
dm_free(dev);
dm_free(alias);
return NULL;
}
dev->flags = DEV_ALLOCED;
@ -92,7 +89,7 @@ struct device *dev_create_file(const char *filename, struct device *dev,
return NULL;
}
}
} else if (!(alias->str = dbg_strdup(filename))) {
} else if (!(alias->str = dm_strdup(filename))) {
log_error("filename strdup failed");
return NULL;
}
@ -213,7 +210,7 @@ static int _add_alias(struct device *dev, const char *path)
}
}
if (!(sl->str = pool_strdup(_cache.mem, path))) {
if (!(sl->str = dm_pool_strdup(_cache.mem, path))) {
stack;
return 0;
}
@ -247,7 +244,7 @@ static int _insert_dev(const char *path, dev_t d)
/* Generate pretend device numbers for loopfiles */
if (!d) {
if (hash_lookup(_cache.names, path))
if (dm_hash_lookup(_cache.names, path))
return 1;
d = ++loopfile_count;
loopfile = 1;
@ -279,7 +276,7 @@ static int _insert_dev(const char *path, dev_t d)
return 0;
}
if (!hash_insert(_cache.names, path, dev)) {
if (!dm_hash_insert(_cache.names, path, dev)) {
log_err("Couldn't add name to hash in dev cache.");
return 0;
}
@ -290,7 +287,7 @@ static int _insert_dev(const char *path, dev_t d)
static char *_join(const char *dir, const char *name)
{
size_t len = strlen(dir) + strlen(name) + 2;
char *r = dbg_malloc(len);
char *r = dm_malloc(len);
if (r)
snprintf(r, len, "%s/%s", dir, name);
@ -340,7 +337,7 @@ static int _insert_dir(const char *dir)
_collapse_slashes(path);
r &= _insert(path, 1);
dbg_free(path);
dm_free(path);
free(dirent[n]);
}
@ -449,14 +446,14 @@ int dev_cache_init(void)
_cache.names = NULL;
_cache.has_scanned = 0;
if (!(_cache.mem = pool_create("dev_cache", 10 * 1024))) {
if (!(_cache.mem = dm_pool_create("dev_cache", 10 * 1024))) {
stack;
return 0;
}
if (!(_cache.names = hash_create(128))) {
if (!(_cache.names = dm_hash_create(128))) {
stack;
pool_destroy(_cache.mem);
dm_pool_destroy(_cache.mem);
_cache.mem = 0;
return 0;
}
@ -484,7 +481,7 @@ static void _check_closed(struct device *dev)
static inline void _check_for_open_devices(void)
{
hash_iter(_cache.names, (iterate_fn) _check_closed);
dm_hash_iter(_cache.names, (dm_hash_iterate_fn) _check_closed);
}
void dev_cache_exit(void)
@ -493,12 +490,12 @@ void dev_cache_exit(void)
_check_for_open_devices();
if (_cache.mem) {
pool_destroy(_cache.mem);
dm_pool_destroy(_cache.mem);
_cache.mem = NULL;
}
if (_cache.names) {
hash_destroy(_cache.names);
dm_hash_destroy(_cache.names);
_cache.names = NULL;
}
@ -592,7 +589,7 @@ const char *dev_name_confirmed(struct device *dev, int quiet)
(int) MINOR(dev->dev));
/* Remove the incorrect hash entry */
hash_remove(_cache.names, name);
dm_hash_remove(_cache.names, name);
/* Leave list alone if there isn't an alternative name */
/* so dev_name will always find something to return. */
@ -615,23 +612,23 @@ const char *dev_name_confirmed(struct device *dev, int quiet)
struct device *dev_cache_get(const char *name, struct dev_filter *f)
{
struct stat buf;
struct device *d = (struct device *) hash_lookup(_cache.names, name);
struct device *d = (struct device *) dm_hash_lookup(_cache.names, name);
if (d && (d->flags & DEV_REGULAR))
return d;
/* If the entry's wrong, remove it */
if (d && (stat(name, &buf) || (buf.st_rdev != d->dev))) {
hash_remove(_cache.names, name);
dm_hash_remove(_cache.names, name);
d = NULL;
}
if (!d) {
_insert(name, 0);
d = (struct device *) hash_lookup(_cache.names, name);
d = (struct device *) dm_hash_lookup(_cache.names, name);
if (!d) {
_full_scan(0);
d = (struct device *) hash_lookup(_cache.names, name);
d = (struct device *) dm_hash_lookup(_cache.names, name);
}
}
@ -641,7 +638,7 @@ struct device *dev_cache_get(const char *name, struct dev_filter *f)
struct dev_iter *dev_iter_create(struct dev_filter *f, int dev_scan)
{
struct dev_iter *di = dbg_malloc(sizeof(*di));
struct dev_iter *di = dm_malloc(sizeof(*di));
if (!di) {
log_error("dev_iter allocation failed");
@ -664,7 +661,7 @@ struct dev_iter *dev_iter_create(struct dev_filter *f, int dev_scan)
void dev_iter_destroy(struct dev_iter *iter)
{
dbg_free(iter);
dm_free(iter);
}
static inline struct device *_iter_next(struct dev_iter *iter)

View File

@ -16,7 +16,6 @@
#ifndef _LVM_DEV_CACHE_H
#define _LVM_DEV_CACHE_H
#include "lvm-types.h"
#include "device.h"
/*

View File

@ -484,10 +484,10 @@ static void _close(struct device *dev)
log_debug("Closed %s", dev_name(dev));
if (dev->flags & DEV_ALLOCED) {
dbg_free((void *) list_item(dev->aliases.n, struct str_list)->
dm_free((void *) list_item(dev->aliases.n, struct str_list)->
str);
dbg_free(dev->aliases.n);
dbg_free(dev);
dm_free(dev->aliases.n);
dm_free(dev);
}
}
@ -508,7 +508,8 @@ static int _dev_close(struct device *dev, int immediate)
dev->open_count--;
if (immediate && dev->open_count) {
log_debug("%s: Immediate close attempt while still referenced");
log_debug("%s: Immediate close attempt while still referenced",
dev_name(dev));
dev->open_count = 0;
}

View File

@ -202,7 +202,7 @@ int _get_partition_type(struct dev_mgr *dm, struct device *d)
return 0;
}
if (!(buffer = dbg_malloc(SECTOR_SIZE))) {
if (!(buffer = dm_malloc(SECTOR_SIZE))) {
log_error("Failed to allocate partition table buffer");
return 0;
}

View File

@ -17,11 +17,12 @@
#define _LVM_DEVICE_H
#include "uuid.h"
#include <fcntl.h>
#define DEV_ACCESSED_W 0x00000001 /* Device written to? */
#define DEV_REGULAR 0x00000002 /* Regular file? */
#define DEV_ALLOCED 0x00000004 /* dbg_malloc used */
#define DEV_ALLOCED 0x00000004 /* dm_malloc used */
#define DEV_OPENED_RW 0x00000008 /* Opened RW */
#define DEV_OPENED_EXCL 0x00000010 /* Opened EXCL */
#define DEV_O_DIRECT 0x00000020 /* Use O_DIRECT */

View File

@ -151,7 +151,7 @@ const char *display_size(struct cmd_context *cmd, uint64_t size, size_len_t sl)
{" ", " ", " "},
};
if (!(size_buf = pool_alloc(cmd->mem, SIZE_BUF))) {
if (!(size_buf = dm_pool_alloc(cmd->mem, SIZE_BUF))) {
log_error("no memory for size display buffer");
return "";
}

View File

@ -13,8 +13,6 @@
*/
#include "lib.h"
#include "pool.h"
#include "list.h"
#include "toolcontext.h"
#include "segtype.h"
#include "display.h"
@ -40,7 +38,7 @@ static int _merge_segments(struct lv_segment *seg1, struct lv_segment *seg2)
}
#ifdef DEVMAPPER_SUPPORT
static int _compose_target_line(struct dev_manager *dm, struct pool *mem,
static int _compose_target_line(struct dev_manager *dm, struct dm_pool *mem,
struct config_tree *cft, void **target_state,
struct lv_segment *seg, char *params,
size_t paramsize, const char **target, int *pos,
@ -69,7 +67,7 @@ static int _target_present(void)
static void _destroy(const struct segment_type *segtype)
{
dbg_free((void *) segtype);
dm_free((void *) segtype);
}
static struct segtype_handler _error_ops = {
@ -84,7 +82,7 @@ static struct segtype_handler _error_ops = {
struct segment_type *init_error_segtype(struct cmd_context *cmd)
{
struct segment_type *segtype = dbg_malloc(sizeof(*segtype));
struct segment_type *segtype = dm_malloc(sizeof(*segtype));
if (!segtype) {
stack;

View File

@ -42,8 +42,8 @@ static void _destroy(struct dev_filter *f)
filters++;
}
dbg_free(f->private);
dbg_free(f);
dm_free(f->private);
dm_free(f);
}
struct dev_filter *composite_filter_create(int n, struct dev_filter **filters)
@ -55,7 +55,7 @@ struct dev_filter *composite_filter_create(int n, struct dev_filter **filters)
return NULL;
}
if (!(filters_copy = dbg_malloc(sizeof(*filters) * (n + 1)))) {
if (!(filters_copy = dm_malloc(sizeof(*filters) * (n + 1)))) {
log_error("composite filters allocation failed");
return NULL;
}
@ -63,9 +63,9 @@ struct dev_filter *composite_filter_create(int n, struct dev_filter **filters)
memcpy(filters_copy, filters, sizeof(*filters) * n);
filters_copy[n] = NULL;
if (!(cft = dbg_malloc(sizeof(*cft)))) {
if (!(cft = dm_malloc(sizeof(*cft)))) {
log_error("compsoite filters allocation failed");
dbg_free(filters_copy);
dm_free(filters_copy);
return NULL;
}

View File

@ -51,14 +51,14 @@ static int _ignore_md(struct dev_filter *f, struct device *dev)
static void _destroy(struct dev_filter *f)
{
dbg_free(f);
dm_free(f);
}
struct dev_filter *md_filter_create(void)
{
struct dev_filter *f;
if (!(f = dbg_malloc(sizeof(*f)))) {
if (!(f = dm_malloc(sizeof(*f)))) {
log_error("md filter allocation failed");
return NULL;
}

View File

@ -16,7 +16,6 @@
#include "lib.h"
#include "config.h"
#include "dev-cache.h"
#include "hash.h"
#include "filter-persistent.h"
#include <sys/stat.h>
@ -25,7 +24,7 @@
struct pfilter {
char *file;
struct hash_table *devices;
struct dm_hash_table *devices;
struct dev_filter *real;
};
@ -39,9 +38,9 @@ struct pfilter {
static int _init_hash(struct pfilter *pf)
{
if (pf->devices)
hash_destroy(pf->devices);
dm_hash_destroy(pf->devices);
if (!(pf->devices = hash_create(128))) {
if (!(pf->devices = dm_hash_create(128))) {
stack;
return 0;
}
@ -54,7 +53,7 @@ int persistent_filter_wipe(struct dev_filter *f)
struct pfilter *pf = (struct pfilter *) f->private;
log_verbose("Wiping cache of LVM-capable devices");
hash_wipe(pf->devices);
dm_hash_wipe(pf->devices);
/* Trigger complete device scan */
dev_cache_scan(1);
@ -85,7 +84,7 @@ static int _read_array(struct pfilter *pf, struct config_tree *cft,
continue;
}
if (!hash_insert(pf->devices, cv->v.str, data))
if (!dm_hash_insert(pf->devices, cv->v.str, data))
log_verbose("Couldn't add '%s' to filter ... ignoring",
cv->v.str);
/* Populate dev_cache ourselves */
@ -118,7 +117,7 @@ int persistent_filter_load(struct dev_filter *f)
PF_BAD_DEVICE); */
/* Did we find anything? */
if (hash_get_num_entries(pf->devices)) {
if (dm_hash_get_num_entries(pf->devices)) {
/* We populated dev_cache ourselves */
dev_cache_scan(0);
r = 1;
@ -136,11 +135,11 @@ static void _write_array(struct pfilter *pf, FILE *fp, const char *path,
{
void *d;
int first = 1;
struct hash_node *n;
struct dm_hash_node *n;
for (n = hash_get_first(pf->devices); n;
n = hash_get_next(pf->devices, n)) {
d = hash_get_data(pf->devices, n);
for (n = dm_hash_get_first(pf->devices); n;
n = dm_hash_get_next(pf->devices, n)) {
d = dm_hash_get_data(pf->devices, n);
if (d != data)
continue;
@ -152,7 +151,7 @@ static void _write_array(struct pfilter *pf, FILE *fp, const char *path,
first = 0;
}
fprintf(fp, "\t\t\"%s\"", hash_get_key(pf->devices, n));
fprintf(fp, "\t\t\"%s\"", dm_hash_get_key(pf->devices, n));
}
if (!first)
@ -167,7 +166,7 @@ int persistent_filter_dump(struct dev_filter *f)
FILE *fp;
if (!hash_get_num_entries(pf->devices)) {
if (!dm_hash_get_num_entries(pf->devices)) {
log_very_verbose("Internal persistent device cache empty "
"- not writing to %s", pf->file);
return 0;
@ -202,7 +201,7 @@ int persistent_filter_dump(struct dev_filter *f)
static int _lookup_p(struct dev_filter *f, struct device *dev)
{
struct pfilter *pf = (struct pfilter *) f->private;
void *l = hash_lookup(pf->devices, dev_name(dev));
void *l = dm_hash_lookup(pf->devices, dev_name(dev));
struct str_list *sl;
if (!l) {
@ -210,7 +209,7 @@ static int _lookup_p(struct dev_filter *f, struct device *dev)
PF_GOOD_DEVICE : PF_BAD_DEVICE;
list_iterate_items(sl, &dev->aliases)
hash_insert(pf->devices, sl->str, l);
dm_hash_insert(pf->devices, sl->str, l);
} else if (l == PF_BAD_DEVICE)
log_debug("%s: Skipping (cached)", dev_name(dev));
@ -222,11 +221,11 @@ static void _destroy(struct dev_filter *f)
{
struct pfilter *pf = (struct pfilter *) f->private;
hash_destroy(pf->devices);
dbg_free(pf->file);
dm_hash_destroy(pf->devices);
dm_free(pf->file);
pf->real->destroy(pf->real);
dbg_free(pf);
dbg_free(f);
dm_free(pf);
dm_free(f);
}
struct dev_filter *persistent_filter_create(struct dev_filter *real,
@ -235,13 +234,13 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,
struct pfilter *pf;
struct dev_filter *f = NULL;
if (!(pf = dbg_malloc(sizeof(*pf)))) {
if (!(pf = dm_malloc(sizeof(*pf)))) {
stack;
return NULL;
}
memset(pf, 0, sizeof(*pf));
if (!(pf->file = dbg_malloc(strlen(file) + 1))) {
if (!(pf->file = dm_malloc(strlen(file) + 1))) {
stack;
goto bad;
}
@ -253,7 +252,7 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,
goto bad;
}
if (!(f = dbg_malloc(sizeof(*f)))) {
if (!(f = dm_malloc(sizeof(*f)))) {
stack;
goto bad;
}
@ -265,10 +264,10 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,
return f;
bad:
dbg_free(pf->file);
dm_free(pf->file);
if (pf->devices)
hash_destroy(pf->devices);
dbg_free(pf);
dbg_free(f);
dm_hash_destroy(pf->devices);
dm_free(pf);
dm_free(f);
return NULL;
}

View File

@ -14,21 +14,18 @@
*/
#include "lib.h"
#include "pool.h"
#include "filter-regex.h"
#include "matcher.h"
#include "device.h"
#include "bitset.h"
#include "list.h"
struct rfilter {
struct pool *mem;
bitset_t accept;
struct dm_pool *mem;
dm_bitset_t accept;
struct matcher *engine;
};
static int _extract_pattern(struct pool *mem, const char *pat,
char **regex, bitset_t accept, int ix)
static int _extract_pattern(struct dm_pool *mem, const char *pat,
char **regex, dm_bitset_t accept, int ix)
{
char sep, *r, *ptr;
@ -37,11 +34,11 @@ static int _extract_pattern(struct pool *mem, const char *pat,
*/
switch (*pat) {
case 'a':
bit_set(accept, ix);
dm_bit_set(accept, ix);
break;
case 'r':
bit_clear(accept, ix);
dm_bit_clear(accept, ix);
break;
default:
@ -74,7 +71,7 @@ static int _extract_pattern(struct pool *mem, const char *pat,
/*
* copy the regex
*/
if (!(r = pool_strdup(mem, pat))) {
if (!(r = dm_pool_strdup(mem, pat))) {
stack;
return 0;
}
@ -95,13 +92,13 @@ static int _extract_pattern(struct pool *mem, const char *pat,
static int _build_matcher(struct rfilter *rf, struct config_value *val)
{
struct pool *scratch;
struct dm_pool *scratch;
struct config_value *v;
char **regex;
unsigned count = 0;
int i, r = 0;
if (!(scratch = pool_create("filter matcher", 1024))) {
if (!(scratch = dm_pool_create("filter matcher", 1024))) {
stack;
return 0;
}
@ -122,7 +119,7 @@ static int _build_matcher(struct rfilter *rf, struct config_value *val)
/*
* allocate space for them
*/
if (!(regex = pool_alloc(scratch, sizeof(*regex) * count))) {
if (!(regex = dm_pool_alloc(scratch, sizeof(*regex) * count))) {
stack;
goto out;
}
@ -130,7 +127,7 @@ static int _build_matcher(struct rfilter *rf, struct config_value *val)
/*
* create the accept/reject bitset
*/
rf->accept = bitset_create(rf->mem, count);
rf->accept = dm_bitset_create(rf->mem, count);
/*
* fill the array back to front because we
@ -152,7 +149,7 @@ static int _build_matcher(struct rfilter *rf, struct config_value *val)
r = 1;
out:
pool_destroy(scratch);
dm_pool_destroy(scratch);
return r;
}
@ -166,7 +163,7 @@ static int _accept_p(struct dev_filter *f, struct device *dev)
m = matcher_run(rf->engine, sl->str);
if (m >= 0) {
if (bit(rf->accept, m)) {
if (dm_bit(rf->accept, m)) {
if (!first) {
log_debug("%s: New preferred name",
@ -197,12 +194,12 @@ static int _accept_p(struct dev_filter *f, struct device *dev)
static void _destroy(struct dev_filter *f)
{
struct rfilter *rf = (struct rfilter *) f->private;
pool_destroy(rf->mem);
dm_pool_destroy(rf->mem);
}
struct dev_filter *regex_filter_create(struct config_value *patterns)
{
struct pool *mem = pool_create("filter regex", 10 * 1024);
struct dm_pool *mem = dm_pool_create("filter regex", 10 * 1024);
struct rfilter *rf;
struct dev_filter *f;
@ -211,7 +208,7 @@ struct dev_filter *regex_filter_create(struct config_value *patterns)
return NULL;
}
if (!(rf = pool_alloc(mem, sizeof(*rf)))) {
if (!(rf = dm_pool_alloc(mem, sizeof(*rf)))) {
stack;
goto bad;
}
@ -223,7 +220,7 @@ struct dev_filter *regex_filter_create(struct config_value *patterns)
goto bad;
}
if (!(f = pool_zalloc(mem, sizeof(*f)))) {
if (!(f = dm_pool_zalloc(mem, sizeof(*f)))) {
stack;
goto bad;
}
@ -234,6 +231,6 @@ struct dev_filter *regex_filter_create(struct config_value *patterns)
return f;
bad:
pool_destroy(mem);
dm_pool_destroy(mem);
return NULL;
}

View File

@ -15,7 +15,6 @@
#include "lib.h"
#include "filter-sysfs.h"
#include "lvm-string.h"
#include "pool.h"
#ifdef linux
@ -69,21 +68,21 @@ struct entry {
#define SET_BUCKETS 64
struct dev_set {
struct pool *mem;
struct dm_pool *mem;
const char *sys_block;
int initialised;
struct entry *slots[SET_BUCKETS];
};
static struct dev_set *_dev_set_create(struct pool *mem, const char *sys_block)
static struct dev_set *_dev_set_create(struct dm_pool *mem, const char *sys_block)
{
struct dev_set *ds;
if (!(ds = pool_zalloc(mem, sizeof(*ds))))
if (!(ds = dm_pool_zalloc(mem, sizeof(*ds))))
return NULL;
ds->mem = mem;
ds->sys_block = pool_strdup(mem, sys_block);
ds->sys_block = dm_pool_strdup(mem, sys_block);
ds->initialised = 0;
return ds;
@ -102,7 +101,7 @@ static int _set_insert(struct dev_set *ds, dev_t dev)
struct entry *e;
unsigned h = _hash_dev(dev);
if (!(e = pool_alloc(ds->mem, sizeof(*e))))
if (!(e = dm_pool_alloc(ds->mem, sizeof(*e))))
return 0;
e->next = ds->slots[h];
@ -258,20 +257,20 @@ static int _accept_p(struct dev_filter *f, struct device *dev)
static void _destroy(struct dev_filter *f)
{
struct dev_set *ds = (struct dev_set *) f->private;
pool_destroy(ds->mem);
dm_pool_destroy(ds->mem);
}
struct dev_filter *sysfs_filter_create(const char *proc)
{
char sys_block[PATH_MAX];
struct pool *mem;
struct dm_pool *mem;
struct dev_set *ds;
struct dev_filter *f;
if (!_locate_sysfs_blocks(proc, sys_block, sizeof(sys_block)))
return NULL;
if (!(mem = pool_create("sysfs", 256))) {
if (!(mem = dm_pool_create("sysfs", 256))) {
log_error("sysfs pool creation failed");
return NULL;
}
@ -281,7 +280,7 @@ struct dev_filter *sysfs_filter_create(const char *proc)
goto bad;
}
if (!(f = pool_zalloc(mem, sizeof(*f)))) {
if (!(f = dm_pool_zalloc(mem, sizeof(*f)))) {
stack;
goto bad;
}
@ -292,7 +291,7 @@ struct dev_filter *sysfs_filter_create(const char *proc)
return f;
bad:
pool_destroy(mem);
dm_pool_destroy(mem);
return NULL;
}

View File

@ -19,7 +19,6 @@
#include "lvm-string.h"
#include "config.h"
#include "metadata.h"
#include "bitset.h"
#include <dirent.h>
#include <unistd.h>
@ -39,7 +38,7 @@ typedef struct {
} device_info_t;
static int _md_major = -1;
static bitset_t _dm_bitset;
static dm_bitset_t _dm_bitset;
int md_major(void)
{
@ -48,7 +47,7 @@ int md_major(void)
int is_dm_major(int major)
{
return bit(_dm_bitset, major) ? 1 : 0;
return dm_bit(_dm_bitset, major) ? 1 : 0;
}
/*
@ -191,7 +190,7 @@ static int _scan_proc_dev(const char *proc, const struct config_node *cn)
/* Look for dm devices */
if (!strncmp("device-mapper", line + i, 13) &&
isspace(*(line + i + 13)))
bit_set(_dm_bitset, line_maj);
dm_bit_set(_dm_bitset, line_maj);
/* Go through the valid device names and if there is a
match store max number of partitions */
@ -254,7 +253,7 @@ struct dev_filter *lvm_type_filter_create(const char *proc,
{
struct dev_filter *f;
if (!(f = dbg_malloc(sizeof(struct dev_filter)))) {
if (!(f = dm_malloc(sizeof(struct dev_filter)))) {
log_error("LVM type filter allocation failed");
return NULL;
}
@ -263,9 +262,9 @@ struct dev_filter *lvm_type_filter_create(const char *proc,
f->destroy = lvm_type_filter_destroy;
f->private = NULL;
if (!(_dm_bitset = bitset_create(NULL, NUMBER_OF_MAJORS))) {
if (!(_dm_bitset = dm_bitset_create(NULL, NUMBER_OF_MAJORS))) {
stack;
dbg_free(f);
dm_free(f);
return NULL;
}
@ -279,7 +278,7 @@ struct dev_filter *lvm_type_filter_create(const char *proc,
void lvm_type_filter_destroy(struct dev_filter *f)
{
bitset_destroy(_dm_bitset);
dbg_free(f);
dm_bitset_destroy(_dm_bitset);
dm_free(f);
return;
}

View File

@ -15,7 +15,6 @@
#include "lib.h"
#include "disk-rep.h"
#include "pool.h"
#include "xlate.h"
#include "filter.h"
#include "lvmcache.h"
@ -255,7 +254,7 @@ static int _read_uuids(struct disk_list *data)
if (!dev_read(data->dev, pos, sizeof(buffer), buffer))
fail;
if (!(ul = pool_alloc(data->mem, sizeof(*ul))))
if (!(ul = dm_pool_alloc(data->mem, sizeof(*ul))))
fail;
memcpy(ul->uuid, buffer, NAME_LEN);
@ -284,7 +283,7 @@ static int _read_lvs(struct disk_list *data)
for (i = 0; (i < vgd->lv_max) && (read < vgd->lv_cur); i++) {
pos = data->pvd.lv_on_disk.base + (i * sizeof(struct lv_disk));
ll = pool_alloc(data->mem, sizeof(*ll));
ll = dm_pool_alloc(data->mem, sizeof(*ll));
if (!ll)
fail;
@ -305,7 +304,7 @@ static int _read_lvs(struct disk_list *data)
static int _read_extents(struct disk_list *data)
{
size_t len = sizeof(struct pe_disk) * data->pvd.pe_total;
struct pe_disk *extents = pool_alloc(data->mem, len);
struct pe_disk *extents = dm_pool_alloc(data->mem, len);
uint64_t pos = data->pvd.pe_on_disk.base;
if (!extents)
@ -321,10 +320,10 @@ static int _read_extents(struct disk_list *data)
}
static struct disk_list *__read_disk(const struct format_type *fmt,
struct device *dev, struct pool *mem,
struct device *dev, struct dm_pool *mem,
const char *vg_name)
{
struct disk_list *dl = pool_alloc(mem, sizeof(*dl));
struct disk_list *dl = dm_pool_alloc(mem, sizeof(*dl));
const char *name = dev_name(dev);
struct lvmcache_info *info;
@ -400,12 +399,12 @@ static struct disk_list *__read_disk(const struct format_type *fmt,
return dl;
bad:
pool_free(dl->mem, dl);
dm_pool_free(dl->mem, dl);
return NULL;
}
struct disk_list *read_disk(const struct format_type *fmt, struct device *dev,
struct pool *mem, const char *vg_name)
struct dm_pool *mem, const char *vg_name)
{
struct disk_list *r;
@ -452,7 +451,7 @@ static void _add_pv_to_list(struct list *head, struct disk_list *data)
* so we can free off all the memory if something goes wrong.
*/
int read_pvs_in_vg(const struct format_type *fmt, const char *vg_name,
struct dev_filter *filter, struct pool *mem,
struct dev_filter *filter, struct dm_pool *mem,
struct list *head)
{
struct dev_iter *iter;
@ -531,8 +530,8 @@ static int _write_uuids(struct disk_list *data)
return 0;
}
log_debug("Writing %s uuidlist to %s at %" PRIu64 " len %"
PRIsize_t, data->pvd.vg_name, dev_name(data->dev),
log_debug("Writing %s uuidlist to %s at %" PRIu64 " len %d",
data->pvd.vg_name, dev_name(data->dev),
pos, NAME_LEN);
if (!dev_write(data->dev, pos, NAME_LEN, ul->uuid))
@ -619,7 +618,7 @@ static int _write_pvd(struct disk_list *data)
/* Make sure that the gap between the PV structure and
the next one is zeroed in order to make non LVM tools
happy (idea from AED) */
buf = dbg_malloc(size);
buf = dm_malloc(size);
if (!buf) {
log_err("Couldn't allocate temporary PV buffer.");
return 0;
@ -634,11 +633,11 @@ static int _write_pvd(struct disk_list *data)
_xlate_pvd((struct pv_disk *) buf);
if (!dev_write(data->dev, pos, size, buf)) {
dbg_free(buf);
dm_free(buf);
fail;
}
dbg_free(buf);
dm_free(buf);
return 1;
}

View File

@ -18,7 +18,6 @@
#include "lvm-types.h"
#include "metadata.h"
#include "pool.h"
#include "toolcontext.h"
#define MAX_PV 256
@ -159,7 +158,7 @@ struct lvd_list {
struct disk_list {
struct list list;
struct pool *mem;
struct dm_pool *mem;
struct device *dev;
struct pv_disk pvd;
@ -191,11 +190,11 @@ int calculate_extent_count(struct physical_volume *pv, uint32_t extent_size,
*/
struct disk_list *read_disk(const struct format_type *fmt, struct device *dev,
struct pool *mem, const char *vg_name);
struct dm_pool *mem, const char *vg_name);
int read_pvs_in_vg(const struct format_type *fmt, const char *vg_name,
struct dev_filter *filter,
struct pool *mem, struct list *results);
struct dm_pool *mem, struct list *results);
int write_disks(const struct format_type *fmt, struct list *pvds);
@ -203,33 +202,33 @@ int write_disks(const struct format_type *fmt, struct list *pvds);
* Functions to translate to between disk and in
* core structures.
*/
int import_pv(struct pool *mem, struct device *dev,
int import_pv(struct dm_pool *mem, struct device *dev,
struct volume_group *vg,
struct physical_volume *pv, struct pv_disk *pvd);
int export_pv(struct cmd_context *cmd, struct pool *mem,
int export_pv(struct cmd_context *cmd, struct dm_pool *mem,
struct volume_group *vg,
struct pv_disk *pvd, struct physical_volume *pv);
int import_vg(struct pool *mem,
int import_vg(struct dm_pool *mem,
struct volume_group *vg, struct disk_list *dl, int partial);
int export_vg(struct vg_disk *vgd, struct volume_group *vg);
int import_lv(struct pool *mem, struct logical_volume *lv, struct lv_disk *lvd);
int import_lv(struct dm_pool *mem, struct logical_volume *lv, struct lv_disk *lvd);
int import_extents(struct cmd_context *cmd, struct volume_group *vg,
struct list *pvds);
int export_extents(struct disk_list *dl, uint32_t lv_num,
struct logical_volume *lv, struct physical_volume *pv);
int import_pvs(const struct format_type *fmt, struct pool *mem,
int import_pvs(const struct format_type *fmt, struct dm_pool *mem,
struct volume_group *vg,
struct list *pvds, struct list *results, int *count);
int import_lvs(struct pool *mem, struct volume_group *vg, struct list *pvds);
int import_lvs(struct dm_pool *mem, struct volume_group *vg, struct list *pvds);
int export_lvs(struct disk_list *dl, struct volume_group *vg,
struct physical_volume *pv, const char *dev_dir);
int import_snapshots(struct pool *mem, struct volume_group *vg,
int import_snapshots(struct dm_pool *mem, struct volume_group *vg,
struct list *pvds);
int export_uuids(struct disk_list *dl, struct volume_group *vg);

View File

@ -15,10 +15,7 @@
#include "lib.h"
#include "disk-rep.h"
#include "pool.h"
#include "hash.h"
#include "limits.h"
#include "list.h"
#include "display.h"
#include "toolcontext.h"
#include "lvmcache.h"
@ -128,8 +125,8 @@ static int _check_vgs(struct list *pvs, int *partial)
static struct volume_group *_build_vg(struct format_instance *fid,
struct list *pvs)
{
struct pool *mem = fid->fmt->cmd->mem;
struct volume_group *vg = pool_alloc(mem, sizeof(*vg));
struct dm_pool *mem = fid->fmt->cmd->mem;
struct volume_group *vg = dm_pool_alloc(mem, sizeof(*vg));
struct disk_list *dl;
int partial;
@ -172,7 +169,7 @@ static struct volume_group *_build_vg(struct format_instance *fid,
bad:
stack;
pool_free(mem, vg);
dm_pool_free(mem, vg);
return NULL;
}
@ -180,7 +177,7 @@ static struct volume_group *_vg_read(struct format_instance *fid,
const char *vg_name,
struct metadata_area *mda)
{
struct pool *mem = pool_create("lvm1 vg_read", 1024 * 10);
struct dm_pool *mem = dm_pool_create("lvm1 vg_read", 1024 * 10);
struct list pvs;
struct volume_group *vg = NULL;
list_init(&pvs);
@ -205,16 +202,16 @@ static struct volume_group *_vg_read(struct format_instance *fid,
}
bad:
pool_destroy(mem);
dm_pool_destroy(mem);
return vg;
}
static struct disk_list *_flatten_pv(struct format_instance *fid,
struct pool *mem, struct volume_group *vg,
struct dm_pool *mem, struct volume_group *vg,
struct physical_volume *pv,
const char *dev_dir)
{
struct disk_list *dl = pool_alloc(mem, sizeof(*dl));
struct disk_list *dl = dm_pool_alloc(mem, sizeof(*dl));
if (!dl) {
stack;
@ -232,14 +229,14 @@ static struct disk_list *_flatten_pv(struct format_instance *fid,
!export_uuids(dl, vg) ||
!export_lvs(dl, vg, pv, dev_dir) || !calculate_layout(dl)) {
stack;
pool_free(mem, dl);
dm_pool_free(mem, dl);
return NULL;
}
return dl;
}
static int _flatten_vg(struct format_instance *fid, struct pool *mem,
static int _flatten_vg(struct format_instance *fid, struct dm_pool *mem,
struct volume_group *vg,
struct list *pvds, const char *dev_dir,
struct dev_filter *filter)
@ -270,7 +267,7 @@ static int _flatten_vg(struct format_instance *fid, struct pool *mem,
static int _vg_write(struct format_instance *fid, struct volume_group *vg,
struct metadata_area *mda)
{
struct pool *mem = pool_create("lvm1 vg_write", 1024 * 10);
struct dm_pool *mem = dm_pool_create("lvm1 vg_write", 1024 * 10);
struct list pvds;
int r = 0;
@ -286,14 +283,14 @@ static int _vg_write(struct format_instance *fid, struct volume_group *vg,
write_disks(fid->fmt, &pvds));
lvmcache_update_vg(vg);
pool_destroy(mem);
dm_pool_destroy(mem);
return r;
}
static int _pv_read(const struct format_type *fmt, const char *pv_name,
struct physical_volume *pv, struct list *mdas)
{
struct pool *mem = pool_create("lvm1 pv_read", 1024);
struct dm_pool *mem = dm_pool_create("lvm1 pv_read", 1024);
struct disk_list *dl;
struct device *dev;
int r = 0;
@ -325,7 +322,7 @@ static int _pv_read(const struct format_type *fmt, const char *pv_name,
r = 1;
out:
pool_destroy(mem);
dm_pool_destroy(mem);
return r;
}
@ -392,7 +389,7 @@ static int _lv_setup(struct format_instance *fid, struct logical_volume *lv)
static int _pv_write(const struct format_type *fmt, struct physical_volume *pv,
struct list *mdas, int64_t sector)
{
struct pool *mem;
struct dm_pool *mem;
struct disk_list *dl;
struct list pvs;
struct label *label;
@ -415,12 +412,12 @@ static int _pv_write(const struct format_type *fmt, struct physical_volume *pv,
pv->pe_size = pv->pe_count = 0;
pv->pe_start = PE_ALIGN;
if (!(mem = pool_create("lvm1 pv_write", 1024))) {
if (!(mem = dm_pool_create("lvm1 pv_write", 1024))) {
stack;
return 0;
}
if (!(dl = pool_alloc(mem, sizeof(*dl)))) {
if (!(dl = dm_pool_alloc(mem, sizeof(*dl)))) {
stack;
goto bad;
}
@ -444,11 +441,11 @@ static int _pv_write(const struct format_type *fmt, struct physical_volume *pv,
goto bad;
}
pool_destroy(mem);
dm_pool_destroy(mem);
return 1;
bad:
pool_destroy(mem);
dm_pool_destroy(mem);
return 0;
}
@ -510,7 +507,7 @@ static struct format_instance *_create_instance(const struct format_type *fmt,
struct format_instance *fid;
struct metadata_area *mda;
if (!(fid = pool_alloc(fmt->cmd->mem, sizeof(*fid)))) {
if (!(fid = dm_pool_alloc(fmt->cmd->mem, sizeof(*fid)))) {
stack;
return NULL;
}
@ -519,9 +516,9 @@ static struct format_instance *_create_instance(const struct format_type *fmt,
list_init(&fid->metadata_areas);
/* Define a NULL metadata area */
if (!(mda = pool_alloc(fmt->cmd->mem, sizeof(*mda)))) {
if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda)))) {
stack;
pool_free(fmt->cmd->mem, fid);
dm_pool_free(fmt->cmd->mem, fid);
return NULL;
}
@ -539,7 +536,7 @@ static void _destroy_instance(struct format_instance *fid)
static void _destroy(const struct format_type *fmt)
{
dbg_free((void *) fmt);
dm_free((void *) fmt);
}
static struct format_handler _format1_ops = {
@ -561,7 +558,7 @@ struct format_type *init_format(struct cmd_context *cmd);
struct format_type *init_format(struct cmd_context *cmd)
#endif
{
struct format_type *fmt = dbg_malloc(sizeof(*fmt));
struct format_type *fmt = dm_malloc(sizeof(*fmt));
if (!fmt) {
stack;

View File

@ -19,9 +19,6 @@
#include "lib.h"
#include "disk-rep.h"
#include "pool.h"
#include "hash.h"
#include "list.h"
#include "lvm-string.h"
#include "filter.h"
#include "toolcontext.h"
@ -38,7 +35,7 @@ static int _check_vg_name(const char *name)
/*
* Extracts the last part of a path.
*/
static char *_create_lv_name(struct pool *mem, const char *full_name)
static char *_create_lv_name(struct dm_pool *mem, const char *full_name)
{
const char *ptr = strrchr(full_name, '/');
@ -47,10 +44,10 @@ static char *_create_lv_name(struct pool *mem, const char *full_name)
else
ptr++;
return pool_strdup(mem, ptr);
return dm_pool_strdup(mem, ptr);
}
int import_pv(struct pool *mem, struct device *dev,
int import_pv(struct dm_pool *mem, struct device *dev,
struct volume_group *vg,
struct physical_volume *pv, struct pv_disk *pvd)
{
@ -58,7 +55,7 @@ int import_pv(struct pool *mem, struct device *dev,
memcpy(&pv->id, pvd->pv_uuid, ID_LEN);
pv->dev = dev;
if (!(pv->vg_name = pool_strdup(mem, pvd->vg_name))) {
if (!(pv->vg_name = dm_pool_strdup(mem, pvd->vg_name))) {
stack;
return 0;
}
@ -112,7 +109,7 @@ static int _system_id(struct cmd_context *cmd, char *s, const char *prefix)
return 1;
}
int export_pv(struct cmd_context *cmd, struct pool *mem,
int export_pv(struct cmd_context *cmd, struct dm_pool *mem,
struct volume_group *vg,
struct pv_disk *pvd, struct physical_volume *pv)
{
@ -198,7 +195,7 @@ int export_pv(struct cmd_context *cmd, struct pool *mem,
return 1;
}
int import_vg(struct pool *mem,
int import_vg(struct dm_pool *mem,
struct volume_group *vg, struct disk_list *dl, int partial)
{
struct vg_disk *vgd = &dl->vgd;
@ -209,12 +206,12 @@ int import_vg(struct pool *mem,
return 0;
}
if (!(vg->name = pool_strdup(mem, dl->pvd.vg_name))) {
if (!(vg->name = dm_pool_strdup(mem, dl->pvd.vg_name))) {
stack;
return 0;
}
if (!(vg->system_id = pool_alloc(mem, NAME_LEN))) {
if (!(vg->system_id = dm_pool_alloc(mem, NAME_LEN))) {
stack;
return 0;
}
@ -288,7 +285,7 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg)
return 1;
}
int import_lv(struct pool *mem, struct logical_volume *lv, struct lv_disk *lvd)
int import_lv(struct dm_pool *mem, struct logical_volume *lv, struct lv_disk *lvd)
{
lvid_from_lvnum(&lv->lvid, &lv->vg->id, lvd->lv_number);
@ -414,7 +411,7 @@ int export_extents(struct disk_list *dl, uint32_t lv_num,
return 1;
}
int import_pvs(const struct format_type *fmt, struct pool *mem,
int import_pvs(const struct format_type *fmt, struct dm_pool *mem,
struct volume_group *vg,
struct list *pvds, struct list *results, int *count)
{
@ -423,8 +420,8 @@ int import_pvs(const struct format_type *fmt, struct pool *mem,
*count = 0;
list_iterate_items(dl, pvds) {
if (!(pvl = pool_zalloc(mem, sizeof(*pvl))) ||
!(pvl->pv = pool_alloc(mem, sizeof(*pvl->pv)))) {
if (!(pvl = dm_pool_zalloc(mem, sizeof(*pvl))) ||
!(pvl->pv = dm_pool_alloc(mem, sizeof(*pvl->pv)))) {
stack;
return 0;
}
@ -442,15 +439,15 @@ int import_pvs(const struct format_type *fmt, struct pool *mem,
return 1;
}
static struct logical_volume *_add_lv(struct pool *mem,
static struct logical_volume *_add_lv(struct dm_pool *mem,
struct volume_group *vg,
struct lv_disk *lvd)
{
struct lv_list *ll;
struct logical_volume *lv;
if (!(ll = pool_zalloc(mem, sizeof(*ll))) ||
!(ll->lv = pool_zalloc(mem, sizeof(*ll->lv)))) {
if (!(ll = dm_pool_zalloc(mem, sizeof(*ll))) ||
!(ll->lv = dm_pool_zalloc(mem, sizeof(*ll->lv)))) {
stack;
return NULL;
}
@ -468,7 +465,7 @@ static struct logical_volume *_add_lv(struct pool *mem,
return lv;
}
int import_lvs(struct pool *mem, struct volume_group *vg, struct list *pvds)
int import_lvs(struct dm_pool *mem, struct volume_group *vg, struct list *pvds)
{
struct disk_list *dl;
struct lvd_list *ll;
@ -498,14 +495,14 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
struct lvd_list *lvdl;
size_t len;
uint32_t lv_num;
struct hash_table *lvd_hash;
struct dm_hash_table *lvd_hash;
if (!_check_vg_name(vg->name)) {
stack;
return 0;
}
if (!(lvd_hash = hash_create(32))) {
if (!(lvd_hash = dm_hash_create(32))) {
stack;
return 0;
}
@ -514,7 +511,7 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
* setup the pv's extents array
*/
len = sizeof(struct pe_disk) * dl->pvd.pe_total;
if (!(dl->extents = pool_alloc(dl->mem, len))) {
if (!(dl->extents = dm_pool_alloc(dl->mem, len))) {
stack;
goto out;
}
@ -524,7 +521,7 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
if (ll->lv->status & SNAPSHOT)
continue;
if (!(lvdl = pool_alloc(dl->mem, sizeof(*lvdl)))) {
if (!(lvdl = dm_pool_alloc(dl->mem, sizeof(*lvdl)))) {
stack;
goto out;
}
@ -534,7 +531,7 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
lv_num = lvnum_from_lvid(&ll->lv->lvid);
lvdl->lvd.lv_number = lv_num;
if (!hash_insert(lvd_hash, ll->lv->name, &lvdl->lvd)) {
if (!dm_hash_insert(lvd_hash, ll->lv->name, &lvdl->lvd)) {
stack;
goto out;
}
@ -561,14 +558,14 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
r = 1;
out:
hash_destroy(lvd_hash);
dm_hash_destroy(lvd_hash);
return r;
}
/*
* FIXME: More inefficient code.
*/
int import_snapshots(struct pool *mem, struct volume_group *vg,
int import_snapshots(struct dm_pool *mem, struct volume_group *vg,
struct list *pvds)
{
struct logical_volume *lvs[MAX_LV];
@ -642,7 +639,7 @@ int export_uuids(struct disk_list *dl, struct volume_group *vg)
struct pv_list *pvl;
list_iterate_items(pvl, &vg->pvs) {
if (!(ul = pool_alloc(dl->mem, sizeof(*ul)))) {
if (!(ul = dm_pool_alloc(dl->mem, sizeof(*ul)))) {
stack;
return 0;
}

View File

@ -15,8 +15,6 @@
#include "lib.h"
#include "metadata.h"
#include "hash.h"
#include "pool.h"
#include "disk-rep.h"
#include "lv_alloc.h"
#include "display.h"
@ -44,10 +42,10 @@ struct lv_map {
struct pe_specifier *map;
};
static struct hash_table *_create_lv_maps(struct pool *mem,
static struct dm_hash_table *_create_lv_maps(struct dm_pool *mem,
struct volume_group *vg)
{
struct hash_table *maps = hash_create(32);
struct dm_hash_table *maps = dm_hash_create(32);
struct lv_list *ll;
struct lv_map *lvm;
@ -61,19 +59,19 @@ static struct hash_table *_create_lv_maps(struct pool *mem,
if (ll->lv->status & SNAPSHOT)
continue;
if (!(lvm = pool_alloc(mem, sizeof(*lvm)))) {
if (!(lvm = dm_pool_alloc(mem, sizeof(*lvm)))) {
stack;
goto bad;
}
lvm->lv = ll->lv;
if (!(lvm->map = pool_zalloc(mem, sizeof(*lvm->map)
if (!(lvm->map = dm_pool_zalloc(mem, sizeof(*lvm->map)
* ll->lv->le_count))) {
stack;
goto bad;
}
if (!hash_insert(maps, ll->lv->name, lvm)) {
if (!dm_hash_insert(maps, ll->lv->name, lvm)) {
stack;
goto bad;
}
@ -82,12 +80,12 @@ static struct hash_table *_create_lv_maps(struct pool *mem,
return maps;
bad:
hash_destroy(maps);
dm_hash_destroy(maps);
return NULL;
}
static int _fill_lv_array(struct lv_map **lvs,
struct hash_table *maps, struct disk_list *dl)
struct dm_hash_table *maps, struct disk_list *dl)
{
struct lvd_list *ll;
struct lv_map *lvm;
@ -95,7 +93,7 @@ static int _fill_lv_array(struct lv_map **lvs,
memset(lvs, 0, sizeof(*lvs) * MAX_LV);
list_iterate_items(ll, &dl->lvds) {
if (!(lvm = hash_lookup(maps, strrchr(ll->lvd.lv_name, '/')
if (!(lvm = dm_hash_lookup(maps, strrchr(ll->lvd.lv_name, '/')
+ 1))) {
log_err("Physical volume (%s) contains an "
"unknown logical volume (%s).",
@ -112,7 +110,7 @@ static int _fill_lv_array(struct lv_map **lvs,
return 1;
}
static int _fill_maps(struct hash_table *maps, struct volume_group *vg,
static int _fill_maps(struct dm_hash_table *maps, struct volume_group *vg,
struct list *pvds)
{
struct disk_list *dl;
@ -184,13 +182,13 @@ static int _check_single_map(struct lv_map *lvm)
return 1;
}
static int _check_maps_are_complete(struct hash_table *maps)
static int _check_maps_are_complete(struct dm_hash_table *maps)
{
struct hash_node *n;
struct dm_hash_node *n;
struct lv_map *lvm;
for (n = hash_get_first(maps); n; n = hash_get_next(maps, n)) {
lvm = (struct lv_map *) hash_get_data(maps, n);
for (n = dm_hash_get_first(maps); n; n = dm_hash_get_next(maps, n)) {
lvm = (struct lv_map *) dm_hash_get_data(maps, n);
if (!_check_single_map(lvm)) {
stack;
@ -327,13 +325,13 @@ static int _build_segments(struct cmd_context *cmd, struct lv_map *lvm)
_read_linear(cmd, lvm));
}
static int _build_all_segments(struct cmd_context *cmd, struct hash_table *maps)
static int _build_all_segments(struct cmd_context *cmd, struct dm_hash_table *maps)
{
struct hash_node *n;
struct dm_hash_node *n;
struct lv_map *lvm;
for (n = hash_get_first(maps); n; n = hash_get_next(maps, n)) {
lvm = (struct lv_map *) hash_get_data(maps, n);
for (n = dm_hash_get_first(maps); n; n = dm_hash_get_next(maps, n)) {
lvm = (struct lv_map *) dm_hash_get_data(maps, n);
if (!_build_segments(cmd, lvm)) {
stack;
return 0;
@ -347,8 +345,8 @@ int import_extents(struct cmd_context *cmd, struct volume_group *vg,
struct list *pvds)
{
int r = 0;
struct pool *scratch = pool_create("lvm1 import_extents", 10 * 1024);
struct hash_table *maps;
struct dm_pool *scratch = dm_pool_create("lvm1 import_extents", 10 * 1024);
struct dm_hash_table *maps;
if (!scratch) {
stack;
@ -378,7 +376,7 @@ int import_extents(struct cmd_context *cmd, struct volume_group *vg,
out:
if (maps)
hash_destroy(maps);
pool_destroy(scratch);
dm_hash_destroy(maps);
dm_pool_destroy(scratch);
return r;
}

View File

@ -117,7 +117,7 @@ int calculate_layout(struct disk_list *dl)
int calculate_extent_count(struct physical_volume *pv, uint32_t extent_size,
uint32_t max_extent_count, uint64_t pe_start)
{
struct pv_disk *pvd = dbg_malloc(sizeof(*pvd));
struct pv_disk *pvd = dm_malloc(sizeof(*pvd));
uint32_t end;
if (!pvd) {
@ -138,7 +138,7 @@ int calculate_extent_count(struct physical_volume *pv, uint32_t extent_size,
if (pvd->pe_total < PE_SIZE_PV_SIZE_REL) {
log_error("Too few extents on %s. Try smaller extent size.",
dev_name(pv->dev));
dbg_free(pvd);
dm_free(pvd);
return 0;
}
@ -160,13 +160,13 @@ int calculate_extent_count(struct physical_volume *pv, uint32_t extent_size,
log_error("Metadata extent limit (%u) exceeded for %s - "
"%u required", MAX_PE_TOTAL, dev_name(pv->dev),
pvd->pe_total);
dbg_free(pvd);
dm_free(pvd);
return 0;
}
pv->pe_count = pvd->pe_total;
pv->pe_start = pvd->pe_start;
/* We can't set pe_size here without breaking LVM1 compatibility */
dbg_free(pvd);
dm_free(pvd);
return 1;
}

View File

@ -90,7 +90,7 @@ static void _destroy_label(struct labeller *l, struct label *label)
static void _destroy(struct labeller *l)
{
dbg_free(l);
dm_free(l);
}
struct label_ops _lvm1_ops = {
@ -107,7 +107,7 @@ struct labeller *lvm1_labeller_create(struct format_type *fmt)
{
struct labeller *l;
if (!(l = dbg_malloc(sizeof(*l)))) {
if (!(l = dm_malloc(sizeof(*l)))) {
log_err("Couldn't allocate labeller object.");
return NULL;
}

View File

@ -14,7 +14,6 @@
*/
#include "lib.h"
#include "pool.h"
#include "disk-rep.h"
/*
@ -29,7 +28,7 @@ int get_free_vg_number(struct format_instance *fid, struct dev_filter *filter,
{
struct list all_pvs;
struct disk_list *dl;
struct pool *mem = pool_create("lvm1 vg_number", 10 * 1024);
struct dm_pool *mem = dm_pool_create("lvm1 vg_number", 10 * 1024);
int numbers[MAX_VG], i, r = 0;
list_init(&all_pvs);
@ -62,6 +61,6 @@ int get_free_vg_number(struct format_instance *fid, struct dev_filter *filter,
}
out:
pool_destroy(mem);
dm_pool_destroy(mem);
return r;
}

View File

@ -14,12 +14,10 @@
*/
#include "lib.h"
#include "pool.h"
#include "label.h"
#include "metadata.h"
#include "lvmcache.h"
#include "filter.h"
#include "list.h"
#include "xlate.h"
#include "disk_rep.h"
@ -35,7 +33,7 @@
#define CPOUT_64(x, y) {(y) = xlate64_be((x));}
static int __read_pool_disk(const struct format_type *fmt, struct device *dev,
struct pool *mem, struct pool_list *pl,
struct dm_pool *mem, struct pool_list *pl,
const char *vg_name)
{
char buf[512];
@ -240,13 +238,13 @@ void get_pool_uuid(char *uuid, uint64_t poolid, uint32_t spid, uint32_t devid)
}
static int _read_vg_pds(const struct format_type *fmt, struct pool *mem,
static int _read_vg_pds(const struct format_type *fmt, struct dm_pool *mem,
struct lvmcache_vginfo *vginfo, struct list *head,
uint32_t *devcount)
{
struct lvmcache_info *info;
struct pool_list *pl = NULL;
struct pool *tmpmem;
struct dm_pool *tmpmem;
uint32_t sp_count = 0;
uint32_t *sp_devs = NULL;
@ -254,7 +252,7 @@ static int _read_vg_pds(const struct format_type *fmt, struct pool *mem,
/* FIXME: maybe should return a different error in memory
* allocation failure */
if (!(tmpmem = pool_create("pool read_vg", 512))) {
if (!(tmpmem = dm_pool_create("pool read_vg", 512))) {
stack;
return 0;
}
@ -271,11 +269,11 @@ static int _read_vg_pds(const struct format_type *fmt, struct pool *mem,
/* FIXME pl left uninitialised if !info->dev */
sp_count = pl->pd.pl_subpools;
if (!(sp_devs =
pool_zalloc(tmpmem,
dm_pool_zalloc(tmpmem,
sizeof(uint32_t) * sp_count))) {
log_error("Unable to allocate %d 32-bit uints",
sp_count);
pool_destroy(tmpmem);
dm_pool_destroy(tmpmem);
return 0;
}
}
@ -296,7 +294,7 @@ static int _read_vg_pds(const struct format_type *fmt, struct pool *mem,
for (i = 0; i < sp_count; i++)
*devcount += sp_devs[i];
pool_destroy(tmpmem);
dm_pool_destroy(tmpmem);
if (pl && *pl->pd.pl_pool_name)
return 1;
@ -306,7 +304,7 @@ static int _read_vg_pds(const struct format_type *fmt, struct pool *mem,
}
int read_pool_pds(const struct format_type *fmt, const char *vg_name,
struct pool *mem, struct list *pdhead)
struct dm_pool *mem, struct list *pdhead)
{
struct lvmcache_vginfo *vginfo;
uint32_t totaldevs;
@ -351,7 +349,7 @@ int read_pool_pds(const struct format_type *fmt, const char *vg_name,
}
struct pool_list *read_pool_disk(const struct format_type *fmt,
struct device *dev, struct pool *mem,
struct device *dev, struct dm_pool *mem,
const char *vg_name)
{
struct pool_list *pl;
@ -361,7 +359,7 @@ struct pool_list *read_pool_disk(const struct format_type *fmt,
return NULL;
}
if (!(pl = pool_zalloc(mem, sizeof(*pl)))) {
if (!(pl = dm_pool_zalloc(mem, sizeof(*pl)))) {
log_error("Unable to allocate pool list structure");
return 0;
}

View File

@ -18,7 +18,6 @@
#include "label.h"
#include "metadata.h"
#include "pool.h"
#define MINOR_OFFSET 65536
@ -138,20 +137,20 @@ int read_pool_label(struct pool_list *pl, struct labeller *l,
void pool_label_out(struct pool_disk *pl, char *buf);
void pool_label_in(struct pool_disk *pl, char *buf);
void get_pool_uuid(char *uuid, uint64_t poolid, uint32_t spid, uint32_t devid);
int import_pool_vg(struct volume_group *vg, struct pool *mem, struct list *pls);
int import_pool_lvs(struct volume_group *vg, struct pool *mem,
int import_pool_vg(struct volume_group *vg, struct dm_pool *mem, struct list *pls);
int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem,
struct list *pls);
int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg,
struct list *pvs, struct pool *mem, struct list *pls);
int import_pool_pv(const struct format_type *fmt, struct pool *mem,
struct list *pvs, struct dm_pool *mem, struct list *pls);
int import_pool_pv(const struct format_type *fmt, struct dm_pool *mem,
struct volume_group *vg, struct physical_volume *pv,
struct pool_list *pl);
int import_pool_segments(struct list *lvs, struct pool *mem,
int import_pool_segments(struct list *lvs, struct dm_pool *mem,
struct user_subpool *usp, int sp_count);
int read_pool_pds(const struct format_type *fmt, const char *vgname,
struct pool *mem, struct list *head);
struct dm_pool *mem, struct list *head);
struct pool_list *read_pool_disk(const struct format_type *fmt,
struct device *dev, struct pool *mem,
struct device *dev, struct dm_pool *mem,
const char *vg_name);
#endif /* DISK_REP_POOL_FORMAT_H */

View File

@ -14,12 +14,9 @@
*/
#include "lib.h"
#include "pool.h"
#include "label.h"
#include "metadata.h"
#include "hash.h"
#include "limits.h"
#include "list.h"
#include "display.h"
#include "toolcontext.h"
#include "lvmcache.h"
@ -30,7 +27,7 @@
#define FMT_POOL_NAME "pool"
/* Must be called after pvs are imported */
static struct user_subpool *_build_usp(struct list *pls, struct pool *mem,
static struct user_subpool *_build_usp(struct list *pls, struct dm_pool *mem,
int *sps)
{
struct pool_list *pl;
@ -43,7 +40,7 @@ static struct user_subpool *_build_usp(struct list *pls, struct pool *mem,
*/
list_iterate_items(pl, pls) {
*sps = pl->pd.pl_subpools;
if (!usp && (!(usp = pool_zalloc(mem, sizeof(*usp) * (*sps))))) {
if (!usp && (!(usp = dm_pool_zalloc(mem, sizeof(*usp) * (*sps))))) {
log_error("Unable to allocate %d subpool structures",
*sps);
return 0;
@ -61,7 +58,7 @@ static struct user_subpool *_build_usp(struct list *pls, struct pool *mem,
if (!cur_sp->devs &&
(!(cur_sp->devs =
pool_zalloc(mem,
dm_pool_zalloc(mem,
sizeof(*usp->devs) * pl->pd.pl_sp_devs)))) {
log_error("Unable to allocate %d pool_device "
@ -103,15 +100,15 @@ static int _check_usp(char *vgname, struct user_subpool *usp, int sp_count)
}
static struct volume_group *_build_vg_from_pds(struct format_instance
*fid, struct pool *mem,
*fid, struct dm_pool *mem,
struct list *pds)
{
struct pool *smem = fid->fmt->cmd->mem;
struct dm_pool *smem = fid->fmt->cmd->mem;
struct volume_group *vg = NULL;
struct user_subpool *usp = NULL;
int sp_count;
if (!(vg = pool_zalloc(smem, sizeof(*vg)))) {
if (!(vg = dm_pool_zalloc(smem, sizeof(*vg)))) {
log_error("Unable to allocate volume group structure");
return NULL;
}
@ -176,7 +173,7 @@ static struct volume_group *_vg_read(struct format_instance *fid,
const char *vg_name,
struct metadata_area *mda)
{
struct pool *mem = pool_create("pool vg_read", 1024);
struct dm_pool *mem = dm_pool_create("pool vg_read", 1024);
struct list pds;
struct volume_group *vg = NULL;
@ -205,7 +202,7 @@ static struct volume_group *_vg_read(struct format_instance *fid,
}
out:
pool_destroy(mem);
dm_pool_destroy(mem);
return vg;
}
@ -222,7 +219,7 @@ static int _pv_setup(const struct format_type *fmt,
static int _pv_read(const struct format_type *fmt, const char *pv_name,
struct physical_volume *pv, struct list *mdas)
{
struct pool *mem = pool_create("pool pv_read", 1024);
struct dm_pool *mem = dm_pool_create("pool pv_read", 1024);
struct pool_list *pl;
struct device *dev;
int r = 0;
@ -259,7 +256,7 @@ static int _pv_read(const struct format_type *fmt, const char *pv_name,
r = 1;
out:
pool_destroy(mem);
dm_pool_destroy(mem);
return r;
}
@ -276,7 +273,7 @@ static struct format_instance *_create_instance(const struct format_type *fmt,
struct format_instance *fid;
struct metadata_area *mda;
if (!(fid = pool_zalloc(fmt->cmd->mem, sizeof(*fid)))) {
if (!(fid = dm_pool_zalloc(fmt->cmd->mem, sizeof(*fid)))) {
log_error("Unable to allocate format instance structure for "
"pool format");
return NULL;
@ -286,10 +283,10 @@ static struct format_instance *_create_instance(const struct format_type *fmt,
list_init(&fid->metadata_areas);
/* Define a NULL metadata area */
if (!(mda = pool_zalloc(fmt->cmd->mem, sizeof(*mda)))) {
if (!(mda = dm_pool_zalloc(fmt->cmd->mem, sizeof(*mda)))) {
log_error("Unable to allocate metadata area structure "
"for pool format");
pool_free(fmt->cmd->mem, fid);
dm_pool_free(fmt->cmd->mem, fid);
return NULL;
}
@ -307,7 +304,7 @@ static void _destroy_instance(struct format_instance *fid)
static void _destroy(const struct format_type *fmt)
{
dbg_free((void *) fmt);
dm_free((void *) fmt);
}
/* *INDENT-OFF* */
@ -327,7 +324,7 @@ struct format_type *init_format(struct cmd_context *cmd);
struct format_type *init_format(struct cmd_context *cmd)
#endif
{
struct format_type *fmt = dbg_malloc(sizeof(*fmt));
struct format_type *fmt = dm_malloc(sizeof(*fmt));
if (!fmt) {
log_error("Unable to allocate format type structure for pool "

View File

@ -14,7 +14,6 @@
*/
#include "lib.h"
#include "pool.h"
#include "label.h"
#include "metadata.h"
#include "lvmcache.h"
@ -28,7 +27,7 @@
/* This file contains only imports at the moment... */
int import_pool_vg(struct volume_group *vg, struct pool *mem, struct list *pls)
int import_pool_vg(struct volume_group *vg, struct dm_pool *mem, struct list *pls)
{
struct pool_list *pl;
@ -41,7 +40,7 @@ int import_pool_vg(struct volume_group *vg, struct pool *mem, struct list *pls)
if (vg->name)
continue;
vg->name = pool_strdup(mem, pl->pd.pl_pool_name);
vg->name = dm_pool_strdup(mem, pl->pd.pl_pool_name);
get_pool_vg_uuid(&vg->id, &pl->pd);
vg->extent_size = POOL_PE_SIZE;
vg->status |= LVM_READ | LVM_WRITE | CLUSTERED | SHARED;
@ -55,10 +54,10 @@ int import_pool_vg(struct volume_group *vg, struct pool *mem, struct list *pls)
return 1;
}
int import_pool_lvs(struct volume_group *vg, struct pool *mem, struct list *pls)
int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem, struct list *pls)
{
struct pool_list *pl;
struct lv_list *lvl = pool_zalloc(mem, sizeof(*lvl));
struct lv_list *lvl = dm_pool_zalloc(mem, sizeof(*lvl));
struct logical_volume *lv;
if (!lvl) {
@ -66,7 +65,7 @@ int import_pool_lvs(struct volume_group *vg, struct pool *mem, struct list *pls)
return 0;
}
if (!(lvl->lv = pool_zalloc(mem, sizeof(*lvl->lv)))) {
if (!(lvl->lv = dm_pool_zalloc(mem, sizeof(*lvl->lv)))) {
log_error("Unable to allocate logical volume structure");
return 0;
}
@ -90,7 +89,7 @@ int import_pool_lvs(struct volume_group *vg, struct pool *mem, struct list *pls)
if (lv->name)
continue;
if (!(lv->name = pool_strdup(mem, pl->pd.pl_pool_name))) {
if (!(lv->name = dm_pool_strdup(mem, pl->pd.pl_pool_name))) {
stack;
return 0;
}
@ -124,17 +123,17 @@ int import_pool_lvs(struct volume_group *vg, struct pool *mem, struct list *pls)
}
int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg,
struct list *pvs, struct pool *mem, struct list *pls)
struct list *pvs, struct dm_pool *mem, struct list *pls)
{
struct pv_list *pvl;
struct pool_list *pl;
list_iterate_items(pl, pls) {
if (!(pvl = pool_zalloc(mem, sizeof(*pvl)))) {
if (!(pvl = dm_pool_zalloc(mem, sizeof(*pvl)))) {
log_error("Unable to allocate pv list structure");
return 0;
}
if (!(pvl->pv = pool_zalloc(mem, sizeof(*pvl->pv)))) {
if (!(pvl->pv = dm_pool_zalloc(mem, sizeof(*pvl->pv)))) {
log_error("Unable to allocate pv structure");
return 0;
}
@ -150,7 +149,7 @@ int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg,
return 1;
}
int import_pool_pv(const struct format_type *fmt, struct pool *mem,
int import_pool_pv(const struct format_type *fmt, struct dm_pool *mem,
struct volume_group *vg, struct physical_volume *pv,
struct pool_list *pl)
{
@ -162,7 +161,7 @@ int import_pool_pv(const struct format_type *fmt, struct pool *mem,
pv->fmt = fmt;
pv->dev = pl->dev;
if (!(pv->vg_name = pool_strdup(mem, pd->pl_pool_name))) {
if (!(pv->vg_name = dm_pool_strdup(mem, pd->pl_pool_name))) {
log_error("Unable to duplicate vg_name string");
return 0;
}
@ -197,7 +196,7 @@ static const char *_cvt_sptype(uint32_t sptype)
return sptype_names[i].name;
}
static int _add_stripe_seg(struct pool *mem,
static int _add_stripe_seg(struct dm_pool *mem,
struct user_subpool *usp, struct logical_volume *lv,
uint32_t *le_cur)
{
@ -243,7 +242,7 @@ static int _add_stripe_seg(struct pool *mem,
return 1;
}
static int _add_linear_seg(struct pool *mem,
static int _add_linear_seg(struct dm_pool *mem,
struct user_subpool *usp, struct logical_volume *lv,
uint32_t *le_cur)
{
@ -284,7 +283,7 @@ static int _add_linear_seg(struct pool *mem,
return 1;
}
int import_pool_segments(struct list *lvs, struct pool *mem,
int import_pool_segments(struct list *lvs, struct dm_pool *mem,
struct user_subpool *usp, int subpools)
{
struct lv_list *lvl;

View File

@ -14,7 +14,6 @@
*/
#include "lib.h"
#include "pool.h"
#include "label.h"
#include "metadata.h"
#include "xlate.h"
@ -79,7 +78,7 @@ static void _destroy_label(struct labeller *l, struct label *label)
static void _destroy(struct labeller *l)
{
dbg_free(l);
dm_free(l);
}
struct label_ops _pool_ops = {
@ -96,7 +95,7 @@ struct labeller *pool_labeller_create(struct format_type *fmt)
{
struct labeller *l;
if (!(l = dbg_malloc(sizeof(*l)))) {
if (!(l = dm_malloc(sizeof(*l)))) {
log_error("Couldn't allocate labeller object.");
return NULL;
}

View File

@ -16,9 +16,7 @@
#include "lib.h"
#include "format-text.h"
#include "pool.h"
#include "config.h"
#include "hash.h"
#include "import-export.h"
#include "lvm-string.h"
#include "lvm-file.h"
@ -109,24 +107,24 @@ static void _insert_file(struct list *head, struct archive_file *b)
list_add_h(&bf->list, &b->list);
}
static char *_join(struct pool *mem, const char *dir, const char *name)
static char *_join(struct dm_pool *mem, const char *dir, const char *name)
{
if (!pool_begin_object(mem, 32) ||
!pool_grow_object(mem, dir, strlen(dir)) ||
!pool_grow_object(mem, "/", 1) ||
!pool_grow_object(mem, name, strlen(name)) ||
!pool_grow_object(mem, "\0", 1)) {
if (!dm_pool_begin_object(mem, 32) ||
!dm_pool_grow_object(mem, dir, strlen(dir)) ||
!dm_pool_grow_object(mem, "/", 1) ||
!dm_pool_grow_object(mem, name, strlen(name)) ||
!dm_pool_grow_object(mem, "\0", 1)) {
stack;
return NULL;
}
return pool_end_object(mem);
return dm_pool_end_object(mem);
}
/*
* Returns a list of archive_files.
*/
static struct list *_scan_archive(struct pool *mem,
static struct list *_scan_archive(struct dm_pool *mem,
const char *vgname, const char *dir)
{
int i, count;
@ -136,7 +134,7 @@ static struct list *_scan_archive(struct pool *mem,
struct archive_file *af;
struct list *results;
if (!(results = pool_alloc(mem, sizeof(*results)))) {
if (!(results = dm_pool_alloc(mem, sizeof(*results)))) {
stack;
return NULL;
}
@ -171,7 +169,7 @@ static struct list *_scan_archive(struct pool *mem,
/*
* Create a new archive_file.
*/
if (!(af = pool_alloc(mem, sizeof(*af)))) {
if (!(af = dm_pool_alloc(mem, sizeof(*af)))) {
log_err("Couldn't create new archive file.");
results = NULL;
goto out;
@ -333,7 +331,7 @@ static void _display_archive(struct cmd_context *cmd, struct archive_file *af)
log_print("Description:\t%s", desc ? desc : "<No description>");
log_print("Backup Time:\t%s", ctime(&when));
pool_free(cmd->mem, vg);
dm_pool_free(cmd->mem, vg);
tf->fmt->ops->destroy_instance(tf);
}
@ -353,7 +351,7 @@ int archive_list(struct cmd_context *cmd, const char *dir, const char *vgname)
list_iterate_back_items(af, archives)
_display_archive(cmd, af);
pool_free(cmd->mem, archives);
dm_pool_free(cmd->mem, archives);
return 1;
}

View File

@ -38,7 +38,7 @@ struct backup_params {
int archive_init(struct cmd_context *cmd, const char *dir,
unsigned int keep_days, unsigned int keep_min)
{
if (!(cmd->archive_params = pool_zalloc(cmd->libmem,
if (!(cmd->archive_params = dm_pool_zalloc(cmd->libmem,
sizeof(*cmd->archive_params)))) {
log_error("archive_params alloc failed");
return 0;
@ -49,7 +49,7 @@ int archive_init(struct cmd_context *cmd, const char *dir,
if (!*dir)
return 1;
if (!(cmd->archive_params->dir = dbg_strdup(dir))) {
if (!(cmd->archive_params->dir = dm_strdup(dir))) {
log_error("Couldn't copy archive directory name.");
return 0;
}
@ -64,7 +64,7 @@ int archive_init(struct cmd_context *cmd, const char *dir,
void archive_exit(struct cmd_context *cmd)
{
if (cmd->archive_params->dir)
dbg_free(cmd->archive_params->dir);
dm_free(cmd->archive_params->dir);
memset(cmd->archive_params, 0, sizeof(*cmd->archive_params));
}
@ -73,12 +73,12 @@ void archive_enable(struct cmd_context *cmd, int flag)
cmd->archive_params->enabled = flag;
}
static char *_build_desc(struct pool *mem, const char *line, int before)
static char *_build_desc(struct dm_pool *mem, const char *line, int before)
{
size_t len = strlen(line) + 32;
char *buffer;
if (!(buffer = pool_zalloc(mem, strlen(line) + 32))) {
if (!(buffer = dm_pool_zalloc(mem, strlen(line) + 32))) {
stack;
return NULL;
}
@ -150,7 +150,7 @@ int archive_display(struct cmd_context *cmd, const char *vg_name)
int backup_init(struct cmd_context *cmd, const char *dir)
{
if (!(cmd->backup_params = pool_zalloc(cmd->libmem,
if (!(cmd->backup_params = dm_pool_zalloc(cmd->libmem,
sizeof(*cmd->archive_params)))) {
log_error("archive_params alloc failed");
return 0;
@ -160,7 +160,7 @@ int backup_init(struct cmd_context *cmd, const char *dir)
if (!*dir)
return 1;
if (!(cmd->backup_params->dir = dbg_strdup(dir))) {
if (!(cmd->backup_params->dir = dm_strdup(dir))) {
log_error("Couldn't copy backup directory name.");
return 0;
}
@ -171,7 +171,7 @@ int backup_init(struct cmd_context *cmd, const char *dir)
void backup_exit(struct cmd_context *cmd)
{
if (cmd->backup_params->dir)
dbg_free(cmd->backup_params->dir);
dm_free(cmd->backup_params->dir);
memset(cmd->backup_params, 0, sizeof(*cmd->backup_params));
}

View File

@ -16,8 +16,6 @@
#include "lib.h"
#include "import-export.h"
#include "metadata.h"
#include "hash.h"
#include "pool.h"
#include "display.h"
#include "lvm-string.h"
#include "segtype.h"
@ -36,8 +34,8 @@ typedef int (*nl_fn) (struct formatter * f);
* exporting the vg, ie. writing it to a file.
*/
struct formatter {
struct pool *mem; /* pv names allocated from here */
struct hash_table *pv_names; /* dev_name -> pv_name (eg, pv1) */
struct dm_pool *mem; /* pv names allocated from here */
struct dm_hash_table *pv_names; /* dev_name -> pv_name (eg, pv1) */
union {
FILE *fp; /* where we're writing to */
@ -108,7 +106,7 @@ static int _nl_raw(struct formatter *f)
/* If metadata doesn't fit, double the buffer size */
if (f->data.buf.used + 2 > f->data.buf.size) {
if (!(newbuf = dbg_realloc(f->data.buf.start,
if (!(newbuf = dm_realloc(f->data.buf.start,
f->data.buf.size * 2))) {
stack;
return 0;
@ -173,7 +171,7 @@ static int _out_with_comment_raw(struct formatter *f, const char *comment,
/* If metadata doesn't fit, double the buffer size */
if (n < 0 || (n + f->data.buf.used + 2 > f->data.buf.size)) {
if (!(newbuf = dbg_realloc(f->data.buf.start,
if (!(newbuf = dm_realloc(f->data.buf.start,
f->data.buf.size * 2))) {
stack;
return 0;
@ -347,7 +345,7 @@ static inline const char *_get_pv_name(struct formatter *f,
struct physical_volume *pv)
{
return (pv) ? (const char *)
hash_lookup(f->pv_names, dev_name(pv->dev)) : "Missing";
dm_hash_lookup(f->pv_names, dev_name(pv->dev)) : "Missing";
}
static int _print_pvs(struct formatter *f, struct volume_group *vg)
@ -602,12 +600,12 @@ static int _build_pv_names(struct formatter *f, struct volume_group *vg)
struct physical_volume *pv;
char buffer[32], *name;
if (!(f->mem = pool_create("text pv_names", 512))) {
if (!(f->mem = dm_pool_create("text pv_names", 512))) {
stack;
goto bad;
}
if (!(f->pv_names = hash_create(128))) {
if (!(f->pv_names = dm_hash_create(128))) {
stack;
goto bad;
}
@ -621,12 +619,12 @@ static int _build_pv_names(struct formatter *f, struct volume_group *vg)
goto bad;
}
if (!(name = pool_strdup(f->mem, buffer))) {
if (!(name = dm_pool_strdup(f->mem, buffer))) {
stack;
goto bad;
}
if (!hash_insert(f->pv_names, dev_name(pv->dev), name)) {
if (!dm_hash_insert(f->pv_names, dev_name(pv->dev), name)) {
stack;
goto bad;
}
@ -636,10 +634,10 @@ static int _build_pv_names(struct formatter *f, struct volume_group *vg)
bad:
if (f->mem)
pool_destroy(f->mem);
dm_pool_destroy(f->mem);
if (f->pv_names)
hash_destroy(f->pv_names);
dm_hash_destroy(f->pv_names);
return 0;
}
@ -686,10 +684,10 @@ static int _text_vg_export(struct formatter *f,
out:
if (f->mem)
pool_destroy(f->mem);
dm_pool_destroy(f->mem);
if (f->pv_names)
hash_destroy(f->pv_names);
dm_hash_destroy(f->pv_names);
return r;
}
@ -701,7 +699,7 @@ int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp)
_init();
if (!(f = dbg_malloc(sizeof(*f)))) {
if (!(f = dm_malloc(sizeof(*f)))) {
stack;
return 0;
}
@ -716,7 +714,7 @@ int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp)
r = _text_vg_export(f, vg, desc);
if (r)
r = !ferror(f->data.fp);
dbg_free(f);
dm_free(f);
return r;
}
@ -728,7 +726,7 @@ int text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
_init();
if (!(f = dbg_malloc(sizeof(*f)))) {
if (!(f = dm_malloc(sizeof(*f)))) {
stack;
return 0;
}
@ -736,7 +734,7 @@ int text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
memset(f, 0, sizeof(*f));
f->data.buf.size = 65536; /* Initial metadata limit */
if (!(f->data.buf.start = dbg_malloc(f->data.buf.size))) {
if (!(f->data.buf.start = dm_malloc(f->data.buf.size))) {
log_error("text_export buffer allocation failed");
goto out;
}
@ -748,7 +746,7 @@ int text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
if (!_text_vg_export(f, vg, desc)) {
stack;
dbg_free(f->data.buf.start);
dm_free(f->data.buf.start);
goto out;
}
@ -756,7 +754,7 @@ int text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
*buf = f->data.buf.start;
out:
dbg_free(f);
dm_free(f);
return r;
}

View File

@ -18,9 +18,7 @@
#include "import-export.h"
#include "device.h"
#include "lvm-file.h"
#include "pool.h"
#include "config.h"
#include "hash.h"
#include "display.h"
#include "toolcontext.h"
#include "lvm-string.h"
@ -83,7 +81,7 @@ static int _lv_setup(struct format_instance *fid, struct logical_volume *lv)
if (lv->size > max_size) {
char *dummy = display_size(max_size, SIZE_SHORT);
log_error("logical volumes cannot be larger than %s", dummy);
dbg_free(dummy);
dm_free(dummy);
return 0;
}
*/
@ -119,14 +117,14 @@ static struct mda_header *_raw_read_mda_header(const struct format_type *fmt,
{
struct mda_header *mdah;
if (!(mdah = pool_alloc(fmt->cmd->mem, MDA_HEADER_SIZE))) {
if (!(mdah = dm_pool_alloc(fmt->cmd->mem, MDA_HEADER_SIZE))) {
log_error("struct mda_header allocation failed");
return NULL;
}
if (!dev_read(dev_area->dev, dev_area->start, MDA_HEADER_SIZE, mdah)) {
stack;
pool_free(fmt->cmd->mem, mdah);
dm_pool_free(fmt->cmd->mem, mdah);
return NULL;
}
@ -174,7 +172,7 @@ static int _raw_write_mda_header(const struct format_type *fmt,
if (!dev_write(dev, start_byte, MDA_HEADER_SIZE, mdah)) {
stack;
pool_free(fmt->cmd->mem, mdah);
dm_pool_free(fmt->cmd->mem, mdah);
return 0;
}
@ -432,7 +430,7 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg,
stack;
if (buf)
dbg_free(buf);
dm_free(buf);
return r;
}
@ -595,7 +593,7 @@ static struct volume_group *_vg_read_file_name(struct format_instance *fid,
* check that it contains the correct volume group.
*/
if (vgname && strcmp(vgname, vg->name)) {
pool_free(fid->fmt->cmd->mem, vg);
dm_pool_free(fid->fmt->cmd->mem, vg);
log_err("'%s' does not contain volume group '%s'.",
read_path, vgname);
return NULL;
@ -1160,7 +1158,7 @@ static int _add_raw(struct list *raw_list, struct device_area *dev_area)
return 1;
}
if (!(rl = dbg_malloc(sizeof(struct raw_list)))) {
if (!(rl = dm_malloc(sizeof(struct raw_list)))) {
log_error("_add_raw allocation failed");
return 0;
}
@ -1234,11 +1232,11 @@ static int _pv_read(const struct format_type *fmt, const char *pv_name,
/* Add copy of mdas to supplied list */
list_iterate_items(mda, &info->mdas) {
mdac = (struct mda_context *) mda->metadata_locn;
if (!(mda_new = pool_alloc(fmt->cmd->mem, sizeof(*mda_new)))) {
if (!(mda_new = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda_new)))) {
log_error("metadata_area allocation failed");
return 0;
}
if (!(mdac_new = pool_alloc(fmt->cmd->mem, sizeof(*mdac_new)))) {
if (!(mdac_new = dm_pool_alloc(fmt->cmd->mem, sizeof(*mdac_new)))) {
log_error("metadata_area allocation failed");
return 0;
}
@ -1262,7 +1260,7 @@ static void _free_dirs(struct list *dir_list)
list_iterate_safe(dl, tmp, dir_list) {
list_del(dl);
dbg_free(dl);
dm_free(dl);
}
}
@ -1272,7 +1270,7 @@ static void _free_raws(struct list *raw_list)
list_iterate_safe(rl, tmp, raw_list) {
list_del(rl);
dbg_free(rl);
dm_free(rl);
}
}
@ -1281,10 +1279,10 @@ static void _destroy(const struct format_type *fmt)
if (fmt->private) {
_free_dirs(&((struct mda_lists *) fmt->private)->dirs);
_free_raws(&((struct mda_lists *) fmt->private)->raws);
dbg_free(fmt->private);
dm_free(fmt->private);
}
dbg_free((void *) fmt);
dm_free((void *) fmt);
}
static struct metadata_area_ops _metadata_text_file_ops = {
@ -1361,13 +1359,13 @@ static int _pv_setup(const struct format_type *fmt,
if (found)
continue;
if (!(mda_new = pool_alloc(fmt->cmd->mem,
if (!(mda_new = dm_pool_alloc(fmt->cmd->mem,
sizeof(*mda_new)))) {
stack;
return 0;
}
if (!(mdac_new = pool_alloc(fmt->cmd->mem,
if (!(mdac_new = dm_pool_alloc(fmt->cmd->mem,
sizeof(*mdac_new)))) {
stack;
return 0;
@ -1412,7 +1410,7 @@ static struct format_instance *_create_text_instance(const struct format_type
struct lvmcache_vginfo *vginfo;
struct lvmcache_info *info;
if (!(fid = pool_alloc(fmt->cmd->mem, sizeof(*fid)))) {
if (!(fid = dm_pool_alloc(fmt->cmd->mem, sizeof(*fid)))) {
log_error("Couldn't allocate format instance object.");
return NULL;
}
@ -1422,7 +1420,7 @@ static struct format_instance *_create_text_instance(const struct format_type
list_init(&fid->metadata_areas);
if (!vgname) {
if (!(mda = pool_alloc(fmt->cmd->mem, sizeof(*mda)))) {
if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda)))) {
stack;
return NULL;
}
@ -1441,7 +1439,7 @@ static struct format_instance *_create_text_instance(const struct format_type
}
context = create_text_context(fmt->cmd, path, NULL);
if (!(mda = pool_alloc(fmt->cmd->mem, sizeof(*mda)))) {
if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda)))) {
stack;
return NULL;
}
@ -1457,12 +1455,12 @@ static struct format_instance *_create_text_instance(const struct format_type
if (!_raw_holds_vgname(fid, &rl->dev_area, vgname))
continue;
if (!(mda = pool_alloc(fmt->cmd->mem, sizeof(*mda)))) {
if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda)))) {
stack;
return NULL;
}
if (!(mdac = pool_alloc(fmt->cmd->mem, sizeof(*mdac)))) {
if (!(mdac = dm_pool_alloc(fmt->cmd->mem, sizeof(*mdac)))) {
stack;
return NULL;
}
@ -1487,13 +1485,13 @@ static struct format_instance *_create_text_instance(const struct format_type
(struct mda_context *) mda->metadata_locn;
/* FIXME Check it holds this VG */
if (!(mda_new = pool_alloc(fmt->cmd->mem,
if (!(mda_new = dm_pool_alloc(fmt->cmd->mem,
sizeof(*mda_new)))) {
stack;
return NULL;
}
if (!(mdac_new = pool_alloc(fmt->cmd->mem,
if (!(mdac_new = dm_pool_alloc(fmt->cmd->mem,
sizeof(*mdac_new)))) {
stack;
return NULL;
@ -1525,17 +1523,17 @@ void *create_text_context(struct cmd_context *cmd, const char *path,
return NULL;
}
if (!(tc = pool_alloc(cmd->mem, sizeof(*tc)))) {
if (!(tc = dm_pool_alloc(cmd->mem, sizeof(*tc)))) {
stack;
return NULL;
}
if (!(tc->path_live = pool_strdup(cmd->mem, path))) {
if (!(tc->path_live = dm_pool_strdup(cmd->mem, path))) {
stack;
goto no_mem;
}
if (!(tc->path_edit = pool_alloc(cmd->mem, strlen(path) + 5))) {
if (!(tc->path_edit = dm_pool_alloc(cmd->mem, strlen(path) + 5))) {
stack;
goto no_mem;
}
@ -1544,7 +1542,7 @@ void *create_text_context(struct cmd_context *cmd, const char *path,
if (!desc)
desc = "";
if (!(tc->desc = pool_strdup(cmd->mem, desc))) {
if (!(tc->desc = dm_pool_strdup(cmd->mem, desc))) {
stack;
goto no_mem;
}
@ -1552,7 +1550,7 @@ void *create_text_context(struct cmd_context *cmd, const char *path,
return (void *) tc;
no_mem:
pool_free(cmd->mem, tc);
dm_pool_free(cmd->mem, tc);
log_err("Couldn't allocate text format context object.");
return NULL;
@ -1575,7 +1573,7 @@ static int _add_dir(const char *dir, struct list *dir_list)
struct dir_list *dl;
if (create_dir(dir)) {
if (!(dl = dbg_malloc(sizeof(struct list) + strlen(dir) + 1))) {
if (!(dl = dm_malloc(sizeof(struct list) + strlen(dir) + 1))) {
log_error("_add_dir allocation failed");
return 0;
}
@ -1647,7 +1645,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
struct config_value *cv;
struct mda_lists *mda_lists;
if (!(fmt = dbg_malloc(sizeof(*fmt)))) {
if (!(fmt = dm_malloc(sizeof(*fmt)))) {
stack;
return NULL;
}
@ -1659,7 +1657,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
fmt->features = FMT_SEGMENTS | FMT_MDAS | FMT_TAGS | FMT_PRECOMMIT |
FMT_UNLIMITED_VOLS;
if (!(mda_lists = dbg_malloc(sizeof(struct mda_lists)))) {
if (!(mda_lists = dm_malloc(sizeof(struct mda_lists)))) {
log_error("Failed to allocate dir_list");
return NULL;
}
@ -1710,6 +1708,6 @@ struct format_type *create_text_format(struct cmd_context *cmd)
err:
_free_dirs(&mda_lists->dirs);
dbg_free(fmt);
dm_free(fmt);
return NULL;
}

View File

@ -18,7 +18,6 @@
#include "lvm-types.h"
#include "metadata.h"
#include "pool.h"
/*
* Archives a vg config. 'retain_days' is the minimum number of
@ -47,11 +46,11 @@ struct labeller *text_labeller_create(const struct format_type *fmt);
int pvhdr_read(struct device *dev, char *buf);
int add_da(const struct format_type *fmt, struct pool *mem, struct list *das,
int add_da(const struct format_type *fmt, struct dm_pool *mem, struct list *das,
uint64_t start, uint64_t size);
void del_das(struct list *das);
int add_mda(const struct format_type *fmt, struct pool *mem, struct list *mdas,
int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct list *mdas,
struct device *dev, uint64_t start, uint64_t size);
void del_mdas(struct list *mdas);

View File

@ -19,7 +19,6 @@
#include "config.h"
#include "lvm-types.h"
#include "metadata.h"
#include "pool.h"
#include <stdio.h>
@ -46,7 +45,7 @@ struct text_vg_version_ops {
int (*check_version) (struct config_tree * cf);
struct volume_group *(*read_vg) (struct format_instance * fid,
struct config_tree * cf);
void (*read_desc) (struct pool * mem, struct config_tree * cf,
void (*read_desc) (struct dm_pool * mem, struct config_tree * cf,
time_t *when, char **desc);
};
@ -56,7 +55,7 @@ int print_flags(uint32_t status, int type, char *buffer, size_t size);
int read_flags(uint32_t *status, int type, struct config_value *cv);
int print_tags(struct list *tags, char *buffer, size_t size);
int read_tags(struct pool *mem, struct list *tags, struct config_value *cv);
int read_tags(struct dm_pool *mem, struct list *tags, struct config_value *cv);
int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp);
int text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf);

View File

@ -16,9 +16,7 @@
#include "lib.h"
#include "metadata.h"
#include "import-export.h"
#include "pool.h"
#include "display.h"
#include "hash.h"
#include "toolcontext.h"
#include "lvmcache.h"

View File

@ -16,9 +16,7 @@
#include "lib.h"
#include "metadata.h"
#include "import-export.h"
#include "pool.h"
#include "display.h"
#include "hash.h"
#include "toolcontext.h"
#include "lvmcache.h"
#include "lv_alloc.h"
@ -26,10 +24,10 @@
#include "segtype.h"
#include "text_import.h"
typedef int (*section_fn) (struct format_instance * fid, struct pool * mem,
typedef int (*section_fn) (struct format_instance * fid, struct dm_pool * mem,
struct volume_group * vg, struct config_node * pvn,
struct config_node * vgn,
struct hash_table * pv_hash);
struct dm_hash_table * pv_hash);
#define _read_int32(root, path, result) \
get_config_uint32(root, path, (uint32_t *) result)
@ -111,16 +109,16 @@ static int _read_id(struct id *id, struct config_node *cn, const char *path)
return 1;
}
static int _read_pv(struct format_instance *fid, struct pool *mem,
static int _read_pv(struct format_instance *fid, struct dm_pool *mem,
struct volume_group *vg, struct config_node *pvn,
struct config_node *vgn, struct hash_table *pv_hash)
struct config_node *vgn, struct dm_hash_table *pv_hash)
{
struct physical_volume *pv;
struct pv_list *pvl;
struct config_node *cn;
if (!(pvl = pool_zalloc(mem, sizeof(*pvl))) ||
!(pvl->pv = pool_zalloc(mem, sizeof(*pvl->pv)))) {
if (!(pvl = dm_pool_zalloc(mem, sizeof(*pvl))) ||
!(pvl->pv = dm_pool_zalloc(mem, sizeof(*pvl->pv)))) {
stack;
return 0;
}
@ -131,7 +129,7 @@ static int _read_pv(struct format_instance *fid, struct pool *mem,
* Add the pv to the pv hash for quick lookup when we read
* the lv segments.
*/
if (!hash_insert(pv_hash, pvn->key, pv)) {
if (!dm_hash_insert(pv_hash, pvn->key, pv)) {
stack;
return 0;
}
@ -164,7 +162,7 @@ static int _read_pv(struct format_instance *fid, struct pool *mem,
return 0;
}
if (!(pv->vg_name = pool_strdup(mem, vg->name))) {
if (!(pv->vg_name = dm_pool_strdup(mem, vg->name))) {
stack;
return 0;
}
@ -236,9 +234,9 @@ static void _insert_segment(struct logical_volume *lv, struct lv_segment *seg)
list_add(&lv->segments, &seg->list);
}
static int _read_segment(struct pool *mem, struct volume_group *vg,
static int _read_segment(struct dm_pool *mem, struct volume_group *vg,
struct logical_volume *lv, struct config_node *sn,
struct hash_table *pv_hash)
struct dm_hash_table *pv_hash)
{
uint32_t area_count = 0u;
struct lv_segment *seg;
@ -323,7 +321,7 @@ static int _read_segment(struct pool *mem, struct volume_group *vg,
}
int text_import_areas(struct lv_segment *seg, const struct config_node *sn,
const struct config_node *cn, struct hash_table *pv_hash,
const struct config_node *cn, struct dm_hash_table *pv_hash,
uint32_t flags)
{
unsigned int s;
@ -359,7 +357,7 @@ int text_import_areas(struct lv_segment *seg, const struct config_node *sn,
}
/* FIXME Cope if LV not yet read in */
if ((pv = hash_lookup(pv_hash, cv->v.str))) {
if ((pv = dm_hash_lookup(pv_hash, cv->v.str))) {
if (!set_lv_segment_area_pv(seg, s, pv, cv->next->v.i)) {
stack;
return 0;
@ -389,9 +387,9 @@ int text_import_areas(struct lv_segment *seg, const struct config_node *sn,
return 1;
}
static int _read_segments(struct pool *mem, struct volume_group *vg,
static int _read_segments(struct dm_pool *mem, struct volume_group *vg,
struct logical_volume *lv, struct config_node *lvn,
struct hash_table *pv_hash)
struct dm_hash_table *pv_hash)
{
struct config_node *sn;
int count = 0, seg_count;
@ -446,23 +444,23 @@ static int _read_segments(struct pool *mem, struct volume_group *vg,
return 1;
}
static int _read_lvnames(struct format_instance *fid, struct pool *mem,
static int _read_lvnames(struct format_instance *fid, struct dm_pool *mem,
struct volume_group *vg, struct config_node *lvn,
struct config_node *vgn, struct hash_table *pv_hash)
struct config_node *vgn, struct dm_hash_table *pv_hash)
{
struct logical_volume *lv;
struct lv_list *lvl;
struct config_node *cn;
if (!(lvl = pool_zalloc(mem, sizeof(*lvl))) ||
!(lvl->lv = pool_zalloc(mem, sizeof(*lvl->lv)))) {
if (!(lvl = dm_pool_zalloc(mem, sizeof(*lvl))) ||
!(lvl->lv = dm_pool_zalloc(mem, sizeof(*lvl->lv)))) {
stack;
return 0;
}
lv = lvl->lv;
if (!(lv->name = pool_strdup(mem, lvn->key))) {
if (!(lv->name = dm_pool_strdup(mem, lvn->key))) {
stack;
return 0;
}
@ -521,9 +519,9 @@ static int _read_lvnames(struct format_instance *fid, struct pool *mem,
return 1;
}
static int _read_lvsegs(struct format_instance *fid, struct pool *mem,
static int _read_lvsegs(struct format_instance *fid, struct dm_pool *mem,
struct volume_group *vg, struct config_node *lvn,
struct config_node *vgn, struct hash_table *pv_hash)
struct config_node *vgn, struct dm_hash_table *pv_hash)
{
struct logical_volume *lv;
struct lv_list *lvl;
@ -586,9 +584,9 @@ static int _read_lvsegs(struct format_instance *fid, struct pool *mem,
static int _read_sections(struct format_instance *fid,
const char *section, section_fn fn,
struct pool *mem,
struct dm_pool *mem,
struct volume_group *vg, struct config_node *vgn,
struct hash_table *pv_hash, int optional)
struct dm_hash_table *pv_hash, int optional)
{
struct config_node *n;
@ -616,8 +614,8 @@ static struct volume_group *_read_vg(struct format_instance *fid,
{
struct config_node *vgn, *cn;
struct volume_group *vg;
struct hash_table *pv_hash = NULL;
struct pool *mem = fid->fmt->cmd->mem;
struct dm_hash_table *pv_hash = NULL;
struct dm_pool *mem = fid->fmt->cmd->mem;
/* skip any top-level values */
for (vgn = cft->root; (vgn && vgn->v); vgn = vgn->sib) ;
@ -627,7 +625,7 @@ static struct volume_group *_read_vg(struct format_instance *fid,
return NULL;
}
if (!(vg = pool_zalloc(mem, sizeof(*vg)))) {
if (!(vg = dm_pool_zalloc(mem, sizeof(*vg)))) {
stack;
return NULL;
}
@ -637,12 +635,12 @@ static struct volume_group *_read_vg(struct format_instance *fid,
/* eg Set to instance of fmt1 here if reading a format1 backup? */
vg->fid = fid;
if (!(vg->name = pool_strdup(mem, vgn->key))) {
if (!(vg->name = dm_pool_strdup(mem, vgn->key))) {
stack;
goto bad;
}
if (!(vg->system_id = pool_zalloc(mem, NAME_LEN))) {
if (!(vg->system_id = dm_pool_zalloc(mem, NAME_LEN))) {
stack;
goto bad;
}
@ -722,7 +720,7 @@ static struct volume_group *_read_vg(struct format_instance *fid,
* The pv hash memoises the pv section names -> pv
* structures.
*/
if (!(pv_hash = hash_create(32))) {
if (!(pv_hash = dm_hash_create(32))) {
log_error("Couldn't create hash table.");
goto bad;
}
@ -759,7 +757,7 @@ static struct volume_group *_read_vg(struct format_instance *fid,
goto bad;
}
hash_destroy(pv_hash);
dm_hash_destroy(pv_hash);
if (vg->status & PARTIAL_VG) {
vg->status &= ~LVM_WRITE;
@ -773,13 +771,13 @@ static struct volume_group *_read_vg(struct format_instance *fid,
bad:
if (pv_hash)
hash_destroy(pv_hash);
dm_hash_destroy(pv_hash);
pool_free(mem, vg);
dm_pool_free(mem, vg);
return NULL;
}
static void _read_desc(struct pool *mem,
static void _read_desc(struct dm_pool *mem,
struct config_tree *cft, time_t *when, char **desc)
{
const char *d;
@ -788,7 +786,7 @@ static void _read_desc(struct pool *mem,
log_suppress(1);
d = find_config_str(cft->root, "description", "");
log_suppress(0);
*desc = pool_strdup(mem, d);
*desc = dm_pool_strdup(mem, d);
get_config_uint32(cft->root, "creation_time", &u);
*when = u;

View File

@ -16,7 +16,6 @@
#include "lib.h"
#include "metadata.h"
#include "import-export.h"
#include "pool.h"
#include "str_list.h"
#include "lvm-string.h"
@ -53,7 +52,7 @@ int print_tags(struct list *tags, char *buffer, size_t size)
return 1;
}
int read_tags(struct pool *mem, struct list *tags, struct config_value *cv)
int read_tags(struct dm_pool *mem, struct list *tags, struct config_value *cv)
{
if (cv->type == CFG_EMPTY_ARRAY)
return 1;
@ -64,7 +63,7 @@ int read_tags(struct pool *mem, struct list *tags, struct config_value *cv)
return 0;
}
if (!str_list_add(mem, tags, pool_strdup(mem, cv->v.str))) {
if (!str_list_add(mem, tags, dm_pool_strdup(mem, cv->v.str))) {
stack;
return 0;
}

View File

@ -20,7 +20,7 @@ struct lv_segment;
struct config_node;
int text_import_areas(struct lv_segment *seg, const struct config_node *sn,
const struct config_node *cn, struct hash_table *pv_hash,
const struct config_node *cn, struct dm_hash_table *pv_hash,
uint32_t flags);
#endif

View File

@ -86,18 +86,18 @@ static int _write(struct label *label, char *buf)
return 1;
}
int add_da(const struct format_type *fmt, struct pool *mem, struct list *das,
int add_da(const struct format_type *fmt, struct dm_pool *mem, struct list *das,
uint64_t start, uint64_t size)
{
struct data_area_list *dal;
if (!mem) {
if (!(dal = dbg_malloc(sizeof(*dal)))) {
if (!(dal = dm_malloc(sizeof(*dal)))) {
log_error("struct data_area_list allocation failed");
return 0;
}
} else {
if (!(dal = pool_alloc(mem, sizeof(*dal)))) {
if (!(dal = dm_pool_alloc(mem, sizeof(*dal)))) {
log_error("struct data_area_list allocation failed");
return 0;
}
@ -119,11 +119,11 @@ void del_das(struct list *das)
list_iterate_safe(dah, tmp, das) {
da = list_item(dah, struct data_area_list);
list_del(&da->list);
dbg_free(da);
dm_free(da);
}
}
int add_mda(const struct format_type *fmt, struct pool *mem, struct list *mdas,
int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct list *mdas,
struct device *dev, uint64_t start, uint64_t size)
{
/* FIXME List size restricted by pv_header SECTOR_SIZE */
@ -132,23 +132,23 @@ int add_mda(const struct format_type *fmt, struct pool *mem, struct list *mdas,
struct mda_context *mdac;
if (!mem) {
if (!(mdal = dbg_malloc(sizeof(struct metadata_area)))) {
if (!(mdal = dm_malloc(sizeof(struct metadata_area)))) {
log_error("struct mda_list allocation failed");
return 0;
}
if (!(mdac = dbg_malloc(sizeof(struct mda_context)))) {
if (!(mdac = dm_malloc(sizeof(struct mda_context)))) {
log_error("struct mda_context allocation failed");
dbg_free(mdal);
dm_free(mdal);
return 0;
}
} else {
if (!(mdal = pool_alloc(mem, sizeof(struct metadata_area)))) {
if (!(mdal = dm_pool_alloc(mem, sizeof(struct metadata_area)))) {
log_error("struct mda_list allocation failed");
return 0;
}
if (!(mdac = pool_alloc(mem, sizeof(struct mda_context)))) {
if (!(mdac = dm_pool_alloc(mem, sizeof(struct mda_context)))) {
log_error("struct mda_context allocation failed");
return 0;
}
@ -173,9 +173,9 @@ void del_mdas(struct list *mdas)
list_iterate_safe(mdah, tmp, mdas) {
mda = list_item(mdah, struct metadata_area);
dbg_free(mda->metadata_locn);
dm_free(mda->metadata_locn);
list_del(&mda->list);
dbg_free(mda);
dm_free(mda);
}
}
@ -255,7 +255,7 @@ static void _destroy_label(struct labeller *l, struct label *label)
static void _destroy(struct labeller *l)
{
dbg_free(l);
dm_free(l);
}
struct label_ops _text_ops = {
@ -272,7 +272,7 @@ struct labeller *text_labeller_create(const struct format_type *fmt)
{
struct labeller *l;
if (!(l = dbg_malloc(sizeof(*l)))) {
if (!(l = dm_malloc(sizeof(*l)))) {
log_err("Couldn't allocate labeller object.");
return NULL;
}

View File

@ -15,7 +15,6 @@
#include "lib.h"
#include "label.h"
#include "list.h"
#include "crc.h"
#include "xlate.h"
#include "lvmcache.h"
@ -46,7 +45,7 @@ static struct labeller_i *_alloc_li(const char *name, struct labeller *l)
len = sizeof(*li) + strlen(name) + 1;
if (!(li = dbg_malloc(len))) {
if (!(li = dm_malloc(len))) {
log_error("Couldn't allocate memory for labeller list object.");
return NULL;
}
@ -59,7 +58,7 @@ static struct labeller_i *_alloc_li(const char *name, struct labeller *l)
static void _free_li(struct labeller_i *li)
{
dbg_free(li);
dm_free(li);
}
int label_init(void)
@ -353,14 +352,14 @@ int label_verify(struct device *dev)
void label_destroy(struct label *label)
{
label->labeller->ops->destroy_label(label->labeller, label);
dbg_free(label);
dm_free(label);
}
struct label *label_create(struct labeller *labeller)
{
struct label *label;
if (!(label = dbg_malloc(sizeof(*label)))) {
if (!(label = dm_malloc(sizeof(*label)))) {
log_error("label allocaction failed");
return NULL;
}

View File

@ -127,7 +127,7 @@ static int _send_request(char *inbuf, int inlen, char **retbuf)
/* Allocate buffer */
buflen = len + outheader->arglen;
*retbuf = dbg_malloc(buflen);
*retbuf = dm_malloc(buflen);
if (!*retbuf) {
errno = ENOMEM;
return 0;
@ -236,7 +236,7 @@ static int _cluster_request(char cmd, const char *node, void *data, int len,
* With an extra pair of INTs on the front to sanity
* check the pointer when we are given it back to free
*/
outptr = dbg_malloc(sizeof(lvm_response_t) * num_responses +
outptr = dm_malloc(sizeof(lvm_response_t) * num_responses +
sizeof(int) * 2);
if (!outptr) {
errno = ENOMEM;
@ -259,12 +259,12 @@ static int _cluster_request(char cmd, const char *node, void *data, int len,
rarray[i].status = *(int *) inptr;
inptr += sizeof(int);
rarray[i].response = dbg_malloc(strlen(inptr) + 1);
rarray[i].response = dm_malloc(strlen(inptr) + 1);
if (rarray[i].response == NULL) {
/* Free up everything else and return error */
int j;
for (j = 0; j < i; j++)
dbg_free(rarray[i].response);
dm_free(rarray[i].response);
free(outptr);
errno = ENOMEM;
status = -1;
@ -281,7 +281,7 @@ static int _cluster_request(char cmd, const char *node, void *data, int len,
out:
if (retbuf)
dbg_free(retbuf);
dm_free(retbuf);
return status;
}
@ -302,10 +302,10 @@ static int _cluster_free_request(lvm_response_t * response)
num = ptr[1];
for (i = 0; i < num; i++) {
dbg_free(response[i].response);
dm_free(response[i].response);
}
dbg_free(ptr);
dm_free(ptr);
return 1;
}

View File

@ -71,8 +71,8 @@ static int _release_lock(const char *file, int unlock)
if (close(ll->lf) < 0)
log_sys_error("close", ll->res);
dbg_free(ll->res);
dbg_free(llh);
dm_free(ll->res);
dm_free(llh);
if (file)
return 1;
@ -150,11 +150,11 @@ static int _lock_file(const char *file, int flags)
return 0;
}
if (!(ll = dbg_malloc(sizeof(struct lock_list))))
if (!(ll = dm_malloc(sizeof(struct lock_list))))
return 0;
if (!(ll->res = dbg_strdup(file))) {
dbg_free(ll);
if (!(ll->res = dm_strdup(file))) {
dm_free(ll);
return 0;
}
@ -197,8 +197,8 @@ static int _lock_file(const char *file, int flags)
return 1;
err:
dbg_free(ll->res);
dbg_free(ll);
dm_free(ll->res);
dm_free(ll);
return 0;
}

View File

@ -100,7 +100,7 @@ void release_log_memory(void)
if (!_log_direct)
return;
dbg_free((char *) _log_dev_alias.str);
dm_free((char *) _log_dev_alias.str);
_log_dev_alias.str = "activate_log file";
}

View File

@ -14,9 +14,8 @@
*/
#ifndef _LVM_LV_ALLOC_H
#include "pool.h"
struct lv_segment *alloc_lv_segment(struct pool *mem,
struct lv_segment *alloc_lv_segment(struct dm_pool *mem,
struct segment_type *segtype,
struct logical_volume *lv,
uint32_t le, uint32_t len,

View File

@ -53,7 +53,7 @@ uint32_t find_free_lvnum(struct logical_volume *lv)
/*
* All lv_segments get created here.
*/
struct lv_segment *alloc_lv_segment(struct pool *mem,
struct lv_segment *alloc_lv_segment(struct dm_pool *mem,
struct segment_type *segtype,
struct logical_volume *lv,
uint32_t le, uint32_t len,
@ -69,7 +69,7 @@ struct lv_segment *alloc_lv_segment(struct pool *mem,
struct lv_segment *seg;
uint32_t sz = sizeof(*seg) + (area_count * sizeof(seg->area[0]));
if (!(seg = pool_zalloc(mem, sz))) {
if (!(seg = dm_pool_zalloc(mem, sz))) {
stack;
return NULL;
}
@ -351,7 +351,7 @@ struct alloced_area {
* Details of an allocation attempt
*/
struct alloc_handle {
struct pool *mem;
struct dm_pool *mem;
alloc_policy_t alloc; /* Overall policy */
uint32_t area_count; /* Number of parallel areas */
@ -366,7 +366,7 @@ struct alloc_handle {
/*
* Preparation for a specific allocation attempt
*/
static struct alloc_handle *_alloc_init(struct pool *mem,
static struct alloc_handle *_alloc_init(struct dm_pool *mem,
struct segment_type *segtype,
alloc_policy_t alloc,
uint32_t mirrors,
@ -403,7 +403,7 @@ static struct alloc_handle *_alloc_init(struct pool *mem,
else
area_count = stripes;
if (!(ah = pool_zalloc(mem, sizeof(*ah) + sizeof(ah->alloced_areas[0]) * area_count))) {
if (!(ah = dm_pool_zalloc(mem, sizeof(*ah) + sizeof(ah->alloced_areas[0]) * area_count))) {
log_error("allocation handle allocation failed");
return NULL;
}
@ -411,7 +411,7 @@ static struct alloc_handle *_alloc_init(struct pool *mem,
if (segtype_is_virtual(segtype))
return ah;
if (!(ah->mem = pool_create("allocation", 1024))) {
if (!(ah->mem = dm_pool_create("allocation", 1024))) {
log_error("allocation pool creation failed");
return NULL;
}
@ -432,7 +432,7 @@ static struct alloc_handle *_alloc_init(struct pool *mem,
void alloc_destroy(struct alloc_handle *ah)
{
if (ah->mem)
pool_destroy(ah->mem);
dm_pool_destroy(ah->mem);
}
static int _setup_alloced_segment(struct logical_volume *lv, uint32_t status,
@ -537,7 +537,7 @@ static int _alloc_parallel_area(struct alloc_handle *ah, uint32_t needed,
if (area_len > smallest)
area_len = smallest;
if (!(aa = pool_alloc(ah->mem, sizeof(*aa) *
if (!(aa = dm_pool_alloc(ah->mem, sizeof(*aa) *
(ah->area_count + (log_area ? 1 : 0))))) {
log_error("alloced_area allocation failed");
return 0;
@ -781,7 +781,7 @@ static int _allocate(struct alloc_handle *ah,
}
/* Allocate an array of pv_areas to hold the largest space on each PV */
if (!(areas = dbg_malloc(sizeof(*areas) * areas_size))) {
if (!(areas = dm_malloc(sizeof(*areas) * areas_size))) {
log_err("Couldn't allocate areas array.");
return 0;
}
@ -831,7 +831,7 @@ static int _allocate(struct alloc_handle *ah,
r = 1;
out:
dbg_free(areas);
dm_free(areas);
return r;
}
@ -1152,21 +1152,21 @@ struct logical_volume *lv_create_empty(struct format_instance *fi,
if (!import)
log_verbose("Creating logical volume %s", name);
if (!(ll = pool_zalloc(cmd->mem, sizeof(*ll))) ||
!(ll->lv = pool_zalloc(cmd->mem, sizeof(*ll->lv)))) {
if (!(ll = dm_pool_zalloc(cmd->mem, sizeof(*ll))) ||
!(ll->lv = dm_pool_zalloc(cmd->mem, sizeof(*ll->lv)))) {
log_error("lv_list allocation failed");
if (ll)
pool_free(cmd->mem, ll);
dm_pool_free(cmd->mem, ll);
return NULL;
}
lv = ll->lv;
lv->vg = vg;
if (!(lv->name = pool_strdup(cmd->mem, name))) {
if (!(lv->name = dm_pool_strdup(cmd->mem, name))) {
log_error("lv name strdup failed");
if (ll)
pool_free(cmd->mem, ll);
dm_pool_free(cmd->mem, ll);
return NULL;
}
@ -1188,7 +1188,7 @@ struct logical_volume *lv_create_empty(struct format_instance *fi,
if (fi->fmt->ops->lv_setup && !fi->fmt->ops->lv_setup(fi, lv)) {
stack;
if (ll)
pool_free(cmd->mem, ll);
dm_pool_free(cmd->mem, ll);
return NULL;
}

View File

@ -14,7 +14,6 @@
*/
#include "lib.h"
#include "pool.h"
#include "device.h"
#include "metadata.h"
#include "toolcontext.h"
@ -29,13 +28,13 @@ static int _add_pv_to_vg(struct format_instance *fid, struct volume_group *vg,
{
struct pv_list *pvl;
struct physical_volume *pv;
struct pool *mem = fid->fmt->cmd->mem;
struct dm_pool *mem = fid->fmt->cmd->mem;
struct list mdas;
log_verbose("Adding physical volume '%s' to volume group '%s'",
pv_name, vg->name);
if (!(pvl = pool_zalloc(mem, sizeof(*pvl)))) {
if (!(pvl = dm_pool_zalloc(mem, sizeof(*pvl)))) {
log_error("pv_list allocation for '%s' failed", pv_name);
return 0;
}
@ -59,7 +58,7 @@ static int _add_pv_to_vg(struct format_instance *fid, struct volume_group *vg,
return 0;
}
if (!(pv->vg_name = pool_strdup(mem, vg->name))) {
if (!(pv->vg_name = dm_pool_strdup(mem, vg->name))) {
log_error("vg->name allocation failed for '%s'", pv_name);
return 0;
}
@ -168,16 +167,16 @@ int get_pv_from_vg_by_id(const struct format_type *fmt, const char *vg_name,
int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
const char *new_name)
{
struct pool *mem = cmd->mem;
struct dm_pool *mem = cmd->mem;
struct pv_list *pvl;
if (!(vg->name = pool_strdup(mem, new_name))) {
if (!(vg->name = dm_pool_strdup(mem, new_name))) {
log_error("vg->name allocation failed for '%s'", new_name);
return 0;
}
list_iterate_items(pvl, &vg->pvs) {
if (!(pvl->pv->vg_name = pool_strdup(mem, new_name))) {
if (!(pvl->pv->vg_name = dm_pool_strdup(mem, new_name))) {
log_error("pv->vg_name allocation failed for '%s'",
dev_name(pvl->pv->dev));
return 0;
@ -220,11 +219,11 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name,
int pv_count, char **pv_names)
{
struct volume_group *vg;
struct pool *mem = cmd->mem;
struct dm_pool *mem = cmd->mem;
int consistent = 0;
int old_partial;
if (!(vg = pool_zalloc(mem, sizeof(*vg)))) {
if (!(vg = dm_pool_zalloc(mem, sizeof(*vg)))) {
stack;
return NULL;
}
@ -248,7 +247,7 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name,
vg->cmd = cmd;
if (!(vg->name = pool_strdup(mem, vg_name))) {
if (!(vg->name = dm_pool_strdup(mem, vg_name))) {
stack;
goto bad;
}
@ -256,7 +255,7 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name,
vg->seqno = 0;
vg->status = (RESIZEABLE_VG | LVM_READ | LVM_WRITE);
vg->system_id = pool_alloc(mem, NAME_LEN);
vg->system_id = dm_pool_alloc(mem, NAME_LEN);
*vg->system_id = '\0';
vg->extent_size = extent_size;
@ -298,7 +297,7 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name,
return vg;
bad:
pool_free(mem, vg);
dm_pool_free(mem, vg);
return NULL;
}
@ -488,8 +487,8 @@ struct physical_volume *pv_create(const struct format_type *fmt,
int pvmetadatacopies,
uint64_t pvmetadatasize, struct list *mdas)
{
struct pool *mem = fmt->cmd->mem;
struct physical_volume *pv = pool_alloc(mem, sizeof(*pv));
struct dm_pool *mem = fmt->cmd->mem;
struct physical_volume *pv = dm_pool_alloc(mem, sizeof(*pv));
if (!pv) {
stack;
@ -506,7 +505,7 @@ struct physical_volume *pv_create(const struct format_type *fmt,
pv->dev = dev;
if (!(pv->vg_name = pool_zalloc(mem, NAME_LEN))) {
if (!(pv->vg_name = dm_pool_zalloc(mem, NAME_LEN))) {
stack;
goto bad;
}
@ -553,7 +552,7 @@ struct physical_volume *pv_create(const struct format_type *fmt,
return pv;
bad:
pool_free(mem, pv);
dm_pool_free(mem, pv);
return NULL;
}
@ -850,7 +849,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd)
return NULL;
}
if (!(vg = pool_zalloc(cmd->mem, sizeof(*vg)))) {
if (!(vg = dm_pool_zalloc(cmd->mem, sizeof(*vg)))) {
log_error("vg allocation failed");
return NULL;
}
@ -858,7 +857,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd)
list_init(&vg->lvs);
list_init(&vg->tags);
vg->cmd = cmd;
if (!(vg->name = pool_strdup(cmd->mem, ORPHAN))) {
if (!(vg->name = dm_pool_strdup(cmd->mem, ORPHAN))) {
log_error("vg name allocation failed");
return NULL;
}
@ -867,7 +866,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd)
if (!(pv = pv_read(cmd, dev_name(info->dev), NULL, NULL, 1))) {
continue;
}
if (!(pvl = pool_zalloc(cmd->mem, sizeof(*pvl)))) {
if (!(pvl = dm_pool_zalloc(cmd->mem, sizeof(*pvl)))) {
log_error("pv_list allocation failed");
return NULL;
}
@ -1200,7 +1199,7 @@ struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name,
if (label_sector && *label_sector)
*label_sector = label->sector;
if (!(pv = pool_zalloc(cmd->mem, sizeof(*pv)))) {
if (!(pv = dm_pool_zalloc(cmd->mem, sizeof(*pv)))) {
log_error("pv allocation for '%s' failed", pv_name);
return NULL;
}
@ -1246,7 +1245,7 @@ struct list *get_pvs(struct cmd_context *cmd)
lvmcache_label_scan(cmd, 0);
if (!(results = pool_alloc(cmd->mem, sizeof(*results)))) {
if (!(results = dm_pool_alloc(cmd->mem, sizeof(*results)))) {
log_error("PV list allocation failed");
return NULL;
}

View File

@ -283,7 +283,7 @@ int insert_pvmove_mirrors(struct cmd_context *cmd,
/* First time, add LV to list of LVs affected */
if (!lv_used) {
if (!(lvl = pool_alloc(cmd->mem, sizeof(*lvl)))) {
if (!(lvl = dm_pool_alloc(cmd->mem, sizeof(*lvl)))) {
log_error("lv_list alloc failed");
return 0;
}
@ -495,7 +495,7 @@ struct list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg,
struct lv_segment *seg;
uint32_t s;
if (!(lvs = pool_alloc(cmd->mem, sizeof(*lvs)))) {
if (!(lvs = dm_pool_alloc(cmd->mem, sizeof(*lvs)))) {
log_error("lvs list alloc failed");
return NULL;
}
@ -514,7 +514,7 @@ struct list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg,
if (seg_type(seg, s) != AREA_LV ||
seg_lv(seg, s) != lv)
continue;
if (!(lvl = pool_alloc(cmd->mem, sizeof(*lvl)))) {
if (!(lvl = dm_pool_alloc(cmd->mem, sizeof(*lvl)))) {
log_error("lv_list alloc failed");
return NULL;
}

View File

@ -13,10 +13,9 @@
*/
#ifndef _LVM_PV_ALLOC_H
#include "pool.h"
int alloc_pv_segment_whole_pv(struct pool *mem, struct physical_volume *pv);
int peg_dup(struct pool *mem, struct list *peg_new, struct list *peg_old);
int alloc_pv_segment_whole_pv(struct dm_pool *mem, struct physical_volume *pv);
int peg_dup(struct dm_pool *mem, struct list *peg_new, struct list *peg_old);
struct pv_segment *assign_peg_to_lvseg(struct physical_volume *pv, uint32_t pe,
uint32_t area_len,
struct lv_segment *seg,

View File

@ -14,12 +14,11 @@
*/
#include "lib.h"
#include "pool.h"
#include "metadata.h"
#include "pv_alloc.h"
#include "toolcontext.h"
static struct pv_segment *_alloc_pv_segment(struct pool *mem,
static struct pv_segment *_alloc_pv_segment(struct dm_pool *mem,
struct physical_volume *pv,
uint32_t pe, uint32_t len,
struct lv_segment *lvseg,
@ -27,7 +26,7 @@ static struct pv_segment *_alloc_pv_segment(struct pool *mem,
{
struct pv_segment *peg;
if (!(peg = pool_zalloc(mem, sizeof(*peg)))) {
if (!(peg = dm_pool_zalloc(mem, sizeof(*peg)))) {
log_error("pv_segment allocation failed");
return NULL;
}
@ -43,7 +42,7 @@ static struct pv_segment *_alloc_pv_segment(struct pool *mem,
return peg;
}
int alloc_pv_segment_whole_pv(struct pool *mem, struct physical_volume *pv)
int alloc_pv_segment_whole_pv(struct dm_pool *mem, struct physical_volume *pv)
{
struct pv_segment *peg;
@ -61,7 +60,7 @@ int alloc_pv_segment_whole_pv(struct pool *mem, struct physical_volume *pv)
return 1;
}
int peg_dup(struct pool *mem, struct list *peg_new, struct list *peg_old)
int peg_dup(struct dm_pool *mem, struct list *peg_new, struct list *peg_old)
{
struct pv_segment *peg, *pego;

View File

@ -15,7 +15,6 @@
#include "lib.h"
#include "pv_map.h"
#include "hash.h"
#include "pv_alloc.h"
/*
@ -33,12 +32,12 @@ static void _insert_area(struct list *head, struct pv_area *a)
list_add(&pva->list, &a->list);
}
static int _create_single_area(struct pool *mem, struct pv_map *pvm,
static int _create_single_area(struct dm_pool *mem, struct pv_map *pvm,
uint32_t start, uint32_t length)
{
struct pv_area *pva;
if (!(pva = pool_zalloc(mem, sizeof(*pva)))) {
if (!(pva = dm_pool_zalloc(mem, sizeof(*pva)))) {
stack;
return 0;
}
@ -53,7 +52,7 @@ static int _create_single_area(struct pool *mem, struct pv_map *pvm,
return 1;
}
static int _create_alloc_areas_for_pv(struct pool *mem, struct pv_map *pvm,
static int _create_alloc_areas_for_pv(struct dm_pool *mem, struct pv_map *pvm,
uint32_t start, uint32_t count)
{
struct pv_segment *peg;
@ -98,7 +97,7 @@ static int _create_alloc_areas_for_pv(struct pool *mem, struct pv_map *pvm,
return 1;
}
static int _create_all_areas_for_pv(struct pool *mem, struct pv_map *pvm,
static int _create_all_areas_for_pv(struct dm_pool *mem, struct pv_map *pvm,
struct list *pe_ranges)
{
struct pe_range *aa;
@ -125,7 +124,7 @@ static int _create_all_areas_for_pv(struct pool *mem, struct pv_map *pvm,
return 1;
}
static int _create_maps(struct pool *mem, struct list *pvs, struct list *pvms)
static int _create_maps(struct dm_pool *mem, struct list *pvs, struct list *pvms)
{
struct pv_map *pvm;
struct pv_list *pvl;
@ -134,7 +133,7 @@ static int _create_maps(struct pool *mem, struct list *pvs, struct list *pvms)
if (!(pvl->pv->status & ALLOCATABLE_PV))
continue;
if (!(pvm = pool_zalloc(mem, sizeof(*pvm)))) {
if (!(pvm = dm_pool_zalloc(mem, sizeof(*pvm)))) {
stack;
return 0;
}
@ -156,12 +155,12 @@ static int _create_maps(struct pool *mem, struct list *pvs, struct list *pvms)
/*
* Create list of PV areas available for this particular allocation
*/
struct list *create_pv_maps(struct pool *mem, struct volume_group *vg,
struct list *create_pv_maps(struct dm_pool *mem, struct volume_group *vg,
struct list *allocatable_pvs)
{
struct list *pvms;
if (!(pvms = pool_zalloc(mem, sizeof(*pvms)))) {
if (!(pvms = dm_pool_zalloc(mem, sizeof(*pvms)))) {
log_error("create_pv_maps alloc failed");
return NULL;
}
@ -171,7 +170,7 @@ struct list *create_pv_maps(struct pool *mem, struct volume_group *vg,
if (!_create_maps(mem, allocatable_pvs, pvms)) {
log_error("Couldn't create physical volume maps in %s",
vg->name);
pool_free(mem, pvms);
dm_pool_free(mem, pvms);
return NULL;
}

View File

@ -17,8 +17,6 @@
#define _LVM_PV_MAP_H
#include "metadata.h"
#include "bitset.h"
#include "pool.h"
/*
* The in core rep. only stores a mapping from
@ -46,7 +44,7 @@ struct pv_map {
/*
* Find intersection between available_pvs and free space in VG
*/
struct list *create_pv_maps(struct pool *mem, struct volume_group *vg,
struct list *create_pv_maps(struct dm_pool *mem, struct volume_group *vg,
struct list *allocatable_pvs);
void consume_pv_area(struct pv_area *area, uint32_t to_go);

View File

@ -22,7 +22,6 @@ struct config_tree;
struct lv_segment;
struct formatter;
struct config_node;
struct hash_table;
struct dev_manager;
/* Feature flags */
@ -62,16 +61,16 @@ struct segtype_handler {
uint32_t *area_count);
int (*text_import) (struct lv_segment * seg,
const struct config_node * sn,
struct hash_table * pv_hash);
struct dm_hash_table * pv_hash);
int (*merge_segments) (struct lv_segment * seg1,
struct lv_segment * seg2);
int (*compose_target_line) (struct dev_manager * dm, struct pool * mem,
int (*compose_target_line) (struct dev_manager * dm, struct dm_pool * mem,
struct config_tree * cft,
void **target_state,
struct lv_segment * seg, char *params,
size_t paramsize, const char **target,
int *pos, uint32_t *pvmove_mirror_count);
int (*target_percent) (void **target_state, struct pool * mem,
int (*target_percent) (void **target_state, struct dm_pool * mem,
struct config_tree * cft,
struct lv_segment * seg, char *params,
uint64_t *total_numerator,

View File

@ -14,8 +14,6 @@
*/
#include "lib.h"
#include "pool.h"
#include "list.h"
#include "toolcontext.h"
#include "metadata.h"
#include "segtype.h"
@ -78,7 +76,7 @@ static int _text_import_area_count(struct config_node *sn, uint32_t *area_count)
}
static int _text_import(struct lv_segment *seg, const struct config_node *sn,
struct hash_table *pv_hash)
struct dm_hash_table *pv_hash)
{
const struct config_node *cn;
char *logname = NULL;
@ -147,12 +145,12 @@ static int _text_export(const struct lv_segment *seg, struct formatter *f)
}
#ifdef DEVMAPPER_SUPPORT
static struct mirror_state *_init_target(struct pool *mem,
static struct mirror_state *_init_target(struct dm_pool *mem,
struct config_tree *cft)
{
struct mirror_state *mirr_state;
if (!(mirr_state = pool_alloc(mem, sizeof(*mirr_state)))) {
if (!(mirr_state = dm_pool_alloc(mem, sizeof(*mirr_state)))) {
log_error("struct mirr_state allocation failed");
return NULL;
}
@ -206,7 +204,7 @@ static int _compose_log_line(struct dev_manager *dm, struct lv_segment *seg,
return 1;
}
static int _compose_target_line(struct dev_manager *dm, struct pool *mem,
static int _compose_target_line(struct dev_manager *dm, struct dm_pool *mem,
struct config_tree *cft, void **target_state,
struct lv_segment *seg, char *params,
size_t paramsize, const char **target, int *pos,
@ -272,7 +270,7 @@ static int _compose_target_line(struct dev_manager *dm, struct pool *mem,
areas);
}
static int _target_percent(void **target_state, struct pool *mem,
static int _target_percent(void **target_state, struct dm_pool *mem,
struct config_tree *cft, struct lv_segment *seg,
char *params, uint64_t *total_numerator,
uint64_t *total_denominator, float *percent)
@ -291,7 +289,7 @@ static int _target_percent(void **target_state, struct pool *mem,
/* Status line: <#mirrors> (maj:min)+ <synced>/<total_regions> */
log_debug("Mirror status: %s", params);
if (sscanf(pos, "%u %n", mirror_count, used) != 1) {
if (sscanf(pos, "%u %n", &mirror_count, &used) != 1) {
log_error("Failure parsing mirror status mirror count: %s",
params);
return 0;
@ -339,7 +337,7 @@ static int _target_present(void)
static void _destroy(const struct segment_type *segtype)
{
dbg_free((void *) segtype);
dm_free((void *) segtype);
}
static struct segtype_handler _mirrored_ops = {
@ -363,7 +361,7 @@ struct segment_type *init_segtype(struct cmd_context *cmd);
struct segment_type *init_segtype(struct cmd_context *cmd)
#endif
{
struct segment_type *segtype = dbg_malloc(sizeof(*segtype));
struct segment_type *segtype = dm_malloc(sizeof(*segtype));
if (!segtype) {
stack;

View File

@ -24,7 +24,9 @@
#define _FILE_OFFSET_BITS 64
#include "log.h"
#include "dbg_malloc.h"
#include "intl.h"
#include "lvm-types.h"
#include <libdevmapper.h>
#endif

View File

@ -146,7 +146,7 @@ static int _create_dir_recursive(const char *dir)
log_verbose("Creating directory \"%s\"", dir);
/* Create parent directories */
orig = s = dbg_strdup(dir);
orig = s = dm_strdup(dir);
while ((s = strchr(s, '/')) != NULL) {
*s = '\0';
if (*orig) {
@ -154,13 +154,13 @@ static int _create_dir_recursive(const char *dir)
if (rc < 0 && errno != EEXIST) {
if (errno != EROFS)
log_sys_error("mkdir", orig);
dbg_free(orig);
dm_free(orig);
return 0;
}
}
*s++ = '/';
}
dbg_free(orig);
dm_free(orig);
/* Create final directory */
rc = mkdir(dir, 0777);
@ -215,7 +215,7 @@ void sync_dir(const char *file)
int fd;
char *dir, *c;
if (!(dir = dbg_strdup(file))) {
if (!(dir = dm_strdup(file))) {
log_error("sync_dir failed in strdup");
return;
}
@ -242,5 +242,5 @@ void sync_dir(const char *file)
close(fd);
out:
dbg_free(dir);
dm_free(dir);
}

View File

@ -16,7 +16,6 @@
#include "lib.h"
#include "lvm-types.h"
#include "lvm-string.h"
#include "pool.h"
#include <ctype.h>
@ -131,7 +130,7 @@ static void _quote_hyphens(char **out, const char *src)
/*
* <vg>-<lv>-<layer> or if !layer just <vg>-<lv>.
*/
char *build_dm_name(struct pool *mem, const char *vg,
char *build_dm_name(struct dm_pool *mem, const char *vg,
const char *lv, const char *layer)
{
size_t len = 1;
@ -148,7 +147,7 @@ char *build_dm_name(struct pool *mem, const char *vg,
len += hyphens;
if (!(r = pool_alloc(mem, len))) {
if (!(r = dm_pool_alloc(mem, len))) {
stack;
return NULL;
}
@ -194,10 +193,10 @@ static char *_unquote(char *component)
return (c + 1);
}
int split_dm_name(struct pool *mem, const char *dmname,
int split_dm_name(struct dm_pool *mem, const char *dmname,
char **vgname, char **lvname, char **layer)
{
if (!(*vgname = pool_strdup(mem, dmname)))
if (!(*vgname = dm_pool_strdup(mem, dmname)))
return 0;
_unquote(*layer = _unquote(*lvname = _unquote(*vgname)));

View File

@ -34,10 +34,10 @@ int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...);
int split_words(char *buffer, unsigned max, char **argv);
char *build_dm_name(struct pool *mem, const char *vg,
char *build_dm_name(struct dm_pool *mem, const char *vg,
const char *lv, const char *layer);
int split_dm_name(struct pool *mem, const char *dmname,
int split_dm_name(struct dm_pool *mem, const char *dmname,
char **vgname, char **lvname, char **layer);
#endif

View File

@ -1,247 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lib.h"
#include "lvm-types.h"
#include "dbg_malloc.h"
#include <stdarg.h>
char *dbg_strdup(const char *str)
{
char *ret = dbg_malloc(strlen(str) + 1);
if (ret)
strcpy(ret, str);
return ret;
}
#ifdef DEBUG_MEM
struct memblock {
struct memblock *prev, *next; /* All allocated blocks are linked */
size_t length; /* Size of the requested block */
int id; /* Index of the block */
const char *file; /* File that allocated */
int line; /* Line that allocated */
void *magic; /* Address of this block */
};
static struct {
unsigned block_serialno;/* Non-decreasing serialno of block */
unsigned blocks_allocated; /* Current number of blocks allocated */
unsigned blocks_max; /* Max no of concurrently-allocated blocks */
unsigned int bytes, mbytes;
} _mem_stats = {
0, 0, 0, 0, 0};
static struct memblock *_head = 0;
static struct memblock *_tail = 0;
void *malloc_aux(size_t s, const char *file, int line)
{
struct memblock *nb;
size_t tsize = s + sizeof(*nb) + sizeof(unsigned long);
if (s > 50000000) {
log_error("Huge memory allocation (size %" PRIsize_t
") rejected - metadata corruption?", s);
return 0;
}
if (!(nb = malloc(tsize))) {
log_error("couldn't allocate any memory, size = %" PRIsize_t,
s);
return 0;
}
/* set up the file and line info */
nb->file = file;
nb->line = line;
#ifdef BOUNDS_CHECK
bounds_check();
#endif
/* setup fields */
nb->magic = nb + 1;
nb->length = s;
nb->id = ++_mem_stats.block_serialno;
nb->next = 0;
nb->prev = _tail;
/* link to tail of the list */
if (!_head)
_head = _tail = nb;
else {
_tail->next = nb;
_tail = nb;
}
/* stomp a pretty pattern across the new memory
and fill in the boundary bytes */
{
char *ptr = (char *) (nb + 1);
size_t i;
for (i = 0; i < s; i++)
*ptr++ = i & 0x1 ? (char) 0xba : (char) 0xbe;
for (i = 0; i < sizeof(unsigned long); i++)
*ptr++ = (char) nb->id;
}
_mem_stats.blocks_allocated++;
if (_mem_stats.blocks_allocated > _mem_stats.blocks_max)
_mem_stats.blocks_max = _mem_stats.blocks_allocated;
_mem_stats.bytes += s;
if (_mem_stats.bytes > _mem_stats.mbytes)
_mem_stats.mbytes = _mem_stats.bytes;
/* log_debug("Allocated: %u %u %u", nb->id, _mem_stats.blocks_allocated,
_mem_stats.bytes); */
return nb + 1;
}
void free_aux(void *p)
{
char *ptr;
size_t i;
struct memblock *mb = ((struct memblock *) p) - 1;
if (!p)
return;
#ifdef BOUNDS_CHECK
bounds_check();
#endif
/* sanity check */
assert(mb->magic == p);
/* check data at the far boundary */
ptr = ((char *) mb) + sizeof(struct memblock) + mb->length;
for (i = 0; i < sizeof(unsigned long); i++)
if (*ptr++ != (char) mb->id)
assert(!"Damage at far end of block");
/* have we freed this before ? */
assert(mb->id != 0);
mb->id = 0;
/* stomp a different pattern across the memory */
ptr = ((char *) mb) + sizeof(struct memblock);
for (i = 0; i < mb->length; i++)
*ptr++ = i & 1 ? (char) 0xde : (char) 0xad;
/* unlink */
if (mb->prev)
mb->prev->next = mb->next;
else
_head = mb->next;
if (mb->next)
mb->next->prev = mb->prev;
else
_tail = mb->prev;
assert(_mem_stats.blocks_allocated);
_mem_stats.blocks_allocated--;
_mem_stats.bytes -= mb->length;
/* free the memory */
free(mb);
}
void *realloc_aux(void *p, unsigned int s, const char *file, int line)
{
void *r;
struct memblock *mb = ((struct memblock *) p) - 1;
r = malloc_aux(s, file, line);
if (p) {
memcpy(r, p, mb->length);
free_aux(p);
}
return r;
}
int dump_memory(void)
{
unsigned long tot = 0;
struct memblock *mb;
char str[32];
size_t c;
if (_head)
log_very_verbose("You have a memory leak:");
for (mb = _head; mb; mb = mb->next) {
for (c = 0; c < sizeof(str) - 1; c++) {
if (c >= mb->length)
str[c] = ' ';
else if (*(char *)(mb->magic + c) == '\0')
str[c] = '\0';
else if (*(char *)(mb->magic + c) < ' ')
str[c] = '?';
else
str[c] = *(char *)(mb->magic + c);
}
str[sizeof(str) - 1] = '\0';
print_log(_LOG_INFO, mb->file, mb->line,
"block %d at %p, size %" PRIsize_t "\t [%s]",
mb->id, mb->magic, mb->length, str);
tot += mb->length;
}
if (_head)
log_very_verbose("%ld bytes leaked in total", tot);
return 1;
}
void bounds_check(void)
{
struct memblock *mb = _head;
while (mb) {
size_t i;
char *ptr = ((char *) (mb + 1)) + mb->length;
for (i = 0; i < sizeof(unsigned long); i++)
if (*ptr++ != (char) mb->id)
assert(!"Memory smash");
mb = mb->next;
}
}
#else
void *malloc_aux(size_t s, const char *file, int line)
{
if (s > 50000000) {
log_error("Huge memory allocation (size %" PRIsize_t
") rejected - metadata corruption?", s);
return 0;
}
return malloc(s);
}
#endif

View File

@ -1,47 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LVM_DBG_MALLOC_H
#define _LVM_DBG_MALLOC_H
#include "lvm-types.h"
#include <stdlib.h>
#include <string.h>
void *malloc_aux(size_t s, const char *file, int line);
#define dbg_malloc(s) malloc_aux((s), __FILE__, __LINE__)
char *dbg_strdup(const char *str);
#ifdef DEBUG_MEM
void free_aux(void *p);
void *realloc_aux(void *p, unsigned int s, const char *file, int line);
int dump_memory(void);
void bounds_check(void);
# define dbg_free(p) free_aux(p)
# define dbg_realloc(p, s) realloc_aux(p, s, __FILE__, __LINE__)
#else
# define dbg_free(p) free(p)
# define dbg_realloc(p, s) realloc(p, s)
# define dump_memory()
# define bounds_check()
#endif
#endif

View File

@ -15,7 +15,6 @@
#include "lib.h"
#include "memlock.h"
#include "pool.h"
#include "defaults.h"
#include "config.h"
#include "toolcontext.h"

View File

@ -1,263 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lib.h"
#include "pool.h"
struct block {
struct block *next;
size_t size;
void *data;
};
typedef struct {
unsigned block_serialno; /* Non-decreasing serialno of block */
unsigned blocks_allocated; /* Current number of blocks allocated */
unsigned blocks_max; /* Max no of concurrently-allocated blocks */
unsigned int bytes, maxbytes;
} pool_stats;
struct pool {
const char *name;
int begun;
struct block *object;
struct block *blocks;
struct block *tail;
pool_stats stats;
};
/* by default things come out aligned for doubles */
#define DEFAULT_ALIGNMENT __alignof__ (double)
struct pool *pool_create(const char *name, size_t chunk_hint)
{
struct pool *mem = dbg_malloc(sizeof(*mem));
if (!mem) {
log_error("Couldn't create memory pool %s (size %"
PRIsize_t ")", name, sizeof(*mem));
return NULL;
}
mem->name = name;
mem->begun = 0;
mem->object = 0;
mem->blocks = mem->tail = NULL;
mem->stats.block_serialno = 0;
mem->stats.blocks_allocated = 0;
mem->stats.blocks_max = 0;
mem->stats.bytes = 0;
mem->stats.maxbytes = 0;
#ifdef DEBUG_POOL
log_debug("Created mempool %s", name);
#endif
return mem;
}
static void _free_blocks(struct pool *p, struct block *b)
{
struct block *n;
while (b) {
p->stats.bytes -= b->size;
p->stats.blocks_allocated--;
n = b->next;
dbg_free(b->data);
dbg_free(b);
b = n;
}
}
static void _pool_stats(struct pool *p, const char *action)
{
#ifdef DEBUG_POOL
log_debug("%s mempool %s: %u/%u bytes, %u/%u blocks, "
"%u allocations)", action, p->name, p->stats.bytes,
p->stats.maxbytes, p->stats.blocks_allocated,
p->stats.blocks_max, p->stats.block_serialno);
#else
;
#endif
}
void pool_destroy(struct pool *p)
{
_pool_stats(p, "Destroying");
_free_blocks(p, p->blocks);
dbg_free(p);
}
void *pool_alloc(struct pool *p, size_t s)
{
return pool_alloc_aligned(p, s, DEFAULT_ALIGNMENT);
}
static void _append_block(struct pool *p, struct block *b)
{
if (p->tail) {
p->tail->next = b;
p->tail = b;
} else
p->blocks = p->tail = b;
p->stats.block_serialno++;
p->stats.blocks_allocated++;
if (p->stats.blocks_allocated > p->stats.blocks_max)
p->stats.blocks_max = p->stats.blocks_allocated;
p->stats.bytes += b->size;
if (p->stats.bytes > p->stats.maxbytes)
p->stats.maxbytes = p->stats.bytes;
}
static struct block *_new_block(size_t s, unsigned alignment)
{
static const char *_oom = "Out of memory";
/* FIXME: I'm currently ignoring the alignment arg. */
size_t len = sizeof(struct block) + s;
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) {
log_err(_oom);
return NULL;
}
if (!(b->data = dbg_malloc(s))) {
log_err(_oom);
dbg_free(b);
return NULL;
}
b->next = NULL;
b->size = s;
return b;
}
void *pool_alloc_aligned(struct pool *p, size_t s, unsigned alignment)
{
struct block *b = _new_block(s, alignment);
if (!b)
return NULL;
_append_block(p, b);
return b->data;
}
void pool_empty(struct pool *p)
{
_pool_stats(p, "Emptying");
_free_blocks(p, p->blocks);
p->blocks = p->tail = NULL;
}
void pool_free(struct pool *p, void *ptr)
{
struct block *b, *prev = NULL;
_pool_stats(p, "Freeing (before)");
for (b = p->blocks; b; b = b->next) {
if (b->data == ptr)
break;
prev = b;
}
/*
* If this fires then you tried to free a
* pointer that either wasn't from this
* pool, or isn't the start of a block.
*/
assert(b);
_free_blocks(p, b);
if (prev) {
p->tail = prev;
prev->next = NULL;
} else
p->blocks = p->tail = NULL;
_pool_stats(p, "Freeing (after)");
}
int pool_begin_object(struct pool *p, size_t init_size)
{
assert(!p->begun);
p->begun = 1;
return 1;
}
int pool_grow_object(struct pool *p, const void *buffer, size_t delta)
{
struct block *new;
size_t size = delta;
assert(p->begun);
if (p->object)
size += p->object->size;
if (!(new = _new_block(size, DEFAULT_ALIGNMENT))) {
log_err("Couldn't extend object.");
return 0;
}
if (p->object) {
memcpy(new->data, p->object->data, p->object->size);
dbg_free(p->object->data);
dbg_free(p->object);
}
p->object = new;
memcpy(new->data + size - delta, buffer, delta);
return 1;
}
void *pool_end_object(struct pool *p)
{
assert(p->begun);
_append_block(p, p->object);
p->begun = 0;
p->object = NULL;
return p->tail->data;
}
void pool_abandon_object(struct pool *p)
{
assert(p->begun);
dbg_free(p->object);
p->begun = 0;
p->object = NULL;
}

View File

@ -1,236 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lib.h"
#include "pool.h"
#include "lvm-types.h"
struct chunk {
char *begin, *end;
struct chunk *prev;
};
struct pool {
struct chunk *chunk, *spare_chunk; /* spare_chunk is a one entry free
list to stop 'bobbling' */
size_t chunk_size;
size_t object_len;
unsigned object_alignment;
};
void _align_chunk(struct chunk *c, unsigned alignment);
struct chunk *_new_chunk(struct pool *p, size_t s);
/* by default things come out aligned for doubles */
#define DEFAULT_ALIGNMENT __alignof__ (double)
struct pool *pool_create(const char *name, size_t chunk_hint)
{
size_t new_size = 1024;
struct pool *p = dbg_malloc(sizeof(*p));
if (!p) {
log_error("Couldn't create memory pool %s (size %"
PRIsize_t ")", name, sizeof(*p));
return 0;
}
memset(p, 0, sizeof(*p));
/* round chunk_hint up to the next power of 2 */
p->chunk_size = chunk_hint + sizeof(struct chunk);
while (new_size < p->chunk_size)
new_size <<= 1;
p->chunk_size = new_size;
return p;
}
void pool_destroy(struct pool *p)
{
struct chunk *c, *pr;
dbg_free(p->spare_chunk);
c = p->chunk;
while (c) {
pr = c->prev;
dbg_free(c);
c = pr;
}
dbg_free(p);
}
void *pool_alloc(struct pool *p, size_t s)
{
return pool_alloc_aligned(p, s, DEFAULT_ALIGNMENT);
}
void *pool_alloc_aligned(struct pool *p, size_t s, unsigned alignment)
{
struct chunk *c = p->chunk;
void *r;
/* realign begin */
if (c)
_align_chunk(c, alignment);
/* have we got room ? */
if (!c || (c->begin > c->end) || (c->end - c->begin < s)) {
/* allocate new chunk */
int needed = s + alignment + sizeof(struct chunk);
c = _new_chunk(p, (needed > p->chunk_size) ?
needed : p->chunk_size);
if (!c)
return NULL;
_align_chunk(c, alignment);
}
r = c->begin;
c->begin += s;
return r;
}
void pool_empty(struct pool *p)
{
struct chunk *c;
for (c = p->chunk; c && c->prev; c = c->prev)
;
if (c)
pool_free(p, (char *) (c + 1));
}
void pool_free(struct pool *p, void *ptr)
{
struct chunk *c = p->chunk;
while (c) {
if (((char *) c < (char *) ptr) &&
((char *) c->end > (char *) ptr)) {
c->begin = ptr;
break;
}
if (p->spare_chunk)
dbg_free(p->spare_chunk);
p->spare_chunk = c;
c = c->prev;
}
if (!c)
log_error("Internal error: pool_free asked to free pointer "
"not in pool");
else
p->chunk = c;
}
int pool_begin_object(struct pool *p, size_t hint)
{
struct chunk *c = p->chunk;
const size_t align = DEFAULT_ALIGNMENT;
p->object_len = 0;
p->object_alignment = align;
if (c)
_align_chunk(c, align);
if (!c || (c->begin > c->end) || (c->end - c->begin < hint)) {
/* allocate a new chunk */
c = _new_chunk(p,
hint > (p->chunk_size - sizeof(struct chunk)) ?
hint + sizeof(struct chunk) + align :
p->chunk_size);
if (!c)
return 0;
_align_chunk(c, align);
}
return 1;
}
int pool_grow_object(struct pool *p, const void *extra, size_t n)
{
struct chunk *c = p->chunk, *nc;
if (c->end - (c->begin + p->object_len) < n) {
/* move into a new chunk */
if (p->object_len + n > (p->chunk_size / 2))
nc = _new_chunk(p, (p->object_len + n) * 2);
else
nc = _new_chunk(p, p->chunk_size);
if (!nc)
return 0;
_align_chunk(p->chunk, p->object_alignment);
memcpy(p->chunk->begin, c->begin, p->object_len);
c = p->chunk;
}
memcpy(c->begin + p->object_len, extra, n);
p->object_len += n;
return 1;
}
void *pool_end_object(struct pool *p)
{
struct chunk *c = p->chunk;
void *r = c->begin;
c->begin += p->object_len;
p->object_len = 0u;
p->object_alignment = DEFAULT_ALIGNMENT;
return r;
}
void pool_abandon_object(struct pool *p)
{
p->object_len = 0;
p->object_alignment = DEFAULT_ALIGNMENT;
}
void _align_chunk(struct chunk *c, unsigned alignment)
{
c->begin += alignment - ((unsigned long) c->begin & (alignment - 1));
}
struct chunk *_new_chunk(struct pool *p, size_t s)
{
struct chunk *c;
if (p->spare_chunk &&
((p->spare_chunk->end - (char *) p->spare_chunk) >= s)) {
/* reuse old chunk */
c = p->spare_chunk;
p->spare_chunk = 0;
} else {
if (!(c = dbg_malloc(s))) {
log_err("Out of memory. Requested %" PRIsize_t
" bytes.", s);
return NULL;
}
c->end = (char *) c + s;
}
c->prev = p->chunk;
c->begin = (char *) (c + 1);
p->chunk = c;
return c;
}

View File

@ -1,52 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef DEBUG_POOL
#include "pool-debug.c"
#else
#include "pool-fast.c"
#endif
char *pool_strdup(struct pool *p, const char *str)
{
char *ret = pool_alloc(p, strlen(str) + 1);
if (ret)
strcpy(ret, str);
return ret;
}
char *pool_strndup(struct pool *p, const char *str, size_t n)
{
char *ret = pool_alloc(p, n + 1);
if (ret) {
strncpy(ret, str, n);
ret[n] = '\0';
}
return ret;
}
void *pool_zalloc(struct pool *p, size_t s)
{
void *ptr = pool_alloc(p, s);
if (ptr)
memset(ptr, 0, s);
return ptr;
}

View File

@ -1,121 +0,0 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License v.2.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LVM_POOL_H
#define _LVM_POOL_H
#include <string.h>
#include <stdlib.h>
/*
* The pool allocator is useful when you are going to allocate
* lots of memory, use the memory for a bit, and then free the
* memory in one go. A surprising amount of code has this usage
* profile.
*
* You should think of the pool as an infinite, contiguous chunk
* of memory. The front of this chunk of memory contains
* allocated objects, the second half is free. pool_alloc grabs
* the next 'size' bytes from the free half, in effect moving it
* into the allocated half. This operation is very efficient.
*
* pool_free frees the allocated object *and* all objects
* allocated after it. It is important to note this semantic
* difference from malloc/free. This is also extremely
* efficient, since a single pool_free can dispose of a large
* complex object.
*
* pool_destroy frees all allocated memory.
*
* eg, If you are building a binary tree in your program, and
* know that you are only ever going to insert into your tree,
* and not delete (eg, maintaining a symbol table for a
* compiler). You can create yourself a pool, allocate the nodes
* from it, and when the tree becomes redundant call pool_destroy
* (no nasty iterating through the tree to free nodes).
*
* eg, On the other hand if you wanted to repeatedly insert and
* remove objects into the tree, you would be better off
* allocating the nodes from a free list; you cannot free a
* single arbitrary node with pool.
*/
struct pool;
/* constructor and destructor */
struct pool *pool_create(const char *name, size_t chunk_hint);
void pool_destroy(struct pool *p);
/* simple allocation/free routines */
void *pool_alloc(struct pool *p, size_t s);
void *pool_alloc_aligned(struct pool *p, size_t s, unsigned alignment);
void pool_empty(struct pool *p);
void pool_free(struct pool *p, void *ptr);
/*
* Object building routines:
*
* These allow you to 'grow' an object, useful for
* building strings, or filling in dynamic
* arrays.
*
* It's probably best explained with an example:
*
* char *build_string(struct pool *mem)
* {
* int i;
* char buffer[16];
*
* if (!pool_begin_object(mem, 128))
* return NULL;
*
* for (i = 0; i < 50; i++) {
* snprintf(buffer, sizeof(buffer), "%d, ", i);
* if (!pool_grow_object(mem, buffer, strlen(buffer)))
* goto bad;
* }
*
* // add null
* if (!pool_grow_object(mem, "\0", 1))
* goto bad;
*
* return pool_end_object(mem);
*
* bad:
*
* pool_abandon_object(mem);
* return NULL;
*}
*
* So start an object by calling pool_begin_object
* with a guess at the final object size - if in
* doubt make the guess too small.
*
* Then append chunks of data to your object with
* pool_grow_object. Finally get your object with
* a call to pool_end_object.
*
*/
int pool_begin_object(struct pool *p, size_t hint);
int pool_grow_object(struct pool *p, const void *extra, size_t delta);
void *pool_end_object(struct pool *p);
void pool_abandon_object(struct pool *p);
/* utilities */
char *pool_strdup(struct pool *p, const char *str);
char *pool_strndup(struct pool *p, const char *str, size_t n);
void *pool_zalloc(struct pool *p, size_t s);
#endif

View File

@ -17,7 +17,6 @@
#include "matcher.h"
#include "parse_rx.h"
#include "ttree.h"
#include "bitset.h"
struct dfa_state {
int final;
@ -26,7 +25,7 @@ struct dfa_state {
struct state_queue {
struct dfa_state *s;
bitset_t bits;
dm_bitset_t bits;
struct state_queue *next;
};
@ -35,7 +34,7 @@ struct matcher { /* Instance variables for the lexer */
unsigned num_nodes;
int nodes_entered;
struct rx_node **nodes;
struct pool *scratch, *mem;
struct dm_pool *scratch, *mem;
};
#define TARGET_TRANS '\0'
@ -72,9 +71,9 @@ static void _create_bitsets(struct matcher *m)
for (i = 0; i < m->num_nodes; i++) {
struct rx_node *n = m->nodes[i];
n->firstpos = bitset_create(m->scratch, m->num_nodes);
n->lastpos = bitset_create(m->scratch, m->num_nodes);
n->followpos = bitset_create(m->scratch, m->num_nodes);
n->firstpos = dm_bitset_create(m->scratch, m->num_nodes);
n->lastpos = dm_bitset_create(m->scratch, m->num_nodes);
n->followpos = dm_bitset_create(m->scratch, m->num_nodes);
}
}
@ -88,48 +87,48 @@ static void _calc_functions(struct matcher *m)
c1 = rx->left;
c2 = rx->right;
if (bit(rx->charset, TARGET_TRANS))
if (dm_bit(rx->charset, TARGET_TRANS))
rx->final = final++;
switch (rx->type) {
case CAT:
if (c1->nullable)
bit_union(rx->firstpos,
dm_bit_union(rx->firstpos,
c1->firstpos, c2->firstpos);
else
bit_copy(rx->firstpos, c1->firstpos);
dm_bit_copy(rx->firstpos, c1->firstpos);
if (c2->nullable)
bit_union(rx->lastpos,
dm_bit_union(rx->lastpos,
c1->lastpos, c2->lastpos);
else
bit_copy(rx->lastpos, c2->lastpos);
dm_bit_copy(rx->lastpos, c2->lastpos);
rx->nullable = c1->nullable && c2->nullable;
break;
case PLUS:
bit_copy(rx->firstpos, c1->firstpos);
bit_copy(rx->lastpos, c1->lastpos);
dm_bit_copy(rx->firstpos, c1->firstpos);
dm_bit_copy(rx->lastpos, c1->lastpos);
rx->nullable = c1->nullable;
break;
case OR:
bit_union(rx->firstpos, c1->firstpos, c2->firstpos);
bit_union(rx->lastpos, c1->lastpos, c2->lastpos);
dm_bit_union(rx->firstpos, c1->firstpos, c2->firstpos);
dm_bit_union(rx->lastpos, c1->lastpos, c2->lastpos);
rx->nullable = c1->nullable || c2->nullable;
break;
case QUEST:
case STAR:
bit_copy(rx->firstpos, c1->firstpos);
bit_copy(rx->lastpos, c1->lastpos);
dm_bit_copy(rx->firstpos, c1->firstpos);
dm_bit_copy(rx->lastpos, c1->lastpos);
rx->nullable = 1;
break;
case CHARSET:
bit_set(rx->firstpos, i);
bit_set(rx->lastpos, i);
dm_bit_set(rx->firstpos, i);
dm_bit_set(rx->lastpos, i);
rx->nullable = 0;
break;
@ -145,9 +144,9 @@ static void _calc_functions(struct matcher *m)
switch (rx->type) {
case CAT:
for (j = 0; j < m->num_nodes; j++) {
if (bit(c1->lastpos, j)) {
if (dm_bit(c1->lastpos, j)) {
struct rx_node *n = m->nodes[j];
bit_union(n->followpos,
dm_bit_union(n->followpos,
n->followpos, c2->firstpos);
}
}
@ -156,9 +155,9 @@ static void _calc_functions(struct matcher *m)
case PLUS:
case STAR:
for (j = 0; j < m->num_nodes; j++) {
if (bit(rx->lastpos, j)) {
if (dm_bit(rx->lastpos, j)) {
struct rx_node *n = m->nodes[j];
bit_union(n->followpos,
dm_bit_union(n->followpos,
n->followpos, rx->firstpos);
}
}
@ -167,16 +166,16 @@ static void _calc_functions(struct matcher *m)
}
}
static inline struct dfa_state *_create_dfa_state(struct pool *mem)
static inline struct dfa_state *_create_dfa_state(struct dm_pool *mem)
{
return pool_zalloc(mem, sizeof(struct dfa_state));
return dm_pool_zalloc(mem, sizeof(struct dfa_state));
}
static struct state_queue *_create_state_queue(struct pool *mem,
static struct state_queue *_create_state_queue(struct dm_pool *mem,
struct dfa_state *dfa,
bitset_t bits)
dm_bitset_t bits)
{
struct state_queue *r = pool_alloc(mem, sizeof(*r));
struct state_queue *r = dm_pool_alloc(mem, sizeof(*r));
if (!r) {
stack;
@ -184,20 +183,20 @@ static struct state_queue *_create_state_queue(struct pool *mem,
}
r->s = dfa;
r->bits = bitset_create(mem, bits[0]); /* first element is the size */
bit_copy(r->bits, bits);
r->bits = dm_bitset_create(mem, bits[0]); /* first element is the size */
dm_bit_copy(r->bits, bits);
r->next = 0;
return r;
}
static int _calc_states(struct matcher *m, struct rx_node *rx)
{
unsigned iwidth = (m->num_nodes / BITS_PER_INT) + 1;
unsigned iwidth = (m->num_nodes / DM_BITS_PER_INT) + 1;
struct ttree *tt = ttree_create(m->scratch, iwidth);
struct state_queue *h, *t, *tmp;
struct dfa_state *dfa, *ldfa;
int i, a, set_bits = 0, count = 0;
bitset_t bs = bitset_create(m->scratch, m->num_nodes), dfa_bits;
dm_bitset_t bs = dm_bitset_create(m->scratch, m->num_nodes), dfa_bits;
if (!tt) {
stack;
@ -223,16 +222,16 @@ static int _calc_states(struct matcher *m, struct rx_node *rx)
h = h->next;
/* iterate through all the inputs for this state */
bit_clear_all(bs);
dm_bit_clear_all(bs);
for (a = 0; a < 256; a++) {
/* iterate through all the states in firstpos */
for (i = bit_get_first(dfa_bits);
i >= 0; i = bit_get_next(dfa_bits, i)) {
if (bit(m->nodes[i]->charset, a)) {
for (i = dm_bit_get_first(dfa_bits);
i >= 0; i = dm_bit_get_next(dfa_bits, i)) {
if (dm_bit(m->nodes[i]->charset, a)) {
if (a == TARGET_TRANS)
dfa->final = m->nodes[i]->final;
bit_union(bs, bs,
dm_bit_union(bs, bs,
m->nodes[i]->followpos);
set_bits = 1;
}
@ -259,7 +258,7 @@ static int _calc_states(struct matcher *m, struct rx_node *rx)
dfa->lookup[a] = ldfa;
set_bits = 0;
bit_clear_all(bs);
dm_bit_clear_all(bs);
}
}
}
@ -268,14 +267,14 @@ static int _calc_states(struct matcher *m, struct rx_node *rx)
return 1;
}
struct matcher *matcher_create(struct pool *mem, const char **patterns,
struct matcher *matcher_create(struct dm_pool *mem, const char **patterns,
unsigned num)
{
char *all, *ptr;
int i;
size_t len = 0;
struct rx_node *rx;
struct pool *scratch = pool_create("regex matcher", 10 * 1024);
struct dm_pool *scratch = dm_pool_create("regex matcher", 10 * 1024);
struct matcher *m;
if (!scratch) {
@ -283,7 +282,7 @@ struct matcher *matcher_create(struct pool *mem, const char **patterns,
return NULL;
}
if (!(m = pool_alloc(mem, sizeof(*m)))) {
if (!(m = dm_pool_alloc(mem, sizeof(*m)))) {
stack;
return NULL;
}
@ -294,7 +293,7 @@ struct matcher *matcher_create(struct pool *mem, const char **patterns,
for (i = 0; i < num; i++)
len += strlen(patterns[i]) + 8;
ptr = all = pool_alloc(scratch, len + 1);
ptr = all = dm_pool_alloc(scratch, len + 1);
if (!all) {
stack;
@ -316,7 +315,7 @@ struct matcher *matcher_create(struct pool *mem, const char **patterns,
m->mem = mem;
m->scratch = scratch;
m->num_nodes = _count_nodes(rx);
m->nodes = pool_alloc(scratch, sizeof(*m->nodes) * m->num_nodes);
m->nodes = dm_pool_alloc(scratch, sizeof(*m->nodes) * m->num_nodes);
if (!m->nodes) {
stack;
@ -327,14 +326,14 @@ struct matcher *matcher_create(struct pool *mem, const char **patterns,
_create_bitsets(m);
_calc_functions(m);
_calc_states(m, rx);
pool_destroy(scratch);
dm_pool_destroy(scratch);
m->scratch = NULL;
return m;
bad:
pool_destroy(scratch);
pool_destroy(mem);
dm_pool_destroy(scratch);
dm_pool_destroy(mem);
return NULL;
}

View File

@ -16,10 +16,8 @@
#ifndef _LVM_MATCHER_H
#define _LVM_MATCHER_H
#include "pool.h"
struct matcher;
struct matcher *matcher_create(struct pool *mem, const char **patterns,
struct matcher *matcher_create(struct dm_pool *mem, const char **patterns,
unsigned num);
int matcher_run(struct matcher *m, const char *begin);

View File

@ -15,12 +15,11 @@
#include "lib.h"
#include "parse_rx.h"
#include "bitset.h"
struct parse_sp { /* scratch pad for the parsing process */
struct pool *mem;
struct dm_pool *mem;
int type; /* token type, 0 indicates a charset */
bitset_t charset; /* The current charset */
dm_bitset_t charset; /* The current charset */
const char *cursor; /* where we are in the regex */
const char *rx_end; /* 1pte for the expression being parsed */
};
@ -31,8 +30,8 @@ static void _single_char(struct parse_sp *ps, unsigned int c, const char *ptr)
{
ps->type = 0;
ps->cursor = ptr + 1;
bit_clear_all(ps->charset);
bit_set(ps->charset, c);
dm_bit_clear_all(ps->charset);
dm_bit_set(ps->charset, c);
}
/*
@ -54,15 +53,15 @@ static int _get_token(struct parse_sp *ps)
case '[':
ptr++;
if (*ptr == '^') {
bit_set_all(ps->charset);
dm_bit_set_all(ps->charset);
/* never transition on zero */
bit_clear(ps->charset, 0);
dm_bit_clear(ps->charset, 0);
neg = 1;
ptr++;
} else
bit_clear_all(ps->charset);
dm_bit_clear_all(ps->charset);
while ((ptr < ps->rx_end) && (*ptr != ']')) {
if (*ptr == '\\') {
@ -104,17 +103,17 @@ static int _get_token(struct parse_sp *ps)
for (; lc <= c; lc++) {
if (neg)
bit_clear(ps->charset, lc);
dm_bit_clear(ps->charset, lc);
else
bit_set(ps->charset, lc);
dm_bit_set(ps->charset, lc);
}
range = 0;
} else {
/* add c into the bitset */
if (neg)
bit_clear(ps->charset, c);
dm_bit_clear(ps->charset, c);
else
bit_set(ps->charset, c);
dm_bit_set(ps->charset, c);
}
ptr++;
lc = c;
@ -154,10 +153,10 @@ static int _get_token(struct parse_sp *ps)
/* The 'all but newline' character set */
ps->type = 0;
ps->cursor = ptr + 1;
bit_set_all(ps->charset);
bit_clear(ps->charset, (int) '\n');
bit_clear(ps->charset, (int) '\r');
bit_clear(ps->charset, 0);
dm_bit_set_all(ps->charset);
dm_bit_clear(ps->charset, (int) '\n');
dm_bit_clear(ps->charset, (int) '\r');
dm_bit_clear(ps->charset, 0);
break;
case '\\':
@ -172,19 +171,19 @@ static int _get_token(struct parse_sp *ps)
ps->type = 0;
ps->cursor = ptr + 1;
bit_clear_all(ps->charset);
dm_bit_clear_all(ps->charset);
switch (*ptr) {
case 'n':
bit_set(ps->charset, (int) '\n');
dm_bit_set(ps->charset, (int) '\n');
break;
case 'r':
bit_set(ps->charset, (int) '\r');
dm_bit_set(ps->charset, (int) '\r');
break;
case 't':
bit_set(ps->charset, (int) '\t');
dm_bit_set(ps->charset, (int) '\t');
break;
default:
bit_set(ps->charset, (int) *ptr);
dm_bit_set(ps->charset, (int) *ptr);
}
break;
@ -192,22 +191,22 @@ static int _get_token(struct parse_sp *ps)
/* add a single character to the bitset */
ps->type = 0;
ps->cursor = ptr + 1;
bit_clear_all(ps->charset);
bit_set(ps->charset, (int) *ptr);
dm_bit_clear_all(ps->charset);
dm_bit_set(ps->charset, (int) *ptr);
break;
}
return 1;
}
static struct rx_node *_node(struct pool *mem, int type,
static struct rx_node *_node(struct dm_pool *mem, int type,
struct rx_node *l, struct rx_node *r)
{
struct rx_node *n = pool_zalloc(mem, sizeof(*n));
struct rx_node *n = dm_pool_zalloc(mem, sizeof(*n));
if (n) {
if (!(n->charset = bitset_create(mem, 256))) {
pool_free(mem, n);
if (!(n->charset = dm_bitset_create(mem, 256))) {
dm_pool_free(mem, n);
return NULL;
}
@ -230,7 +229,7 @@ static struct rx_node *_term(struct parse_sp *ps)
return NULL;
}
bit_copy(n->charset, ps->charset);
dm_bit_copy(n->charset, ps->charset);
_get_token(ps); /* match charset */
break;
@ -330,11 +329,11 @@ static struct rx_node *_or_term(struct parse_sp *ps)
return n;
}
struct rx_node *rx_parse_tok(struct pool *mem,
struct rx_node *rx_parse_tok(struct dm_pool *mem,
const char *begin, const char *end)
{
struct rx_node *r;
struct parse_sp *ps = pool_zalloc(mem, sizeof(*ps));
struct parse_sp *ps = dm_pool_zalloc(mem, sizeof(*ps));
if (!ps) {
stack;
@ -342,20 +341,20 @@ struct rx_node *rx_parse_tok(struct pool *mem,
}
ps->mem = mem;
ps->charset = bitset_create(mem, 256);
ps->charset = dm_bitset_create(mem, 256);
ps->cursor = begin;
ps->rx_end = end;
_get_token(ps); /* load the first token */
if (!(r = _or_term(ps))) {
log_error("Parse error in regex");
pool_free(mem, ps);
dm_pool_free(mem, ps);
}
return r;
}
struct rx_node *rx_parse_str(struct pool *mem, const char *str)
struct rx_node *rx_parse_str(struct dm_pool *mem, const char *str)
{
return rx_parse_tok(mem, str, str + strlen(str));
}

View File

@ -16,8 +16,6 @@
#ifndef _LVM_PARSE_REGEX_H
#define _LVM_PARSE_REGEX_H
#include "bitset.h"
enum {
CAT,
STAR,
@ -37,18 +35,18 @@ enum {
struct rx_node {
int type;
bitset_t charset;
dm_bitset_t charset;
struct rx_node *left, *right;
/* used to build the dfa for the toker */
int nullable, final;
bitset_t firstpos;
bitset_t lastpos;
bitset_t followpos;
dm_bitset_t firstpos;
dm_bitset_t lastpos;
dm_bitset_t followpos;
};
struct rx_node *rx_parse_str(struct pool *mem, const char *str);
struct rx_node *rx_parse_tok(struct pool *mem,
struct rx_node *rx_parse_str(struct dm_pool *mem, const char *str);
struct rx_node *rx_parse_tok(struct dm_pool *mem,
const char *begin, const char *end);
#endif

View File

@ -15,7 +15,6 @@
#include "lib.h"
#include "ttree.h"
#include "pool.h"
struct node {
unsigned k;
@ -25,7 +24,7 @@ struct node {
struct ttree {
int klen;
struct pool *mem;
struct dm_pool *mem;
struct node *root;
};
@ -60,9 +59,9 @@ void *ttree_lookup(struct ttree *tt, unsigned *key)
return *c ? (*c)->data : NULL;
}
static struct node *_node(struct pool *mem, unsigned int k)
static struct node *_node(struct dm_pool *mem, unsigned int k)
{
struct node *n = pool_zalloc(mem, sizeof(*n));
struct node *n = dm_pool_zalloc(mem, sizeof(*n));
if (n)
n->k = k;
@ -103,11 +102,11 @@ int ttree_insert(struct ttree *tt, unsigned int *key, void *data)
return 1;
}
struct ttree *ttree_create(struct pool *mem, unsigned int klen)
struct ttree *ttree_create(struct dm_pool *mem, unsigned int klen)
{
struct ttree *tt;
if (!(tt = pool_zalloc(mem, sizeof(*tt)))) {
if (!(tt = dm_pool_zalloc(mem, sizeof(*tt)))) {
stack;
return NULL;
}

View File

@ -16,11 +16,9 @@
#ifndef _LVM_TTREE_H
#define _LVM_TTREE_H
#include "pool.h"
struct ttree;
struct ttree *ttree_create(struct pool *mem, unsigned int klen);
struct ttree *ttree_create(struct dm_pool *mem, unsigned int klen);
void *ttree_lookup(struct ttree *tt, unsigned *key);
int ttree_insert(struct ttree *tt, unsigned *key, void *data);

View File

@ -17,7 +17,6 @@
#include "metadata.h"
#include "report.h"
#include "toolcontext.h"
#include "pool.h"
#include "lvm-string.h"
#include "display.h"
#include "activate.h"
@ -45,7 +44,7 @@ static union {
struct report_handle {
struct cmd_context *cmd;
struct pool *mem;
struct dm_pool *mem;
report_type_t type;
const char *field_prefix;
@ -121,8 +120,8 @@ static int _string_disp(struct report_handle *rh, struct field *field,
{
if (!
(field->report_string =
pool_strdup(rh->mem, *(const char **) data))) {
log_error("pool_strdup failed");
dm_pool_strdup(rh->mem, *(const char **) data))) {
log_error("dm_pool_strdup failed");
return 0;
}
@ -144,12 +143,12 @@ static int _devices_disp(struct report_handle *rh, struct field *field,
{
const struct lv_segment *seg = (const struct lv_segment *) data;
unsigned int s;
const char *name;
uint32_t extent;
const char *name = NULL;
uint32_t extent = 0;
char extent_str[32];
if (!pool_begin_object(rh->mem, 256)) {
log_error("pool_begin_object failed");
if (!dm_pool_begin_object(rh->mem, 256)) {
log_error("dm_pool_begin_object failed");
return 0;
}
@ -168,8 +167,8 @@ static int _devices_disp(struct report_handle *rh, struct field *field,
extent = 0;
}
if (!pool_grow_object(rh->mem, name, strlen(name))) {
log_error("pool_grow_object failed");
if (!dm_pool_grow_object(rh->mem, name, strlen(name))) {
log_error("dm_pool_grow_object failed");
return 0;
}
@ -179,24 +178,24 @@ static int _devices_disp(struct report_handle *rh, struct field *field,
return 0;
}
if (!pool_grow_object(rh->mem, extent_str, strlen(extent_str))) {
log_error("pool_grow_object failed");
if (!dm_pool_grow_object(rh->mem, extent_str, strlen(extent_str))) {
log_error("dm_pool_grow_object failed");
return 0;
}
if ((s != seg->area_count - 1) &&
!pool_grow_object(rh->mem, ",", 1)) {
log_error("pool_grow_object failed");
!dm_pool_grow_object(rh->mem, ",", 1)) {
log_error("dm_pool_grow_object failed");
return 0;
}
}
if (!pool_grow_object(rh->mem, "\0", 1)) {
log_error("pool_grow_object failed");
if (!dm_pool_grow_object(rh->mem, "\0", 1)) {
log_error("dm_pool_grow_object failed");
return 0;
}
field->report_string = pool_end_object(rh->mem);
field->report_string = dm_pool_end_object(rh->mem);
field->sort_value = (const void *) field->report_string;
return 1;
@ -207,25 +206,25 @@ static int _tags_disp(struct report_handle *rh, struct field *field,
const struct list *tags = (const struct list *) data;
struct str_list *sl;
if (!pool_begin_object(rh->mem, 256)) {
log_error("pool_begin_object failed");
if (!dm_pool_begin_object(rh->mem, 256)) {
log_error("dm_pool_begin_object failed");
return 0;
}
list_iterate_items(sl, tags) {
if (!pool_grow_object(rh->mem, sl->str, strlen(sl->str)) ||
(sl->list.n != tags && !pool_grow_object(rh->mem, ",", 1))) {
log_error("pool_grow_object failed");
if (!dm_pool_grow_object(rh->mem, sl->str, strlen(sl->str)) ||
(sl->list.n != tags && !dm_pool_grow_object(rh->mem, ",", 1))) {
log_error("dm_pool_grow_object failed");
return 0;
}
}
if (!pool_grow_object(rh->mem, "\0", 1)) {
log_error("pool_grow_object failed");
if (!dm_pool_grow_object(rh->mem, "\0", 1)) {
log_error("dm_pool_grow_object failed");
return 0;
}
field->report_string = pool_end_object(rh->mem);
field->report_string = dm_pool_end_object(rh->mem);
field->sort_value = (const void *) field->report_string;
return 1;
@ -267,13 +266,13 @@ static int _int_disp(struct report_handle *rh, struct field *field,
uint64_t *sortval;
char *repstr;
if (!(repstr = pool_zalloc(rh->mem, 13))) {
log_error("pool_alloc failed");
if (!(repstr = dm_pool_zalloc(rh->mem, 13))) {
log_error("dm_pool_alloc failed");
return 0;
}
if (!(sortval = pool_alloc(rh->mem, sizeof(int64_t)))) {
log_error("pool_alloc failed");
if (!(sortval = dm_pool_alloc(rh->mem, sizeof(int64_t)))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -328,8 +327,8 @@ static int _lvstatus_disp(struct report_handle *rh, struct field *field,
struct lv_segment *snap_seg;
float snap_percent;
if (!(repstr = pool_zalloc(rh->mem, 7))) {
log_error("pool_alloc failed");
if (!(repstr = dm_pool_zalloc(rh->mem, 7))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -405,8 +404,8 @@ static int _pvstatus_disp(struct report_handle *rh, struct field *field,
const uint32_t status = *(const uint32_t *) data;
char *repstr;
if (!(repstr = pool_zalloc(rh->mem, 4))) {
log_error("pool_alloc failed");
if (!(repstr = dm_pool_zalloc(rh->mem, 4))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -432,8 +431,8 @@ static int _vgstatus_disp(struct report_handle *rh, struct field *field,
const struct volume_group *vg = (const struct volume_group *) data;
char *repstr;
if (!(repstr = pool_zalloc(rh->mem, 7))) {
log_error("pool_alloc failed");
if (!(repstr = dm_pool_zalloc(rh->mem, 7))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -531,8 +530,8 @@ static int _lvname_disp(struct report_handle *rh, struct field *field,
}
len = strlen(lv->name) + 3;
if (!(repstr = pool_zalloc(rh->mem, len))) {
log_error("pool_alloc failed");
if (!(repstr = dm_pool_zalloc(rh->mem, len))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -543,8 +542,8 @@ static int _lvname_disp(struct report_handle *rh, struct field *field,
field->report_string = repstr;
if (!(field->sort_value = pool_strdup(rh->mem, lv->name))) {
log_error("pool_strdup failed");
if (!(field->sort_value = dm_pool_strdup(rh->mem, lv->name))) {
log_error("dm_pool_strdup failed");
return 0;
}
@ -583,13 +582,13 @@ static int _size32_disp(struct report_handle *rh, struct field *field,
return 0;
}
if (!(field->report_string = pool_strdup(rh->mem, disp))) {
log_error("pool_strdup failed");
if (!(field->report_string = dm_pool_strdup(rh->mem, disp))) {
log_error("dm_pool_strdup failed");
return 0;
}
if (!(sortval = pool_alloc(rh->mem, sizeof(uint64_t)))) {
log_error("pool_alloc failed");
if (!(sortval = dm_pool_alloc(rh->mem, sizeof(uint64_t)))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -611,13 +610,13 @@ static int _size64_disp(struct report_handle *rh, struct field *field,
return 0;
}
if (!(field->report_string = pool_strdup(rh->mem, disp))) {
log_error("pool_strdup failed");
if (!(field->report_string = dm_pool_strdup(rh->mem, disp))) {
log_error("dm_pool_strdup failed");
return 0;
}
if (!(sortval = pool_alloc(rh->mem, sizeof(uint64_t)))) {
log_error("pool_alloc failed");
if (!(sortval = dm_pool_alloc(rh->mem, sizeof(uint64_t)))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -748,8 +747,8 @@ static int _uuid_disp(struct report_handle *rh, struct field *field,
{
char *repstr = NULL;
if (!(repstr = pool_alloc(rh->mem, 40))) {
log_error("pool_alloc failed");
if (!(repstr = dm_pool_alloc(rh->mem, 40))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -771,13 +770,13 @@ static int _uint32_disp(struct report_handle *rh, struct field *field,
uint64_t *sortval;
char *repstr;
if (!(repstr = pool_zalloc(rh->mem, 12))) {
log_error("pool_alloc failed");
if (!(repstr = dm_pool_zalloc(rh->mem, 12))) {
log_error("dm_pool_alloc failed");
return 0;
}
if (!(sortval = pool_alloc(rh->mem, sizeof(uint64_t)))) {
log_error("pool_alloc failed");
if (!(sortval = dm_pool_alloc(rh->mem, sizeof(uint64_t)))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -800,13 +799,13 @@ static int _int32_disp(struct report_handle *rh, struct field *field,
uint64_t *sortval;
char *repstr;
if (!(repstr = pool_zalloc(rh->mem, 13))) {
log_error("pool_alloc failed");
if (!(repstr = dm_pool_zalloc(rh->mem, 13))) {
log_error("dm_pool_alloc failed");
return 0;
}
if (!(sortval = pool_alloc(rh->mem, sizeof(int64_t)))) {
log_error("pool_alloc failed");
if (!(sortval = dm_pool_alloc(rh->mem, sizeof(int64_t)))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -843,8 +842,8 @@ static int _snpercent_disp(struct report_handle *rh, struct field *field,
uint64_t *sortval;
char *repstr;
if (!(sortval = pool_alloc(rh->mem, sizeof(uint64_t)))) {
log_error("pool_alloc failed");
if (!(sortval = dm_pool_alloc(rh->mem, sizeof(uint64_t)))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -864,8 +863,8 @@ static int _snpercent_disp(struct report_handle *rh, struct field *field,
return 1;
}
if (!(repstr = pool_zalloc(rh->mem, 8))) {
log_error("pool_alloc failed");
if (!(repstr = dm_pool_zalloc(rh->mem, 8))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -889,8 +888,8 @@ static int _copypercent_disp(struct report_handle *rh, struct field *field,
uint64_t *sortval;
char *repstr;
if (!(sortval = pool_alloc(rh->mem, sizeof(uint64_t)))) {
log_error("pool_alloc failed");
if (!(sortval = dm_pool_alloc(rh->mem, sizeof(uint64_t)))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -904,8 +903,8 @@ static int _copypercent_disp(struct report_handle *rh, struct field *field,
percent = copy_percent(lv);
if (!(repstr = pool_zalloc(rh->mem, 8))) {
log_error("pool_alloc failed");
if (!(repstr = dm_pool_zalloc(rh->mem, 8))) {
log_error("dm_pool_alloc failed");
return 0;
}
@ -966,7 +965,7 @@ static int _field_match(struct report_handle *rh, const char *field, size_t len)
!strncasecmp(_fields[f].id + l, field, len) &&
strlen(_fields[f].id) == l + len)) {
rh->type |= _fields[f].type;
if (!(fp = pool_zalloc(rh->mem, sizeof(*fp)))) {
if (!(fp = dm_pool_zalloc(rh->mem, sizeof(*fp)))) {
log_error("struct field_properties allocation "
"failed");
return 0;
@ -1002,7 +1001,7 @@ static int _add_sort_key(struct report_handle *rh, uint32_t field_num,
if (!found) {
/* Add as a non-display field */
if (!(found = pool_zalloc(rh->mem, sizeof(*found)))) {
if (!(found = dm_pool_zalloc(rh->mem, sizeof(*found)))) {
log_error("struct field_properties allocation failed");
return 0;
}
@ -1116,8 +1115,8 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
{
struct report_handle *rh;
if (!(rh = pool_zalloc(cmd->mem, sizeof(*rh)))) {
log_error("report_handle pool_zalloc failed");
if (!(rh = dm_pool_zalloc(cmd->mem, sizeof(*rh)))) {
log_error("report_handle dm_pool_zalloc failed");
return 0;
}
@ -1157,7 +1156,7 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
rh->field_prefix = "";
}
if (!(rh->mem = pool_create("report", 10 * 1024))) {
if (!(rh->mem = dm_pool_create("report", 10 * 1024))) {
log_error("Allocation of memory pool for report failed");
return NULL;
}
@ -1196,7 +1195,7 @@ void report_free(void *handle)
{
struct report_handle *rh = handle;
pool_destroy(rh->mem);
dm_pool_destroy(rh->mem);
return;
}
@ -1220,7 +1219,7 @@ int report_object(void *handle, struct volume_group *vg,
return 0;
}
if (!(row = pool_zalloc(rh->mem, sizeof(*row)))) {
if (!(row = dm_pool_zalloc(rh->mem, sizeof(*row)))) {
log_error("struct row allocation failed");
return 0;
}
@ -1228,7 +1227,7 @@ int report_object(void *handle, struct volume_group *vg,
row->rh = rh;
if ((rh->flags & RH_SORT_REQUIRED) &&
!(row->sort_fields = pool_zalloc(rh->mem, sizeof(struct field *) *
!(row->sort_fields = dm_pool_zalloc(rh->mem, sizeof(struct field *) *
rh->keys_count))) {
log_error("row sort value structure allocation failed");
return 0;
@ -1241,7 +1240,7 @@ int report_object(void *handle, struct volume_group *vg,
list_iterate_items(fp, &rh->field_props) {
skip = 0;
if (!(field = pool_zalloc(rh->mem, sizeof(*field)))) {
if (!(field = dm_pool_zalloc(rh->mem, sizeof(*field)))) {
log_error("struct field allocation failed");
return 0;
}
@ -1311,8 +1310,8 @@ static int _report_headings(void *handle)
if (!(rh->flags & RH_HEADINGS))
return 1;
if (!pool_begin_object(rh->mem, 128)) {
log_error("pool_begin_object failed for headings");
if (!dm_pool_begin_object(rh->mem, 128)) {
log_error("dm_pool_begin_object failed for headings");
return 0;
}
@ -1326,24 +1325,24 @@ static int _report_headings(void *handle)
if (lvm_snprintf(buf, sizeof(buf), "%-*.*s",
fp->width, fp->width, heading) < 0) {
log_error("snprintf heading failed");
pool_end_object(rh->mem);
dm_pool_end_object(rh->mem);
return 0;
}
if (!pool_grow_object(rh->mem, buf, fp->width))
if (!dm_pool_grow_object(rh->mem, buf, fp->width))
goto bad;
} else if (!pool_grow_object(rh->mem, heading, strlen(heading)))
} else if (!dm_pool_grow_object(rh->mem, heading, strlen(heading)))
goto bad;
if (!list_end(&rh->field_props, &fp->list))
if (!pool_grow_object(rh->mem, rh->separator,
if (!dm_pool_grow_object(rh->mem, rh->separator,
strlen(rh->separator)))
goto bad;
}
if (!pool_grow_object(rh->mem, "\0", 1)) {
log_error("pool_grow_object failed");
if (!dm_pool_grow_object(rh->mem, "\0", 1)) {
log_error("dm_pool_grow_object failed");
goto bad;
}
log_print("%s", (char *) pool_end_object(rh->mem));
log_print("%s", (char *) dm_pool_end_object(rh->mem));
return 1;
@ -1405,7 +1404,7 @@ static int _sort_rows(struct report_handle *rh)
uint32_t count = 0;
struct row *row;
if (!(rows = pool_alloc(rh->mem, sizeof(**rows) *
if (!(rows = dm_pool_alloc(rh->mem, sizeof(**rows) *
list_size(&rh->rows)))) {
log_error("sort array allocation failed");
return 0;
@ -1449,8 +1448,8 @@ int report_output(void *handle)
/* Print and clear buffer */
list_iterate_safe(rowh, rtmp, &rh->rows) {
if (!pool_begin_object(rh->mem, 512)) {
log_error("pool_begin_object failed for row");
if (!dm_pool_begin_object(rh->mem, 512)) {
log_error("dm_pool_begin_object failed for row");
return 0;
}
row = list_item(rowh, struct row);
@ -1462,45 +1461,45 @@ int report_output(void *handle)
repstr = field->report_string;
width = field->props->width;
if (!(rh->flags & RH_ALIGNED)) {
if (!pool_grow_object(rh->mem, repstr,
if (!dm_pool_grow_object(rh->mem, repstr,
strlen(repstr)))
goto bad;
} else if (field->props->flags & FLD_ALIGN_LEFT) {
if (lvm_snprintf(buf, sizeof(buf), "%-*.*s",
width, width, repstr) < 0) {
log_error("snprintf repstr failed");
pool_end_object(rh->mem);
dm_pool_end_object(rh->mem);
return 0;
}
if (!pool_grow_object(rh->mem, buf, width))
if (!dm_pool_grow_object(rh->mem, buf, width))
goto bad;
} else if (field->props->flags & FLD_ALIGN_RIGHT) {
if (lvm_snprintf(buf, sizeof(buf), "%*.*s",
width, width, repstr) < 0) {
log_error("snprintf repstr failed");
pool_end_object(rh->mem);
dm_pool_end_object(rh->mem);
return 0;
}
if (!pool_grow_object(rh->mem, buf, width))
if (!dm_pool_grow_object(rh->mem, buf, width))
goto bad;
}
if (!list_end(&row->fields, fh))
if (!pool_grow_object(rh->mem, rh->separator,
if (!dm_pool_grow_object(rh->mem, rh->separator,
strlen(rh->separator)))
goto bad;
list_del(&field->list);
}
if (!pool_grow_object(rh->mem, "\0", 1)) {
log_error("pool_grow_object failed for row");
if (!dm_pool_grow_object(rh->mem, "\0", 1)) {
log_error("dm_pool_grow_object failed for row");
return 0;
}
log_print("%s", (char *) pool_end_object(rh->mem));
log_print("%s", (char *) dm_pool_end_object(rh->mem));
list_del(&row->list);
}
if (row)
pool_free(rh->mem, row);
dm_pool_free(rh->mem, row);
return 1;

View File

@ -14,8 +14,6 @@
*/
#include "lib.h"
#include "pool.h"
#include "list.h"
#include "toolcontext.h"
#include "metadata.h"
#include "segtype.h"
@ -89,7 +87,7 @@ static int _text_export(const struct lv_segment *seg, struct formatter *f)
}
#ifdef DEVMAPPER_SUPPORT
static int _target_percent(void **target_state, struct pool *mem,
static int _target_percent(void **target_state, struct dm_pool *mem,
struct config_tree *cft, struct lv_segment *seg,
char *params, uint64_t *total_numerator,
uint64_t *total_denominator, float *percent)
@ -128,7 +126,7 @@ static int _target_present(void)
static void _destroy(const struct segment_type *segtype)
{
dbg_free((void *) segtype);
dm_free((void *) segtype);
}
static struct segtype_handler _snapshot_ops = {
@ -149,7 +147,7 @@ struct segment_type *init_segtype(struct cmd_context *cmd);
struct segment_type *init_segtype(struct cmd_context *cmd)
#endif
{
struct segment_type *segtype = dbg_malloc(sizeof(*segtype));
struct segment_type *segtype = dm_malloc(sizeof(*segtype));
if (!segtype) {
stack;

View File

@ -14,8 +14,6 @@
*/
#include "lib.h"
#include "pool.h"
#include "list.h"
#include "toolcontext.h"
#include "segtype.h"
#include "display.h"
@ -63,7 +61,7 @@ static int _text_import_area_count(struct config_node *sn, uint32_t *area_count)
}
static int _text_import(struct lv_segment *seg, const struct config_node *sn,
struct hash_table *pv_hash)
struct dm_hash_table *pv_hash)
{
struct config_node *cn;
@ -152,7 +150,7 @@ static int _merge_segments(struct lv_segment *seg1, struct lv_segment *seg2)
}
#ifdef DEVMAPPER_SUPPORT
static int _compose_target_line(struct dev_manager *dm, struct pool *mem,
static int _compose_target_line(struct dev_manager *dm, struct dm_pool *mem,
struct config_tree *cft, void **target_state,
struct lv_segment *seg, char *params,
size_t paramsize, const char **target, int *pos,
@ -195,7 +193,7 @@ static int _target_present(void)
static void _destroy(const struct segment_type *segtype)
{
dbg_free((void *) segtype);
dm_free((void *) segtype);
}
static struct segtype_handler _striped_ops = {
@ -214,7 +212,7 @@ static struct segtype_handler _striped_ops = {
struct segment_type *init_striped_segtype(struct cmd_context *cmd)
{
struct segment_type *segtype = dbg_malloc(sizeof(*segtype));
struct segment_type *segtype = dm_malloc(sizeof(*segtype));
if (!segtype) {
stack;

View File

@ -13,8 +13,6 @@
*/
#include "lib.h"
#include "pool.h"
#include "list.h"
#include "toolcontext.h"
#include "segtype.h"
#include "display.h"
@ -40,7 +38,7 @@ static int _merge_segments(struct lv_segment *seg1, struct lv_segment *seg2)
}
#ifdef DEVMAPPER_SUPPORT
static int _compose_target_line(struct dev_manager *dm, struct pool *mem,
static int _compose_target_line(struct dev_manager *dm, struct dm_pool *mem,
struct config_tree *cft, void **target_state,
struct lv_segment *seg, char *params,
size_t paramsize, const char **target, int *pos,
@ -69,7 +67,7 @@ static int _target_present(void)
static void _destroy(const struct segment_type *segtype)
{
dbg_free((void *) segtype);
dm_free((void *) segtype);
}
static struct segtype_handler _zero_ops = {
@ -84,7 +82,7 @@ static struct segtype_handler _zero_ops = {
struct segment_type *init_zero_segtype(struct cmd_context *cmd)
{
struct segment_type *segtype = dbg_malloc(sizeof(*segtype));
struct segment_type *segtype = dm_malloc(sizeof(*segtype));
if (!segtype) {
stack;

View File

@ -202,6 +202,26 @@ static inline struct list *list_next(struct list *head, struct list *elem)
*/
#define list_iterate_items(v, head) list_iterate_items_gen(v, (head), list)
/*
* Walk a list, setting 'v' in turn to the containing structure of each item.
* The containing structure should be the same type as 'v'.
* The 'struct list' variable within the containing structure is 'field'.
* t must be defined as a temporary variable of the same type as v.
*/
#define list_iterate_items_gen_safe(v, t, head, field) \
for (v = list_struct_base((head)->n, typeof(*v), field), \
t = list_struct_base(v->field.n, typeof(*v), field); \
&v->field != (head); \
v = t, t = list_struct_base(v->field.n, typeof(*v), field))
/*
* Walk a list, setting 'v' in turn to the containing structure of each item.
* The containing structure should be the same type as 'v'.
* The list should be 'struct list list' within the containing structure.
* t must be defined as a temporary variable of the same type as v.
*/
#define list_iterate_items_safe(v, t, head) \
list_iterate_items_gen_safe(v, t, (head), list)
/*
* Walk a list backwards, setting 'v' in turn to the containing structure
* of each item.

View File

@ -3,7 +3,6 @@
*/
#include <stdio.h>
#include "dbg_malloc.h"
#include "config.h"
int main(int argc, char **argv)

View File

@ -13,9 +13,6 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "hash.h"
#include "dbg_malloc.h"
#include <stdio.h>
static void _help(FILE *fp, const char *prog)

Some files were not shown because too many files have changed in this diff Show More