mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
91f737383c
Currently lvm2app properties have the following structure: typedef struct lvm_property_value { uint32_t is_settable:1; uint32_t is_string:1; uint32_t is_integer:1; uint32_t is_valid:1; uint32_t padding:28; union { const char *string; uint64_t integer; } value; } lvm_property_value_t; which assumes that numerical values were in the range of 0 to 2**64-1. However, some of the properties were 'signed', like LV major/minor numbers and some reserved values for properties that represent percentages. Thus when the values were retrieved they were in two's complement notation. So for a -1 major number the API user would get a value of 18446744073709551615. The API user could cast the returned value to an int64_t to handle this, but that requires the API developer to look at the source code and determine when it should be done. This change modifies the return property structure to: typedef struct lvm_property_value { uint32_t is_settable:1; uint32_t is_string:1; uint32_t is_integer:1; uint32_t is_valid:1; uint32_t is_signed:1; uint32_t padding:27; union { const char *string; uint64_t integer; int64_t signed_integer; } value; } lvm_property_value_t; With this addition the API user can interrogate that the value is numerical, (is_integer = 1) and subsequently check if it's signed (is_signed = 1) too. If signed, then the API developer should use the union's signed_integer to avoid casting. This change maintains backwards compatibility as the structure size remains unchanged and integer value remains unchanged. Only the additional bit taken from the pad is utilized. Bugzilla reference: https://bugzilla.redhat.com/show_bug.cgi?id=838257 Signed-off-by: Tony Asleson <tasleson@redhat.com>
75 lines
2.5 KiB
C
75 lines
2.5 KiB
C
/*
|
|
* Copyright (C) 2013 Red Hat, Inc. All rights reserved.
|
|
*
|
|
* This file is part of LVM2.
|
|
*
|
|
* This copyrighted material is made available to anyone wishing to use,
|
|
* modify, copy, or redistribute it subject to the terms and conditions
|
|
* of the GNU Lesser General Public License v.2.1.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include "lvm_prop.h"
|
|
#include "libdevmapper.h"
|
|
#include "metadata.h"
|
|
|
|
/* lv create parameters */
|
|
GET_LVCREATEPARAMS_NUM_PROPERTY_FN(skip_zero, lvcp->zero)
|
|
SET_LVCREATEPARAMS_NUM_PROPERTY_FN(skip_zero, lvcp->zero)
|
|
|
|
/* PV create parameters */
|
|
GET_PVCREATEPARAMS_NUM_PROPERTY_FN(size, pvcp->size)
|
|
SET_PVCREATEPARAMS_NUM_PROPERTY_FN(size, pvcp->size)
|
|
|
|
GET_PVCREATEPARAMS_NUM_PROPERTY_FN(pvmetadatacopies, pvcp->pvmetadatacopies)
|
|
SET_PVCREATEPARAMS_NUM_PROPERTY_FN(pvmetadatacopies, pvcp->pvmetadatacopies)
|
|
|
|
GET_PVCREATEPARAMS_NUM_PROPERTY_FN(pvmetadatasize, pvcp->pvmetadatasize)
|
|
SET_PVCREATEPARAMS_NUM_PROPERTY_FN(pvmetadatasize, pvcp->pvmetadatasize)
|
|
|
|
GET_PVCREATEPARAMS_NUM_PROPERTY_FN(data_alignment, pvcp->data_alignment)
|
|
SET_PVCREATEPARAMS_NUM_PROPERTY_FN(data_alignment, pvcp->data_alignment)
|
|
|
|
GET_PVCREATEPARAMS_NUM_PROPERTY_FN(data_alignment_offset, pvcp->data_alignment_offset)
|
|
SET_PVCREATEPARAMS_NUM_PROPERTY_FN(data_alignment_offset, pvcp->data_alignment_offset)
|
|
|
|
GET_PVCREATEPARAMS_NUM_PROPERTY_FN(zero, pvcp->zero)
|
|
SET_PVCREATEPARAMS_NUM_PROPERTY_FN(zero, pvcp->zero)
|
|
|
|
struct lvm_property_type _lib_properties[] = {
|
|
#include "lvm_prop_fields.h"
|
|
{ 0, "", 0, 0, 0, 0, { .integer = 0 }, prop_not_implemented_get,
|
|
prop_not_implemented_set },
|
|
};
|
|
|
|
#undef STR
|
|
#undef NUM
|
|
#undef FIELD
|
|
|
|
int lv_create_param_get_property(const struct lvcreate_params *lvcp,
|
|
struct lvm_property_type *prop)
|
|
{
|
|
return prop_get_property(_lib_properties, lvcp, prop, LV_CREATE_PARAMS);
|
|
}
|
|
|
|
int lv_create_param_set_property(struct lvcreate_params *lvcp,
|
|
struct lvm_property_type *prop)
|
|
{
|
|
return prop_set_property(_lib_properties, lvcp, prop, LV_CREATE_PARAMS);
|
|
}
|
|
|
|
int pv_create_param_get_property(const struct pvcreate_params *pvcp,
|
|
struct lvm_property_type *prop)
|
|
{
|
|
return prop_get_property(_lib_properties, pvcp, prop, PV_CREATE_PARAMS);
|
|
}
|
|
|
|
int pv_create_param_set_property(struct pvcreate_params *pvcp,
|
|
struct lvm_property_type *prop)
|
|
{
|
|
return prop_set_property(_lib_properties, pvcp, prop, PV_CREATE_PARAMS);
|
|
}
|