Skip to contentSkip to conversation

LVM2 lib/report/properties.c liblvm/lvm2app.h ...

PATCH [email protected] 1 participant 1 message Dec 14, 2010

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: mornfall at sourceware.org 2010-12-14 23:20:59

Modified files:
lib/report : properties.c
liblvm : lvm2app.h lvm_base.c lvm_lv.c lvm_misc.c
lvm_misc.h lvm_pv.c lvm_vg.c
test/api : Makefile.in
Added files:
test/api : percent.c percent.sh

Log message:
Add getters for copy_percent and snap_percent to the lvm2app API.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/properties.c.diff?cvsroot=lvm2&r1=1.26&r2=1.27
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm2app.h.diff?cvsroot=lvm2&r1=1.30&r2=1.31
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_base.c.diff?cvsroot=lvm2&r1=1.18&r2=1.19
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_lv.c.diff?cvsroot=lvm2&r1=1.33&r2=1.34
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_misc.c.diff?cvsroot=lvm2&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_misc.h.diff?cvsroot=lvm2&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_pv.c.diff?cvsroot=lvm2&r1=1.19&r2=1.20
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_vg.c.diff?cvsroot=lvm2&r1=1.49&r2=1.50
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/percent.c.diff?cvsroot=lvm2&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/percent.sh.diff?cvsroot=lvm2&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/api/Makefile.in.diff?cvsroot=lvm2&r1=1.18&r2=1.19

lib/report/properties.c +15 -2
@@ -16,6 +16,7 @@
 
 #include "libdevmapper.h"
 #include "properties.h"
+#include "activate.h"
 #include "lvm-logging.h"
 #include "lvm-types.h"
 #include "metadata.h"
@@ -85,6 +86,18 @@
 	return 0;
 }
 
+static percent_t _copy_percent(const struct logical_volume *lv) {
+    percent_t perc;
+    lv_mirror_percent(lv->vg->cmd, (struct logical_volume *) lv, 0, &perc, NULL);
+    return perc;
+}
+
+static percent_t _snap_percent(const struct logical_volume *lv) {
+    percent_t perc;
+    lv_snapshot_percent(lv, &perc);
+    return perc;
+}
+
 /* PV */
 GET_PV_STR_PROPERTY_FN(pv_fmt, pv_fmt_dup(pv))
 #define _pv_fmt_set _not_implemented_set
@@ -148,9 +161,9 @@
 #define _origin_set _not_implemented_set
 GET_LV_NUM_PROPERTY_FN(origin_size, lv_origin_size(lv))
 #define _origin_size_set _not_implemented_set
-#define _snap_percent_get _not_implemented_get
+GET_LV_NUM_PROPERTY_FN(snap_percent, _snap_percent(lv))
 #define _snap_percent_set _not_implemented_set
-#define _copy_percent_get _not_implemented_get
+GET_LV_NUM_PROPERTY_FN(copy_percent, _copy_percent(lv))
 #define _copy_percent_set _not_implemented_set
 GET_LV_STR_PROPERTY_FN(move_pv, lv_move_pv_dup(lv->vg->vgmem, lv))
 #define _move_pv_set _not_implemented_set
liblvm/lvm2app.h +28 -2
@@ -1446,8 +1446,10 @@
  * Name of property to query.  See pvs man page for full list of properties
  * that may be queried.
  *
- * The memory allocated for a string property value is tied to the vg_t
- * handle and will be released when lvm_vg_close() is called.
+ * The memory allocated for a string property value is tied to the vg_t handle
+ * and will be released when lvm_vg_close() is called. For "percent" values
+ * (those obtained for copy_percent and snap_percent properties), please see
+ * percent_range_t and lvm_percent_to_float().
  *
  * Example:
  *      lvm_property_value value;
@@ -1578,6 +1580,30 @@
  */
 int lvm_pv_resize(const pv_t pv, uint64_t new_size);
 
+#ifndef _LVM_PERCENT_H
+
+/**
+ * This type defines a couple of special percent values. The PERCENT_0 and
+ * PERCENT_100 constants designate *exact* percentages: values are never
+ * rounded to either of these two.
+ */
+typedef enum {
+	PERCENT_0 = 0,
+	PERCENT_1 = 1000000,
+	PERCENT_100 = 100 * PERCENT_1,
+	PERCENT_INVALID = -1
+} percent_range_t;
+
+typedef int32_t percent_t;
+
+#endif
+
+/**
+ * Convert a (fixed-point) value obtained from the percent-denominated
+ * *_get_property functions into a floating-point value.
+ */
+float lvm_percent_to_float(percent_t v);
+
 #ifdef __cplusplus
 }
 #endif
liblvm/lvm_base.c +1 -1
@@ -13,11 +13,11 @@
  */
 
 #include "lib.h"
-#include "lvm2app.h"
 #include "toolcontext.h"
 #include "locking.h"
 #include "lvm-version.h"
 #include "metadata-exported.h"
+#include "lvm2app.h"
 
 const char *lvm_library_get_version(void)
 {
liblvm/lvm_lv.c +1 -1
@@ -13,7 +13,6 @@
  */
 
 #include "lib.h"
-#include "lvm2app.h"
 #include "metadata.h"
 #include "lvm-string.h"
 #include "defaults.h"
@@ -21,6 +20,7 @@
 #include "locking.h"
 #include "activate.h"
 #include "lvm_misc.h"
+#include "lvm2app.h"
 
 static int _lv_check_handle(const lv_t lv, const int vg_writeable)
 {
liblvm/lvm_misc.c +2 -2
@@ -12,10 +12,10 @@
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "lvm2app.h"
-#include "lvm_misc.h"
 #include "lib.h"
 #include "properties.h"
+#include "lvm_misc.h"
+#include "lvm2app.h"
 
 struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list)
 {
liblvm/lvm_misc.h +1 -0
@@ -15,6 +15,7 @@
 #define _LVM2APP_MISC_H
 
 #include "libdevmapper.h"
+#include "lvm2app.h"
 
 struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list);
 struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
liblvm/lvm_pv.c +1 -1
@@ -13,10 +13,10 @@
  */
 
 #include "lib.h"
-#include "lvm2app.h"
 #include "metadata.h"
 #include "lvm-string.h"
 #include "lvm_misc.h"
+#include "lvm2app.h"
 
 const char *lvm_pv_get_uuid(const pv_t pv)
 {
liblvm/lvm_vg.c +1 -1
@@ -13,13 +13,13 @@
  */
 
 #include "lib.h"
-#include "lvm2app.h"
 #include "toolcontext.h"
 #include "metadata.h"
 #include "archiver.h"
 #include "locking.h"
 #include "lvmcache.h"
 #include "lvm_misc.h"
+#include "lvm2app.h"
 
 int lvm_vg_add_tag(vg_t vg, const char *tag)
 {

/cvs/lvm2/LVM2/test/api/percent.c,v --> standard output revision 1.1

- renamed from test/api/percent.c +45 -0

45 lines not on this page · raw message

/cvs/lvm2/LVM2/test/api/percent.sh,v --> standard output revision 1.1

- renamed from test/api/percent.sh +10 -0
@@ -0,0 +1,10 @@
+. ./test-utils.sh
+aux prepare_devs 2
+vgcreate -c n -s 4k $vg $devs
+lvcreate -n foo $vg -l 5
+lvcreate -s -n snap $vg/foo -l 2 -c 4k
+lvcreate -s -n snap2 $vg/foo -l 6 -c 4k
+dd if=/dev/urandom of=$DM_DEV_DIR/$vg/snap2 count=1 bs=1024
+lvcreate -m 1 -n mirr $vg -l 1 --mirrorlog core
+lvs
+apitest percent $vg
test/api/Makefile.in +1 -1
@@ -24,7 +24,7 @@
 wrapper_SOURCES = test.c
 INCLUDES += -I../../include
 
-UNIT = vgtest.t
+UNIT = vgtest.t percent.t
 
 LVMLIBS = @LVM2APP_LIB@ -ldevmapper
 DEPLIBS = $(top_builddir)/liblvm/liblvm2app.so $(top_builddir)/libdm/libdevmapper.so