For now, we use the following scheme.
For APIs that return an int, success is 0, fail is -1.
APIs that return handles, success is non-NULL, fail is NULL.
At this early stage, liblvm error handling mechanism is subject to change,
but for now we go with this simple scheme consistent with system
programming.
Author: Dave Wysochanski <dwysocha@redhat.com>
*
* \param libh
* Handle obtained from lvm_create.
+ * \return 0 (success) or -1 (failure).
*/
int lvm_reload_config(lvm_t libh);
/**
* Scan all devices on the system for VGs and LVM metadata.
*
- * \return Status code of 1 (success) or 0 (failure).
+ * \return 0 (success) or -1 (failure).
*/
int lvm_scan(lvm_t libh);
* Handle obtained from lvm_create.
*
* \return List of copied uuid strings.
+ * If no VGs exist on the system, NULL is returned.
*/
struct dm_list *lvm_list_vg_uuids(lvm_t libh);
*
* \param vg
* VG handle obtained from lvm_vg_create or lvm_vg_open.
- * \return Status code of 1 (success) or 0 (failure).
+ * \return 0 (success) or -1 (failure).
*/
int lvm_vg_write(vg_t *vg);
*
* \param vg
* VG handle obtained from lvm_vg_create or lvm_vg_open.
- * \return Status code of 1 (success) or 0 (failure).
+ * \return 0 (success) or -1 (failure).
*/
int lvm_vg_remove(vg_t *vg);
*
* \param vg
* VG handle obtained from lvm_vg_create or lvm_vg_open.
- * \return Status code of 1 (success) or 0 (failure).
+ * \return 0 (success) or -1 (failure).
*/
int lvm_vg_close(vg_t *vg);
* VG handle obtained from lvm_vg_create or lvm_vg_open.
* \param device
* Name of device to add to VG.
- * \return Status code of 1 (success) or 0 (failure).
+ * \return 0 (success) or -1 (failure).
*/
int lvm_vg_extend(vg_t *vg, const char *device);
* VG handle obtained from lvm_vg_create or lvm_vg_open.
* \param new_size
* New extent size in bytes.
- * \return Status code of 1 (success) or 0 (failure).
+ * \return 0 (success) or -1 (failure).
*/
int lvm_vg_set_extent_size(vg_t *vg, uint32_t new_size);
*
* \param lv
* Logical volume handle.
- * \return Status code of 1 (success) or 0 (failure).
+ * \return 0 (success) or -1 (failure).
*/
int lvm_vg_remove_lv(lv_t *lv);
void lvm_destroy(lvm_t libh)
{
- /* FIXME: error handling */
destroy_toolcontext((struct cmd_context *)libh);
}
int lvm_reload_config(lvm_t libh)
{
/* FIXME: re-init locking needed here? */
- return refresh_toolcontext((struct cmd_context *)libh);
+ if (refresh_toolcontext((struct cmd_context *)libh))
+ return -1;
+ return 0;
}
int lvm_errno(lvm_t libh)
int lvm_vg_remove_lv(lv_t *lv)
{
if (!lv || !lv->vg || vg_read_error(lv->vg))
- return 0;
- return lv_remove_single(lv->vg->cmd, lv, DONT_PROMPT);
+ return -1;
+ if (!lv_remove_single(lv->vg->cmd, lv, DONT_PROMPT))
+ return -1;
+ return 0;
}
int lvm_vg_extend(vg_t *vg, const char *device)
{
if (vg_read_error(vg))
- return 0;
+ return -1;
if (!lock_vol(vg->cmd, VG_ORPHANS, LCK_VG_WRITE)) {
log_error("Can't get lock for orphan PVs");
- return 0;
+ return -1;
}
/* If device not initialized, pvcreate it */
(!pvcreate_single(vg->cmd, device, NULL))) {
log_error("Unable to initialize device for LVM use\n");
unlock_vg(vg->cmd, VG_ORPHANS);
- return 0;
+ return -1;
}
if (!vg_extend(vg, 1, (char **) &device)) {
unlock_vg(vg->cmd, VG_ORPHANS);
- return 0;
+ return -1;
}
/*
* FIXME: Either commit to disk, or keep holding VG_ORPHANS and
* release in lvm_vg_close().
*/
unlock_vg(vg->cmd, VG_ORPHANS);
- return 1;
+ return 0;
}
int lvm_vg_set_extent_size(vg_t *vg, uint32_t new_size)
{
if (vg_read_error(vg))
- goto_bad;
+ return -1;
- return vg_set_extent_size(vg, new_size);
-bad:
+ if (!vg_set_extent_size(vg, new_size))
+ return -1;
return 0;
}
int lvm_vg_write(vg_t *vg)
{
if (vg_read_error(vg))
- goto_bad;
+ return -1;
- if (!archive(vg)) {
- goto_bad;
- }
+ if (!archive(vg))
+ return -1;
/* Store VG on disk(s) */
- if (!vg_write(vg) || !vg_commit(vg)) {
- goto_bad;
- }
- return 1;
-bad:
+ if (!vg_write(vg) || !vg_commit(vg))
+ return -1;
return 0;
}
vg_release(vg);
else
unlock_and_release_vg(vg->cmd, vg, vg->name);
- return 1;
+ return 0;
}
int lvm_vg_remove(vg_t *vg)
{
if (vg_read_error(vg))
- goto_bad;
+ return -1;
- return vg_remove_single(vg);
-bad:
+ if (!vg_remove_single(vg))
+ return -1;
return 0;
}
int lvm_scan(lvm_t libh)
{
- return lvmcache_label_scan((struct cmd_context *)libh, 2);
+ if (!lvmcache_label_scan((struct cmd_context *)libh, 2))
+ return -1;
+ return 0;
}