]> sourceware.org Git - lvm2.git/commitdiff
Add generic infrastructure to internal library to 'set' a property.
authorPetr Rockai <prockai@redhat.com>
Wed, 17 Nov 2010 19:15:10 +0000 (19:15 +0000)
committerPetr Rockai <prockai@redhat.com>
Wed, 17 Nov 2010 19:15:10 +0000 (19:15 +0000)
Similar to 'get' property internal functions.
Add specific 'set' function for vg_mda_copies.

Signed-off-by: Dave Wysochanski <wysochanski@pobox.com>
Reviewed-by: Petr Rockai <prockai@redhat.com>
lib/report/columns.h
lib/report/properties.c
lib/report/properties.h

index 689f6a55f76c12815d70a2edecea63d1e793b4c4..acc232f28b07c8505afc2f647357281bacbdec10 100644 (file)
@@ -121,7 +121,7 @@ FIELD(VGS, vg, NUM, "#VMda", cmd, 5, vgmdas, vg_mda_count, "Number of metadata a
 FIELD(VGS, vg, NUM, "#VMdaUse", cmd, 8, vgmdasused, vg_mda_used_count, "Number of metadata areas in use on this VG.", 0)
 FIELD(VGS, vg, NUM, "VMdaFree", cmd, 9, vgmdafree, vg_mda_free, "Free metadata area space for this VG in current units.", 0)
 FIELD(VGS, vg, NUM, "VMdaSize", cmd, 9, vgmdasize, vg_mda_size, "Size of smallest metadata area for this VG in current units.", 0)
-FIELD(VGS, vg, NUM, "#VMdaCps", cmd, 8, vgmdacopies, vg_mda_copies, "Target number of in use metadata areas in the VG.", 0)
+FIELD(VGS, vg, NUM, "#VMdaCps", cmd, 8, vgmdacopies, vg_mda_copies, "Target number of in use metadata areas in the VG.", 1)
 
 FIELD(SEGS, seg, STR, "Type", list, 4, segtype, segtype, "Type of LV segment.", 0)
 FIELD(SEGS, seg, NUM, "#Str", area_count, 4, uint32, stripes, "Number of stripes or mirror legs.", 0)
index 339fd847a7eb4478e427062f349c26bf15835ac3..d814afe7630c2aae7b7f27d166ac08daba0a1ecf 100644 (file)
@@ -35,6 +35,21 @@ static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
 #define GET_LV_NUM_PROPERTY_FN(NAME, VALUE) \
        GET_NUM_PROPERTY_FN(NAME, VALUE, logical_volume, lv)
 
+#define SET_NUM_PROPERTY_FN(NAME, SETFN, TYPE, VAR)                    \
+static int _ ## NAME ## _set (void *obj, struct lvm_property_type *prop) \
+{ \
+       struct TYPE *VAR = (struct TYPE *)obj; \
+\
+       SETFN(VAR, prop->value.integer);                \
+       return 1; \
+}
+#define SET_VG_NUM_PROPERTY_FN(NAME, SETFN) \
+       SET_NUM_PROPERTY_FN(NAME, SETFN, volume_group, vg)
+#define SET_PV_NUM_PROPERTY_FN(NAME, SETFN) \
+       SET_NUM_PROPERTY_FN(NAME, SETFN, physical_volume, pv)
+#define SET_LV_NUM_PROPERTY_FN(NAME, SETFN) \
+       SET_NUM_PROPERTY_FN(NAME, SETFN, logical_volume, lv)
+
 #define GET_STR_PROPERTY_FN(NAME, VALUE, TYPE, VAR)                    \
 static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \
 { \
@@ -184,7 +199,7 @@ GET_VG_NUM_PROPERTY_FN(vg_mda_free, (SECTOR_SIZE * vg_mda_free(vg)))
 GET_VG_NUM_PROPERTY_FN(vg_mda_size, (SECTOR_SIZE * vg_mda_size(vg)))
 #define _vg_mda_size_set _not_implemented_set
 GET_VG_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg)))
-#define _vg_mda_copies_set _not_implemented_set
+SET_VG_NUM_PROPERTY_FN(vg_mda_copies, vg_set_mda_copies)
 
 /* LVSEG */
 #define _segtype_get _not_implemented_get
@@ -267,6 +282,42 @@ static int _get_property(const void *obj, struct lvm_property_type *prop,
        return 1;
 }
 
+static int _set_property(void *obj, struct lvm_property_type *prop,
+                        report_type_t type)
+{
+       struct lvm_property_type *p;
+
+       p = _properties;
+       while (p->id[0]) {
+               if (!strcmp(p->id, prop->id))
+                       break;
+               p++;
+       }
+       if (!p->id[0]) {
+               log_errno(EINVAL, "Invalid property name %s", prop->id);
+               return 0;
+       }
+       if (!p->is_settable) {
+               log_errno(EINVAL, "Unable to set read-only property %s",
+                         prop->id);
+               return 0;
+       }
+       if (!(p->type & type)) {
+               log_errno(EINVAL, "Property name %s does not match type %d",
+                         prop->id, p->type);
+               return 0;
+       }
+
+       if (p->is_string)
+               p->value.string = prop->value.string;
+       else
+               p->value.integer = prop->value.integer;
+       if (!p->set(obj, p)) {
+               return 0;
+       }
+       return 1;
+}
+
 int lv_get_property(const struct logical_volume *lv,
                    struct lvm_property_type *prop)
 {
@@ -284,3 +335,21 @@ int pv_get_property(const struct physical_volume *pv,
 {
        return _get_property(pv, prop, PVS | LABEL);
 }
+
+int lv_set_property(struct logical_volume *lv,
+                   struct lvm_property_type *prop)
+{
+       return _set_property(lv, prop, LVS);
+}
+
+int vg_set_property(struct volume_group *vg,
+                   struct lvm_property_type *prop)
+{
+       return _set_property(vg, prop, VGS);
+}
+
+int pv_set_property(struct physical_volume *pv,
+                   struct lvm_property_type *prop)
+{
+       return _set_property(pv, prop, PVS | LABEL);
+}
index 054f4007f50476b23c0935b5e0b615ef079fb2c1..7756cbeb564b49e9bb4cb5e7e528e864dd5d40e5 100644 (file)
@@ -39,5 +39,11 @@ int vg_get_property(const struct volume_group *vg,
                    struct lvm_property_type *prop);
 int pv_get_property(const struct physical_volume *pv,
                    struct lvm_property_type *prop);
+int lv_set_property(struct logical_volume *lv,
+                   struct lvm_property_type *prop);
+int vg_set_property(struct volume_group *vg,
+                   struct lvm_property_type *prop);
+int pv_set_property(struct physical_volume *pv,
+                   struct lvm_property_type *prop);
 
 #endif
This page took 0.038555 seconds and 5 git commands to generate.