mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
toollib: Implement process_each_label.
This commit is contained in:
parent
9b91977f4e
commit
1ef2c3c4ee
@ -1801,3 +1801,61 @@ int change_tag(struct cmd_context *cmd, struct volume_group *vg,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int process_each_label(struct cmd_context *cmd, int argc, char **argv, void *handle,
|
||||
process_single_label_fn_t process_single_label)
|
||||
{
|
||||
struct label *label;
|
||||
struct dev_iter *iter;
|
||||
struct device *dev;
|
||||
|
||||
int ret_max = ECMD_PROCESSED;
|
||||
int ret = 0;
|
||||
int opt = 0;
|
||||
|
||||
if (argc) {
|
||||
for (; opt < argc; opt++) {
|
||||
if (!(dev = dev_cache_get(argv[opt], cmd->filter))) {
|
||||
log_error("Failed to find device "
|
||||
"\"%s\"", argv[opt]);
|
||||
ret_max = ECMD_FAILED;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!label_read(dev, &label, 0))
|
||||
continue;
|
||||
|
||||
ret = process_single_label(cmd, label, handle);
|
||||
|
||||
if (ret > ret_max)
|
||||
ret_max = ret;
|
||||
|
||||
if (sigint_caught())
|
||||
break;
|
||||
}
|
||||
|
||||
return ret_max;
|
||||
}
|
||||
|
||||
if (!(iter = dev_iter_create(cmd->filter, 1))) {
|
||||
log_error("dev_iter creation failed");
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
while ((dev = dev_iter_get(iter)))
|
||||
{
|
||||
if (!label_read(dev, &label, 0))
|
||||
continue;
|
||||
|
||||
ret = process_single_label(cmd, label, handle);
|
||||
|
||||
if (ret > ret_max)
|
||||
ret_max = ret;
|
||||
|
||||
if (sigint_caught())
|
||||
break;
|
||||
}
|
||||
|
||||
dev_iter_destroy(iter);
|
||||
|
||||
return ret_max;
|
||||
}
|
||||
|
@ -38,6 +38,9 @@ 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_label_fn_t) (struct cmd_context *cmd,
|
||||
struct label *label,
|
||||
void *handle);
|
||||
typedef int (*process_single_lv_fn_t) (struct cmd_context *cmd,
|
||||
struct logical_volume *lv,
|
||||
void *handle);
|
||||
@ -58,6 +61,9 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
|
||||
int scan_label_only, void *handle,
|
||||
process_single_pv_fn_t process_single_pv);
|
||||
|
||||
int process_each_label(struct cmd_context *cmd, int argc, char **argv,
|
||||
void *handle, process_single_label_fn_t process_single_label);
|
||||
|
||||
int process_each_segment_in_pv(struct cmd_context *cmd,
|
||||
struct volume_group *vg,
|
||||
struct physical_volume *pv,
|
||||
|
Loading…
Reference in New Issue
Block a user