mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-24 17:57:48 +03:00
Update liblvm status return codes to be consistent.
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>
This commit is contained in:
parent
648fa396d9
commit
f864285b3a
16
liblvm/lvm.h
16
liblvm/lvm.h
@ -144,6 +144,7 @@ void lvm_destroy(lvm_t libh);
|
||||
*
|
||||
* \param libh
|
||||
* Handle obtained from lvm_create.
|
||||
* \return 0 (success) or -1 (failure).
|
||||
*/
|
||||
int lvm_reload_config(lvm_t libh);
|
||||
|
||||
@ -174,7 +175,7 @@ const char *lvm_errmsg(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);
|
||||
|
||||
@ -217,6 +218,7 @@ struct dm_list *lvm_list_vg_names(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);
|
||||
|
||||
@ -268,7 +270,7 @@ vg_t *lvm_vg_create(lvm_t libh, const char *vg_name);
|
||||
*
|
||||
* \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);
|
||||
|
||||
@ -280,7 +282,7 @@ 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);
|
||||
|
||||
@ -291,7 +293,7 @@ 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);
|
||||
|
||||
@ -311,7 +313,7 @@ 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);
|
||||
|
||||
@ -327,7 +329,7 @@ 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);
|
||||
|
||||
@ -452,7 +454,7 @@ lv_t *lvm_vg_create_lv_linear(vg_t *vg, const char *name, uint64_t 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);
|
||||
|
||||
|
@ -61,14 +61,15 @@ lvm_t lvm_create(const char *system_dir)
|
||||
|
||||
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)
|
||||
|
@ -99,6 +99,8 @@ lv_t *lvm_vg_create_lv_linear(vg_t *vg, const char *name, uint64_t size)
|
||||
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;
|
||||
}
|
||||
|
@ -41,11 +41,11 @@ vg_t *lvm_vg_create(lvm_t libh, const char *vg_name)
|
||||
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 */
|
||||
@ -53,46 +53,42 @@ int lvm_vg_extend(vg_t *vg, const char *device)
|
||||
(!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;
|
||||
}
|
||||
|
||||
@ -102,16 +98,16 @@ int lvm_vg_close(vg_t *vg)
|
||||
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;
|
||||
}
|
||||
|
||||
@ -254,5 +250,7 @@ struct dm_list *lvm_list_vg_uuids(lvm_t libh)
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user