mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
python: update coding style
Update code to match lvm coding standards Disable/skip test - since it's accessing VGs available in the system. Before reenable - validate it's not touching any PV outside those created during test.
This commit is contained in:
parent
7319bc0420
commit
9e79cca9e7
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2008,2009 Red Hat, Inc. All rights reserved.
|
* Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* This file is part of LVM2.
|
* This file is part of LVM2.
|
||||||
*
|
*
|
||||||
@ -28,8 +28,7 @@ const char *lvm_pv_get_uuid(const pv_t pv)
|
|||||||
|
|
||||||
const char *lvm_pv_get_name(const pv_t pv)
|
const char *lvm_pv_get_name(const pv_t pv)
|
||||||
{
|
{
|
||||||
return dm_pool_strndup(pv->vg->vgmem,
|
return dm_pool_strndup(pv->vg->vgmem, pv_dev_name(pv), NAME_LEN);
|
||||||
(const char *)pv_dev_name(pv), NAME_LEN + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t lvm_pv_get_mda_count(const pv_t pv)
|
uint64_t lvm_pv_get_mda_count(const pv_t pv)
|
||||||
@ -39,17 +38,17 @@ uint64_t lvm_pv_get_mda_count(const pv_t pv)
|
|||||||
|
|
||||||
uint64_t lvm_pv_get_dev_size(const pv_t pv)
|
uint64_t lvm_pv_get_dev_size(const pv_t pv)
|
||||||
{
|
{
|
||||||
return (uint64_t) SECTOR_SIZE * pv_dev_size(pv);
|
return SECTOR_SIZE * pv_dev_size(pv);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t lvm_pv_get_size(const pv_t pv)
|
uint64_t lvm_pv_get_size(const pv_t pv)
|
||||||
{
|
{
|
||||||
return (uint64_t) SECTOR_SIZE * pv_size_field(pv);
|
return SECTOR_SIZE * pv_size_field(pv);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t lvm_pv_get_free(const pv_t pv)
|
uint64_t lvm_pv_get_free(const pv_t pv)
|
||||||
{
|
{
|
||||||
return (uint64_t) SECTOR_SIZE * pv_free(pv);
|
return SECTOR_SIZE * pv_free(pv);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
|
struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
|
||||||
@ -63,11 +62,6 @@ struct lvm_property_value lvm_pvseg_get_property(const pvseg_t pvseg,
|
|||||||
return get_property(NULL, NULL, NULL, NULL, pvseg, NULL, name);
|
return get_property(NULL, NULL, NULL, NULL, pvseg, NULL, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define address_of(p, t, m) ({ \
|
|
||||||
const typeof( ((t *)0)->m ) *__mptr = (p); \
|
|
||||||
(t *)( (char *)__mptr - offsetof(t,m) );})
|
|
||||||
|
|
||||||
struct lvm_list_wrapper
|
struct lvm_list_wrapper
|
||||||
{
|
{
|
||||||
unsigned long magic;
|
unsigned long magic;
|
||||||
@ -78,9 +72,10 @@ struct lvm_list_wrapper
|
|||||||
int lvm_pv_remove(lvm_t libh, const char *pv_name)
|
int lvm_pv_remove(lvm_t libh, const char *pv_name)
|
||||||
{
|
{
|
||||||
struct cmd_context *cmd = (struct cmd_context *)libh;
|
struct cmd_context *cmd = (struct cmd_context *)libh;
|
||||||
if ( 1 != pvremove_single(cmd, pv_name, NULL, 0, 0)) {
|
|
||||||
|
if (pvremove_single(cmd, pv_name, NULL, 0, 0) != 1)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,9 +84,7 @@ struct dm_list *lvm_list_pvs(lvm_t libh)
|
|||||||
struct lvm_list_wrapper *rc = NULL;
|
struct lvm_list_wrapper *rc = NULL;
|
||||||
struct cmd_context *cmd = (struct cmd_context *)libh;
|
struct cmd_context *cmd = (struct cmd_context *)libh;
|
||||||
|
|
||||||
|
if (!(rc = dm_pool_zalloc(cmd->mem, sizeof(*rc)))) {
|
||||||
rc = dm_pool_zalloc(cmd->mem, sizeof(*rc));
|
|
||||||
if (!rc) {
|
|
||||||
log_errno(ENOMEM, "Memory allocation fail for pv list.");
|
log_errno(ENOMEM, "Memory allocation fail for pv list.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -113,36 +106,33 @@ struct dm_list *lvm_list_pvs(lvm_t libh)
|
|||||||
|
|
||||||
int lvm_list_pvs_free(struct dm_list *pvlist)
|
int lvm_list_pvs_free(struct dm_list *pvlist)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
struct lvm_list_wrapper *to_delete;
|
||||||
struct lvm_list_wrapper *to_delete = NULL;
|
struct vg_list *vgl;
|
||||||
struct vg_list *vgl = NULL;
|
struct pv_list *pvl;
|
||||||
struct pv_list *pvl = NULL;
|
|
||||||
struct cmd_context *cmd = NULL;
|
struct cmd_context *cmd = NULL;
|
||||||
|
|
||||||
if (pvlist) {
|
if (pvlist) {
|
||||||
to_delete = address_of(pvlist, struct lvm_list_wrapper, pvslist);
|
to_delete = dm_list_struct_base(pvlist, struct lvm_list_wrapper, pvslist);
|
||||||
if (to_delete->magic == 0xF005BA11) {
|
if (to_delete->magic != 0xF005BA11) {
|
||||||
|
log_errno(EINVAL, "Not a correct pvlist structure");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
dm_list_iterate_items(vgl, &to_delete->vgslist) {
|
dm_list_iterate_items(vgl, &to_delete->vgslist) {
|
||||||
cmd = vgl->vg->cmd;
|
cmd = vgl->vg->cmd;
|
||||||
release_vg(vgl->vg);
|
release_vg(vgl->vg);
|
||||||
}
|
}
|
||||||
|
|
||||||
dm_list_iterate_items(pvl, &to_delete->pvslist) {
|
dm_list_iterate_items(pvl, &to_delete->pvslist)
|
||||||
free_pv_fid(pvl->pv);
|
free_pv_fid(pvl->pv);
|
||||||
}
|
|
||||||
|
|
||||||
unlock_vg(cmd, VG_GLOBAL);
|
unlock_vg(cmd, VG_GLOBAL);
|
||||||
} else {
|
|
||||||
log_errno(EINVAL, "Not a correct pvlist structure");
|
|
||||||
rc = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
to_delete->magic = 0xA5A5A5A5;
|
to_delete->magic = 0xA5A5A5A5;
|
||||||
dm_pool_free(cmd->mem, to_delete);
|
dm_pool_free(cmd->mem, to_delete);
|
||||||
|
|
||||||
}
|
}
|
||||||
return rc;
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
|
struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
|
||||||
@ -158,6 +148,7 @@ struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
|
|||||||
log_errno(ENOMEM, "Memory allocation fail for dm_list.");
|
log_errno(ENOMEM, "Memory allocation fail for dm_list.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dm_list_init(list);
|
dm_list_init(list);
|
||||||
|
|
||||||
dm_list_iterate_items(pvl, &pv->segments) {
|
dm_list_iterate_items(pvl, &pv->segments) {
|
||||||
@ -169,6 +160,7 @@ struct dm_list *lvm_pv_list_pvsegs(pv_t pv)
|
|||||||
pvseg->pvseg = pvl;
|
pvseg->pvseg = pvl;
|
||||||
dm_list_add(list, &pvseg->list);
|
dm_list_add(list, &pvseg->list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,10 +168,10 @@ pv_t lvm_pv_from_name(vg_t vg, const char *name)
|
|||||||
{
|
{
|
||||||
struct pv_list *pvl;
|
struct pv_list *pvl;
|
||||||
|
|
||||||
dm_list_iterate_items(pvl, &vg->pvs) {
|
dm_list_iterate_items(pvl, &vg->pvs)
|
||||||
if (!strcmp(name, pv_dev_name(pvl->pv)))
|
if (!strcmp(name, pv_dev_name(pvl->pv)))
|
||||||
return pvl->pv;
|
return pvl->pv;
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,14 +190,13 @@ pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dm_list_iterate_items(pvl, &vg->pvs) {
|
dm_list_iterate_items(pvl, &vg->pvs)
|
||||||
if (id_equal(&id, &pvl->pv->id))
|
if (id_equal(&id, &pvl->pv->id))
|
||||||
return pvl->pv;
|
return pvl->pv;
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lvm_pv_resize(const pv_t pv, uint64_t new_size)
|
int lvm_pv_resize(const pv_t pv, uint64_t new_size)
|
||||||
{
|
{
|
||||||
uint64_t size = new_size >> SECTOR_SHIFT;
|
uint64_t size = new_size >> SECTOR_SHIFT;
|
||||||
@ -215,21 +206,19 @@ int lvm_pv_resize(const pv_t pv, uint64_t new_size)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vg_check_write_mode(pv->vg)) {
|
if (!vg_check_write_mode(pv->vg))
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (!pv_resize_single(pv->vg->cmd, pv->vg, pv, size)) {
|
if (!pv_resize_single(pv->vg->cmd, pv->vg, pv, size)) {
|
||||||
log_error("PV re-size failed!");
|
log_error("PV re-size failed!");
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size)
|
int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size)
|
||||||
{
|
{
|
||||||
int rc = -1;
|
|
||||||
struct pvcreate_params pp;
|
struct pvcreate_params pp;
|
||||||
struct cmd_context *cmd = (struct cmd_context *)libh;
|
struct cmd_context *cmd = (struct cmd_context *)libh;
|
||||||
uint64_t size_sectors = size;
|
uint64_t size_sectors = size;
|
||||||
@ -246,9 +235,8 @@ int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size)
|
|||||||
|
|
||||||
pp.size = size_sectors;
|
pp.size = size_sectors;
|
||||||
|
|
||||||
if (ECMD_PROCESSED == pvcreate_locked(cmd, pv_name, &pp)) {
|
if (pvcreate_locked(cmd, pv_name, &pp) != ECMD_PROCESSED)
|
||||||
rc = 0;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,16 @@ aux prepare_pvs 6
|
|||||||
|
|
||||||
#Locate the python binding library to use.
|
#Locate the python binding library to use.
|
||||||
python_lib=`find $abs_top_builddir -name lvm.so`
|
python_lib=`find $abs_top_builddir -name lvm.so`
|
||||||
if [ "$python_lib" != "" ]
|
|
||||||
then
|
# Unable to test python bindings if library not available
|
||||||
|
test -z "$python_lib" && skip
|
||||||
|
|
||||||
export PYTHONPATH=`dirname $python_lib`:$PYTHONPATH
|
export PYTHONPATH=`dirname $python_lib`:$PYTHONPATH
|
||||||
|
|
||||||
|
skip
|
||||||
|
|
||||||
|
# skiped until fixed
|
||||||
|
# FIXME - script must ONLY use $(cat DEVICES) as PVs
|
||||||
|
# it must NOT create/modify/remove volumes from other places
|
||||||
python_lvm_unit.py -v
|
python_lvm_unit.py -v
|
||||||
# nemiver python ../api/python_lvm_unit.py -v -f
|
# nemiver python ../api/python_lvm_unit.py -v -f
|
||||||
else
|
|
||||||
echo "Unable to test python bindings as library not available"
|
|
||||||
fi
|
|
||||||
|
Loading…
Reference in New Issue
Block a user