]>
sourceware.org Git - lvm2.git/blob - tools/vgcfgrestore.c
1b51299ea67e3c96e009deffe303f13ea55ea259
2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2018 Red Hat, Inc. All rights reserved.
5 * This file is part of LVM2.
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 #include "device_mapper/all.h"
18 #include "device_mapper/misc/dm-ioctl.h"
21 * Check if there are any active volumes from restored vg_name.
22 * We can prompt user, as such operation may make some serious
23 * troubles later, when user will try to continue such devices.
25 static int _check_all_dm_devices(const char *vg_name
, unsigned *found
)
28 struct dm_names
*names
;
29 char vgname_buf
[DM_NAME_LEN
* 2];
30 char *vgname
, *lvname
, *lvlayer
;
34 if (!(dmt
= dm_task_create(DM_DEVICE_LIST
)))
37 if (!dm_task_run(dmt
)) {
42 if (!(names
= dm_task_get_names(dmt
))) {
48 log_verbose("No devices found.");
53 /* TODO: Do we want to validate UUID LVM- prefix as well ? */
54 names
= (struct dm_names
*)((char *) names
+ next
);
55 if (!_dm_strncpy(vgname_buf
, names
->name
, sizeof(vgname_buf
))) {
60 if (!dm_split_lvm_name(NULL
, NULL
, &vgname
, &lvname
, &lvlayer
)) {
64 if (strcmp(vgname
, vg_name
) == 0) {
65 log_print("Volume group %s has active volume: %s.", vgname
, lvname
);
76 int vgcfgrestore(struct cmd_context
*cmd
, int argc
, char **argv
)
78 const char *vg_name
= NULL
;
83 vg_name
= skip_dev_dir(cmd
, argv
[0], NULL
);
84 if (!validate_name(vg_name
)) {
85 log_error("Volume group name \"%s\" is invalid.", vg_name
);
86 return EINVALID_CMD_LINE
;
88 } else if (!(arg_is_set(cmd
, list_ARG
) && arg_is_set(cmd
, file_ARG
))) {
89 log_error("Please specify a *single* volume group to restore.");
90 return EINVALID_CMD_LINE
;
94 * FIXME: overloading the -l arg for now to display a
95 * list of archive files for a particular vg
97 if (arg_is_set(cmd
, list_ARG
)) {
98 if (!(arg_is_set(cmd
,file_ARG
) ?
99 archive_display_file(cmd
,
100 arg_str_value(cmd
, file_ARG
, "")) :
101 archive_display(cmd
, vg_name
)))
104 return ECMD_PROCESSED
;
108 log_error(INTERNAL_ERROR
"VG name is not set.");
110 } else if (!_check_all_dm_devices(vg_name
, &found
)) {
111 log_warn("WARNING: Failed to check for active volumes in volume group \"%s\".", vg_name
);
113 log_warn("WARNING: Found %u active volume(s) in volume group \"%s\".",
115 log_print("Restoring VG with active LVs, may cause mismatch with its metadata.");
116 if (!arg_is_set(cmd
, yes_ARG
) &&
117 yes_no_prompt("Do you really want to proceed with restore of volume group \"%s\", "
118 "while %u volume(s) are active? [y/n]: ",
119 vg_name
, found
) == 'n') {
120 log_error("Restore aborted.");
125 if (!lock_global(cmd
, "ex"))
128 if (!lock_vol(cmd
, vg_name
, LCK_VG_WRITE
, NULL
)) {
129 log_error("Unable to lock volume group %s.", vg_name
);
133 clear_hint_file(cmd
);
135 if (!lvmcache_label_scan(cmd
)) {
136 unlock_vg(cmd
, NULL
, vg_name
);
140 cmd
->handles_unknown_segments
= 1;
142 if (!(arg_is_set(cmd
, file_ARG
) ?
143 backup_restore_from_file(cmd
, vg_name
,
144 arg_str_value(cmd
, file_ARG
, ""),
145 arg_count(cmd
, force_long_ARG
)) :
146 backup_restore(cmd
, vg_name
, arg_count(cmd
, force_long_ARG
)))) {
147 unlock_vg(cmd
, NULL
, vg_name
);
148 log_error("Restore failed.");
153 ret
= ECMD_PROCESSED
;
154 log_print_unless_silent("Restored volume group %s.", vg_name
);
156 unlock_vg(cmd
, NULL
, vg_name
);
This page took 0.049477 seconds and 6 git commands to generate.