[*_restore] if things go wrong wipe the superblock.
So we don't leave the metadata device with partially restored metadata.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
// with thin-provisioning-tools. If not, see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "base/file_utils.h"
|
||||
#include "base/output_file_requirements.h"
|
||||
#include "persistent-data/file_utils.h"
|
||||
#include "thin-provisioning/commands.h"
|
||||
@@ -44,15 +45,20 @@ using namespace thin_provisioning;
|
||||
|
||||
namespace {
|
||||
int restore(string const &backup_file, string const &dev, bool quiet) {
|
||||
bool metadata_touched = false;
|
||||
try {
|
||||
// The block size gets updated by the restorer.
|
||||
block_manager<>::ptr bm(open_bm(dev, block_manager<>::READ_WRITE));
|
||||
file_utils::check_file_exists(backup_file);
|
||||
metadata_touched = true;
|
||||
metadata::ptr md(new metadata(bm, metadata::CREATE, 128, 0));
|
||||
emitter::ptr restorer = create_restore_emitter(md);
|
||||
|
||||
parse_xml(backup_file, restorer, quiet);
|
||||
|
||||
} catch (std::exception &e) {
|
||||
if (metadata_touched)
|
||||
file_utils::zero_superblock(dev);
|
||||
cerr << e.what() << endl;
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user