[*_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:
Joe Thornber
2017-09-28 14:39:24 +01:00
parent 8035e10b2a
commit 5b92f410ec
5 changed files with 35 additions and 3 deletions

View File

@ -9,6 +9,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
//----------------------------------------------------------------
@ -140,4 +141,16 @@ file_utils::get_file_length(string const &file) {
return nr_bytes;
}
void
file_utils::zero_superblock(std::string const &path)
{
unsigned const SUPERBLOCK_SIZE = 4096;
char buffer[SUPERBLOCK_SIZE];
int fd = open_block_file(path, SUPERBLOCK_SIZE, true, true);
memset(buffer, 0, SUPERBLOCK_SIZE);
if (::write(fd, buffer, SUPERBLOCK_SIZE) != SUPERBLOCK_SIZE)
throw runtime_error("couldn't zero superblock");
}
//----------------------------------------------------------------