Compare commits

..

3 Commits

Author SHA1 Message Date
Vitaliy Filippov e518ad98f5 WIP Implement resizing partitions created with vitastor-disk
Test / test_root_node (push) Successful in 7s Details
Test / test_dd (push) Successful in 13s Details
Test / test_rebalance_verify_ec (push) Successful in 1m39s Details
Test / test_rebalance_verify_ec_imm (push) Successful in 1m41s Details
Test / test_write_no_same (push) Successful in 8s Details
Test / test_switch_primary (push) Successful in 32s Details
Test / test_write (push) Successful in 32s Details
Test / test_write_xor (push) Successful in 34s Details
Test / test_heal_pg_size_2 (push) Successful in 2m14s Details
Test / test_heal_antietcd (push) Successful in 2m17s Details
Test / test_heal_csum_32k_dmj (push) Successful in 2m17s Details
Test / test_heal_ec (push) Successful in 2m35s Details
Test / test_heal_csum_32k_dj (push) Successful in 2m18s Details
Test / test_heal_csum_32k (push) Successful in 2m17s Details
Test / test_heal_csum_4k_dmj (push) Successful in 2m18s Details
Test / test_heal_csum_4k_dj (push) Successful in 2m13s Details
Test / test_snapshot_pool2 (push) Successful in 13s Details
Test / test_osd_tags (push) Successful in 7s Details
Test / test_enospc (push) Successful in 11s Details
Test / test_enospc_imm (push) Successful in 10s Details
Test / test_enospc_xor (push) Successful in 12s Details
Test / test_enospc_imm_xor (push) Successful in 12s Details
Test / test_scrub (push) Successful in 13s Details
Test / test_scrub_zero_osd_2 (push) Successful in 13s Details
Test / test_scrub_xor (push) Successful in 14s Details
Test / test_scrub_pg_size_3 (push) Successful in 15s Details
Test / test_scrub_pg_size_6_pg_minsize_4_osd_count_6_ec (push) Successful in 15s Details
Test / test_scrub_ec (push) Successful in 12s Details
Test / test_nfs (push) Successful in 10s Details
Test / test_heal_csum_4k (push) Successful in 2m18s Details
2024-10-12 11:55:49 +03:00
Vitaliy Filippov 005f06bf25 Extract clear_osd_superblock() 2024-10-12 11:54:39 +03:00
Vitaliy Filippov 70acd8137e Extract check_existing_partition(), get_device_size() 2024-10-12 00:40:39 +03:00
5 changed files with 27 additions and 33 deletions

View File

@ -141,7 +141,7 @@ void disk_tool_simple_offsets(json11::Json cfg, bool json_output);
uint64_t sscanf_json(const char *fmt, const json11::Json & str);
void fromhexstr(const std::string & from, int bytes, uint8_t *to);
int disable_cache(std::string dev);
uint64_t get_device_size(const std::string & dev, bool should_exist = false);
uint64_t get_device_size(const std::string & dev);
std::string get_parent_device(std::string dev);
int shell_exec(const std::vector<std::string> & cmd, const std::string & in, std::string *out, std::string *err);
int write_zero(int fd, uint64_t offset, uint64_t size);

View File

@ -53,7 +53,7 @@ int disk_tool_t::prepare_one(std::map<std::string, std::string> options, int is_
return 1;
}
if (i == 0 && is_hdd == -1)
is_hdd = trim(read_file("/sys/block/"+parent_dev.substr(5)+"/queue/rotational")) == "1";
is_hdd = trim(read_file("/sys/block/"+parent_dev+"/queue/rotational")) == "1";
if (check_existing_partition(dev) != 0)
return 1;
}
@ -241,12 +241,12 @@ std::vector<vitastor_dev_info_t> disk_tool_t::collect_devices(const std::vector<
continue;
}
struct stat sys_st;
uint64_t dev_size = get_device_size(dev, false);
if (dev_size == UINT64_MAX)
uint64_t dev_size = get_device_size(dev);
if (!dev_size)
{
return {};
}
else if (!dev_size)
else if (dev_size == UINT64_MAX)
{
fprintf(stderr, "%s does not exist, skipping\n", dev.c_str());
continue;

View File

@ -22,6 +22,7 @@ int disk_tool_t::resize_data(std::string device)
if (sb.is_null())
return 1;
auto sb_params = json_to_string_map(sb["params"].object_items());
blockstore_disk_t dsk;
try
{
dsk.parse_config(sb_params);
@ -178,7 +179,7 @@ int disk_tool_t::resize_parse_move_journal(std::map<std::string, std::string> &
auto new_parts = add_partitions(devinfos[0], sizes);
if (!new_parts.array_items().size())
return 1;
options["move_journal"] = "/dev/disk/by-partuuid/"+strtolower(new_parts[0]["uuid"].string_value());
options["move_journal"] = "/dev/disk/by-partuuid/"+new_parts[0]["uuid"].string_value();
}
else if (options["move_journal"].substr(0, 22) != "/dev/disk/by-partuuid/")
{
@ -195,10 +196,7 @@ int disk_tool_t::resize_parse_move_journal(std::map<std::string, std::string> &
return 1;
}
}
new_journal_len = get_device_size(options["move_journal"], true);
if (new_journal_len == UINT64_MAX)
return 1;
new_journal_len -= 4096;
new_journal_len = get_device_size(options["move_journal"]) - 4096;
move_options["new_journal_device"] = options["move_journal"];
move_options["new_journal_offset"] = "4096";
move_options["new_journal_len"] = std::to_string(new_journal_len);
@ -257,7 +255,7 @@ int disk_tool_t::resize_parse_move_meta(std::map<std::string, std::string> & mov
auto new_parts = add_partitions(devinfos[0], sizes);
if (!new_parts.array_items().size())
return 1;
options["move_meta"] = "/dev/disk/by-partuuid/"+strtolower(new_parts[0]["uuid"].string_value());
options["move_meta"] = "/dev/disk/by-partuuid/"+new_parts[0]["uuid"].string_value();
}
else if (options["move_meta"].substr(0, 22) != "/dev/disk/by-partuuid/")
{
@ -274,11 +272,7 @@ int disk_tool_t::resize_parse_move_meta(std::map<std::string, std::string> & mov
return 1;
}
}
auto new_meta_len = get_device_size(options["move_meta"], true);
if (new_meta_len == UINT64_MAX)
return 1;
new_meta_len -= 4096;
move_options["new_meta_len"] = std::to_string(new_meta_len);
move_options["new_meta_len"] = std::to_string(get_device_size(options["move_meta"]) - 4096);
move_options["new_meta_device"] = options["move_meta"];
move_options["new_meta_offset"] = "4096";
if (dsk.meta_device == dsk.data_device)

View File

@ -496,7 +496,7 @@ int disk_tool_t::purge_devices(const std::vector<std::string> & devices)
fprintf(stderr, "Failed to delete partition %s: failed to find parent device\n", dev.c_str());
continue;
}
auto pt = read_parttable(parent_dev);
auto pt = read_parttable("/dev/"+parent_dev);
if (!pt.is_object())
continue;
json11::Json::array newpt = pt["partitions"].array_items();
@ -507,7 +507,7 @@ int disk_tool_t::purge_devices(const std::vector<std::string> & devices)
auto old_part = newpt[i];
newpt.erase(newpt.begin()+i, newpt.begin()+i+1);
vitastor_dev_info_t devinfo = {
.path = parent_dev,
.path = "/dev/"+parent_dev,
.pt = json11::Json::object{ { "partitions", newpt } },
};
add_partitions(devinfo, {});
@ -516,7 +516,7 @@ int disk_tool_t::purge_devices(const std::vector<std::string> & devices)
errno != ENOENT)
{
std::string out;
shell_exec({ "partprobe", parent_dev }, "", &out, NULL);
shell_exec({ "partprobe", "/dev/"+parent_dev }, "", &out, NULL);
}
break;
}

View File

@ -60,14 +60,14 @@ int disable_cache(std::string dev)
auto parent_dev = get_parent_device(dev);
if (parent_dev == "")
return 1;
auto scsi_disk = "/sys/block/"+parent_dev.substr(5)+"/device/scsi_disk";
auto scsi_disk = "/sys/block/"+parent_dev+"/device/scsi_disk";
DIR *dir = opendir(scsi_disk.c_str());
if (!dir)
{
if (errno == ENOENT)
{
// Not a SCSI/SATA device, just check /sys/block/.../queue/write_cache
return check_queue_cache(dev.substr(5), parent_dev.substr(5));
return check_queue_cache(dev.substr(5), parent_dev);
}
else
{
@ -84,7 +84,7 @@ int disable_cache(std::string dev)
{
// Not a SCSI/SATA device, just check /sys/block/.../queue/write_cache
closedir(dir);
return check_queue_cache(dev.substr(5), parent_dev.substr(5));
return check_queue_cache(dev.substr(5), parent_dev);
}
scsi_disk += "/";
scsi_disk += de->d_name;
@ -117,17 +117,17 @@ int disable_cache(std::string dev)
return 0;
}
uint64_t get_device_size(const std::string & dev, bool should_exist)
uint64_t get_device_size(const std::string & dev)
{
struct stat dev_st;
if (stat(dev.c_str(), &dev_st) < 0)
{
if (errno == ENOENT && !should_exist)
if (errno == ENOENT)
{
return 0;
return UINT64_MAX;
}
fprintf(stderr, "Error checking %s: %s\n", dev.c_str(), strerror(errno));
return UINT64_MAX;
return 0;
}
uint64_t dev_size = dev_st.st_size;
if (S_ISBLK(dev_st.st_mode))
@ -136,13 +136,13 @@ uint64_t get_device_size(const std::string & dev, bool should_exist)
if (fd < 0)
{
fprintf(stderr, "Failed to open %s: %s\n", dev.c_str(), strerror(errno));
return UINT64_MAX;
return 0;
}
if (ioctl(fd, BLKGETSIZE64, &dev_size) < 0)
{
fprintf(stderr, "Failed to get %s size: %s\n", dev.c_str(), strerror(errno));
close(fd);
return UINT64_MAX;
return 0;
}
close(fd);
}
@ -163,7 +163,7 @@ std::string get_parent_device(std::string dev)
if (stat(chk.c_str(), &st) == 0)
{
// present in /sys/block/ - not a partition
return "/dev/"+dev;
return dev;
}
else if (errno != ENOENT)
{
@ -184,9 +184,9 @@ std::string get_parent_device(std::string dev)
fprintf(stderr, "Failed to stat %s: %s\n", chk.c_str(), strerror(errno));
return "";
}
return "/dev/"+dev;
return dev;
}
return "/dev/"+dev.substr(0, i);
return dev.substr(0, i);
}
int shell_exec(const std::vector<std::string> & cmd, const std::string & in, std::string *out, std::string *err)
@ -349,7 +349,7 @@ int fix_partition_type(std::string dev_by_uuid)
std::string parent_dev = get_parent_device(realpath_str(dev_by_uuid, false));
if (parent_dev == "")
return 1;
auto pt = read_parttable(parent_dev);
auto pt = read_parttable("/dev/"+parent_dev);
if (pt.is_null() || pt.is_bool())
return 1;
std::string script = "label: gpt\n\n";
@ -377,7 +377,7 @@ int fix_partition_type(std::string dev_by_uuid)
script += "\n";
}
std::string out;
return shell_exec({ "sfdisk", "--no-reread", "--force", parent_dev }, script, &out, NULL);
return shell_exec({ "sfdisk", "--no-reread", "--force", "/dev/"+parent_dev }, script, &out, NULL);
}
std::string csum_type_str(uint32_t data_csum_type)