Compare commits

..

4 Commits

Author SHA1 Message Date
Vitaliy Filippov aeeb73e40a WIP Implement resizing partitions created with vitastor-disk
Test / test_dd (push) Successful in 13s Details
Test / test_rebalance_verify_ec (push) Successful in 1m41s Details
Test / test_root_node (push) Successful in 11s Details
Test / test_rebalance_verify_ec_imm (push) Successful in 1m43s Details
Test / test_write_no_same (push) Successful in 7s Details
Test / test_write (push) Successful in 30s Details
Test / test_switch_primary (push) Successful in 33s Details
Test / test_write_xor (push) Successful in 34s Details
Test / test_heal_pg_size_2 (push) Successful in 2m14s Details
Test / test_heal_ec (push) Successful in 2m15s Details
Test / test_heal_antietcd (push) Successful in 2m15s Details
Test / test_heal_csum_32k_dmj (push) Successful in 2m18s 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 2m18s Details
Test / test_osd_tags (push) Successful in 8s Details
Test / test_snapshot_pool2 (push) Successful in 14s Details
Test / test_enospc (push) Successful in 10s Details
Test / test_enospc_xor (push) Successful in 12s Details
Test / test_enospc_imm (push) Successful in 9s Details
Test / test_enospc_imm_xor (push) Successful in 11s Details
Test / test_scrub (push) Successful in 12s Details
Test / test_scrub_zero_osd_2 (push) Successful in 12s Details
Test / test_scrub_xor (push) Successful in 12s Details
Test / test_scrub_pg_size_3 (push) Successful in 14s Details
Test / test_scrub_pg_size_6_pg_minsize_4_osd_count_6_ec (push) Successful in 14s Details
Test / test_scrub_ec (push) Successful in 13s Details
Test / test_nfs (push) Successful in 10s Details
Test / test_heal_csum_4k (push) Successful in 2m9s Details
2024-10-12 13:45:07 +03:00
Vitaliy Filippov d27a8bdabc Make get_parent_device return full path 2024-10-12 13:44:52 +03:00
Vitaliy Filippov ebd616e42f Extract clear_osd_superblock() 2024-10-12 13:44:52 +03:00
Vitaliy Filippov b18d296e01 Extract check_existing_partition(), get_device_size() 2024-10-12 13:44:52 +03:00
5 changed files with 33 additions and 27 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); uint64_t sscanf_json(const char *fmt, const json11::Json & str);
void fromhexstr(const std::string & from, int bytes, uint8_t *to); void fromhexstr(const std::string & from, int bytes, uint8_t *to);
int disable_cache(std::string dev); int disable_cache(std::string dev);
uint64_t get_device_size(const std::string & dev); uint64_t get_device_size(const std::string & dev, bool should_exist = false);
std::string get_parent_device(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 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); 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; return 1;
} }
if (i == 0 && is_hdd == -1) if (i == 0 && is_hdd == -1)
is_hdd = trim(read_file("/sys/block/"+parent_dev+"/queue/rotational")) == "1"; is_hdd = trim(read_file("/sys/block/"+parent_dev.substr(5)+"/queue/rotational")) == "1";
if (check_existing_partition(dev) != 0) if (check_existing_partition(dev) != 0)
return 1; return 1;
} }
@ -241,12 +241,12 @@ std::vector<vitastor_dev_info_t> disk_tool_t::collect_devices(const std::vector<
continue; continue;
} }
struct stat sys_st; struct stat sys_st;
uint64_t dev_size = get_device_size(dev); uint64_t dev_size = get_device_size(dev, false);
if (!dev_size) if (dev_size == UINT64_MAX)
{ {
return {}; return {};
} }
else if (dev_size == UINT64_MAX) else if (!dev_size)
{ {
fprintf(stderr, "%s does not exist, skipping\n", dev.c_str()); fprintf(stderr, "%s does not exist, skipping\n", dev.c_str());
continue; continue;

View File

@ -22,7 +22,6 @@ int disk_tool_t::resize_data(std::string device)
if (sb.is_null()) if (sb.is_null())
return 1; return 1;
auto sb_params = json_to_string_map(sb["params"].object_items()); auto sb_params = json_to_string_map(sb["params"].object_items());
blockstore_disk_t dsk;
try try
{ {
dsk.parse_config(sb_params); dsk.parse_config(sb_params);
@ -179,7 +178,7 @@ int disk_tool_t::resize_parse_move_journal(std::map<std::string, std::string> &
auto new_parts = add_partitions(devinfos[0], sizes); auto new_parts = add_partitions(devinfos[0], sizes);
if (!new_parts.array_items().size()) if (!new_parts.array_items().size())
return 1; return 1;
options["move_journal"] = "/dev/disk/by-partuuid/"+new_parts[0]["uuid"].string_value(); options["move_journal"] = "/dev/disk/by-partuuid/"+strtolower(new_parts[0]["uuid"].string_value());
} }
else if (options["move_journal"].substr(0, 22) != "/dev/disk/by-partuuid/") else if (options["move_journal"].substr(0, 22) != "/dev/disk/by-partuuid/")
{ {
@ -196,7 +195,10 @@ int disk_tool_t::resize_parse_move_journal(std::map<std::string, std::string> &
return 1; return 1;
} }
} }
new_journal_len = get_device_size(options["move_journal"]) - 4096; new_journal_len = get_device_size(options["move_journal"], true);
if (new_journal_len == UINT64_MAX)
return 1;
new_journal_len -= 4096;
move_options["new_journal_device"] = options["move_journal"]; move_options["new_journal_device"] = options["move_journal"];
move_options["new_journal_offset"] = "4096"; move_options["new_journal_offset"] = "4096";
move_options["new_journal_len"] = std::to_string(new_journal_len); move_options["new_journal_len"] = std::to_string(new_journal_len);
@ -255,7 +257,7 @@ int disk_tool_t::resize_parse_move_meta(std::map<std::string, std::string> & mov
auto new_parts = add_partitions(devinfos[0], sizes); auto new_parts = add_partitions(devinfos[0], sizes);
if (!new_parts.array_items().size()) if (!new_parts.array_items().size())
return 1; return 1;
options["move_meta"] = "/dev/disk/by-partuuid/"+new_parts[0]["uuid"].string_value(); options["move_meta"] = "/dev/disk/by-partuuid/"+strtolower(new_parts[0]["uuid"].string_value());
} }
else if (options["move_meta"].substr(0, 22) != "/dev/disk/by-partuuid/") else if (options["move_meta"].substr(0, 22) != "/dev/disk/by-partuuid/")
{ {
@ -272,7 +274,11 @@ int disk_tool_t::resize_parse_move_meta(std::map<std::string, std::string> & mov
return 1; return 1;
} }
} }
move_options["new_meta_len"] = std::to_string(get_device_size(options["move_meta"]) - 4096); 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_device"] = options["move_meta"]; move_options["new_meta_device"] = options["move_meta"];
move_options["new_meta_offset"] = "4096"; move_options["new_meta_offset"] = "4096";
if (dsk.meta_device == dsk.data_device) 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()); fprintf(stderr, "Failed to delete partition %s: failed to find parent device\n", dev.c_str());
continue; continue;
} }
auto pt = read_parttable("/dev/"+parent_dev); auto pt = read_parttable(parent_dev);
if (!pt.is_object()) if (!pt.is_object())
continue; continue;
json11::Json::array newpt = pt["partitions"].array_items(); 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]; auto old_part = newpt[i];
newpt.erase(newpt.begin()+i, newpt.begin()+i+1); newpt.erase(newpt.begin()+i, newpt.begin()+i+1);
vitastor_dev_info_t devinfo = { vitastor_dev_info_t devinfo = {
.path = "/dev/"+parent_dev, .path = parent_dev,
.pt = json11::Json::object{ { "partitions", newpt } }, .pt = json11::Json::object{ { "partitions", newpt } },
}; };
add_partitions(devinfo, {}); add_partitions(devinfo, {});
@ -516,7 +516,7 @@ int disk_tool_t::purge_devices(const std::vector<std::string> & devices)
errno != ENOENT) errno != ENOENT)
{ {
std::string out; std::string out;
shell_exec({ "partprobe", "/dev/"+parent_dev }, "", &out, NULL); shell_exec({ "partprobe", parent_dev }, "", &out, NULL);
} }
break; break;
} }

View File

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