Make get_parent_device return full path
This commit is contained in:
@@ -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+"/queue/rotational")) == "1";
|
||||
is_hdd = trim(read_file("/sys/block/"+parent_dev.substr(5)+"/queue/rotational")) == "1";
|
||||
if (check_existing_partition(dev) != 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -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("/dev/"+parent_dev);
|
||||
auto pt = read_parttable(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 = "/dev/"+parent_dev,
|
||||
.path = 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", "/dev/"+parent_dev }, "", &out, NULL);
|
||||
shell_exec({ "partprobe", parent_dev }, "", &out, NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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+"/device/scsi_disk";
|
||||
auto scsi_disk = "/sys/block/"+parent_dev.substr(5)+"/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);
|
||||
return check_queue_cache(dev.substr(5), parent_dev.substr(5));
|
||||
}
|
||||
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);
|
||||
return check_queue_cache(dev.substr(5), parent_dev.substr(5));
|
||||
}
|
||||
scsi_disk += "/";
|
||||
scsi_disk += de->d_name;
|
||||
@@ -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;
|
||||
return "/dev/"+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;
|
||||
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)
|
||||
@@ -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("/dev/"+parent_dev);
|
||||
auto pt = read_parttable(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", "/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)
|
||||
|
||||
Reference in New Issue
Block a user