From: Tony Asleson Date: Tue, 10 Sep 2013 23:05:28 +0000 (-0500) Subject: python-lvm: Add addl. PV create arguments X-Git-Tag: v2_02_105~190 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=531d85a0ee3854e49f9b81658dd6d7c60bb4de86;p=lvm2.git python-lvm: Add addl. PV create arguments Added overloaded PV create arguments with defaults for PV creation. Addresses bug: https://bugzilla.redhat.com/show_bug.cgi?id=880395 Signed-off-by: Tony Asleson --- diff --git a/python/liblvm.c b/python/liblvm.c index 36b64e4e7..033de820c 100644 --- a/python/liblvm.c +++ b/python/liblvm.c @@ -23,6 +23,7 @@ #include #include "lvm2app.h" +#include "defaults.h" static lvm_t _libh; @@ -317,24 +318,62 @@ static PyObject *_liblvm_lvm_pv_remove(PyObject *self, PyObject *arg) return Py_None; } +static int _set_pv_numeric_prop(pv_create_params_t pv_params, const char *name, + unsigned long long value) +{ + struct lvm_property_value prop_value; + prop_value.is_integer = 1; + prop_value.value.integer = value; + + return lvm_pv_params_set_property(pv_params, name, &prop_value); +} + +#define SET_PV_PROP(params, name, value) \ + do { \ + if (_set_pv_numeric_prop(params, name, value) == -1) \ + goto error; \ + } while(0)\ + static PyObject *_liblvm_lvm_pv_create(PyObject *self, PyObject *arg) { const char *pv_name; - unsigned long long size; + unsigned long long size = 0; + unsigned long long pvmetadatacopies = DEFAULT_PVMETADATACOPIES; + unsigned long long pvmetadatasize = DEFAULT_PVMETADATASIZE; + unsigned long long data_alignment = 0; + unsigned long long data_alignment_offset = 0; + unsigned long long zero = 1; + pv_create_params_t pv_params = NULL; LVM_VALID(NULL); - if (!PyArg_ParseTuple(arg, "sK", &pv_name, &size)) + if (!PyArg_ParseTuple(arg, "s|KKKKKK", &pv_name, &size, &pvmetadatacopies, + &pvmetadatasize, &data_alignment, + &data_alignment_offset, &zero)) return NULL; - if (lvm_pv_create(_libh, pv_name, size) == -1) { - PyErr_SetObject(_LibLVMError, _liblvm_get_last_error()); - return NULL; + pv_params = lvm_pv_params_create(_libh, pv_name); + if (!pv_params) { + goto error; } - Py_INCREF(Py_None); + SET_PV_PROP(pv_params, "size", size); + SET_PV_PROP(pv_params, "pvmetadatacopies", pvmetadatacopies); + SET_PV_PROP(pv_params, "pvmetadatasize", pvmetadatasize); + SET_PV_PROP(pv_params, "data_alignment", data_alignment); + SET_PV_PROP(pv_params, "data_alignment_offset", data_alignment_offset); + SET_PV_PROP(pv_params, "zero", zero); + + if (lvm_pv_create_adv(pv_params)) { + goto error; + } + Py_INCREF(Py_None); return Py_None; + +error: + PyErr_SetObject(_LibLVMError, _liblvm_get_last_error()); + return NULL; } static PyObject *_liblvm_lvm_percent_to_float(PyObject *self, PyObject *arg)