From 6917a32ca8af3140e363f28b127f11ac85d0254f Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 17 Dec 2022 02:47:15 +0300 Subject: [PATCH] Add --force to vitastor-disk read-sb --- src/disk_tool.cpp | 3 ++- src/disk_tool.h | 2 +- src/disk_tool_udev.cpp | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/disk_tool.cpp b/src/disk_tool.cpp index 2fce0ecc..e293711a 100644 --- a/src/disk_tool.cpp +++ b/src/disk_tool.cpp @@ -109,8 +109,9 @@ static const char *help_text = " Commands are passed to systemctl with vitastor-osd@ units as arguments.\n" " When --now is added to enable/disable, OSDs are also immediately started/stopped.\n" "\n" - "vitastor-disk read-sb \n" + "vitastor-disk read-sb [--force] \n" " Try to read Vitastor OSD superblock from and print it in JSON format.\n" + " --force allows to bypass \"does not refer to the device itself\" errors.\n" "\n" "vitastor-disk write-sb \n" " Read JSON from STDIN and write it into Vitastor OSD superblock on .\n" diff --git a/src/disk_tool.h b/src/disk_tool.h index f69bf0b7..7580927b 100644 --- a/src/disk_tool.h +++ b/src/disk_tool.h @@ -111,7 +111,7 @@ struct disk_tool_t int systemd_start_stop_osds(std::vector cmd, std::vector devices); int pre_exec_osd(std::string device); - json11::Json read_osd_superblock(std::string device, bool expect_exist = true); + json11::Json read_osd_superblock(std::string device, bool expect_exist = true, bool ignore_nonref = false); uint32_t write_osd_superblock(std::string device, json11::Json params); int prepare_one(std::map options, int is_hdd = -1); diff --git a/src/disk_tool_udev.cpp b/src/disk_tool_udev.cpp index e78dce70..bd4056ce 100644 --- a/src/disk_tool_udev.cpp +++ b/src/disk_tool_udev.cpp @@ -54,7 +54,7 @@ int disk_tool_t::udev_import(std::string device) int disk_tool_t::read_sb(std::string device) { - json11::Json sb = read_osd_superblock(device); + json11::Json sb = read_osd_superblock(device, true, options.find("force") != options.end()); if (sb.is_null()) { return 1; @@ -123,7 +123,7 @@ uint32_t disk_tool_t::write_osd_superblock(std::string device, json11::Json para return sb_size; } -json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_exist) +json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_exist, bool ignore_nonref) { vitastor_disk_superblock_t *sb = NULL; uint8_t *buf = NULL; @@ -226,7 +226,7 @@ json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_ex { device_type = "journal"; } - else + else if (!ignore_nonref) { if (expect_exist) fprintf(stderr, "Invalid OSD superblock on %s: does not refer to the device itself\n", device.c_str());