Fix bugs in the upgrade script and in the udev startup script
This commit is contained in:
@@ -254,6 +254,15 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
return self.exec_osd(cmd[1]);
|
||||
}
|
||||
else if (!strcmp(cmd[0], "pre-exec"))
|
||||
{
|
||||
if (cmd.size() != 2)
|
||||
{
|
||||
fprintf(stderr, "Exactly 1 device path argument is required\n");
|
||||
return 1;
|
||||
}
|
||||
return self.pre_exec_osd(cmd[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
print_help(help_text, "vitastor-disk", cmd.size() > 1 ? cmd[1] : "", self.all);
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ void disk_tool_simple_offsets(json11::Json cfg, bool json_output);
|
||||
|
||||
std::string realpath_str(std::string path, bool nofail = true);
|
||||
std::string read_all_fd(int fd);
|
||||
std::string read_file(std::string file);
|
||||
std::string read_file(std::string file, bool allow_enoent = false);
|
||||
int check_queue_cache(std::string dev, std::string parent_dev);
|
||||
std::string get_parent_device(std::string dev);
|
||||
bool json_is_true(const json11::Json & val);
|
||||
|
||||
@@ -43,7 +43,7 @@ int disk_tool_t::udev_import(std::string device)
|
||||
uint64_t osd_num = sb["params"]["osd_num"].uint64_value();
|
||||
// Print variables for udev
|
||||
printf("VITASTOR_OSD_NUM=%lu\n", osd_num);
|
||||
printf("VITASTOR_ALIAS=osd%lu%s\n", osd_num, sb["device_type"].string_value().c_str());
|
||||
printf("VITASTOR_ALIAS=osd%lu-%s\n", osd_num, sb["device_type"].string_value().c_str());
|
||||
printf("VITASTOR_DATA_DEVICE=%s\n", udev_escape(sb["params"]["data_device"].string_value()).c_str());
|
||||
if (sb["real_meta_device"].string_value() != "" && sb["real_meta_device"] != sb["real_data_device"])
|
||||
printf("VITASTOR_META_DEVICE=%s\n", udev_escape(sb["params"]["meta_device"].string_value()).c_str());
|
||||
@@ -201,9 +201,9 @@ json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_ex
|
||||
}
|
||||
real_device = realpath_str(device);
|
||||
real_data = realpath_str(osd_params["data_device"].string_value());
|
||||
real_meta = osd_params["meta_device"] != "" && osd_params["meta_device"] != osd_params["data_device"]
|
||||
real_meta = osd_params["meta_device"].string_value() != "" && osd_params["meta_device"] != osd_params["data_device"]
|
||||
? realpath_str(osd_params["meta_device"].string_value()) : "";
|
||||
real_journal = osd_params["journal_device"] != "" && osd_params["journal_device"] != osd_params["meta_device"]
|
||||
real_journal = osd_params["journal_device"].string_value() != "" && osd_params["journal_device"] != osd_params["meta_device"]
|
||||
? realpath_str(osd_params["journal_device"].string_value()) : "";
|
||||
if (real_journal == real_meta)
|
||||
{
|
||||
@@ -322,7 +322,7 @@ static int disable_cache(std::string dev)
|
||||
if (errno == ENOENT)
|
||||
{
|
||||
// Not a SCSI/SATA device, just check /sys/block/.../queue/write_cache
|
||||
return check_queue_cache(dev, parent_dev);
|
||||
return check_queue_cache(dev.substr(5), parent_dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -339,7 +339,7 @@ static 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, parent_dev);
|
||||
return check_queue_cache(dev.substr(5), parent_dev);
|
||||
}
|
||||
scsi_disk += "/";
|
||||
scsi_disk += de->d_name;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "disk_tool.h"
|
||||
#include "rw_blocking.h"
|
||||
#include "str_util.h"
|
||||
|
||||
std::string realpath_str(std::string path, bool nofail)
|
||||
{
|
||||
@@ -36,15 +37,17 @@ std::string read_all_fd(int fd)
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string read_file(std::string file)
|
||||
std::string read_file(std::string file, bool allow_enoent)
|
||||
{
|
||||
std::string res;
|
||||
int fd = open(file.c_str(), O_RDONLY);
|
||||
if (fd < 0 || (res = read_all_fd(fd)) == "")
|
||||
{
|
||||
int err = errno;
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
fprintf(stderr, "Can't read %s: %s\n", file.c_str(), strerror(errno));
|
||||
if (!allow_enoent || err != ENOENT)
|
||||
fprintf(stderr, "Can't read %s: %s\n", file.c_str(), strerror(err));
|
||||
return "";
|
||||
}
|
||||
close(fd);
|
||||
@@ -53,12 +56,12 @@ std::string read_file(std::string file)
|
||||
|
||||
int check_queue_cache(std::string dev, std::string parent_dev)
|
||||
{
|
||||
auto r = read_file("/sys/block/"+dev+"/queue/write_cache");
|
||||
auto r = read_file("/sys/block/"+dev+"/queue/write_cache", true);
|
||||
if (r == "")
|
||||
r = read_file("/sys/block/"+parent_dev+"/queue/write_cache");
|
||||
if (r == "")
|
||||
return 1;
|
||||
return r == "write through" ? 0 : -1;
|
||||
return trim(r) == "write through" ? 0 : -1;
|
||||
}
|
||||
|
||||
std::string get_parent_device(std::string dev)
|
||||
|
||||
Reference in New Issue
Block a user