Version 2.02.00 -
===================================
+ Move mknodes into libdevmapper.
+ Move bitset, hash, pool and dbg_malloc into libdevmapper.
Version 2.01.15 - 16th October 2005
===================================
#include <errno.h>
#include "list.h"
-#include "hash.h"
#include "locking.h"
#include "log.h"
#include "lvm-functions.h"
#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;
#include "toolcontext.h"
#include "log.h"
#include "activate.h"
-#include "hash.h"
#include "locking.h"
static struct cmd_context *cmd = NULL;
}
/* clean the pool for another command */
- pool_empty(cmd->mem);
+ dm_pool_empty(cmd->mem);
DEBUGLOG("Command return is %d\n", status);
return status;
#include "clvmd-comms.h"
#include "clvmd.h"
#include "clvmd-gulm.h"
-#include "hash.h"
#define DEFAULT_TCP_PORT 21064
../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
../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
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 \
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 \
#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"
int r = 1;
if (!lv) {
- r = dev_manager_mknodes();
+ r = dm_mknodes(NULL);
fs_unlock();
return r;
}
#include "metadata.h"
-#ifdef DEVMAPPER_SUPPORT
-# include <libdevmapper.h>
-#endif
-
struct lvinfo {
int exists;
int suspended;
#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"
#include "targets.h"
#include "config.h"
-#include <libdevmapper.h>
#include <limits.h>
#include <dirent.h>
static const char *stripe_filler = NULL;
struct dev_manager {
- struct pool *mem;
+ struct dm_pool *mem;
struct cmd_context *cmd;
*/
struct list remove_list;
- struct hash_table *layers;
+ struct dm_hash_table *layers;
};
/*
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;
len = strlen(lvid) + strlen(layer) + 2;
- if (!(dlid = pool_alloc(mem, len))) {
+ if (!(dlid = dm_pool_alloc(mem, len))) {
stack;
return NULL;
}
}
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;
stack;
goto out;
}
- *uuid_out = pool_strdup(mem, u);
+ *uuid_out = dm_pool_strdup(mem, u);
}
r = 1;
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) &&
{
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;
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;
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;
}
}
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;
}
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,
return 0;
}
- /* FIXME pool_free ? */
+ /* FIXME dm_pool_free ? */
/* If the snapshot isn't available, percent will be -1 */
return 1;
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,
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;
}
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;
}
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;
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;
}
/* 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;
}
/* 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;
}
/* 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;
}
*/
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);
}
}
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;
}
*/
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;
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;
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;
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;
}
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;
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);
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);
*/
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)) {
/*
* 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)) {
}
/* 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;
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;
}
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;
}
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;
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,
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();
#include <unistd.h>
#include <limits.h>
#include <dirent.h>
-#include <libdevmapper.h>
static int _mk_dir(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;
}
_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);
}
}
#include "lib.h"
#include "lvmcache.h"
-#include "hash.h"
#include "toolcontext.h"
#include "dev-cache.h"
#include "metadata.h"
#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;
{
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;
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++;
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)
if (!_vgname_hash)
return NULL;
- if (!(vginfo = hash_lookup(_vgname_hash, vgname)))
+ if (!(vginfo = dm_hash_lookup(_vgname_hash, vgname)))
return NULL;
return vginfo;
* 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);
}
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;
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;
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;
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;
}
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;
}
}
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;
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;
} */
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;
}
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;
/* 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 */
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;
if (!_lvmcache_update_pvid(info, pvid_s)) {
if (!existing) {
- dbg_free(info);
+ dm_free(info);
label_destroy(label);
}
return NULL;
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;
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)
_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;
}
#include "lib.h"
#include "toolcontext.h"
-#include "pool.h"
#include "metadata.h"
#include "defaults.h"
#include "lvm-string.h"
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);
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;
}
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;
}
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;
}
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;
}
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;
}
return cmd;
error:
- dbg_free(cmd);
+ dm_free(cmd);
return NULL;
}
_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();
#define _LVM_TOOLCONTEXT_H
#include "dev-cache.h"
-#include "pool.h"
#include <stdio.h>
#include <limits.h>
/* 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 */
#include "lib.h"
#include "config.h"
#include "crc.h"
-#include "pool.h"
#include "device.h"
#include "str_list.h"
#include "toolcontext.h"
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;
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;
}
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,
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;
}
}
p->fb = p->fb + mmap_offset;
} else {
- if (!(p->fb = dbg_malloc(size + size2))) {
+ if (!(p->fb = dm_malloc(size + size2))) {
stack;
return 0;
}
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)) {
*/
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;
}
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;
#ifndef _LVM_CONFIG_H
#define _LVM_CONFIG_H
+#include "lvm-types.h"
+
struct device;
struct cmd_context;
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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
};
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;
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;
}
#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);
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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
*/
#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.
#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;
}
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;
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;
}
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;
#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
#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"
};
static struct {
- struct pool *mem;
- struct hash_table *names;
+ struct dm_pool *mem;
+ struct dm_hash_table *names;
struct btree *devices;
int has_scanned;
} _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);
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;
return NULL;
}
}
- } else if (!(alias->str = dbg_strdup(filename))) {
+ } else if (!(alias->str = dm_strdup(filename))) {
log_error("filename strdup failed");
return NULL;
}
}
}
- if (!(sl->str = pool_strdup(_cache.mem, path))) {
+ if (!(sl->str = dm_pool_strdup(_cache.mem, path))) {
stack;
return 0;
}
/* 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;
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;
}
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);
_collapse_slashes(path);
r &= _insert(path, 1);
- dbg_free(path);
+ dm_free(path);
free(dirent[n]);
}
_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;
}
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)
_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;
}
(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. */
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);
}
}
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");
void dev_iter_destroy(struct dev_iter *iter)
{
- dbg_free(iter);
+ dm_free(iter);
}
static inline struct device *_iter_next(struct dev_iter *iter)
#ifndef _LVM_DEV_CACHE_H
#define _LVM_DEV_CACHE_H
-#include "lvm-types.h"
#include "device.h"
/*
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);
}
}
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;
}
return 0;
}
- if (!(buffer = dbg_malloc(SECTOR_SIZE))) {
+ if (!(buffer = dm_malloc(SECTOR_SIZE))) {
log_error("Failed to allocate partition table buffer");
return 0;
}
#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 */
{" ", " ", " "},
};
- 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 "";
}
*/
#include "lib.h"
-#include "pool.h"
-#include "list.h"
#include "toolcontext.h"
#include "segtype.h"
#include "display.h"
}
#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,
static void _destroy(const struct segment_type *segtype)
{
- dbg_free((void *) segtype);
+ dm_free((void *) segtype);
}
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;
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)
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;
}
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;
}
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;
}
#include "lib.h"
#include "config.h"
#include "dev-cache.h"
-#include "hash.h"
#include "filter-persistent.h"
#include <sys/stat.h>
struct pfilter {
char *file;
- struct hash_table *devices;
+ struct dm_hash_table *devices;
struct dev_filter *real;
};
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;
}
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);
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 */
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;
{
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;
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)
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;
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) {
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));
{
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,
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;
}
goto bad;
}
- if (!(f = dbg_malloc(sizeof(*f)))) {
+ if (!(f = dm_malloc(sizeof(*f)))) {
stack;
goto bad;
}
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;
}
*/
#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;
*/
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:
/*
* copy the regex
*/
- if (!(r = pool_strdup(mem, pat))) {
+ if (!(r = dm_pool_strdup(mem, pat))) {
stack;
return 0;
}
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;
}
/*
* allocate space for them
*/
- if (!(regex = pool_alloc(scratch, sizeof(*regex) * count))) {
+ if (!(regex = dm_pool_alloc(scratch, sizeof(*regex) * count))) {
stack;
goto out;
}
/*
* 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
r = 1;
out:
- pool_destroy(scratch);
+ dm_pool_destroy(scratch);
return r;
}
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",
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;
return NULL;
}
- if (!(rf = pool_alloc(mem, sizeof(*rf)))) {
+ if (!(rf = dm_pool_alloc(mem, sizeof(*rf)))) {
stack;
goto bad;
}
goto bad;
}
- if (!(f = pool_zalloc(mem, sizeof(*f)))) {
+ if (!(f = dm_pool_zalloc(mem, sizeof(*f)))) {
stack;
goto bad;
}
return f;
bad:
- pool_destroy(mem);
+ dm_pool_destroy(mem);
return NULL;
}
#include "lib.h"
#include "filter-sysfs.h"
#include "lvm-string.h"
-#include "pool.h"
#ifdef linux
#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;
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];
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;
}
goto bad;
}
- if (!(f = pool_zalloc(mem, sizeof(*f)))) {
+ if (!(f = dm_pool_zalloc(mem, sizeof(*f)))) {
stack;
goto bad;
}
return f;
bad:
- pool_destroy(mem);
+ dm_pool_destroy(mem);
return NULL;
}
#include "lvm-string.h"
#include "config.h"
#include "metadata.h"
-#include "bitset.h"
#include <dirent.h>
#include <unistd.h>
} device_info_t;
static int _md_major = -1;
-static bitset_t _dm_bitset;
+static dm_bitset_t _dm_bitset;
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;
}
/*
/* 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 */
{
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;
}
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;
}
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;
}
#include "lib.h"
#include "disk-rep.h"
-#include "pool.h"
#include "xlate.h"
#include "filter.h"
#include "lvmcache.h"
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);
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;
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)
}
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;
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;
* 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;
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))
/* 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;
_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;
}
#include "lvm-types.h"
#include "metadata.h"
-#include "pool.h"
#include "toolcontext.h"
#define MAX_PV 256
struct disk_list {
struct list list;
- struct pool *mem;
+ struct dm_pool *mem;
struct device *dev;
struct pv_disk pvd;
*/
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);
* 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);
#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"
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;
bad:
stack;
- pool_free(mem, vg);
+ dm_pool_free(mem, vg);
return NULL;
}
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);
}
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;
!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)
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;
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;
r = 1;
out:
- pool_destroy(mem);
+ dm_pool_destroy(mem);
return r;
}
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;
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;
}
goto bad;
}
- pool_destroy(mem);
+ dm_pool_destroy(mem);
return 1;
bad:
- pool_destroy(mem);
+ dm_pool_destroy(mem);
return 0;
}
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;
}
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;
}
static void _destroy(const struct format_type *fmt)
{
- dbg_free((void *) fmt);
+ dm_free((void *) fmt);
}
static struct format_handler _format1_ops = {
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;
#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"
/*
* 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, '/');
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)
{
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;
}
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)
{
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;
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;
}
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);
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)
{
*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;
}
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;
}
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;
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;
}
* 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;
}
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;
}
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;
}
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];
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;
}
#include "lib.h"
#include "metadata.h"
-#include "hash.h"
-#include "pool.h"
#include "disk-rep.h"
#include "lv_alloc.h"
#include "display.h"
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;
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;
}
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;
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).",
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;
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;
_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;
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;
out:
if (maps)
- hash_destroy(maps);
- pool_destroy(scratch);
+ dm_hash_destroy(maps);
+ dm_pool_destroy(scratch);
return r;
}
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) {
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;
}
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;
}
static void _destroy(struct labeller *l)
{
- dbg_free(l);
+ dm_free(l);
}
struct label_ops _lvm1_ops = {
{
struct labeller *l;
- if (!(l = dbg_malloc(sizeof(*l)))) {
+ if (!(l = dm_malloc(sizeof(*l)))) {
log_err("Couldn't allocate labeller object.");
return NULL;
}
*/
#include "lib.h"
-#include "pool.h"
#include "disk-rep.h"
/*
{
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);
}
out:
- pool_destroy(mem);
+ dm_pool_destroy(mem);
return r;
}
*/
#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"
#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];
}
-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;
/* 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;
}
/* 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;
}
}
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;
}
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;
}
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;
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;
}
#include "label.h"
#include "metadata.h"
-#include "pool.h"
#define MINOR_OFFSET 65536
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 */
*/
#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"
#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;
*/
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;
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 "
}
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;
}
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;
}
out:
- pool_destroy(mem);
+ dm_pool_destroy(mem);
return vg;
}
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;
r = 1;
out:
- pool_destroy(mem);
+ dm_pool_destroy(mem);
return r;
}
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;
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;
}
static void _destroy(const struct format_type *fmt)
{
- dbg_free((void *) fmt);
+ dm_free((void *) fmt);
}
/* *INDENT-OFF* */
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 "
*/
#include "lib.h"
-#include "pool.h"
#include "label.h"
#include "metadata.h"
#include "lvmcache.h"
/* 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;
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;
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) {
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;
}
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;
}
}
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;
}
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)
{
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;
}
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)
{
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)
{
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;
*/
#include "lib.h"
-#include "pool.h"
#include "label.h"
#include "metadata.h"
#include "xlate.h"
static void _destroy(struct labeller *l)
{
- dbg_free(l);
+ dm_free(l);
}
struct label_ops _pool_ops = {
{
struct labeller *l;
- if (!(l = dbg_malloc(sizeof(*l)))) {
+ if (!(l = dm_malloc(sizeof(*l)))) {
log_error("Couldn't allocate labeller object.");
return NULL;
}
#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"
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;
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;
}
/*
* 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;
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);
}
list_iterate_back_items(af, archives)
_display_archive(cmd, af);
- pool_free(cmd->mem, archives);
+ dm_pool_free(cmd->mem, archives);
return 1;
}
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;
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;
}
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));
}
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;
}
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;
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;
}
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));
}
#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"
* 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 */
/* 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;
/* 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;
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)
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;
}
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;
}
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;
}
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;
}
_init();
- if (!(f = dbg_malloc(sizeof(*f)))) {
+ if (!(f = dm_malloc(sizeof(*f)))) {
stack;
return 0;
}
r = _text_vg_export(f, vg, desc);
if (r)
r = !ferror(f->data.fp);
- dbg_free(f);
+ dm_free(f);
return r;
}
_init();
- if (!(f = dbg_malloc(sizeof(*f)))) {
+ if (!(f = dm_malloc(sizeof(*f)))) {
stack;
return 0;
}
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;
}
if (!_text_vg_export(f, vg, desc)) {
stack;
- dbg_free(f->data.buf.start);
+ dm_free(f->data.buf.start);
goto out;
}
*buf = f->data.buf.start;
out:
- dbg_free(f);
+ dm_free(f);
return r;
}
#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"
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;
}
*/
{
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;
}
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;
}
stack;
if (buf)
- dbg_free(buf);
+ dm_free(buf);
return r;
}
* 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;
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;
}
/* 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;
}
list_iterate_safe(dl, tmp, dir_list) {
list_del(dl);
- dbg_free(dl);
+ dm_free(dl);
}
}
list_iterate_safe(rl, tmp, raw_list) {
list_del(rl);
- dbg_free(rl);
+ dm_free(rl);
}
}
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 = {
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;
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;
}
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;
}
}
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;
}
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;
}
(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;
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;
}
if (!desc)
desc = "";
- if (!(tc->desc = pool_strdup(cmd->mem, desc))) {
+ if (!(tc->desc = dm_pool_strdup(cmd->mem, desc))) {
stack;
goto no_mem;
}
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;
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;
}
struct config_value *cv;
struct mda_lists *mda_lists;
- if (!(fmt = dbg_malloc(sizeof(*fmt)))) {
+ if (!(fmt = dm_malloc(sizeof(*fmt)))) {
stack;
return NULL;
}
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;
}
err:
_free_dirs(&mda_lists->dirs);
- dbg_free(fmt);
+ dm_free(fmt);
return NULL;
}
#include "lvm-types.h"
#include "metadata.h"
-#include "pool.h"
/*
* Archives a vg config. 'retain_days' is the minimum number of
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);
#include "config.h"
#include "lvm-types.h"
#include "metadata.h"
-#include "pool.h"
#include <stdio.h>
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);
};
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);
#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 "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"
#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)
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;
}
* 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;
}
return 0;
}
- if (!(pv->vg_name = pool_strdup(mem, vg->name))) {
+ if (!(pv->vg_name = dm_pool_strdup(mem, vg->name))) {
stack;
return 0;
}
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;
}
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;
}
/* 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;
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;
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;
}
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;
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;
{
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) ;
return NULL;
}
- if (!(vg = pool_zalloc(mem, sizeof(*vg)))) {
+ if (!(vg = dm_pool_zalloc(mem, sizeof(*vg)))) {
stack;
return NULL;
}
/* 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;
}
* 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;
}
goto bad;
}
- hash_destroy(pv_hash);
+ dm_hash_destroy(pv_hash);
if (vg->status & PARTIAL_VG) {
vg->status &= ~LVM_WRITE;
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;
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;
#include "lib.h"
#include "metadata.h"
#include "import-export.h"
-#include "pool.h"
#include "str_list.h"
#include "lvm-string.h"
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;
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;
}
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
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;
}
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 */
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;
}
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);
}
}
static void _destroy(struct labeller *l)
{
- dbg_free(l);
+ dm_free(l);
}
struct label_ops _text_ops = {
{
struct labeller *l;
- if (!(l = dbg_malloc(sizeof(*l)))) {
+ if (!(l = dm_malloc(sizeof(*l)))) {
log_err("Couldn't allocate labeller object.");
return NULL;
}
#include "lib.h"
#include "label.h"
-#include "list.h"
#include "crc.h"
#include "xlate.h"
#include "lvmcache.h"
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;
}
static void _free_li(struct labeller_i *li)
{
- dbg_free(li);
+ dm_free(li);
}
int label_init(void)
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;
}
/* Allocate buffer */
buflen = len + outheader->arglen;
- *retbuf = dbg_malloc(buflen);
+ *retbuf = dm_malloc(buflen);
if (!*retbuf) {
errno = ENOMEM;
return 0;
* 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;
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;
out:
if (retbuf)
- dbg_free(retbuf);
+ dm_free(retbuf);
return status;
}
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;
}
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;
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;
}
return 1;
err:
- dbg_free(ll->res);
- dbg_free(ll);
+ dm_free(ll->res);
+ dm_free(ll);
return 0;
}
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";
}
*/
#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,
/*
* 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,
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;
}
* 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 */
/*
* 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,
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;
}
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;
}
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,
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;
}
/* 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;
}
r = 1;
out:
- dbg_free(areas);
+ dm_free(areas);
return r;
}
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;
}
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;
}
*/
#include "lib.h"
-#include "pool.h"
#include "device.h"
#include "metadata.h"
#include "toolcontext.h"
{
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;
}
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;
}
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;
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;
}
vg->cmd = cmd;
- if (!(vg->name = pool_strdup(mem, vg_name))) {
+ if (!(vg->name = dm_pool_strdup(mem, vg_name))) {
stack;
goto bad;
}
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;
return vg;
bad:
- pool_free(mem, vg);
+ dm_pool_free(mem, vg);
return NULL;
}
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;
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;
}
return pv;
bad:
- pool_free(mem, pv);
+ dm_pool_free(mem, pv);
return NULL;
}
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;
}
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;
}
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;
}
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;
}
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;
}
/* 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;
}
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;
}
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;
}
*/
#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,
*/
#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,
{
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;
}
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;
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;
#include "lib.h"
#include "pv_map.h"
-#include "hash.h"
#include "pv_alloc.h"
/*
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;
}
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;
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;
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;
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;
}
/*
* 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;
}
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;
}
#define _LVM_PV_MAP_H
#include "metadata.h"
-#include "bitset.h"
-#include "pool.h"
/*
* The in core rep. only stores a mapping from
/*
* 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);
struct lv_segment;
struct formatter;
struct config_node;
-struct hash_table;
struct dev_manager;
/* Feature flags */
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,
*/
#include "lib.h"
-#include "pool.h"
-#include "list.h"
#include "toolcontext.h"
#include "metadata.h"
#include "segtype.h"
}
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;
}
#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;
}
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,
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)
/* 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;
static void _destroy(const struct segment_type *segtype)
{
- dbg_free((void *) segtype);
+ dm_free((void *) segtype);
}
static struct segtype_handler _mirrored_ops = {
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;
#define _FILE_OFFSET_BITS 64
#include "log.h"
-#include "dbg_malloc.h"
#include "intl.h"
+#include "lvm-types.h"
+
+#include <libdevmapper.h>
#endif
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) {
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);
int fd;
char *dir, *c;
- if (!(dir = dbg_strdup(file))) {
+ if (!(dir = dm_strdup(file))) {
log_error("sync_dir failed in strdup");
return;
}
close(fd);
out:
- dbg_free(dir);
+ dm_free(dir);
}
#include "lib.h"
#include "lvm-types.h"
#include "lvm-string.h"
-#include "pool.h"
#include <ctype.h>
/*
* <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;
len += hyphens;
- if (!(r = pool_alloc(mem, len))) {
+ if (!(r = dm_pool_alloc(mem, len))) {
stack;
return NULL;
}
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)));
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
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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
#include "lib.h"
#include "memlock.h"
-#include "pool.h"
#include "defaults.h"
#include "config.h"
#include "toolcontext.h"
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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
#include "matcher.h"
#include "parse_rx.h"
#include "ttree.h"
-#include "bitset.h"
struct dfa_state {
int final;
struct state_queue {
struct dfa_state *s;
- bitset_t bits;
+ dm_bitset_t bits;
struct state_queue *next;
};
unsigned num_nodes;
int nodes_entered;
struct rx_node **nodes;
- struct pool *scratch, *mem;
+ struct dm_pool *scratch, *mem;
};
#define TARGET_TRANS '\0'
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);
}
}
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;
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);
}
}
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);
}
}
}
}
-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;
}
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;
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;
}
dfa->lookup[a] = ldfa;
set_bits = 0;
- bit_clear_all(bs);
+ dm_bit_clear_all(bs);
}
}
}
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) {
return NULL;
}
- if (!(m = pool_alloc(mem, sizeof(*m)))) {
+ if (!(m = dm_pool_alloc(mem, sizeof(*m)))) {
stack;
return NULL;
}
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;
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;
_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;
}
#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);
#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 */
};
{
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);
}
/*
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 == '\\') {
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;
/* 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 '\\':
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;
/* 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;
}
return NULL;
}
- bit_copy(n->charset, ps->charset);
+ dm_bit_copy(n->charset, ps->charset);
_get_token(ps); /* match charset */
break;
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;
}
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));
}
#ifndef _LVM_PARSE_REGEX_H
#define _LVM_PARSE_REGEX_H
-#include "bitset.h"
-
enum {
CAT,
STAR,
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
#include "lib.h"
#include "ttree.h"
-#include "pool.h"
struct node {
unsigned k;
struct ttree {
int klen;
- struct pool *mem;
+ struct dm_pool *mem;
struct node *root;
};
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;
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;
}
#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);
#include "metadata.h"
#include "report.h"
#include "toolcontext.h"
-#include "pool.h"
#include "lvm-string.h"
#include "display.h"
#include "activate.h"
struct report_handle {
struct cmd_context *cmd;
- struct pool *mem;
+ struct dm_pool *mem;
report_type_t type;
const char *field_prefix;
{
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;
}
{
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;
}
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;
}
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;
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;
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;
}
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;
}
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;
}
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;
}
}
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;
}
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;
}
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;
}
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;
}
{
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
!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;
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;
}
{
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;
}
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;
}
{
struct report_handle *rh = handle;
- pool_destroy(rh->mem);
+ dm_pool_destroy(rh->mem);
return;
}
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;
}
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;
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;
}
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;
}
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;
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;
/* 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);
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;
*/
#include "lib.h"
-#include "pool.h"
-#include "list.h"
#include "toolcontext.h"
#include "metadata.h"
#include "segtype.h"
}
#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)
static void _destroy(const struct segment_type *segtype)
{
- dbg_free((void *) segtype);
+ dm_free((void *) segtype);
}
static struct segtype_handler _snapshot_ops = {
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;
*/
#include "lib.h"
-#include "pool.h"
-#include "list.h"
#include "toolcontext.h"
#include "segtype.h"
#include "display.h"
}
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;
}
#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,
static void _destroy(const struct segment_type *segtype)
{
- dbg_free((void *) segtype);
+ dm_free((void *) segtype);
}
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;
*/
#include "lib.h"
-#include "pool.h"
-#include "list.h"
#include "toolcontext.h"
#include "segtype.h"
#include "display.h"
}
#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,
static void _destroy(const struct segment_type *segtype)
{
- dbg_free((void *) segtype);
+ dm_free((void *) segtype);
}
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;
*/
#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.
*/
#include <stdio.h>
-#include "dbg_malloc.h"
#include "config.h"
int main(int argc, char **argv)
* 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)
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "dbg_malloc.h"
#include "dev-cache.h"
#include "log.h"
#include "filter-persistent.h"
#include "log.h"
-#include "dbg_malloc.h"
#include "config.h"
#include "filter-regex.h"
#include "filter-regex.h"
#include "config.h"
#include "log.h"
-#include "dbg_malloc.h"
#include <stdio.h>
#include <ctype.h>
#include "log.h"
#include "format1.h"
-#include "dbg_malloc.h"
-#include "pool.h"
#include "pretty_print.h"
#include "list.h"
{
struct io_space *ios;
struct list_head *pvs, *tmp;
- struct pool *mem;
+ struct dm_pool *mem;
init_log(stderr);
init_debug(_LOG_INFO);
exit(1);
}
- if (!(mem = pool_create(10 * 1024))) {
+ if (!(mem = dm_pool_create(10 * 1024))) {
fprintf(stderr, "couldn't create pool\n");
exit(1);
}
ios->destroy(ios);
- pool_destroy(mem);
+ dm_pool_destroy(mem);
dev_cache_exit();
dump_memory();
fin_log();
#include "log.h"
#include "format1.h"
-#include "dbg_malloc.h"
-#include "pool.h"
#include "pretty_print.h"
#include "list.h"
{
struct io_space *ios;
struct list_head *vgs;
- struct pool *mem;
+ struct dm_pool *mem;
init_log(stderr);
init_debug(_LOG_INFO);
exit(1);
}
- if (!(mem = pool_create(10 * 1024))) {
+ if (!(mem = dm_pool_create(10 * 1024))) {
fprintf(stderr, "couldn't create pool\n");
exit(1);
}
dump_vg_names(vgs, stdout);
ios->destroy(ios);
- pool_destroy(mem);
+ dm_pool_destroy(mem);
dev_cache_exit();
dump_memory();
fin_log();
#include "log.h"
#include "format1.h"
-#include "dbg_malloc.h"
-#include "pool.h"
#include "pretty_print.h"
#include "list.h"
{
struct io_space *ios;
struct physical_volume *pv;
- struct pool *mem;
+ struct dm_pool *mem;
struct device *dev;
if (argc != 2) {
exit(1);
}
- if (!(mem = pool_create(10 * 1024))) {
+ if (!(mem = dm_pool_create(10 * 1024))) {
fprintf(stderr, "couldn't create pool\n");
exit(1);
}
dump_pv(pv, stdout);
ios->destroy(ios);
- pool_destroy(mem);
+ dm_pool_destroy(mem);
dev_cache_exit();
dump_memory();
fin_log();
#include "log.h"
#include "format1.h"
-#include "dbg_malloc.h"
-#include "pool.h"
#include "pretty_print.h"
#include <stdio.h>
{
struct io_space *ios;
struct volume_group *vg;
- struct pool *mem;
+ struct dm_pool *mem;
if (argc != 2) {
fprintf(stderr, "usage: read_vg_t <vg_name>\n");
exit(1);
}
- if (!(mem = pool_create(10 * 1024))) {
+ if (!(mem = dm_pool_create(10 * 1024))) {
fprintf(stderr, "couldn't create pool\n");
exit(1);
}
ios->destroy(ios);
- pool_destroy(mem);
+ dm_pool_destroy(mem);
dev_cache_exit();
dump_memory();
fin_log();
#include "log.h"
#include "format1.h"
-#include "dbg_malloc.h"
-#include "pool.h"
#include "pretty_print.h"
#include <stdio.h>
{
struct io_space *ios;
struct volume_group *vg;
- struct pool *mem;
+ struct dm_pool *mem;
if (argc != 2) {
fprintf(stderr, "usage: read_vg_t <vg_name>\n");
exit(1);
}
- if (!(mem = pool_create(10 * 1024))) {
+ if (!(mem = dm_pool_create(10 * 1024))) {
fprintf(stderr, "couldn't create pool\n");
exit(1);
}
ios->destroy(ios);
- pool_destroy(mem);
+ dm_pool_destroy(mem);
dev_cache_exit();
dump_memory();
fin_log();
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "dbg_malloc.h"
#include "log.h"
#include <stdio.h>
*/
#include "matcher.h"
-#include "dbg_malloc.h"
#include "log.h"
#include <stdio.h>
int main(int argc, char **argv)
{
- struct pool *mem;
+ struct dm_pool *mem;
struct matcher *scanner;
char **regex;
int nregex;
init_log(stderr);
init_debug(_LOG_DEBUG);
- if (!(mem = pool_create(10 * 1024))) {
+ if (!(mem = dm_pool_create(10 * 1024))) {
fprintf(stderr, "Couldn't create pool\n");
exit(2);
}
_scan_input(scanner, regex);
_free_regex(regex, nregex);
- pool_destroy(mem);
+ dm_pool_destroy(mem);
dump_memory();
fin_log();
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "dbg_malloc.h"
#include "log.h"
#include "../../lib/regex/parse_rx.h"
-#include "bitset.h"
#include <stdio.h>
#include <ctype.h>
int main(int argc, char **argv)
{
- struct pool *mem;
+ struct dm_pool *mem;
struct rx_node *rx;
if (argc != 2) {
init_log(stderr);
init_debug(_LOG_INFO);
- if (!(mem = pool_create(1024))) {
+ if (!(mem = dm_pool_create(1024))) {
fprintf(stderr, "Couldn't create pool\n");
exit(1);
}
}
_pretty_print(rx, 0);
- pool_destroy(mem);
+ dm_pool_destroy(mem);
dump_memory();
fin_log();
static void __alloc(int size)
{
- if (!(_commands = dbg_realloc(_commands, sizeof(*_commands) * size))) {
+ if (!(_commands = dm_realloc(_commands, sizeof(*_commands) * size))) {
log_fatal("Couldn't allocate memory.");
exit(ECMD_FAILED);
}
va_end(ap);
/* allocate space for them */
- if (!(args = dbg_malloc(sizeof(*args) * nargs))) {
+ if (!(args = dm_malloc(sizeof(*args) * nargs))) {
log_fatal("Out of memory.");
exit(ECMD_FAILED);
}
* Build up the complete command line, used as a
* description for backups.
*/
- if (!pool_begin_object(cmd->mem, 128))
+ if (!dm_pool_begin_object(cmd->mem, 128))
goto bad;
for (i = 0; i < argc; i++) {
- if (!pool_grow_object(cmd->mem, argv[i], strlen(argv[i])))
+ if (!dm_pool_grow_object(cmd->mem, argv[i], strlen(argv[i])))
goto bad;
if (i < (argc - 1))
- if (!pool_grow_object(cmd->mem, " ", 1))
+ if (!dm_pool_grow_object(cmd->mem, " ", 1))
goto bad;
}
/*
* Terminate.
*/
- if (!pool_grow_object(cmd->mem, "\0", 1))
+ if (!dm_pool_grow_object(cmd->mem, "\0", 1))
goto bad;
- return pool_end_object(cmd->mem);
+ return dm_pool_end_object(cmd->mem);
bad:
log_err("Couldn't copy command line.");
- pool_abandon_object(cmd->mem);
+ dm_pool_abandon_object(cmd->mem);
return NULL;
}
/*
* free off any memory the command used.
*/
- pool_empty(cmd->mem);
+ dm_pool_empty(cmd->mem);
if (ret == EINVALID_CMD_LINE && !_interactive)
_usage(cmd->command->name);
int i;
for (i = 0; i < _num_commands; i++)
- dbg_free(_commands[i].valid_args);
+ dm_free(_commands[i].valid_args);
- dbg_free(_commands);
+ dm_free(_commands);
}
static void _fin(struct cmd_context *cmd)
cmd->argv = argv;
- if (!(cmdcopy = dbg_strdup(cmdline))) {
+ if (!(cmdcopy = dm_strdup(cmdline))) {
log_error("Cmdline copy failed.");
ret = ECMD_FAILED;
goto out;
ret = _run_command(cmd, argc, argv);
out:
- dbg_free(cmdcopy);
+ dm_free(cmdcopy);
if (oneoff)
lvm2_exit(handle);
goto error;
}
- if (!(lv->name = pool_strdup(cmd->mem, lv_name_new))) {
+ if (!(lv->name = dm_pool_strdup(cmd->mem, lv_name_new))) {
log_error("Failed to allocate space for new name");
goto error;
}
else
log_verbose("%s: Moved: %.1f%%", name, overall_percent);
-x = pool_alloc(cmd->mem, 1);
-pool_free(cmd->mem, x);
+x = dm_pool_alloc(cmd->mem, 1);
+dm_pool_free(cmd->mem, x);
if (segment_percent < 100.0) {
/* The only case the caller *should* try again later */
lv_mirr->status |= (PVMOVE | LOCKED);
- if (!(*lvs_changed = pool_alloc(cmd->mem, sizeof(**lvs_changed)))) {
+ if (!(*lvs_changed = dm_pool_alloc(cmd->mem, sizeof(**lvs_changed)))) {
log_error("lvs_changed list struct allocation failed");
return NULL;
}
/* Drop any PE lists from PV name */
if ((colon = strchr(pv_name, ':'))) {
- if (!(pv_name = pool_strndup(cmd->mem, pv_name,
+ if (!(pv_name = dm_pool_strndup(cmd->mem, pv_name,
(unsigned) (colon -
pv_name)))) {
log_error("Failed to clone PV name");
return 0;
}
if (*opts == '+') {
- str = pool_alloc(cmd->mem,
+ str = dm_pool_alloc(cmd->mem,
strlen(options) + strlen(opts) + 1);
strcpy(str, options);
strcat(str, ",");
continue;
}
if (!str_list_add(cmd->mem, &tags,
- pool_strdup(cmd->mem,
+ dm_pool_strdup(cmd->mem,
vgname + 1))) {
log_error("strlist allocation failed");
return ECMD_FAILED;
lv_name = NULL;
if (!str_list_add(cmd->mem, &arg_vgnames,
- pool_strdup(cmd->mem, vgname))) {
+ dm_pool_strdup(cmd->mem, vgname))) {
log_error("strlist allocation failed");
return ECMD_FAILED;
}
if (!lv_name) {
if (!str_list_add(cmd->mem, &arg_lvnames,
- pool_strdup(cmd->mem,
+ dm_pool_strdup(cmd->mem,
vgname))) {
log_error("strlist allocation failed");
return ECMD_FAILED;
}
} else {
vglv_sz = strlen(vgname) + strlen(lv_name) + 2;
- if (!(vglv = pool_alloc(cmd->mem, vglv_sz)) ||
+ if (!(vglv = dm_pool_alloc(cmd->mem, vglv_sz)) ||
lvm_snprintf(vglv, vglv_sz, "%s/%s", vgname,
lv_name) < 0) {
log_error("vg/lv string alloc failed");
} else if (!strncmp(vg_name, vgname, strlen(vgname)) &&
strlen(vgname) == lv_name - vg_name) {
if (!str_list_add(cmd->mem, &lvnames,
- pool_strdup(cmd->mem,
+ dm_pool_strdup(cmd->mem,
lv_name + 1))) {
log_error("strlist allocation failed");
return ECMD_FAILED;
continue;
}
if (!str_list_add(cmd->mem, &tags,
- pool_strdup(cmd->mem,
+ dm_pool_strdup(cmd->mem,
vg_name + 1))) {
log_error("strlist allocation failed");
return ECMD_FAILED;
continue;
}
if (!str_list_add(cmd->mem, &arg_vgnames,
- pool_strdup(cmd->mem, vg_name))) {
+ dm_pool_strdup(cmd->mem, vg_name))) {
log_error("strlist allocation failed");
return ECMD_FAILED;
}
continue;
}
if (!str_list_add(cmd->mem, &tags,
- pool_strdup(cmd->mem,
+ dm_pool_strdup(cmd->mem,
tagname))) {
log_error("strlist allocation failed");
return ECMD_FAILED;
return 0;
}
- vg_name = pool_strdup(cmd->mem, vg_name);
+ vg_name = dm_pool_strdup(cmd->mem, vg_name);
if (!vg_name) {
log_error("Allocation of vg_name failed");
return 0;
return 0;
}
- return pool_strdup(cmd->mem, vg_path);
+ return dm_pool_strdup(cmd->mem, vg_path);
}
/*
* Process physical extent range specifiers
*/
-static int _add_pe_range(struct pool *mem, struct list *pe_ranges,
+static int _add_pe_range(struct dm_pool *mem, struct list *pe_ranges,
uint32_t start, uint32_t count)
{
struct pe_range *per;
}
}
- if (!(per = pool_alloc(mem, sizeof(*per)))) {
+ if (!(per = dm_pool_alloc(mem, sizeof(*per)))) {
log_error("Allocation of list failed");
return 0;
}
return 1;
}
-static int _parse_pes(struct pool *mem, char *c, struct list *pe_ranges,
+static int _parse_pes(struct dm_pool *mem, char *c, struct list *pe_ranges,
uint32_t size)
{
char *endptr;
return 0;
}
-static void _create_pv_entry(struct pool *mem, struct pv_list *pvl,
+static void _create_pv_entry(struct dm_pool *mem, struct pv_list *pvl,
char *colon, int allocatable_only, struct list *r)
{
const char *pvname;
return;
}
- if (!(new_pvl = pool_alloc(mem, sizeof(*new_pvl)))) {
+ if (!(new_pvl = dm_pool_alloc(mem, sizeof(*new_pvl)))) {
log_err("Unable to allocate physical volume list.");
return;
}
memcpy(new_pvl, pvl, sizeof(*new_pvl));
- if (!(pe_ranges = pool_alloc(mem, sizeof(*pe_ranges)))) {
+ if (!(pe_ranges = dm_pool_alloc(mem, sizeof(*pe_ranges)))) {
log_error("Allocation of pe_ranges list failed");
return;
}
list_add(r, &new_pvl->list);
}
-struct list *create_pv_list(struct pool *mem, struct volume_group *vg, int argc,
+struct list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int argc,
char **argv, int allocatable_only)
{
struct list *r;
int i;
/* Build up list of PVs */
- if (!(r = pool_alloc(mem, sizeof(*r)))) {
+ if (!(r = dm_pool_alloc(mem, sizeof(*r)))) {
log_error("Allocation of list failed");
return NULL;
}
pvname = argv[i];
if ((colon = strchr(pvname, ':'))) {
- if (!(pvname = pool_strndup(mem, pvname,
+ if (!(pvname = dm_pool_strndup(mem, pvname,
(unsigned) (colon -
pvname)))) {
log_error("Failed to clone PV name");
return list_empty(r) ? NULL : r;
}
-struct list *clone_pv_list(struct pool *mem, struct list *pvsl)
+struct list *clone_pv_list(struct dm_pool *mem, struct list *pvsl)
{
struct list *r;
struct pv_list *pvl, *new_pvl;
/* Build up list of PVs */
- if (!(r = pool_alloc(mem, sizeof(*r)))) {
+ if (!(r = dm_pool_alloc(mem, sizeof(*r)))) {
log_error("Allocation of list failed");
return NULL;
}
list_init(r);
list_iterate_items(pvl, pvsl) {
- if (!(new_pvl = pool_zalloc(mem, sizeof(*new_pvl)))) {
+ if (!(new_pvl = dm_pool_zalloc(mem, sizeof(*new_pvl)))) {
log_error("Unable to allocate physical volume list.");
return NULL;
}
* <ejt_> k, I'll drop a fixme to that effect
* (I know the device is at least 4k, but not 32k)
*/
- if (!(name = pool_alloc(cmd->mem, PATH_MAX))) {
+ if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) {
log_error("Name allocation failed - device not zeroed");
return 0;
}
#define _LVM_TOOLLIB_H
#include "metadata.h"
-#include "pool.h"
int autobackup_set(void);
int autobackup_init(const char *backup_dir, int keep_days, int keep_number,
* Builds a list of pv's from the names in argv. Used in
* lvcreate/extend.
*/
-struct list *create_pv_list(struct pool *mem, struct volume_group *vg, int argc,
+struct list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int argc,
char **argv, int allocatable_only);
-struct list *clone_pv_list(struct pool *mem, struct list *pvs);
+struct list *clone_pv_list(struct dm_pool *mem, struct list *pvs);
int exec_cmd(const char *command, const char *fscmd, const char *lv_path,
const char *size);
#define _FILE_OFFSET_BITS 64
#include <assert.h>
+#include <libdevmapper.h>
+#include "lvm-types.h"
#include "log.h"
#include "activate.h"
#include "archiver.h"
#include "lvmcache.h"
#include "config.h"
#include "defaults.h"
-#include "dbg_malloc.h"
#include "dev-cache.h"
#include "device.h"
#include "display.h"
#include "locking.h"
#include "lvm-file.h"
#include "lvm-string.h"
-#include "pool.h"
#include "segtype.h"
#include "str_list.h"
#include "toolcontext.h"
char *filename;
if (security_level())
- return dbg_strdup(template);
+ return dm_strdup(template);
- filename = dbg_malloc(PATH_MAX);
+ filename = dm_malloc(PATH_MAX);
if (snprintf(filename, PATH_MAX, template, vg_name) < 0) {
log_error("Error processing filename template %s",
template);
- dbg_free(filename);
+ dm_free(filename);
return NULL;
}
if (*last_filename && !strncmp(*last_filename, filename,
strlen(template))) {
log_error("VGs must be backed up into different files. "
"Use %%s in filename for VG name.");
- dbg_free(filename);
+ dm_free(filename);
return NULL;
}
- dbg_free(*last_filename);
+ dm_free(*last_filename);
*last_filename = filename;
return filename;
ret = process_each_vg(cmd, argc, argv, LCK_VG_READ, 0, &last_filename,
&vg_backup_single);
- dbg_free(last_filename);
+ dm_free(last_filename);
init_pvmove(0);
/********** FIXME
log_print("maximum logical volume size is %s",
(dummy = lvm_show_size(LVM_LV_SIZE_MAX(vg) / 2, LONG)));
- dbg_free(dummy);
+ dm_free(dummy);
dummy = NULL;
**********/
list_add(&vg_to->pvs, pvh);
pv = list_item(pvh, struct pv_list)->pv;
- pv->vg_name = pool_strdup(cmd->mem, vg_to->name);
+ pv->vg_name = dm_pool_strdup(cmd->mem, vg_to->name);
}
vg_to->pv_count += vg_from->pv_count;