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

Use stack return macros throughout.

This commit is contained in:
Alasdair Kergon 2008-01-30 13:19:47 +00:00
parent 962b2a559d
commit c51b9fff19
59 changed files with 789 additions and 1547 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.33 - Version 2.02.33 -
=================================== ===================================
Use stack return macros throughout.
Rely upon internally-cached PV labels while corresponding VG lock is held. Rely upon internally-cached PV labels while corresponding VG lock is held.
Version 2.02.32 - 29th January 2008 Version 2.02.32 - 29th January 2008

View File

@ -100,10 +100,8 @@ static struct dm_task *_setup_task(const char *name, const char *uuid,
{ {
struct dm_task *dmt; struct dm_task *dmt;
if (!(dmt = dm_task_create(task))) { if (!(dmt = dm_task_create(task)))
stack; return_NULL;
return NULL;
}
if (name) if (name)
dm_task_set_name(dmt, name); dm_task_set_name(dmt, name);
@ -127,10 +125,8 @@ static int _info_run(const char *name, const char *dlid, struct dm_info *info,
dmtask = mknodes ? DM_DEVICE_MKNODES : DM_DEVICE_INFO; dmtask = mknodes ? DM_DEVICE_MKNODES : DM_DEVICE_INFO;
if (!(dmt = _setup_task(name, dlid, 0, dmtask))) { if (!(dmt = _setup_task(name, dlid, 0, dmtask)))
stack; return_0;
return 0;
}
if (!with_open_count) if (!with_open_count)
if (!dm_task_no_open_count(dmt)) if (!dm_task_no_open_count(dmt))
@ -259,10 +255,8 @@ static int _status_run(const char *name, const char *uuid,
char *type = NULL; char *type = NULL;
char *params = NULL; char *params = NULL;
if (!(dmt = _setup_task(name, uuid, 0, DM_DEVICE_STATUS))) { if (!(dmt = _setup_task(name, uuid, 0, DM_DEVICE_STATUS)))
stack; return_0;
return 0;
}
if (!dm_task_no_open_count(dmt)) if (!dm_task_no_open_count(dmt))
log_error("Failed to disable open_count"); log_error("Failed to disable open_count");
@ -348,10 +342,8 @@ static int _percent_run(struct dev_manager *dm, const char *name,
*percent = -1; *percent = -1;
if (!(dmt = _setup_task(name, dlid, event_nr, if (!(dmt = _setup_task(name, dlid, event_nr,
wait ? DM_DEVICE_WAITEVENT : DM_DEVICE_STATUS))) { wait ? DM_DEVICE_WAITEVENT : DM_DEVICE_STATUS)))
stack; return_0;
return 0;
}
if (!dm_task_no_open_count(dmt)) if (!dm_task_no_open_count(dmt))
log_error("Failed to disable open_count"); log_error("Failed to disable open_count");
@ -443,10 +435,8 @@ struct dev_manager *dev_manager_create(struct cmd_context *cmd,
struct dm_pool *mem; struct dm_pool *mem;
struct dev_manager *dm; struct dev_manager *dm;
if (!(mem = dm_pool_create("dev_manager", 16 * 1024))) { if (!(mem = dm_pool_create("dev_manager", 16 * 1024)))
stack; return_NULL;
return NULL;
}
if (!(dm = dm_pool_alloc(mem, sizeof(*dm)))) if (!(dm = dm_pool_alloc(mem, sizeof(*dm))))
goto_bad; goto_bad;
@ -509,10 +499,8 @@ int dev_manager_snapshot_percent(struct dev_manager *dm,
*/ */
log_debug("Getting device status percentage for %s", name); log_debug("Getting device status percentage for %s", name);
if (!(_percent(dm, name, dlid, "snapshot", 0, NULL, percent, if (!(_percent(dm, name, dlid, "snapshot", 0, NULL, percent,
NULL))) { NULL)))
stack; return_0;
return 0;
}
/* FIXME dm_pool_free ? */ /* FIXME dm_pool_free ? */
@ -544,10 +532,8 @@ int dev_manager_mirror_percent(struct dev_manager *dm,
log_debug("Getting device mirror status percentage for %s", name); log_debug("Getting device mirror status percentage for %s", name);
if (!(_percent(dm, name, dlid, "mirror", wait, lv, percent, if (!(_percent(dm, name, dlid, "mirror", wait, lv, percent,
event_nr))) { event_nr)))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -691,31 +677,25 @@ static struct dm_tree *_create_partial_dtree(struct dev_manager *dm, struct logi
return NULL; return NULL;
} }
if (!_add_lv_to_dtree(dm, dtree, lv)) { if (!_add_lv_to_dtree(dm, dtree, lv))
stack; goto_bad;
goto fail;
}
/* Add any snapshots of this LV */ /* Add any snapshots of this LV */
list_iterate_safe(snh, snht, &lv->snapshot_segs) list_iterate_safe(snh, snht, &lv->snapshot_segs)
if (!_add_lv_to_dtree(dm, dtree, list_struct_base(snh, struct lv_segment, origin_list)->cow)) { if (!_add_lv_to_dtree(dm, dtree, list_struct_base(snh, struct lv_segment, origin_list)->cow))
stack; goto_bad;
goto fail;
}
/* Add any LVs used by segments in this LV */ /* Add any LVs used by segments in this LV */
list_iterate_items(seg, &lv->segments) list_iterate_items(seg, &lv->segments)
for (s = 0; s < seg->area_count; s++) for (s = 0; s < seg->area_count; s++)
if (seg_type(seg, s) == AREA_LV && seg_lv(seg, s)) { if (seg_type(seg, s) == AREA_LV && seg_lv(seg, s)) {
if (!_add_lv_to_dtree(dm, dtree, seg_lv(seg, s))) { if (!_add_lv_to_dtree(dm, dtree, seg_lv(seg, s)))
stack; goto_bad;
goto fail;
}
} }
return dtree; return dtree;
fail: bad:
dm_tree_free(dtree); dm_tree_free(dtree);
return NULL; return NULL;
} }

View File

@ -175,10 +175,8 @@ static int _mk_link(const char *dev_dir, const char *vg_name,
} }
#ifdef HAVE_SELINUX #ifdef HAVE_SELINUX
if (!dm_set_selinux_context(lv_path, S_IFLNK)) { if (!dm_set_selinux_context(lv_path, S_IFLNK))
stack; return_0;
return 0;
}
#endif #endif
return 1; return 1;
@ -225,17 +223,13 @@ static int _do_fs_op(fs_op_t type, const char *dev_dir, const char *vg_name,
switch (type) { switch (type) {
case FS_ADD: case FS_ADD:
if (!_mk_dir(dev_dir, vg_name) || if (!_mk_dir(dev_dir, vg_name) ||
!_mk_link(dev_dir, vg_name, lv_name, dev)) { !_mk_link(dev_dir, vg_name, lv_name, dev))
stack; return_0;
return 0;
}
break; break;
case FS_DEL: case FS_DEL:
if (!_rm_link(dev_dir, vg_name, lv_name) || if (!_rm_link(dev_dir, vg_name, lv_name) ||
!_rm_dir(dev_dir, vg_name)) { !_rm_dir(dev_dir, vg_name))
stack; return_0;
return 0;
}
break; break;
/* FIXME Use rename() */ /* FIXME Use rename() */
case FS_RENAME: case FS_RENAME:
@ -316,10 +310,8 @@ static int _fs_op(fs_op_t type, const char *dev_dir, const char *vg_name,
{ {
if (memlock()) { if (memlock()) {
if (!_stack_fs_op(type, dev_dir, vg_name, lv_name, dev, if (!_stack_fs_op(type, dev_dir, vg_name, lv_name, dev,
old_lv_name)) { old_lv_name))
stack; return_0;
return 0;
}
return 1; return 1;
} }

12
lib/cache/lvmcache.c vendored
View File

@ -803,10 +803,8 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
if (!(existing = info_from_pvid(pvid_s, 0)) && if (!(existing = info_from_pvid(pvid_s, 0)) &&
!(existing = info_from_pvid(dev->pvid, 0))) { !(existing = info_from_pvid(dev->pvid, 0))) {
if (!(label = label_create(labeller))) { if (!(label = label_create(labeller)))
stack; return_NULL;
return NULL;
}
if (!(info = dm_malloc(sizeof(*info)))) { if (!(info = dm_malloc(sizeof(*info)))) {
log_error("lvmcache_info allocation failed"); log_error("lvmcache_info allocation failed");
label_destroy(label); label_destroy(label);
@ -862,11 +860,9 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
/* Has labeller changed? */ /* Has labeller changed? */
if (info->label->labeller != labeller) { if (info->label->labeller != labeller) {
label_destroy(info->label); label_destroy(info->label);
if (!(info->label = label_create(labeller))) { if (!(info->label = label_create(labeller)))
/* FIXME leaves info without label! */ /* FIXME leaves info without label! */
stack; return_NULL;
return NULL;
}
info->label->info = info; info->label->info = info;
} }
label = info->label; label = info->label;

View File

@ -282,10 +282,8 @@ static int _init_tags(struct cmd_context *cmd, struct config_tree *cft)
if (!cmd->hosttags && find_config_int(cft->root, "tags/hosttags", if (!cmd->hosttags && find_config_int(cft->root, "tags/hosttags",
DEFAULT_HOSTTAGS)) { DEFAULT_HOSTTAGS)) {
/* FIXME Strip out invalid chars: only A-Za-z0-9_+.- */ /* FIXME Strip out invalid chars: only A-Za-z0-9_+.- */
if (!_set_tag(cmd, cmd->hostname)) { if (!_set_tag(cmd, cmd->hostname))
stack; return_0;
return 0;
}
cmd->hosttags = 1; cmd->hosttags = 1;
} }
@ -301,17 +299,13 @@ static int _init_tags(struct cmd_context *cmd, struct config_tree *cft)
} }
if (cn->child) { if (cn->child) {
passes = 0; passes = 0;
if (!_check_host_filters(cmd, cn->child, &passes)) { if (!_check_host_filters(cmd, cn->child, &passes))
stack; return_0;
return 0;
}
if (!passes) if (!passes)
continue; continue;
} }
if (!_set_tag(cmd, tag)) { if (!_set_tag(cmd, tag))
stack; return_0;
return 0;
}
} }
return 1; return 1;
@ -385,10 +379,8 @@ static int _init_lvm_conf(struct cmd_context *cmd)
return 1; return 1;
} }
if (!_load_config_file(cmd, "")) { if (!_load_config_file(cmd, ""))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -400,11 +392,8 @@ static int _init_tag_configs(struct cmd_context *cmd)
/* Tag list may grow while inside this loop */ /* Tag list may grow while inside this loop */
list_iterate_items(sl, &cmd->tags) { list_iterate_items(sl, &cmd->tags) {
if (!_load_config_file(cmd, sl->str)) { if (!_load_config_file(cmd, sl->str))
stack; return_0;
return 0;
}
} }
return 1; return 1;
@ -424,10 +413,8 @@ static int _merge_config_files(struct cmd_context *cmd)
list_iterate_items(cfl, &cmd->config_files) { list_iterate_items(cfl, &cmd->config_files) {
/* Merge all config trees into cmd->cft using merge/tag rules */ /* Merge all config trees into cmd->cft using merge/tag rules */
if (!merge_config_tree(cmd, cmd->cft, cfl->cft)) { if (!merge_config_tree(cmd, cmd->cft, cfl->cft))
stack; return_0;
return 0;
}
} }
return 1; return 1;
@ -694,10 +681,8 @@ static int _init_formats(struct cmd_context *cmd)
return 0; return 0;
} }
if (!(lib = load_shared_library(cmd, cv->v.str, if (!(lib = load_shared_library(cmd, cv->v.str,
"format", 0))) { "format", 0)))
stack; return_0;
return 0;
}
if (!(init_format_fn = dlsym(lib, "init_format"))) { if (!(init_format_fn = dlsym(lib, "init_format"))) {
log_error("Shared library %s does not contain " log_error("Shared library %s does not contain "
@ -790,10 +775,8 @@ static int _init_segtypes(struct cmd_context *cmd)
return 0; return 0;
} }
if (!(lib = load_shared_library(cmd, cv->v.str, if (!(lib = load_shared_library(cmd, cv->v.str,
"segment type", 0))) { "segment type", 0)))
stack; return_0;
return 0;
}
if (!(init_segtype_fn = dlsym(lib, "init_segtype"))) { if (!(init_segtype_fn = dlsym(lib, "init_segtype"))) {
log_error("Shared library %s does not contain " log_error("Shared library %s does not contain "

View File

@ -196,10 +196,8 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
off_t mmap_offset = 0; off_t mmap_offset = 0;
char *buf = NULL; char *buf = NULL;
if (!(p = dm_pool_alloc(c->mem, sizeof(*p)))) { if (!(p = dm_pool_alloc(c->mem, sizeof(*p))))
stack; return_0;
return 0;
}
p->mem = c->mem; p->mem = c->mem;
/* Only use mmap with regular files */ /* Only use mmap with regular files */
@ -217,10 +215,8 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
} }
p->fb = p->fb + mmap_offset; p->fb = p->fb + mmap_offset;
} else { } else {
if (!(buf = dm_malloc(size + size2))) { if (!(buf = dm_malloc(size + size2)))
stack; return_0;
return 0;
}
if (!dev_read_circular(dev, (uint64_t) offset, size, if (!dev_read_circular(dev, (uint64_t) offset, size,
(uint64_t) offset2, size2, buf)) { (uint64_t) offset2, size2, buf)) {
goto out; goto out;
@ -237,10 +233,8 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
p->fe = p->fb + size + size2; p->fe = p->fb + size + size2;
if (!_parse_config_file(p, cft)) { if (!_parse_config_file(p, cft))
stack; goto_out;
goto out;
}
r = 1; r = 1;
@ -537,10 +531,8 @@ static struct config_node *_file(struct parser *p)
{ {
struct config_node *root = NULL, *n, *l = NULL; struct config_node *root = NULL, *n, *l = NULL;
while (p->t != TOK_EOF) { while (p->t != TOK_EOF) {
if (!(n = _section(p))) { if (!(n = _section(p)))
stack; return_0;
return 0;
}
if (!root) if (!root)
root = n; root = n;
@ -555,25 +547,19 @@ static struct config_node *_section(struct parser *p)
{ {
/* IDENTIFIER SECTION_B_CHAR VALUE* SECTION_E_CHAR */ /* IDENTIFIER SECTION_B_CHAR VALUE* SECTION_E_CHAR */
struct config_node *root, *n, *l = NULL; struct config_node *root, *n, *l = NULL;
if (!(root = _create_node(p))) { if (!(root = _create_node(p)))
stack; return_0;
return 0;
}
if (!(root->key = _dup_tok(p))) { if (!(root->key = _dup_tok(p)))
stack; return_0;
return 0;
}
match(TOK_IDENTIFIER); match(TOK_IDENTIFIER);
if (p->t == TOK_SECTION_B) { if (p->t == TOK_SECTION_B) {
match(TOK_SECTION_B); match(TOK_SECTION_B);
while (p->t != TOK_SECTION_E) { while (p->t != TOK_SECTION_E) {
if (!(n = _section(p))) { if (!(n = _section(p)))
stack; return_0;
return 0;
}
if (!root->child) if (!root->child)
root->child = n; root->child = n;
@ -584,10 +570,8 @@ static struct config_node *_section(struct parser *p)
match(TOK_SECTION_E); match(TOK_SECTION_E);
} else { } else {
match(TOK_EQ); match(TOK_EQ);
if (!(root->v = _value(p))) { if (!(root->v = _value(p)))
stack; return_0;
return 0;
}
} }
return root; return root;
@ -600,10 +584,8 @@ static struct config_value *_value(struct parser *p)
if (p->t == TOK_ARRAY_B) { if (p->t == TOK_ARRAY_B) {
match(TOK_ARRAY_B); match(TOK_ARRAY_B);
while (p->t != TOK_ARRAY_E) { while (p->t != TOK_ARRAY_E) {
if (!(l = _type(p))) { if (!(l = _type(p)))
stack; return_0;
return 0;
}
if (!h) if (!h)
h = l; h = l;
@ -656,10 +638,8 @@ static struct config_value *_type(struct parser *p)
v->type = CFG_STRING; v->type = CFG_STRING;
p->tb++, p->te--; /* strip "'s */ p->tb++, p->te--; /* strip "'s */
if (!(v->v.str = _dup_tok(p))) { if (!(v->v.str = _dup_tok(p)))
stack; return_0;
return 0;
}
p->te++; p->te++;
match(TOK_STRING); match(TOK_STRING);
break; break;
@ -847,10 +827,8 @@ static char *_dup_tok(struct parser *p)
{ {
size_t len = p->te - p->tb; size_t len = p->te - p->tb;
char *str = dm_pool_alloc(p->mem, len + 1); char *str = dm_pool_alloc(p->mem, len + 1);
if (!str) { if (!str)
stack; return_0;
return 0;
}
strncpy(str, p->tb, len); strncpy(str, p->tb, len);
str[len] = '\0'; str[len] = '\0';
return str; return str;

View File

@ -87,10 +87,8 @@ int btree_insert(struct btree *t, uint32_t k, void *data)
struct node *p, **c = _lookup(&t->root, key, &p), *n; struct node *p, **c = _lookup(&t->root, key, &p), *n;
if (!*c) { if (!*c) {
if (!(n = dm_pool_alloc(t->mem, sizeof(*n)))) { if (!(n = dm_pool_alloc(t->mem, sizeof(*n))))
stack; return_0;
return 0;
}
n->key = key; n->key = key;
n->data = data; n->data = data;

View File

@ -20,10 +20,8 @@ struct list *str_list_create(struct dm_pool *mem)
{ {
struct list *sl; struct list *sl;
if (!(sl = dm_pool_alloc(mem, sizeof(struct list)))) { if (!(sl = dm_pool_alloc(mem, sizeof(struct list))))
stack; return_NULL;
return NULL;
}
list_init(sl); list_init(sl);
@ -34,19 +32,15 @@ int str_list_add(struct dm_pool *mem, struct list *sll, const char *str)
{ {
struct str_list *sln; struct str_list *sln;
if (!str) { if (!str)
stack; return_0;
return 0;
}
/* Already in list? */ /* Already in list? */
if (str_list_match_item(sll, str)) if (str_list_match_item(sll, str))
return 1; return 1;
if (!(sln = dm_pool_alloc(mem, sizeof(*sln)))) { if (!(sln = dm_pool_alloc(mem, sizeof(*sln))))
stack; return_0;
return 0;
}
sln->str = str; sln->str = str;
list_add(sll, &sln->list); list_add(sll, &sln->list);
@ -74,10 +68,8 @@ int str_list_dup(struct dm_pool *mem, struct list *sllnew,
list_init(sllnew); list_init(sllnew);
list_iterate_items(sl, sllold) { list_iterate_items(sl, sllold) {
if (!str_list_add(mem, sllnew, dm_pool_strdup(mem, sl->str))) { if (!str_list_add(mem, sllnew, dm_pool_strdup(mem, sl->str)))
stack; return_0;
return 0;
}
} }
return 1; return 1;

View File

@ -236,10 +236,8 @@ static int _add_alias(struct device *dev, const char *path)
const char *oldpath; const char *oldpath;
int prefer_old = 1; int prefer_old = 1;
if (!sl) { if (!sl)
stack; return_0;
return 0;
}
/* Is name already there? */ /* Is name already there? */
list_iterate_items(strl, &dev->aliases) { list_iterate_items(strl, &dev->aliases) {
@ -249,10 +247,8 @@ static int _add_alias(struct device *dev, const char *path)
} }
} }
if (!(sl->str = dm_pool_strdup(_cache.mem, path))) { if (!(sl->str = dm_pool_strdup(_cache.mem, path)))
stack; return_0;
return 0;
}
if (!list_empty(&dev->aliases)) { if (!list_empty(&dev->aliases)) {
oldpath = list_item(dev->aliases.n, struct str_list)->str; oldpath = list_item(dev->aliases.n, struct str_list)->str;
@ -294,14 +290,10 @@ static int _insert_dev(const char *path, dev_t d)
(uint32_t) d))) { (uint32_t) d))) {
/* create new device */ /* create new device */
if (loopfile) { if (loopfile) {
if (!(dev = dev_create_file(path, NULL, NULL, 0))) { if (!(dev = dev_create_file(path, NULL, NULL, 0)))
stack; return_0;
return 0; } else if (!(dev = _dev_create(d)))
} return_0;
} else if (!(dev = _dev_create(d))) {
stack;
return 0;
}
if (!(btree_insert(_cache.devices, (uint32_t) d, dev))) { if (!(btree_insert(_cache.devices, (uint32_t) d, dev))) {
log_err("Couldn't insert device into binary tree."); log_err("Couldn't insert device into binary tree.");
@ -369,10 +361,8 @@ static int _insert_dir(const char *dir)
continue; continue;
} }
if (!(path = _join(dir, dirent[n]->d_name))) { if (!(path = _join(dir, dirent[n]->d_name)))
stack; return_0;
return 0;
}
_collapse_slashes(path); _collapse_slashes(path);
r &= _insert(path, 1); r &= _insert(path, 1);
@ -400,10 +390,8 @@ static int _insert_file(const char *path)
return 0; return 0;
} }
if (!_insert_dev(path, 0)) { if (!_insert_dev(path, 0))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -439,10 +427,8 @@ static int _insert(const char *path, int rec)
return 0; return 0;
} }
if (!_insert_dev(path, info.st_rdev)) { if (!_insert_dev(path, info.st_rdev))
stack; return_0;
return 0;
}
r = 1; r = 1;
} }
@ -543,16 +529,13 @@ int dev_cache_init(struct cmd_context *cmd)
_cache.names = NULL; _cache.names = NULL;
_cache.has_scanned = 0; _cache.has_scanned = 0;
if (!(_cache.mem = dm_pool_create("dev_cache", 10 * 1024))) { if (!(_cache.mem = dm_pool_create("dev_cache", 10 * 1024)))
stack; return_0;
return 0;
}
if (!(_cache.names = dm_hash_create(128))) { if (!(_cache.names = dm_hash_create(128))) {
stack;
dm_pool_destroy(_cache.mem); dm_pool_destroy(_cache.mem);
_cache.mem = 0; _cache.mem = 0;
return 0; return_0;
} }
if (!(_cache.devices = btree_create(_cache.mem))) { if (!(_cache.devices = btree_create(_cache.mem))) {

View File

@ -170,10 +170,8 @@ static int _aligned_io(struct device_area *where, void *buffer,
struct device_area widened; struct device_area widened;
if (!(where->dev->flags & DEV_REGULAR) && if (!(where->dev->flags & DEV_REGULAR) &&
!_get_block_size(where->dev, &block_size)) { !_get_block_size(where->dev, &block_size))
stack; return_0;
return 0;
}
if (!block_size) if (!block_size)
block_size = lvm_getpagesize(); block_size = lvm_getpagesize();
@ -200,10 +198,8 @@ static int _aligned_io(struct device_area *where, void *buffer,
/* channel the io through the bounce buffer */ /* channel the io through the bounce buffer */
if (!_io(&widened, bounce, 0)) { if (!_io(&widened, bounce, 0)) {
if (!should_write) { if (!should_write)
stack; return_0;
return 0;
}
/* FIXME pre-extend the file */ /* FIXME pre-extend the file */
memset(bounce, '\n', widened.size); memset(bounce, '\n', widened.size);
} }
@ -354,10 +350,8 @@ int dev_open_flags(struct device *dev, int flags, int direct, int quiet)
if (dev->flags & DEV_REGULAR) if (dev->flags & DEV_REGULAR)
name = dev_name(dev); name = dev_name(dev);
else if (!(name = dev_name_confirmed(dev, quiet))) { else if (!(name = dev_name_confirmed(dev, quiet)))
stack; return_0;
return 0;
}
if (!(dev->flags & DEV_REGULAR)) { if (!(dev->flags & DEV_REGULAR)) {
if (stat(name, &buf) < 0) { if (stat(name, &buf) < 0) {
@ -557,10 +551,8 @@ int dev_read(struct device *dev, uint64_t offset, size_t len, void *buffer)
{ {
struct device_area where; struct device_area where;
if (!dev->open_count) { if (!dev->open_count)
stack; return_0;
return 0;
}
where.dev = dev; where.dev = dev;
where.start = offset; where.start = offset;
@ -607,10 +599,8 @@ int dev_append(struct device *dev, size_t len, void *buffer)
{ {
int r; int r;
if (!dev->open_count) { if (!dev->open_count)
stack; return_0;
return 0;
}
r = dev_write(dev, dev->end, len, buffer); r = dev_write(dev, dev->end, len, buffer);
dev->end += (uint64_t) len; dev->end += (uint64_t) len;
@ -625,10 +615,8 @@ int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer)
{ {
struct device_area where; struct device_area where;
if (!dev->open_count) { if (!dev->open_count)
stack; return_0;
return 0;
}
where.dev = dev; where.dev = dev;
where.start = offset; where.start = offset;
@ -644,10 +632,8 @@ int dev_set(struct device *dev, uint64_t offset, size_t len, int value)
size_t s; size_t s;
char buffer[4096] __attribute((aligned(8))); char buffer[4096] __attribute((aligned(8)));
if (!dev_open(dev)) { if (!dev_open(dev))
stack; return_0;
return 0;
}
if ((offset % SECTOR_SIZE) || (len % SECTOR_SIZE)) if ((offset % SECTOR_SIZE) || (len % SECTOR_SIZE))
log_debug("Wiping %s at %" PRIu64 " length %" PRIsize_t, log_debug("Wiping %s at %" PRIu64 " length %" PRIsize_t,

View File

@ -62,10 +62,8 @@ static int _has_partition_table(struct device *dev)
return -1; return -1;
} }
if (!dev_read(dev, UINT64_C(0), sizeof(buf), &buf)) { if (!dev_read(dev, UINT64_C(0), sizeof(buf), &buf))
stack; goto_out;
goto out;
}
/* FIXME Check for other types of partition table too */ /* FIXME Check for other types of partition table too */

View File

@ -360,10 +360,8 @@ int pvdisplay_short(const struct cmd_context *cmd __attribute((unused)),
if (!pv) if (!pv)
return 0; return 0;
if (!id_write_format(&pv->id, uuid, sizeof(uuid))) { if (!id_write_format(&pv->id, uuid, sizeof(uuid)))
stack; return_0;
return 0;
}
log_print("PV Name %s ", pv_dev_name(pv)); log_print("PV Name %s ", pv_dev_name(pv));
/* FIXME pv->pv_number); */ /* FIXME pv->pv_number); */
@ -407,10 +405,8 @@ int lvdisplay_full(struct cmd_context *cmd,
struct lv_segment *snap_seg = NULL; struct lv_segment *snap_seg = NULL;
float snap_percent; /* fused, fsize; */ float snap_percent; /* fused, fsize; */
if (!id_write_format(&lv->lvid.id[1], uuid, sizeof(uuid))) { if (!id_write_format(&lv->lvid.id[1], uuid, sizeof(uuid)))
stack; return_0;
return 0;
}
inkernel = lv_info(cmd, lv, &info, 1, 1) && info.exists; inkernel = lv_info(cmd, lv, &info, 1, 1) && info.exists;

View File

@ -50,10 +50,8 @@ struct dev_filter *composite_filter_create(int n, struct dev_filter **filters)
{ {
struct dev_filter **filters_copy, *cft; struct dev_filter **filters_copy, *cft;
if (!filters) { if (!filters)
stack; return_NULL;
return NULL;
}
if (!(filters_copy = dm_malloc(sizeof(*filters) * (n + 1)))) { if (!(filters_copy = dm_malloc(sizeof(*filters) * (n + 1)))) {
log_error("composite filters allocation failed"); log_error("composite filters allocation failed");

View File

@ -42,10 +42,8 @@ static int _init_hash(struct pfilter *pf)
if (pf->devices) if (pf->devices)
dm_hash_destroy(pf->devices); dm_hash_destroy(pf->devices);
if (!(pf->devices = dm_hash_create(128))) { if (!(pf->devices = dm_hash_create(128)))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -293,10 +291,8 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,
struct pfilter *pf; struct pfilter *pf;
struct dev_filter *f = NULL; struct dev_filter *f = NULL;
if (!(pf = dm_malloc(sizeof(*pf)))) { if (!(pf = dm_malloc(sizeof(*pf))))
stack; return_NULL;
return NULL;
}
memset(pf, 0, sizeof(*pf)); memset(pf, 0, sizeof(*pf));
if (!(pf->file = dm_malloc(strlen(file) + 1))) if (!(pf->file = dm_malloc(strlen(file) + 1)))

View File

@ -70,10 +70,8 @@ static int _extract_pattern(struct dm_pool *mem, const char *pat,
/* /*
* copy the regex * copy the regex
*/ */
if (!(r = dm_pool_strdup(mem, pat))) { if (!(r = dm_pool_strdup(mem, pat)))
stack; return_0;
return 0;
}
/* /*
* trim the trailing character, having checked it's sep. * trim the trailing character, having checked it's sep.
@ -192,10 +190,8 @@ struct dev_filter *regex_filter_create(struct config_value *patterns)
struct rfilter *rf; struct rfilter *rf;
struct dev_filter *f; struct dev_filter *f;
if (!mem) { if (!mem)
stack; return_NULL;
return NULL;
}
if (!(rf = dm_pool_alloc(mem, sizeof(*rf)))) if (!(rf = dm_pool_alloc(mem, sizeof(*rf))))
goto_bad; goto_bad;

View File

@ -277,9 +277,8 @@ struct dev_filter *lvm_type_filter_create(const char *proc,
f->private = NULL; f->private = NULL;
if (!_scan_proc_dev(proc, cn)) { if (!_scan_proc_dev(proc, cn)) {
stack;
dm_free(f); dm_free(f);
return NULL; return_NULL;
} }
return f; return f;

View File

@ -21,7 +21,6 @@
#include <fcntl.h> #include <fcntl.h>
#define fail do {stack; return 0;} while(0)
#define xx16(v) disk->v = xlate16(disk->v) #define xx16(v) disk->v = xlate16(disk->v)
#define xx32(v) disk->v = xlate32(disk->v) #define xx32(v) disk->v = xlate32(disk->v)
#define xx64(v) disk->v = xlate64(disk->v) #define xx64(v) disk->v = xlate64(disk->v)
@ -218,7 +217,7 @@ static int _read_pvd(struct device *dev, struct pv_disk *pvd)
static int _read_lvd(struct device *dev, uint64_t pos, struct lv_disk *disk) static int _read_lvd(struct device *dev, uint64_t pos, struct lv_disk *disk)
{ {
if (!dev_read(dev, pos, sizeof(*disk), disk)) if (!dev_read(dev, pos, sizeof(*disk), disk))
fail; return_0;
_xlate_lvd(disk); _xlate_lvd(disk);
@ -230,12 +229,12 @@ int read_vgd(struct device *dev, struct vg_disk *vgd, struct pv_disk *pvd)
uint64_t pos = pvd->vg_on_disk.base; uint64_t pos = pvd->vg_on_disk.base;
if (!dev_read(dev, pos, sizeof(*vgd), vgd)) if (!dev_read(dev, pos, sizeof(*vgd), vgd))
fail; return_0;
_xlate_vgd(vgd); _xlate_vgd(vgd);
if ((vgd->lv_max > MAX_LV) || (vgd->pv_max > MAX_PV)) if ((vgd->lv_max > MAX_LV) || (vgd->pv_max > MAX_PV))
fail; return_0;
/* If UUID is missing, create one */ /* If UUID is missing, create one */
if (vgd->vg_uuid[0] == '\0') if (vgd->vg_uuid[0] == '\0')
@ -254,10 +253,10 @@ static int _read_uuids(struct disk_list *data)
while (pos < end && num_read < data->vgd.pv_cur) { while (pos < end && num_read < data->vgd.pv_cur) {
if (!dev_read(data->dev, pos, sizeof(buffer), buffer)) if (!dev_read(data->dev, pos, sizeof(buffer), buffer))
fail; return_0;
if (!(ul = dm_pool_alloc(data->mem, sizeof(*ul)))) if (!(ul = dm_pool_alloc(data->mem, sizeof(*ul))))
fail; return_0;
memcpy(ul->uuid, buffer, NAME_LEN); memcpy(ul->uuid, buffer, NAME_LEN);
ul->uuid[NAME_LEN - 1] = '\0'; ul->uuid[NAME_LEN - 1] = '\0';
@ -288,10 +287,10 @@ static int _read_lvs(struct disk_list *data)
ll = dm_pool_alloc(data->mem, sizeof(*ll)); ll = dm_pool_alloc(data->mem, sizeof(*ll));
if (!ll) if (!ll)
fail; return_0;
if (!_read_lvd(data->dev, pos, &ll->lvd)) if (!_read_lvd(data->dev, pos, &ll->lvd))
fail; return_0;
if (!_check_lvd(&ll->lvd)) if (!_check_lvd(&ll->lvd))
continue; continue;
@ -310,10 +309,10 @@ static int _read_extents(struct disk_list *data)
uint64_t pos = data->pvd.pe_on_disk.base; uint64_t pos = data->pvd.pe_on_disk.base;
if (!extents) if (!extents)
fail; return_0;
if (!dev_read(data->dev, pos, len, extents)) if (!dev_read(data->dev, pos, len, extents))
fail; return_0;
_xlate_extents(extents, data->pvd.pe_total); _xlate_extents(extents, data->pvd.pe_total);
data->extents = extents; data->extents = extents;
@ -347,10 +346,8 @@ static struct disk_list *__read_disk(const struct format_type *fmt,
struct disk_list *dl = dm_pool_zalloc(mem, sizeof(*dl)); struct disk_list *dl = dm_pool_zalloc(mem, sizeof(*dl));
const char *name = dev_name(dev); const char *name = dev_name(dev);
if (!dl) { if (!dl)
stack; return_NULL;
return NULL;
}
dl->dev = dev; dl->dev = dev;
dl->mem = mem; dl->mem = mem;
@ -417,10 +414,8 @@ struct disk_list *read_disk(const struct format_type *fmt, struct device *dev,
{ {
struct disk_list *dl; struct disk_list *dl;
if (!dev_open(dev)) { if (!dev_open(dev))
stack; return_NULL;
return NULL;
}
dl = __read_disk(fmt, dev, mem, vg_name); dl = __read_disk(fmt, dev, mem, vg_name);
@ -519,7 +514,7 @@ static int _write_vgd(struct disk_list *data)
_xlate_vgd(vgd); _xlate_vgd(vgd);
if (!dev_write(data->dev, pos, sizeof(*vgd), vgd)) if (!dev_write(data->dev, pos, sizeof(*vgd), vgd))
fail; return_0;
_xlate_vgd(vgd); _xlate_vgd(vgd);
@ -544,7 +539,7 @@ static int _write_uuids(struct disk_list *data)
pos, NAME_LEN); pos, NAME_LEN);
if (!dev_write(data->dev, pos, NAME_LEN, ul->uuid)) if (!dev_write(data->dev, pos, NAME_LEN, ul->uuid))
fail; return_0;
pos += NAME_LEN; pos += NAME_LEN;
} }
@ -560,7 +555,7 @@ static int _write_lvd(struct device *dev, uint64_t pos, struct lv_disk *disk)
_xlate_lvd(disk); _xlate_lvd(disk);
if (!dev_write(dev, pos, sizeof(*disk), disk)) if (!dev_write(dev, pos, sizeof(*disk), disk))
fail; return_0;
_xlate_lvd(disk); _xlate_lvd(disk);
@ -588,7 +583,7 @@ static int _write_lvs(struct disk_list *data)
} }
if (!_write_lvd(data->dev, pos + offset, &ll->lvd)) if (!_write_lvd(data->dev, pos + offset, &ll->lvd))
fail; return_0;
} }
return 1; return 1;
@ -606,7 +601,7 @@ static int _write_extents(struct disk_list *data)
_xlate_extents(extents, data->pvd.pe_total); _xlate_extents(extents, data->pvd.pe_total);
if (!dev_write(data->dev, pos, len, extents)) if (!dev_write(data->dev, pos, len, extents))
fail; return_0;
_xlate_extents(extents, data->pvd.pe_total); _xlate_extents(extents, data->pvd.pe_total);
@ -643,7 +638,7 @@ static int _write_pvd(struct disk_list *data)
_xlate_pvd((struct pv_disk *) buf); _xlate_pvd((struct pv_disk *) buf);
if (!dev_write(data->dev, pos, size, buf)) { if (!dev_write(data->dev, pos, size, buf)) {
dm_free(buf); dm_free(buf);
fail; return_0;
} }
dm_free(buf); dm_free(buf);
@ -707,10 +702,8 @@ static int _write_all_pvd(const struct format_type *fmt, struct disk_list *data)
{ {
int r; int r;
if (!dev_open(data->dev)) { if (!dev_open(data->dev))
stack; return_0;
return 0;
}
r = __write_all_pvd(fmt, data); r = __write_all_pvd(fmt, data);
@ -731,7 +724,7 @@ int write_disks(const struct format_type *fmt, struct list *pvs)
list_iterate_items(dl, pvs) { list_iterate_items(dl, pvs) {
if (!(_write_all_pvd(fmt, dl))) if (!(_write_all_pvd(fmt, dl)))
fail; return_0;
log_very_verbose("Successfully wrote data to %s", log_very_verbose("Successfully wrote data to %s",
dev_name(dl->dev)); dev_name(dl->dev));

View File

@ -168,7 +168,6 @@ static struct volume_group *_build_vg(struct format_instance *fid,
return vg; return vg;
bad: bad:
stack;
dm_pool_free(mem, vg); dm_pool_free(mem, vg);
return NULL; return NULL;
} }
@ -182,10 +181,8 @@ static struct volume_group *_format1_vg_read(struct format_instance *fid,
struct volume_group *vg = NULL; struct volume_group *vg = NULL;
list_init(&pvs); list_init(&pvs);
if (!mem) { if (!mem)
stack; return_NULL;
return NULL;
}
/* Strip dev_dir if present */ /* Strip dev_dir if present */
vg_name = strip_dir(vg_name, fid->fmt->cmd->dev_dir); vg_name = strip_dir(vg_name, fid->fmt->cmd->dev_dir);
@ -209,10 +206,8 @@ static struct disk_list *_flatten_pv(struct format_instance *fid,
{ {
struct disk_list *dl = dm_pool_alloc(mem, sizeof(*dl)); struct disk_list *dl = dm_pool_alloc(mem, sizeof(*dl));
if (!dl) { if (!dl)
stack; return_NULL;
return NULL;
}
dl->mem = mem; dl->mem = mem;
dl->dev = pv->dev; dl->dev = pv->dev;
@ -224,9 +219,8 @@ static struct disk_list *_flatten_pv(struct format_instance *fid,
!export_vg(&dl->vgd, vg) || !export_vg(&dl->vgd, vg) ||
!export_uuids(dl, vg) || !export_uuids(dl, vg) ||
!export_lvs(dl, vg, pv, dev_dir) || !calculate_layout(dl)) { !export_lvs(dl, vg, pv, dev_dir) || !calculate_layout(dl)) {
stack;
dm_pool_free(mem, dl); dm_pool_free(mem, dl);
return NULL; return_NULL;
} }
return dl; return dl;
@ -241,10 +235,8 @@ static int _flatten_vg(struct format_instance *fid, struct dm_pool *mem,
struct disk_list *data; struct disk_list *data;
list_iterate_items(pvl, &vg->pvs) { list_iterate_items(pvl, &vg->pvs) {
if (!(data = _flatten_pv(fid, mem, vg, pvl->pv, dev_dir))) { if (!(data = _flatten_pv(fid, mem, vg, pvl->pv, dev_dir)))
stack; return_0;
return 0;
}
list_add(pvds, &data->list); list_add(pvds, &data->list);
} }
@ -252,10 +244,8 @@ static int _flatten_vg(struct format_instance *fid, struct dm_pool *mem,
export_numbers(pvds, vg); export_numbers(pvds, vg);
export_pv_act(pvds); export_pv_act(pvds);
if (!export_vg_number(fid, pvds, vg->name, filter)) { if (!export_vg_number(fid, pvds, vg->name, filter))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -267,10 +257,8 @@ static int _format1_vg_write(struct format_instance *fid, struct volume_group *v
struct list pvds; struct list pvds;
int r = 0; int r = 0;
if (!mem) { if (!mem)
stack; return_0;
return 0;
}
list_init(&pvds); list_init(&pvds);
@ -293,25 +281,17 @@ static int _format1_pv_read(const struct format_type *fmt, const char *pv_name,
log_very_verbose("Reading physical volume data %s from disk", pv_name); log_very_verbose("Reading physical volume data %s from disk", pv_name);
if (!mem) { if (!mem)
stack; return_0;
return 0;
}
if (!(dev = dev_cache_get(pv_name, fmt->cmd->filter))) { if (!(dev = dev_cache_get(pv_name, fmt->cmd->filter)))
stack; goto_out;
goto out;
}
if (!(dl = read_disk(fmt, dev, mem, NULL))) { if (!(dl = read_disk(fmt, dev, mem, NULL)))
stack; goto_out;
goto out;
}
if (!import_pv(fmt, fmt->cmd->mem, dl->dev, NULL, pv, &dl->pvd, &dl->vgd)) { if (!import_pv(fmt, fmt->cmd->mem, dl->dev, NULL, pv, &dl->pvd, &dl->vgd))
stack; goto_out;
goto out;
}
pv->fmt = fmt; pv->fmt = fmt;
@ -344,10 +324,8 @@ static int _format1_pv_setup(const struct format_type *fmt,
/* /*
* This works out pe_start and pe_count. * This works out pe_start and pe_count.
*/ */
if (!calculate_extent_count(pv, extent_size, extent_count, pe_start)) { if (!calculate_extent_count(pv, extent_size, extent_count, pe_start))
stack; return_0;
return 0;
}
/* Retain existing extent locations exactly */ /* Retain existing extent locations exactly */
if (((pe_start || extent_count) && (pe_start != pv->pe_start)) || if (((pe_start || extent_count) && (pe_start != pv->pe_start)) ||
@ -390,10 +368,8 @@ static int _format1_pv_write(const struct format_type *fmt, struct physical_volu
struct lvmcache_info *info; struct lvmcache_info *info;
if (!(info = lvmcache_add(fmt->labeller, (char *) &pv->id, pv->dev, if (!(info = lvmcache_add(fmt->labeller, (char *) &pv->id, pv->dev,
pv->vg_name, NULL, 0))) { pv->vg_name, NULL, 0)))
stack; return_0;
return 0;
}
label = info->label; label = info->label;
info->device_size = pv->size << SECTOR_SHIFT; info->device_size = pv->size << SECTOR_SHIFT;
info->fmt = fmt; info->fmt = fmt;
@ -406,10 +382,8 @@ static int _format1_pv_write(const struct format_type *fmt, struct physical_volu
pv->pe_size = pv->pe_count = 0; pv->pe_size = pv->pe_count = 0;
pv->pe_start = LVM1_PE_ALIGN; pv->pe_start = LVM1_PE_ALIGN;
if (!(mem = dm_pool_create("lvm1 pv_write", 1024))) { if (!(mem = dm_pool_create("lvm1 pv_write", 1024)))
stack; return_0;
return 0;
}
if (!(dl = dm_pool_alloc(mem, sizeof(*dl)))) if (!(dl = dm_pool_alloc(mem, sizeof(*dl))))
goto_bad; goto_bad;
@ -473,10 +447,8 @@ static int _format1_vg_setup(struct format_instance *fid, struct volume_group *v
static int _format1_segtype_supported(struct format_instance *fid __attribute((unused)), static int _format1_segtype_supported(struct format_instance *fid __attribute((unused)),
const struct segment_type *segtype) const struct segment_type *segtype)
{ {
if (!(segtype->flags & SEG_FORMAT1_SUPPORT)) { if (!(segtype->flags & SEG_FORMAT1_SUPPORT))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -494,19 +466,16 @@ static struct format_instance *_format1_create_instance(const struct format_type
struct format_instance *fid; struct format_instance *fid;
struct metadata_area *mda; struct metadata_area *mda;
if (!(fid = dm_pool_alloc(fmt->cmd->mem, sizeof(*fid)))) { if (!(fid = dm_pool_alloc(fmt->cmd->mem, sizeof(*fid))))
stack; return_NULL;
return NULL;
}
fid->fmt = fmt; fid->fmt = fmt;
list_init(&fid->metadata_areas); list_init(&fid->metadata_areas);
/* Define a NULL metadata area */ /* Define a NULL metadata area */
if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda)))) { if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda)))) {
stack;
dm_pool_free(fmt->cmd->mem, fid); dm_pool_free(fmt->cmd->mem, fid);
return NULL; return_NULL;
} }
mda->ops = &_metadata_format1_ops; mda->ops = &_metadata_format1_ops;
@ -547,10 +516,8 @@ struct format_type *init_format(struct cmd_context *cmd)
{ {
struct format_type *fmt = dm_malloc(sizeof(*fmt)); struct format_type *fmt = dm_malloc(sizeof(*fmt));
if (!fmt) { if (!fmt)
stack; return_NULL;
return NULL;
}
fmt->cmd = cmd; fmt->cmd = cmd;
fmt->ops = &_format1_ops; fmt->ops = &_format1_ops;

View File

@ -117,10 +117,8 @@ int import_pv(const struct format_type *fmt, struct dm_pool *mem,
list_init(&pv->tags); list_init(&pv->tags);
list_init(&pv->segments); list_init(&pv->segments);
if (!alloc_pv_segment_whole_pv(mem, pv)) { if (!alloc_pv_segment_whole_pv(mem, pv))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -150,10 +148,8 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute((unused))
memcpy(pvd->pv_uuid, pv->id.uuid, ID_LEN); memcpy(pvd->pv_uuid, pv->id.uuid, ID_LEN);
if (pv->vg_name) { if (pv->vg_name) {
if (!_check_vg_name(pv->vg_name)) { if (!_check_vg_name(pv->vg_name))
stack; return_0;
return 0;
}
strncpy((char *)pvd->vg_name, pv->vg_name, sizeof(pvd->vg_name)); strncpy((char *)pvd->vg_name, pv->vg_name, sizeof(pvd->vg_name));
} }
@ -167,10 +163,8 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute((unused))
if (!*vg->system_id || if (!*vg->system_id ||
strncmp(vg->system_id, EXPORTED_TAG, strncmp(vg->system_id, EXPORTED_TAG,
sizeof(EXPORTED_TAG) - 1)) { sizeof(EXPORTED_TAG) - 1)) {
if (!_system_id(cmd, (char *)pvd->system_id, EXPORTED_TAG)) { if (!_system_id(cmd, (char *)pvd->system_id, EXPORTED_TAG))
stack; return_0;
return 0;
}
} }
if (strlen((char *)pvd->vg_name) + sizeof(EXPORTED_TAG) > if (strlen((char *)pvd->vg_name) + sizeof(EXPORTED_TAG) >
sizeof(pvd->vg_name)) { sizeof(pvd->vg_name)) {
@ -184,18 +178,14 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute((unused))
/* Is VG being imported? */ /* Is VG being imported? */
if (vg && !(vg->status & EXPORTED_VG) && *vg->system_id && if (vg && !(vg->status & EXPORTED_VG) && *vg->system_id &&
!strncmp(vg->system_id, EXPORTED_TAG, sizeof(EXPORTED_TAG) - 1)) { !strncmp(vg->system_id, EXPORTED_TAG, sizeof(EXPORTED_TAG) - 1)) {
if (!_system_id(cmd, (char *)pvd->system_id, IMPORTED_TAG)) { if (!_system_id(cmd, (char *)pvd->system_id, IMPORTED_TAG))
stack; return_0;
return 0;
}
} }
/* Generate system_id if PV is in VG */ /* Generate system_id if PV is in VG */
if (!pvd->system_id || !*pvd->system_id) if (!pvd->system_id || !*pvd->system_id)
if (!_system_id(cmd, (char *)pvd->system_id, "")) { if (!_system_id(cmd, (char *)pvd->system_id, ""))
stack; return_0;
return 0;
}
/* Update internal system_id if we changed it */ /* Update internal system_id if we changed it */
if (vg && if (vg &&
@ -227,20 +217,14 @@ int import_vg(struct dm_pool *mem,
struct vg_disk *vgd = &dl->vgd; struct vg_disk *vgd = &dl->vgd;
memcpy(vg->id.uuid, vgd->vg_uuid, ID_LEN); memcpy(vg->id.uuid, vgd->vg_uuid, ID_LEN);
if (!_check_vg_name((char *)dl->pvd.vg_name)) { if (!_check_vg_name((char *)dl->pvd.vg_name))
stack; return_0;
return 0;
}
if (!(vg->name = dm_pool_strdup(mem, (char *)dl->pvd.vg_name))) { if (!(vg->name = dm_pool_strdup(mem, (char *)dl->pvd.vg_name)))
stack; return_0;
return 0;
}
if (!(vg->system_id = dm_pool_alloc(mem, NAME_LEN))) { if (!(vg->system_id = dm_pool_alloc(mem, NAME_LEN)))
stack; return_0;
return 0;
}
*vg->system_id = '\0'; *vg->system_id = '\0';
@ -315,10 +299,8 @@ int import_lv(struct dm_pool *mem, struct logical_volume *lv, struct lv_disk *lv
{ {
lvid_from_lvnum(&lv->lvid, &lv->vg->id, lvd->lv_number); lvid_from_lvnum(&lv->lvid, &lv->vg->id, lvd->lv_number);
if (!(lv->name = _create_lv_name(mem, (char *)lvd->lv_name))) { if (!(lv->name = _create_lv_name(mem, (char *)lvd->lv_name)))
stack; return_0;
return 0;
}
lv->status |= VISIBLE_LV; lv->status |= VISIBLE_LV;
@ -457,15 +439,11 @@ int import_pvs(const struct format_type *fmt, struct dm_pool *mem,
*count = 0; *count = 0;
list_iterate_items(dl, pvds) { list_iterate_items(dl, pvds) {
if (!(pvl = dm_pool_zalloc(mem, sizeof(*pvl))) || if (!(pvl = dm_pool_zalloc(mem, sizeof(*pvl))) ||
!(pvl->pv = dm_pool_alloc(mem, sizeof(*pvl->pv)))) { !(pvl->pv = dm_pool_alloc(mem, sizeof(*pvl->pv))))
stack; return_0;
return 0;
}
if (!import_pv(fmt, mem, dl->dev, vg, pvl->pv, &dl->pvd, &dl->vgd)) { if (!import_pv(fmt, mem, dl->dev, vg, pvl->pv, &dl->pvd, &dl->vgd))
stack; return_0;
return 0;
}
pvl->pv->fmt = fmt; pvl->pv->fmt = fmt;
list_add(results, &pvl->list); list_add(results, &pvl->list);
@ -483,17 +461,13 @@ static struct logical_volume *_add_lv(struct dm_pool *mem,
struct logical_volume *lv; struct logical_volume *lv;
if (!(ll = dm_pool_zalloc(mem, sizeof(*ll))) || if (!(ll = dm_pool_zalloc(mem, sizeof(*ll))) ||
!(ll->lv = dm_pool_zalloc(mem, sizeof(*ll->lv)))) { !(ll->lv = dm_pool_zalloc(mem, sizeof(*ll->lv))))
stack; return_NULL;
return NULL;
}
lv = ll->lv; lv = ll->lv;
lv->vg = vg; lv->vg = vg;
if (!import_lv(mem, lv, lvd)) { if (!import_lv(mem, lv, lvd))
stack; return_NULL;
return NULL;
}
list_add(&vg->lvs, &ll->list); list_add(&vg->lvs, &ll->list);
vg->lv_count++; vg->lv_count++;
@ -512,10 +486,8 @@ int import_lvs(struct dm_pool *mem, struct volume_group *vg, struct list *pvds)
lvd = &ll->lvd; lvd = &ll->lvd;
if (!find_lv(vg, (char *)lvd->lv_name) && if (!find_lv(vg, (char *)lvd->lv_name) &&
!_add_lv(mem, vg, lvd)) { !_add_lv(mem, vg, lvd))
stack; return_0;
return 0;
}
} }
} }
@ -533,49 +505,37 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
uint32_t lv_num; uint32_t lv_num;
struct dm_hash_table *lvd_hash; struct dm_hash_table *lvd_hash;
if (!_check_vg_name(vg->name)) { if (!_check_vg_name(vg->name))
stack; return_0;
return 0;
}
if (!(lvd_hash = dm_hash_create(32))) { if (!(lvd_hash = dm_hash_create(32)))
stack; return_0;
return 0;
}
/* /*
* setup the pv's extents array * setup the pv's extents array
*/ */
len = sizeof(struct pe_disk) * dl->pvd.pe_total; len = sizeof(struct pe_disk) * dl->pvd.pe_total;
if (!(dl->extents = dm_pool_alloc(dl->mem, len))) { if (!(dl->extents = dm_pool_alloc(dl->mem, len)))
stack; goto_out;
goto out;
}
memset(dl->extents, 0, len); memset(dl->extents, 0, len);
list_iterate_items(ll, &vg->lvs) { list_iterate_items(ll, &vg->lvs) {
if (ll->lv->status & SNAPSHOT) if (ll->lv->status & SNAPSHOT)
continue; continue;
if (!(lvdl = dm_pool_alloc(dl->mem, sizeof(*lvdl)))) { if (!(lvdl = dm_pool_alloc(dl->mem, sizeof(*lvdl))))
stack; goto_out;
goto out;
}
_export_lv(&lvdl->lvd, vg, ll->lv, dev_dir); _export_lv(&lvdl->lvd, vg, ll->lv, dev_dir);
lv_num = lvnum_from_lvid(&ll->lv->lvid); lv_num = lvnum_from_lvid(&ll->lv->lvid);
lvdl->lvd.lv_number = lv_num; lvdl->lvd.lv_number = lv_num;
if (!dm_hash_insert(lvd_hash, ll->lv->name, &lvdl->lvd)) { if (!dm_hash_insert(lvd_hash, ll->lv->name, &lvdl->lvd))
stack; goto_out;
goto out;
}
if (!export_extents(dl, lv_num + 1, ll->lv, pv)) { if (!export_extents(dl, lv_num + 1, ll->lv, pv))
stack; goto_out;
goto out;
}
if (lv_is_origin(ll->lv)) if (lv_is_origin(ll->lv))
lvdl->lvd.lv_access |= LV_SNAPSHOT_ORG; lvdl->lvd.lv_access |= LV_SNAPSHOT_ORG;
@ -675,10 +635,8 @@ int export_uuids(struct disk_list *dl, struct volume_group *vg)
struct pv_list *pvl; struct pv_list *pvl;
list_iterate_items(pvl, &vg->pvs) { list_iterate_items(pvl, &vg->pvs) {
if (!(ul = dm_pool_alloc(dl->mem, sizeof(*ul)))) { if (!(ul = dm_pool_alloc(dl->mem, sizeof(*ul))))
stack; return_0;
return 0;
}
memset(ul->uuid, 0, sizeof(ul->uuid)); memset(ul->uuid, 0, sizeof(ul->uuid));
memcpy(ul->uuid, pvl->pv->id.uuid, ID_LEN); memcpy(ul->uuid, pvl->pv->id.uuid, ID_LEN);
@ -723,10 +681,8 @@ int export_vg_number(struct format_instance *fid, struct list *pvds,
struct disk_list *dl; struct disk_list *dl;
int vg_num; int vg_num;
if (!get_free_vg_number(fid, filter, vg_name, &vg_num)) { if (!get_free_vg_number(fid, filter, vg_name, &vg_num))
stack; return_0;
return 0;
}
list_iterate_items(dl, pvds) list_iterate_items(dl, pvds)
dl->vgd.vg_number = vg_num; dl->vgd.vg_number = vg_num;

View File

@ -118,10 +118,8 @@ static int _fill_maps(struct dm_hash_table *maps, struct volume_group *vg,
e = dl->extents; e = dl->extents;
/* build an array of lv's for this pv */ /* build an array of lv's for this pv */
if (!_fill_lv_array(lvms, maps, dl)) { if (!_fill_lv_array(lvms, maps, dl))
stack; return_0;
return 0;
}
for (i = 0; i < dl->pvd.pe_total; i++) { for (i = 0; i < dl->pvd.pe_total; i++) {
lv_num = e[i].lv_num; lv_num = e[i].lv_num;
@ -189,10 +187,8 @@ static int _check_maps_are_complete(struct dm_hash_table *maps)
for (n = dm_hash_get_first(maps); n; n = dm_hash_get_next(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); lvm = (struct lv_map *) dm_hash_get_data(maps, n);
if (!_check_single_map(lvm)) { if (!_check_single_map(lvm))
stack; return_0;
return 0;
}
} }
return 1; return 1;
} }
@ -216,10 +212,8 @@ static int _read_linear(struct cmd_context *cmd, struct lv_map *lvm)
struct lv_segment *seg; struct lv_segment *seg;
struct segment_type *segtype; struct segment_type *segtype;
if (!(segtype = get_segtype_from_string(cmd, "striped"))) { if (!(segtype = get_segtype_from_string(cmd, "striped")))
stack; return_0;
return 0;
}
while (le < lvm->lv->le_count) { while (le < lvm->lv->le_count) {
len = _area_length(lvm, le); len = _area_length(lvm, le);
@ -334,10 +328,8 @@ static int _build_all_segments(struct cmd_context *cmd, struct dm_hash_table *ma
for (n = dm_hash_get_first(maps); n; n = dm_hash_get_next(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); lvm = (struct lv_map *) dm_hash_get_data(maps, n);
if (!_build_segments(cmd, lvm)) { if (!_build_segments(cmd, lvm))
stack; return_0;
return 0;
}
} }
return 1; return 1;
@ -350,10 +342,8 @@ int import_extents(struct cmd_context *cmd, struct volume_group *vg,
struct dm_pool *scratch = dm_pool_create("lvm1 import_extents", 10 * 1024); struct dm_pool *scratch = dm_pool_create("lvm1 import_extents", 10 * 1024);
struct dm_hash_table *maps; struct dm_hash_table *maps;
if (!scratch) { if (!scratch)
stack; return_0;
return 0;
}
if (!(maps = _create_lv_maps(scratch, vg))) { if (!(maps = _create_lv_maps(scratch, vg))) {
log_err("Couldn't allocate logical volume maps."); log_err("Couldn't allocate logical volume maps.");
@ -365,10 +355,8 @@ int import_extents(struct cmd_context *cmd, struct volume_group *vg,
goto out; goto out;
} }
if (!_check_maps_are_complete(maps) && !(vg->status & PARTIAL_VG)) { if (!_check_maps_are_complete(maps) && !(vg->status & PARTIAL_VG))
stack; goto_out;
goto out;
}
if (!_build_all_segments(cmd, maps)) { if (!_build_all_segments(cmd, maps)) {
log_err("Couldn't build extent segments."); log_err("Couldn't build extent segments.");

View File

@ -122,10 +122,8 @@ int calculate_extent_count(struct physical_volume *pv, uint32_t extent_size,
struct pv_disk *pvd = dm_malloc(sizeof(*pvd)); struct pv_disk *pvd = dm_malloc(sizeof(*pvd));
uint32_t end; uint32_t end;
if (!pvd) { if (!pvd)
stack; return_0;
return 0;
}
/* /*
* Guess how many extents will fit, bearing in mind that * Guess how many extents will fit, bearing in mind that

View File

@ -71,10 +71,8 @@ static int _lvm1_read(struct labeller *l, struct device *dev, void *buf,
} }
if (!(info = lvmcache_add(l, (char *)pvd->pv_uuid, dev, (char *)pvd->vg_name, vgid, if (!(info = lvmcache_add(l, (char *)pvd->pv_uuid, dev, (char *)pvd->vg_name, vgid,
exported))) { exported)))
stack; return_0;
return 0;
}
*label = info->label; *label = info->label;
info->device_size = xlate32(pvd->pv_size) << SECTOR_SHIFT; info->device_size = xlate32(pvd->pv_size) << SECTOR_SHIFT;

View File

@ -33,15 +33,11 @@ int get_free_vg_number(struct format_instance *fid, struct dev_filter *filter,
list_init(&all_pvs); list_init(&all_pvs);
if (!mem) { if (!mem)
stack; return_0;
return 0;
}
if (!read_pvs_in_vg(fid->fmt, NULL, filter, mem, &all_pvs)) { if (!read_pvs_in_vg(fid->fmt, NULL, filter, mem, &all_pvs))
stack; goto_out;
goto out;
}
memset(numbers, 0, sizeof(numbers)); memset(numbers, 0, sizeof(numbers));

View File

@ -45,10 +45,8 @@ static int __read_pool_disk(const struct format_type *fmt, struct device *dev,
return 0; return 0;
} }
if (!read_pool_label(pl, fmt->labeller, dev, buf, NULL)) { if (!read_pool_label(pl, fmt->labeller, dev, buf, NULL))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -98,10 +96,8 @@ int read_pool_label(struct pool_list *pl, struct labeller *l,
log_debug("Calculated uuid %s for %s", uuid, pd->pl_pool_name); log_debug("Calculated uuid %s for %s", uuid, pd->pl_pool_name);
if (!(info = lvmcache_add(l, (char *) &pvid, dev, pd->pl_pool_name, if (!(info = lvmcache_add(l, (char *) &pvid, dev, pd->pl_pool_name,
(char *) &vgid, 0))) { (char *) &vgid, 0)))
stack; return_0;
return 0;
}
if (label) if (label)
*label = info->label; *label = info->label;
@ -252,10 +248,8 @@ static int _read_vg_pds(const struct format_type *fmt, struct dm_pool *mem,
/* FIXME: maybe should return a different error in memory /* FIXME: maybe should return a different error in memory
* allocation failure */ * allocation failure */
if (!(tmpmem = dm_pool_create("pool read_vg", 512))) { if (!(tmpmem = dm_pool_create("pool read_vg", 512)))
stack; return_0;
return 0;
}
list_iterate_items(info, &vginfo->infos) { list_iterate_items(info, &vginfo->infos) {
if (info->dev && if (info->dev &&
@ -354,20 +348,16 @@ struct pool_list *read_pool_disk(const struct format_type *fmt,
{ {
struct pool_list *pl; struct pool_list *pl;
if (!dev_open(dev)) { if (!dev_open(dev))
stack; return_NULL;
return NULL;
}
if (!(pl = dm_pool_zalloc(mem, sizeof(*pl)))) { if (!(pl = dm_pool_zalloc(mem, sizeof(*pl)))) {
log_error("Unable to allocate pool list structure"); log_error("Unable to allocate pool list structure");
return 0; return 0;
} }
if (!__read_pool_disk(fmt, dev, mem, pl, vg_name)) { if (!__read_pool_disk(fmt, dev, mem, pl, vg_name))
stack; return_NULL;
return NULL;
}
if (!dev_close(dev)) if (!dev_close(dev))
stack; stack;

View File

@ -128,44 +128,32 @@ static struct volume_group *_build_vg_from_pds(struct format_instance
list_init(&vg->lvs); list_init(&vg->lvs);
list_init(&vg->tags); list_init(&vg->tags);
if (!import_pool_vg(vg, smem, pds)) { if (!import_pool_vg(vg, smem, pds))
stack; return_NULL;
return NULL;
}
if (!import_pool_pvs(fid->fmt, vg, &vg->pvs, smem, pds)) { if (!import_pool_pvs(fid->fmt, vg, &vg->pvs, smem, pds))
stack; return_NULL;
return NULL;
}
if (!import_pool_lvs(vg, smem, pds)) { if (!import_pool_lvs(vg, smem, pds))
stack; return_NULL;
return NULL;
}
/* /*
* I need an intermediate subpool structure that contains all the * I need an intermediate subpool structure that contains all the
* relevant info for this. Then i can iterate through the subpool * relevant info for this. Then i can iterate through the subpool
* structures for checking, and create the segments * structures for checking, and create the segments
*/ */
if (!(usp = _build_usp(pds, mem, &sp_count))) { if (!(usp = _build_usp(pds, mem, &sp_count)))
stack; return_NULL;
return NULL;
}
/* /*
* check the subpool structures - we can't handle partial VGs in * check the subpool structures - we can't handle partial VGs in
* the pool format, so this will error out if we're missing PVs * the pool format, so this will error out if we're missing PVs
*/ */
if (!_check_usp(vg->name, usp, sp_count)) { if (!_check_usp(vg->name, usp, sp_count))
stack; return_NULL;
return NULL;
}
if (!import_pool_segments(&vg->lvs, smem, usp, sp_count)) { if (!import_pool_segments(&vg->lvs, smem, usp, sp_count))
stack; return_NULL;
return NULL;
}
return vg; return vg;
} }
@ -182,25 +170,19 @@ static struct volume_group *_pool_vg_read(struct format_instance *fid,
/* We can safely ignore the mda passed in */ /* We can safely ignore the mda passed in */
if (!mem) { if (!mem)
stack; return_NULL;
return NULL;
}
/* Strip dev_dir if present */ /* Strip dev_dir if present */
vg_name = strip_dir(vg_name, fid->fmt->cmd->dev_dir); vg_name = strip_dir(vg_name, fid->fmt->cmd->dev_dir);
/* Read all the pvs in the vg */ /* Read all the pvs in the vg */
if (!read_pool_pds(fid->fmt, vg_name, mem, &pds)) { if (!read_pool_pds(fid->fmt, vg_name, mem, &pds))
stack; goto_out;
goto out;
}
/* Do the rest of the vg stuff */ /* Do the rest of the vg stuff */
if (!(vg = _build_vg_from_pds(fid, mem, &pds))) { if (!(vg = _build_vg_from_pds(fid, mem, &pds)))
stack; goto_out;
goto out;
}
out: out:
dm_pool_destroy(mem); dm_pool_destroy(mem);
@ -231,30 +213,22 @@ static int _pool_pv_read(const struct format_type *fmt, const char *pv_name,
log_very_verbose("Reading physical volume data %s from disk", pv_name); log_very_verbose("Reading physical volume data %s from disk", pv_name);
if (!mem) { if (!mem)
stack; return_0;
return 0;
}
if (!(dev = dev_cache_get(pv_name, fmt->cmd->filter))) { if (!(dev = dev_cache_get(pv_name, fmt->cmd->filter)))
stack; goto_out;
goto out;
}
/* /*
* I need to read the disk and populate a pv structure here * I need to read the disk and populate a pv structure here
* I'll probably need to abstract some of this later for the * I'll probably need to abstract some of this later for the
* vg_read code * vg_read code
*/ */
if (!(pl = read_pool_disk(fmt, dev, mem, NULL))) { if (!(pl = read_pool_disk(fmt, dev, mem, NULL)))
stack; goto_out;
goto out;
}
if (!import_pool_pv(fmt, fmt->cmd->mem, NULL, pv, pl)) { if (!import_pool_pv(fmt, fmt->cmd->mem, NULL, pv, pl))
stack; goto_out;
goto out;
}
pv->fmt = fmt; pv->fmt = fmt;

View File

@ -91,10 +91,8 @@ int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem, struct list *p
if (lv->name) if (lv->name)
continue; continue;
if (!(lv->name = dm_pool_strdup(mem, pl->pd.pl_pool_name))) { if (!(lv->name = dm_pool_strdup(mem, pl->pd.pl_pool_name)))
stack; return_0;
return 0;
}
get_pool_lv_uuid(lv->lvid.id, &pl->pd); get_pool_lv_uuid(lv->lvid.id, &pl->pd);
log_debug("Calculated lv uuid for lv %s: %s", lv->name, log_debug("Calculated lv uuid for lv %s: %s", lv->name,
@ -178,10 +176,8 @@ int import_pool_pv(const struct format_type *fmt, struct dm_pool *mem,
list_init(&pv->tags); list_init(&pv->tags);
list_init(&pv->segments); list_init(&pv->segments);
if (!alloc_pv_segment_whole_pv(mem, pv)) { if (!alloc_pv_segment_whole_pv(mem, pv))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -216,10 +212,8 @@ static int _add_stripe_seg(struct dm_pool *mem,
area_len = (usp->devs[0].blocks) / POOL_PE_SIZE; area_len = (usp->devs[0].blocks) / POOL_PE_SIZE;
if (!(segtype = get_segtype_from_string(lv->vg->cmd, if (!(segtype = get_segtype_from_string(lv->vg->cmd,
"striped"))) { "striped")))
stack; return_0;
return 0;
}
if (!(seg = alloc_lv_segment(mem, segtype, lv, *le_cur, if (!(seg = alloc_lv_segment(mem, segtype, lv, *le_cur,
area_len * usp->num_devs, 0, area_len * usp->num_devs, 0,
@ -230,10 +224,8 @@ static int _add_stripe_seg(struct dm_pool *mem,
} }
for (j = 0; j < usp->num_devs; j++) for (j = 0; j < usp->num_devs; j++)
if (!set_lv_segment_area_pv(seg, j, usp->devs[j].pv, 0)) { if (!set_lv_segment_area_pv(seg, j, usp->devs[j].pv, 0))
stack; return_0;
return 0;
}
/* add the subpool type to the segment tag list */ /* add the subpool type to the segment tag list */
str_list_add(mem, &seg->tags, _cvt_sptype(usp->type)); str_list_add(mem, &seg->tags, _cvt_sptype(usp->type));
@ -254,10 +246,8 @@ static int _add_linear_seg(struct dm_pool *mem,
unsigned j; unsigned j;
uint32_t area_len; uint32_t area_len;
if (!(segtype = get_segtype_from_string(lv->vg->cmd, "striped"))) { if (!(segtype = get_segtype_from_string(lv->vg->cmd, "striped")))
stack; return_0;
return 0;
}
for (j = 0; j < usp->num_devs; j++) { for (j = 0; j < usp->num_devs; j++) {
area_len = (usp->devs[j].blocks) / POOL_PE_SIZE; area_len = (usp->devs[j].blocks) / POOL_PE_SIZE;
@ -274,10 +264,8 @@ static int _add_linear_seg(struct dm_pool *mem,
/* add the subpool type to the segment tag list */ /* add the subpool type to the segment tag list */
str_list_add(mem, &seg->tags, _cvt_sptype(usp->type)); str_list_add(mem, &seg->tags, _cvt_sptype(usp->type));
if (!set_lv_segment_area_pv(seg, 0, usp->devs[j].pv, 0)) { if (!set_lv_segment_area_pv(seg, 0, usp->devs[j].pv, 0))
stack; return_0;
return 0;
}
list_add(&lv->segments, &seg->list); list_add(&lv->segments, &seg->list);
*le_cur += seg->len; *le_cur += seg->len;
@ -302,15 +290,11 @@ int import_pool_segments(struct list *lvs, struct dm_pool *mem,
for (i = 0; i < subpools; i++) { for (i = 0; i < subpools; i++) {
if (usp[i].striping) { if (usp[i].striping) {
if (!_add_stripe_seg(mem, &usp[i], lv, &le_cur)) { if (!_add_stripe_seg(mem, &usp[i], lv, &le_cur))
stack; return_0;
return 0;
}
} else { } else {
if (!_add_linear_seg(mem, &usp[i], lv, &le_cur)) { if (!_add_linear_seg(mem, &usp[i], lv, &le_cur))
stack; return_0;
return 0;
}
} }
} }
} }

View File

@ -113,10 +113,8 @@ static char *_join_file_to_dir(struct dm_pool *mem, const char *dir, const char
!dm_pool_grow_object(mem, dir, strlen(dir)) || !dm_pool_grow_object(mem, dir, strlen(dir)) ||
!dm_pool_grow_object(mem, "/", 1) || !dm_pool_grow_object(mem, "/", 1) ||
!dm_pool_grow_object(mem, name, strlen(name)) || !dm_pool_grow_object(mem, name, strlen(name)) ||
!dm_pool_grow_object(mem, "\0", 1)) { !dm_pool_grow_object(mem, "\0", 1))
stack; return_NULL;
return NULL;
}
return dm_pool_end_object(mem); return dm_pool_end_object(mem);
} }
@ -134,10 +132,8 @@ static struct list *_scan_archive(struct dm_pool *mem,
struct archive_file *af; struct archive_file *af;
struct list *results; struct list *results;
if (!(results = dm_pool_alloc(mem, sizeof(*results)))) { if (!(results = dm_pool_alloc(mem, sizeof(*results))))
stack; return_NULL;
return NULL;
}
list_init(results); list_init(results);
@ -161,10 +157,8 @@ static struct list *_scan_archive(struct dm_pool *mem,
if (strcmp(vgname, vgname_found)) if (strcmp(vgname, vgname_found))
continue; continue;
if (!(path = _join_file_to_dir(mem, dir, dirent[i]->d_name))) { if (!(path = _join_file_to_dir(mem, dir, dirent[i]->d_name)))
stack; goto_out;
goto out;
}
/* /*
* Create a new archive_file. * Create a new archive_file.
@ -255,10 +249,9 @@ int archive_vg(struct volume_group *vg,
} }
if (!text_vg_export_file(vg, desc, fp)) { if (!text_vg_export_file(vg, desc, fp)) {
stack;
if (fclose(fp)) if (fclose(fp))
log_sys_error("fclose", temp_file); log_sys_error("fclose", temp_file);
return 0; return_0;
} }
if (lvm_fclose(fp, temp_file)) if (lvm_fclose(fp, temp_file))
@ -267,10 +260,8 @@ int archive_vg(struct volume_group *vg,
/* /*
* Now we want to rename this file to <vg>_index.vg. * Now we want to rename this file to <vg>_index.vg.
*/ */
if (!(archives = _scan_archive(vg->cmd->mem, vg->name, dir))) { if (!(archives = _scan_archive(vg->cmd->mem, vg->name, dir)))
stack; return_0;
return 0;
}
if (list_empty(archives)) if (list_empty(archives))
ix = 0; ix = 0;
@ -343,10 +334,8 @@ int archive_list(struct cmd_context *cmd, const char *dir, const char *vgname)
struct list *archives; struct list *archives;
struct archive_file *af; struct archive_file *af;
if (!(archives = _scan_archive(cmd->mem, vgname, dir))) { if (!(archives = _scan_archive(cmd->mem, vgname, dir)))
stack; return_0;
return 0;
}
if (list_empty(archives)) if (list_empty(archives))
log_print("No archives found in %s.", dir); log_print("No archives found in %s.", dir);
@ -379,10 +368,8 @@ int backup_list(struct cmd_context *cmd, const char *dir, const char *vgname)
{ {
struct archive_file af; struct archive_file af;
if (!(af.path = _join_file_to_dir(cmd->mem, dir, vgname))) { if (!(af.path = _join_file_to_dir(cmd->mem, dir, vgname)))
stack; return_0;
return 0;
}
if (path_exists(af.path)) if (path_exists(af.path))
_display_archive(cmd, &af); _display_archive(cmd, &af);

View File

@ -78,17 +78,13 @@ static char *_build_desc(struct dm_pool *mem, const char *line, int before)
size_t len = strlen(line) + 32; size_t len = strlen(line) + 32;
char *buffer; char *buffer;
if (!(buffer = dm_pool_zalloc(mem, strlen(line) + 32))) { if (!(buffer = dm_pool_zalloc(mem, strlen(line) + 32)))
stack; return_NULL;
return NULL;
}
if (snprintf(buffer, len, if (snprintf(buffer, len,
"Created %s executing '%s'", "Created %s executing '%s'",
before ? "*before*" : "*after*", line) < 0) { before ? "*before*" : "*after*", line) < 0)
stack; return_NULL;
return NULL;
}
return buffer; return buffer;
} }
@ -97,10 +93,8 @@ static int __archive(struct volume_group *vg)
{ {
char *desc; char *desc;
if (!(desc = _build_desc(vg->cmd->mem, vg->cmd->cmd_line, 1))) { if (!(desc = _build_desc(vg->cmd->mem, vg->cmd->cmd_line, 1)))
stack; return_0;
return 0;
}
return archive_vg(vg, vg->cmd->archive_params->dir, desc, return archive_vg(vg, vg->cmd->archive_params->dir, desc,
vg->cmd->archive_params->keep_days, vg->cmd->archive_params->keep_days,
@ -196,10 +190,8 @@ static int __backup(struct volume_group *vg)
char name[PATH_MAX]; char name[PATH_MAX];
char *desc; char *desc;
if (!(desc = _build_desc(vg->cmd->mem, vg->cmd->cmd_line, 0))) { if (!(desc = _build_desc(vg->cmd->mem, vg->cmd->cmd_line, 0)))
stack; return_0;
return 0;
}
if (dm_snprintf(name, sizeof(name), "%s/%s", if (dm_snprintf(name, sizeof(name), "%s/%s",
vg->cmd->backup_params->dir, vg->name) < 0) { vg->cmd->backup_params->dir, vg->name) < 0) {
@ -324,10 +316,8 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg)
} }
} }
if (!vg_write(vg) || !vg_commit(vg)) { if (!vg_write(vg) || !vg_commit(vg))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -341,10 +331,8 @@ int backup_restore_from_file(struct cmd_context *cmd, const char *vg_name,
/* /*
* Read in the volume group from the text file. * Read in the volume group from the text file.
*/ */
if (!(vg = backup_read_vg(cmd, vg_name, file))) { if (!(vg = backup_read_vg(cmd, vg_name, file)))
stack; return_0;
return 0;
}
return backup_restore_vg(cmd, vg); return backup_restore_vg(cmd, vg);
} }

View File

@ -135,10 +135,8 @@ static int _nl_raw(struct formatter *f)
{ {
/* If metadata doesn't fit, extend buffer */ /* If metadata doesn't fit, extend buffer */
if ((f->data.buf.used + 2 > f->data.buf.size) && if ((f->data.buf.used + 2 > f->data.buf.size) &&
(!_extend_buffer(f))) { (!_extend_buffer(f)))
stack; return_0;
return 0;
}
*(f->data.buf.start + f->data.buf.used) = '\n'; *(f->data.buf.start + f->data.buf.used) = '\n';
f->data.buf.used += 1; f->data.buf.used += 1;
@ -195,10 +193,8 @@ static int _out_with_comment_raw(struct formatter *f,
/* If metadata doesn't fit, extend buffer */ /* If metadata doesn't fit, extend buffer */
if (n < 0 || (n + f->data.buf.used + 2 > f->data.buf.size)) { if (n < 0 || (n + f->data.buf.used + 2 > f->data.buf.size)) {
if (!_extend_buffer(f)) { if (!_extend_buffer(f))
stack; return_0;
return 0;
}
return -1; /* Retry */ return -1; /* Retry */
} }
@ -323,26 +319,20 @@ static int _print_vg(struct formatter *f, struct volume_group *vg)
{ {
char buffer[4096]; char buffer[4096];
if (!id_write_format(&vg->id, buffer, sizeof(buffer))) { if (!id_write_format(&vg->id, buffer, sizeof(buffer)))
stack; return_0;
return 0;
}
outf(f, "id = \"%s\"", buffer); outf(f, "id = \"%s\"", buffer);
outf(f, "seqno = %u", vg->seqno); outf(f, "seqno = %u", vg->seqno);
if (!print_flags(vg->status, VG_FLAGS, buffer, sizeof(buffer))) { if (!print_flags(vg->status, VG_FLAGS, buffer, sizeof(buffer)))
stack; return_0;
return 0;
}
outf(f, "status = %s", buffer); outf(f, "status = %s", buffer);
if (!list_empty(&vg->tags)) { if (!list_empty(&vg->tags)) {
if (!print_tags(&vg->tags, buffer, sizeof(buffer))) { if (!print_tags(&vg->tags, buffer, sizeof(buffer)))
stack; return_0;
return 0;
}
outf(f, "tags = %s", buffer); outf(f, "tags = %s", buffer);
} }
@ -350,10 +340,8 @@ static int _print_vg(struct formatter *f, struct volume_group *vg)
outf(f, "system_id = \"%s\"", vg->system_id); outf(f, "system_id = \"%s\"", vg->system_id);
if (!out_size(f, (uint64_t) vg->extent_size, "extent_size = %u", if (!out_size(f, (uint64_t) vg->extent_size, "extent_size = %u",
vg->extent_size)) { vg->extent_size))
stack; return_0;
return 0;
}
outf(f, "max_lv = %u", vg->max_lv); outf(f, "max_lv = %u", vg->max_lv);
outf(f, "max_pv = %u", vg->max_pv); outf(f, "max_pv = %u", vg->max_pv);
@ -390,52 +378,38 @@ static int _print_pvs(struct formatter *f, struct volume_group *vg)
list_iterate_items(pvl, &vg->pvs) { list_iterate_items(pvl, &vg->pvs) {
pv = pvl->pv; pv = pvl->pv;
if (!(name = _get_pv_name(f, pv))) { if (!(name = _get_pv_name(f, pv)))
stack; return_0;
return 0;
}
outnl(f); outnl(f);
outf(f, "%s {", name); outf(f, "%s {", name);
_inc_indent(f); _inc_indent(f);
if (!id_write_format(&pv->id, buffer, sizeof(buffer))) { if (!id_write_format(&pv->id, buffer, sizeof(buffer)))
stack; return_0;
return 0;
}
outf(f, "id = \"%s\"", buffer); outf(f, "id = \"%s\"", buffer);
if (!out_hint(f, "device = \"%s\"", pv_dev_name(pv))) { if (!out_hint(f, "device = \"%s\"", pv_dev_name(pv)))
stack; return_0;
return 0;
}
outnl(f); outnl(f);
if (!print_flags(pv->status, PV_FLAGS, buffer, sizeof(buffer))) { if (!print_flags(pv->status, PV_FLAGS, buffer, sizeof(buffer)))
stack; return_0;
return 0;
}
outf(f, "status = %s", buffer); outf(f, "status = %s", buffer);
if (!list_empty(&pv->tags)) { if (!list_empty(&pv->tags)) {
if (!print_tags(&pv->tags, buffer, sizeof(buffer))) { if (!print_tags(&pv->tags, buffer, sizeof(buffer)))
stack; return_0;
return 0;
}
outf(f, "tags = %s", buffer); outf(f, "tags = %s", buffer);
} }
if (!out_size(f, pv->size, "dev_size = %" PRIu64, pv->size)) { if (!out_size(f, pv->size, "dev_size = %" PRIu64, pv->size))
stack; return_0;
return 0;
}
outf(f, "pe_start = %" PRIu64, pv->pe_start); outf(f, "pe_start = %" PRIu64, pv->pe_start);
if (!out_size(f, vg->extent_size * (uint64_t) pv->pe_count, if (!out_size(f, vg->extent_size * (uint64_t) pv->pe_count,
"pe_count = %u", pv->pe_count)) { "pe_count = %u", pv->pe_count))
stack; return_0;
return 0;
}
_dec_indent(f); _dec_indent(f);
outf(f, "}"); outf(f, "}");
@ -456,27 +430,21 @@ static int _print_segment(struct formatter *f, struct volume_group *vg,
outf(f, "start_extent = %u", seg->le); outf(f, "start_extent = %u", seg->le);
if (!out_size(f, (uint64_t) seg->len * vg->extent_size, if (!out_size(f, (uint64_t) seg->len * vg->extent_size,
"extent_count = %u", seg->len)) { "extent_count = %u", seg->len))
stack; return_0;
return 0;
}
outnl(f); outnl(f);
outf(f, "type = \"%s\"", seg->segtype->name); outf(f, "type = \"%s\"", seg->segtype->name);
if (!list_empty(&seg->tags)) { if (!list_empty(&seg->tags)) {
if (!print_tags(&seg->tags, buffer, sizeof(buffer))) { if (!print_tags(&seg->tags, buffer, sizeof(buffer)))
stack; return_0;
return 0;
}
outf(f, "tags = %s", buffer); outf(f, "tags = %s", buffer);
} }
if (seg->segtype->ops->text_export && if (seg->segtype->ops->text_export &&
!seg->segtype->ops->text_export(seg, f)) { !seg->segtype->ops->text_export(seg, f))
stack; return_0;
return 0;
}
_dec_indent(f); _dec_indent(f);
outf(f, "}"); outf(f, "}");
@ -498,10 +466,8 @@ int out_areas(struct formatter *f, const struct lv_segment *seg,
for (s = 0; s < seg->area_count; s++) { for (s = 0; s < seg->area_count; s++) {
switch (seg_type(seg, s)) { switch (seg_type(seg, s)) {
case AREA_PV: case AREA_PV:
if (!(name = _get_pv_name(f, seg_pv(seg, s)))) { if (!(name = _get_pv_name(f, seg_pv(seg, s))))
stack; return_0;
return 0;
}
outf(f, "\"%s\", %u%s", name, outf(f, "\"%s\", %u%s", name,
seg_pe(seg, s), seg_pe(seg, s),
@ -534,24 +500,18 @@ static int _print_lv(struct formatter *f, struct logical_volume *lv)
_inc_indent(f); _inc_indent(f);
/* FIXME: Write full lvid */ /* FIXME: Write full lvid */
if (!id_write_format(&lv->lvid.id[1], buffer, sizeof(buffer))) { if (!id_write_format(&lv->lvid.id[1], buffer, sizeof(buffer)))
stack; return_0;
return 0;
}
outf(f, "id = \"%s\"", buffer); outf(f, "id = \"%s\"", buffer);
if (!print_flags(lv->status, LV_FLAGS, buffer, sizeof(buffer))) { if (!print_flags(lv->status, LV_FLAGS, buffer, sizeof(buffer)))
stack; return_0;
return 0;
}
outf(f, "status = %s", buffer); outf(f, "status = %s", buffer);
if (!list_empty(&lv->tags)) { if (!list_empty(&lv->tags)) {
if (!print_tags(&lv->tags, buffer, sizeof(buffer))) { if (!print_tags(&lv->tags, buffer, sizeof(buffer)))
stack; return_0;
return 0;
}
outf(f, "tags = %s", buffer); outf(f, "tags = %s", buffer);
} }
@ -579,10 +539,8 @@ static int _print_lv(struct formatter *f, struct logical_volume *lv)
seg_count = 1; seg_count = 1;
list_iterate_items(seg, &lv->segments) { list_iterate_items(seg, &lv->segments) {
if (!_print_segment(f, lv->vg, seg_count++, seg)) { if (!_print_segment(f, lv->vg, seg_count++, seg))
stack; return_0;
return 0;
}
} }
_dec_indent(f); _dec_indent(f);
@ -610,19 +568,15 @@ static int _print_lvs(struct formatter *f, struct volume_group *vg)
list_iterate_items(lvl, &vg->lvs) { list_iterate_items(lvl, &vg->lvs) {
if (!(lvl->lv->status & VISIBLE_LV)) if (!(lvl->lv->status & VISIBLE_LV))
continue; continue;
if (!_print_lv(f, lvl->lv)) { if (!_print_lv(f, lvl->lv))
stack; return_0;
return 0;
}
} }
list_iterate_items(lvl, &vg->lvs) { list_iterate_items(lvl, &vg->lvs) {
if ((lvl->lv->status & VISIBLE_LV)) if ((lvl->lv->status & VISIBLE_LV))
continue; continue;
if (!_print_lv(f, lvl->lv)) { if (!_print_lv(f, lvl->lv))
stack; return_0;
return 0;
}
} }
_dec_indent(f); _dec_indent(f);
@ -671,10 +625,8 @@ static int _text_vg_export(struct formatter *f,
{ {
int r = 0; int r = 0;
if (!_build_pv_names(f, vg)) { if (!_build_pv_names(f, vg))
stack; goto_out;
goto out;
}
if (f->header && !_print_header(f, desc)) if (f->header && !_print_header(f, desc))
goto_out; goto_out;
@ -721,10 +673,8 @@ int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp)
_init(); _init();
if (!(f = dm_malloc(sizeof(*f)))) { if (!(f = dm_malloc(sizeof(*f))))
stack; return_0;
return 0;
}
memset(f, 0, sizeof(*f)); memset(f, 0, sizeof(*f));
f->data.fp = fp; f->data.fp = fp;
@ -748,10 +698,8 @@ int text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
_init(); _init();
if (!(f = dm_malloc(sizeof(*f)))) { if (!(f = dm_malloc(sizeof(*f))))
stack; return_0;
return 0;
}
memset(f, 0, sizeof(*f)); memset(f, 0, sizeof(*f));
@ -767,9 +715,8 @@ int text_vg_export_raw(struct volume_group *vg, const char *desc, char **buf)
f->nl = &_nl_raw; f->nl = &_nl_raw;
if (!_text_vg_export(f, vg, desc)) { if (!_text_vg_export(f, vg, desc)) {
stack;
dm_free(f->data.buf.start); dm_free(f->data.buf.start);
goto out; goto_out;
} }
r = f->data.buf.used + 1; r = f->data.buf.used + 1;

View File

@ -91,10 +91,8 @@ int print_flags(uint32_t status, int type, char *buffer, size_t size)
int f, first = 1; int f, first = 1;
struct flag *flags; struct flag *flags;
if (!(flags = _get_flags(type))) { if (!(flags = _get_flags(type)))
stack; return_0;
return 0;
}
if (!emit_to_buffer(&buffer, &size, "[")) if (!emit_to_buffer(&buffer, &size, "["))
return 0; return 0;
@ -135,10 +133,8 @@ int read_flags(uint32_t *status, int type, struct config_value *cv)
uint32_t s = 0; uint32_t s = 0;
struct flag *flags; struct flag *flags;
if (!(flags = _get_flags(type))) { if (!(flags = _get_flags(type)))
stack; return_0;
return 0;
}
if (cv->type == CFG_EMPTY_ARRAY) if (cv->type == CFG_EMPTY_ARRAY)
goto out; goto out;

View File

@ -297,40 +297,38 @@ static struct mda_header *_raw_read_mda_header(const struct format_type *fmt,
return NULL; return NULL;
} }
if (!dev_read(dev_area->dev, dev_area->start, MDA_HEADER_SIZE, mdah)) { if (!dev_read(dev_area->dev, dev_area->start, MDA_HEADER_SIZE, mdah))
stack; goto_bad;
goto error;
}
if (mdah->checksum_xl != xlate32(calc_crc(INITIAL_CRC, mdah->magic, if (mdah->checksum_xl != xlate32(calc_crc(INITIAL_CRC, mdah->magic,
MDA_HEADER_SIZE - MDA_HEADER_SIZE -
sizeof(mdah->checksum_xl)))) { sizeof(mdah->checksum_xl)))) {
log_error("Incorrect metadata area header checksum"); log_error("Incorrect metadata area header checksum");
goto error; goto bad;
} }
_xlate_mdah(mdah); _xlate_mdah(mdah);
if (strncmp((char *)mdah->magic, FMTT_MAGIC, sizeof(mdah->magic))) { if (strncmp((char *)mdah->magic, FMTT_MAGIC, sizeof(mdah->magic))) {
log_error("Wrong magic number in metadata area header"); log_error("Wrong magic number in metadata area header");
goto error; goto bad;
} }
if (mdah->version != FMTT_VERSION) { if (mdah->version != FMTT_VERSION) {
log_error("Incompatible metadata area header version: %d", log_error("Incompatible metadata area header version: %d",
mdah->version); mdah->version);
goto error; goto bad;
} }
if (mdah->start != dev_area->start) { if (mdah->start != dev_area->start) {
log_error("Incorrect start sector in metadata area header: %" log_error("Incorrect start sector in metadata area header: %"
PRIu64, mdah->start); PRIu64, mdah->start);
goto error; goto bad;
} }
return mdah; return mdah;
error: bad:
dm_pool_free(fmt->cmd->mem, mdah); dm_pool_free(fmt->cmd->mem, mdah);
return NULL; return NULL;
} }
@ -349,9 +347,8 @@ static int _raw_write_mda_header(const struct format_type *fmt,
sizeof(mdah->checksum_xl))); sizeof(mdah->checksum_xl)));
if (!dev_write(dev, start_byte, MDA_HEADER_SIZE, mdah)) { if (!dev_write(dev, start_byte, MDA_HEADER_SIZE, mdah)) {
stack;
dm_pool_free(fmt->cmd->mem, mdah); dm_pool_free(fmt->cmd->mem, mdah);
return 0; return_0;
} }
return 1; return 1;
@ -380,17 +377,15 @@ static struct raw_locn *_find_vg_rlocn(struct device_area *dev_area,
/* FIXME Loop through rlocns two-at-a-time. List null-terminated. */ /* FIXME Loop through rlocns two-at-a-time. List null-terminated. */
/* FIXME Ignore if checksum incorrect!!! */ /* FIXME Ignore if checksum incorrect!!! */
if (!dev_read(dev_area->dev, dev_area->start + rlocn->offset, if (!dev_read(dev_area->dev, dev_area->start + rlocn->offset,
sizeof(vgnamebuf), vgnamebuf)) { sizeof(vgnamebuf), vgnamebuf))
stack; goto_bad;
goto error;
}
if (!strncmp(vgnamebuf, vgname, len = strlen(vgname)) && if (!strncmp(vgnamebuf, vgname, len = strlen(vgname)) &&
(isspace(vgnamebuf[len]) || vgnamebuf[len] == '{')) { (isspace(vgnamebuf[len]) || vgnamebuf[len] == '{')) {
return rlocn; return rlocn;
} }
error: bad:
if ((info = info_from_pvid(dev_area->dev->pvid, 0))) if ((info = info_from_pvid(dev_area->dev->pvid, 0)))
lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN, 0, NULL); lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN, 0, NULL);
@ -422,15 +417,11 @@ static int _raw_holds_vgname(struct format_instance *fid,
int noprecommit = 0; int noprecommit = 0;
struct mda_header *mdah; struct mda_header *mdah;
if (!dev_open(dev_area->dev)) { if (!dev_open(dev_area->dev))
stack; return_0;
return 0;
}
if (!(mdah = _raw_read_mda_header(fid->fmt, dev_area))) { if (!(mdah = _raw_read_mda_header(fid->fmt, dev_area)))
stack; return_0;
return 0;
}
if (_find_vg_rlocn(dev_area, mdah, vgname, &noprecommit)) if (_find_vg_rlocn(dev_area, mdah, vgname, &noprecommit))
r = 1; r = 1;
@ -453,15 +444,11 @@ static struct volume_group *_vg_read_raw_area(struct format_instance *fid,
char *desc; char *desc;
uint32_t wrap = 0; uint32_t wrap = 0;
if (!dev_open(area->dev)) { if (!dev_open(area->dev))
stack; return_NULL;
return NULL;
}
if (!(mdah = _raw_read_mda_header(fid->fmt, area))) { if (!(mdah = _raw_read_mda_header(fid->fmt, area)))
stack; goto_out;
goto out;
}
if (!(rlocn = _find_vg_rlocn(area, mdah, vgname, &precommitted))) { if (!(rlocn = _find_vg_rlocn(area, mdah, vgname, &precommitted))) {
log_debug("VG %s not found on %s", vgname, dev_name(area->dev)); log_debug("VG %s not found on %s", vgname, dev_name(area->dev));
@ -483,10 +470,8 @@ static struct volume_group *_vg_read_raw_area(struct format_instance *fid,
(uint32_t) (rlocn->size - wrap), (uint32_t) (rlocn->size - wrap),
(off_t) (area->start + MDA_HEADER_SIZE), (off_t) (area->start + MDA_HEADER_SIZE),
wrap, calc_crc, rlocn->checksum, &when, wrap, calc_crc, rlocn->checksum, &when,
&desc))) { &desc)))
stack; goto_out;
goto out;
}
log_debug("Read %s %smetadata (%u) from %s at %" PRIu64 " size %" log_debug("Read %s %smetadata (%u) from %s at %" PRIu64 " size %"
PRIu64, vg->name, precommitted ? "pre-commit " : "", PRIu64, vg->name, precommitted ? "pre-commit " : "",
vg->seqno, dev_name(area->dev), vg->seqno, dev_name(area->dev),
@ -544,15 +529,11 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg,
if (!found) if (!found)
return 1; return 1;
if (!dev_open(mdac->area.dev)) { if (!dev_open(mdac->area.dev))
stack; return_0;
return 0;
}
if (!(mdah = _raw_read_mda_header(fid->fmt, &mdac->area))) { if (!(mdah = _raw_read_mda_header(fid->fmt, &mdac->area)))
stack; goto_out;
goto out;
}
rlocn = _find_vg_rlocn(&mdac->area, mdah, vg->name, &noprecommit); rlocn = _find_vg_rlocn(&mdac->area, mdah, vg->name, &noprecommit);
mdac->rlocn.offset = _next_rlocn_offset(rlocn, mdah); mdac->rlocn.offset = _next_rlocn_offset(rlocn, mdah);
@ -589,10 +570,8 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg,
/* Write text out, circularly */ /* Write text out, circularly */
if (!dev_write(mdac->area.dev, mdac->area.start + mdac->rlocn.offset, if (!dev_write(mdac->area.dev, mdac->area.start + mdac->rlocn.offset,
(size_t) (mdac->rlocn.size - new_wrap), (size_t) (mdac->rlocn.size - new_wrap),
fidtc->raw_metadata_buf)) { fidtc->raw_metadata_buf))
stack; goto_out;
goto out;
}
if (new_wrap) { if (new_wrap) {
log_debug("Writing metadata to %s at %" PRIu64 " len %" PRIu32, log_debug("Writing metadata to %s at %" PRIu64 " len %" PRIu32,
@ -603,10 +582,8 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg,
mdac->area.start + MDA_HEADER_SIZE, mdac->area.start + MDA_HEADER_SIZE,
(size_t) new_wrap, (size_t) new_wrap,
fidtc->raw_metadata_buf + fidtc->raw_metadata_buf +
mdac->rlocn.size - new_wrap)) { mdac->rlocn.size - new_wrap))
stack; goto_out;
goto out;
}
} }
mdac->rlocn.checksum = calc_crc(INITIAL_CRC, fidtc->raw_metadata_buf, mdac->rlocn.checksum = calc_crc(INITIAL_CRC, fidtc->raw_metadata_buf,
@ -652,10 +629,8 @@ static int _vg_commit_raw_rlocn(struct format_instance *fid,
if (!found) if (!found)
return 1; return 1;
if (!(mdah = _raw_read_mda_header(fid->fmt, &mdac->area))) { if (!(mdah = _raw_read_mda_header(fid->fmt, &mdac->area)))
stack; goto_out;
goto out;
}
if (!(rlocn = _find_vg_rlocn(&mdac->area, mdah, vg->name, &noprecommit))) { if (!(rlocn = _find_vg_rlocn(&mdac->area, mdah, vg->name, &noprecommit))) {
mdah->raw_locns[0].offset = 0; mdah->raw_locns[0].offset = 0;
@ -759,15 +734,11 @@ static int _vg_remove_raw(struct format_instance *fid, struct volume_group *vg,
int r = 0; int r = 0;
int noprecommit = 0; int noprecommit = 0;
if (!dev_open(mdac->area.dev)) { if (!dev_open(mdac->area.dev))
stack; return_0;
return 0;
}
if (!(mdah = _raw_read_mda_header(fid->fmt, &mdac->area))) { if (!(mdah = _raw_read_mda_header(fid->fmt, &mdac->area)))
stack; goto_out;
goto out;
}
if (!(rlocn = _find_vg_rlocn(&mdac->area, mdah, vg->name, &noprecommit))) { if (!(rlocn = _find_vg_rlocn(&mdac->area, mdah, vg->name, &noprecommit))) {
rlocn = &mdah->raw_locns[0]; rlocn = &mdah->raw_locns[0];
@ -801,10 +772,8 @@ static struct volume_group *_vg_read_file_name(struct format_instance *fid,
time_t when; time_t when;
char *desc; char *desc;
if (!(vg = text_vg_import_file(fid, read_path, &when, &desc))) { if (!(vg = text_vg_import_file(fid, read_path, &when, &desc)))
stack; return_NULL;
return NULL;
}
/* /*
* Currently you can only have a single volume group per * Currently you can only have a single volume group per
@ -1065,10 +1034,8 @@ const char *vgname_from_mda(const struct format_type *fmt,
if (mda_free_sectors) if (mda_free_sectors)
*mda_free_sectors = ((dev_area->size - MDA_HEADER_SIZE) / 2) >> SECTOR_SHIFT; *mda_free_sectors = ((dev_area->size - MDA_HEADER_SIZE) / 2) >> SECTOR_SHIFT;
if (!dev_open(dev_area->dev)) { if (!dev_open(dev_area->dev))
stack; return_NULL;
return NULL;
}
if (!(mdah = _raw_read_mda_header(fmt, dev_area))) if (!(mdah = _raw_read_mda_header(fmt, dev_area)))
goto_out; goto_out;
@ -1114,15 +1081,13 @@ const char *vgname_from_mda(const struct format_type *fmt,
/* Ignore this entry if the characters aren't permissible */ /* Ignore this entry if the characters aren't permissible */
if (!validate_name(vgname)) { if (!validate_name(vgname)) {
stack;
vgname = NULL; vgname = NULL;
goto out; goto_out;
} }
if (!id_write_format(vgid, uuid, sizeof(uuid))) { if (!id_write_format(vgid, uuid, sizeof(uuid))) {
stack;
vgname = NULL; vgname = NULL;
goto out; goto_out;
} }
log_debug("%s: Found metadata at %" PRIu64 " size %" PRIu64 log_debug("%s: Found metadata at %" PRIu64 " size %" PRIu64
@ -1328,10 +1293,8 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume
/* FIXME Test mode don't update cache? */ /* FIXME Test mode don't update cache? */
if (!(info = lvmcache_add(fmt->labeller, (char *) &pv->id, pv->dev, if (!(info = lvmcache_add(fmt->labeller, (char *) &pv->id, pv->dev,
ORPHAN, NULL, 0))) { ORPHAN, NULL, 0)))
stack; return_0;
return 0;
}
label = info->label; label = info->label;
if (label_sector != -1) if (label_sector != -1)
@ -1384,15 +1347,11 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume
} }
} }
if (!add_da if (!add_da
(NULL, &info->das, pv->pe_start << SECTOR_SHIFT, UINT64_C(0))) { (NULL, &info->das, pv->pe_start << SECTOR_SHIFT, UINT64_C(0)))
stack; return_0;
return 0;
}
if (!dev_open(pv->dev)) { if (!dev_open(pv->dev))
stack; return_0;
return 0;
}
list_iterate_items(mda, &info->mdas) { list_iterate_items(mda, &info->mdas) {
mdac = mda->metadata_locn; mdac = mda->metadata_locn;
@ -1400,19 +1359,16 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume
mdah->size = mdac->area.size; mdah->size = mdac->area.size;
if (!_raw_write_mda_header(fmt, mdac->area.dev, if (!_raw_write_mda_header(fmt, mdac->area.dev,
mdac->area.start, mdah)) { mdac->area.start, mdah)) {
stack;
if (!dev_close(pv->dev)) if (!dev_close(pv->dev))
stack; stack;
return 0; return_0;
} }
} }
label_write(pv->dev, label); label_write(pv->dev, label);
if (!dev_close(pv->dev)) { if (!dev_close(pv->dev))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -1449,16 +1405,12 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name,
struct mda_context *mdac, *mdac_new; struct mda_context *mdac, *mdac_new;
struct data_area_list *da; struct data_area_list *da;
if (!(dev = dev_cache_get(pv_name, fmt->cmd->filter))) { if (!(dev = dev_cache_get(pv_name, fmt->cmd->filter)))
stack; return_0;
return 0;
}
/* FIXME Optimise out repeated reading when cache lock held */ /* FIXME Optimise out repeated reading when cache lock held */
if (!(label_read(dev, &label, UINT64_C(0)))) { if (!(label_read(dev, &label, UINT64_C(0))))
stack; return_0;
return 0;
}
info = (struct lvmcache_info *) label->info; info = (struct lvmcache_info *) label->info;
/* Have we already cached vgname? */ /* Have we already cached vgname? */
@ -1642,16 +1594,12 @@ static int _text_pv_setup(const struct format_type *fmt,
continue; continue;
if (!(mda_new = dm_pool_alloc(fmt->cmd->mem, if (!(mda_new = dm_pool_alloc(fmt->cmd->mem,
sizeof(*mda_new)))) { sizeof(*mda_new))))
stack; return_0;
return 0;
}
if (!(mdac_new = dm_pool_alloc(fmt->cmd->mem, if (!(mdac_new = dm_pool_alloc(fmt->cmd->mem,
sizeof(*mdac_new)))) { sizeof(*mdac_new))))
stack; return_0;
return 0;
}
/* FIXME multiple dev_areas inside area */ /* FIXME multiple dev_areas inside area */
memcpy(mda_new, mda, sizeof(*mda)); memcpy(mda_new, mda, sizeof(*mda));
memcpy(mdac_new, mdac, sizeof(*mdac)); memcpy(mdac_new, mdac, sizeof(*mdac));
@ -1687,11 +1635,8 @@ static int _text_pv_setup(const struct format_type *fmt,
if (extent_count) if (extent_count)
pe_end = pe_start + extent_count * extent_size - 1; pe_end = pe_start + extent_count * extent_size - 1;
if (!_mda_setup(fmt, pe_start, pe_end, pvmetadatacopies, if (!_mda_setup(fmt, pe_start, pe_end, pvmetadatacopies,
pvmetadatasize, mdas, pv, vg)) { pvmetadatasize, mdas, pv, vg))
stack; return_0;
return 0;
}
} }
return 1; return 1;
@ -1732,10 +1677,8 @@ static struct format_instance *_text_create_text_instance(const struct format_ty
list_init(&fid->metadata_areas); list_init(&fid->metadata_areas);
if (!vgname) { if (!vgname) {
if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda)))) { if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda))))
stack; return_NULL;
return NULL;
}
mda->ops = &_metadata_text_file_backup_ops; mda->ops = &_metadata_text_file_backup_ops;
mda->metadata_locn = context; mda->metadata_locn = context;
list_add(&fid->metadata_areas, &mda->list); list_add(&fid->metadata_areas, &mda->list);
@ -1751,10 +1694,8 @@ static struct format_instance *_text_create_text_instance(const struct format_ty
} }
context = create_text_context(fmt->cmd, path, NULL); context = create_text_context(fmt->cmd, path, NULL);
if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda)))) { if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda))))
stack; return_NULL;
return NULL;
}
mda->ops = &_metadata_text_file_ops; mda->ops = &_metadata_text_file_ops;
mda->metadata_locn = context; mda->metadata_locn = context;
list_add(&fid->metadata_areas, &mda->list); list_add(&fid->metadata_areas, &mda->list);
@ -1767,15 +1708,11 @@ static struct format_instance *_text_create_text_instance(const struct format_ty
if (!_raw_holds_vgname(fid, &rl->dev_area, vgname)) if (!_raw_holds_vgname(fid, &rl->dev_area, vgname))
continue; continue;
if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda)))) { if (!(mda = dm_pool_alloc(fmt->cmd->mem, sizeof(*mda))))
stack; return_NULL;
return NULL;
}
if (!(mdac = dm_pool_alloc(fmt->cmd->mem, sizeof(*mdac)))) { if (!(mdac = dm_pool_alloc(fmt->cmd->mem, sizeof(*mdac))))
stack; return_NULL;
return NULL;
}
mda->metadata_locn = mdac; mda->metadata_locn = mdac;
/* FIXME Allow multiple dev_areas inside area */ /* FIXME Allow multiple dev_areas inside area */
memcpy(&mdac->area, &rl->dev_area, sizeof(mdac->area)); memcpy(&mdac->area, &rl->dev_area, sizeof(mdac->area));
@ -1786,10 +1723,8 @@ static struct format_instance *_text_create_text_instance(const struct format_ty
/* Scan PVs in VG for any further MDAs */ /* Scan PVs in VG for any further MDAs */
lvmcache_label_scan(fmt->cmd, 0); lvmcache_label_scan(fmt->cmd, 0);
if (!(vginfo = vginfo_from_vgname(vgname, vgid))) { if (!(vginfo = vginfo_from_vgname(vgname, vgid)))
stack; goto_out;
goto out;
}
list_iterate_items(info, &vginfo->infos) { list_iterate_items(info, &vginfo->infos) {
mdas = &info->mdas; mdas = &info->mdas;
list_iterate_items(mda, mdas) { list_iterate_items(mda, mdas) {
@ -1798,16 +1733,12 @@ static struct format_instance *_text_create_text_instance(const struct format_ty
/* FIXME Check it holds this VG */ /* FIXME Check it holds this VG */
if (!(mda_new = dm_pool_alloc(fmt->cmd->mem, if (!(mda_new = dm_pool_alloc(fmt->cmd->mem,
sizeof(*mda_new)))) { sizeof(*mda_new))))
stack; return_NULL;
return NULL;
}
if (!(mdac_new = dm_pool_alloc(fmt->cmd->mem, if (!(mdac_new = dm_pool_alloc(fmt->cmd->mem,
sizeof(*mdac_new)))) { sizeof(*mdac_new))))
stack; return_NULL;
return NULL;
}
/* FIXME multiple dev_areas inside area */ /* FIXME multiple dev_areas inside area */
memcpy(mda_new, mda, sizeof(*mda)); memcpy(mda_new, mda, sizeof(*mda));
memcpy(mdac_new, mdac, sizeof(*mdac)); memcpy(mdac_new, mdac, sizeof(*mdac));
@ -1834,33 +1765,26 @@ void *create_text_context(struct cmd_context *cmd, const char *path,
return NULL; return NULL;
} }
if (!(tc = dm_pool_alloc(cmd->mem, sizeof(*tc)))) { if (!(tc = dm_pool_alloc(cmd->mem, sizeof(*tc))))
stack; return_NULL;
return NULL;
}
if (!(tc->path_live = dm_pool_strdup(cmd->mem, path))) { if (!(tc->path_live = dm_pool_strdup(cmd->mem, path)))
stack; goto_bad;
goto no_mem;
} if (!(tc->path_edit = dm_pool_alloc(cmd->mem, strlen(path) + 5)))
goto_bad;
if (!(tc->path_edit = dm_pool_alloc(cmd->mem, strlen(path) + 5))) {
stack;
goto no_mem;
}
sprintf(tc->path_edit, "%s.tmp", path); sprintf(tc->path_edit, "%s.tmp", path);
if (!desc) if (!desc)
desc = ""; desc = "";
if (!(tc->desc = dm_pool_strdup(cmd->mem, desc))) { if (!(tc->desc = dm_pool_strdup(cmd->mem, desc)))
stack; goto_bad;
goto no_mem;
}
return (void *) tc; return (void *) tc;
no_mem: bad:
dm_pool_free(cmd->mem, tc); dm_pool_free(cmd->mem, tc);
log_err("Couldn't allocate text format context object."); log_err("Couldn't allocate text format context object.");
@ -1956,10 +1880,8 @@ struct format_type *create_text_format(struct cmd_context *cmd)
struct config_value *cv; struct config_value *cv;
struct mda_lists *mda_lists; struct mda_lists *mda_lists;
if (!(fmt = dm_malloc(sizeof(*fmt)))) { if (!(fmt = dm_malloc(sizeof(*fmt))))
stack; return_NULL;
return NULL;
}
fmt->cmd = cmd; fmt->cmd = cmd;
fmt->ops = &_text_handler; fmt->ops = &_text_handler;

View File

@ -111,10 +111,8 @@ struct volume_group *text_vg_import_fd(struct format_instance *fid,
if (!(*vsn)->check_version(cft)) if (!(*vsn)->check_version(cft))
continue; continue;
if (!(vg = (*vsn)->read_vg(fid, cft))) { if (!(vg = (*vsn)->read_vg(fid, cft)))
stack; goto_out;
goto out;
}
(*vsn)->read_desc(fid->fmt->cmd->mem, cft, when, desc); (*vsn)->read_desc(fid->fmt->cmd->mem, cft, when, desc);
break; break;

View File

@ -136,10 +136,8 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem,
uint64_t size; uint64_t size;
if (!(pvl = dm_pool_zalloc(mem, sizeof(*pvl))) || if (!(pvl = dm_pool_zalloc(mem, sizeof(*pvl))) ||
!(pvl->pv = dm_pool_zalloc(mem, sizeof(*pvl->pv)))) { !(pvl->pv = dm_pool_zalloc(mem, sizeof(*pvl->pv))))
stack; return_0;
return 0;
}
pv = pvl->pv; pv = pvl->pv;
@ -147,10 +145,8 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem,
* Add the pv to the pv hash for quick lookup when we read * Add the pv to the pv hash for quick lookup when we read
* the lv segments. * the lv segments.
*/ */
if (!dm_hash_insert(pv_hash, pvn->key, pv)) { if (!dm_hash_insert(pv_hash, pvn->key, pv))
stack; return_0;
return 0;
}
if (!(pvn = pvn->child)) { if (!(pvn = pvn->child)) {
log_error("Empty pv section."); log_error("Empty pv section.");
@ -180,10 +176,8 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem,
return 0; return 0;
} }
if (!(pv->vg_name = dm_pool_strdup(mem, vg->name))) { if (!(pv->vg_name = dm_pool_strdup(mem, vg->name)))
stack; return_0;
return 0;
}
memcpy(&pv->vgid, &vg->id, sizeof(vg->id)); memcpy(&pv->vgid, &vg->id, sizeof(vg->id));
@ -250,10 +244,8 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem,
} }
} }
if (!alloc_pv_segment_whole_pv(mem, pv)) { if (!alloc_pv_segment_whole_pv(mem, pv))
stack; return_0;
return 0;
}
vg->pv_count++; vg->pv_count++;
list_add(&vg->pvs, &pvl->list); list_add(&vg->pvs, &pvl->list);
@ -316,16 +308,12 @@ static int _read_segment(struct dm_pool *mem, struct volume_group *vg,
segtype_str = cv->v.str; segtype_str = cv->v.str;
} }
if (!(segtype = get_segtype_from_string(vg->cmd, segtype_str))) { if (!(segtype = get_segtype_from_string(vg->cmd, segtype_str)))
stack; return_0;
return 0;
}
if (segtype->ops->text_import_area_count && if (segtype->ops->text_import_area_count &&
!segtype->ops->text_import_area_count(sn, &area_count)) { !segtype->ops->text_import_area_count(sn, &area_count))
stack; return_0;
return 0;
}
if (!(seg = alloc_lv_segment(mem, segtype, lv, start_extent, if (!(seg = alloc_lv_segment(mem, segtype, lv, start_extent,
extent_count, 0, 0, NULL, area_count, extent_count, 0, 0, NULL, area_count,
@ -335,10 +323,8 @@ static int _read_segment(struct dm_pool *mem, struct volume_group *vg,
} }
if (seg->segtype->ops->text_import && if (seg->segtype->ops->text_import &&
!seg->segtype->ops->text_import(seg, sn, pv_hash)) { !seg->segtype->ops->text_import(seg, sn, pv_hash))
stack; return_0;
return 0;
}
/* Optional tags */ /* Optional tags */
if ((cn = find_config_node(sn, "tags")) && if ((cn = find_config_node(sn, "tags")) &&
@ -403,10 +389,8 @@ int text_import_areas(struct lv_segment *seg, const struct config_node *sn,
/* FIXME Cope if LV not yet read in */ /* FIXME Cope if LV not yet read in */
if ((pv = dm_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, (uint32_t) cv->next->v.i)) { if (!set_lv_segment_area_pv(seg, s, pv, (uint32_t) cv->next->v.i))
stack; return_0;
return 0;
}
} else if ((lv1 = find_lv(seg->lv->vg, cv->v.str))) { } else if ((lv1 = find_lv(seg->lv->vg, cv->v.str))) {
if (!set_lv_segment_area_lv(seg, s, lv1, if (!set_lv_segment_area_lv(seg, s, lv1,
(uint32_t) cv->next->v.i, (uint32_t) cv->next->v.i,
@ -447,10 +431,8 @@ static int _read_segments(struct dm_pool *mem, struct volume_group *vg,
* All sub-sections are assumed to be segments. * All sub-sections are assumed to be segments.
*/ */
if (!sn->v) { if (!sn->v) {
if (!_read_segment(mem, vg, lv, sn, pv_hash)) { if (!_read_segment(mem, vg, lv, sn, pv_hash))
stack; return_0;
return 0;
}
count++; count++;
} }
@ -475,18 +457,14 @@ static int _read_segments(struct dm_pool *mem, struct volume_group *vg,
/* /*
* Check there are no gaps or overlaps in the lv. * Check there are no gaps or overlaps in the lv.
*/ */
if (!check_lv_segments(lv, 0)) { if (!check_lv_segments(lv, 0))
stack; return_0;
return 0;
}
/* /*
* Merge segments in case someones been editing things by hand. * Merge segments in case someones been editing things by hand.
*/ */
if (!lv_merge_segments(lv)) { if (!lv_merge_segments(lv))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -502,17 +480,13 @@ static int _read_lvnames(struct format_instance *fid __attribute((unused)),
struct config_node *cn; struct config_node *cn;
if (!(lvl = dm_pool_zalloc(mem, sizeof(*lvl))) || if (!(lvl = dm_pool_zalloc(mem, sizeof(*lvl))) ||
!(lvl->lv = dm_pool_zalloc(mem, sizeof(*lvl->lv)))) { !(lvl->lv = dm_pool_zalloc(mem, sizeof(*lvl->lv))))
stack; return_0;
return 0;
}
lv = lvl->lv; lv = lvl->lv;
if (!(lv->name = dm_pool_strdup(mem, lvn->key))) { if (!(lv->name = dm_pool_strdup(mem, lvn->key)))
stack; return_0;
return 0;
}
if (!(lvn = lvn->child)) { if (!(lvn = lvn->child)) {
log_error("Empty logical volume section."); log_error("Empty logical volume section.");
@ -538,10 +512,8 @@ static int _read_lvnames(struct format_instance *fid __attribute((unused)),
} }
lv->alloc = get_alloc_from_string(cv->v.str); lv->alloc = get_alloc_from_string(cv->v.str);
if (lv->alloc == ALLOC_INVALID) { if (lv->alloc == ALLOC_INVALID)
stack; return_0;
return 0;
}
} }
if (!_read_int32(lvn, "read_ahead", &lv->read_ahead)) if (!_read_int32(lvn, "read_ahead", &lv->read_ahead))
@ -611,10 +583,8 @@ static int _read_lvsegs(struct format_instance *fid __attribute((unused)),
memcpy(&lv->lvid.id[0], &lv->vg->id, sizeof(lv->lvid.id[0])); memcpy(&lv->lvid.id[0], &lv->vg->id, sizeof(lv->lvid.id[0]));
if (!_read_segments(mem, vg, lv, lvn, pv_hash)) { if (!_read_segments(mem, vg, lv, lvn, pv_hash))
stack; return_0;
return 0;
}
lv->size = (uint64_t) lv->le_count * (uint64_t) vg->extent_size; lv->size = (uint64_t) lv->le_count * (uint64_t) vg->extent_size;
@ -664,10 +634,8 @@ static int _read_sections(struct format_instance *fid,
} }
for (n = n->child; n; n = n->sib) { for (n = n->child; n; n = n->sib) {
if (!fn(fid, mem, vg, n, vgn, pv_hash)) { if (!fn(fid, mem, vg, n, vgn, pv_hash))
stack; return_0;
return 0;
}
} }
return 1; return 1;
@ -689,10 +657,8 @@ static struct volume_group *_read_vg(struct format_instance *fid,
return NULL; return NULL;
} }
if (!(vg = dm_pool_zalloc(mem, sizeof(*vg)))) { if (!(vg = dm_pool_zalloc(mem, sizeof(*vg))))
stack; return_NULL;
return NULL;
}
vg->cmd = fid->fmt->cmd; vg->cmd = fid->fmt->cmd;
/* FIXME Determine format type from file contents */ /* FIXME Determine format type from file contents */
@ -770,10 +736,8 @@ static struct volume_group *_read_vg(struct format_instance *fid,
} }
vg->alloc = get_alloc_from_string(cv->v.str); vg->alloc = get_alloc_from_string(cv->v.str);
if (vg->alloc == ALLOC_INVALID) { if (vg->alloc == ALLOC_INVALID)
stack; return_0;
return 0;
}
} }
/* /*

View File

@ -24,30 +24,22 @@ int print_tags(struct list *tags, char *buffer, size_t size)
struct str_list *sl; struct str_list *sl;
int first = 1; int first = 1;
if (!emit_to_buffer(&buffer, &size, "[")) { if (!emit_to_buffer(&buffer, &size, "["))
stack; return_0;
return 0;
}
list_iterate_items(sl, tags) { list_iterate_items(sl, tags) {
if (!first) { if (!first) {
if (!emit_to_buffer(&buffer, &size, ", ")) { if (!emit_to_buffer(&buffer, &size, ", "))
stack; return_0;
return 0;
}
} else } else
first = 0; first = 0;
if (!emit_to_buffer(&buffer, &size, "\"%s\"", sl->str)) { if (!emit_to_buffer(&buffer, &size, "\"%s\"", sl->str))
stack; return_0;
return 0;
}
} }
if (!emit_to_buffer(&buffer, &size, "]")) { if (!emit_to_buffer(&buffer, &size, "]"))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -63,10 +55,8 @@ int read_tags(struct dm_pool *mem, struct list *tags, struct config_value *cv)
return 0; return 0;
} }
if (!str_list_add(mem, tags, dm_pool_strdup(mem, cv->v.str))) { if (!str_list_add(mem, tags, dm_pool_strdup(mem, cv->v.str)))
stack; return_0;
return 0;
}
cv = cv->next; cv = cv->next;
} }

View File

@ -86,10 +86,8 @@ int label_register_handler(const char *name, struct labeller *handler)
{ {
struct labeller_i *li; struct labeller_i *li;
if (!(li = _alloc_li(name, handler))) { if (!(li = _alloc_li(name, handler)))
stack; return_0;
return 0;
}
list_add(&_labellers, &li->list); list_add(&_labellers, &li->list);
return 1; return 1;
@ -203,10 +201,8 @@ int label_remove(struct device *dev)
log_very_verbose("Scanning for labels to wipe from %s", dev_name(dev)); log_very_verbose("Scanning for labels to wipe from %s", dev_name(dev));
if (!dev_open(dev)) { if (!dev_open(dev))
stack; return_0;
return 0;
}
/* /*
* We flush the device just in case someone is stupid * We flush the device just in case someone is stupid
@ -322,18 +318,14 @@ int label_write(struct device *dev, struct label *label)
lh->sector_xl = xlate64(label->sector); lh->sector_xl = xlate64(label->sector);
lh->offset_xl = xlate32(sizeof(*lh)); lh->offset_xl = xlate32(sizeof(*lh));
if (!(label->labeller->ops->write)(label, buf)) { if (!(label->labeller->ops->write)(label, buf))
stack; return_0;
return 0;
}
lh->crc_xl = xlate32(calc_crc(INITIAL_CRC, &lh->offset_xl, LABEL_SIZE - lh->crc_xl = xlate32(calc_crc(INITIAL_CRC, &lh->offset_xl, LABEL_SIZE -
((void *) &lh->offset_xl - (void *) lh))); ((void *) &lh->offset_xl - (void *) lh)));
if (!dev_open(dev)) { if (!dev_open(dev))
stack; return_0;
return 0;
}
log_info("%s: Writing label to sector %" PRIu64, dev_name(dev), log_info("%s: Writing label to sector %" PRIu64, dev_name(dev),
label->sector); label->sector);

View File

@ -73,10 +73,8 @@ int init_external_locking(struct locking_type *locking, struct cmd_context *cmd)
libname = find_config_tree_str(cmd, "global/locking_library", libname = find_config_tree_str(cmd, "global/locking_library",
DEFAULT_LOCKING_LIB); DEFAULT_LOCKING_LIB);
if (!(_locking_lib = load_shared_library(cmd, libname, "locking", 1))) { if (!(_locking_lib = load_shared_library(cmd, libname, "locking", 1)))
stack; return_0;
return 0;
}
/* Get the functions we need */ /* Get the functions we need */
if (!(_init_fn = dlsym(_locking_lib, "locking_init")) || if (!(_init_fn = dlsym(_locking_lib, "locking_init")) ||

View File

@ -178,15 +178,12 @@ struct lv_segment *alloc_lv_segment(struct dm_pool *mem,
struct lv_segment *seg; struct lv_segment *seg;
uint32_t areas_sz = area_count * sizeof(*seg->areas); uint32_t areas_sz = area_count * sizeof(*seg->areas);
if (!(seg = dm_pool_zalloc(mem, sizeof(*seg)))) { if (!(seg = dm_pool_zalloc(mem, sizeof(*seg))))
stack; return_NULL;
return NULL;
}
if (!(seg->areas = dm_pool_zalloc(mem, areas_sz))) { if (!(seg->areas = dm_pool_zalloc(mem, areas_sz))) {
dm_pool_free(mem, seg); dm_pool_free(mem, seg);
stack; return_NULL;
return NULL;
} }
if (!segtype) { if (!segtype) {
@ -290,10 +287,8 @@ int move_lv_segment_area(struct lv_segment *seg_to, uint32_t area_to,
seg_from->area_len); seg_from->area_len);
release_lv_segment_area(seg_to, area_to, seg_to->area_len); release_lv_segment_area(seg_to, area_to, seg_to->area_len);
if (!set_lv_segment_area_pv(seg_to, area_to, pv, pe)) { if (!set_lv_segment_area_pv(seg_to, area_to, pv, pe))
stack; return_0;
return 0;
}
break; break;
@ -326,10 +321,8 @@ int set_lv_segment_area_pv(struct lv_segment *seg, uint32_t area_num,
seg->areas[area_num].type = AREA_PV; seg->areas[area_num].type = AREA_PV;
if (!(seg_pvseg(seg, area_num) = if (!(seg_pvseg(seg, area_num) =
assign_peg_to_lvseg(pv, pe, seg->area_len, seg, area_num))) { assign_peg_to_lvseg(pv, pe, seg->area_len, seg, area_num)))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -365,10 +358,8 @@ static int _lv_segment_add_areas(struct logical_volume *lv,
struct lv_segment_area *newareas; struct lv_segment_area *newareas;
uint32_t areas_sz = new_area_count * sizeof(*newareas); uint32_t areas_sz = new_area_count * sizeof(*newareas);
if (!(newareas = dm_pool_zalloc(lv->vg->cmd->mem, areas_sz))) { if (!(newareas = dm_pool_zalloc(lv->vg->cmd->mem, areas_sz)))
stack; return_0;
return 0;
}
memcpy(newareas, seg->areas, seg->area_count * sizeof(*seg->areas)); memcpy(newareas, seg->areas, seg->area_count * sizeof(*seg->areas));
@ -423,19 +414,15 @@ static int _lv_reduce(struct logical_volume *lv, uint32_t extents, int delete)
if (seg->len <= count) { if (seg->len <= count) {
/* remove this segment completely */ /* remove this segment completely */
/* FIXME Check this is safe */ /* FIXME Check this is safe */
if (seg->log_lv && !lv_remove(seg->log_lv)) { if (seg->log_lv && !lv_remove(seg->log_lv))
stack; return_0;
return 0;
}
list_del(&seg->list); list_del(&seg->list);
reduction = seg->len; reduction = seg->len;
} else } else
reduction = count; reduction = count;
if (!_lv_segment_reduce(seg, reduction)) { if (!_lv_segment_reduce(seg, reduction))
stack; return_0;
return 0;
}
count -= reduction; count -= reduction;
} }
@ -447,19 +434,15 @@ static int _lv_reduce(struct logical_volume *lv, uint32_t extents, int delete)
/* Remove the LV if it is now empty */ /* Remove the LV if it is now empty */
if (!lv->le_count) { if (!lv->le_count) {
if (!(lvl = find_lv_in_vg(lv->vg, lv->name))) { if (!(lvl = find_lv_in_vg(lv->vg, lv->name)))
stack; return_0;
return 0;
}
list_del(&lvl->list); list_del(&lvl->list);
lv->vg->lv_count--; lv->vg->lv_count--;
} else if (lv->vg->fid->fmt->ops->lv_setup && } else if (lv->vg->fid->fmt->ops->lv_setup &&
!lv->vg->fid->fmt->ops->lv_setup(lv->vg->fid, lv)) { !lv->vg->fid->fmt->ops->lv_setup(lv->vg->fid, lv))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -504,10 +487,8 @@ int lv_reduce(struct logical_volume *lv, uint32_t extents)
int lv_remove(struct logical_volume *lv) int lv_remove(struct logical_volume *lv)
{ {
if (!lv_reduce(lv, lv->le_count)) { if (!lv_reduce(lv, lv->le_count))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -684,12 +665,9 @@ static int _setup_alloced_segment(struct logical_volume *lv, uint32_t status,
return 0; return 0;
} }
for (s = 0; s < area_count; s++) { for (s = 0; s < area_count; s++)
if (!set_lv_segment_area_pv(seg, s, aa[s].pv, aa[s].pe)) { if (!set_lv_segment_area_pv(seg, s, aa[s].pv, aa[s].pe))
stack; return_0;
return 0;
}
}
list_add(&lv->segments, &seg->list); list_add(&lv->segments, &seg->list);
@ -717,10 +695,8 @@ static int _setup_alloced_segments(struct logical_volume *lv,
list_iterate_items(aa, &alloced_areas[0]) { list_iterate_items(aa, &alloced_areas[0]) {
if (!_setup_alloced_segment(lv, status, area_count, if (!_setup_alloced_segment(lv, status, area_count,
stripe_size, segtype, aa, stripe_size, segtype, aa,
region_size, log_lv)) { region_size, log_lv))
stack; return_0;
return 0;
}
} }
return 1; return 1;
@ -1142,10 +1118,8 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc,
allocated, allocated,
(ah->log_count && !ah->log_area.len) ? (ah->log_count && !ah->log_area.len) ?
*(areas + ix_offset + ix - 1) : *(areas + ix_offset + ix - 1) :
NULL)) { NULL))
stack; return_0;
return 0;
}
} while (!contiguous && *allocated != needed && can_split); } while (!contiguous && *allocated != needed && can_split);
@ -1187,10 +1161,8 @@ static int _allocate(struct alloc_handle *ah,
/* /*
* Build the sets of available areas on the pv's. * Build the sets of available areas on the pv's.
*/ */
if (!(pvms = create_pv_maps(ah->mem, vg, allocatable_pvs))) { if (!(pvms = create_pv_maps(ah->mem, vg, allocatable_pvs)))
stack; return_0;
return 0;
}
if (!_log_parallel_areas(ah->mem, ah->parallel_areas)) if (!_log_parallel_areas(ah->mem, ah->parallel_areas))
stack; stack;
@ -1315,9 +1287,8 @@ struct alloc_handle *allocate_extents(struct volume_group *vg,
if (!segtype_is_virtual(segtype) && if (!segtype_is_virtual(segtype) &&
!_allocate(ah, vg, lv, (lv ? lv->le_count : 0) + extents, !_allocate(ah, vg, lv, (lv ? lv->le_count : 0) + extents,
1, allocatable_pvs)) { 1, allocatable_pvs)) {
stack;
alloc_destroy(ah); alloc_destroy(ah);
return NULL; return_NULL;
} }
return ah; return ah;
@ -1348,10 +1319,8 @@ int lv_add_segment(struct alloc_handle *ah,
if (!_setup_alloced_segments(lv, &ah->alloced_areas[first_area], if (!_setup_alloced_segments(lv, &ah->alloced_areas[first_area],
num_areas, status, num_areas, status,
stripe_size, segtype, stripe_size, segtype,
region_size, log_lv)) { region_size, log_lv))
stack; return_0;
return 0;
}
if ((segtype->flags & SEG_CAN_SPLIT) && !lv_merge_segments(lv)) { if ((segtype->flags & SEG_CAN_SPLIT) && !lv_merge_segments(lv)) {
log_err("Couldn't merge segments after extending " log_err("Couldn't merge segments after extending "
@ -1360,10 +1329,8 @@ int lv_add_segment(struct alloc_handle *ah,
} }
if (lv->vg->fid->fmt->ops->lv_setup && if (lv->vg->fid->fmt->ops->lv_setup &&
!lv->vg->fid->fmt->ops->lv_setup(lv->vg->fid, lv)) { !lv->vg->fid->fmt->ops->lv_setup(lv->vg->fid, lv))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -1615,10 +1582,8 @@ int lv_extend(struct logical_volume *lv,
if (mirrors < 2) { if (mirrors < 2) {
if (!lv_add_segment(ah, 0, ah->area_count, lv, segtype, stripe_size, if (!lv_add_segment(ah, 0, ah->area_count, lv, segtype, stripe_size,
status, 0, NULL)) { status, 0, NULL))
stack; goto_out;
goto out;
}
} else { } else {
if (!_lv_extend_mirror(ah, lv, extents, 0)) if (!_lv_extend_mirror(ah, lv, extents, 0))
return_0; return_0;
@ -1787,15 +1752,13 @@ int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,
backup(vg); backup(vg);
if (!suspend_lv(cmd, lv)) { if (!suspend_lv(cmd, lv)) {
stack;
vg_revert(vg); vg_revert(vg);
return 0; return_0;
} }
if (!vg_commit(vg)) { if (!vg_commit(vg)) {
stack;
resume_lv(cmd, lv); resume_lv(cmd, lv);
return 0; return_0;
} }
resume_lv(cmd, lv); resume_lv(cmd, lv);
@ -1890,10 +1853,9 @@ struct logical_volume *lv_create_empty(const char *name,
lv->lvid = *lvid; lv->lvid = *lvid;
if (fi->fmt->ops->lv_setup && !fi->fmt->ops->lv_setup(fi, lv)) { if (fi->fmt->ops->lv_setup && !fi->fmt->ops->lv_setup(fi, lv)) {
stack;
if (ll) if (ll)
dm_pool_free(cmd->mem, ll); dm_pool_free(cmd->mem, ll);
return NULL; return_NULL;
} }
if (!import) if (!import)
@ -1960,10 +1922,8 @@ struct list *build_parallel_areas_from_lv(struct cmd_context *cmd,
/* Find next segment end */ /* Find next segment end */
/* FIXME Unnecessary nesting! */ /* FIXME Unnecessary nesting! */
if (!_for_each_pv(cmd, lv, current_le, spvs->len, &spvs->len, if (!_for_each_pv(cmd, lv, current_le, spvs->len, &spvs->len,
0, 0, -1, 0, _add_pvs, (void *) spvs)) { 0, 0, -1, 0, _add_pvs, (void *) spvs))
stack; return_NULL;
return NULL;
}
current_le = spvs->le + spvs->len; current_le = spvs->le + spvs->len;
} while (current_le < lv->le_count); } while (current_le < lv->le_count);
@ -2055,10 +2015,8 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
if (lv_is_cow(lv)) { if (lv_is_cow(lv)) {
origin = origin_from_cow(lv); origin = origin_from_cow(lv);
log_verbose("Removing snapshot %s", lv->name); log_verbose("Removing snapshot %s", lv->name);
if (!vg_remove_snapshot(lv)) { if (!vg_remove_snapshot(lv))
stack; return_0;
return 0;
}
} }
log_verbose("Releasing logical volume \"%s\"", lv->name); log_verbose("Releasing logical volume \"%s\"", lv->name);

View File

@ -305,10 +305,8 @@ static int _lv_split_segment(struct logical_volume *lv, struct lv_segment *seg,
seg->area_len, seg->area_len,
seg_pvseg(seg, s)->len - seg_pvseg(seg, s)->len -
seg->area_len, seg->area_len,
split_seg, s))) { split_seg, s)))
stack; return_0;
return 0;
}
log_debug("Split %s:%u[%u] at %u: %s PE %u", lv->name, log_debug("Split %s:%u[%u] at %u: %s PE %u", lv->name,
seg->le, s, le, seg->le, s, le,
dev_name(seg_dev(seg, s)), dev_name(seg_dev(seg, s)),
@ -344,15 +342,11 @@ int lv_split_segment(struct logical_volume *lv, uint32_t le)
if (le == seg->le) if (le == seg->le)
return 1; return 1;
if (!_lv_split_segment(lv, seg, le)) { if (!_lv_split_segment(lv, seg, le))
stack; return_0;
return 0;
}
if (!vg_validate(lv->vg)) { if (!vg_validate(lv->vg))
stack; return_0;
return 0;
}
return 1; return 1;
} }

View File

@ -154,10 +154,8 @@ int add_pv_to_vg(struct volume_group *vg, const char *pv_name,
return 0; return 0;
} }
if (!alloc_pv_segment_whole_pv(mem, pv)) { if (!alloc_pv_segment_whole_pv(mem, pv))
stack; return_0;
return 0;
}
pvl->pv = pv; pvl->pv = pv;
list_add(&vg->pvs, &pvl->list); list_add(&vg->pvs, &pvl->list);
@ -189,10 +187,8 @@ static int _copy_pv(struct physical_volume *pv_to,
} }
if (!peg_dup(pv_to->fmt->cmd->mem, &pv_to->segments, if (!peg_dup(pv_to->fmt->cmd->mem, &pv_to->segments,
&pv_from->segments)) { &pv_from->segments))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -217,10 +213,8 @@ int get_pv_from_vg_by_id(const struct format_type *fmt, const char *vg_name,
list_iterate_items(pvl, &vg->pvs) { list_iterate_items(pvl, &vg->pvs) {
if (id_equal(&pvl->pv->id, (const struct id *) pvid)) { if (id_equal(&pvl->pv->id, (const struct id *) pvid)) {
if (!_copy_pv(pv, pvl->pv)) { if (!_copy_pv(pv, pvl->pv))
stack; return_0;
return 0;
}
return 1; return 1;
} }
} }
@ -475,10 +469,8 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name,
int consistent = 0; int consistent = 0;
int old_partial; int old_partial;
if (!(vg = dm_pool_zalloc(mem, sizeof(*vg)))) { if (!(vg = dm_pool_zalloc(mem, sizeof(*vg))))
stack; return_NULL;
return NULL;
}
/* is this vg name already in use ? */ /* is this vg name already in use ? */
old_partial = partial_mode(); old_partial = partial_mode();
@ -499,10 +491,8 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name,
vg->cmd = cmd; vg->cmd = cmd;
if (!(vg->name = dm_pool_strdup(mem, vg_name))) { if (!(vg->name = dm_pool_strdup(mem, vg_name)))
stack; goto_bad;
goto bad;
}
vg->seqno = 0; vg->seqno = 0;
@ -595,22 +585,16 @@ int vg_change_pesize(struct cmd_context *cmd __attribute((unused)),
vg->extent_size = new_size; vg->extent_size = new_size;
if (vg->fid->fmt->ops->vg_setup && if (vg->fid->fmt->ops->vg_setup &&
!vg->fid->fmt->ops->vg_setup(vg->fid, vg)) { !vg->fid->fmt->ops->vg_setup(vg->fid, vg))
stack; return_0;
return 0;
}
if (!_recalc_extents(&vg->extent_count, vg->name, "", old_size, if (!_recalc_extents(&vg->extent_count, vg->name, "", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
if (!_recalc_extents(&vg->free_count, vg->name, " free space", if (!_recalc_extents(&vg->free_count, vg->name, " free space",
old_size, new_size)) { old_size, new_size))
stack; return_0;
return 0;
}
/* foreach PV */ /* foreach PV */
list_iterate_items(pvl, &vg->pvs) { list_iterate_items(pvl, &vg->pvs) {
@ -618,16 +602,12 @@ int vg_change_pesize(struct cmd_context *cmd __attribute((unused)),
pv->pe_size = new_size; pv->pe_size = new_size;
if (!_recalc_extents(&pv->pe_count, pv_dev_name(pv), "", if (!_recalc_extents(&pv->pe_count, pv_dev_name(pv), "",
old_size, new_size)) { old_size, new_size))
stack; return_0;
return 0;
}
if (!_recalc_extents(&pv->pe_alloc_count, pv_dev_name(pv), if (!_recalc_extents(&pv->pe_alloc_count, pv_dev_name(pv),
" allocated space", old_size, new_size)) { " allocated space", old_size, new_size))
stack; return_0;
return 0;
}
/* foreach free PV Segment */ /* foreach free PV Segment */
list_iterate_items(pvseg, &pv->segments) { list_iterate_items(pvseg, &pv->segments) {
@ -636,16 +616,12 @@ int vg_change_pesize(struct cmd_context *cmd __attribute((unused)),
if (!_recalc_extents(&pvseg->pe, pv_dev_name(pv), if (!_recalc_extents(&pvseg->pe, pv_dev_name(pv),
" PV segment start", old_size, " PV segment start", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
if (!_recalc_extents(&pvseg->len, pv_dev_name(pv), if (!_recalc_extents(&pvseg->len, pv_dev_name(pv),
" PV segment length", old_size, " PV segment length", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
} }
} }
@ -654,39 +630,29 @@ int vg_change_pesize(struct cmd_context *cmd __attribute((unused)),
lv = lvl->lv; lv = lvl->lv;
if (!_recalc_extents(&lv->le_count, lv->name, "", old_size, if (!_recalc_extents(&lv->le_count, lv->name, "", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
list_iterate_items(seg, &lv->segments) { list_iterate_items(seg, &lv->segments) {
if (!_recalc_extents(&seg->le, lv->name, if (!_recalc_extents(&seg->le, lv->name,
" segment start", old_size, " segment start", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
if (!_recalc_extents(&seg->len, lv->name, if (!_recalc_extents(&seg->len, lv->name,
" segment length", old_size, " segment length", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
if (!_recalc_extents(&seg->area_len, lv->name, if (!_recalc_extents(&seg->area_len, lv->name,
" area length", old_size, " area length", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
if (!_recalc_extents(&seg->extents_copied, lv->name, if (!_recalc_extents(&seg->extents_copied, lv->name,
" extents moved", old_size, " extents moved", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
/* foreach area */ /* foreach area */
for (s = 0; s < seg->area_count; s++) { for (s = 0; s < seg->area_count; s++) {
@ -696,27 +662,21 @@ int vg_change_pesize(struct cmd_context *cmd __attribute((unused)),
(&seg_pe(seg, s), (&seg_pe(seg, s),
lv->name, lv->name,
" pvseg start", old_size, " pvseg start", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
if (!_recalc_extents if (!_recalc_extents
(&seg_pvseg(seg, s)->len, (&seg_pvseg(seg, s)->len,
lv->name, lv->name,
" pvseg length", old_size, " pvseg length", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
break; break;
case AREA_LV: case AREA_LV:
if (!_recalc_extents if (!_recalc_extents
(&seg_le(seg, s), lv->name, (&seg_le(seg, s), lv->name,
" area start", old_size, " area start", old_size,
new_size)) { new_size))
stack; return_0;
return 0;
}
break; break;
case AREA_UNASSIGNED: case AREA_UNASSIGNED:
log_error("Unassigned area %u found in " log_error("Unassigned area %u found in "
@ -804,10 +764,8 @@ static struct physical_volume *_alloc_pv(struct dm_pool *mem)
{ {
struct physical_volume *pv = dm_pool_zalloc(mem, sizeof(*pv)); struct physical_volume *pv = dm_pool_zalloc(mem, sizeof(*pv));
if (!pv) { if (!pv)
stack; return_NULL;
return NULL;
}
if (!(pv->vg_name = dm_pool_zalloc(mem, NAME_LEN))) { if (!(pv->vg_name = dm_pool_zalloc(mem, NAME_LEN))) {
dm_pool_free(mem, pv); dm_pool_free(mem, pv);
@ -1074,10 +1032,8 @@ int vg_remove(struct volume_group *vg)
/* Remove each copy of the metadata */ /* Remove each copy of the metadata */
list_iterate_items(mda, &vg->fid->metadata_areas) { list_iterate_items(mda, &vg->fid->metadata_areas) {
if (mda->ops->vg_remove && if (mda->ops->vg_remove &&
!mda->ops->vg_remove(vg->fid, vg, mda)) { !mda->ops->vg_remove(vg->fid, vg, mda))
stack; return_0;
return 0;
}
} }
return 1; return 1;
@ -1260,10 +1216,8 @@ int vg_write(struct volume_group *vg)
struct list *mdah; struct list *mdah;
struct metadata_area *mda; struct metadata_area *mda;
if (!vg_validate(vg)) { if (!vg_validate(vg))
stack; return_0;
return 0;
}
if (vg->status & PARTIAL_VG) { if (vg->status & PARTIAL_VG) {
log_error("Cannot change metadata for partial volume group %s", log_error("Cannot change metadata for partial volume group %s",
@ -1378,10 +1332,8 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd)
struct volume_group *vg; struct volume_group *vg;
struct physical_volume *pv; struct physical_volume *pv;
if (!(vginfo = vginfo_from_vgname(ORPHAN, NULL))) { if (!(vginfo = vginfo_from_vgname(ORPHAN, NULL)))
stack; return_NULL;
return NULL;
}
if (!(vg = dm_pool_zalloc(cmd->mem, sizeof(*vg)))) { if (!(vg = dm_pool_zalloc(cmd->mem, sizeof(*vg)))) {
log_error("vg allocation failed"); log_error("vg allocation failed");
@ -1477,15 +1429,11 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
if (!(fmt = fmt_from_vgname(vgname, vgid))) { if (!(fmt = fmt_from_vgname(vgname, vgid))) {
lvmcache_label_scan(cmd, 0); lvmcache_label_scan(cmd, 0);
if (!(fmt = fmt_from_vgname(vgname, vgid))) { if (!(fmt = fmt_from_vgname(vgname, vgid))) {
if (memlock()) { if (memlock())
stack; return_NULL;
return NULL;
}
lvmcache_label_scan(cmd, 2); lvmcache_label_scan(cmd, 2);
if (!(fmt = fmt_from_vgname(vgname, vgid))) { if (!(fmt = fmt_from_vgname(vgname, vgid)))
stack; return_NULL;
return NULL;
}
} }
} }
@ -1493,10 +1441,8 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
use_precommitted = 0; use_precommitted = 0;
/* Store pvids for later so we can check if any are missing */ /* Store pvids for later so we can check if any are missing */
if (!(pvids = lvmcache_get_pvids(cmd, vgname, vgid))) { if (!(pvids = lvmcache_get_pvids(cmd, vgname, vgid)))
stack; return_NULL;
return NULL;
}
/* create format instance with appropriate metadata area */ /* create format instance with appropriate metadata area */
if (!(fid = fmt->ops->create_instance(fmt, vgname, vgid, NULL))) { if (!(fid = fmt->ops->create_instance(fmt, vgname, vgid, NULL))) {
@ -1551,15 +1497,11 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
if (!correct_vg) { if (!correct_vg) {
inconsistent = 0; inconsistent = 0;
if (memlock()) { if (memlock())
stack; return_NULL;
return NULL;
}
lvmcache_label_scan(cmd, 2); lvmcache_label_scan(cmd, 2);
if (!(fmt = fmt_from_vgname(vgname, vgid))) { if (!(fmt = fmt_from_vgname(vgname, vgid)))
stack; return_NULL;
return NULL;
}
if (precommitted && !(fmt->features & FMT_PRECOMMIT)) if (precommitted && !(fmt->features & FMT_PRECOMMIT))
use_precommitted = 0; use_precommitted = 0;
@ -1605,10 +1547,8 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
} }
/* Give up looking */ /* Give up looking */
if (!correct_vg) { if (!correct_vg)
stack; return_NULL;
return NULL;
}
} }
lvmcache_update_vg(correct_vg); lvmcache_update_vg(correct_vg);
@ -1837,10 +1777,8 @@ static struct physical_volume *_pv_read(struct cmd_context *cmd,
struct lvmcache_info *info; struct lvmcache_info *info;
struct device *dev; struct device *dev;
if (!(dev = dev_cache_get(pv_name, cmd->filter))) { if (!(dev = dev_cache_get(pv_name, cmd->filter)))
stack; return_NULL;
return NULL;
}
if (!(label_read(dev, &label, UINT64_C(0)))) { if (!(label_read(dev, &label, UINT64_C(0)))) {
if (warnings) if (warnings)
@ -1871,10 +1809,8 @@ static struct physical_volume *_pv_read(struct cmd_context *cmd,
if (!pv->size) if (!pv->size)
return NULL; return NULL;
if (!alloc_pv_segment_whole_pv(cmd->mem, pv)) { if (!alloc_pv_segment_whole_pv(cmd->mem, pv))
stack; return_NULL;
return NULL;
}
return pv; return pv;
} }
@ -1996,10 +1932,8 @@ static int _pv_write(struct cmd_context *cmd __attribute((unused)),
return 0; return 0;
} }
if (!pv->fmt->ops->pv_write(pv->fmt, pv, mdas, label_sector)) { if (!pv->fmt->ops->pv_write(pv->fmt, pv, mdas, label_sector))
stack; return_0;
return 0;
}
return 1; return 1;
} }

View File

@ -1002,10 +1002,8 @@ struct logical_volume *find_pvmove_lv_from_pvname(struct cmd_context *cmd,
{ {
struct physical_volume *pv; struct physical_volume *pv;
if (!(pv = find_pv_by_name(cmd, name))) { if (!(pv = find_pv_by_name(cmd, name)))
stack; return_NULL;
return NULL;
}
return find_pvmove_lv(vg, pv->dev, lv_type); return find_pvmove_lv(vg, pv->dev, lv_type);
} }

View File

@ -53,10 +53,8 @@ int alloc_pv_segment_whole_pv(struct dm_pool *mem, struct physical_volume *pv)
return 1; return 1;
/* FIXME Cope with holes in PVs */ /* FIXME Cope with holes in PVs */
if (!(peg = _alloc_pv_segment(mem, pv, 0, pv->pe_count, NULL, 0))) { if (!(peg = _alloc_pv_segment(mem, pv, 0, pv->pe_count, NULL, 0)))
stack; return_0;
return 0;
}
list_add(&pv->segments, &peg->list); list_add(&pv->segments, &peg->list);
@ -72,10 +70,8 @@ int peg_dup(struct dm_pool *mem, struct list *peg_new, struct list *peg_old)
list_iterate_items(pego, peg_old) { list_iterate_items(pego, peg_old) {
if (!(peg = _alloc_pv_segment(mem, pego->pv, pego->pe, if (!(peg = _alloc_pv_segment(mem, pego->pv, pego->pe,
pego->len, pego->lvseg, pego->len, pego->lvseg,
pego->lv_area))) { pego->lv_area)))
stack; return_0;
return 0;
}
list_add(peg_new, &peg->list); list_add(peg_new, &peg->list);
} }
@ -93,10 +89,8 @@ static int _pv_split_segment(struct physical_volume *pv, struct pv_segment *peg,
if (!(peg_new = _alloc_pv_segment(pv->fmt->cmd->mem, peg->pv, pe, if (!(peg_new = _alloc_pv_segment(pv->fmt->cmd->mem, peg->pv, pe,
peg->len + peg->pe - pe, peg->len + peg->pe - pe,
NULL, 0))) { NULL, 0)))
stack; return_0;
return 0;
}
peg->len = peg->len - peg_new->len; peg->len = peg->len - peg_new->len;
@ -130,10 +124,8 @@ int pv_split_segment(struct physical_volume *pv, uint32_t pe)
if (pe == peg->pe) if (pe == peg->pe)
return 1; return 1;
if (!_pv_split_segment(pv, peg, pe)) { if (!_pv_split_segment(pv, peg, pe))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -155,10 +147,8 @@ struct pv_segment *assign_peg_to_lvseg(struct physical_volume *pv,
return &null_pv_segment; return &null_pv_segment;
if (!pv_split_segment(pv, pe) || if (!pv_split_segment(pv, pe) ||
!pv_split_segment(pv, pe + area_len)) { !pv_split_segment(pv, pe + area_len))
stack; return_NULL;
return NULL;
}
if (!(peg = find_peg_by_pe(pv, pe))) { if (!(peg = find_peg_by_pe(pv, pe))) {
log_error("Missing PV segment on %s at %u.", log_error("Missing PV segment on %s at %u.",
@ -196,10 +186,8 @@ int release_pv_segment(struct pv_segment *peg, uint32_t area_reduction)
} }
if (!pv_split_segment(peg->pv, peg->pe + peg->lvseg->area_len - if (!pv_split_segment(peg->pv, peg->pe + peg->lvseg->area_len -
area_reduction)) { area_reduction))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -371,10 +359,8 @@ static int _reduce_pv(struct physical_volume *pv, struct volume_group *vg, uint3
} }
} }
if (!pv_split_segment(pv, new_pe_count)) { if (!pv_split_segment(pv, new_pe_count))
stack; return_0;
return 0;
}
list_iterate_items_safe(peg, pegt, &pv->segments) { list_iterate_items_safe(peg, pegt, &pv->segments) {
if (peg->pe + peg->len > new_pe_count) if (peg->pe + peg->len > new_pe_count)

View File

@ -40,10 +40,8 @@ static int _create_single_area(struct dm_pool *mem, struct pv_map *pvm,
{ {
struct pv_area *pva; struct pv_area *pva;
if (!(pva = dm_pool_zalloc(mem, sizeof(*pva)))) { if (!(pva = dm_pool_zalloc(mem, sizeof(*pva))))
stack; return_0;
return 0;
}
log_debug("Allowing allocation on %s start PE %" PRIu32 " length %" log_debug("Allowing allocation on %s start PE %" PRIu32 " length %"
PRIu32, pv_dev_name(pvm->pv), start, length); PRIu32, pv_dev_name(pvm->pv), start, length);
@ -88,10 +86,8 @@ static int _create_alloc_areas_for_pv(struct dm_pool *mem, struct pv_map *pvm,
area_len = (end >= peg->pe + peg->len - 1) ? area_len = (end >= peg->pe + peg->len - 1) ?
peg->len - (pe - peg->pe) : end - pe + 1; peg->len - (pe - peg->pe) : end - pe + 1;
if (!_create_single_area(mem, pvm, pe, area_len)) { if (!_create_single_area(mem, pvm, pe, area_len))
stack; return_0;
return 0;
}
next: next:
pe = peg->pe + peg->len; pe = peg->pe + peg->len;
@ -108,20 +104,16 @@ static int _create_all_areas_for_pv(struct dm_pool *mem, struct pv_map *pvm,
if (!pe_ranges) { if (!pe_ranges) {
/* Use whole PV */ /* Use whole PV */
if (!_create_alloc_areas_for_pv(mem, pvm, UINT32_C(0), if (!_create_alloc_areas_for_pv(mem, pvm, UINT32_C(0),
pvm->pv->pe_count)) { pvm->pv->pe_count))
stack; return_0;
return 0;
}
return 1; return 1;
} }
list_iterate_items(aa, pe_ranges) { list_iterate_items(aa, pe_ranges) {
if (!_create_alloc_areas_for_pv(mem, pvm, aa->start, if (!_create_alloc_areas_for_pv(mem, pvm, aa->start,
aa->count)) { aa->count))
stack; return_0;
return 0;
}
} }
return 1; return 1;
@ -145,20 +137,16 @@ static int _create_maps(struct dm_pool *mem, struct list *pvs, struct list *pvms
} }
if (!pvm) { if (!pvm) {
if (!(pvm = dm_pool_zalloc(mem, sizeof(*pvm)))) { if (!(pvm = dm_pool_zalloc(mem, sizeof(*pvm))))
stack; return_0;
return 0;
}
pvm->pv = pvl->pv; pvm->pv = pvl->pv;
list_init(&pvm->areas); list_init(&pvm->areas);
list_add(pvms, &pvm->list); list_add(pvms, &pvm->list);
} }
if (!_create_all_areas_for_pv(mem, pvm, pvl->pe_ranges)) { if (!_create_all_areas_for_pv(mem, pvm, pvl->pe_ranges))
stack; return_0;
return 0;
}
} }
return 1; return 1;

View File

@ -70,17 +70,13 @@ int vg_add_snapshot(const char *name, struct logical_volume *origin,
if (!(snap = lv_create_empty(name ? name : "snapshot%d", if (!(snap = lv_create_empty(name ? name : "snapshot%d",
lvid, LVM_READ | LVM_WRITE | VISIBLE_LV, lvid, LVM_READ | LVM_WRITE | VISIBLE_LV,
ALLOC_INHERIT, 1, origin->vg))) { ALLOC_INHERIT, 1, origin->vg)))
stack; return_0;
return 0;
}
snap->le_count = extent_count; snap->le_count = extent_count;
if (!(seg = alloc_snapshot_seg(snap, 0, 0))) { if (!(seg = alloc_snapshot_seg(snap, 0, 0)))
stack; return_0;
return 0;
}
seg->chunk_size = chunk_size; seg->chunk_size = chunk_size;
seg->origin = origin; seg->origin = origin;

View File

@ -555,10 +555,8 @@ struct segment_type *init_segtype(struct cmd_context *cmd)
{ {
struct segment_type *segtype = dm_malloc(sizeof(*segtype)); struct segment_type *segtype = dm_malloc(sizeof(*segtype));
if (!segtype) { if (!segtype)
stack; return_NULL;
return NULL;
}
segtype->cmd = cmd; segtype->cmd = cmd;
segtype->ops = &_mirrored_ops; segtype->ops = &_mirrored_ops;

View File

@ -583,10 +583,8 @@ static int _size32_disp(struct dm_report *rh __attribute((unused)), struct dm_po
const char *disp, *repstr; const char *disp, *repstr;
uint64_t *sortval; uint64_t *sortval;
if (!*(disp = display_size_units(private, (uint64_t) size))) { if (!*(disp = display_size_units(private, (uint64_t) size)))
stack; return_0;
return 0;
}
if (!(repstr = dm_pool_strdup(mem, disp))) { if (!(repstr = dm_pool_strdup(mem, disp))) {
log_error("dm_pool_strdup failed"); log_error("dm_pool_strdup failed");
@ -614,10 +612,8 @@ static int _size64_disp(struct dm_report *rh __attribute((unused)),
const char *disp, *repstr; const char *disp, *repstr;
uint64_t *sortval; uint64_t *sortval;
if (!*(disp = display_size_units(private, size))) { if (!*(disp = display_size_units(private, size)))
stack; return_0;
return 0;
}
if (!(repstr = dm_pool_strdup(mem, disp))) { if (!(repstr = dm_pool_strdup(mem, disp))) {
log_error("dm_pool_strdup failed"); log_error("dm_pool_strdup failed");
@ -809,10 +805,8 @@ static int _uuid_disp(struct dm_report *rh __attribute((unused)), struct dm_pool
return 0; return 0;
} }
if (!id_write_format((const struct id *) data, repstr, 40)) { if (!id_write_format((const struct id *) data, repstr, 40))
stack; return_0;
return 0;
}
dm_report_field_set_value(field, repstr, NULL); dm_report_field_set_value(field, repstr, NULL);
return 1; return 1;

View File

@ -74,10 +74,8 @@ static int _snap_text_import(struct lv_segment *seg, const struct config_node *s
} }
if (!vg_add_snapshot(seg->lv->name, org, cow, if (!vg_add_snapshot(seg->lv->name, org, cow,
&seg->lv->lvid, seg->len, chunk_size)) { &seg->lv->lvid, seg->len, chunk_size))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -304,10 +302,8 @@ struct segment_type *init_segtype(struct cmd_context *cmd)
char *dso; char *dso;
#endif #endif
if (!segtype) { if (!segtype)
stack; return_NULL;
return NULL;
}
segtype->cmd = cmd; segtype->cmd = cmd;
segtype->ops = &_snapshot_ops; segtype->ops = &_snapshot_ops;

View File

@ -213,10 +213,8 @@ struct segment_type *init_striped_segtype(struct cmd_context *cmd)
{ {
struct segment_type *segtype = dm_malloc(sizeof(*segtype)); struct segment_type *segtype = dm_malloc(sizeof(*segtype));
if (!segtype) { if (!segtype)
stack; return_NULL;
return NULL;
}
segtype->cmd = cmd; segtype->cmd = cmd;
segtype->ops = &_striped_ops; segtype->ops = &_striped_ops;

View File

@ -96,10 +96,8 @@ struct segment_type *init_zero_segtype(struct cmd_context *cmd)
{ {
struct segment_type *segtype = dm_malloc(sizeof(*segtype)); struct segment_type *segtype = dm_malloc(sizeof(*segtype));
if (!segtype) { if (!segtype)
stack; return_NULL;
return NULL;
}
segtype->cmd = cmd; segtype->cmd = cmd;
segtype->ops = &_zero_ops; segtype->ops = &_zero_ops;

View File

@ -53,10 +53,8 @@ static int lvchange_permission(struct cmd_context *cmd,
} }
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!vg_write(lv->vg)) { if (!vg_write(lv->vg))
stack; return_0;
return 0;
}
backup(lv->vg); backup(lv->vg);
@ -114,16 +112,12 @@ static int lvchange_availability(struct cmd_context *cmd,
if (activate == CHANGE_ALN) { if (activate == CHANGE_ALN) {
log_verbose("Deactivating logical volume \"%s\" locally", log_verbose("Deactivating logical volume \"%s\" locally",
lv->name); lv->name);
if (!deactivate_lv_local(cmd, lv)) { if (!deactivate_lv_local(cmd, lv))
stack; return_0;
return 0;
}
} else if (activate == CHANGE_AN) { } else if (activate == CHANGE_AN) {
log_verbose("Deactivating logical volume \"%s\"", lv->name); log_verbose("Deactivating logical volume \"%s\"", lv->name);
if (!deactivate_lv(cmd, lv)) { if (!deactivate_lv(cmd, lv))
stack; return_0;
return 0;
}
} else { } else {
if (lockingfailed() && (lv->vg->status & CLUSTERED)) { if (lockingfailed() && (lv->vg->status & CLUSTERED)) {
log_verbose("Locking failed: ignoring clustered " log_verbose("Locking failed: ignoring clustered "
@ -134,24 +128,18 @@ static int lvchange_availability(struct cmd_context *cmd,
if (lv_is_origin(lv) || (activate == CHANGE_AE)) { if (lv_is_origin(lv) || (activate == CHANGE_AE)) {
log_verbose("Activating logical volume \"%s\" " log_verbose("Activating logical volume \"%s\" "
"exclusively", lv->name); "exclusively", lv->name);
if (!activate_lv_excl(cmd, lv)) { if (!activate_lv_excl(cmd, lv))
stack; return_0;
return 0;
}
} else if (activate == CHANGE_ALY) { } else if (activate == CHANGE_ALY) {
log_verbose("Activating logical volume \"%s\" locally", log_verbose("Activating logical volume \"%s\" locally",
lv->name); lv->name);
if (!activate_lv_local(cmd, lv)) { if (!activate_lv_local(cmd, lv))
stack; return_0;
return 0;
}
} else { } else {
log_verbose("Activating logical volume \"%s\"", log_verbose("Activating logical volume \"%s\"",
lv->name); lv->name);
if (!activate_lv(cmd, lv)) { if (!activate_lv(cmd, lv))
stack; return_0;
return 0;
}
} }
if ((lv->status & LOCKED) && if ((lv->status & LOCKED) &&
@ -357,18 +345,14 @@ static int lvchange_alloc(struct cmd_context *cmd, struct logical_volume *lv)
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!vg_write(lv->vg)) { if (!vg_write(lv->vg))
stack; return_0;
return 0;
}
backup(lv->vg); backup(lv->vg);
/* No need to suspend LV for this change */ /* No need to suspend LV for this change */
if (!vg_commit(lv->vg)) { if (!vg_commit(lv->vg))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -407,10 +391,8 @@ static int lvchange_readahead(struct cmd_context *cmd,
lv->name); lv->name);
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!vg_write(lv->vg)) { if (!vg_write(lv->vg))
stack; return_0;
return 0;
}
backup(lv->vg); backup(lv->vg);
@ -488,17 +470,13 @@ static int lvchange_persistent(struct cmd_context *cmd,
} }
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!vg_write(lv->vg)) { if (!vg_write(lv->vg))
stack; return_0;
return 0;
}
backup(lv->vg); backup(lv->vg);
if (!vg_commit(lv->vg)) { if (!vg_commit(lv->vg))
stack; return_0;
return 0;
}
if (active) { if (active) {
log_verbose("Re-activating logical volume \"%s\"", lv->name); log_verbose("Re-activating logical volume \"%s\"", lv->name);
@ -542,18 +520,14 @@ static int lvchange_tag(struct cmd_context *cmd, struct logical_volume *lv,
} }
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name); log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
if (!vg_write(lv->vg)) { if (!vg_write(lv->vg))
stack; return_0;
return 0;
}
backup(lv->vg); backup(lv->vg);
/* No need to suspend LV for this change */ /* No need to suspend LV for this change */
if (!vg_commit(lv->vg)) { if (!vg_commit(lv->vg))
stack; return_0;
return 0;
}
return 1; return 1;
} }

View File

@ -743,21 +743,19 @@ int lvconvert(struct cmd_context * cmd, int argc, char **argv)
if (!(lvl = find_lv_in_vg(vg, lp.lv_name))) { if (!(lvl = find_lv_in_vg(vg, lp.lv_name))) {
log_error("Logical volume \"%s\" not found in " log_error("Logical volume \"%s\" not found in "
"volume group \"%s\"", lp.lv_name, lp.vg_name); "volume group \"%s\"", lp.lv_name, lp.vg_name);
goto error; goto bad;
} }
if (lp.pv_count) { if (lp.pv_count) {
if (!(lp.pvh = create_pv_list(cmd->mem, vg, lp.pv_count, if (!(lp.pvh = create_pv_list(cmd->mem, vg, lp.pv_count,
lp.pvs, 1))) { lp.pvs, 1)))
stack; goto_bad;
goto error;
}
} else } else
lp.pvh = &vg->pvs; lp.pvh = &vg->pvs;
ret = lvconvert_single(cmd, lvl->lv, &lp); ret = lvconvert_single(cmd, lvl->lv, &lp);
error: bad:
unlock_vg(cmd, lp.vg_name); unlock_vg(cmd, lp.vg_name);
if (ret == ECMD_PROCESSED && lp.need_polling) { if (ret == ECMD_PROCESSED && lp.need_polling) {

View File

@ -135,10 +135,8 @@ static int _lvcreate_name_params(struct lvcreate_params *lp,
if ((ptr = strrchr(lp->lv_name, '/'))) if ((ptr = strrchr(lp->lv_name, '/')))
lp->lv_name = ptr + 1; lp->lv_name = ptr + 1;
if (!apply_lvname_restrictions(lp->lv_name)) { if (!apply_lvname_restrictions(lp->lv_name))
stack; return_0;
return 0;
}
if (!validate_name(lp->lv_name)) { if (!validate_name(lp->lv_name)) {
log_error("Logical volume name \"%s\" is invalid", log_error("Logical volume name \"%s\" is invalid",
@ -385,10 +383,8 @@ static int _lvcreate_params(struct lvcreate_params *lp, struct cmd_context *cmd,
} }
log_verbose("Setting chunksize to %d sectors.", lp->chunk_size); log_verbose("Setting chunksize to %d sectors.", lp->chunk_size);
if (!(lp->segtype = get_segtype_from_string(cmd, "snapshot"))) { if (!(lp->segtype = get_segtype_from_string(cmd, "snapshot")))
stack; return_0;
return 0;
}
} else { } else {
if (arg_count(cmd, chunksize_ARG)) { if (arg_count(cmd, chunksize_ARG)) {
log_error("-c is only available with snapshots"); log_error("-c is only available with snapshots");
@ -409,10 +405,8 @@ static int _lvcreate_params(struct lvcreate_params *lp, struct cmd_context *cmd,
return 0; return 0;
} }
if (!(lp->segtype = get_segtype_from_string(cmd, "striped"))) { if (!(lp->segtype = get_segtype_from_string(cmd, "striped")))
stack; return_0;
return 0;
}
} else { } else {
if (arg_count(cmd, corelog_ARG)) { if (arg_count(cmd, corelog_ARG)) {
log_error("--corelog is only available with mirrors"); log_error("--corelog is only available with mirrors");
@ -435,10 +429,8 @@ static int _lvcreate_params(struct lvcreate_params *lp, struct cmd_context *cmd,
if (!_lvcreate_name_params(lp, cmd, &argc, &argv) || if (!_lvcreate_name_params(lp, cmd, &argc, &argv) ||
!_read_size_params(lp, cmd) || !_read_size_params(lp, cmd) ||
!_read_stripe_params(lp, cmd) || !_read_stripe_params(lp, cmd) ||
!_read_mirror_params(lp, cmd)) { !_read_mirror_params(lp, cmd))
stack; return_0;
return 0;
}
/* /*
* Should we zero the lv. * Should we zero the lv.
@ -557,10 +549,8 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
*/ */
if (lp->pv_count) { if (lp->pv_count) {
if (!(pvh = create_pv_list(cmd->mem, vg, if (!(pvh = create_pv_list(cmd->mem, vg,
lp->pv_count, lp->pvs, 1))) { lp->pv_count, lp->pvs, 1)))
stack; return_0;
return 0;
}
} else } else
pvh = &vg->pvs; pvh = &vg->pvs;
@ -712,10 +702,8 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
/* The snapshot segment gets created later */ /* The snapshot segment gets created later */
if (lp->snapshot && if (lp->snapshot &&
!(lp->segtype = get_segtype_from_string(cmd, "striped"))) { !(lp->segtype = get_segtype_from_string(cmd, "striped")))
stack; return_0;
return 0;
}
if (!archive(vg)) if (!archive(vg))
return 0; return 0;
@ -754,10 +742,8 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
} }
if (!(lv = lv_create_empty(lv_name ? lv_name : "lvol%d", NULL, if (!(lv = lv_create_empty(lv_name ? lv_name : "lvol%d", NULL,
status, lp->alloc, 0, vg))) { status, lp->alloc, 0, vg)))
stack; return_0;
goto error;
}
if (lp->read_ahead) { if (lp->read_ahead) {
log_verbose("Setting read ahead sectors"); log_verbose("Setting read ahead sectors");
@ -775,7 +761,7 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
if (tag && !str_list_add(cmd->mem, &lv->tags, tag)) { if (tag && !str_list_add(cmd->mem, &lv->tags, tag)) {
log_error("Failed to add tag %s to %s/%s", log_error("Failed to add tag %s to %s/%s",
tag, lv->vg->name, lv->name); tag, lv->vg->name, lv->name);
goto error; return 0;
} }
if (!lv_extend(lv, lp->segtype, lp->stripes, lp->stripe_size, if (!lv_extend(lv, lp->segtype, lp->stripes, lp->stripe_size,
@ -880,9 +866,6 @@ static int _lvcreate(struct cmd_context *cmd, struct volume_group *vg,
return 1; return 1;
error:
return 0;
deactivate_and_revert_new_lv: deactivate_and_revert_new_lv:
if (!deactivate_lv(cmd, lv)) { if (!deactivate_lv(cmd, lv)) {
log_error("Unable to deactivate failed new LV. " log_error("Unable to deactivate failed new LV. "

View File

@ -1028,10 +1028,8 @@ struct cmd_context *init_lvm(unsigned is_static)
_cmdline.the_args = &_the_args[0]; _cmdline.the_args = &_the_args[0];
if (!(cmd = create_toolcontext(_cmdline.the_args, is_static, 0))) { if (!(cmd = create_toolcontext(_cmdline.the_args, is_static, 0)))
stack; return_NULL;
return NULL;
}
_init_rand(); _init_rand();

View File

@ -150,19 +150,13 @@ static int do_resizefs_reduce(const struct cmd_context *cmd,
return 0; return 0;
} }
if (!lp->nofsck) { if (!lp->nofsck)
if (!exec_cmd("fsadm", "check", lv_path, NULL)) { if (!exec_cmd("fsadm", "check", lv_path, NULL))
stack; return_0;
return 0;
}
}
if (lp->resize == LV_REDUCE) { if (lp->resize == LV_REDUCE)
if (!exec_cmd("fsadm", "resize", lv_path, size_buf)) { if (!exec_cmd("fsadm", "resize", lv_path, size_buf))
stack; return_0;
return 0;
}
}
return 1; return 1;
} }

View File

@ -164,9 +164,8 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
return 0; return 0;
} }
if (!id_write_format(&pv->id, uuid, sizeof(uuid))) { if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
stack;
unlock_vg(cmd, vg_name); unlock_vg(cmd, vg_name);
return 0; return_0;
} }
log_verbose("Changing uuid of %s to %s.", pv_name, uuid); log_verbose("Changing uuid of %s to %s.", pv_name, uuid);
if (!is_orphan(pv)) { if (!is_orphan(pv)) {

View File

@ -71,18 +71,13 @@ static struct list *_get_allocatable_pvs(struct cmd_context *cmd, int argc,
struct list *allocatable_pvs, *pvht, *pvh; struct list *allocatable_pvs, *pvht, *pvh;
struct pv_list *pvl; struct pv_list *pvl;
if (argc) { if (argc)
if (!(allocatable_pvs = create_pv_list(cmd->mem, vg, argc, allocatable_pvs = create_pv_list(cmd->mem, vg, argc, argv, 1);
argv, 1))) { else
stack; allocatable_pvs = clone_pv_list(cmd->mem, &vg->pvs);
return NULL;
} if (!allocatable_pvs)
} else { return_NULL;
if (!(allocatable_pvs = clone_pv_list(cmd->mem, &vg->pvs))) {
stack;
return NULL;
}
}
list_iterate_safe(pvh, pvht, allocatable_pvs) { list_iterate_safe(pvh, pvht, allocatable_pvs) {
pvl = list_item(pvh, struct pv_list); pvl = list_item(pvh, struct pv_list);
@ -197,10 +192,8 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
continue; continue;
} }
if (!_insert_pvmove_mirrors(cmd, lv_mirr, source_pvl, lv, if (!_insert_pvmove_mirrors(cmd, lv_mirr, source_pvl, lv,
*lvs_changed)) { *lvs_changed))
stack; return_NULL;
return NULL;
}
} }
/* Is temporary mirror empty? */ /* Is temporary mirror empty? */
@ -236,10 +229,8 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
backup(vg); backup(vg);
/* Suspend lvs_changed */ /* Suspend lvs_changed */
if (!suspend_lvs(cmd, lvs_changed)) { if (!suspend_lvs(cmd, lvs_changed))
stack; return_0;
return 0;
}
/* Suspend mirrors on subsequent calls */ /* Suspend mirrors on subsequent calls */
if (!first_time) { if (!first_time) {

View File

@ -144,9 +144,8 @@ static int _pv_resize_single(struct cmd_context *cmd,
} }
if (!pv_resize(pv, vg, new_pe_count)) { if (!pv_resize(pv, vg, new_pe_count)) {
stack;
unlock_vg(cmd, vg_name); unlock_vg(cmd, vg_name);
return 0; return_0;
} }
} }

View File

@ -978,10 +978,8 @@ static int _parse_pes(struct dm_pool *mem, char *c, struct list *pe_ranges,
/* Default to whole PV */ /* Default to whole PV */
if (!c) { if (!c) {
if (!_add_pe_range(mem, pvname, pe_ranges, UINT32_C(0), size)) { if (!_add_pe_range(mem, pvname, pe_ranges, UINT32_C(0), size))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -1026,10 +1024,8 @@ static int _parse_pes(struct dm_pool *mem, char *c, struct list *pe_ranges,
return 0; return 0;
} }
if (!_add_pe_range(mem, pvname, pe_ranges, start, end - start + 1)) { if (!_add_pe_range(mem, pvname, pe_ranges, start, end - start + 1))
stack; return_0;
return 0;
}
} }
@ -1084,10 +1080,8 @@ static int _create_pv_entry(struct dm_pool *mem, struct pv_list *pvl,
/* Determine selected physical extents */ /* Determine selected physical extents */
if (!_parse_pes(mem, colon, new_pvl->pe_ranges, pv_dev_name(pvl->pv), if (!_parse_pes(mem, colon, new_pvl->pe_ranges, pv_dev_name(pvl->pv),
pvl->pv->pe_count)) { pvl->pv->pe_count))
stack; return_0;
return 0;
}
return 1; return 1;
} }
@ -1124,10 +1118,8 @@ struct list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int ar
tagname)) { tagname)) {
if (!_create_pv_entry(mem, pvl, NULL, if (!_create_pv_entry(mem, pvl, NULL,
allocatable_only, allocatable_only,
r)) { r))
stack; return_NULL;
return NULL;
}
} }
} }
continue; continue;
@ -1149,10 +1141,8 @@ struct list *create_pv_list(struct dm_pool *mem, struct volume_group *vg, int ar
"Volume Group \"%s\"", pvname, vg->name); "Volume Group \"%s\"", pvname, vg->name);
return NULL; return NULL;
} }
if (!_create_pv_entry(mem, pvl, colon, allocatable_only, r)) { if (!_create_pv_entry(mem, pvl, colon, allocatable_only, r))
stack; return_NULL;
return NULL;
}
} }
if (list_empty(r)) if (list_empty(r))

View File

@ -42,12 +42,12 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
} }
if (!vgs_are_compatible(cmd, vg_from, vg_to)) if (!vgs_are_compatible(cmd, vg_from, vg_to))
goto error; goto_bad;
/* FIXME List arg: vg_show_with_pv_and_lv(vg_to); */ /* FIXME List arg: vg_show_with_pv_and_lv(vg_to); */
if (!archive(vg_from) || !archive(vg_to)) if (!archive(vg_from) || !archive(vg_to))
goto error; goto_bad;
/* Merge volume groups */ /* Merge volume groups */
while (!list_empty(&vg_from->pvs)) { while (!list_empty(&vg_from->pvs)) {
@ -75,13 +75,11 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
log_error("Failed to generate new " log_error("Failed to generate new "
"random LVID for %s", "random LVID for %s",
lvl2->lv->name); lvl2->lv->name);
goto error; goto bad;
} }
if (!id_write_format(&lvid2->id[1], uuid, if (!id_write_format(&lvid2->id[1], uuid,
sizeof(uuid))) { sizeof(uuid)))
stack; goto_bad;
goto error;
}
log_verbose("Changed LVID for %s to %s", log_verbose("Changed LVID for %s to %s",
lvl2->lv->name, uuid); lvl2->lv->name, uuid);
@ -110,9 +108,8 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
/* store it on disks */ /* store it on disks */
log_verbose("Writing out updated volume group"); log_verbose("Writing out updated volume group");
if (!vg_write(vg_to) || !vg_commit(vg_to)) { if (!vg_write(vg_to) || !vg_commit(vg_to))
goto error; goto_bad;
}
/* FIXME Remove /dev/vgfrom */ /* FIXME Remove /dev/vgfrom */
@ -125,7 +122,7 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
vg_from->name, vg_to->name); vg_from->name, vg_to->name);
return ECMD_PROCESSED; return ECMD_PROCESSED;
error: bad:
unlock_vg(cmd, vg_name_from); unlock_vg(cmd, vg_name_from);
unlock_vg(cmd, vg_name_to); unlock_vg(cmd, vg_name_to);
return ECMD_FAILED; return ECMD_FAILED;

View File

@ -25,10 +25,8 @@ static int _remove_pv(struct volume_group *vg, struct pv_list *pvl)
return 0; return 0;
} }
if (!id_write_format(&pvl->pv->id, uuid, sizeof(uuid))) { if (!id_write_format(&pvl->pv->id, uuid, sizeof(uuid)))
stack; return_0;
return 0;
}
log_verbose("Removing PV with UUID %s from VG %s", uuid, vg->name); log_verbose("Removing PV with UUID %s from VG %s", uuid, vg->name);
@ -91,16 +89,12 @@ static int _remove_lv(struct cmd_context *cmd, struct logical_volume *lv,
} }
*list_unsafe = 1; /* May remove caller's lvht! */ *list_unsafe = 1; /* May remove caller's lvht! */
if (!vg_remove_snapshot(cow)) { if (!vg_remove_snapshot(cow))
stack; return_0;
return 0;
}
log_verbose("Removing LV %s from VG %s", cow->name, log_verbose("Removing LV %s from VG %s", cow->name,
lv->vg->name); lv->vg->name);
if (!lv_remove(cow)) { if (!lv_remove(cow))
stack; return_0;
return 0;
}
first = 0; first = 0;
} }
@ -129,10 +123,8 @@ static int _remove_lv(struct cmd_context *cmd, struct logical_volume *lv,
} else { } else {
/* Remove LV immediately. */ /* Remove LV immediately. */
log_verbose("Removing LV %s from VG %s", lv->name, lv->vg->name); log_verbose("Removing LV %s from VG %s", lv->name, lv->vg->name);
if (!lv_remove(lv)) { if (!lv_remove(lv))
stack; return_0;
return 0;
}
} }
return 1; return 1;
@ -177,10 +169,8 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
only_mirror_images_found = 0; only_mirror_images_found = 0;
continue; continue;
} }
if (!_remove_lv(cmd, lv, &list_unsafe, &lvs_changed)) { if (!_remove_lv(cmd, lv, &list_unsafe, &lvs_changed))
stack; return_0;
return 0;
}
if (list_unsafe) if (list_unsafe)
goto restart_loop; goto restart_loop;
} }
@ -198,10 +188,8 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
pvl = list_item(pvh, struct pv_list); pvl = list_item(pvh, struct pv_list);
if (pvl->pv->dev) if (pvl->pv->dev)
continue; continue;
if (!_remove_pv(vg, pvl)) { if (!_remove_pv(vg, pvl))
stack; return_0;
return 0;
}
} }
/* VG is now consistent */ /* VG is now consistent */
@ -223,10 +211,9 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
/* Suspend lvs_changed */ /* Suspend lvs_changed */
init_partial(1); init_partial(1);
if (!suspend_lvs(cmd, &lvs_changed)) { if (!suspend_lvs(cmd, &lvs_changed)) {
stack;
init_partial(0); init_partial(0);
vg_revert(vg); vg_revert(vg);
return 0; return_0;
} }
init_partial(0); init_partial(0);
} }
@ -290,10 +277,8 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
if ((mimages != mirrored_seg->area_count) || remove_log){ if ((mimages != mirrored_seg->area_count) || remove_log){
if (!reconfigure_mirror_images(mirrored_seg, mimages, if (!reconfigure_mirror_images(mirrored_seg, mimages,
NULL, remove_log)) { NULL, remove_log))
stack; return_0;
return 0;
}
if (!vg_write(vg)) { if (!vg_write(vg)) {
log_error("Failed to write out updated " log_error("Failed to write out updated "
@ -353,10 +338,8 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
lvl->lv->vg->name); lvl->lv->vg->name);
/* Skip LVs already removed by mirror code */ /* Skip LVs already removed by mirror code */
if (find_lv_in_vg(vg, lvl->lv->name) && if (find_lv_in_vg(vg, lvl->lv->name) &&
!lv_remove(lvl->lv)) { !lv_remove(lvl->lv))
stack; return_0;
return 0;
}
} }
} }