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