]> sourceware.org Git - lvm2.git/commitdiff
Const fixing
authorZdenek Kabelac <zkabelac@redhat.com>
Fri, 18 Feb 2011 14:47:28 +0000 (14:47 +0000)
committerZdenek Kabelac <zkabelac@redhat.com>
Fri, 18 Feb 2011 14:47:28 +0000 (14:47 +0000)
Fixing some const warnings - with API change in:

int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names,

Change is needed - as lvm2api expects const behaviour here.
So vg_extend() is doing local strdup for unescaping.

skip_dev_dir return const char* from const char* vg_name.

Rest of the patch is cleanup of related warnings.

Also using dm_report_filed_string() API change to simplify
casting in _string_disp and _lvname_disp.

26 files changed:
WHATS_NEW
daemons/clvmd/clvmd.c
daemons/clvmd/clvmd.h
lib/activate/activate.c
lib/activate/activate.h
lib/filters/filter-regex.c
lib/metadata/lv.h
lib/metadata/lv_manip.c
lib/metadata/metadata-exported.h
lib/metadata/metadata.c
lib/metadata/mirror.c
lib/report/properties.c
lib/report/report.c
lib/uuid/uuid.c
liblvm/lvm_vg.c
tools/lvcreate.c
tools/reporter.c
tools/toollib.c
tools/toollib.h
tools/vgcfgrestore.c
tools/vgcreate.c
tools/vgextend.c
tools/vgmerge.c
tools/vgreduce.c
tools/vgrename.c
tools/vgsplit.c

index aaa100b813470c4e3e4727913ec46e9097f3a3b3..8df073be935a242b39dd4780866806e43a4a9f01 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.85 - 
 ===================================
+  Fixing some const cast gcc warnings in the code.
   Use char* arithmetic in _text_write(), _text_read() & send_message().
   Fix compilation when devmapper is dissabled.
   Remove fs_unlock() from lv_suspend error path.
index 3726324c0d5fe371bb7a4a13851d911222da38b1..1f3184e27448fea62fa303b3e27284cee4358f93 100644 (file)
@@ -2091,7 +2091,7 @@ error:
        return -1;
 }
 
-void process_message(struct local_client *client, const char *buf, int len,
+void process_message(struct local_client *client, char *buf, int len,
                     const char *csid)
 {
        struct clvm_header *inheader;
index 95244e1387b5108f698e491811cdf4b37e87abc6..5bad43aca91267b293d1378be99f50f78972a3c5 100644 (file)
@@ -112,7 +112,7 @@ extern void cmd_client_cleanup(struct local_client *client);
 extern int add_client(struct local_client *new_client);
 
 extern void clvmd_cluster_init_completed(void);
-extern void process_message(struct local_client *client, const char *buf,
+extern void process_message(struct local_client *client, char *buf,
                            int len, const char *csid);
 extern void debuglog(const char *fmt, ... )
   __attribute__ ((format(printf, 1, 2)));
index 779b41b3a9058b5cfa204a9854340e41414042dd..1ec518d59d62bfc8b57174bfe828505cb91e8a68 100644 (file)
@@ -162,7 +162,7 @@ int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent)
 {
        return 0;
 }
-int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
+int lv_mirror_percent(struct cmd_context *cmd, const struct logical_volume *lv,
                      int wait, percent_t *percent, uint32_t *event_nr)
 {
        return 0;
@@ -568,7 +568,7 @@ int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent)
 }
 
 /* FIXME Merge with snapshot_percent */
-int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
+int lv_mirror_percent(struct cmd_context *cmd, const struct logical_volume *lv,
                      int wait, percent_t *percent, uint32_t *event_nr)
 {
        int r;
index 53ab19262774e7b53532e8d137380e4bd21d904e..145fefb6512a071aaba260368ace52c313686ee3 100644 (file)
@@ -85,7 +85,7 @@ int lv_check_transient(struct logical_volume *lv);
  * Returns 1 if percent has been set, else 0.
  */
 int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent);
-int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
+int lv_mirror_percent(struct cmd_context *cmd, const struct logical_volume *lv,
                      int wait, percent_t *percent, uint32_t *event_nr);
 
 /*
index e046c719f6d5d9e9f6fb42b1b4d9b1d5fa87084d..fc83469d578c2eb6c68804550284cf92b188af29 100644 (file)
@@ -135,7 +135,7 @@ static int _build_matcher(struct rfilter *rf, const struct config_value *val)
        /*
         * build the matcher.
         */
-       if (!(rf->engine = dm_regex_create(rf->mem, (const char **) regex,
+       if (!(rf->engine = dm_regex_create(rf->mem, (const char * const*) regex,
                                           count)))
                goto_out;
        r = 1;
index bff36d280a9d06df990c75244bad62596ef7ffd1..50afa281792159b82722a043d68da120b4e4a283 100644 (file)
@@ -23,7 +23,7 @@ struct replicator_device;
 
 struct logical_volume {
        union lvid lvid;
-       char *name;
+       const char *name;
 
        struct volume_group *vg;
 
index eb2a3e4a3bc652801d30b819d190e32e6ebaeb42..684eb83f24209dde454da185e42d6f7c12b5ee27 100644 (file)
@@ -1897,7 +1897,8 @@ static int _rename_sub_lv(struct cmd_context *cmd,
                          struct logical_volume *lv,
                          const char *lv_name_old, const char *lv_name_new)
 {
-       char *suffix, *new_name;
+       const char *suffix;
+       char *new_name;
        size_t len;
 
        /*
index 4e2463a239be1b032f94ded88fadfc537e60135b..32f0ac3cc5347ba6dcdbb3f4f099c7eb869e0829 100644 (file)
@@ -410,9 +410,9 @@ void vg_remove_pvs(struct volume_group *vg);
 int vg_remove(struct volume_group *vg);
 int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
              const char *new_name);
-int vg_extend(struct volume_group *vg, int pv_count, char **pv_names,
+int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names,
              struct pvcreate_params *pp);
-int vg_reduce(struct volume_group *vg, char *pv_name);
+int vg_reduce(struct volume_group *vg, const char *pv_name);
 int vg_change_tag(struct volume_group *vg, const char *tag, int add_tag);
 int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from,
                  struct volume_group *vg_to);
@@ -698,7 +698,7 @@ struct logical_volume *find_pvmove_lv_from_pvname(struct cmd_context *cmd,
                                                  uint32_t lv_type);
 const char *get_pvmove_pvname_from_lv(struct logical_volume *lv);
 const char *get_pvmove_pvname_from_lv_mirr(struct logical_volume *lv_mirr);
-percent_t copy_percent(struct logical_volume *lv_mirr);
+percent_t copy_percent(const struct logical_volume *lv_mirr);
 struct dm_list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg,
                          struct logical_volume *lv);
 
@@ -721,7 +721,7 @@ int lv_has_unknown_segments(const struct logical_volume *lv);
 int vg_has_unknown_segments(const struct volume_group *vg);
 
 struct vgcreate_params {
-       char *vg_name;
+       const char *vg_name;
        uint32_t extent_size;
        size_t max_pv;
        size_t max_lv;
index 7b692be31ed46e181a346eb83a0777cca15e352b..55120c56d38548165e2329c37d93055b96e215e2 100644 (file)
@@ -662,33 +662,38 @@ static int vg_extend_single_pv(struct volume_group *vg, char *pv_name,
  * - pp: parameters to pass to implicit pvcreate; if NULL, do not pvcreate
  *
  */
-int vg_extend(struct volume_group *vg, int pv_count, char **pv_names,
+int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names,
              struct pvcreate_params *pp)
 {
        int i;
+       char *pv_name;
 
        if (_vg_bad_status_bits(vg, RESIZEABLE_VG))
                return 0;
 
        /* attach each pv */
        for (i = 0; i < pv_count; i++) {
-               unescape_colons_and_at_signs(pv_names[i], NULL, NULL);
-               if (!vg_extend_single_pv(vg, pv_names[i], pp))
-                       goto bad;
+               if (!(pv_name = dm_strdup(pv_names[i]))) {
+                       log_error("Failed to duplicate pv name %s.", pv_names[i]);
+                       return 0;
+               }
+               unescape_colons_and_at_signs(pv_name, NULL, NULL);
+               if (!vg_extend_single_pv(vg, pv_name, pp)) {
+                       log_error("Unable to add physical volume '%s' to "
+                                 "volume group '%s'.", pv_name, vg->name);
+                       dm_free(pv_name);
+                       return 0;
+               }
+               dm_free(pv_name);
        }
 
 /* FIXME Decide whether to initialise and add new mdahs to format instance */
 
        return 1;
-
-      bad:
-       log_error("Unable to add physical volume '%s' to "
-                 "volume group '%s'.", pv_names[i], vg->name);
-       return 0;
 }
 
 /* FIXME: use this inside vgreduce_single? */
-int vg_reduce(struct volume_group *vg, char *pv_name)
+int vg_reduce(struct volume_group *vg, const char *pv_name)
 {
        struct physical_volume *pv;
        struct pv_list *pvl;
@@ -1875,7 +1880,7 @@ int vgs_are_compatible(struct cmd_context *cmd __attribute__((unused)),
 {
        struct lv_list *lvl1, *lvl2;
        struct pv_list *pvl;
-       char *name1, *name2;
+       const char *name1, *name2;
 
        if (lvs_in_vg_activated(vg_from)) {
                log_error("Logical volumes in \"%s\" must be inactive",
index 318ac037e171b31ff7e479fda2ca39caa7a09ba1..03e73cd7637f7b35f2428a8804b8822cb2f9d9ed 100644 (file)
@@ -1514,7 +1514,7 @@ struct dm_list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg,
        return lvs;
 }
 
-percent_t copy_percent(struct logical_volume *lv_mirr)
+percent_t copy_percent(const struct logical_volume *lv_mirr)
 {
        uint32_t numerator = 0u, denominator = 0u;
        struct lv_segment *seg;
@@ -1727,8 +1727,8 @@ static struct logical_volume *_set_up_mirror_log(struct cmd_context *cmd,
                                                 int in_sync)
 {
        struct logical_volume *log_lv;
-       const char *suffix, *c;
-       char *lv_name;
+       const char *suffix, *lv_name;
+       char *tmp_name;
        size_t len;
        struct lv_segment *seg;
 
@@ -1747,21 +1747,21 @@ static struct logical_volume *_set_up_mirror_log(struct cmd_context *cmd,
            strstr(seg_lv(seg, 0)->name, MIRROR_SYNC_LAYER)) {
                lv_name = lv->name;
                suffix = "_mlogtmp_%d";
-       } else if ((c = strstr(lv->name, MIRROR_SYNC_LAYER))) {
-               len = c - lv->name + 1;
-               if (!(lv_name = alloca(len)) ||
-                   !dm_snprintf(lv_name, len, "%s", lv->name)) {
+       } else if ((lv_name = strstr(lv->name, MIRROR_SYNC_LAYER))) {
+               len = lv_name - lv->name + 1;
+               if (!(tmp_name = alloca(len)) ||
+                   !dm_snprintf(tmp_name, len, "%s", lv->name)) {
                        log_error("mirror log name allocation failed");
                        return 0;
                }
+               lv_name = tmp_name;
                suffix = "_mlog";
        } else {
                lv_name = lv->name;
                suffix = "_mlog";
        }
 
-       if (!(log_lv = _create_mirror_log(lv, ah, alloc,
-                                         (const char *) lv_name, suffix))) {
+       if (!(log_lv = _create_mirror_log(lv, ah, alloc, lv_name, suffix))) {
                log_error("Failed to create mirror log.");
                return NULL;
        }
index 06e11ba92c915babb73006ea01373f5303edc0ef..a08470c353892d2ec5ac68a42f11b6eb63841c4f 100644 (file)
@@ -88,8 +88,7 @@ static int _not_implemented_set(void *obj, struct lvm_property_type *prop)
 
 static percent_t _copy_percent(const struct logical_volume *lv) {
        percent_t perc;
-       if (!lv_mirror_percent(lv->vg->cmd, (struct logical_volume *) lv,
-                          0, &perc, NULL))
+       if (!lv_mirror_percent(lv->vg->cmd, lv, 0, &perc, NULL))
                perc = PERCENT_INVALID;
        return perc;
 }
index 136ad4c53db2ad9a4f94301de9aab3232a7e3cd4..0b1523f00a0a6b4e3447f18ef9df3f32c59f03b5 100644 (file)
@@ -44,7 +44,7 @@ static int _string_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(
                        struct dm_report_field *field,
                        const void *data, void *private __attribute__((unused)))
 {
-       return dm_report_field_string(rh, field, (const char **) data);
+       return dm_report_field_string(rh, field, (const char * const *) data);
 }
 
 static int _dev_name_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -307,10 +307,8 @@ static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem,
        char *repstr, *lvname;
        size_t len;
 
-       if (lv_is_visible(lv)) {
-               repstr = lv->name;
-               return dm_report_field_string(rh, field, (const char **) &repstr);
-       }
+       if (lv_is_visible(lv))
+               return dm_report_field_string(rh, field, &lv->name);
 
        len = strlen(lv->name) + 3;
        if (!(repstr = dm_pool_zalloc(mem, len))) {
@@ -615,7 +613,7 @@ static int _uuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_po
 {
        char *repstr = NULL;
 
-       if (!(repstr = id_format_and_copy(mem, (struct id *)data)))
+       if (!(repstr = id_format_and_copy(mem, data)))
                return_0;
 
        dm_report_field_set_value(field, repstr, NULL);
@@ -853,7 +851,7 @@ static int _copypercent_disp(struct dm_report *rh __attribute__((unused)),
                             struct dm_report_field *field,
                             const void *data, void *private __attribute__((unused)))
 {
-       struct logical_volume *lv = (struct logical_volume *) data;
+       const struct logical_volume *lv = (const struct logical_volume *) data;
        percent_t percent;
        uint64_t *sortval;
        char *repstr;
@@ -899,7 +897,7 @@ static struct format_instance _dummy_fid = {
 
 static struct volume_group _dummy_vg = {
        .fid = &_dummy_fid,
-       .name = (char *) "",
+       .name = "",
        .system_id = (char *) "",
        .pvs = { &(_dummy_vg.pvs), &(_dummy_vg.pvs) },
        .lvs = { &(_dummy_vg.lvs), &(_dummy_vg.lvs) },
index edcb1ba30f7a581f760a3b491f9cc64d63c84f38..c85b822d7db2c4ad2de0a94c24257a8c9743730b 100644 (file)
@@ -158,7 +158,7 @@ int id_write_format(const struct id *id, char *buffer, size_t size)
 {
        int i, tot;
 
-       static unsigned group_size[] = { 6, 4, 4, 4, 4, 4, 6 };
+       static const unsigned group_size[] = { 6, 4, 4, 4, 4, 4, 6 };
 
        assert(ID_LEN == 32);
 
index f087ba4356241647c3e3106b39d9de441a7dc438..dfc0c5ee20a35bac7978396068ee205ecb1e86ea 100644 (file)
@@ -79,7 +79,7 @@ int lvm_vg_extend(vg_t vg, const char *device)
        }
 
        pvcreate_params_set_defaults(&pp);
-       if (!vg_extend(vg, 1, (char **) &device, &pp)) {
+       if (!vg_extend(vg, 1, &device, &pp)) {
                unlock_vg(vg->cmd, VG_ORPHANS);
                return -1;
        }
@@ -98,7 +98,7 @@ int lvm_vg_reduce(vg_t vg, const char *device)
        if (!vg_check_write_mode(vg))
                return -1;
 
-       if (!vg_reduce(vg, (char *)device))
+       if (!vg_reduce(vg, device))
                return -1;
        return 0;
 }
index 7016417150d0754c1aa60668f4888be29ef1249c..d1abdf7b0e4e5fad97c4ddea19178ac68ad0fee7 100644 (file)
@@ -31,7 +31,7 @@ static int _lvcreate_name_params(struct lvcreate_params *lp,
 {
        int argc = *pargc;
        char **argv = *pargv, *ptr;
-       char *vg_name;
+       const char *vg_name;
 
        lp->lv_name = arg_str_value(cmd, name_ARG, NULL);
 
index fbd0c27453825d0e11a763b0d6cd1eaa324a4071..ebe85e7f51f3e30dd77cc8de2b48a0fa755cf983 100644 (file)
@@ -61,7 +61,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,
 
        struct volume_group _free_vg = {
                .cmd = cmd,
-               .name = (char *)"",
+               .name = "",
        };
 
         if (!(_free_vg.vgmem = dm_pool_create("_free_vg", 10240)))
@@ -69,7 +69,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,
 
        struct logical_volume _free_logical_volume = {
                .vg = vg ?: &_free_vg,
-               .name = (char *) "",
+               .name = "",
                .snapshot = NULL,
                .status = VISIBLE_LV,
                .major = -1,
index c85b7f0a402987c060d8e0db59753735e601a6c8..5467a3b778ffff0f354b669aa0b858a86c956c90 100644 (file)
@@ -28,7 +28,7 @@ const char *command_name(struct cmd_context *cmd)
 /*
  * Strip dev_dir if present
  */
-char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
+const char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
                   unsigned *dev_dir_found)
 {
        const char *dmdir = dm_dir();
@@ -54,7 +54,7 @@ char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
                    *layer) {
                        log_error("skip_dev_dir: Couldn't split up device name %s",
                                  vg_name);
-                       return (char *) vg_name;
+                       return vg_name;
                }
                vglv_sz = strlen(vgname) + strlen(lvname) + 2;
                if (!(vglv = dm_pool_alloc(cmd->mem, vglv_sz)) ||
@@ -62,7 +62,7 @@ char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
                                 *lvname ? "/" : "",
                                 lvname) < 0) {
                        log_error("vg/lv string alloc failed");
-                       return (char *) vg_name;
+                       return vg_name;
                }
                return vglv;
        }
@@ -76,7 +76,7 @@ char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
        } else if (dev_dir_found)
                *dev_dir_found = 0;
 
-       return (char *) vg_name;
+       return vg_name;
 }
 
 /*
@@ -898,7 +898,7 @@ const char *extract_vgname(struct cmd_context *cmd, const char *lv_name)
  */
 char *default_vgname(struct cmd_context *cmd)
 {
-       char *vg_path;
+       const char *vg_path;
 
        /* Take default VG from environment? */
        vg_path = getenv("LVM_VG_NAME");
index 506945a06585a19374c77884f6581c1423ef7415..1ef83f68ba38d721577fe1b4ad3e91ac1e409913 100644 (file)
@@ -84,8 +84,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd,
 
 char *default_vgname(struct cmd_context *cmd);
 const char *extract_vgname(struct cmd_context *cmd, const char *lv_name);
-char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
-                  unsigned *dev_dir_found);
+const char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
+                        unsigned *dev_dir_found);
 
 /*
  * Builds a list of pv's from the names in argv.  Used in
index dc0158f8e47b6f1f57035892a8f06992f94e45d8..1f1ab52136514ace37263edf3702fbd081957608 100644 (file)
@@ -17,7 +17,7 @@
 
 int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
 {
-       char *vg_name = NULL;
+       const char *vg_name = NULL;
 
        if (argc == 1) {
                vg_name = skip_dev_dir(cmd, argv[0], NULL);
index 49574f335595a1b8f8d129b5e5111bc5121ae5dd..62b5ac7bdd9432b60957c3f239e03b0de10ec7af 100644 (file)
@@ -74,7 +74,7 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
        }
 
        /* attach the pv's */
-       if (!vg_extend(vg, argc, argv, &pp))
+       if (!vg_extend(vg, argc, (const char* const*)argv, &pp))
                goto_bad;
 
        if (vp_new.max_lv != vg->max_lv)
index a0c166b065a218fd2093d77bd2dd903ab1d6e1a5..5d2b54d7ecb6046749be336317269fe2583c7e7e 100644 (file)
@@ -40,7 +40,7 @@ static int _restore_pv(struct volume_group *vg, char *pv_name)
 
 int vgextend(struct cmd_context *cmd, int argc, char **argv)
 {
-       char *vg_name;
+       const char *vg_name;
        struct volume_group *vg = NULL;
        int r = ECMD_FAILED;
        struct pvcreate_params pp;
@@ -107,7 +107,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
                }
 
                /* extend vg */
-               if (!vg_extend(vg, argc, argv, &pp))
+               if (!vg_extend(vg, argc, (const char* const*)argv, &pp))
                        goto_bad;
 
                if (arg_count(cmd, metadataignore_ARG) &&
index 391764f9a8b31d0be12fbe6e0d676c8843edc5d2..adb00a0f6c3c2da99f82f2bfbea6acb5cc4b5e9d 100644 (file)
@@ -163,7 +163,7 @@ bad:
 
 int vgmerge(struct cmd_context *cmd, int argc, char **argv)
 {
-       char *vg_name_to, *vg_name_from;
+       const char *vg_name_to, *vg_name_from;
        int opt = 0;
        int ret = 0, ret_max = 0;
 
index 4aa8f01e68acab18f69bdc155ee18e394bce0cac..5e61cf832544d46ca72c6f9f541e094b65f0325b 100644 (file)
@@ -457,7 +457,7 @@ bad:
 int vgreduce(struct cmd_context *cmd, int argc, char **argv)
 {
        struct volume_group *vg;
-       char *vg_name;
+       const char *vg_name;
        int ret = ECMD_FAILED;
        int fixed = 1;
        int repairing = arg_count(cmd, removemissing_ARG);
index 7a4e730e205ee348e82113c39f1ed31c98714cc0..2f83fc63dcd420932df14acd63096a6895925586 100644 (file)
@@ -63,7 +63,7 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,
        int found_id = 0;
        struct dm_list *vgids;
        struct str_list *sl;
-       char *vg_name_new;
+       const char *vg_name_new;
        const char *vgid = NULL, *vg_name, *vg_name_old;
        char old_path[NAME_LEN], new_path[NAME_LEN];
        struct volume_group *vg = NULL;
index bd2f0ab31e7b59d7dadebeee6c3a6b2fb741a64d..b97db97b1e7406ffecca60e792fb43780e9e8cc6 100644 (file)
@@ -281,7 +281,7 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
 {
        struct vgcreate_params vp_new;
        struct vgcreate_params vp_def;
-       char *vg_name_from, *vg_name_to;
+       const char *vg_name_from, *vg_name_to;
        struct volume_group *vg_to = NULL, *vg_from = NULL;
        int opt;
        int existing_vg = 0;
This page took 0.070875 seconds and 5 git commands to generate.