Compare commits
2 Commits
d1dc11aad0
...
f7eb7621fc
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | f7eb7621fc | |
Vitaliy Filippov | 005f06bf25 |
|
@ -39,6 +39,8 @@ int disk_tool_t::resize_data(std::string device)
|
|||
return 1;
|
||||
}
|
||||
dsk.close_all();
|
||||
auto old_journal_device = dsk.journal_device;
|
||||
auto old_meta_device = dsk.meta_device;
|
||||
new_data_offset = dsk.data_offset;
|
||||
new_meta_offset = dsk.meta_offset;
|
||||
new_journal_len = dsk.journal_len;
|
||||
|
@ -74,20 +76,59 @@ int disk_tool_t::resize_data(std::string device)
|
|||
options = sb_params;
|
||||
for (auto & kv: move_options)
|
||||
options[kv.first] = kv.second;
|
||||
if (orig_options.find("dry_run") != orig_options.end())
|
||||
bool dry_run = orig_options.find("dry_run") != orig_options.end();
|
||||
if (!json)
|
||||
{
|
||||
if (json)
|
||||
printf("%s\n", json11::Json(options).dump().c_str());
|
||||
else
|
||||
{
|
||||
std::string cmd = "vitastor-disk resize";
|
||||
for (auto & kv: options)
|
||||
std::string cmd;
|
||||
for (auto & kv: move_options)
|
||||
cmd += " --"+kv.first+" "+kv.second;
|
||||
printf("%s\n", cmd.c_str());
|
||||
fprintf(stderr, "Running resize%s\n", cmd.c_str());
|
||||
}
|
||||
if (!dry_run && raw_resize() != 0)
|
||||
return 1;
|
||||
// Write new superblocks
|
||||
json11::Json::object new_sb_params = sb["params"].object_items();
|
||||
if (move_options.find("new_journal_device") != move_options.end())
|
||||
new_sb_params["journal_device"] = move_options["new_journal_device"];
|
||||
if (move_options.find("new_meta_device") != move_options.end())
|
||||
new_sb_params["meta_device"] = move_options["new_meta_device"];
|
||||
new_sb_params["data_offset"] = new_data_offset;
|
||||
new_sb_params["meta_offset"] = new_meta_offset;
|
||||
if (move_options.find("new_data_len") != move_options.end())
|
||||
new_sb_params["data_size"] = stoull_full(move_options["new_data_len"]);
|
||||
std::set<std::string> clear_superblocks, write_superblocks;
|
||||
auto new_journal_device = move_options.find("new_journal_device") != move_options.end()
|
||||
? move_options["new_journal_device"] : dsk.journal_device;
|
||||
auto new_meta_device = move_options.find("new_meta_device") != move_options.end()
|
||||
? move_options["new_meta_device"] : dsk.meta_device;
|
||||
write_superblocks.insert(dsk.data_device);
|
||||
write_superblocks.insert(new_journal_device);
|
||||
write_superblocks.insert(new_meta_device);
|
||||
if (write_superblocks.find(old_journal_device) == write_superblocks.end())
|
||||
clear_superblocks.insert(old_journal_device);
|
||||
if (write_superblocks.find(old_meta_device) == write_superblocks.end())
|
||||
clear_superblocks.insert(old_meta_device);
|
||||
for (auto & dev: clear_superblocks)
|
||||
{
|
||||
if (!json)
|
||||
fprintf(stderr, "Clearing OSD superblock on %s\n", dev.c_str());
|
||||
if (!dry_run && !clear_osd_superblock(dev))
|
||||
return 1;
|
||||
}
|
||||
for (auto & dev: write_superblocks)
|
||||
{
|
||||
if (!json)
|
||||
fprintf(stderr, "Writing new OSD superblock to %s\n", dev.c_str());
|
||||
if (!dry_run && !write_osd_superblock(dev, new_sb_params))
|
||||
return 1;
|
||||
}
|
||||
if (json)
|
||||
{
|
||||
printf("%s\n", json11::Json(json11::Json::object {
|
||||
{ "new_sb_params", new_sb_params },
|
||||
}).dump().c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return raw_resize();
|
||||
}
|
||||
|
||||
int disk_tool_t::resize_parse_move_journal(std::map<std::string, std::string> & move_options)
|
||||
|
|
|
@ -384,6 +384,7 @@ int disk_tool_t::pre_exec_osd(std::string device)
|
|||
|
||||
int disk_tool_t::clear_osd_superblock(const std::string & dev)
|
||||
{
|
||||
uint8_t *buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
|
||||
int fd = -1, r = open(dev.c_str(), O_DIRECT|O_RDWR);
|
||||
if (r >= 0)
|
||||
{
|
||||
|
@ -404,6 +405,8 @@ int disk_tool_t::clear_osd_superblock(const std::string & dev)
|
|||
}
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -465,7 +468,6 @@ int disk_tool_t::purge_devices(const std::vector<std::string> & devices)
|
|||
return 1;
|
||||
}
|
||||
// Destroy OSD superblocks
|
||||
uint8_t *buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096);
|
||||
for (auto & sb: superblocks)
|
||||
{
|
||||
for (auto dev_type: std::vector<std::string>{ "data", "meta", "journal" })
|
||||
|
@ -523,7 +525,5 @@ int disk_tool_t::purge_devices(const std::vector<std::string> & devices)
|
|||
}
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue