From 6c4f65fecdd0b1cb3fc721f417b9af2ad9e9f5af Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 13 Apr 2010 23:57:41 +0000 Subject: [PATCH] Use typedefs for toollib process_each functions. --- WHATS_NEW | 1 + tools/toollib.c | 67 ++++++++++++++++++------------------------------- tools/toollib.h | 56 ++++++++++++++++++++--------------------- 3 files changed, 52 insertions(+), 72 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index b4c4f46f1..c7c7fce6d 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.63 - ================================ + Use typedefs for toollib process_each functions. Use C locales and use_mlockall for clvmd. Refactor code related to vg->pvs list and add pv->vg link. Mask LCK_HOLD flag in cluster VG locks for compatibility reasons. diff --git a/tools/toollib.c b/tools/toollib.c index 74425bcea..3f64c9e35 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -87,7 +87,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, const struct dm_list *arg_lvnames, const struct dm_list *tags, void *handle, - process_single_lv_fn_t process_single) + process_single_lv_fn_t process_single_lv) { int ret_max = ECMD_PROCESSED; int ret = 0; @@ -147,7 +147,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, if (!process_lv) continue; - ret = process_single(cmd, lvl->lv, handle); + ret = process_single_lv(cmd, lvl->lv, handle); if (ret > ret_max) ret_max = ret; if (sigint_caught()) @@ -165,9 +165,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t flags, void *handle, - int (*process_single) (struct cmd_context * cmd, - struct logical_volume * lv, - void *handle)) + process_single_lv_fn_t process_single_lv) { int opt = 0; int ret_max = ECMD_PROCESSED; @@ -320,7 +318,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, } ret = process_each_lv_in_vg(cmd, vg, &lvnames, tags_arg, - handle, process_single); + handle, process_single_lv); unlock_and_release_vg(cmd, vg, vgname); if (ret > ret_max) ret_max = ret; @@ -335,10 +333,7 @@ int process_each_segment_in_pv(struct cmd_context *cmd, struct volume_group *vg, struct physical_volume *pv, void *handle, - int (*process_single) (struct cmd_context * cmd, - struct volume_group * vg, - struct pv_segment * pvseg, - void *handle)) + process_single_pvseg_fn_t process_single_pvseg) { struct pv_segment *pvseg; struct pv_list *pvl; @@ -373,12 +368,12 @@ int process_each_segment_in_pv(struct cmd_context *cmd, } if (dm_list_empty(&pv->segments)) { - ret = process_single(cmd, NULL, &_free_pv_segment, handle); + ret = process_single_pvseg(cmd, NULL, &_free_pv_segment, handle); if (ret > ret_max) ret_max = ret; } else dm_list_iterate_items(pvseg, &pv->segments) { - ret = process_single(cmd, vg, pvseg, handle); + ret = process_single_pvseg(cmd, vg, pvseg, handle); if (ret > ret_max) ret_max = ret; if (sigint_caught()) @@ -396,16 +391,14 @@ int process_each_segment_in_pv(struct cmd_context *cmd, int process_each_segment_in_lv(struct cmd_context *cmd, struct logical_volume *lv, void *handle, - int (*process_single) (struct cmd_context * cmd, - struct lv_segment * seg, - void *handle)) + process_single_seg_fn_t process_single_seg) { struct lv_segment *seg; int ret_max = ECMD_PROCESSED; int ret; dm_list_iterate_items(seg, &lv->segments) { - ret = process_single(cmd, seg, handle); + ret = process_single_seg(cmd, seg, handle); if (ret > ret_max) ret_max = ret; if (sigint_caught()) @@ -419,10 +412,7 @@ static int _process_one_vg(struct cmd_context *cmd, const char *vg_name, const char *vgid, struct dm_list *tags, struct dm_list *arg_vgnames, uint32_t flags, void *handle, int ret_max, - int (*process_single) (struct cmd_context * cmd, - const char *vg_name, - struct volume_group * vg, - void *handle)) + process_single_vg_fn_t process_single_vg) { struct volume_group *vg; int ret = 0; @@ -445,7 +435,7 @@ static int _process_one_vg(struct cmd_context *cmd, const char *vg_name, goto out; } - if ((ret = process_single(cmd, vg_name, vg, + if ((ret = process_single_vg(cmd, vg_name, vg, handle)) > ret_max) ret_max = ret; @@ -459,10 +449,7 @@ out: int process_each_vg(struct cmd_context *cmd, int argc, char **argv, uint32_t flags, void *handle, - int (*process_single) (struct cmd_context * cmd, - const char *vg_name, - struct volume_group * vg, - void *handle)) + process_single_vg_fn_t process_single_vg) { int opt = 0; int ret_max = ECMD_PROCESSED; @@ -529,7 +516,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv, ret_max = _process_one_vg(cmd, vg_name, vgid, &tags, &arg_vgnames, flags, handle, - ret_max, process_single); + ret_max, process_single_vg); if (sigint_caught()) return ret_max; } @@ -541,7 +528,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv, ret_max = _process_one_vg(cmd, vg_name, NULL, &tags, &arg_vgnames, flags, handle, - ret_max, process_single); + ret_max, process_single_vg); if (sigint_caught()) return ret_max; } @@ -552,7 +539,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv, int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg, const struct dm_list *tags, void *handle, - process_single_pv_fn_t process_single) + process_single_pv_fn_t process_single_pv) { int ret_max = ECMD_PROCESSED; int ret = 0; @@ -563,7 +550,7 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg, !str_list_match_list(tags, &pvl->pv->tags)) { continue; } - if ((ret = process_single(cmd, vg, pvl->pv, handle)) > ret_max) + if ((ret = process_single_pv(cmd, vg, pvl->pv, handle)) > ret_max) ret_max = ret; if (sigint_caught()) return ret_max; @@ -573,10 +560,7 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg, } static int _process_all_devs(struct cmd_context *cmd, void *handle, - int (*process_single) (struct cmd_context * cmd, - struct volume_group * vg, - struct physical_volume * pv, - void *handle)) + process_single_pv_fn_t process_single_pv) { struct physical_volume *pv; struct physical_volume pv_dummy; @@ -605,7 +589,7 @@ static int _process_all_devs(struct cmd_context *cmd, void *handle, pv_dummy.fmt = NULL; pv = &pv_dummy; } - ret = process_single(cmd, NULL, pv, handle); + ret = process_single_pv(cmd, NULL, pv, handle); if (ret > ret_max) ret_max = ret; if (sigint_caught()) @@ -625,10 +609,7 @@ static int _process_all_devs(struct cmd_context *cmd, void *handle, int process_each_pv(struct cmd_context *cmd, int argc, char **argv, struct volume_group *vg, uint32_t flags, int scan_label_only, void *handle, - int (*process_single) (struct cmd_context * cmd, - struct volume_group * vg, - struct physical_volume * pv, - void *handle)) + process_single_pv_fn_t process_single_pv) { int opt = 0; int ret_max = ECMD_PROCESSED; @@ -721,7 +702,7 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, } } - ret = process_single(cmd, vg, pv, handle); + ret = process_single_pv(cmd, vg, pv, handle); if (ret > ret_max) ret_max = ret; if (sigint_caught()) @@ -740,7 +721,7 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, ret = process_each_pv_in_vg(cmd, vg, &tags, handle, - process_single); + process_single_pv); unlock_and_release_vg(cmd, vg, sll->str); @@ -755,13 +736,13 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, log_verbose("Using all physical volume(s) in " "volume group"); ret = process_each_pv_in_vg(cmd, vg, NULL, handle, - process_single); + process_single_pv); if (ret > ret_max) ret_max = ret; if (sigint_caught()) goto out; } else if (arg_count(cmd, all_ARG)) { - ret = _process_all_devs(cmd, handle, process_single); + ret = _process_all_devs(cmd, handle, process_single_pv); if (ret > ret_max) ret_max = ret; if (sigint_caught()) @@ -773,7 +754,7 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv, goto bad; dm_list_iterate_items(pvl, pvslist) { - ret = process_single(cmd, NULL, pvl->pv, + ret = process_single_pv(cmd, NULL, pvl->pv, handle); if (ret > ret_max) ret_max = ret; diff --git a/tools/toollib.h b/tools/toollib.h index 8c6bfef42..23ccd8681 100644 --- a/tools/toollib.h +++ b/tools/toollib.h @@ -26,61 +26,60 @@ int autobackup(struct volume_group *vg); struct volume_group *recover_vg(struct cmd_context *cmd, const char *vgname, uint32_t lock_type); +typedef int (*process_single_vg_fn_t) (struct cmd_context * cmd, + const char *vg_name, + struct volume_group * vg, + void *handle); +typedef int (*process_single_pv_fn_t) (struct cmd_context *cmd, + struct volume_group *vg, + struct physical_volume *pv, + void *handle); +typedef int (*process_single_lv_fn_t) (struct cmd_context *cmd, + struct logical_volume *lv, + void *handle); +typedef int (*process_single_seg_fn_t) (struct cmd_context * cmd, + struct lv_segment * seg, + void *handle); +typedef int (*process_single_pvseg_fn_t) (struct cmd_context * cmd, + struct volume_group * vg, + struct pv_segment * pvseg, + void *handle); + int process_each_vg(struct cmd_context *cmd, int argc, char **argv, uint32_t flags, void *handle, - int (*process_single) (struct cmd_context * cmd, - const char *vg_name, - struct volume_group * vg, - void *handle)); + process_single_vg_fn_t process_single_vg); int process_each_pv(struct cmd_context *cmd, int argc, char **argv, struct volume_group *vg, uint32_t lock_type, int scan_label_only, void *handle, - int (*process_single) (struct cmd_context * cmd, - struct volume_group * vg, - struct physical_volume * pv, - void *handle)); + process_single_pv_fn_t process_single_pv); int process_each_segment_in_pv(struct cmd_context *cmd, struct volume_group *vg, struct physical_volume *pv, void *handle, - int (*process_single) (struct cmd_context * cmd, - struct volume_group * vg, - struct pv_segment * pvseg, - void *handle)); + process_single_pvseg_fn_t process_single_pvseg); int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t flags, void *handle, - int (*process_single) (struct cmd_context * cmd, - struct logical_volume * lv, - void *handle)); + process_single_lv_fn_t process_single_lv); + int process_each_segment_in_lv(struct cmd_context *cmd, struct logical_volume *lv, void *handle, - int (*process_single) (struct cmd_context * cmd, - struct lv_segment * seg, - void *handle)); - -typedef int (*process_single_pv_fn_t) (struct cmd_context *cmd, - struct volume_group *vg, - struct physical_volume *pv, - void *handle); + process_single_seg_fn_t process_single_seg); int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg, const struct dm_list *tags, void *handle, - process_single_pv_fn_t process_single); + process_single_pv_fn_t process_single_pv); -typedef int (*process_single_lv_fn_t) (struct cmd_context *cmd, - struct logical_volume *lv, - void *handle); int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg, const struct dm_list *arg_lvnames, const struct dm_list *tags, void *handle, - process_single_lv_fn_t process_single); + process_single_lv_fn_t process_single_lv); char *default_vgname(struct cmd_context *cmd); const char *extract_vgname(struct cmd_context *cmd, const char *lv_name); @@ -118,5 +117,4 @@ int get_activation_monitoring_mode(struct cmd_context *cmd, int get_stripe_params(struct cmd_context *cmd, uint32_t *stripes, uint32_t *stripe_size); - #endif