diff --git a/tools/pvck.c b/tools/pvck.c index 76fcf45c3..bd4d076ae 100644 --- a/tools/pvck.c +++ b/tools/pvck.c @@ -3002,10 +3002,9 @@ out: return 0; } -int pvck(struct cmd_context *cmd, int argc, char **argv) +static int _pvck_mf(struct metadata_file *mf, struct cmd_context *cmd, int argc, char **argv) { - struct settings set; - struct metadata_file mf; + struct settings set = { 0 }; struct device *dev = NULL; struct devicefile *def = NULL; const char *dump, *repair; @@ -3015,9 +3014,6 @@ int pvck(struct cmd_context *cmd, int argc, char **argv) int ret = 0; int i; - memset(&set, 0, sizeof(set)); - memset(&mf, 0, sizeof(mf)); - /* * By default LVM skips the first sector (sector 0), and writes * the label_header in the second sector (sector 1). @@ -3073,10 +3069,10 @@ int pvck(struct cmd_context *cmd, int argc, char **argv) return_ECMD_FAILED; if (arg_is_set(cmd, file_ARG) && (arg_is_set(cmd, repairtype_ARG) || arg_is_set(cmd, repair_ARG))) { - if (!(mf.filename = arg_str_value(cmd, file_ARG, NULL))) + if (!(mf->filename = arg_str_value(cmd, file_ARG, NULL))) return_ECMD_FAILED; - if (!_read_metadata_file(cmd, &mf)) + if (!_read_metadata_file(cmd, mf)) return_ECMD_FAILED; } @@ -3149,10 +3145,10 @@ int pvck(struct cmd_context *cmd, int argc, char **argv) ret = _repair_label_header(cmd, repair, &set, labelsector, dev); else if (!strcmp(repair, "pv_header")) - ret = _repair_pv_header(cmd, repair, &set, &mf, labelsector, dev); + ret = _repair_pv_header(cmd, repair, &set, mf, labelsector, dev); else if (!strcmp(repair, "metadata")) - ret = _repair_metadata(cmd, repair, &set, &mf, labelsector, dev); + ret = _repair_metadata(cmd, repair, &set, mf, labelsector, dev); else log_error("Unknown repair value."); @@ -3166,10 +3162,10 @@ int pvck(struct cmd_context *cmd, int argc, char **argv) /* repair is a combination of repairtype pv_header+metadata */ - if (!_repair_pv_header(cmd, "pv_header", &set, &mf, labelsector, dev)) + if (!_repair_pv_header(cmd, "pv_header", &set, mf, labelsector, dev)) return_ECMD_FAILED; - if (!_repair_metadata(cmd, "metadata", &set, &mf, labelsector, dev)) + if (!_repair_metadata(cmd, "metadata", &set, mf, labelsector, dev)) return_ECMD_FAILED; return ECMD_PROCESSED; @@ -3202,3 +3198,12 @@ int pvck(struct cmd_context *cmd, int argc, char **argv) return_ECMD_FAILED; return ECMD_PROCESSED; } + +int pvck(struct cmd_context *cmd, int argc, char **argv) +{ + struct metadata_file mf = { 0 }; + int ret = _pvck_mf(&mf, cmd, argc, argv); + + free(mf.text_buf); + return ret; +}