Compare commits
2 Commits
a87e236c70
...
c72e8e649e
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | c72e8e649e | |
Vitaliy Filippov | 8bdb3e8786 |
|
@ -224,6 +224,10 @@ int main(int argc, char *argv[])
|
|||
cmd.push_back((char*)"dump-journal");
|
||||
aliased = true;
|
||||
}
|
||||
else if (!strcmp(exe_name, "vitastor-disk-test"))
|
||||
{
|
||||
self.test_mode = true;
|
||||
}
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (!strcmp(argv[i], "--all"))
|
||||
|
@ -318,6 +322,7 @@ int main(int argc, char *argv[])
|
|||
// First argument is an OSD device - take metadata layout parameters from it
|
||||
if (self.dump_load_check_superblock(self.new_journal_device))
|
||||
return 1;
|
||||
self.new_journal_device = self.dsk.journal_device;
|
||||
self.new_journal_offset = self.dsk.journal_offset;
|
||||
self.new_journal_len = self.dsk.journal_len;
|
||||
}
|
||||
|
@ -383,6 +388,7 @@ int main(int argc, char *argv[])
|
|||
// First argument is an OSD device - take metadata layout parameters from it
|
||||
if (self.dump_load_check_superblock(self.new_meta_device))
|
||||
return 1;
|
||||
self.new_meta_device = self.dsk.meta_device;
|
||||
self.new_meta_offset = self.dsk.meta_offset;
|
||||
self.new_meta_len = self.dsk.meta_len;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ struct disk_tool_t
|
|||
/**** Parameters ****/
|
||||
|
||||
std::map<std::string, std::string> options;
|
||||
bool test_mode = false;
|
||||
bool all, json, now;
|
||||
bool dump_with_blocks, dump_with_data;
|
||||
blockstore_disk_t dsk;
|
||||
|
@ -128,6 +129,7 @@ struct disk_tool_t
|
|||
|
||||
int prepare_one(std::map<std::string, std::string> options, int is_hdd = -1);
|
||||
int check_existing_partition(const std::string & dev);
|
||||
int fix_partition_type(const std::string & dev_by_uuid);
|
||||
int prepare(std::vector<std::string> devices);
|
||||
std::vector<vitastor_dev_info_t> collect_devices(const std::vector<std::string> & devices);
|
||||
json11::Json add_partitions(vitastor_dev_info_t & devinfo, std::vector<std::string> sizes);
|
||||
|
@ -149,6 +151,6 @@ int write_zero(int fd, uint64_t offset, uint64_t size);
|
|||
json11::Json read_parttable(std::string dev);
|
||||
uint64_t dev_size_from_parttable(json11::Json pt);
|
||||
uint64_t free_from_parttable(json11::Json pt);
|
||||
int fix_partition_type(std::string dev_by_uuid);
|
||||
int fix_partition_type_uuid(std::string dev_by_uuid, const std::string & type_uuid);
|
||||
std::string csum_type_str(uint32_t data_csum_type);
|
||||
uint32_t csum_type_from_str(std::string data_csum_type);
|
||||
|
|
|
@ -159,7 +159,11 @@ int disk_tool_t::prepare_one(std::map<std::string, std::string> options, int is_
|
|||
return 1;
|
||||
}
|
||||
std::string osd_num_str;
|
||||
if (shell_exec({ "vitastor-cli", "alloc-osd" }, "", &osd_num_str, NULL) != 0)
|
||||
if (test_mode && options.find("osd_num") != options.end())
|
||||
{
|
||||
osd_num_str = options["osd_num"];
|
||||
}
|
||||
else if (shell_exec({ "vitastor-cli", "alloc-osd" }, "", &osd_num_str, NULL) != 0)
|
||||
{
|
||||
dsk.close_all();
|
||||
return 1;
|
||||
|
@ -199,11 +203,14 @@ int disk_tool_t::prepare_one(std::map<std::string, std::string> options, int is_
|
|||
if (sep_j)
|
||||
desc += (sep_m ? " and journal on " : " with journal on ") + realpath_str(options["journal_device"]);
|
||||
fprintf(stderr, "Initialized OSD %ju on %s\n", osd_num, desc.c_str());
|
||||
if (!test_mode || options.find("no_init") == options.end())
|
||||
{
|
||||
if (shell_exec({ "systemctl", "enable", "--now", "vitastor-osd@"+std::to_string(osd_num) }, "", NULL, NULL) != 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to enable systemd unit vitastor-osd@%ju\n", osd_num);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -229,6 +236,16 @@ int disk_tool_t::check_existing_partition(const std::string & dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int disk_tool_t::fix_partition_type(const std::string & dev)
|
||||
{
|
||||
std::string type_uuid = VITASTOR_PART_TYPE;
|
||||
if (test_mode && options.find("part_type_uuid") != options.end())
|
||||
{
|
||||
type_uuid = options["part_type_uuid"];
|
||||
}
|
||||
return fix_partition_type_uuid(dev, type_uuid);
|
||||
}
|
||||
|
||||
std::vector<vitastor_dev_info_t> disk_tool_t::collect_devices(const std::vector<std::string> & devices)
|
||||
{
|
||||
std::vector<vitastor_dev_info_t> devinfo;
|
||||
|
|
|
@ -343,7 +343,7 @@ uint64_t free_from_parttable(json11::Json pt)
|
|||
return free;
|
||||
}
|
||||
|
||||
int fix_partition_type(std::string dev_by_uuid)
|
||||
int fix_partition_type_uuid(std::string dev_by_uuid, const std::string & type_uuid)
|
||||
{
|
||||
auto uuid = strtolower(dev_by_uuid.substr(dev_by_uuid.rfind('/')+1));
|
||||
std::string parent_dev = get_parent_device(realpath_str(dev_by_uuid, false));
|
||||
|
@ -356,7 +356,7 @@ int fix_partition_type(std::string dev_by_uuid)
|
|||
for (const auto & part: pt["partitions"].array_items())
|
||||
{
|
||||
bool this_part = (strtolower(part["uuid"].string_value()) == uuid);
|
||||
if (this_part && strtolower(part["type"].string_value()) == "e7009fac-a5a1-4d72-af72-53de13059903")
|
||||
if (this_part && strtolower(part["type"].string_value()) == type_uuid)
|
||||
{
|
||||
// Already correct type
|
||||
return 0;
|
||||
|
@ -369,7 +369,7 @@ int fix_partition_type(std::string dev_by_uuid)
|
|||
{
|
||||
script += (first ? "" : ", ")+kv.first+"="+
|
||||
(kv.first == "type" && this_part
|
||||
? "e7009fac-a5a1-4d72-af72-53de13059903"
|
||||
? type_uuid
|
||||
: (kv.second.is_string() ? kv.second.string_value() : kv.second.dump()));
|
||||
first = false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue