summaryrefslogtreecommitdiff
path: root/liblvm
diff options
context:
space:
mode:
Diffstat (limited to 'liblvm')
-rw-r--r--liblvm/Makefile.in4
-rw-r--r--liblvm/lvm2app.h41
-rw-r--r--liblvm/lvm_base.c16
-rw-r--r--liblvm/lvm_lv.c56
-rw-r--r--liblvm/lvm_misc.c27
-rw-r--r--liblvm/lvm_pv.c10
-rw-r--r--liblvm/lvm_vg.c13
7 files changed, 119 insertions, 48 deletions
diff --git a/liblvm/Makefile.in b/liblvm/Makefile.in
index ec9522b..8ae4661 100644
--- a/liblvm/Makefile.in
+++ b/liblvm/Makefile.in
@@ -1,6 +1,6 @@
#
# Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
-# Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2004-2012 Red Hat, Inc. All rights reserved.
#
# This file is part of LVM2.
#
@@ -37,6 +37,8 @@ CLEAN_TARGETS += liblvm.cflow $(LIB_NAME).a
EXPORTED_HEADER = $(srcdir)/lvm2app.h
EXPORTED_FN_PREFIX = lvm
+LDDEPS += $(top_builddir)/lib/liblvm-internal.a
+
include $(top_builddir)/make.tmpl
LIBS += $(LVMINTERNAL_LIBS) -ldevmapper
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index 317911d..b758945 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -303,6 +303,28 @@ int lvm_config_reload(lvm_t libh);
int lvm_config_override(lvm_t libh, const char *config_string);
/**
+ * Find a boolean value in the LVM configuration.
+ *
+ * \memberof lvm_t
+ *
+ * This function finds a boolean value associated with a path
+ * in current LVM configuration.
+ *
+ * \param libh
+ * Handle obtained from lvm_init().
+ *
+ * \param config_path
+ * A path in LVM configuration
+ *
+ * \param fail
+ * Value to return if the path is not found.
+ *
+ * \return
+ * boolean value for 'config_path' (success) or the value of 'fail' (error)
+ */
+int lvm_config_find_bool(lvm_t libh, const char *config_path, int fail);
+
+/**
* Return stored error no describing last LVM API error.
*
* \memberof lvm_t
@@ -1321,6 +1343,22 @@ int lvm_lv_remove_tag(lv_t lv, const char *tag);
*/
struct dm_list *lvm_lv_get_tags(const lv_t lv);
+/**
+ * Rename logical volume to new_name.
+ *
+ * \memberof lv_t
+ *
+ * \param lv
+ * Logical volume handle.
+ *
+ * \param new_name
+ * New name of logical volume.
+ *
+ * \return
+ * 0 (success) or -1 (failure).
+ *
+ */
+int lvm_lv_rename(lv_t lv, const char *new_name);
/**
* Resize logical volume to new_size bytes.
@@ -1591,7 +1629,8 @@ typedef enum {
PERCENT_0 = 0,
PERCENT_1 = 1000000,
PERCENT_100 = 100 * PERCENT_1,
- PERCENT_INVALID = -1
+ PERCENT_INVALID = -1,
+ PERCENT_MERGE_FAILED = -2
} percent_range_t;
typedef int32_t percent_t;
diff --git a/liblvm/lvm_base.c b/liblvm/lvm_base.c
index 9e1a8ec..01ea0d7 100644
--- a/liblvm/lvm_base.c
+++ b/liblvm/lvm_base.c
@@ -31,10 +31,13 @@ lvm_t lvm_init(const char *system_dir)
/* FIXME: logging bound to handle
*/
+ if (!udev_init_library_context())
+ stack;
+
/* create context */
/* FIXME: split create_toolcontext */
/* FIXME: make all globals configurable */
- cmd = create_toolcontext(0, system_dir);
+ cmd = create_toolcontext(0, system_dir, 0, 0);
if (!cmd)
return NULL;
@@ -69,6 +72,7 @@ lvm_t lvm_init(const char *system_dir)
void lvm_quit(lvm_t libh)
{
destroy_toolcontext((struct cmd_context *)libh);
+ udev_fin_library_context();
}
int lvm_config_reload(lvm_t libh)
@@ -90,6 +94,11 @@ int lvm_config_override(lvm_t libh, const char *config_settings)
return 0;
}
+int lvm_config_find_bool(lvm_t libh, const char *config_path, int fail)
+{
+ return find_config_tree_bool((struct cmd_context *)libh, config_path, fail);
+}
+
int lvm_errno(lvm_t libh)
{
return stored_errno();
@@ -117,3 +126,8 @@ const char *lvm_vgname_from_device(lvm_t libh, const char *device)
struct cmd_context *cmd = (struct cmd_context *)libh;
return find_vgname_from_pvname(cmd, device);
}
+
+float lvm_percent_to_float(percent_t v)
+{
+ return percent_to_float(v);
+}
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index b77f78c..d47a857 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -62,7 +62,7 @@ struct lvm_property_value lvm_lvseg_get_property(const lvseg_t lvseg,
uint64_t lvm_lv_is_active(const lv_t lv)
{
struct lvinfo info;
- if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0) &&
+ if (lv_info(lv->vg->cmd, lv, 0, &info, 0, 0) &&
info.exists && info.live_table)
return 1;
return 0;
@@ -71,7 +71,7 @@ uint64_t lvm_lv_is_active(const lv_t lv)
uint64_t lvm_lv_is_suspended(const lv_t lv)
{
struct lvinfo info;
- if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0) &&
+ if (lv_info(lv->vg->cmd, lv, 0, &info, 0, 0) &&
info.exists && info.suspended)
return 1;
return 0;
@@ -110,7 +110,7 @@ static void _lv_set_default_params(struct lvcreate_params *lp,
lp->zero = 1;
lp->major = -1;
lp->minor = -1;
- lp->activation_monitoring = DEFAULT_DMEVENTD_MONITOR;
+ lp->activate = CHANGE_AY;
lp->vg_name = vg->name;
lp->lv_name = lvname; /* FIXME: check this for safety */
lp->pvh = &vg->pvs;
@@ -123,12 +123,18 @@ static void _lv_set_default_params(struct lvcreate_params *lp,
}
/* Set default for linear segment specific LV parameters */
-static void _lv_set_default_linear_params(struct cmd_context *cmd,
+static int _lv_set_default_linear_params(struct cmd_context *cmd,
struct lvcreate_params *lp)
{
- lp->segtype = get_segtype_from_string(cmd, "striped");
+ if (!(lp->segtype = get_segtype_from_string(cmd, "striped"))) {
+ log_error(INTERNAL_ERROR "Segtype striped not found.");
+ return 0;
+ }
+
lp->stripes = 1;
lp->stripe_size = DEFAULT_STRIPESIZE * 2;
+
+ return 1;
}
/*
@@ -138,7 +144,7 @@ static void _lv_set_default_linear_params(struct cmd_context *cmd,
*/
lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size)
{
- struct lvcreate_params lp;
+ struct lvcreate_params lp = { 0 };
uint64_t extents;
struct lv_list *lvl;
@@ -146,15 +152,19 @@ lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size)
return NULL;
if (!vg_check_write_mode(vg))
return NULL;
- memset(&lp, 0, sizeof(lp));
- extents = extents_from_size(vg->cmd, size / SECTOR_SIZE,
- vg->extent_size);
+
+ if (!(extents = extents_from_size(vg->cmd, size / SECTOR_SIZE,
+ vg->extent_size))) {
+ log_error("Unable to create LV without size.");
+ return NULL;
+ }
+
_lv_set_default_params(&lp, vg, name, extents);
- _lv_set_default_linear_params(vg->cmd, &lp);
+ if (!_lv_set_default_linear_params(vg->cmd, &lp))
+ return_NULL;
if (!lv_create_single(vg, &lp))
- return NULL;
- lvl = find_lv_in_vg(vg, name);
- if (!lvl)
+ return_NULL;
+ if (!(lvl = find_lv_in_vg(vg, name)))
return NULL;
return (lv_t) lvl->lv;
}
@@ -269,12 +279,12 @@ lv_t lvm_lv_from_uuid(vg_t vg, const char *uuid)
log_errno (EINVAL, "Invalid UUID string length");
return NULL;
}
- if (strlen(uuid) >= ID_LEN) {
- if (!id_read_format(&id, uuid)) {
- log_errno(EINVAL, "Invalid UUID format");
- return NULL;
- }
+
+ if (!id_read_format(&id, uuid)) {
+ log_errno(EINVAL, "Invalid UUID format.");
+ return NULL;
}
+
dm_list_iterate_items(lvl, &vg->lvs) {
if (id_equal(&vg->id, &lvl->lv->lvid.id[0]) &&
id_equal(&id, &lvl->lv->lvid.id[1]))
@@ -282,6 +292,16 @@ lv_t lvm_lv_from_uuid(vg_t vg, const char *uuid)
}
return NULL;
}
+
+int lvm_lv_rename(lv_t lv, const char *new_name)
+{
+ if (!lv_rename(lv->vg->cmd, lv, new_name)) {
+ log_verbose("LV Rename failed.");
+ return -1;
+ }
+ return 0;
+}
+
int lvm_lv_resize(const lv_t lv, uint64_t new_size)
{
/* FIXME: add lv resize code here */
diff --git a/liblvm/lvm_misc.c b/liblvm/lvm_misc.c
index 62fef61..0a0ea12 100644
--- a/liblvm/lvm_misc.c
+++ b/liblvm/lvm_misc.c
@@ -50,35 +50,30 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
const pvseg_t pvseg, const char *name)
{
struct lvm_property_type prop;
- struct lvm_property_value v;
+ struct lvm_property_value v = { 0 };
prop.id = name;
+
if (pv) {
- if (!pv_get_property(pv, &prop)) {
- v.is_valid = 0;
+ if (!pv_get_property(pv, &prop))
return v;
- }
} else if (vg) {
- if (!vg_get_property(vg, &prop)) {
- v.is_valid = 0;
+ if (!vg_get_property(vg, &prop))
return v;
- }
} else if (lv) {
- if (!lv_get_property(lv, &prop)) {
- v.is_valid = 0;
+ if (!lv_get_property(lv, &prop))
return v;
- }
} else if (lvseg) {
- if (!lvseg_get_property(lvseg, &prop)) {
- v.is_valid = 0;
+ if (!lvseg_get_property(lvseg, &prop))
return v;
- }
} else if (pvseg) {
- if (!pvseg_get_property(pvseg, &prop)) {
- v.is_valid = 0;
+ if (!pvseg_get_property(pvseg, &prop))
return v;
- }
+ } else {
+ log_errno(EINVAL, "Invalid NULL handle passed to library function.");
+ return v;
}
+
v.is_settable = prop.is_settable;
v.is_string = prop.is_string;
v.is_integer = prop.is_integer;
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index 4fe2d3e..90edaed 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -107,12 +107,12 @@ pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid)
log_errno (EINVAL, "Invalid UUID string length");
return NULL;
}
- if (strlen(uuid) >= ID_LEN) {
- if (!id_read_format(&id, uuid)) {
- log_errno(EINVAL, "Invalid UUID format");
- return NULL;
- }
+
+ if (!id_read_format(&id, uuid)) {
+ log_errno(EINVAL, "Invalid UUID format.");
+ return NULL;
}
+
dm_list_iterate_items(pvl, &vg->pvs) {
if (id_equal(&id, &pvl->pv->id))
return pvl->pv;
diff --git a/liblvm/lvm_vg.c b/liblvm/lvm_vg.c
index f087ba4..405a91a 100644
--- a/liblvm/lvm_vg.c
+++ b/liblvm/lvm_vg.c
@@ -56,7 +56,7 @@ vg_t lvm_vg_create(lvm_t libh, const char *vg_name)
vg = vg_create((struct cmd_context *)libh, vg_name);
/* FIXME: error handling is still TBD */
if (vg_read_error(vg)) {
- free_vg(vg);
+ release_vg(vg);
return NULL;
}
vg->open_mode = 'w';
@@ -79,7 +79,7 @@ int lvm_vg_extend(vg_t vg, const char *device)
}
pvcreate_params_set_defaults(&pp);
- if (!vg_extend(vg, 1, (char **) &device, &pp)) {
+ if (!vg_extend(vg, 1, &device, &pp)) {
unlock_vg(vg->cmd, VG_ORPHANS);
return -1;
}
@@ -98,7 +98,7 @@ int lvm_vg_reduce(vg_t vg, const char *device)
if (!vg_check_write_mode(vg))
return -1;
- if (!vg_reduce(vg, (char *)device))
+ if (!vg_reduce(vg, device))
return -1;
return 0;
}
@@ -147,6 +147,7 @@ int lvm_vg_write(vg_t vg)
if (! dm_list_empty(&vg->removed_pvs)) {
dm_list_iterate_items(pvl, &vg->removed_pvs) {
pv_write_orphan(vg->cmd, pvl->pv);
+ pv_set_fid(pvl->pv, NULL);
/* FIXME: do pvremove / label_remove()? */
}
dm_list_init(&vg->removed_pvs);
@@ -159,9 +160,9 @@ int lvm_vg_write(vg_t vg)
int lvm_vg_close(vg_t vg)
{
if (vg_read_error(vg) == FAILED_LOCKING)
- free_vg(vg);
+ release_vg(vg);
else
- unlock_and_free_vg(vg->cmd, vg, vg->name);
+ unlock_and_release_vg(vg->cmd, vg, vg->name);
return 0;
}
@@ -196,7 +197,7 @@ vg_t lvm_vg_open(lvm_t libh, const char *vgname, const char *mode,
vg = vg_read((struct cmd_context *)libh, vgname, NULL, internal_flags);
if (vg_read_error(vg)) {
/* FIXME: use log_errno either here in inside vg_read */
- free_vg(vg);
+ release_vg(vg);
return NULL;
}
/* FIXME: combine this with locking ? */