:)
This commit is contained in:
Generated
-989
@@ -1,989 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15af2628f6890fe2609a3b91bef4c83450512802e59489f9c1cb1fa5df064a61"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
|
||||
[[package]]
|
||||
name = "bitvec"
|
||||
version = "0.19.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321"
|
||||
dependencies = [
|
||||
"funty",
|
||||
"radium",
|
||||
"tap",
|
||||
"wyz",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "cassowary"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.33.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"atty",
|
||||
"bitflags",
|
||||
"strsim",
|
||||
"textwrap",
|
||||
"unicode-width",
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "console"
|
||||
version = "0.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45"
|
||||
dependencies = [
|
||||
"encode_unicode",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"terminal_size",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32c"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "210cdf933e6a81212bfabf90cd8762f471b5922e5f6b709547673ad8e04b9448"
|
||||
dependencies = [
|
||||
"rustc_version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "data-encoding"
|
||||
version = "2.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57"
|
||||
|
||||
[[package]]
|
||||
name = "duct"
|
||||
version = "0.13.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fc6a0a59ed0888e0041cf708e66357b7ae1a82f1c67247e1f93b5e0818f7d8d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"once_cell",
|
||||
"os_pipe",
|
||||
"shared_child",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encode_unicode"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
|
||||
dependencies = [
|
||||
"log",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "398ea4fabe40b9b0d885340a2a991a44c8a645624075ad966d21f88688e2b69e"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crc32fast",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "funty"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-executor",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1"
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1"
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"proc-macro-hack",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-macro",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
"proc-macro-hack",
|
||||
"proc-macro-nested",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.9.0+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.10.2+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indicatif"
|
||||
version = "0.16.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d207dc617c7a380ab07ff572a6e52fa202a2a8f355860ac9c38e23f8196be1b"
|
||||
dependencies = [
|
||||
"console",
|
||||
"lazy_static",
|
||||
"number_prefix",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-uring"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f7589adca0ddd74f56ed83a5098b45e3abf264dc27e150a8bec3397fcc34338"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "json"
|
||||
version = "0.12.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "lexical-core"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"ryu",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.102"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
|
||||
dependencies = [
|
||||
"adler",
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7555d6c7164cc913be1ce7f95cbecdabda61eb2ccd89008524af306fb7f5031"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"memoffset",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "6.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c5c51b9083a3c620fa67a2a635d1ce7d95b897e957d6b28ff9a5da960a103a6"
|
||||
dependencies = [
|
||||
"bitvec",
|
||||
"funty",
|
||||
"lexical-core",
|
||||
"memchr",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-derive"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "number_prefix"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
||||
|
||||
[[package]]
|
||||
name = "numtoa"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
|
||||
|
||||
[[package]]
|
||||
name = "os_pipe"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb233f06c2307e1f5ce2ecad9f8121cffbbee2c95428f44ea85222e460d0d213"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-hack"
|
||||
version = "0.5.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-nested"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.22.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8533f14c8382aaad0d592c812ac3b826162128b65662331e1127b45c3d18536b"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quickcheck"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a44883e74aa97ad63db83c4bf8ca490f02b2fc02f92575e720c8551e843c945f"
|
||||
dependencies = [
|
||||
"env_logger",
|
||||
"log",
|
||||
"rand 0.7.3",
|
||||
"rand_core 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quickcheck_macros"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "608c156fd8e97febc07dc9c2e2c80bf74cfc6ef26893eae3daf8bc2bc94a4b7f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "radium"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
|
||||
dependencies = [
|
||||
"getrandom 0.1.16",
|
||||
"libc",
|
||||
"rand_chacha 0.2.2",
|
||||
"rand_core 0.5.1",
|
||||
"rand_hc 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha 0.3.1",
|
||||
"rand_core 0.6.3",
|
||||
"rand_hc 0.3.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core 0.6.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||
dependencies = [
|
||||
"getrandom 0.1.16",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
||||
dependencies = [
|
||||
"getrandom 0.2.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||
dependencies = [
|
||||
"rand_core 0.5.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_hc"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
|
||||
dependencies = [
|
||||
"rand_core 0.6.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_termios"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
|
||||
dependencies = [
|
||||
"redox_syscall",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||
|
||||
[[package]]
|
||||
name = "remove_dir_all"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "safemem"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
dependencies = [
|
||||
"semver-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
|
||||
[[package]]
|
||||
name = "shared_child"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6be9f7d5565b1483af3e72975e2dee33879b3b86bd48c0929fccf6585d79e65a"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527"
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.73"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tap"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"rand 0.8.4",
|
||||
"redox_syscall",
|
||||
"remove_dir_all",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.1.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termion"
|
||||
version = "1.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"numtoa",
|
||||
"redox_syscall",
|
||||
"redox_termios",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thinp"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"atty",
|
||||
"base64",
|
||||
"byteorder",
|
||||
"clap",
|
||||
"crc32c",
|
||||
"data-encoding",
|
||||
"duct",
|
||||
"fixedbitset",
|
||||
"flate2",
|
||||
"futures",
|
||||
"indicatif",
|
||||
"io-uring",
|
||||
"json",
|
||||
"libc",
|
||||
"nix",
|
||||
"nom",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"num_cpus",
|
||||
"quick-xml",
|
||||
"quickcheck",
|
||||
"quickcheck_macros",
|
||||
"rand 0.8.4",
|
||||
"safemem",
|
||||
"tempfile",
|
||||
"termion",
|
||||
"thiserror",
|
||||
"threadpool",
|
||||
"tui",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "threadpool"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa"
|
||||
dependencies = [
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tui"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ced152a8e9295a5b168adc254074525c17ac4a83c90b2716274cc38118bddc9"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cassowary",
|
||||
"termion",
|
||||
"unicode-segmentation",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.9.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "wyz"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
[package]
|
||||
name = "thinp"
|
||||
version = "0.1.0"
|
||||
authors = ["Joe Thornber <ejt@redhat.com>"]
|
||||
edition = "2018"
|
||||
license = "GPL3"
|
||||
|
||||
[dependencies]
|
||||
atty = "0.2"
|
||||
anyhow = "1.0"
|
||||
base64 = "0.13"
|
||||
byteorder = "1.4"
|
||||
clap = "2.33"
|
||||
crc32c = "0.6"
|
||||
data-encoding = "2.3"
|
||||
duct = "0.13"
|
||||
fixedbitset = "0.4"
|
||||
futures = "0.3"
|
||||
flate2 = "1.0"
|
||||
io-uring = "0.4"
|
||||
indicatif = "0.16"
|
||||
libc = "0.2"
|
||||
nix = "0.22"
|
||||
nom = "6.2"
|
||||
num_cpus = "1.13"
|
||||
num-derive = "0.3"
|
||||
num-traits = "0.2"
|
||||
quick-xml = "0.22"
|
||||
rand = "0.8"
|
||||
safemem = "0.3"
|
||||
tempfile = "3.2"
|
||||
threadpool = "1.8"
|
||||
thiserror = "1.0"
|
||||
tui = "0.14"
|
||||
termion = "1.5"
|
||||
|
||||
[dev-dependencies]
|
||||
json = "0.12"
|
||||
quickcheck = "0.9"
|
||||
quickcheck_macros = "0.9"
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
||||
|
||||
[features]
|
||||
rust_tests = []
|
||||
+1
-14
@@ -344,20 +344,7 @@ install: bin/pdata_tools $(MANPAGES)
|
||||
$(INSTALL_DATA) man8/era_invalidate.8 $(MANPATH)/man8
|
||||
$(INSTALL_DATA) man8/thin_trim.8 $(MANPATH)/man8
|
||||
|
||||
.PHONY: install install-rust-tools rust-tools
|
||||
|
||||
rust-tools:
|
||||
cargo build --release
|
||||
|
||||
install-rust-tools: man8/thin_metadata_pack.8 man8/thin_metadata_unpack.8 rust-tools
|
||||
$(INSTALL_DIR) $(BINDIR)
|
||||
$(INSTALL_PROGRAM) target/release/thin_metadata_pack $(BINDIR)
|
||||
$(INSTALL_PROGRAM) target/release/thin_metadata_unpack $(BINDIR)
|
||||
$(STRIP) $(BINDIR)/thin_metadata_pack
|
||||
$(STRIP) $(BINDIR)/thin_metadata_unpack
|
||||
$(INSTALL_DIR) $(MANPATH)/man8
|
||||
$(INSTALL_DATA) man8/thin_metadata_pack.8 $(MANPATH)/man8
|
||||
$(INSTALL_DATA) man8/thin_metadata_unpack.8 $(MANPATH)/man8
|
||||
.PHONY: install
|
||||
|
||||
#----------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools_dev
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools_dev
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools_dev
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools_dev
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools_dev
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools_dev
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
../target/release/thin_metadata_pack
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
../target/release/thin_metadata_unpack
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools_dev
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools_dev
|
||||
@@ -1 +0,0 @@
|
||||
pdata_tools_dev
|
||||
@@ -1,79 +0,0 @@
|
||||
use anyhow::{anyhow, ensure, Result};
|
||||
use std::ffi::OsString;
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
use thinp::commands::*;
|
||||
|
||||
fn name_eq(name: &Path, cmd: &str) -> bool {
|
||||
name == Path::new(cmd)
|
||||
}
|
||||
|
||||
fn main_() -> Result<()> {
|
||||
let mut args = std::env::args_os();
|
||||
ensure!(args.len() > 0);
|
||||
|
||||
let mut os_name = args.next().unwrap();
|
||||
let mut name = Path::new(&os_name);
|
||||
name = Path::new(name.file_name().unwrap());
|
||||
|
||||
if name == Path::new("pdata_tools") {
|
||||
os_name = args.next().unwrap();
|
||||
name = Path::new(&os_name);
|
||||
}
|
||||
|
||||
let mut new_args = vec![OsString::from(&name)];
|
||||
for a in args.into_iter() {
|
||||
new_args.push(a);
|
||||
}
|
||||
|
||||
if name_eq(name, "cache_check") {
|
||||
cache_check::run(&new_args);
|
||||
} else if name_eq(name, "cache_dump") {
|
||||
cache_dump::run(&new_args);
|
||||
} else if name_eq(name, "cache_metadata_size") {
|
||||
cache_metadata_size::run(&new_args);
|
||||
} else if name_eq(name, "cache_repair") {
|
||||
cache_repair::run(&new_args);
|
||||
} else if name_eq(name, "cache_restore") {
|
||||
cache_restore::run(&new_args);
|
||||
} else if name_eq(name, "era_check") {
|
||||
era_check::run(&new_args);
|
||||
} else if name_eq(name, "era_dump") {
|
||||
era_dump::run(&new_args);
|
||||
} else if name_eq(name, "era_restore") {
|
||||
era_restore::run(&new_args);
|
||||
} else if name_eq(name, "thin_check") {
|
||||
thin_check::run(&new_args);
|
||||
} else if name_eq(name, "thin_dump") {
|
||||
thin_dump::run(&new_args);
|
||||
} else if name_eq(name, "thin_metadata_pack") {
|
||||
thin_metadata_pack::run(&new_args);
|
||||
} else if name_eq(name, "thin_metadata_size") {
|
||||
thin_metadata_size::run(&new_args);
|
||||
} else if name_eq(name, "thin_metadata_unpack") {
|
||||
thin_metadata_unpack::run(&new_args);
|
||||
} else if name_eq(name, "thin_repair") {
|
||||
thin_repair::run(&new_args);
|
||||
} else if name_eq(name, "thin_restore") {
|
||||
thin_restore::run(&new_args);
|
||||
} else if name_eq(name, "thin_shrink") {
|
||||
thin_shrink::run(&new_args);
|
||||
} else {
|
||||
return Err(anyhow!("unrecognised command"));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let code = match main_() {
|
||||
Ok(()) => 0,
|
||||
Err(_) => {
|
||||
// We don't print out the error since -q may be set
|
||||
// eprintln!("{}", e);
|
||||
1
|
||||
}
|
||||
};
|
||||
|
||||
exit(code)
|
||||
}
|
||||
@@ -1,867 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::{App, Arg};
|
||||
use std::fmt;
|
||||
use std::io::{self, Write};
|
||||
use std::path::Path;
|
||||
use std::sync::mpsc;
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use termion::event::Key;
|
||||
use termion::input::TermRead;
|
||||
use termion::raw::IntoRawMode;
|
||||
|
||||
use tui::{
|
||||
backend::TermionBackend,
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
terminal::Frame,
|
||||
text::Span,
|
||||
widgets::{Block, Borders, List, ListItem, ListState, Row, StatefulWidget, Table, Widget},
|
||||
Terminal,
|
||||
};
|
||||
|
||||
use thinp::io_engine::*;
|
||||
use thinp::pdata::btree;
|
||||
use thinp::pdata::unpack::*;
|
||||
use thinp::thin::block_time::*;
|
||||
use thinp::thin::device_detail::*;
|
||||
use thinp::thin::superblock::*;
|
||||
|
||||
//------------------------------------
|
||||
|
||||
pub enum Event<I> {
|
||||
Input(I),
|
||||
Tick,
|
||||
}
|
||||
|
||||
pub struct Events {
|
||||
rx: mpsc::Receiver<Event<Key>>,
|
||||
input_handle: thread::JoinHandle<()>,
|
||||
ignore_exit_key: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Config {
|
||||
pub exit_key: Key,
|
||||
pub tick_rate: Duration,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Config {
|
||||
Config {
|
||||
exit_key: Key::Char('q'),
|
||||
tick_rate: Duration::from_millis(250),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Events {
|
||||
pub fn new() -> Events {
|
||||
Events::with_config(Config::default())
|
||||
}
|
||||
|
||||
pub fn with_config(config: Config) -> Events {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let ignore_exit_key = Arc::new(AtomicBool::new(false));
|
||||
let input_handle = {
|
||||
let ignore_exit_key = ignore_exit_key.clone();
|
||||
thread::spawn(move || {
|
||||
let stdin = io::stdin();
|
||||
for key in stdin.keys().flatten() {
|
||||
if let Err(err) = tx.send(Event::Input(key)) {
|
||||
eprintln!("{}", err);
|
||||
return;
|
||||
}
|
||||
if !ignore_exit_key.load(Ordering::Relaxed) && key == config.exit_key {
|
||||
return;
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
Events {
|
||||
rx,
|
||||
input_handle,
|
||||
ignore_exit_key,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next(&self) -> Result<Event<Key>, mpsc::RecvError> {
|
||||
self.rx.recv()
|
||||
}
|
||||
|
||||
pub fn disable_exit_key(&mut self) {
|
||||
self.ignore_exit_key.store(true, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub fn enable_exit_key(&mut self) {
|
||||
self.ignore_exit_key.store(false, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Events {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
fn ls_next(ls: &mut ListState, max: usize) {
|
||||
let i = match ls.selected() {
|
||||
Some(i) => {
|
||||
if i >= max - 1 {
|
||||
max - 1
|
||||
} else {
|
||||
i + 1
|
||||
}
|
||||
}
|
||||
None => 0,
|
||||
};
|
||||
ls.select(Some(i));
|
||||
}
|
||||
|
||||
fn ls_previous(ls: &mut ListState) {
|
||||
let i = match ls.selected() {
|
||||
Some(i) => {
|
||||
if i == 0 {
|
||||
0
|
||||
} else {
|
||||
i - 1
|
||||
}
|
||||
}
|
||||
None => 0,
|
||||
};
|
||||
ls.select(Some(i));
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
struct SBWidget<'a> {
|
||||
sb: &'a Superblock,
|
||||
}
|
||||
|
||||
impl<'a> StatefulWidget for SBWidget<'a> {
|
||||
type State = ListState;
|
||||
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut ListState) {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Min(10), Constraint::Percentage(80)].as_ref())
|
||||
.split(area);
|
||||
|
||||
let sb = self.sb;
|
||||
let flags = vec!["flags".to_string(), format!("{}", sb.flags)];
|
||||
let block = vec!["block".to_string(), format!("{}", sb.block)];
|
||||
let uuid = vec!["uuid".to_string(), "-".to_string()];
|
||||
let version = vec!["version".to_string(), format!("{}", sb.version)];
|
||||
let time = vec!["time".to_string(), format!("{}", sb.time)];
|
||||
let transaction_id = vec![
|
||||
"transaction_id".to_string(),
|
||||
format!("{}", sb.transaction_id),
|
||||
];
|
||||
let metadata_snap = vec![
|
||||
"metadata_snap".to_string(),
|
||||
if sb.metadata_snap == 0 {
|
||||
"-".to_string()
|
||||
} else {
|
||||
format!("{}", sb.metadata_snap)
|
||||
},
|
||||
];
|
||||
let mapping_root = vec!["mapping root".to_string(), format!("{}", sb.mapping_root)];
|
||||
let details_root = vec!["details root".to_string(), format!("{}", sb.details_root)];
|
||||
let data_block_size = vec![
|
||||
"data block size".to_string(),
|
||||
format!("{}k", sb.data_block_size * 2),
|
||||
];
|
||||
|
||||
let table = Table::new(vec![
|
||||
Row::new(flags),
|
||||
Row::new(block),
|
||||
Row::new(uuid),
|
||||
Row::new(version),
|
||||
Row::new(time),
|
||||
Row::new(transaction_id),
|
||||
Row::new(metadata_snap),
|
||||
Row::new(mapping_root),
|
||||
Row::new(details_root),
|
||||
Row::new(data_block_size),
|
||||
])
|
||||
.header(Row::new(vec!["Field", "Value"]).style(Style::default().fg(Color::Yellow)))
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("Superblock".to_string()),
|
||||
)
|
||||
.widths(&[Constraint::Length(20), Constraint::Length(60)])
|
||||
.style(Style::default().fg(Color::White))
|
||||
.column_spacing(1);
|
||||
|
||||
Widget::render(table, chunks[0], buf);
|
||||
|
||||
let items = vec![
|
||||
ListItem::new(Span::raw("Device tree".to_string())),
|
||||
ListItem::new(Span::raw("Mapping tree".to_string())),
|
||||
];
|
||||
|
||||
let items = List::new(items)
|
||||
.block(Block::default().borders(Borders::ALL).title("Entries"))
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.bg(Color::LightGreen)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
);
|
||||
|
||||
StatefulWidget::render(items, chunks[1], buf, state);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
struct HeaderWidget<'a> {
|
||||
title: String,
|
||||
hdr: &'a btree::NodeHeader,
|
||||
}
|
||||
|
||||
impl<'a> Widget for HeaderWidget<'a> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let hdr = &self.hdr;
|
||||
let block = vec!["block".to_string(), format!("{}", hdr.block)];
|
||||
let kind = vec![
|
||||
"type".to_string(),
|
||||
match hdr.is_leaf {
|
||||
true => "LEAF".to_string(),
|
||||
false => "INTERNAL".to_string(),
|
||||
},
|
||||
];
|
||||
let nr_entries = vec!["nr_entries".to_string(), format!("{}", hdr.nr_entries)];
|
||||
let max_entries = vec!["max_entries".to_string(), format!("{}", hdr.max_entries)];
|
||||
let value_size = vec!["value size".to_string(), format!("{}", hdr.value_size)];
|
||||
|
||||
let table = Table::new(vec![
|
||||
Row::new(block),
|
||||
Row::new(kind),
|
||||
Row::new(nr_entries),
|
||||
Row::new(max_entries),
|
||||
Row::new(value_size),
|
||||
])
|
||||
.header(Row::new(vec!["Field", "Value"]).style(Style::default().fg(Color::Yellow)))
|
||||
.block(Block::default().borders(Borders::ALL).title(self.title))
|
||||
.widths(&[Constraint::Length(20), Constraint::Length(60)])
|
||||
.style(Style::default().fg(Color::White))
|
||||
.column_spacing(1);
|
||||
|
||||
Widget::render(table, area, buf);
|
||||
}
|
||||
}
|
||||
|
||||
fn read_node<V: Unpack>(engine: &dyn IoEngine, loc: u64) -> Result<btree::Node<V>> {
|
||||
let b = engine.read(loc)?;
|
||||
let path = Vec::new();
|
||||
btree::unpack_node(&path, b.get_data(), true, false)
|
||||
.map_err(|_| anyhow!("couldn't unpack btree node"))
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
// For types that have the concept of adjacency, but not of a distance
|
||||
// between values. For instance with a BlockTime there is no delta that
|
||||
// will get between two values with different times.
|
||||
trait Adjacent {
|
||||
fn adjacent(&self, rhs: &Self) -> bool;
|
||||
}
|
||||
|
||||
impl Adjacent for u64 {
|
||||
fn adjacent(&self, rhs: &Self) -> bool {
|
||||
(*self + 1) == *rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Adjacent for BlockTime {
|
||||
fn adjacent(&self, rhs: &Self) -> bool {
|
||||
if self.time != rhs.time {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.block + 1 == rhs.block
|
||||
}
|
||||
}
|
||||
|
||||
impl Adjacent for DeviceDetail {
|
||||
fn adjacent(&self, _rhs: &Self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl<X: Adjacent, Y: Adjacent> Adjacent for (X, Y) {
|
||||
fn adjacent(&self, rhs: &Self) -> bool {
|
||||
self.0.adjacent(&rhs.0) && self.1.adjacent(&rhs.1)
|
||||
}
|
||||
}
|
||||
|
||||
fn adjacent_runs<V: Adjacent + Copy>(mut ns: Vec<V>) -> Vec<(V, usize)> {
|
||||
let mut result = Vec::new();
|
||||
|
||||
if ns.is_empty() {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Reverse so we can pop without cloning the value.
|
||||
ns.reverse();
|
||||
|
||||
let mut base = ns.pop().unwrap();
|
||||
let mut current = base;
|
||||
let mut len = 1;
|
||||
while let Some(v) = ns.pop() {
|
||||
if current.adjacent(&v) {
|
||||
current = v;
|
||||
len += 1;
|
||||
} else {
|
||||
result.push((base, len));
|
||||
base = v;
|
||||
current = v;
|
||||
len = 1;
|
||||
}
|
||||
}
|
||||
result.push((base, len));
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn mk_runs<V: Adjacent + Sized + Copy>(keys: &[u64], values: &[V]) -> Vec<((u64, V), usize)> {
|
||||
let mut pairs = Vec::new();
|
||||
for (k, v) in keys.iter().zip(values.iter()) {
|
||||
pairs.push((*k, *v));
|
||||
}
|
||||
|
||||
adjacent_runs(pairs)
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
struct NodeWidget<'a, V: Unpack + Adjacent + Clone> {
|
||||
title: String,
|
||||
node: &'a btree::Node<V>,
|
||||
}
|
||||
|
||||
fn mk_item<'a, V: fmt::Display>(k: u64, v: &V, len: usize) -> ListItem<'a> {
|
||||
if len > 1 {
|
||||
ListItem::new(Span::raw(format!("{} x {} -> {}", k, len as u64, v)))
|
||||
} else {
|
||||
ListItem::new(Span::raw(format!("{} -> {}", k, v)))
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_items<'a, V>(keys: &[u64], values: &[V], selected: usize) -> (Vec<ListItem<'a>>, usize)
|
||||
where
|
||||
V: Adjacent + Copy + fmt::Display,
|
||||
{
|
||||
let mut items = Vec::new();
|
||||
let bkeys = &keys[0..selected];
|
||||
let key = keys[selected];
|
||||
let akeys = &keys[(selected + 1)..];
|
||||
|
||||
let bvalues = &values[0..selected];
|
||||
let value = values[selected];
|
||||
let avalues = &values[(selected + 1)..];
|
||||
|
||||
let bruns = mk_runs(bkeys, bvalues);
|
||||
let aruns = mk_runs(akeys, avalues);
|
||||
let i = bruns.len();
|
||||
|
||||
for ((k, v), len) in bruns {
|
||||
items.push(mk_item(k, &v, len));
|
||||
}
|
||||
|
||||
items.push(ListItem::new(Span::raw(format!("{} -> {}", key, value))));
|
||||
|
||||
for ((k, v), len) in aruns {
|
||||
items.push(mk_item(k, &v, len));
|
||||
}
|
||||
|
||||
(items, i)
|
||||
}
|
||||
|
||||
impl<'a, V: Unpack + fmt::Display + Adjacent + Copy> StatefulWidget for NodeWidget<'a, V> {
|
||||
type State = ListState;
|
||||
|
||||
fn render(self, area: Rect, buf: &mut Buffer, state: &mut ListState) {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Min(10), Constraint::Percentage(80)].as_ref())
|
||||
.split(area);
|
||||
|
||||
let hdr = HeaderWidget {
|
||||
title: self.title,
|
||||
hdr: self.node.get_header(),
|
||||
};
|
||||
hdr.render(chunks[0], buf);
|
||||
|
||||
let items: Vec<ListItem>;
|
||||
let i: usize;
|
||||
let selected = state.selected().unwrap();
|
||||
let mut state = ListState::default();
|
||||
|
||||
match self.node {
|
||||
btree::Node::Internal { keys, values, .. } => {
|
||||
let (items_, i_) = mk_items(keys, values, selected);
|
||||
items = items_;
|
||||
i = i_;
|
||||
}
|
||||
btree::Node::Leaf { keys, values, .. } => {
|
||||
let (items_, i_) = mk_items(keys, values, selected);
|
||||
items = items_;
|
||||
i = i_;
|
||||
}
|
||||
}
|
||||
state.select(Some(i));
|
||||
|
||||
let items = List::new(items)
|
||||
.block(Block::default().borders(Borders::ALL).title("Entries"))
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.bg(Color::LightGreen)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
);
|
||||
|
||||
StatefulWidget::render(items, chunks[1], buf, &mut state);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
enum Action {
|
||||
PushDeviceDetail(u64),
|
||||
PushTopLevel(u64),
|
||||
PushBottomLevel(u32, u64),
|
||||
PopPanel,
|
||||
}
|
||||
|
||||
use Action::*;
|
||||
|
||||
type Frame_<'a, 'b> = Frame<'a, TermionBackend<termion::raw::RawTerminal<std::io::StdoutLock<'b>>>>;
|
||||
|
||||
trait Panel {
|
||||
fn render(&mut self, area: Rect, f: &mut Frame_);
|
||||
fn input(&mut self, k: Key) -> Option<Action>;
|
||||
fn path_action(&mut self, child: u64) -> Option<Action>;
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
struct SBPanel {
|
||||
sb: Superblock,
|
||||
state: ListState,
|
||||
}
|
||||
|
||||
impl SBPanel {
|
||||
fn new(sb: Superblock) -> SBPanel {
|
||||
let mut state = ListState::default();
|
||||
state.select(Some(0));
|
||||
|
||||
SBPanel { sb, state }
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for SBPanel {
|
||||
fn render(&mut self, area: Rect, f: &mut Frame_) {
|
||||
let w = SBWidget { sb: &self.sb };
|
||||
f.render_stateful_widget(w, area, &mut self.state);
|
||||
}
|
||||
|
||||
fn input(&mut self, k: Key) -> Option<Action> {
|
||||
match k {
|
||||
Key::Char('j') | Key::Down => {
|
||||
ls_next(&mut self.state, 2);
|
||||
None
|
||||
}
|
||||
Key::Char('k') | Key::Up => {
|
||||
ls_previous(&mut self.state);
|
||||
None
|
||||
}
|
||||
Key::Char('l') | Key::Right => {
|
||||
if self.state.selected().unwrap() == 0 {
|
||||
Some(PushDeviceDetail(self.sb.details_root))
|
||||
} else {
|
||||
Some(PushTopLevel(self.sb.mapping_root))
|
||||
}
|
||||
}
|
||||
Key::Char('h') | Key::Left => Some(PopPanel),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn path_action(&mut self, child: u64) -> Option<Action> {
|
||||
if child == self.sb.mapping_root {
|
||||
Some(PushTopLevel(child))
|
||||
} else if child == self.sb.details_root {
|
||||
Some(PushDeviceDetail(child))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
struct DeviceDetailPanel {
|
||||
node: btree::Node<DeviceDetail>,
|
||||
nr_entries: usize,
|
||||
state: ListState,
|
||||
}
|
||||
|
||||
impl DeviceDetailPanel {
|
||||
fn new(node: btree::Node<DeviceDetail>) -> DeviceDetailPanel {
|
||||
let nr_entries = node.get_header().nr_entries as usize;
|
||||
let mut state = ListState::default();
|
||||
state.select(Some(0));
|
||||
|
||||
DeviceDetailPanel {
|
||||
node,
|
||||
nr_entries,
|
||||
state,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for DeviceDetailPanel {
|
||||
fn render(&mut self, area: Rect, f: &mut Frame_) {
|
||||
let w = NodeWidget {
|
||||
title: "Device Details".to_string(),
|
||||
node: &self.node,
|
||||
};
|
||||
|
||||
f.render_stateful_widget(w, area, &mut self.state);
|
||||
}
|
||||
|
||||
fn input(&mut self, k: Key) -> Option<Action> {
|
||||
match k {
|
||||
Key::Char('j') | Key::Down => {
|
||||
ls_next(&mut self.state, self.nr_entries);
|
||||
None
|
||||
}
|
||||
Key::Char('k') | Key::Up => {
|
||||
ls_previous(&mut self.state);
|
||||
None
|
||||
}
|
||||
Key::Char('l') | Key::Right => match &self.node {
|
||||
btree::Node::Internal { values, .. } => {
|
||||
Some(PushDeviceDetail(values[self.state.selected().unwrap()]))
|
||||
}
|
||||
btree::Node::Leaf { .. } => None,
|
||||
},
|
||||
Key::Char('h') | Key::Left => Some(PopPanel),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn path_action(&mut self, child: u64) -> Option<Action> {
|
||||
match &self.node {
|
||||
btree::Node::Internal { values, .. } => {
|
||||
for (i, v) in values.iter().enumerate() {
|
||||
if *v == child {
|
||||
self.state.select(Some(i));
|
||||
return Some(PushDeviceDetail(child));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
btree::Node::Leaf { .. } => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
struct TopLevelPanel {
|
||||
node: btree::Node<u64>,
|
||||
nr_entries: usize,
|
||||
state: ListState,
|
||||
}
|
||||
|
||||
impl TopLevelPanel {
|
||||
fn new(node: btree::Node<u64>) -> TopLevelPanel {
|
||||
let nr_entries = node.get_header().nr_entries as usize;
|
||||
let mut state = ListState::default();
|
||||
state.select(Some(0));
|
||||
|
||||
TopLevelPanel {
|
||||
node,
|
||||
nr_entries,
|
||||
state,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for TopLevelPanel {
|
||||
fn render(&mut self, area: Rect, f: &mut Frame_) {
|
||||
let w = NodeWidget {
|
||||
title: "Top Level".to_string(),
|
||||
node: &self.node,
|
||||
};
|
||||
|
||||
f.render_stateful_widget(w, area, &mut self.state);
|
||||
}
|
||||
|
||||
fn input(&mut self, k: Key) -> Option<Action> {
|
||||
match k {
|
||||
Key::Char('j') | Key::Down => {
|
||||
ls_next(&mut self.state, self.nr_entries);
|
||||
None
|
||||
}
|
||||
Key::Char('k') | Key::Up => {
|
||||
ls_previous(&mut self.state);
|
||||
None
|
||||
}
|
||||
Key::Char('l') | Key::Right => match &self.node {
|
||||
btree::Node::Internal { values, .. } => {
|
||||
Some(PushTopLevel(values[self.state.selected().unwrap()]))
|
||||
}
|
||||
btree::Node::Leaf { values, keys, .. } => {
|
||||
let index = self.state.selected().unwrap();
|
||||
|
||||
Some(PushBottomLevel(keys[index] as u32, values[index]))
|
||||
}
|
||||
},
|
||||
Key::Char('h') | Key::Left => Some(PopPanel),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn path_action(&mut self, child: u64) -> Option<Action> {
|
||||
match &self.node {
|
||||
btree::Node::Internal { values, .. } => {
|
||||
for (i, v) in values.iter().enumerate() {
|
||||
if *v == child {
|
||||
self.state.select(Some(i));
|
||||
return Some(PushTopLevel(child));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
btree::Node::Leaf { keys, values, .. } => {
|
||||
for i in 0..values.len() {
|
||||
if values[i] == child {
|
||||
self.state.select(Some(i));
|
||||
return Some(PushBottomLevel(keys[i] as u32, child));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct BottomLevelPanel {
|
||||
thin_id: u32,
|
||||
node: btree::Node<BlockTime>,
|
||||
nr_entries: usize,
|
||||
state: ListState,
|
||||
}
|
||||
|
||||
impl BottomLevelPanel {
|
||||
fn new(thin_id: u32, node: btree::Node<BlockTime>) -> BottomLevelPanel {
|
||||
let nr_entries = node.get_header().nr_entries as usize;
|
||||
let mut state = ListState::default();
|
||||
state.select(Some(0));
|
||||
|
||||
BottomLevelPanel {
|
||||
thin_id,
|
||||
node,
|
||||
nr_entries,
|
||||
state,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for BottomLevelPanel {
|
||||
fn render(&mut self, area: Rect, f: &mut Frame_) {
|
||||
let w = NodeWidget {
|
||||
title: format!("Thin dev #{}", self.thin_id),
|
||||
node: &self.node,
|
||||
};
|
||||
|
||||
f.render_stateful_widget(w, area, &mut self.state);
|
||||
}
|
||||
|
||||
fn input(&mut self, k: Key) -> Option<Action> {
|
||||
match k {
|
||||
Key::Char('j') | Key::Down => {
|
||||
ls_next(&mut self.state, self.nr_entries);
|
||||
None
|
||||
}
|
||||
Key::Char('k') | Key::Up => {
|
||||
ls_previous(&mut self.state);
|
||||
None
|
||||
}
|
||||
Key::Char('l') | Key::Right => match &self.node {
|
||||
btree::Node::Internal { values, .. } => Some(PushBottomLevel(
|
||||
self.thin_id,
|
||||
values[self.state.selected().unwrap()],
|
||||
)),
|
||||
_ => None,
|
||||
},
|
||||
|
||||
Key::Char('h') | Key::Left => Some(PopPanel),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn path_action(&mut self, child: u64) -> Option<Action> {
|
||||
match &self.node {
|
||||
btree::Node::Internal { values, .. } => {
|
||||
for (i, v) in values.iter().enumerate() {
|
||||
if *v == child {
|
||||
self.state.select(Some(i));
|
||||
return Some(PushBottomLevel(self.thin_id, child));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
btree::Node::Leaf { .. } => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
fn perform_action(
|
||||
panels: &mut Vec<Box<dyn Panel>>,
|
||||
engine: &dyn IoEngine,
|
||||
action: Action,
|
||||
) -> Result<()> {
|
||||
match action {
|
||||
PushDeviceDetail(b) => {
|
||||
let node = read_node::<DeviceDetail>(engine, b)?;
|
||||
panels.push(Box::new(DeviceDetailPanel::new(node)));
|
||||
}
|
||||
PushTopLevel(b) => {
|
||||
let node = read_node::<u64>(engine, b)?;
|
||||
panels.push(Box::new(TopLevelPanel::new(node)));
|
||||
}
|
||||
PushBottomLevel(thin_id, b) => {
|
||||
let node = read_node::<BlockTime>(engine, b)?;
|
||||
panels.push(Box::new(BottomLevelPanel::new(thin_id, node)));
|
||||
}
|
||||
PopPanel => {
|
||||
if panels.len() > 1 {
|
||||
panels.pop();
|
||||
}
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn explore(path: &Path, node_path: Option<Vec<u64>>) -> Result<()> {
|
||||
let engine = SyncIoEngine::new(path, 1, false)?;
|
||||
|
||||
let mut panels: Vec<Box<dyn Panel>> = Vec::new();
|
||||
|
||||
if let Some(path) = node_path {
|
||||
eprintln!("using path: {:?}", path);
|
||||
assert_eq!(path[0], 0);
|
||||
let sb = read_superblock(&engine, path[0])?;
|
||||
panels.push(Box::new(SBPanel::new(sb)));
|
||||
for b in &path[1..] {
|
||||
let action = panels.last_mut().unwrap().path_action(*b);
|
||||
if let Some(action) = action {
|
||||
perform_action(&mut panels, &engine, action)?;
|
||||
} else {
|
||||
return Err(anyhow!("bad node path: couldn't find child node {}", b));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let sb = read_superblock(&engine, 0)?;
|
||||
panels.push(Box::new(SBPanel::new(sb)));
|
||||
}
|
||||
|
||||
let events = Events::new();
|
||||
|
||||
let stdout = io::stdout();
|
||||
let mut stdout = stdout.lock().into_raw_mode()?;
|
||||
write!(stdout, "{}", termion::clear::All)?;
|
||||
let backend = TermionBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
'main: loop {
|
||||
let render_panels = |f: &mut Frame_| {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||
.split(f.size());
|
||||
|
||||
let mut base = panels.len();
|
||||
if base >= 2 {
|
||||
base -= 2;
|
||||
} else {
|
||||
base = 0;
|
||||
}
|
||||
|
||||
for i in base..panels.len() {
|
||||
panels[i].render(chunks[i - base], f);
|
||||
}
|
||||
};
|
||||
|
||||
terminal.draw(render_panels)?;
|
||||
|
||||
let last = panels.len() - 1;
|
||||
let active_panel = &mut panels[last];
|
||||
if let Event::Input(key) = events.next()? {
|
||||
match key {
|
||||
Key::Char('q') => break 'main,
|
||||
_ => {
|
||||
if let Some(action) = active_panel.input(key) {
|
||||
perform_action(&mut panels, &engine, action)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
events.input_handle.join().unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let parser = App::new("thin_explore")
|
||||
.version(thinp::version::tools_version())
|
||||
.about("A text user interface for examining thin metadata.")
|
||||
.arg(
|
||||
Arg::with_name("NODE_PATH")
|
||||
.help("Pass in a node path as output by thin_check")
|
||||
.short("p")
|
||||
.long("node-path")
|
||||
.value_name("NODE_PATH"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device to check")
|
||||
.required(true)
|
||||
.index(1),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches();
|
||||
let node_path = matches
|
||||
.value_of("NODE_PATH")
|
||||
.map(|text| btree::decode_node_path(text).unwrap());
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
|
||||
explore(input_file, node_path)
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
Vendored
-373
@@ -1,373 +0,0 @@
|
||||
use anyhow::anyhow;
|
||||
use std::collections::BTreeSet;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::cache::hint::*;
|
||||
use crate::cache::mapping::*;
|
||||
use crate::cache::superblock::*;
|
||||
use crate::commands::utils::*;
|
||||
use crate::io_engine::{AsyncIoEngine, IoEngine, SyncIoEngine};
|
||||
use crate::pdata::array::{self, ArrayBlock, ArrayError};
|
||||
use crate::pdata::array_walker::*;
|
||||
use crate::pdata::bitset::*;
|
||||
use crate::pdata::space_map::*;
|
||||
use crate::pdata::space_map_checker::*;
|
||||
use crate::pdata::space_map_common::*;
|
||||
use crate::pdata::unpack::unpack;
|
||||
use crate::report::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
const MAX_CONCURRENT_IO: u32 = 1024;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
fn inc_superblock(sm: &ASpaceMap) -> anyhow::Result<()> {
|
||||
let mut sm = sm.lock().unwrap();
|
||||
sm.inc(SUPERBLOCK_LOCATION, 1)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
mod format1 {
|
||||
use super::*;
|
||||
|
||||
pub struct MappingChecker {
|
||||
nr_origin_blocks: u64,
|
||||
seen_oblocks: Mutex<BTreeSet<u64>>,
|
||||
}
|
||||
|
||||
impl MappingChecker {
|
||||
pub fn new(nr_origin_blocks: Option<u64>) -> MappingChecker {
|
||||
MappingChecker {
|
||||
nr_origin_blocks: if let Some(n) = nr_origin_blocks {
|
||||
n
|
||||
} else {
|
||||
MAX_ORIGIN_BLOCKS
|
||||
},
|
||||
seen_oblocks: Mutex::new(BTreeSet::new()),
|
||||
}
|
||||
}
|
||||
|
||||
fn check_flags(&self, m: &Mapping) -> array::Result<()> {
|
||||
if (m.flags & !(MappingFlags::Valid as u32 | MappingFlags::Dirty as u32)) != 0 {
|
||||
return Err(array::value_err(format!(
|
||||
"unknown flags in mapping: {}",
|
||||
m.flags
|
||||
)));
|
||||
}
|
||||
if !m.is_valid() && m.is_dirty() {
|
||||
return Err(array::value_err(
|
||||
"dirty bit found on an unmapped block".to_string(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_oblock(&self, m: &Mapping) -> array::Result<()> {
|
||||
if !m.is_valid() {
|
||||
if m.oblock > 0 {
|
||||
return Err(array::value_err("invalid block is mapped".to_string()));
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if m.oblock >= self.nr_origin_blocks {
|
||||
return Err(array::value_err(
|
||||
"mapping beyond end of the origin device".to_string(),
|
||||
));
|
||||
}
|
||||
let mut seen_oblocks = self.seen_oblocks.lock().unwrap();
|
||||
if seen_oblocks.contains(&m.oblock) {
|
||||
return Err(array::value_err("origin block already mapped".to_string()));
|
||||
}
|
||||
seen_oblocks.insert(m.oblock);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ArrayVisitor<Mapping> for MappingChecker {
|
||||
fn visit(&self, _index: u64, b: ArrayBlock<Mapping>) -> array::Result<()> {
|
||||
let mut errs: Vec<ArrayError> = Vec::new();
|
||||
|
||||
for m in b.values.iter() {
|
||||
if let Err(e) = self.check_flags(m) {
|
||||
errs.push(e);
|
||||
}
|
||||
if let Err(e) = self.check_oblock(m) {
|
||||
errs.push(e);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: duplicate to BTreeWalker::build_aggregrate()
|
||||
match errs.len() {
|
||||
0 => Ok(()),
|
||||
1 => Err(errs[0].clone()),
|
||||
_ => Err(array::aggregate_error(errs)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod format2 {
|
||||
use super::*;
|
||||
|
||||
pub struct MappingChecker {
|
||||
nr_origin_blocks: u64,
|
||||
inner: Mutex<Inner>,
|
||||
}
|
||||
|
||||
struct Inner {
|
||||
seen_oblocks: BTreeSet<u64>,
|
||||
dirty_bits: CheckedBitSet,
|
||||
}
|
||||
|
||||
impl MappingChecker {
|
||||
pub fn new(nr_origin_blocks: Option<u64>, dirty_bits: CheckedBitSet) -> MappingChecker {
|
||||
MappingChecker {
|
||||
nr_origin_blocks: if let Some(n) = nr_origin_blocks {
|
||||
n
|
||||
} else {
|
||||
MAX_ORIGIN_BLOCKS
|
||||
},
|
||||
inner: Mutex::new(Inner {
|
||||
seen_oblocks: BTreeSet::new(),
|
||||
dirty_bits,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
fn check_flags(&self, m: &Mapping, dirty_bit: Option<bool>) -> array::Result<()> {
|
||||
if (m.flags & !(MappingFlags::Valid as u32)) != 0 {
|
||||
return Err(array::value_err(format!(
|
||||
"unknown flags in mapping: {}",
|
||||
m.flags
|
||||
)));
|
||||
}
|
||||
if !m.is_valid() && dirty_bit.is_some() && dirty_bit.unwrap() {
|
||||
return Err(array::value_err(
|
||||
"dirty bit found on an unmapped block".to_string(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_oblock(&self, m: &Mapping, seen_oblocks: &mut BTreeSet<u64>) -> array::Result<()> {
|
||||
if !m.is_valid() {
|
||||
if m.oblock > 0 {
|
||||
return Err(array::value_err("invalid mapped block".to_string()));
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if m.oblock >= self.nr_origin_blocks {
|
||||
return Err(array::value_err(
|
||||
"mapping beyond end of the origin device".to_string(),
|
||||
));
|
||||
}
|
||||
if seen_oblocks.contains(&m.oblock) {
|
||||
return Err(array::value_err("origin block already mapped".to_string()));
|
||||
}
|
||||
seen_oblocks.insert(m.oblock);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ArrayVisitor<Mapping> for MappingChecker {
|
||||
fn visit(&self, index: u64, b: ArrayBlock<Mapping>) -> array::Result<()> {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
let mut errs: Vec<ArrayError> = Vec::new();
|
||||
|
||||
let cbegin = index as u32 * b.header.max_entries;
|
||||
let cend = cbegin + b.header.nr_entries;
|
||||
for (m, cblock) in b.values.iter().zip(cbegin..cend) {
|
||||
if let Err(e) = self.check_flags(m, inner.dirty_bits.contains(cblock as usize)) {
|
||||
errs.push(e);
|
||||
}
|
||||
if let Err(e) = self.check_oblock(m, &mut inner.seen_oblocks) {
|
||||
errs.push(e);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: duplicate to BTreeWalker::build_aggregrate()
|
||||
match errs.len() {
|
||||
0 => Ok(()),
|
||||
1 => Err(errs[0].clone()),
|
||||
_ => Err(array::aggregate_error(errs)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
struct HintChecker;
|
||||
|
||||
impl HintChecker {
|
||||
fn new() -> HintChecker {
|
||||
HintChecker
|
||||
}
|
||||
}
|
||||
|
||||
impl ArrayVisitor<Hint> for HintChecker {
|
||||
fn visit(&self, _index: u64, _b: ArrayBlock<Hint>) -> array::Result<()> {
|
||||
// TODO: check hints
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
// TODO: clear_needs_check, auto_repair
|
||||
pub struct CacheCheckOptions<'a> {
|
||||
pub dev: &'a Path,
|
||||
pub async_io: bool,
|
||||
pub sb_only: bool,
|
||||
pub skip_mappings: bool,
|
||||
pub skip_hints: bool,
|
||||
pub skip_discards: bool,
|
||||
pub ignore_non_fatal: bool,
|
||||
pub auto_repair: bool,
|
||||
pub report: Arc<Report>,
|
||||
}
|
||||
|
||||
// TODO: thread pool
|
||||
struct Context {
|
||||
report: Arc<Report>,
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
}
|
||||
|
||||
fn mk_context(opts: &CacheCheckOptions) -> anyhow::Result<Context> {
|
||||
let engine: Arc<dyn IoEngine + Send + Sync>;
|
||||
|
||||
if opts.async_io {
|
||||
engine = Arc::new(AsyncIoEngine::new(opts.dev, MAX_CONCURRENT_IO, false)?);
|
||||
} else {
|
||||
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
||||
engine = Arc::new(SyncIoEngine::new(opts.dev, nr_threads, false)?);
|
||||
}
|
||||
|
||||
Ok(Context {
|
||||
report: opts.report.clone(),
|
||||
engine,
|
||||
})
|
||||
}
|
||||
|
||||
fn check_superblock(sb: &Superblock) -> anyhow::Result<()> {
|
||||
if sb.version >= 2 && sb.dirty_root == None {
|
||||
return Err(anyhow!("dirty bitset not found"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn check(opts: CacheCheckOptions) -> anyhow::Result<()> {
|
||||
let ctx = mk_context(&opts)?;
|
||||
|
||||
let engine = &ctx.engine;
|
||||
let metadata_sm = core_sm(engine.get_nr_blocks(), u8::MAX as u32);
|
||||
inc_superblock(&metadata_sm)?;
|
||||
|
||||
let sb = match read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION) {
|
||||
Ok(sb) => sb,
|
||||
Err(e) => {
|
||||
check_not_xml(opts.dev, &opts.report);
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
check_superblock(&sb)?;
|
||||
|
||||
if opts.sb_only {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// The discard bitset is optional and could be updated during device suspension.
|
||||
// A restored metadata therefore comes with a zero-sized discard bitset,
|
||||
// and also zeroed discard_block_size and discard_nr_blocks.
|
||||
let nr_origin_blocks;
|
||||
if sb.flags.clean_shutdown && sb.discard_block_size > 0 && sb.discard_nr_blocks > 0 {
|
||||
let origin_sectors = sb.discard_block_size * sb.discard_nr_blocks;
|
||||
nr_origin_blocks = Some(origin_sectors / sb.data_block_size as u64);
|
||||
} else {
|
||||
nr_origin_blocks = None;
|
||||
}
|
||||
|
||||
// TODO: factor out into check_mappings()
|
||||
if !opts.skip_mappings {
|
||||
let w =
|
||||
ArrayWalker::new_with_sm(engine.clone(), metadata_sm.clone(), opts.ignore_non_fatal)?;
|
||||
match sb.version {
|
||||
1 => {
|
||||
let mut c = format1::MappingChecker::new(nr_origin_blocks);
|
||||
if let Err(e) = w.walk(&mut c, sb.mapping_root) {
|
||||
ctx.report.fatal(&format!("{}", e));
|
||||
}
|
||||
}
|
||||
2 => {
|
||||
let (dirty_bits, err) = read_bitset_with_sm(
|
||||
engine.clone(),
|
||||
sb.dirty_root.unwrap(),
|
||||
sb.cache_blocks as usize,
|
||||
metadata_sm.clone(),
|
||||
opts.ignore_non_fatal,
|
||||
)?;
|
||||
if err.is_some() {
|
||||
ctx.report.fatal(&format!("{}", err.unwrap()));
|
||||
}
|
||||
let mut c = format2::MappingChecker::new(nr_origin_blocks, dirty_bits);
|
||||
if let Err(e) = w.walk(&mut c, sb.mapping_root) {
|
||||
ctx.report.fatal(&format!("{}", e));
|
||||
}
|
||||
}
|
||||
v => {
|
||||
return Err(anyhow!("unsupported metadata version {}", v));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !opts.skip_hints && sb.hint_root != 0 && sb.policy_hint_size != 0 {
|
||||
if sb.policy_hint_size != 4 {
|
||||
return Err(anyhow!("cache_check only supports policy hint size of 4"));
|
||||
}
|
||||
let w =
|
||||
ArrayWalker::new_with_sm(engine.clone(), metadata_sm.clone(), opts.ignore_non_fatal)?;
|
||||
let mut c = HintChecker::new();
|
||||
if let Err(e) = w.walk(&mut c, sb.hint_root) {
|
||||
ctx.report.fatal(&format!("{}", e));
|
||||
}
|
||||
}
|
||||
|
||||
// The discard bitset might not be available if the cache has never been suspended,
|
||||
// e.g., a crash of freshly created cache.
|
||||
if !opts.skip_discards && sb.discard_root != 0 {
|
||||
let (_discard_bits, err) = read_bitset_with_sm(
|
||||
engine.clone(),
|
||||
sb.discard_root,
|
||||
sb.discard_nr_blocks as usize,
|
||||
metadata_sm.clone(),
|
||||
opts.ignore_non_fatal,
|
||||
)?;
|
||||
if err.is_some() {
|
||||
ctx.report.fatal(&format!("{}", err.unwrap()));
|
||||
}
|
||||
}
|
||||
|
||||
let root = unpack::<SMRoot>(&sb.metadata_sm_root[0..])?;
|
||||
let metadata_leaks = check_metadata_space_map(
|
||||
engine.clone(),
|
||||
ctx.report.clone(),
|
||||
root,
|
||||
metadata_sm.clone(),
|
||||
opts.ignore_non_fatal,
|
||||
)?;
|
||||
|
||||
if opts.auto_repair && !metadata_leaks.is_empty() {
|
||||
ctx.report.info("Repairing metadata leaks.");
|
||||
repair_space_map(ctx.engine.clone(), metadata_leaks, metadata_sm.clone())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
Vendored
-301
@@ -1,301 +0,0 @@
|
||||
use anyhow::anyhow;
|
||||
use fixedbitset::FixedBitSet;
|
||||
use std::fs::File;
|
||||
use std::io::BufWriter;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::cache::hint::Hint;
|
||||
use crate::cache::ir::{self, MetadataVisitor};
|
||||
use crate::cache::mapping::Mapping;
|
||||
use crate::cache::superblock::*;
|
||||
use crate::cache::xml;
|
||||
use crate::io_engine::{AsyncIoEngine, IoEngine, SyncIoEngine};
|
||||
use crate::pdata::array::{self, ArrayBlock};
|
||||
use crate::pdata::array_walker::*;
|
||||
use crate::pdata::bitset::{read_bitset, CheckedBitSet};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
const MAX_CONCURRENT_IO: u32 = 1024;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
mod format1 {
|
||||
use super::*;
|
||||
|
||||
struct Inner<'a> {
|
||||
visitor: &'a mut dyn MetadataVisitor,
|
||||
valid_mappings: FixedBitSet,
|
||||
}
|
||||
|
||||
pub struct MappingEmitter<'a> {
|
||||
inner: Mutex<Inner<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> MappingEmitter<'a> {
|
||||
pub fn new(nr_entries: usize, visitor: &'a mut dyn MetadataVisitor) -> MappingEmitter<'a> {
|
||||
MappingEmitter {
|
||||
inner: Mutex::new(Inner {
|
||||
visitor,
|
||||
valid_mappings: FixedBitSet::with_capacity(nr_entries),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_valid(self) -> FixedBitSet {
|
||||
let inner = self.inner.into_inner().unwrap();
|
||||
inner.valid_mappings
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArrayVisitor<Mapping> for MappingEmitter<'a> {
|
||||
fn visit(&self, index: u64, b: ArrayBlock<Mapping>) -> array::Result<()> {
|
||||
let cbegin = index as u32 * b.header.max_entries;
|
||||
let cend = cbegin + b.header.nr_entries;
|
||||
for (map, cblock) in b.values.iter().zip(cbegin..cend) {
|
||||
if !map.is_valid() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let m = ir::Map {
|
||||
cblock,
|
||||
oblock: map.oblock,
|
||||
dirty: map.is_dirty(),
|
||||
};
|
||||
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
inner.valid_mappings.set(cblock as usize, true);
|
||||
inner
|
||||
.visitor
|
||||
.mapping(&m)
|
||||
.map_err(|e| array::value_err(format!("{}", e)))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
mod format2 {
|
||||
use super::*;
|
||||
|
||||
//-------------------
|
||||
// Mapping visitor
|
||||
|
||||
struct Inner<'a> {
|
||||
visitor: &'a mut dyn MetadataVisitor,
|
||||
dirty_bits: CheckedBitSet,
|
||||
valid_mappings: FixedBitSet,
|
||||
}
|
||||
|
||||
pub struct MappingEmitter<'a> {
|
||||
inner: Mutex<Inner<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> MappingEmitter<'a> {
|
||||
pub fn new(
|
||||
nr_entries: usize,
|
||||
dirty_bits: CheckedBitSet,
|
||||
visitor: &'a mut dyn MetadataVisitor,
|
||||
) -> MappingEmitter<'a> {
|
||||
MappingEmitter {
|
||||
inner: Mutex::new(Inner {
|
||||
visitor,
|
||||
dirty_bits,
|
||||
valid_mappings: FixedBitSet::with_capacity(nr_entries),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_valid(self) -> FixedBitSet {
|
||||
let inner = self.inner.into_inner().unwrap();
|
||||
inner.valid_mappings
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArrayVisitor<Mapping> for MappingEmitter<'a> {
|
||||
fn visit(&self, index: u64, b: ArrayBlock<Mapping>) -> array::Result<()> {
|
||||
let cbegin = index as u32 * b.header.max_entries;
|
||||
let cend = cbegin + b.header.nr_entries;
|
||||
for (map, cblock) in b.values.iter().zip(cbegin..cend) {
|
||||
if !map.is_valid() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
let dirty;
|
||||
if let Some(bit) = inner.dirty_bits.contains(cblock as usize) {
|
||||
dirty = bit;
|
||||
} else {
|
||||
// default to dirty if the bitset is damaged
|
||||
dirty = true;
|
||||
}
|
||||
let m = ir::Map {
|
||||
cblock,
|
||||
oblock: map.oblock,
|
||||
dirty,
|
||||
};
|
||||
|
||||
inner.valid_mappings.set(cblock as usize, true);
|
||||
inner
|
||||
.visitor
|
||||
.mapping(&m)
|
||||
.map_err(|e| array::value_err(format!("{}", e)))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
struct HintEmitter<'a> {
|
||||
emitter: Mutex<&'a mut dyn MetadataVisitor>,
|
||||
valid_mappings: FixedBitSet,
|
||||
}
|
||||
|
||||
impl<'a> HintEmitter<'a> {
|
||||
pub fn new(emitter: &'a mut dyn MetadataVisitor, valid_mappings: FixedBitSet) -> HintEmitter {
|
||||
HintEmitter {
|
||||
emitter: Mutex::new(emitter),
|
||||
valid_mappings,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArrayVisitor<Hint> for HintEmitter<'a> {
|
||||
fn visit(&self, index: u64, b: ArrayBlock<Hint>) -> array::Result<()> {
|
||||
let cbegin = index as u32 * b.header.max_entries;
|
||||
let cend = cbegin + b.header.nr_entries;
|
||||
for (hint, cblock) in b.values.iter().zip(cbegin..cend) {
|
||||
if !self.valid_mappings.contains(cblock as usize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let h = ir::Hint {
|
||||
cblock,
|
||||
data: hint.hint.to_vec(),
|
||||
};
|
||||
|
||||
self.emitter
|
||||
.lock()
|
||||
.unwrap()
|
||||
.hint(&h)
|
||||
.map_err(|e| array::value_err(format!("{}", e)))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub struct CacheDumpOptions<'a> {
|
||||
pub input: &'a Path,
|
||||
pub output: Option<&'a Path>,
|
||||
pub async_io: bool,
|
||||
pub repair: bool,
|
||||
}
|
||||
|
||||
struct Context {
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
}
|
||||
|
||||
fn mk_context(opts: &CacheDumpOptions) -> anyhow::Result<Context> {
|
||||
let engine: Arc<dyn IoEngine + Send + Sync>;
|
||||
|
||||
if opts.async_io {
|
||||
engine = Arc::new(AsyncIoEngine::new(opts.input, MAX_CONCURRENT_IO, false)?);
|
||||
} else {
|
||||
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
||||
engine = Arc::new(SyncIoEngine::new(opts.input, nr_threads, false)?);
|
||||
}
|
||||
|
||||
Ok(Context { engine })
|
||||
}
|
||||
|
||||
pub fn dump_metadata(
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
out: &mut dyn MetadataVisitor,
|
||||
sb: &Superblock,
|
||||
repair: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let xml_sb = ir::Superblock {
|
||||
uuid: "".to_string(),
|
||||
block_size: sb.data_block_size,
|
||||
nr_cache_blocks: sb.cache_blocks,
|
||||
policy: std::str::from_utf8(&sb.policy_name)?.to_string(),
|
||||
hint_width: sb.policy_hint_size,
|
||||
};
|
||||
out.superblock_b(&xml_sb)?;
|
||||
|
||||
out.mappings_b()?;
|
||||
let valid_mappings = match sb.version {
|
||||
1 => {
|
||||
let w = ArrayWalker::new(engine.clone(), repair);
|
||||
let mut emitter = format1::MappingEmitter::new(sb.cache_blocks as usize, out);
|
||||
w.walk(&mut emitter, sb.mapping_root)?;
|
||||
emitter.get_valid()
|
||||
}
|
||||
2 => {
|
||||
// We need to walk the dirty bitset first.
|
||||
let dirty_bits;
|
||||
if let Some(root) = sb.dirty_root {
|
||||
let (bits, errs) =
|
||||
read_bitset(engine.clone(), root, sb.cache_blocks as usize, repair);
|
||||
if errs.is_some() && !repair {
|
||||
return Err(anyhow!("errors in bitset {}", errs.unwrap()));
|
||||
}
|
||||
dirty_bits = bits;
|
||||
} else {
|
||||
// FIXME: is there a way this can legally happen? eg,
|
||||
// a crash of a freshly created cache?
|
||||
return Err(anyhow!("format 2 selected, but no dirty bitset present"));
|
||||
}
|
||||
|
||||
let w = ArrayWalker::new(engine.clone(), repair);
|
||||
let mut emitter =
|
||||
format2::MappingEmitter::new(sb.cache_blocks as usize, dirty_bits, out);
|
||||
w.walk(&mut emitter, sb.mapping_root)?;
|
||||
emitter.get_valid()
|
||||
}
|
||||
v => {
|
||||
return Err(anyhow!("unsupported metadata version: {}", v));
|
||||
}
|
||||
};
|
||||
out.mappings_e()?;
|
||||
|
||||
out.hints_b()?;
|
||||
{
|
||||
let w = ArrayWalker::new(engine.clone(), repair);
|
||||
let mut emitter = HintEmitter::new(out, valid_mappings);
|
||||
w.walk(&mut emitter, sb.hint_root)?;
|
||||
}
|
||||
out.hints_e()?;
|
||||
|
||||
out.superblock_e()?;
|
||||
out.eof()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn dump(opts: CacheDumpOptions) -> anyhow::Result<()> {
|
||||
let ctx = mk_context(&opts)?;
|
||||
let sb = read_superblock(ctx.engine.as_ref(), SUPERBLOCK_LOCATION)?;
|
||||
|
||||
let writer: Box<dyn Write>;
|
||||
if opts.output.is_some() {
|
||||
writer = Box::new(BufWriter::new(File::create(opts.output.unwrap())?));
|
||||
} else {
|
||||
writer = Box::new(BufWriter::new(std::io::stdout()));
|
||||
}
|
||||
let mut out = xml::XmlWriter::new(writer);
|
||||
|
||||
dump_metadata(ctx.engine, &mut out, &sb, opts.repair)
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
Vendored
-46
@@ -1,46 +0,0 @@
|
||||
use anyhow::Result;
|
||||
use byteorder::WriteBytesExt;
|
||||
use nom::IResult;
|
||||
use std::convert::TryInto;
|
||||
|
||||
use crate::pdata::unpack::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Hint {
|
||||
pub hint: [u8; 4],
|
||||
}
|
||||
|
||||
impl Unpack for Hint {
|
||||
fn disk_size() -> u32 {
|
||||
4
|
||||
}
|
||||
|
||||
fn unpack(i: &[u8]) -> IResult<&[u8], Hint> {
|
||||
let size = 4;
|
||||
Ok((
|
||||
&i[size..],
|
||||
Hint {
|
||||
hint: i[0..size].try_into().unwrap(),
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Pack for Hint {
|
||||
fn pack<W: WriteBytesExt>(&self, data: &mut W) -> Result<()> {
|
||||
for v in &self.hint {
|
||||
data.write_u8(*v)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Hint {
|
||||
fn default() -> Self {
|
||||
Hint { hint: [0; 4] }
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
Vendored
-60
@@ -1,60 +0,0 @@
|
||||
use anyhow::Result;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Superblock {
|
||||
pub uuid: String,
|
||||
pub block_size: u32,
|
||||
pub nr_cache_blocks: u32,
|
||||
pub policy: String,
|
||||
pub hint_width: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Map {
|
||||
pub cblock: u32,
|
||||
pub oblock: u64,
|
||||
pub dirty: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Hint {
|
||||
pub cblock: u32,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Discard {
|
||||
pub begin: u64,
|
||||
pub end: u64,
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Visit {
|
||||
Continue,
|
||||
Stop,
|
||||
}
|
||||
|
||||
pub trait MetadataVisitor {
|
||||
fn superblock_b(&mut self, sb: &Superblock) -> Result<Visit>;
|
||||
fn superblock_e(&mut self) -> Result<Visit>;
|
||||
|
||||
fn mappings_b(&mut self) -> Result<Visit>;
|
||||
fn mappings_e(&mut self) -> Result<Visit>;
|
||||
fn mapping(&mut self, m: &Map) -> Result<Visit>;
|
||||
|
||||
fn hints_b(&mut self) -> Result<Visit>;
|
||||
fn hints_e(&mut self) -> Result<Visit>;
|
||||
fn hint(&mut self, h: &Hint) -> Result<Visit>;
|
||||
|
||||
fn discards_b(&mut self) -> Result<Visit>;
|
||||
fn discards_e(&mut self) -> Result<Visit>;
|
||||
fn discard(&mut self, d: &Discard) -> Result<Visit>;
|
||||
|
||||
fn eof(&mut self) -> Result<Visit>;
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
Vendored
-72
@@ -1,72 +0,0 @@
|
||||
use anyhow::Result;
|
||||
use byteorder::WriteBytesExt;
|
||||
use nom::number::complete::*;
|
||||
use nom::IResult;
|
||||
|
||||
use crate::pdata::unpack::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub const MAX_ORIGIN_BLOCKS: u64 = 1 << 48;
|
||||
const FLAGS_MASK: u64 = (1 << 16) - 1;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub enum MappingFlags {
|
||||
Valid = 1,
|
||||
Dirty = 2,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Mapping {
|
||||
pub oblock: u64,
|
||||
pub flags: u32,
|
||||
}
|
||||
|
||||
impl Mapping {
|
||||
pub fn is_valid(&self) -> bool {
|
||||
(self.flags & MappingFlags::Valid as u32) != 0
|
||||
}
|
||||
|
||||
pub fn is_dirty(&self) -> bool {
|
||||
(self.flags & MappingFlags::Dirty as u32) != 0
|
||||
}
|
||||
}
|
||||
|
||||
impl Unpack for Mapping {
|
||||
fn disk_size() -> u32 {
|
||||
8
|
||||
}
|
||||
|
||||
fn unpack(i: &[u8]) -> IResult<&[u8], Mapping> {
|
||||
let (i, n) = le_u64(i)?;
|
||||
let oblock = n >> 16;
|
||||
let flags = n & FLAGS_MASK;
|
||||
|
||||
Ok((
|
||||
i,
|
||||
Mapping {
|
||||
oblock,
|
||||
flags: flags as u32,
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Pack for Mapping {
|
||||
fn pack<W: WriteBytesExt>(&self, data: &mut W) -> Result<()> {
|
||||
let m: u64 = (self.oblock << 16) | self.flags as u64;
|
||||
m.pack(data)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Mapping {
|
||||
fn default() -> Self {
|
||||
Mapping {
|
||||
oblock: 0,
|
||||
flags: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
Vendored
-19
@@ -1,19 +0,0 @@
|
||||
use anyhow::Result;
|
||||
|
||||
pub struct CacheMetadataSizeOptions {
|
||||
pub nr_blocks: u64,
|
||||
pub max_hint_width: u32, // bytes
|
||||
}
|
||||
|
||||
pub fn metadata_size(opts: &CacheMetadataSizeOptions) -> Result<u64> {
|
||||
const SECTOR_SHIFT: u64 = 9; // 512 bytes per sector
|
||||
const BYTES_PER_BLOCK_SHIFT: u64 = 4; // 16 bytes for key and value
|
||||
const TRANSACTION_OVERHEAD: u64 = 8192; // in sectors; 4 MB
|
||||
const HINT_OVERHEAD_PER_BLOCK: u64 = 8; // 8 bytes for the key
|
||||
|
||||
let mapping_size = (opts.nr_blocks << BYTES_PER_BLOCK_SHIFT) >> SECTOR_SHIFT;
|
||||
let hint_size =
|
||||
(opts.nr_blocks * (opts.max_hint_width as u64 + HINT_OVERHEAD_PER_BLOCK)) >> SECTOR_SHIFT;
|
||||
|
||||
Ok(TRANSACTION_OVERHEAD + mapping_size + hint_size)
|
||||
}
|
||||
Vendored
-10
@@ -1,10 +0,0 @@
|
||||
pub mod check;
|
||||
pub mod dump;
|
||||
pub mod hint;
|
||||
pub mod ir;
|
||||
pub mod mapping;
|
||||
pub mod metadata_size;
|
||||
pub mod repair;
|
||||
pub mod restore;
|
||||
pub mod superblock;
|
||||
pub mod xml;
|
||||
Vendored
-68
@@ -1,68 +0,0 @@
|
||||
use anyhow::Result;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::cache::dump::*;
|
||||
use crate::cache::restore::*;
|
||||
use crate::cache::superblock::*;
|
||||
use crate::io_engine::*;
|
||||
use crate::pdata::space_map_metadata::*;
|
||||
use crate::report::*;
|
||||
use crate::write_batcher::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub struct CacheRepairOptions<'a> {
|
||||
pub input: &'a Path,
|
||||
pub output: &'a Path,
|
||||
pub async_io: bool,
|
||||
pub report: Arc<Report>,
|
||||
}
|
||||
|
||||
struct Context {
|
||||
_report: Arc<Report>,
|
||||
engine_in: Arc<dyn IoEngine + Send + Sync>,
|
||||
engine_out: Arc<dyn IoEngine + Send + Sync>,
|
||||
}
|
||||
|
||||
const MAX_CONCURRENT_IO: u32 = 1024;
|
||||
|
||||
fn new_context(opts: &CacheRepairOptions) -> Result<Context> {
|
||||
let engine_in: Arc<dyn IoEngine + Send + Sync>;
|
||||
let engine_out: Arc<dyn IoEngine + Send + Sync>;
|
||||
|
||||
if opts.async_io {
|
||||
engine_in = Arc::new(AsyncIoEngine::new(opts.input, MAX_CONCURRENT_IO, false)?);
|
||||
engine_out = Arc::new(AsyncIoEngine::new(opts.output, MAX_CONCURRENT_IO, true)?);
|
||||
} else {
|
||||
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
||||
engine_in = Arc::new(SyncIoEngine::new(opts.input, nr_threads, false)?);
|
||||
engine_out = Arc::new(SyncIoEngine::new(opts.output, nr_threads, true)?);
|
||||
}
|
||||
|
||||
Ok(Context {
|
||||
_report: opts.report.clone(),
|
||||
engine_in,
|
||||
engine_out,
|
||||
})
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub fn repair(opts: CacheRepairOptions) -> Result<()> {
|
||||
let ctx = new_context(&opts)?;
|
||||
|
||||
let sb = read_superblock(ctx.engine_in.as_ref(), SUPERBLOCK_LOCATION)?;
|
||||
|
||||
let sm = core_metadata_sm(ctx.engine_out.get_nr_blocks(), u32::MAX);
|
||||
let mut w = WriteBatcher::new(
|
||||
ctx.engine_out.clone(),
|
||||
sm.clone(),
|
||||
ctx.engine_out.get_batch_size(),
|
||||
);
|
||||
let mut restorer = Restorer::new(&mut w);
|
||||
|
||||
dump_metadata(ctx.engine_in, &mut restorer, &sb, true)
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
Vendored
-313
@@ -1,313 +0,0 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
|
||||
use std::convert::TryInto;
|
||||
use std::fs::OpenOptions;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::cache::hint::Hint;
|
||||
use crate::cache::ir::{self, MetadataVisitor, Visit};
|
||||
use crate::cache::mapping::{Mapping, MappingFlags};
|
||||
use crate::cache::superblock::*;
|
||||
use crate::cache::xml;
|
||||
use crate::io_engine::*;
|
||||
use crate::math::*;
|
||||
use crate::pdata::array_builder::*;
|
||||
use crate::pdata::space_map_common::pack_root;
|
||||
use crate::pdata::space_map_metadata::*;
|
||||
use crate::report::*;
|
||||
use crate::write_batcher::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
const MAX_CONCURRENT_IO: u32 = 1024;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub struct CacheRestoreOptions<'a> {
|
||||
pub input: &'a Path,
|
||||
pub output: &'a Path,
|
||||
pub async_io: bool,
|
||||
pub report: Arc<Report>,
|
||||
}
|
||||
|
||||
struct Context {
|
||||
_report: Arc<Report>,
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
}
|
||||
|
||||
fn mk_context(opts: &CacheRestoreOptions) -> anyhow::Result<Context> {
|
||||
let engine: Arc<dyn IoEngine + Send + Sync>;
|
||||
|
||||
if opts.async_io {
|
||||
engine = Arc::new(AsyncIoEngine::new(opts.output, MAX_CONCURRENT_IO, true)?);
|
||||
} else {
|
||||
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
||||
engine = Arc::new(SyncIoEngine::new(opts.output, nr_threads, true)?);
|
||||
}
|
||||
|
||||
Ok(Context {
|
||||
_report: opts.report.clone(),
|
||||
engine,
|
||||
})
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum Section {
|
||||
None,
|
||||
Superblock,
|
||||
Mappings,
|
||||
Hints,
|
||||
Finalized,
|
||||
}
|
||||
|
||||
pub struct Restorer<'a> {
|
||||
write_batcher: &'a mut WriteBatcher,
|
||||
sb: Option<ir::Superblock>,
|
||||
mapping_builder: Option<ArrayBuilder<Mapping>>,
|
||||
dirty_builder: Option<ArrayBuilder<u64>>,
|
||||
hint_builder: Option<ArrayBuilder<Hint>>,
|
||||
mapping_root: Option<u64>,
|
||||
dirty_root: Option<u64>,
|
||||
hint_root: Option<u64>,
|
||||
discard_root: Option<u64>,
|
||||
dirty_bits: (u32, u64), // (index in u64 array, value)
|
||||
in_section: Section,
|
||||
}
|
||||
|
||||
impl<'a> Restorer<'a> {
|
||||
pub fn new(w: &'a mut WriteBatcher) -> Restorer<'a> {
|
||||
Restorer {
|
||||
write_batcher: w,
|
||||
sb: None,
|
||||
mapping_builder: None,
|
||||
dirty_builder: None,
|
||||
hint_builder: None,
|
||||
mapping_root: None,
|
||||
dirty_root: None,
|
||||
hint_root: None,
|
||||
discard_root: None,
|
||||
dirty_bits: (0, 0),
|
||||
in_section: Section::None,
|
||||
}
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
let src_sb;
|
||||
if let Some(sb) = self.sb.take() {
|
||||
src_sb = sb;
|
||||
} else {
|
||||
return Err(anyhow!("not in superblock"));
|
||||
}
|
||||
|
||||
// complete the mapping array
|
||||
if let Some(builder) = self.mapping_builder.take() {
|
||||
self.mapping_root = Some(builder.complete(self.write_batcher)?);
|
||||
}
|
||||
|
||||
// complete the dirty array
|
||||
if let Some(mut builder) = self.dirty_builder.take() {
|
||||
// push the bufferred trailing bits
|
||||
builder.push_value(
|
||||
self.write_batcher,
|
||||
self.dirty_bits.0 as u64,
|
||||
self.dirty_bits.1,
|
||||
)?;
|
||||
|
||||
self.dirty_root = Some(builder.complete(self.write_batcher)?);
|
||||
}
|
||||
|
||||
// complete the hint array
|
||||
if let Some(builder) = self.hint_builder.take() {
|
||||
self.hint_root = Some(builder.complete(self.write_batcher)?);
|
||||
}
|
||||
|
||||
// build metadata space map
|
||||
let metadata_sm_root = build_metadata_sm(self.write_batcher)?;
|
||||
|
||||
let mapping_root = self.mapping_root.as_ref().unwrap();
|
||||
let hint_root = self.hint_root.as_ref().unwrap();
|
||||
let discard_root = self.discard_root.as_ref().unwrap();
|
||||
let sb = Superblock {
|
||||
flags: SuperblockFlags {
|
||||
clean_shutdown: true,
|
||||
needs_check: false,
|
||||
},
|
||||
block: SUPERBLOCK_LOCATION,
|
||||
version: 2,
|
||||
policy_name: src_sb.policy.as_bytes().to_vec(),
|
||||
policy_version: vec![2, 0, 0],
|
||||
policy_hint_size: src_sb.hint_width,
|
||||
metadata_sm_root,
|
||||
mapping_root: *mapping_root,
|
||||
dirty_root: self.dirty_root, // dirty_root is optional
|
||||
hint_root: *hint_root,
|
||||
discard_root: *discard_root,
|
||||
discard_block_size: 0,
|
||||
discard_nr_blocks: 0,
|
||||
data_block_size: src_sb.block_size,
|
||||
cache_blocks: src_sb.nr_cache_blocks,
|
||||
compat_flags: 0,
|
||||
compat_ro_flags: 0,
|
||||
incompat_flags: 0,
|
||||
read_hits: 0,
|
||||
read_misses: 9,
|
||||
write_hits: 0,
|
||||
write_misses: 0,
|
||||
};
|
||||
write_superblock(self.write_batcher.engine.as_ref(), SUPERBLOCK_LOCATION, &sb)?;
|
||||
|
||||
self.in_section = Section::Finalized;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> MetadataVisitor for Restorer<'a> {
|
||||
fn superblock_b(&mut self, sb: &ir::Superblock) -> Result<Visit> {
|
||||
if self.in_section != Section::None {
|
||||
return Err(anyhow!("duplicated superblock"));
|
||||
}
|
||||
|
||||
self.sb = Some(sb.clone());
|
||||
let b = self.write_batcher.alloc()?;
|
||||
if b.loc != SUPERBLOCK_LOCATION {
|
||||
return Err(anyhow!("superblock was occupied"));
|
||||
}
|
||||
|
||||
self.mapping_builder = Some(ArrayBuilder::new(sb.nr_cache_blocks as u64));
|
||||
self.dirty_builder = Some(ArrayBuilder::new(div_up(sb.nr_cache_blocks as u64, 64)));
|
||||
self.hint_builder = Some(ArrayBuilder::new(sb.nr_cache_blocks as u64));
|
||||
|
||||
let discard_builder = ArrayBuilder::<u64>::new(0); // discard bitset is optional
|
||||
self.discard_root = Some(discard_builder.complete(self.write_batcher)?);
|
||||
self.in_section = Section::Superblock;
|
||||
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn superblock_e(&mut self) -> Result<Visit> {
|
||||
self.finalize()?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn mappings_b(&mut self) -> Result<Visit> {
|
||||
if self.in_section != Section::Superblock {
|
||||
return Err(anyhow!("not in superblock"));
|
||||
}
|
||||
self.in_section = Section::Mappings;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn mappings_e(&mut self) -> Result<Visit> {
|
||||
if self.in_section != Section::Mappings {
|
||||
return Err(anyhow!("not in mappings"));
|
||||
}
|
||||
self.in_section = Section::Superblock;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn mapping(&mut self, m: &ir::Map) -> Result<Visit> {
|
||||
let map = Mapping {
|
||||
oblock: m.oblock,
|
||||
flags: MappingFlags::Valid as u32,
|
||||
};
|
||||
let mapping_builder = self.mapping_builder.as_mut().unwrap();
|
||||
mapping_builder.push_value(self.write_batcher, m.cblock as u64, map)?;
|
||||
|
||||
if m.dirty {
|
||||
let index = m.cblock >> 6;
|
||||
let mask = 1 << (m.cblock & 63);
|
||||
if index == self.dirty_bits.0 {
|
||||
self.dirty_bits.1 |= mask;
|
||||
} else {
|
||||
let dirty_builder = self.dirty_builder.as_mut().unwrap();
|
||||
dirty_builder.push_value(
|
||||
self.write_batcher,
|
||||
self.dirty_bits.0 as u64,
|
||||
self.dirty_bits.1,
|
||||
)?;
|
||||
self.dirty_bits.0 = index;
|
||||
self.dirty_bits.1 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn hints_b(&mut self) -> Result<Visit> {
|
||||
if self.in_section != Section::Superblock {
|
||||
return Err(anyhow!("not in superblock"));
|
||||
}
|
||||
self.in_section = Section::Hints;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn hints_e(&mut self) -> Result<Visit> {
|
||||
if self.in_section != Section::Hints {
|
||||
return Err(anyhow!("not in hints"));
|
||||
}
|
||||
self.in_section = Section::Superblock;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn hint(&mut self, h: &ir::Hint) -> Result<Visit> {
|
||||
let hint = Hint {
|
||||
hint: h.data[..].try_into().unwrap(),
|
||||
};
|
||||
let hint_builder = self.hint_builder.as_mut().unwrap();
|
||||
hint_builder.push_value(self.write_batcher, h.cblock as u64, hint)?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn discards_b(&mut self) -> Result<Visit> {
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn discards_e(&mut self) -> Result<Visit> {
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn discard(&mut self, _d: &ir::Discard) -> Result<Visit> {
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn eof(&mut self) -> Result<Visit> {
|
||||
if self.in_section != Section::Finalized {
|
||||
return Err(anyhow!("incompleted source metadata"));
|
||||
}
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
fn build_metadata_sm(w: &mut WriteBatcher) -> Result<Vec<u8>> {
|
||||
let r = write_metadata_sm(w)?;
|
||||
let sm_root = pack_root(&r, SPACE_MAP_ROOT_SIZE)?;
|
||||
|
||||
Ok(sm_root)
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub fn restore(opts: CacheRestoreOptions) -> Result<()> {
|
||||
let input = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(false)
|
||||
.open(opts.input)?;
|
||||
|
||||
let ctx = mk_context(&opts)?;
|
||||
|
||||
let sm = core_metadata_sm(ctx.engine.get_nr_blocks(), u32::MAX);
|
||||
let mut w = WriteBatcher::new(ctx.engine.clone(), sm.clone(), ctx.engine.get_batch_size());
|
||||
|
||||
// build cache mappings
|
||||
let mut restorer = Restorer::new(&mut w);
|
||||
xml::read(input, &mut restorer)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
Vendored
-224
@@ -1,224 +0,0 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use byteorder::{LittleEndian, WriteBytesExt};
|
||||
use nom::{bytes::complete::*, number::complete::*, IResult};
|
||||
use std::io::Cursor;
|
||||
|
||||
use crate::checksum::*;
|
||||
use crate::io_engine::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub const SPACE_MAP_ROOT_SIZE: usize = 128;
|
||||
pub const SUPERBLOCK_LOCATION: u64 = 0;
|
||||
|
||||
const MAGIC: u64 = 0o6142003; // 0x18c403 in hex
|
||||
const POLICY_NAME_SIZE: usize = 16;
|
||||
const UUID_SIZE: usize = 16;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SuperblockFlags {
|
||||
pub clean_shutdown: bool,
|
||||
pub needs_check: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Superblock {
|
||||
pub flags: SuperblockFlags,
|
||||
pub block: u64,
|
||||
pub version: u32,
|
||||
|
||||
pub policy_name: Vec<u8>,
|
||||
pub policy_version: Vec<u32>,
|
||||
pub policy_hint_size: u32,
|
||||
|
||||
pub metadata_sm_root: Vec<u8>,
|
||||
pub mapping_root: u64,
|
||||
pub dirty_root: Option<u64>, // format 2 only
|
||||
pub hint_root: u64,
|
||||
|
||||
pub discard_root: u64,
|
||||
pub discard_block_size: u64,
|
||||
pub discard_nr_blocks: u64,
|
||||
|
||||
pub data_block_size: u32,
|
||||
pub cache_blocks: u32,
|
||||
|
||||
pub compat_flags: u32,
|
||||
pub compat_ro_flags: u32,
|
||||
pub incompat_flags: u32,
|
||||
|
||||
pub read_hits: u32,
|
||||
pub read_misses: u32,
|
||||
pub write_hits: u32,
|
||||
pub write_misses: u32,
|
||||
}
|
||||
|
||||
fn unpack(data: &[u8]) -> IResult<&[u8], Superblock> {
|
||||
let (i, _csum) = le_u32(data)?;
|
||||
let (i, flags) = le_u32(i)?;
|
||||
let (i, block) = le_u64(i)?;
|
||||
let (i, _uuid) = take(16usize)(i)?;
|
||||
let (i, _magic) = le_u64(i)?;
|
||||
let (i, version) = le_u32(i)?;
|
||||
|
||||
let (i, policy_name) = take(POLICY_NAME_SIZE)(i)?;
|
||||
let (i, policy_hint_size) = le_u32(i)?;
|
||||
|
||||
let (i, metadata_sm_root) = take(SPACE_MAP_ROOT_SIZE)(i)?;
|
||||
let (i, mapping_root) = le_u64(i)?;
|
||||
let (i, hint_root) = le_u64(i)?;
|
||||
|
||||
let (i, discard_root) = le_u64(i)?;
|
||||
let (i, discard_block_size) = le_u64(i)?;
|
||||
let (i, discard_nr_blocks) = le_u64(i)?;
|
||||
|
||||
let (i, data_block_size) = le_u32(i)?;
|
||||
let (i, _metadata_block_size) = le_u32(i)?;
|
||||
let (i, cache_blocks) = le_u32(i)?;
|
||||
|
||||
let (i, compat_flags) = le_u32(i)?;
|
||||
let (i, compat_ro_flags) = le_u32(i)?;
|
||||
let (i, incompat_flags) = le_u32(i)?;
|
||||
|
||||
let (i, read_hits) = le_u32(i)?;
|
||||
let (i, read_misses) = le_u32(i)?;
|
||||
let (i, write_hits) = le_u32(i)?;
|
||||
let (i, write_misses) = le_u32(i)?;
|
||||
|
||||
let (i, vsn_major) = le_u32(i)?;
|
||||
let (i, vsn_minor) = le_u32(i)?;
|
||||
let (i, vsn_patch) = le_u32(i)?;
|
||||
|
||||
let mut i = i;
|
||||
let mut dirty_root = None;
|
||||
if version >= 2 {
|
||||
let (m, root) = le_u64(i)?;
|
||||
dirty_root = Some(root);
|
||||
i = m;
|
||||
}
|
||||
|
||||
Ok((
|
||||
i,
|
||||
Superblock {
|
||||
flags: SuperblockFlags {
|
||||
clean_shutdown: (flags & 0x1) != 0,
|
||||
needs_check: (flags & 0x2) != 0,
|
||||
},
|
||||
block,
|
||||
version,
|
||||
policy_name: policy_name.splitn(2, |c| *c == 0).next().unwrap().to_vec(),
|
||||
policy_version: vec![vsn_major, vsn_minor, vsn_patch],
|
||||
policy_hint_size,
|
||||
metadata_sm_root: metadata_sm_root.to_vec(),
|
||||
mapping_root,
|
||||
dirty_root,
|
||||
hint_root,
|
||||
discard_root,
|
||||
discard_block_size,
|
||||
discard_nr_blocks,
|
||||
data_block_size,
|
||||
cache_blocks,
|
||||
compat_flags,
|
||||
compat_ro_flags,
|
||||
incompat_flags,
|
||||
read_hits,
|
||||
read_misses,
|
||||
write_hits,
|
||||
write_misses,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn read_superblock(engine: &dyn IoEngine, loc: u64) -> Result<Superblock> {
|
||||
let b = engine.read(loc)?;
|
||||
|
||||
if metadata_block_type(b.get_data()) != BT::CACHE_SUPERBLOCK {
|
||||
return Err(anyhow!("bad checksum in superblock"));
|
||||
}
|
||||
|
||||
if let Ok((_, sb)) = unpack(b.get_data()) {
|
||||
Ok(sb)
|
||||
} else {
|
||||
Err(anyhow!("couldn't unpack superblock"))
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
fn pack_superblock<W: WriteBytesExt>(sb: &Superblock, w: &mut W) -> Result<()> {
|
||||
// checksum, which we don't know yet
|
||||
w.write_u32::<LittleEndian>(0)?;
|
||||
|
||||
// flags
|
||||
let mut flags: u32 = 0;
|
||||
if sb.flags.clean_shutdown {
|
||||
flags |= 0x1;
|
||||
}
|
||||
if sb.flags.needs_check {
|
||||
flags |= 0x2;
|
||||
}
|
||||
w.write_u32::<LittleEndian>(flags)?;
|
||||
|
||||
w.write_u64::<LittleEndian>(sb.block)?;
|
||||
w.write_all(&[0; UUID_SIZE])?;
|
||||
w.write_u64::<LittleEndian>(MAGIC)?;
|
||||
w.write_u32::<LittleEndian>(sb.version)?;
|
||||
|
||||
let mut policy_name = [0u8; POLICY_NAME_SIZE];
|
||||
policy_name[..sb.policy_name.len()].copy_from_slice(&sb.policy_name[..]);
|
||||
w.write_all(&policy_name)?;
|
||||
|
||||
w.write_u32::<LittleEndian>(sb.policy_hint_size)?;
|
||||
w.write_all(&sb.metadata_sm_root)?;
|
||||
w.write_u64::<LittleEndian>(sb.mapping_root)?;
|
||||
w.write_u64::<LittleEndian>(sb.hint_root)?;
|
||||
|
||||
w.write_u64::<LittleEndian>(sb.discard_root)?;
|
||||
w.write_u64::<LittleEndian>(sb.discard_block_size)?;
|
||||
w.write_u64::<LittleEndian>(sb.discard_nr_blocks)?;
|
||||
|
||||
w.write_u32::<LittleEndian>(sb.data_block_size)?;
|
||||
// metadata block size
|
||||
w.write_u32::<LittleEndian>((BLOCK_SIZE >> SECTOR_SHIFT) as u32)?;
|
||||
w.write_u32::<LittleEndian>(sb.cache_blocks)?;
|
||||
|
||||
w.write_u32::<LittleEndian>(sb.compat_flags)?;
|
||||
w.write_u32::<LittleEndian>(sb.compat_ro_flags)?;
|
||||
w.write_u32::<LittleEndian>(sb.incompat_flags)?;
|
||||
|
||||
w.write_u32::<LittleEndian>(sb.read_hits)?;
|
||||
w.write_u32::<LittleEndian>(sb.read_misses)?;
|
||||
w.write_u32::<LittleEndian>(sb.write_hits)?;
|
||||
w.write_u32::<LittleEndian>(sb.write_misses)?;
|
||||
|
||||
w.write_u32::<LittleEndian>(sb.policy_version[0])?;
|
||||
w.write_u32::<LittleEndian>(sb.policy_version[1])?;
|
||||
w.write_u32::<LittleEndian>(sb.policy_version[2])?;
|
||||
|
||||
if sb.dirty_root.is_some() {
|
||||
w.write_u64::<LittleEndian>(sb.dirty_root.unwrap())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_superblock(engine: &dyn IoEngine, _loc: u64, sb: &Superblock) -> Result<()> {
|
||||
let b = Block::zeroed(SUPERBLOCK_LOCATION);
|
||||
|
||||
// pack the superblock
|
||||
{
|
||||
let mut cursor = Cursor::new(b.get_data());
|
||||
pack_superblock(sb, &mut cursor)?;
|
||||
}
|
||||
|
||||
// calculate the checksum
|
||||
write_checksum(b.get_data(), BT::CACHE_SUPERBLOCK)?;
|
||||
|
||||
// write
|
||||
engine.write(&b)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
Vendored
-268
@@ -1,268 +0,0 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use base64::{decode, encode};
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use quick_xml::events::{BytesEnd, BytesStart, Event};
|
||||
use quick_xml::{Reader, Writer};
|
||||
|
||||
use crate::cache::ir::*;
|
||||
use crate::xml::*;
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
pub struct XmlWriter<W: Write> {
|
||||
w: Writer<W>,
|
||||
}
|
||||
|
||||
impl<W: Write> XmlWriter<W> {
|
||||
pub fn new(w: W) -> XmlWriter<W> {
|
||||
XmlWriter {
|
||||
w: Writer::new_with_indent(w, 0x20, 2),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<W: Write> MetadataVisitor for XmlWriter<W> {
|
||||
fn superblock_b(&mut self, sb: &Superblock) -> Result<Visit> {
|
||||
let tag = b"superblock";
|
||||
let mut elem = BytesStart::owned(tag.to_vec(), tag.len());
|
||||
elem.push_attribute(mk_attr(b"uuid", sb.uuid.clone()));
|
||||
elem.push_attribute(mk_attr(b"block_size", sb.block_size));
|
||||
elem.push_attribute(mk_attr(b"nr_cache_blocks", sb.nr_cache_blocks));
|
||||
elem.push_attribute(mk_attr(b"policy", sb.policy.clone()));
|
||||
elem.push_attribute(mk_attr(b"hint_width", sb.hint_width));
|
||||
|
||||
self.w.write_event(Event::Start(elem))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn superblock_e(&mut self) -> Result<Visit> {
|
||||
self.w
|
||||
.write_event(Event::End(BytesEnd::borrowed(b"superblock")))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn mappings_b(&mut self) -> Result<Visit> {
|
||||
let tag = b"mappings";
|
||||
let elem = BytesStart::owned(tag.to_vec(), tag.len());
|
||||
self.w.write_event(Event::Start(elem))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn mappings_e(&mut self) -> Result<Visit> {
|
||||
self.w
|
||||
.write_event(Event::End(BytesEnd::borrowed(b"mappings")))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn mapping(&mut self, m: &Map) -> Result<Visit> {
|
||||
let tag = b"mapping";
|
||||
let mut elem = BytesStart::owned(tag.to_vec(), tag.len());
|
||||
elem.push_attribute(mk_attr(b"cache_block", m.cblock));
|
||||
elem.push_attribute(mk_attr(b"origin_block", m.oblock));
|
||||
elem.push_attribute(mk_attr(b"dirty", m.dirty));
|
||||
self.w.write_event(Event::Empty(elem))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn hints_b(&mut self) -> Result<Visit> {
|
||||
let tag = b"hints";
|
||||
let elem = BytesStart::owned(tag.to_vec(), tag.len());
|
||||
self.w.write_event(Event::Start(elem))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn hints_e(&mut self) -> Result<Visit> {
|
||||
self.w
|
||||
.write_event(Event::End(BytesEnd::borrowed(b"hints")))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn hint(&mut self, h: &Hint) -> Result<Visit> {
|
||||
let tag = b"hint";
|
||||
let mut elem = BytesStart::owned(tag.to_vec(), tag.len());
|
||||
elem.push_attribute(mk_attr(b"cache_block", h.cblock));
|
||||
elem.push_attribute(mk_attr(b"data", encode(&h.data[0..])));
|
||||
self.w.write_event(Event::Empty(elem))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn discards_b(&mut self) -> Result<Visit> {
|
||||
let tag = b"discards";
|
||||
let elem = BytesStart::owned(tag.to_vec(), tag.len());
|
||||
self.w.write_event(Event::Start(elem))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn discards_e(&mut self) -> Result<Visit> {
|
||||
self.w
|
||||
.write_event(Event::End(BytesEnd::borrowed(b"discards")))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn discard(&mut self, d: &Discard) -> Result<Visit> {
|
||||
let tag = b"discard";
|
||||
let mut elem = BytesStart::owned(tag.to_vec(), tag.len());
|
||||
elem.push_attribute(mk_attr(b"dbegin", d.begin));
|
||||
elem.push_attribute(mk_attr(b"dend", d.end));
|
||||
self.w.write_event(Event::Empty(elem))?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn eof(&mut self) -> Result<Visit> {
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
fn parse_superblock(e: &BytesStart) -> Result<Superblock> {
|
||||
let mut uuid: Option<String> = None;
|
||||
let mut block_size: Option<u32> = None;
|
||||
let mut nr_cache_blocks: Option<u32> = None;
|
||||
let mut policy: Option<String> = None;
|
||||
let mut hint_width: Option<u32> = None;
|
||||
|
||||
for a in e.attributes() {
|
||||
let kv = a.unwrap();
|
||||
match kv.key {
|
||||
b"uuid" => uuid = Some(string_val(&kv)),
|
||||
b"block_size" => block_size = Some(u32_val(&kv)?),
|
||||
b"nr_cache_blocks" => nr_cache_blocks = Some(u32_val(&kv)?),
|
||||
b"policy" => policy = Some(string_val(&kv)),
|
||||
b"hint_width" => hint_width = Some(u32_val(&kv)?),
|
||||
_ => return bad_attr("superblock", kv.key),
|
||||
}
|
||||
}
|
||||
|
||||
let tag = "cache";
|
||||
|
||||
Ok(Superblock {
|
||||
uuid: check_attr(tag, "uuid", uuid)?,
|
||||
block_size: check_attr(tag, "block_size", block_size)?,
|
||||
nr_cache_blocks: check_attr(tag, "nr_cache_blocks", nr_cache_blocks)?,
|
||||
policy: check_attr(tag, "policy", policy)?,
|
||||
hint_width: check_attr(tag, "hint_width", hint_width)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_mapping(e: &BytesStart) -> Result<Map> {
|
||||
let mut cblock: Option<u32> = None;
|
||||
let mut oblock: Option<u64> = None;
|
||||
let mut dirty: Option<bool> = None;
|
||||
|
||||
for a in e.attributes() {
|
||||
let kv = a.unwrap();
|
||||
match kv.key {
|
||||
b"cache_block" => cblock = Some(u32_val(&kv)?),
|
||||
b"origin_block" => oblock = Some(u64_val(&kv)?),
|
||||
b"dirty" => dirty = Some(bool_val(&kv)?),
|
||||
_ => return bad_attr("mapping", kv.key),
|
||||
}
|
||||
}
|
||||
|
||||
let tag = "mapping";
|
||||
|
||||
Ok(Map {
|
||||
cblock: check_attr(tag, "cache_block", cblock)?,
|
||||
oblock: check_attr(tag, "origin_block", oblock)?,
|
||||
dirty: check_attr(tag, "dirty", dirty)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_hint(e: &BytesStart) -> Result<Hint> {
|
||||
let mut cblock: Option<u32> = None;
|
||||
let mut data: Option<Vec<u8>> = None;
|
||||
|
||||
for a in e.attributes() {
|
||||
let kv = a.unwrap();
|
||||
match kv.key {
|
||||
b"cache_block" => cblock = Some(u32_val(&kv)?),
|
||||
b"data" => data = Some(decode(bytes_val(&kv))?),
|
||||
_ => return bad_attr("mapping", kv.key),
|
||||
}
|
||||
}
|
||||
|
||||
let tag = "hint";
|
||||
|
||||
Ok(Hint {
|
||||
cblock: check_attr(tag, "cache_block", cblock)?,
|
||||
data: check_attr(tag, "data", data)?,
|
||||
})
|
||||
}
|
||||
|
||||
fn handle_event<R, M>(reader: &mut Reader<R>, buf: &mut Vec<u8>, visitor: &mut M) -> Result<Visit>
|
||||
where
|
||||
R: Read + BufRead,
|
||||
M: MetadataVisitor,
|
||||
{
|
||||
match reader.read_event(buf) {
|
||||
Ok(Event::Start(ref e)) => match e.name() {
|
||||
b"superblock" => visitor.superblock_b(&parse_superblock(e)?),
|
||||
b"mappings" => visitor.mappings_b(),
|
||||
b"hints" => visitor.hints_b(),
|
||||
_ => {
|
||||
return Err(anyhow!(
|
||||
"Parse error 1 at byte {}",
|
||||
reader.buffer_position()
|
||||
))
|
||||
}
|
||||
},
|
||||
Ok(Event::End(ref e)) => match e.name() {
|
||||
b"superblock" => visitor.superblock_e(),
|
||||
b"mappings" => visitor.mappings_e(),
|
||||
b"hints" => visitor.hints_e(),
|
||||
_ => {
|
||||
return Err(anyhow!(
|
||||
"Parse error 2 at byte {}",
|
||||
reader.buffer_position()
|
||||
))
|
||||
}
|
||||
},
|
||||
Ok(Event::Empty(ref e)) => match e.name() {
|
||||
b"mapping" => visitor.mapping(&parse_mapping(e)?),
|
||||
b"hint" => visitor.hint(&parse_hint(e)?),
|
||||
_ => {
|
||||
return Err(anyhow!(
|
||||
"Parse error 3 at byte {}",
|
||||
reader.buffer_position()
|
||||
))
|
||||
}
|
||||
},
|
||||
Ok(Event::Text(_)) => Ok(Visit::Continue),
|
||||
Ok(Event::Comment(_)) => Ok(Visit::Continue),
|
||||
Ok(Event::Eof) => {
|
||||
visitor.eof()?;
|
||||
Ok(Visit::Stop)
|
||||
}
|
||||
Ok(_) => {
|
||||
return Err(anyhow!(
|
||||
"Parse error 4 at byte {}",
|
||||
reader.buffer_position()
|
||||
))
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(anyhow!(
|
||||
"Parse error 5 at byte {}: {:?}",
|
||||
reader.buffer_position(),
|
||||
e
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read<R, M>(input: R, visitor: &mut M) -> Result<()>
|
||||
where
|
||||
R: Read,
|
||||
M: MetadataVisitor,
|
||||
{
|
||||
let input = BufReader::new(input);
|
||||
let mut reader = Reader::from_reader(input);
|
||||
|
||||
reader.trim_text(true);
|
||||
let mut buf = Vec::new();
|
||||
|
||||
while let Visit::Continue = handle_event(&mut reader, &mut buf, visitor)? {}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use crc32c::crc32c;
|
||||
|
||||
use std::io::Cursor;
|
||||
|
||||
const BLOCK_SIZE: u64 = 4096;
|
||||
const THIN_SUPERBLOCK_CSUM_XOR: u32 = 160774;
|
||||
const CACHE_SUPERBLOCK_CSUM_XOR: u32 = 9031977;
|
||||
const ERA_SUPERBLOCK_CSUM_XOR: u32 = 146538381;
|
||||
const BITMAP_CSUM_XOR: u32 = 240779;
|
||||
const INDEX_CSUM_XOR: u32 = 160478;
|
||||
const BTREE_CSUM_XOR: u32 = 121107;
|
||||
const ARRAY_CSUM_XOR: u32 = 595846735;
|
||||
|
||||
fn checksum(buf: &[u8]) -> u32 {
|
||||
crc32c(&buf[4..]) ^ 0xffffffff
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum BT {
|
||||
THIN_SUPERBLOCK,
|
||||
CACHE_SUPERBLOCK,
|
||||
ERA_SUPERBLOCK,
|
||||
NODE,
|
||||
INDEX,
|
||||
BITMAP,
|
||||
ARRAY,
|
||||
UNKNOWN,
|
||||
}
|
||||
|
||||
pub fn metadata_block_type(buf: &[u8]) -> BT {
|
||||
if buf.len() != BLOCK_SIZE as usize {
|
||||
return BT::UNKNOWN;
|
||||
}
|
||||
|
||||
// The checksum is always stored in the first u32 of the buffer.
|
||||
let mut rdr = Cursor::new(buf);
|
||||
let sum_on_disk = rdr.read_u32::<LittleEndian>().unwrap();
|
||||
let csum = checksum(buf);
|
||||
let btype = csum ^ sum_on_disk;
|
||||
|
||||
match btype {
|
||||
THIN_SUPERBLOCK_CSUM_XOR => BT::THIN_SUPERBLOCK,
|
||||
CACHE_SUPERBLOCK_CSUM_XOR => BT::CACHE_SUPERBLOCK,
|
||||
ERA_SUPERBLOCK_CSUM_XOR => BT::ERA_SUPERBLOCK,
|
||||
BTREE_CSUM_XOR => BT::NODE,
|
||||
BITMAP_CSUM_XOR => BT::BITMAP,
|
||||
INDEX_CSUM_XOR => BT::INDEX,
|
||||
ARRAY_CSUM_XOR => BT::ARRAY,
|
||||
_ => BT::UNKNOWN,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_checksum(buf: &mut [u8], kind: BT) -> Result<()> {
|
||||
if buf.len() != BLOCK_SIZE as usize {
|
||||
return Err(anyhow!("block is wrong size"));
|
||||
}
|
||||
|
||||
use BT::*;
|
||||
let salt = match kind {
|
||||
THIN_SUPERBLOCK => THIN_SUPERBLOCK_CSUM_XOR,
|
||||
CACHE_SUPERBLOCK => CACHE_SUPERBLOCK_CSUM_XOR,
|
||||
ERA_SUPERBLOCK => ERA_SUPERBLOCK_CSUM_XOR,
|
||||
NODE => BTREE_CSUM_XOR,
|
||||
BITMAP => BITMAP_CSUM_XOR,
|
||||
INDEX => INDEX_CSUM_XOR,
|
||||
ARRAY => ARRAY_CSUM_XOR,
|
||||
UNKNOWN => {
|
||||
return Err(anyhow!("Invalid block type"));
|
||||
}
|
||||
};
|
||||
|
||||
let csum = checksum(buf) ^ salt;
|
||||
let mut out = std::io::Cursor::new(buf);
|
||||
out.write_u32::<LittleEndian>(csum)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use atty::Stream;
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::cache::check::{check, CacheCheckOptions};
|
||||
use crate::commands::utils::*;
|
||||
use crate::report::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("cache_check")
|
||||
.version(crate::version::tools_version())
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("AUTO_REPAIR")
|
||||
.help("Auto repair trivial issues.")
|
||||
.long("auto-repair"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("IGNORE_NON_FATAL")
|
||||
.help("Only return a non-zero exit code if a fatal error is found.")
|
||||
.long("ignore-non-fatal-errors"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("QUIET")
|
||||
.help("Suppress output messages, return only exit code.")
|
||||
.short("q")
|
||||
.long("quiet"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("SB_ONLY")
|
||||
.help("Only check the superblock.")
|
||||
.long("super-block-only"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("SKIP_HINTS")
|
||||
.help("Don't check the hint array")
|
||||
.long("skip-hints"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("SKIP_DISCARDS")
|
||||
.help("Don't check the discard bitset")
|
||||
.long("skip-discards"),
|
||||
)
|
||||
// arguments
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device to check")
|
||||
.required(true)
|
||||
.index(1),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
|
||||
let report = if matches.is_present("QUIET") {
|
||||
std::sync::Arc::new(mk_quiet_report())
|
||||
} else if atty::is(Stream::Stdout) {
|
||||
std::sync::Arc::new(mk_progress_bar_report())
|
||||
} else {
|
||||
Arc::new(mk_simple_report())
|
||||
};
|
||||
|
||||
check_input_file(input_file, &report);
|
||||
check_file_not_tiny(input_file, &report);
|
||||
|
||||
let opts = CacheCheckOptions {
|
||||
dev: input_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
sb_only: matches.is_present("SB_ONLY"),
|
||||
skip_mappings: matches.is_present("SKIP_MAPPINGS"),
|
||||
skip_hints: matches.is_present("SKIP_HINTS"),
|
||||
skip_discards: matches.is_present("SKIP_DISCARDS"),
|
||||
ignore_non_fatal: matches.is_present("IGNORE_NON_FATAL"),
|
||||
auto_repair: matches.is_present("AUTO_REPAIR"),
|
||||
report: report.clone(),
|
||||
};
|
||||
|
||||
if let Err(reason) = check(opts) {
|
||||
report.fatal(&format!("{}", reason));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,73 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
|
||||
use crate::cache::dump::{dump, CacheDumpOptions};
|
||||
use crate::commands::utils::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("cache_dump")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Dump the cache metadata to stdout in XML format")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("REPAIR")
|
||||
.help("Repair the metadata whilst dumping it")
|
||||
.short("r")
|
||||
.long("repair"),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify the output file rather than stdout")
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE"),
|
||||
)
|
||||
// arguments
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device to dump")
|
||||
.required(true)
|
||||
.index(1),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = if matches.is_present("OUTPUT") {
|
||||
Some(Path::new(matches.value_of("OUTPUT").unwrap()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Create a temporary report just in case these checks
|
||||
// need to report anything.
|
||||
let report = std::sync::Arc::new(crate::report::mk_simple_report());
|
||||
check_input_file(input_file, &report);
|
||||
check_file_not_tiny(input_file, &report);
|
||||
drop(report);
|
||||
|
||||
let opts = CacheDumpOptions {
|
||||
input: input_file,
|
||||
output: output_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
repair: matches.is_present("REPAIR"),
|
||||
};
|
||||
|
||||
if let Err(reason) = dump(opts) {
|
||||
eprintln!("{}", reason);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,88 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{value_t_or_exit, App, Arg, ArgGroup};
|
||||
use std::ffi::OsString;
|
||||
use std::process;
|
||||
|
||||
use crate::cache::metadata_size::{metadata_size, CacheMetadataSizeOptions};
|
||||
use crate::math::div_up;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
fn parse_args<I, T>(args: I) -> CacheMetadataSizeOptions
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<OsString> + Clone,
|
||||
{
|
||||
let parser = App::new("cache_metadata_size")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Estimate the size of the metadata device needed for a given configuration.")
|
||||
.usage("cache_metadata_size [OPTIONS] <--device-size <SECTORS> --block-size <SECTORS> | --nr-blocks <NUM>>")
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("BLOCK_SIZE")
|
||||
.help("Specify the size of each cache block")
|
||||
.long("block-size")
|
||||
.requires("DEVICE_SIZE")
|
||||
.value_name("SECTORS"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("DEVICE_SIZE")
|
||||
.help("Specify total size of the fast device used in the cache")
|
||||
.long("device-size")
|
||||
.requires("BLOCK_SIZE")
|
||||
.value_name("SECTORS"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("NR_BLOCKS")
|
||||
.help("Specify the number of cache blocks")
|
||||
.long("nr-blocks")
|
||||
.value_name("NUM"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("MAX_HINT_WIDTH")
|
||||
.help("Specity the per-block hint width")
|
||||
.long("max-hint-width")
|
||||
.value_name("BYTES")
|
||||
.default_value("4"),
|
||||
)
|
||||
.group(
|
||||
ArgGroup::with_name("selection")
|
||||
.args(&["DEVICE_SIZE", "NR_BLOCKS"])
|
||||
.required(true)
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
|
||||
let nr_blocks = matches.value_of("NR_BLOCKS").map_or_else(
|
||||
|| {
|
||||
let device_size = value_t_or_exit!(matches.value_of("DEVICE_SIZE"), u64);
|
||||
let block_size = value_t_or_exit!(matches.value_of("BLOCK_SIZE"), u32);
|
||||
div_up(device_size, block_size as u64)
|
||||
},
|
||||
|_| value_t_or_exit!(matches.value_of("NR_BLOCKS"), u64),
|
||||
);
|
||||
|
||||
let max_hint_width = value_t_or_exit!(matches.value_of("MAX_HINT_WIDTH"), u32);
|
||||
|
||||
CacheMetadataSizeOptions {
|
||||
nr_blocks,
|
||||
max_hint_width,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let opts = parse_args(args);
|
||||
|
||||
match metadata_size(&opts) {
|
||||
Ok(size) => {
|
||||
println!("{} sectors", size);
|
||||
}
|
||||
Err(reason) => {
|
||||
eprintln!("{}", reason);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,73 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use atty::Stream;
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::cache::repair::{repair, CacheRepairOptions};
|
||||
use crate::commands::utils::*;
|
||||
use crate::report::*;
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("cache_repair")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Repair binary cache metadata, and write it to a different device or file")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("QUIET")
|
||||
.help("Suppress output messages, return only exit code.")
|
||||
.short("q")
|
||||
.long("quiet"),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device")
|
||||
.short("i")
|
||||
.long("input")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify the output device")
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
||||
|
||||
let report = if matches.is_present("QUIET") {
|
||||
std::sync::Arc::new(mk_quiet_report())
|
||||
} else if atty::is(Stream::Stdout) {
|
||||
std::sync::Arc::new(mk_progress_bar_report())
|
||||
} else {
|
||||
Arc::new(mk_simple_report())
|
||||
};
|
||||
|
||||
check_input_file(input_file, &report);
|
||||
|
||||
let opts = CacheRepairOptions {
|
||||
input: input_file,
|
||||
output: output_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
report: report.clone(),
|
||||
};
|
||||
|
||||
if let Err(reason) = repair(opts) {
|
||||
report.fatal(&format!("{}", reason));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
|
||||
use crate::cache::restore::{restore, CacheRestoreOptions};
|
||||
use crate::commands::utils::*;
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("cache_restore")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Convert XML format metadata to binary.")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("QUIET")
|
||||
.help("Suppress output messages, return only exit code.")
|
||||
.short("q")
|
||||
.long("quiet"),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input xml")
|
||||
.short("i")
|
||||
.long("input")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify the output device to check")
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
||||
|
||||
let report = mk_report(matches.is_present("QUIET"));
|
||||
check_input_file(input_file, &report);
|
||||
check_output_file(output_file, &report);
|
||||
|
||||
let opts = CacheRestoreOptions {
|
||||
input: input_file,
|
||||
output: output_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
report: report.clone(),
|
||||
};
|
||||
|
||||
if let Err(reason) = restore(opts) {
|
||||
report.fatal(&format!("{}", reason));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use atty::Stream;
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
use crate::era::check::{check, EraCheckOptions};
|
||||
use crate::report::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("era_check")
|
||||
.version(crate::version::tools_version())
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("IGNORE_NON_FATAL")
|
||||
.help("Only return a non-zero exit code if a fatal error is found.")
|
||||
.long("ignore-non-fatal-errors"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("QUIET")
|
||||
.help("Suppress output messages, return only exit code.")
|
||||
.short("q")
|
||||
.long("quiet"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("SB_ONLY")
|
||||
.help("Only check the superblock.")
|
||||
.long("super-block-only"),
|
||||
)
|
||||
// arguments
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device to check")
|
||||
.required(true)
|
||||
.index(1),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
|
||||
let report = if matches.is_present("QUIET") {
|
||||
std::sync::Arc::new(mk_quiet_report())
|
||||
} else if atty::is(Stream::Stdout) {
|
||||
std::sync::Arc::new(mk_progress_bar_report())
|
||||
} else {
|
||||
Arc::new(mk_simple_report())
|
||||
};
|
||||
|
||||
check_input_file(input_file, &report);
|
||||
check_file_not_tiny(input_file, &report);
|
||||
check_not_xml(input_file, &report);
|
||||
|
||||
let opts = EraCheckOptions {
|
||||
dev: input_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
sb_only: matches.is_present("SB_ONLY"),
|
||||
ignore_non_fatal: matches.is_present("IGNORE_NON_FATAL"),
|
||||
report: report.clone(),
|
||||
};
|
||||
|
||||
if let Err(reason) = check(&opts) {
|
||||
report.fatal(&format!("{}", reason));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,79 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
use crate::era::dump::{dump, EraDumpOptions};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("era_dump")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Dump the era metadata to stdout in XML format")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("LOGICAL")
|
||||
.help("Fold any unprocessed write sets into the final era array")
|
||||
.long("logical"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("REPAIR")
|
||||
.help("Repair the metadata whilst dumping it")
|
||||
.short("r")
|
||||
.long("repair"),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify the output file rather than stdout")
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE"),
|
||||
)
|
||||
// arguments
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device to dump")
|
||||
.required(true)
|
||||
.index(1),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = if matches.is_present("OUTPUT") {
|
||||
Some(Path::new(matches.value_of("OUTPUT").unwrap()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Create a temporary report just in case these checks
|
||||
// need to report anything.
|
||||
let report = std::sync::Arc::new(crate::report::mk_simple_report());
|
||||
check_input_file(input_file, &report);
|
||||
check_file_not_tiny(input_file, &report);
|
||||
drop(report);
|
||||
|
||||
let opts = EraDumpOptions {
|
||||
input: input_file,
|
||||
output: output_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
logical: matches.is_present("LOGICAL"),
|
||||
repair: matches.is_present("REPAIR"),
|
||||
};
|
||||
|
||||
if let Err(reason) = dump(opts) {
|
||||
eprintln!("{}", reason);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,85 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
use crate::era::invalidate::{invalidate, EraInvalidateOptions};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("era_invalidate")
|
||||
.version(crate::version::tools_version())
|
||||
.about("List blocks that may have changed since a given era")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify the output file rather than stdout")
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE"),
|
||||
)
|
||||
// arguments
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device to dump")
|
||||
.required(true)
|
||||
.index(1),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("WRITTEN_SINCE")
|
||||
.help("Blocks written since the given era will be listed")
|
||||
.long("written-since")
|
||||
.required(true)
|
||||
.value_name("ERA"),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = if matches.is_present("OUTPUT") {
|
||||
Some(Path::new(matches.value_of("OUTPUT").unwrap()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Create a temporary report just in case these checks
|
||||
// need to report anything.
|
||||
let report = std::sync::Arc::new(crate::report::mk_simple_report());
|
||||
check_input_file(input_file, &report);
|
||||
check_file_not_tiny(input_file, &report);
|
||||
drop(report);
|
||||
|
||||
let threshold = matches
|
||||
.value_of("WRITTEN_SINCE")
|
||||
.map(|s| {
|
||||
s.parse::<u32>().unwrap_or_else(|_| {
|
||||
eprintln!("Couldn't parse written_since");
|
||||
process::exit(1);
|
||||
})
|
||||
})
|
||||
.unwrap_or(0);
|
||||
|
||||
let opts = EraInvalidateOptions {
|
||||
input: input_file,
|
||||
output: output_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
threshold,
|
||||
metadata_snap: matches.is_present("METADATA_SNAP"),
|
||||
};
|
||||
|
||||
if let Err(reason) = invalidate(&opts) {
|
||||
eprintln!("{}", reason);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,73 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use atty::Stream;
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
use crate::era::repair::{repair, EraRepairOptions};
|
||||
use crate::report::*;
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("era_repair")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Repair binary era metadata, and write it to a different device or file")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("QUIET")
|
||||
.help("Suppress output messages, return only exit code.")
|
||||
.short("q")
|
||||
.long("quiet"),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device")
|
||||
.short("i")
|
||||
.long("input")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify the output device")
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
||||
|
||||
let report = if matches.is_present("QUIET") {
|
||||
std::sync::Arc::new(mk_quiet_report())
|
||||
} else if atty::is(Stream::Stdout) {
|
||||
std::sync::Arc::new(mk_progress_bar_report())
|
||||
} else {
|
||||
Arc::new(mk_simple_report())
|
||||
};
|
||||
|
||||
check_input_file(input_file, &report);
|
||||
|
||||
let opts = EraRepairOptions {
|
||||
input: input_file,
|
||||
output: output_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
report: report.clone(),
|
||||
};
|
||||
|
||||
if let Err(reason) = repair(opts) {
|
||||
report.fatal(&format!("{}", reason));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
use crate::era::restore::{restore, EraRestoreOptions};
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("era_restore")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Convert XML format metadata to binary.")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("QUIET")
|
||||
.help("Suppress output messages, return only exit code.")
|
||||
.short("q")
|
||||
.long("quiet"),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input xml")
|
||||
.short("i")
|
||||
.long("input")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify the output device to check")
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
||||
|
||||
let report = mk_report(matches.is_present("QUIET"));
|
||||
check_input_file(input_file, &report);
|
||||
check_output_file(output_file, &report);
|
||||
|
||||
let opts = EraRestoreOptions {
|
||||
input: input_file,
|
||||
output: output_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
report: report.clone(),
|
||||
};
|
||||
|
||||
if let Err(reason) = restore(opts) {
|
||||
report.fatal(&format!("{}", reason));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
pub mod cache_check;
|
||||
pub mod cache_dump;
|
||||
pub mod cache_metadata_size;
|
||||
pub mod cache_repair;
|
||||
pub mod cache_restore;
|
||||
pub mod era_check;
|
||||
pub mod era_dump;
|
||||
pub mod era_invalidate;
|
||||
pub mod era_repair;
|
||||
pub mod era_restore;
|
||||
pub mod thin_check;
|
||||
pub mod thin_dump;
|
||||
pub mod thin_metadata_pack;
|
||||
pub mod thin_metadata_size;
|
||||
pub mod thin_metadata_unpack;
|
||||
pub mod thin_repair;
|
||||
pub mod thin_restore;
|
||||
pub mod thin_shrink;
|
||||
pub mod utils;
|
||||
@@ -1,128 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
use crate::io_engine::*;
|
||||
use crate::thin::check::{check, ThinCheckOptions, MAX_CONCURRENT_IO};
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("thin_check")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Validates thin provisioning metadata on a device or file.")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("AUTO_REPAIR")
|
||||
.help("Auto repair trivial issues.")
|
||||
.long("auto-repair")
|
||||
.conflicts_with_all(&[
|
||||
"IGNORE_NON_FATAL",
|
||||
"METADATA_SNAPSHOT",
|
||||
"OVERRIDE_MAPPING_ROOT",
|
||||
"SB_ONLY",
|
||||
"SKIP_MAPPINGS",
|
||||
]),
|
||||
)
|
||||
.arg(
|
||||
// Using --clear-needs-check along with --skip-mappings is allowed
|
||||
// (but not recommended) for backward compatibility (commit 1fe8a0d)
|
||||
Arg::with_name("CLEAR_NEEDS_CHECK")
|
||||
.help("Clears the 'needs_check' flag in the superblock")
|
||||
.long("clear-needs-check-flag")
|
||||
.conflicts_with_all(&[
|
||||
"IGNORE_NON_FATAL",
|
||||
"METADATA_SNAPSHOT",
|
||||
"OVERRIDE_MAPPING_ROOT",
|
||||
"SB_ONLY",
|
||||
]),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("IGNORE_NON_FATAL")
|
||||
.help("Only return a non-zero exit code if a fatal error is found.")
|
||||
.long("ignore-non-fatal-errors"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("METADATA_SNAPSHOT")
|
||||
.help("Check the metadata snapshot on a live pool")
|
||||
.short("m")
|
||||
.long("metadata-snapshot"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("QUIET")
|
||||
.help("Suppress output messages, return only exit code.")
|
||||
.short("q")
|
||||
.long("quiet"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("SB_ONLY")
|
||||
.help("Only check the superblock.")
|
||||
.long("super-block-only"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("SKIP_MAPPINGS")
|
||||
.help("Don't check the mapping tree")
|
||||
.long("skip-mappings"),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("OVERRIDE_MAPPING_ROOT")
|
||||
.help("Specify a mapping root to use")
|
||||
.long("override-mapping-root")
|
||||
.value_name("OVERRIDE_MAPPING_ROOT")
|
||||
.takes_value(true),
|
||||
)
|
||||
// arguments
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device to check")
|
||||
.required(true)
|
||||
.index(1),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args.iter());
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
|
||||
let report = mk_report(matches.is_present("QUIET"));
|
||||
check_input_file(input_file, &report);
|
||||
check_file_not_tiny(input_file, &report);
|
||||
check_not_xml(input_file, &report);
|
||||
|
||||
let engine: Arc<dyn IoEngine + Send + Sync>;
|
||||
let writable = matches.is_present("AUTO_REPAIR") || matches.is_present("CLEAR_NEEDS_CHECK");
|
||||
|
||||
if matches.is_present("ASYNC_IO") {
|
||||
engine = Arc::new(
|
||||
AsyncIoEngine::new(input_file, MAX_CONCURRENT_IO, writable)
|
||||
.expect("unable to open input file"),
|
||||
);
|
||||
} else {
|
||||
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
||||
engine = Arc::new(
|
||||
SyncIoEngine::new(input_file, nr_threads, writable).expect("unable to open input file"),
|
||||
);
|
||||
}
|
||||
|
||||
let opts = ThinCheckOptions {
|
||||
engine,
|
||||
sb_only: matches.is_present("SB_ONLY"),
|
||||
skip_mappings: matches.is_present("SKIP_MAPPINGS"),
|
||||
ignore_non_fatal: matches.is_present("IGNORE_NON_FATAL"),
|
||||
auto_repair: matches.is_present("AUTO_REPAIR"),
|
||||
clear_needs_check: matches.is_present("CLEAR_NEEDS_CHECK"),
|
||||
report: report.clone(),
|
||||
};
|
||||
|
||||
if let Err(reason) = check(opts) {
|
||||
report.fatal(&format!("{}", reason));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use atty::Stream;
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
use crate::report::*;
|
||||
use crate::thin::dump::{dump, ThinDumpOptions};
|
||||
use crate::thin::metadata_repair::SuperblockOverrides;
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("thin_dump")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Dump thin-provisioning metadata to stdout in XML format")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("QUIET")
|
||||
.help("Suppress output messages, return only exit code.")
|
||||
.short("q")
|
||||
.long("quiet"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("REPAIR")
|
||||
.help("Repair the metadata whilst dumping it")
|
||||
.short("r")
|
||||
.long("repair"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("SKIP_MAPPINGS")
|
||||
.help("Do not dump the mappings")
|
||||
.long("skip-mappings"),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("DATA_BLOCK_SIZE")
|
||||
.help("Provide the data block size for repairing")
|
||||
.long("data-block-size")
|
||||
.value_name("SECTORS"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("METADATA_SNAPSHOT")
|
||||
.help("Access the metadata snapshot on a live pool")
|
||||
.short("m")
|
||||
.long("metadata-snapshot")
|
||||
.value_name("METADATA_SNAPSHOT"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("NR_DATA_BLOCKS")
|
||||
.help("Override the number of data blocks if needed")
|
||||
.long("nr-data-blocks")
|
||||
.value_name("NUM"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify the output file rather than stdout")
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("TRANSACTION_ID")
|
||||
.help("Override the transaction id if needed")
|
||||
.long("transaction-id")
|
||||
.value_name("NUM"),
|
||||
)
|
||||
// arguments
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device to dump")
|
||||
.required(true)
|
||||
.index(1),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = if matches.is_present("OUTPUT") {
|
||||
Some(Path::new(matches.value_of("OUTPUT").unwrap()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let report = std::sync::Arc::new(mk_simple_report());
|
||||
check_input_file(input_file, &report);
|
||||
|
||||
let transaction_id = matches.value_of("TRANSACTION_ID").map(|s| {
|
||||
s.parse::<u64>().unwrap_or_else(|_| {
|
||||
eprintln!("Couldn't parse transaction_id");
|
||||
process::exit(1);
|
||||
})
|
||||
});
|
||||
|
||||
let data_block_size = matches.value_of("DATA_BLOCK_SIZE").map(|s| {
|
||||
s.parse::<u32>().unwrap_or_else(|_| {
|
||||
eprintln!("Couldn't parse data_block_size");
|
||||
process::exit(1);
|
||||
})
|
||||
});
|
||||
|
||||
let nr_data_blocks = matches.value_of("NR_DATA_BLOCKS").map(|s| {
|
||||
s.parse::<u64>().unwrap_or_else(|_| {
|
||||
eprintln!("Couldn't parse nr_data_blocks");
|
||||
process::exit(1);
|
||||
})
|
||||
});
|
||||
|
||||
let report;
|
||||
|
||||
if matches.is_present("QUIET") {
|
||||
report = std::sync::Arc::new(mk_quiet_report());
|
||||
} else if atty::is(Stream::Stdout) {
|
||||
report = std::sync::Arc::new(mk_progress_bar_report());
|
||||
} else {
|
||||
report = Arc::new(mk_simple_report());
|
||||
}
|
||||
|
||||
let opts = ThinDumpOptions {
|
||||
input: input_file,
|
||||
output: output_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
report: report.clone(),
|
||||
repair: matches.is_present("REPAIR"),
|
||||
overrides: SuperblockOverrides {
|
||||
transaction_id,
|
||||
data_block_size,
|
||||
nr_data_blocks,
|
||||
},
|
||||
};
|
||||
|
||||
if let Err(reason) = dump(opts) {
|
||||
report.fatal(&format!("{}", reason));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
use crate::report::*;
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("thin_metadata_pack")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Produces a compressed file of thin metadata. Only packs metadata blocks that are actually used.")
|
||||
.arg(Arg::with_name("INPUT")
|
||||
.help("Specify thinp metadata binary device/file")
|
||||
.required(true)
|
||||
.short("i")
|
||||
.value_name("DEV")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("OUTPUT")
|
||||
.help("Specify packed output file")
|
||||
.required(true)
|
||||
.short("o")
|
||||
.value_name("FILE")
|
||||
.takes_value(true));
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
||||
|
||||
let report = std::sync::Arc::new(mk_simple_report());
|
||||
check_input_file(input_file, &report);
|
||||
|
||||
if let Err(reason) = crate::pack::toplevel::pack(input_file, output_file) {
|
||||
report.fatal(&format!("Application error: {}\n", reason));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{value_t_or_exit, App, Arg};
|
||||
use std::ffi::OsString;
|
||||
use std::process;
|
||||
|
||||
use crate::thin::metadata_size::{metadata_size, ThinMetadataSizeOptions};
|
||||
use crate::units::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
fn parse_args<I, T>(args: I) -> (ThinMetadataSizeOptions, Units, bool)
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<OsString> + Clone,
|
||||
{
|
||||
let parser = App::new("thin_metadata_size")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Estimate the size of the metadata device needed for a given configuration.")
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("BLOCK_SIZE")
|
||||
.help("Specify the data block size")
|
||||
.short("b")
|
||||
.long("block-size")
|
||||
.required(true)
|
||||
.value_name("SECTORS"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("POOL_SIZE")
|
||||
.help("Specify the size of pool device")
|
||||
.short("s")
|
||||
.long("pool-size")
|
||||
.required(true)
|
||||
.value_name("SECTORS"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("MAX_THINS")
|
||||
.help("Maximum number of thin devices and snapshots")
|
||||
.short("m")
|
||||
.long("max-thins")
|
||||
.required(true)
|
||||
.value_name("NUM"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("UNIT")
|
||||
.help("Specify the output unit")
|
||||
.short("u")
|
||||
.long("unit")
|
||||
.value_name("UNIT")
|
||||
.default_value("sector"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("NUMERIC_ONLY")
|
||||
.help("Output numeric value only")
|
||||
.short("n")
|
||||
.long("numeric-only"),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
|
||||
// TODO: handle unit suffix
|
||||
let pool_size = value_t_or_exit!(matches.value_of("POOL_SIZE"), u64);
|
||||
let block_size = value_t_or_exit!(matches.value_of("BLOCK_SIZE"), u32);
|
||||
let max_thins = value_t_or_exit!(matches.value_of("MAX_THINS"), u64);
|
||||
let unit = value_t_or_exit!(matches.value_of("UNIT"), Units);
|
||||
let numeric_only = matches.is_present("NUMERIC_ONLY");
|
||||
|
||||
(
|
||||
ThinMetadataSizeOptions {
|
||||
nr_blocks: pool_size / block_size as u64,
|
||||
max_thins,
|
||||
},
|
||||
unit,
|
||||
numeric_only,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let (opts, unit, numeric_only) = parse_args(args);
|
||||
|
||||
match metadata_size(&opts) {
|
||||
Ok(size) => {
|
||||
let size = to_units(size * 512, unit.clone());
|
||||
if numeric_only {
|
||||
println!("{}", size);
|
||||
} else {
|
||||
let mut name = unit.to_string();
|
||||
name.push('s');
|
||||
println!("{} {}", size, name);
|
||||
}
|
||||
}
|
||||
Err(reason) => {
|
||||
eprintln!("{}", reason);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,44 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use crate::file_utils;
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
|
||||
use std::process::exit;
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("thin_metadata_unpack")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Unpack a compressed file of thin metadata.")
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify thinp metadata binary device/file")
|
||||
.required(true)
|
||||
.short("i")
|
||||
.value_name("DEV")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify packed output file")
|
||||
.required(true)
|
||||
.short("o")
|
||||
.value_name("FILE")
|
||||
.takes_value(true),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
||||
|
||||
if !file_utils::is_file(input_file) {
|
||||
eprintln!("Invalid input file '{}'.", input_file.display());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if let Err(reason) = crate::pack::toplevel::unpack(input_file, output_file) {
|
||||
eprintln!("Application error: {}", reason);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
use crate::thin::metadata_repair::SuperblockOverrides;
|
||||
use crate::thin::repair::{repair, ThinRepairOptions};
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("thin_repair")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Repair thin-provisioning metadata, and write it to different device or file")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("QUIET")
|
||||
.help("Suppress output messages, return only exit code.")
|
||||
.short("q")
|
||||
.long("quiet"),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("DATA_BLOCK_SIZE")
|
||||
.help("Provide the data block size for repairing")
|
||||
.long("data-block-size")
|
||||
.value_name("SECTORS"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input device")
|
||||
.short("i")
|
||||
.long("input")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("NR_DATA_BLOCKS")
|
||||
.help("Override the number of data blocks if needed")
|
||||
.long("nr-data-blocks")
|
||||
.value_name("NUM"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify the output device")
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("TRANSACTION_ID")
|
||||
.help("Override the transaction id if needed")
|
||||
.long("transaction-id")
|
||||
.value_name("NUM"),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
||||
|
||||
let report = mk_report(matches.is_present("QUIET"));
|
||||
check_input_file(input_file, &report);
|
||||
check_output_file(output_file, &report);
|
||||
|
||||
let transaction_id = matches.value_of("TRANSACTION_ID").map(|s| {
|
||||
s.parse::<u64>().unwrap_or_else(|_| {
|
||||
report.fatal("Couldn't parse transaction_id");
|
||||
process::exit(1);
|
||||
})
|
||||
});
|
||||
|
||||
let data_block_size = matches.value_of("DATA_BLOCK_SIZE").map(|s| {
|
||||
s.parse::<u32>().unwrap_or_else(|_| {
|
||||
report.fatal("Couldn't parse data_block_size");
|
||||
process::exit(1);
|
||||
})
|
||||
});
|
||||
|
||||
let nr_data_blocks = matches.value_of("NR_DATA_BLOCKS").map(|s| {
|
||||
s.parse::<u64>().unwrap_or_else(|_| {
|
||||
report.fatal("Couldn't parse nr_data_blocks");
|
||||
process::exit(1);
|
||||
})
|
||||
});
|
||||
|
||||
let opts = ThinRepairOptions {
|
||||
input: input_file,
|
||||
output: output_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
report: report.clone(),
|
||||
overrides: SuperblockOverrides {
|
||||
transaction_id,
|
||||
data_block_size,
|
||||
nr_data_blocks,
|
||||
},
|
||||
};
|
||||
|
||||
if let Err(reason) = repair(opts) {
|
||||
report.fatal(&format!("{}", reason));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
use crate::thin::restore::{restore, ThinRestoreOptions};
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("thin_restore")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Convert XML format metadata to binary.")
|
||||
// flags
|
||||
.arg(
|
||||
Arg::with_name("ASYNC_IO")
|
||||
.help("Force use of io_uring for synchronous io")
|
||||
.long("async-io")
|
||||
.hidden(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("QUIET")
|
||||
.help("Suppress output messages, return only exit code.")
|
||||
.short("q")
|
||||
.long("quiet"),
|
||||
)
|
||||
// options
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify the input xml")
|
||||
.short("i")
|
||||
.long("input")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify the output device")
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE")
|
||||
.required(true),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
||||
|
||||
let report = mk_report(matches.is_present("QUIET"));
|
||||
check_input_file(input_file, &report);
|
||||
check_output_file(output_file, &report);
|
||||
|
||||
let opts = ThinRestoreOptions {
|
||||
input: input_file,
|
||||
output: output_file,
|
||||
async_io: matches.is_present("ASYNC_IO"),
|
||||
report: report.clone(),
|
||||
};
|
||||
|
||||
if let Err(reason) = restore(opts) {
|
||||
report.fatal(&format!("{}", reason));
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
// This work is based on the implementation by Nikhil Kshirsagar which
|
||||
// can be found here:
|
||||
// https://github.com/nkshirsagar/thinpool_shrink/blob/split_ranges/thin_shrink.py
|
||||
|
||||
extern crate clap;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
|
||||
use crate::commands::utils::*;
|
||||
|
||||
pub fn run(args: &[std::ffi::OsString]) {
|
||||
let parser = App::new("thin_shrink")
|
||||
.version(crate::version::tools_version())
|
||||
.about("Rewrite xml metadata and move data in an inactive pool.")
|
||||
.arg(
|
||||
Arg::with_name("INPUT")
|
||||
.help("Specify thinp metadata xml file")
|
||||
.required(true)
|
||||
.short("i")
|
||||
.long("input")
|
||||
.value_name("FILE")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("OUTPUT")
|
||||
.help("Specify output xml file")
|
||||
.required(true)
|
||||
.short("o")
|
||||
.long("output")
|
||||
.value_name("FILE")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("DATA")
|
||||
.help("Specify pool data device where data will be moved")
|
||||
.required(true)
|
||||
.long("data")
|
||||
.value_name("DATA")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("NOCOPY")
|
||||
.help("Skip the copying of data, useful for benchmarking")
|
||||
.required(false)
|
||||
.long("no-copy")
|
||||
.value_name("NOCOPY")
|
||||
.takes_value(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("SIZE")
|
||||
.help("Specify new size for the pool (in data blocks)")
|
||||
.required(true)
|
||||
.long("nr-blocks")
|
||||
.value_name("SIZE")
|
||||
.takes_value(true),
|
||||
);
|
||||
|
||||
let matches = parser.get_matches_from(args);
|
||||
|
||||
// FIXME: check these look like xml
|
||||
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
||||
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
||||
let size = matches.value_of("SIZE").unwrap().parse::<u64>().unwrap();
|
||||
let data_file = Path::new(matches.value_of("DATA").unwrap());
|
||||
let do_copy = !matches.is_present("NOCOPY");
|
||||
|
||||
let report = mk_report(false);
|
||||
check_input_file(input_file, &report);
|
||||
|
||||
if let Err(reason) =
|
||||
crate::shrink::toplevel::shrink(input_file, output_file, data_file, size, do_copy)
|
||||
{
|
||||
eprintln!("Application error: {}\n", reason);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
use anyhow::Result;
|
||||
use atty::Stream;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::process::exit;
|
||||
|
||||
use crate::file_utils;
|
||||
use crate::report::*;
|
||||
|
||||
pub fn check_input_file(input_file: &Path, report: &Report) {
|
||||
if !file_utils::file_exists(input_file) {
|
||||
report.fatal(&format!("Couldn't find input file '{:?}'.", &input_file));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if !file_utils::is_file_or_blk(input_file) {
|
||||
report.fatal(&format!(
|
||||
"Not a block device or regular file '{:?}'.",
|
||||
&input_file
|
||||
));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_file_not_tiny(input_file: &Path, report: &Report) {
|
||||
if file_utils::file_size(input_file).expect("couldn't get input size") < 4096 {
|
||||
report.fatal("Metadata device/file too small. Is this binary metadata?");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_output_file(path: &Path, report: &Report) {
|
||||
// minimal thin metadata size is 10 blocks, with one device
|
||||
match file_utils::file_size(path) {
|
||||
Ok(size) => {
|
||||
if size < 40960 {
|
||||
report.fatal("Output file too small.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
report.fatal(&format!("{}", e));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mk_report(quiet: bool) -> std::sync::Arc<Report> {
|
||||
use std::sync::Arc;
|
||||
|
||||
if quiet {
|
||||
Arc::new(mk_quiet_report())
|
||||
} else if atty::is(Stream::Stdout) {
|
||||
Arc::new(mk_progress_bar_report())
|
||||
} else {
|
||||
Arc::new(mk_simple_report())
|
||||
}
|
||||
}
|
||||
|
||||
fn is_xml(line: &[u8]) -> bool {
|
||||
line.starts_with(b"<superblock") || line.starts_with(b"?xml") || line.starts_with(b"<!DOCTYPE")
|
||||
}
|
||||
|
||||
pub fn check_not_xml_(input_file: &Path, report: &Report) -> Result<()> {
|
||||
let mut file = OpenOptions::new().read(true).open(input_file)?;
|
||||
let mut data = vec![0; 16];
|
||||
file.read_exact(&mut data)?;
|
||||
|
||||
if is_xml(&data) {
|
||||
report.fatal("This looks like XML. This tool only checks the binary metadata format.");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// This trys to read the start of input_path to see
|
||||
/// if it's xml. If there are any problems reading the file
|
||||
/// then it fails silently.
|
||||
pub fn check_not_xml(input_file: &Path, report: &Report) {
|
||||
let _ = check_not_xml_(input_file, report);
|
||||
}
|
||||
|
||||
//---------------------------------------
|
||||
@@ -1,152 +0,0 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::era::superblock::*;
|
||||
use crate::era::writeset::*;
|
||||
use crate::io_engine::{AsyncIoEngine, IoEngine, SyncIoEngine};
|
||||
use crate::pdata::array::{self, ArrayBlock, ArrayError};
|
||||
use crate::pdata::array_walker::*;
|
||||
use crate::pdata::bitset::*;
|
||||
use crate::pdata::btree_walker::*;
|
||||
use crate::pdata::space_map::*;
|
||||
use crate::report::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
const MAX_CONCURRENT_IO: u32 = 1024;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
fn inc_superblock(sm: &ASpaceMap) -> anyhow::Result<()> {
|
||||
let mut sm = sm.lock().unwrap();
|
||||
sm.inc(SUPERBLOCK_LOCATION, 1)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
struct EraChecker {
|
||||
current_era: u32,
|
||||
}
|
||||
|
||||
impl EraChecker {
|
||||
pub fn new(current_era: u32) -> EraChecker {
|
||||
EraChecker { current_era }
|
||||
}
|
||||
}
|
||||
|
||||
impl ArrayVisitor<u32> for EraChecker {
|
||||
fn visit(&self, index: u64, b: ArrayBlock<u32>) -> array::Result<()> {
|
||||
let mut errs: Vec<ArrayError> = Vec::new();
|
||||
|
||||
let dbegin = index as u32 * b.header.max_entries;
|
||||
let dend = dbegin + b.header.max_entries;
|
||||
for (era, dblock) in b.values.iter().zip(dbegin..dend) {
|
||||
if era > &self.current_era {
|
||||
errs.push(array::value_err(format!(
|
||||
"invalid era value at data block {}: {}",
|
||||
dblock, era
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
match errs.len() {
|
||||
0 => Ok(()),
|
||||
1 => Err(errs[0].clone()),
|
||||
_ => Err(array::aggregate_error(errs)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub struct EraCheckOptions<'a> {
|
||||
pub dev: &'a Path,
|
||||
pub async_io: bool,
|
||||
pub sb_only: bool,
|
||||
pub ignore_non_fatal: bool,
|
||||
pub report: Arc<Report>,
|
||||
}
|
||||
|
||||
struct Context {
|
||||
report: Arc<Report>,
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
}
|
||||
|
||||
fn mk_context(opts: &EraCheckOptions) -> anyhow::Result<Context> {
|
||||
let engine: Arc<dyn IoEngine + Send + Sync>;
|
||||
|
||||
if opts.async_io {
|
||||
engine = Arc::new(AsyncIoEngine::new(opts.dev, MAX_CONCURRENT_IO, false)?);
|
||||
} else {
|
||||
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
||||
engine = Arc::new(SyncIoEngine::new(opts.dev, nr_threads, false)?);
|
||||
}
|
||||
|
||||
Ok(Context {
|
||||
report: opts.report.clone(),
|
||||
engine,
|
||||
})
|
||||
}
|
||||
|
||||
fn check_superblock(sb: &Superblock) -> anyhow::Result<()> {
|
||||
if sb.version > 1 {
|
||||
return Err(anyhow!("unknown superblock version"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn check(opts: &EraCheckOptions) -> Result<()> {
|
||||
let ctx = mk_context(opts)?;
|
||||
let engine = &ctx.engine;
|
||||
let report = &ctx.report;
|
||||
let mut fatal = false;
|
||||
|
||||
report.set_title("Checking era metadata");
|
||||
|
||||
let metadata_sm = core_sm(engine.get_nr_blocks(), u8::MAX as u32);
|
||||
inc_superblock(&metadata_sm)?;
|
||||
|
||||
let sb = read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION)?;
|
||||
check_superblock(&sb)?;
|
||||
|
||||
if opts.sb_only {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut path = vec![0];
|
||||
let writesets = btree_to_map::<Writeset>(
|
||||
&mut path,
|
||||
engine.clone(),
|
||||
opts.ignore_non_fatal,
|
||||
sb.writeset_tree_root,
|
||||
)?;
|
||||
|
||||
for ws in writesets.values() {
|
||||
let (_bs, err) = read_bitset_with_sm(
|
||||
engine.clone(),
|
||||
ws.root,
|
||||
ws.nr_bits as usize,
|
||||
metadata_sm.clone(),
|
||||
opts.ignore_non_fatal,
|
||||
)?;
|
||||
if err.is_some() {
|
||||
ctx.report.fatal(&format!("{}", err.unwrap()));
|
||||
fatal = true;
|
||||
}
|
||||
}
|
||||
|
||||
let w = ArrayWalker::new_with_sm(engine.clone(), metadata_sm.clone(), opts.ignore_non_fatal)?;
|
||||
let mut c = EraChecker::new(sb.current_era);
|
||||
if let Err(e) = w.walk(&mut c, sb.era_array_root) {
|
||||
ctx.report.fatal(&format!("{}", e));
|
||||
fatal = true;
|
||||
}
|
||||
|
||||
if fatal {
|
||||
Err(anyhow!("fatal errors in metadata"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
-420
@@ -1,420 +0,0 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use fixedbitset::FixedBitSet;
|
||||
use std::convert::TryFrom;
|
||||
use std::fs::File;
|
||||
use std::io::BufWriter;
|
||||
use std::io::Write;
|
||||
use std::ops::Deref;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::era::ir::{self, MetadataVisitor};
|
||||
use crate::era::superblock::*;
|
||||
use crate::era::writeset::Writeset;
|
||||
use crate::era::xml;
|
||||
use crate::io_engine::{AsyncIoEngine, IoEngine, SyncIoEngine};
|
||||
use crate::pdata::array::{self, ArrayBlock};
|
||||
use crate::pdata::array_walker::*;
|
||||
use crate::pdata::bitset::read_bitset_no_err;
|
||||
use crate::pdata::btree_walker::btree_to_map;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
const MAX_CONCURRENT_IO: u32 = 1024;
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
struct EraEmitter<'a> {
|
||||
emitter: Mutex<&'a mut dyn MetadataVisitor>,
|
||||
}
|
||||
|
||||
impl<'a> EraEmitter<'a> {
|
||||
pub fn new(emitter: &'a mut dyn MetadataVisitor) -> EraEmitter {
|
||||
EraEmitter {
|
||||
emitter: Mutex::new(emitter),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArrayVisitor<u32> for EraEmitter<'a> {
|
||||
fn visit(&self, index: u64, b: ArrayBlock<u32>) -> array::Result<()> {
|
||||
let begin = index as u32 * b.header.max_entries;
|
||||
let end = begin + b.header.nr_entries;
|
||||
for (v, block) in b.values.iter().zip(begin..end) {
|
||||
let era = ir::Era { block, era: *v };
|
||||
|
||||
self.emitter
|
||||
.lock()
|
||||
.unwrap()
|
||||
.era(&era)
|
||||
.map_err(|e| array::value_err(format!("{}", e)))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
trait Archive {
|
||||
fn set(&mut self, key: u32, value: u32) -> Result<()>;
|
||||
fn get(&self, key: u32) -> Option<u32>;
|
||||
}
|
||||
|
||||
// In-core archive of writeset eras.
|
||||
// The actual era for a given block is `digested_era + deltas[b]` if `deltas[b]` is non-zero.
|
||||
struct EraArchive<T> {
|
||||
digested_era: u32, // maximum possible era in the era array
|
||||
deltas: Vec<T>,
|
||||
}
|
||||
|
||||
fn new_era_archive(nr_blocks: u32, archived_begin: u32, nr_writesets: u32) -> Box<dyn Archive> {
|
||||
match nr_writesets + 1 {
|
||||
0..=255 => Box::new(EraArchive {
|
||||
digested_era: archived_begin.wrapping_sub(1),
|
||||
deltas: vec![0u8; nr_blocks as usize],
|
||||
}),
|
||||
256..=65535 => Box::new(EraArchive {
|
||||
digested_era: archived_begin.wrapping_sub(1),
|
||||
deltas: vec![0u16; nr_blocks as usize],
|
||||
}),
|
||||
_ => Box::new(EraArchive {
|
||||
digested_era: archived_begin.wrapping_sub(1),
|
||||
deltas: vec![0u32; nr_blocks as usize],
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: std::convert::TryFrom<u32>> Archive for EraArchive<T>
|
||||
where
|
||||
T: Copy + Into<u32> + TryFrom<u32>,
|
||||
<T as TryFrom<u32>>::Error: std::fmt::Debug,
|
||||
{
|
||||
fn set(&mut self, block: u32, delta: u32) -> Result<()> {
|
||||
self.deltas[block as usize] = T::try_from(delta).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get(&self, block: u32) -> Option<u32> {
|
||||
if let Some(&delta) = self.deltas.get(block as usize) {
|
||||
let d: u32 = delta.into();
|
||||
if d == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(self.digested_era.wrapping_add(d))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
struct Inner<'a> {
|
||||
emitter: &'a mut dyn MetadataVisitor,
|
||||
era_archive: &'a dyn Archive,
|
||||
}
|
||||
|
||||
struct LogicalEraEmitter<'a> {
|
||||
inner: Mutex<Inner<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> LogicalEraEmitter<'a> {
|
||||
pub fn new(
|
||||
emitter: &'a mut dyn MetadataVisitor,
|
||||
era_archive: &'a dyn Archive,
|
||||
) -> LogicalEraEmitter<'a> {
|
||||
LogicalEraEmitter {
|
||||
inner: Mutex::new(Inner {
|
||||
emitter,
|
||||
era_archive,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArrayVisitor<u32> for LogicalEraEmitter<'a> {
|
||||
fn visit(&self, index: u64, b: ArrayBlock<u32>) -> array::Result<()> {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
|
||||
let begin = index as u32 * b.header.max_entries;
|
||||
let end = begin + b.header.nr_entries;
|
||||
for (v, block) in b.values.iter().zip(begin..end) {
|
||||
let era;
|
||||
if let Some(archived) = inner.era_archive.get(block) {
|
||||
era = ir::Era {
|
||||
block,
|
||||
era: archived,
|
||||
}
|
||||
} else {
|
||||
era = ir::Era { block, era: *v }
|
||||
};
|
||||
|
||||
inner
|
||||
.emitter
|
||||
.era(&era)
|
||||
.map_err(|e| array::value_err(format!("{}", e)))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub struct EraDumpOptions<'a> {
|
||||
pub input: &'a Path,
|
||||
pub output: Option<&'a Path>,
|
||||
pub async_io: bool,
|
||||
pub logical: bool,
|
||||
pub repair: bool,
|
||||
}
|
||||
|
||||
struct Context {
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
}
|
||||
|
||||
fn mk_context(opts: &EraDumpOptions) -> anyhow::Result<Context> {
|
||||
let engine: Arc<dyn IoEngine + Send + Sync>;
|
||||
|
||||
if opts.async_io {
|
||||
engine = Arc::new(AsyncIoEngine::new(opts.input, MAX_CONCURRENT_IO, false)?);
|
||||
} else {
|
||||
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
||||
engine = Arc::new(SyncIoEngine::new(opts.input, nr_threads, false)?);
|
||||
}
|
||||
|
||||
Ok(Context { engine })
|
||||
}
|
||||
|
||||
// notify the visitor about the marked blocks only
|
||||
fn dump_writeset(
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
out: &mut dyn MetadataVisitor,
|
||||
era: u32,
|
||||
ws: &Writeset,
|
||||
repair: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
// TODO: deal with broken writeset
|
||||
let bits = read_bitset_no_err(engine.clone(), ws.root, ws.nr_bits as usize, repair)?;
|
||||
|
||||
out.writeset_b(&ir::Writeset {
|
||||
era,
|
||||
nr_bits: ws.nr_bits,
|
||||
})?;
|
||||
|
||||
// [begin, end) denotes the range of set bits.
|
||||
let mut begin: u32 = 0;
|
||||
let mut end: u32 = 0;
|
||||
for (index, entry) in bits.as_slice().iter().enumerate() {
|
||||
let mut n = *entry;
|
||||
|
||||
if n == u32::MAX {
|
||||
end = std::cmp::min(end + 32, ws.nr_bits);
|
||||
continue;
|
||||
}
|
||||
|
||||
while n > 0 {
|
||||
let zeros = n.trailing_zeros();
|
||||
if zeros > 0 {
|
||||
if end > begin {
|
||||
let m = ir::MarkedBlocks {
|
||||
begin,
|
||||
len: end - begin,
|
||||
};
|
||||
out.writeset_blocks(&m)?;
|
||||
}
|
||||
n >>= zeros;
|
||||
end += zeros;
|
||||
begin = end;
|
||||
}
|
||||
|
||||
let ones = n.trailing_ones();
|
||||
n >>= ones;
|
||||
end = std::cmp::min(end + ones, ws.nr_bits);
|
||||
}
|
||||
|
||||
// emit the range if it ends before the entry boundary
|
||||
let endpos = ((index as u32) << 5) + 32;
|
||||
if end < endpos {
|
||||
if end > begin {
|
||||
let m = ir::MarkedBlocks {
|
||||
begin,
|
||||
len: end - begin,
|
||||
};
|
||||
out.writeset_blocks(&m)?;
|
||||
}
|
||||
begin = endpos;
|
||||
end = begin;
|
||||
}
|
||||
}
|
||||
|
||||
if end > begin {
|
||||
let m = ir::MarkedBlocks {
|
||||
begin,
|
||||
len: end - begin,
|
||||
};
|
||||
out.writeset_blocks(&m)?;
|
||||
}
|
||||
|
||||
out.writeset_e()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn dump_metadata(
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
out: &mut dyn MetadataVisitor,
|
||||
sb: &Superblock,
|
||||
repair: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let xml_sb = ir::Superblock {
|
||||
uuid: "".to_string(),
|
||||
block_size: sb.data_block_size,
|
||||
nr_blocks: sb.nr_blocks,
|
||||
current_era: sb.current_era,
|
||||
};
|
||||
out.superblock_b(&xml_sb)?;
|
||||
|
||||
let writesets = get_writesets_ordered(engine.clone(), sb, repair)?;
|
||||
for (era, ws) in writesets.iter() {
|
||||
dump_writeset(engine.clone(), out, *era as u32, ws, repair)?;
|
||||
}
|
||||
|
||||
out.era_b()?;
|
||||
let w = ArrayWalker::new(engine.clone(), repair);
|
||||
let mut emitter = EraEmitter::new(out);
|
||||
w.walk(&mut emitter, sb.era_array_root)?;
|
||||
out.era_e()?;
|
||||
|
||||
out.superblock_e()?;
|
||||
out.eof()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
fn get_writesets_ordered(
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
sb: &Superblock,
|
||||
repair: bool,
|
||||
) -> Result<Vec<(u32, Writeset)>> {
|
||||
let mut path = vec![0];
|
||||
let mut writesets =
|
||||
btree_to_map::<Writeset>(&mut path, engine.clone(), repair, sb.writeset_tree_root)?;
|
||||
|
||||
if sb.current_writeset.root != 0 {
|
||||
if writesets.contains_key(&(sb.current_era as u64)) {
|
||||
return Err(anyhow!(
|
||||
"Duplicated era found in current_writeset and the writeset tree"
|
||||
));
|
||||
}
|
||||
writesets.insert(sb.current_era as u64, sb.current_writeset);
|
||||
}
|
||||
|
||||
if writesets.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let mut v = Vec::<(u32, Writeset)>::new();
|
||||
let era_begin = sb.current_era.wrapping_sub((writesets.len() - 1) as u32);
|
||||
for era in era_begin..=sb.current_era {
|
||||
if let Some(ws) = writesets.get(&(era as u64)) {
|
||||
v.push((era, *ws));
|
||||
} else {
|
||||
return Err(anyhow!("Writeset of era {} is not present", era));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
fn collate_writeset(index: u32, bitset: &FixedBitSet, archive: &mut dyn Archive) -> Result<()> {
|
||||
let era_delta = index + 1;
|
||||
|
||||
for (i, entry) in bitset.as_slice().iter().enumerate() {
|
||||
let mut bi = (i << 5) as u32;
|
||||
let mut n = *entry;
|
||||
while n > 0 {
|
||||
if n & 0x1 > 0 {
|
||||
archive.set(bi, era_delta)?;
|
||||
}
|
||||
n >>= 1;
|
||||
bi += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn collate_writesets(
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
sb: &Superblock,
|
||||
repair: bool,
|
||||
) -> Result<Box<dyn Archive>> {
|
||||
let writesets = get_writesets_ordered(engine.clone(), sb, repair)?;
|
||||
|
||||
let archived_begin = writesets.get(0).map_or(0u32, |(era, _ws)| *era);
|
||||
let mut archive = new_era_archive(sb.nr_blocks, archived_begin, writesets.len() as u32);
|
||||
|
||||
for (index, (_era, ws)) in writesets.iter().enumerate() {
|
||||
let bitset = read_bitset_no_err(engine.clone(), ws.root, ws.nr_bits as usize, repair)?;
|
||||
collate_writeset(index as u32, &bitset, archive.as_mut())?;
|
||||
}
|
||||
|
||||
Ok(archive)
|
||||
}
|
||||
|
||||
pub fn dump_metadata_logical(
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
out: &mut dyn MetadataVisitor,
|
||||
sb: &Superblock,
|
||||
repair: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let era_archive = collate_writesets(engine.clone(), sb, repair)?;
|
||||
|
||||
let xml_sb = ir::Superblock {
|
||||
uuid: "".to_string(),
|
||||
block_size: sb.data_block_size,
|
||||
nr_blocks: sb.nr_blocks,
|
||||
current_era: sb.current_era,
|
||||
};
|
||||
out.superblock_b(&xml_sb)?;
|
||||
|
||||
out.era_b()?;
|
||||
let w = ArrayWalker::new(engine, repair);
|
||||
let mut emitter = LogicalEraEmitter::new(out, era_archive.deref());
|
||||
w.walk(&mut emitter, sb.era_array_root)?;
|
||||
out.era_e()?;
|
||||
|
||||
out.superblock_e()?;
|
||||
out.eof()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
pub fn dump(opts: EraDumpOptions) -> anyhow::Result<()> {
|
||||
let ctx = mk_context(&opts)?;
|
||||
let sb = read_superblock(ctx.engine.as_ref(), SUPERBLOCK_LOCATION)?;
|
||||
|
||||
let writer: Box<dyn Write>;
|
||||
if opts.output.is_some() {
|
||||
writer = Box::new(BufWriter::new(File::create(opts.output.unwrap())?));
|
||||
} else {
|
||||
writer = Box::new(BufWriter::new(std::io::stdout()));
|
||||
}
|
||||
let mut out = xml::XmlWriter::new(writer, false);
|
||||
|
||||
let writesets = get_writesets_ordered(ctx.engine.clone(), &sb, opts.repair)?;
|
||||
if opts.logical && !writesets.is_empty() {
|
||||
dump_metadata_logical(ctx.engine, &mut out, &sb, opts.repair)
|
||||
} else {
|
||||
dump_metadata(ctx.engine, &mut out, &sb, opts.repair)
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,285 +0,0 @@
|
||||
use anyhow::Result;
|
||||
use quick_xml::events::{BytesEnd, BytesStart, Event};
|
||||
use quick_xml::Writer;
|
||||
use std::fs::File;
|
||||
use std::io::{BufWriter, Write};
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::era::superblock::*;
|
||||
use crate::era::writeset::*;
|
||||
use crate::io_engine::{AsyncIoEngine, IoEngine, SyncIoEngine};
|
||||
use crate::math::div_up;
|
||||
use crate::pdata::array::{self, value_err, ArrayBlock};
|
||||
use crate::pdata::array_walker::*;
|
||||
use crate::pdata::btree_walker::*;
|
||||
use crate::xml::mk_attr;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
const MAX_CONCURRENT_IO: u32 = 1024;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
struct BitsetCollator<'a> {
|
||||
composed_bits: Box<Mutex<&'a mut [u64]>>,
|
||||
}
|
||||
|
||||
impl<'a> BitsetCollator<'a> {
|
||||
fn new(bitset: &mut [u64]) -> BitsetCollator {
|
||||
BitsetCollator {
|
||||
composed_bits: Box::new(Mutex::new(bitset)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArrayVisitor<u64> for BitsetCollator<'a> {
|
||||
fn visit(&self, index: u64, b: ArrayBlock<u64>) -> array::Result<()> {
|
||||
let mut bitset = self.composed_bits.lock().unwrap();
|
||||
let idx = index as usize * b.header.max_entries as usize; // index of u64 in bitset array
|
||||
for (entry, dest) in b.values.iter().zip(bitset.iter_mut().skip(idx)) {
|
||||
*dest |= entry;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
struct EraArrayCollator<'a> {
|
||||
composed_bits: Box<Mutex<&'a mut [u64]>>,
|
||||
threshold: u32,
|
||||
}
|
||||
|
||||
impl<'a> EraArrayCollator<'a> {
|
||||
fn new(bitset: &mut [u64], threshold: u32) -> EraArrayCollator {
|
||||
EraArrayCollator {
|
||||
composed_bits: Box::new(Mutex::new(bitset)),
|
||||
threshold,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ArrayVisitor<u32> for EraArrayCollator<'a> {
|
||||
fn visit(&self, index: u64, b: ArrayBlock<u32>) -> array::Result<()> {
|
||||
let blk_begin = index as usize * b.header.max_entries as usize; // range of data blocks
|
||||
let blk_end = blk_begin + b.header.max_entries as usize;
|
||||
|
||||
let mut bitset = self.composed_bits.lock().unwrap();
|
||||
let mut bitset_iter = bitset.iter_mut();
|
||||
let mut idx = blk_begin >> 6; // index of u64 in bitset array
|
||||
let mut dest = bitset_iter
|
||||
.nth(idx)
|
||||
.ok_or_else(|| value_err("array index out of bounds".to_string()))?;
|
||||
let mut buf = *dest;
|
||||
for (era, blk) in b.values.iter().zip(blk_begin..blk_end) {
|
||||
if *era < self.threshold {
|
||||
continue;
|
||||
}
|
||||
let steps = (blk >> 6) - idx;
|
||||
if steps > 0 {
|
||||
*dest = buf;
|
||||
idx += steps;
|
||||
dest = bitset_iter
|
||||
.nth(steps - 1)
|
||||
.ok_or_else(|| value_err("array index out of bounds".to_string()))?;
|
||||
buf = *dest;
|
||||
}
|
||||
buf |= 1 << (blk & 0x3F);
|
||||
}
|
||||
*dest = buf;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
fn collate_writeset(
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
writeset_root: u64,
|
||||
marked_bits: &mut [u64],
|
||||
) -> Result<()> {
|
||||
let w = ArrayWalker::new(engine, false);
|
||||
let mut c = BitsetCollator::new(marked_bits);
|
||||
w.walk(&mut c, writeset_root)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn collate_era_array(
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
era_array_root: u64,
|
||||
marked_bits: &mut [u64],
|
||||
threshold: u32,
|
||||
) -> Result<()> {
|
||||
let w = ArrayWalker::new(engine, false);
|
||||
let mut c = EraArrayCollator::new(marked_bits, threshold);
|
||||
w.walk(&mut c, era_array_root)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn mark_blocks_since(
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
sb: &Superblock,
|
||||
threshold: u32,
|
||||
) -> Result<Vec<u64>> {
|
||||
let mut marked_bits = Vec::<u64>::new();
|
||||
marked_bits.resize(div_up(sb.nr_blocks as usize, 64), 0);
|
||||
|
||||
let mut path = vec![0];
|
||||
let wsets = btree_to_map::<Writeset>(&mut path, engine.clone(), false, sb.writeset_tree_root)?;
|
||||
for (era, ws) in wsets.iter() {
|
||||
if (*era as u32) < threshold {
|
||||
continue;
|
||||
}
|
||||
collate_writeset(engine.clone(), ws.root, &mut marked_bits)?;
|
||||
}
|
||||
|
||||
if let Some(archived_begin) = wsets.keys().next() {
|
||||
if *archived_begin as u32 > threshold {
|
||||
collate_era_array(
|
||||
engine.clone(),
|
||||
sb.era_array_root,
|
||||
&mut marked_bits,
|
||||
threshold,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(marked_bits)
|
||||
}
|
||||
|
||||
fn emit_start<W: Write>(w: &mut Writer<W>) -> Result<()> {
|
||||
let elem = BytesStart::owned_name(b"blocks".to_vec());
|
||||
w.write_event(Event::Start(elem))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn emit_end<W: Write>(w: &mut Writer<W>) -> Result<()> {
|
||||
let elem = BytesEnd::borrowed(b"blocks");
|
||||
w.write_event(Event::End(elem))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn emit_range<W: Write>(w: &mut Writer<W>, begin: u32, end: u32) -> Result<()> {
|
||||
if end > begin + 1 {
|
||||
let mut elem = BytesStart::owned_name(b"range".to_vec());
|
||||
elem.push_attribute(mk_attr(b"begin", begin));
|
||||
elem.push_attribute(mk_attr(b"end", end));
|
||||
w.write_event(Event::Empty(elem))?;
|
||||
} else if end > begin {
|
||||
let mut elem = BytesStart::owned_name(b"block".to_vec());
|
||||
elem.push_attribute(mk_attr(b"block", begin));
|
||||
w.write_event(Event::Empty(elem))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn emit_blocks<W: Write>(marked_bits: &[u64], nr_blocks: u32, w: &mut Writer<W>) -> Result<()> {
|
||||
let mut begin: u32 = 0;
|
||||
let mut end: u32 = 0;
|
||||
|
||||
emit_start(w)?;
|
||||
|
||||
for (index, entry) in marked_bits.iter().enumerate() {
|
||||
let mut n = *entry;
|
||||
|
||||
if n == u64::max_value() {
|
||||
end = std::cmp::min(end + 64, nr_blocks);
|
||||
continue;
|
||||
}
|
||||
|
||||
while n > 0 {
|
||||
let zeros = n.trailing_zeros();
|
||||
if zeros > 0 {
|
||||
if end > begin {
|
||||
emit_range(w, begin, end)?;
|
||||
}
|
||||
n >>= zeros;
|
||||
end += zeros;
|
||||
begin = end;
|
||||
}
|
||||
|
||||
let ones = n.trailing_ones();
|
||||
n >>= ones;
|
||||
end = std::cmp::min(end + ones, nr_blocks);
|
||||
}
|
||||
|
||||
let endpos = (index << 6) as u32 + 64;
|
||||
if end < endpos {
|
||||
if end > begin {
|
||||
emit_range(w, begin, end)?;
|
||||
}
|
||||
begin = endpos;
|
||||
end = begin;
|
||||
}
|
||||
}
|
||||
|
||||
if end > begin {
|
||||
emit_range(w, begin, end)?;
|
||||
}
|
||||
|
||||
emit_end(w)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub struct EraInvalidateOptions<'a> {
|
||||
pub input: &'a Path,
|
||||
pub output: Option<&'a Path>,
|
||||
pub async_io: bool,
|
||||
pub threshold: u32,
|
||||
pub metadata_snap: bool,
|
||||
}
|
||||
|
||||
struct Context {
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
}
|
||||
|
||||
fn mk_context(opts: &EraInvalidateOptions) -> anyhow::Result<Context> {
|
||||
let engine: Arc<dyn IoEngine + Send + Sync>;
|
||||
|
||||
if opts.async_io {
|
||||
engine = Arc::new(AsyncIoEngine::new_with(
|
||||
opts.input,
|
||||
MAX_CONCURRENT_IO,
|
||||
false,
|
||||
!opts.metadata_snap,
|
||||
)?);
|
||||
} else {
|
||||
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
||||
engine = Arc::new(SyncIoEngine::new_with(
|
||||
opts.input,
|
||||
nr_threads,
|
||||
false,
|
||||
!opts.metadata_snap,
|
||||
)?);
|
||||
}
|
||||
|
||||
Ok(Context { engine })
|
||||
}
|
||||
|
||||
pub fn invalidate(opts: &EraInvalidateOptions) -> Result<()> {
|
||||
let ctx = mk_context(opts)?;
|
||||
|
||||
let mut sb = read_superblock(ctx.engine.as_ref(), SUPERBLOCK_LOCATION)?;
|
||||
if opts.metadata_snap {
|
||||
sb = read_superblock(ctx.engine.as_ref(), sb.metadata_snap)?;
|
||||
}
|
||||
|
||||
let w: Box<dyn Write>;
|
||||
if opts.output.is_some() {
|
||||
w = Box::new(BufWriter::new(File::create(opts.output.unwrap())?));
|
||||
} else {
|
||||
w = Box::new(BufWriter::new(std::io::stdout()));
|
||||
}
|
||||
let mut writer = Writer::new_with_indent(w, 0x20, 2);
|
||||
|
||||
let marked_bits = mark_blocks_since(ctx.engine, &sb, opts.threshold)?;
|
||||
emit_blocks(&marked_bits, sb.nr_blocks, &mut writer)
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,54 +0,0 @@
|
||||
use anyhow::Result;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Superblock {
|
||||
pub uuid: String,
|
||||
pub block_size: u32,
|
||||
pub nr_blocks: u32,
|
||||
pub current_era: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Writeset {
|
||||
pub era: u32,
|
||||
pub nr_bits: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MarkedBlocks {
|
||||
pub begin: u32,
|
||||
pub len: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Era {
|
||||
pub block: u32,
|
||||
pub era: u32,
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Visit {
|
||||
Continue,
|
||||
Stop,
|
||||
}
|
||||
|
||||
pub trait MetadataVisitor {
|
||||
fn superblock_b(&mut self, sb: &Superblock) -> Result<Visit>;
|
||||
fn superblock_e(&mut self) -> Result<Visit>;
|
||||
|
||||
fn writeset_b(&mut self, ws: &Writeset) -> Result<Visit>;
|
||||
fn writeset_e(&mut self) -> Result<Visit>;
|
||||
fn writeset_blocks(&mut self, blocks: &MarkedBlocks) -> Result<Visit>;
|
||||
|
||||
fn era_b(&mut self) -> Result<Visit>;
|
||||
fn era_e(&mut self) -> Result<Visit>;
|
||||
fn era(&mut self, era: &Era) -> Result<Visit>;
|
||||
|
||||
fn eof(&mut self) -> Result<Visit>;
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,9 +0,0 @@
|
||||
pub mod check;
|
||||
pub mod dump;
|
||||
pub mod invalidate;
|
||||
pub mod ir;
|
||||
pub mod repair;
|
||||
pub mod restore;
|
||||
pub mod superblock;
|
||||
pub mod writeset;
|
||||
pub mod xml;
|
||||
@@ -1,68 +0,0 @@
|
||||
use anyhow::Result;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::era::dump::*;
|
||||
use crate::era::restore::*;
|
||||
use crate::era::superblock::*;
|
||||
use crate::io_engine::*;
|
||||
use crate::pdata::space_map_metadata::*;
|
||||
use crate::report::*;
|
||||
use crate::write_batcher::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub struct EraRepairOptions<'a> {
|
||||
pub input: &'a Path,
|
||||
pub output: &'a Path,
|
||||
pub async_io: bool,
|
||||
pub report: Arc<Report>,
|
||||
}
|
||||
|
||||
struct Context {
|
||||
_report: Arc<Report>,
|
||||
engine_in: Arc<dyn IoEngine + Send + Sync>,
|
||||
engine_out: Arc<dyn IoEngine + Send + Sync>,
|
||||
}
|
||||
|
||||
const MAX_CONCURRENT_IO: u32 = 1024;
|
||||
|
||||
fn new_context(opts: &EraRepairOptions) -> Result<Context> {
|
||||
let engine_in: Arc<dyn IoEngine + Send + Sync>;
|
||||
let engine_out: Arc<dyn IoEngine + Send + Sync>;
|
||||
|
||||
if opts.async_io {
|
||||
engine_in = Arc::new(AsyncIoEngine::new(opts.input, MAX_CONCURRENT_IO, false)?);
|
||||
engine_out = Arc::new(AsyncIoEngine::new(opts.output, MAX_CONCURRENT_IO, true)?);
|
||||
} else {
|
||||
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
||||
engine_in = Arc::new(SyncIoEngine::new(opts.input, nr_threads, false)?);
|
||||
engine_out = Arc::new(SyncIoEngine::new(opts.output, nr_threads, true)?);
|
||||
}
|
||||
|
||||
Ok(Context {
|
||||
_report: opts.report.clone(),
|
||||
engine_in,
|
||||
engine_out,
|
||||
})
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub fn repair(opts: EraRepairOptions) -> Result<()> {
|
||||
let ctx = new_context(&opts)?;
|
||||
|
||||
let sb = read_superblock(ctx.engine_in.as_ref(), SUPERBLOCK_LOCATION)?;
|
||||
|
||||
let sm = core_metadata_sm(ctx.engine_out.get_nr_blocks(), u32::MAX);
|
||||
let mut w = WriteBatcher::new(
|
||||
ctx.engine_out.clone(),
|
||||
sm.clone(),
|
||||
ctx.engine_out.get_batch_size(),
|
||||
);
|
||||
let mut restorer = Restorer::new(&mut w);
|
||||
|
||||
dump_metadata(ctx.engine_in, &mut restorer, &sb, true)
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,313 +0,0 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs::OpenOptions;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::era::ir::{self, MetadataVisitor, Visit};
|
||||
use crate::era::superblock::*;
|
||||
use crate::era::writeset::Writeset;
|
||||
use crate::era::xml;
|
||||
use crate::io_engine::*;
|
||||
use crate::math::*;
|
||||
use crate::pdata::array_builder::*;
|
||||
use crate::pdata::btree_builder::*;
|
||||
use crate::pdata::space_map_common::pack_root;
|
||||
use crate::pdata::space_map_metadata::*;
|
||||
use crate::report::*;
|
||||
use crate::write_batcher::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
const MAX_CONCURRENT_IO: u32 = 1024;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub struct EraRestoreOptions<'a> {
|
||||
pub input: &'a Path,
|
||||
pub output: &'a Path,
|
||||
pub async_io: bool,
|
||||
pub report: Arc<Report>,
|
||||
}
|
||||
|
||||
struct Context {
|
||||
_report: Arc<Report>,
|
||||
engine: Arc<dyn IoEngine + Send + Sync>,
|
||||
}
|
||||
|
||||
fn mk_context(opts: &EraRestoreOptions) -> anyhow::Result<Context> {
|
||||
let engine: Arc<dyn IoEngine + Send + Sync>;
|
||||
|
||||
if opts.async_io {
|
||||
engine = Arc::new(AsyncIoEngine::new(opts.output, MAX_CONCURRENT_IO, true)?);
|
||||
} else {
|
||||
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
||||
engine = Arc::new(SyncIoEngine::new(opts.output, nr_threads, true)?);
|
||||
}
|
||||
|
||||
Ok(Context {
|
||||
_report: opts.report.clone(),
|
||||
engine,
|
||||
})
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum Section {
|
||||
None,
|
||||
Superblock,
|
||||
Writeset,
|
||||
EraArray,
|
||||
Finalized,
|
||||
}
|
||||
|
||||
pub struct Restorer<'a> {
|
||||
w: &'a mut WriteBatcher,
|
||||
sb: Option<ir::Superblock>,
|
||||
writesets: BTreeMap<u32, Writeset>,
|
||||
writeset_builder: Option<ArrayBuilder<u64>>, // bitset
|
||||
current_writeset: Option<ir::Writeset>,
|
||||
era_array_builder: Option<ArrayBuilder<u32>>,
|
||||
writeset_entry: u64,
|
||||
entry_index: u32,
|
||||
in_section: Section,
|
||||
}
|
||||
|
||||
impl<'a> Restorer<'a> {
|
||||
pub fn new(w: &'a mut WriteBatcher) -> Restorer<'a> {
|
||||
Restorer {
|
||||
w,
|
||||
sb: None,
|
||||
writesets: BTreeMap::new(),
|
||||
writeset_builder: None,
|
||||
current_writeset: None,
|
||||
era_array_builder: None,
|
||||
writeset_entry: 0,
|
||||
entry_index: 0,
|
||||
in_section: Section::None,
|
||||
}
|
||||
}
|
||||
|
||||
fn finalize(&mut self) -> Result<()> {
|
||||
let src_sb;
|
||||
if let Some(sb) = self.sb.take() {
|
||||
src_sb = sb;
|
||||
} else {
|
||||
return Err(anyhow!("not in superblock"));
|
||||
}
|
||||
|
||||
// build the writeset tree
|
||||
let mut tree_builder = BTreeBuilder::<Writeset>::new(Box::new(NoopRC {}));
|
||||
let mut writesets = BTreeMap::<u32, Writeset>::new();
|
||||
std::mem::swap(&mut self.writesets, &mut writesets);
|
||||
for (era, ws) in writesets {
|
||||
tree_builder.push_value(self.w, era as u64, ws)?;
|
||||
}
|
||||
let writeset_tree_root = tree_builder.complete(self.w)?;
|
||||
|
||||
// complete the era array
|
||||
let era_array_root;
|
||||
if let Some(builder) = self.era_array_builder.take() {
|
||||
era_array_root = builder.complete(self.w)?;
|
||||
} else {
|
||||
return Err(anyhow!("internal error. couldn't find era array"));
|
||||
}
|
||||
|
||||
// build metadata space map
|
||||
let metadata_sm_root = build_metadata_sm(self.w)?;
|
||||
|
||||
let sb = Superblock {
|
||||
flags: SuperblockFlags {
|
||||
clean_shutdown: true,
|
||||
},
|
||||
block: SUPERBLOCK_LOCATION,
|
||||
version: 1,
|
||||
metadata_sm_root,
|
||||
data_block_size: src_sb.block_size,
|
||||
nr_blocks: src_sb.nr_blocks,
|
||||
current_era: src_sb.current_era,
|
||||
current_writeset: Writeset {
|
||||
nr_bits: src_sb.nr_blocks,
|
||||
root: 0,
|
||||
},
|
||||
writeset_tree_root,
|
||||
era_array_root,
|
||||
metadata_snap: 0,
|
||||
};
|
||||
write_superblock(self.w.engine.as_ref(), SUPERBLOCK_LOCATION, &sb)?;
|
||||
|
||||
self.in_section = Section::Finalized;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> MetadataVisitor for Restorer<'a> {
|
||||
fn superblock_b(&mut self, sb: &ir::Superblock) -> Result<Visit> {
|
||||
if self.in_section != Section::None {
|
||||
return Err(anyhow!("duplicated superblock"));
|
||||
}
|
||||
|
||||
self.sb = Some(sb.clone());
|
||||
let b = self.w.alloc()?;
|
||||
if b.loc != SUPERBLOCK_LOCATION {
|
||||
return Err(anyhow!("superblock was occupied"));
|
||||
}
|
||||
|
||||
self.writeset_builder = None;
|
||||
self.era_array_builder = Some(ArrayBuilder::new(sb.nr_blocks as u64));
|
||||
self.in_section = Section::Superblock;
|
||||
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn superblock_e(&mut self) -> Result<Visit> {
|
||||
self.finalize()?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn writeset_b(&mut self, ws: &ir::Writeset) -> Result<Visit> {
|
||||
if self.in_section != Section::Superblock {
|
||||
return Err(anyhow!("not in superblock"));
|
||||
}
|
||||
self.writeset_builder = Some(ArrayBuilder::new(div_up(ws.nr_bits as u64, 64)));
|
||||
self.entry_index = 0;
|
||||
self.writeset_entry = 0;
|
||||
self.current_writeset = Some(ws.clone());
|
||||
self.in_section = Section::Writeset;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn writeset_e(&mut self) -> Result<Visit> {
|
||||
if self.in_section != Section::Writeset {
|
||||
return Err(anyhow!("not in writeset"));
|
||||
}
|
||||
|
||||
if let Some(mut builder) = self.writeset_builder.take() {
|
||||
if let Some(ws) = self.current_writeset.take() {
|
||||
// push the trailing bits
|
||||
builder.push_value(self.w, self.entry_index as u64, self.writeset_entry)?;
|
||||
|
||||
let root = builder.complete(self.w)?;
|
||||
self.writesets.insert(
|
||||
ws.era,
|
||||
Writeset {
|
||||
root,
|
||||
nr_bits: ws.nr_bits,
|
||||
},
|
||||
);
|
||||
self.in_section = Section::Superblock;
|
||||
} else {
|
||||
return Err(anyhow!("internal error. couldn't find writeset"));
|
||||
}
|
||||
} else {
|
||||
return Err(anyhow!("internal error. couldn't find writeset"));
|
||||
}
|
||||
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn writeset_blocks(&mut self, blocks: &ir::MarkedBlocks) -> Result<Visit> {
|
||||
let first = blocks.begin;
|
||||
let last = first + blocks.len - 1; // inclusive
|
||||
let mut idx = first >> 6;
|
||||
let last_idx = last >> 6; // inclusive
|
||||
let builder = self.writeset_builder.as_mut().unwrap();
|
||||
|
||||
// emit the bufferred bits
|
||||
if idx > self.entry_index {
|
||||
builder.push_value(self.w, self.entry_index as u64, self.writeset_entry)?;
|
||||
self.entry_index = idx;
|
||||
self.writeset_entry = 0;
|
||||
}
|
||||
|
||||
// buffer the bits of the first entry
|
||||
let bi_first = first & 63;
|
||||
if idx == last_idx {
|
||||
let bi_last = last & 63;
|
||||
let mask = 1u64 << bi_last;
|
||||
self.writeset_entry |= (mask ^ mask.wrapping_sub(1)) & (u64::MAX << bi_first);
|
||||
|
||||
return Ok(Visit::Continue);
|
||||
}
|
||||
|
||||
self.writeset_entry |= u64::MAX << bi_first;
|
||||
|
||||
// emit the all-1 entries if necessary
|
||||
while idx < last_idx {
|
||||
builder.push_value(self.w, self.entry_index as u64, self.writeset_entry)?;
|
||||
self.entry_index += 1;
|
||||
self.writeset_entry = u64::MAX;
|
||||
idx += 1;
|
||||
}
|
||||
|
||||
// buffer the bits of the last entry
|
||||
builder.push_value(self.w, self.entry_index as u64, self.writeset_entry)?;
|
||||
let bi_last = last & 63;
|
||||
let mask = 1u64 << bi_last;
|
||||
self.entry_index += 1;
|
||||
self.writeset_entry |= mask ^ mask.wrapping_sub(1);
|
||||
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn era_b(&mut self) -> Result<Visit> {
|
||||
if self.in_section != Section::Superblock {
|
||||
return Err(anyhow!("not in superblock"));
|
||||
}
|
||||
self.in_section = Section::EraArray;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn era_e(&mut self) -> Result<Visit> {
|
||||
if self.in_section != Section::EraArray {
|
||||
return Err(anyhow!("not in era array"));
|
||||
}
|
||||
self.in_section = Section::Superblock;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn era(&mut self, era: &ir::Era) -> Result<Visit> {
|
||||
let builder = self.era_array_builder.as_mut().unwrap();
|
||||
builder.push_value(self.w, era.block as u64, era.era)?;
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
|
||||
fn eof(&mut self) -> Result<Visit> {
|
||||
if self.in_section != Section::Finalized {
|
||||
return Err(anyhow!("incompleted source metadata"));
|
||||
}
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
fn build_metadata_sm(w: &mut WriteBatcher) -> Result<Vec<u8>> {
|
||||
let r = write_metadata_sm(w)?;
|
||||
let sm_root = pack_root(&r, SPACE_MAP_ROOT_SIZE)?;
|
||||
|
||||
Ok(sm_root)
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub fn restore(opts: EraRestoreOptions) -> Result<()> {
|
||||
let input = OpenOptions::new()
|
||||
.read(true)
|
||||
.write(false)
|
||||
.open(opts.input)?;
|
||||
|
||||
let ctx = mk_context(&opts)?;
|
||||
|
||||
let sm = core_metadata_sm(ctx.engine.get_nr_blocks(), u32::MAX);
|
||||
let mut w = WriteBatcher::new(ctx.engine.clone(), sm.clone(), ctx.engine.get_batch_size());
|
||||
|
||||
let mut restorer = Restorer::new(&mut w);
|
||||
xml::read(input, &mut restorer)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -1,153 +0,0 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use byteorder::{LittleEndian, WriteBytesExt};
|
||||
use nom::{bytes::complete::*, number::complete::*, IResult};
|
||||
use std::io::Cursor;
|
||||
|
||||
use crate::checksum::*;
|
||||
use crate::era::writeset::Writeset;
|
||||
use crate::io_engine::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub const SPACE_MAP_ROOT_SIZE: usize = 128;
|
||||
pub const SUPERBLOCK_LOCATION: u64 = 0;
|
||||
|
||||
const MAGIC: u64 = 0o17660203573; // 0x7EC1077B in hex
|
||||
const UUID_SIZE: usize = 16;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SuperblockFlags {
|
||||
pub clean_shutdown: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Superblock {
|
||||
pub flags: SuperblockFlags,
|
||||
pub block: u64,
|
||||
pub version: u32,
|
||||
|
||||
pub metadata_sm_root: Vec<u8>,
|
||||
|
||||
pub data_block_size: u32,
|
||||
pub nr_blocks: u32,
|
||||
|
||||
pub current_era: u32,
|
||||
pub current_writeset: Writeset,
|
||||
|
||||
pub writeset_tree_root: u64,
|
||||
pub era_array_root: u64,
|
||||
|
||||
pub metadata_snap: u64,
|
||||
}
|
||||
|
||||
fn unpack(data: &[u8]) -> IResult<&[u8], Superblock> {
|
||||
let (i, _csum) = le_u32(data)?;
|
||||
let (i, flags) = le_u32(i)?;
|
||||
let (i, block) = le_u64(i)?;
|
||||
let (i, _uuid) = take(16usize)(i)?;
|
||||
let (i, _magic) = le_u64(i)?;
|
||||
let (i, version) = le_u32(i)?;
|
||||
|
||||
let (i, metadata_sm_root) = take(SPACE_MAP_ROOT_SIZE)(i)?;
|
||||
let (i, data_block_size) = le_u32(i)?;
|
||||
let (i, _metadata_block_size) = le_u32(i)?;
|
||||
let (i, nr_blocks) = le_u32(i)?;
|
||||
|
||||
let (i, current_era) = le_u32(i)?;
|
||||
let (i, nr_bits) = le_u32(i)?;
|
||||
let (i, root) = le_u64(i)?;
|
||||
|
||||
let (i, writeset_tree_root) = le_u64(i)?;
|
||||
let (i, era_array_root) = le_u64(i)?;
|
||||
let (i, metadata_snap) = le_u64(i)?;
|
||||
|
||||
Ok((
|
||||
i,
|
||||
Superblock {
|
||||
flags: SuperblockFlags {
|
||||
clean_shutdown: (flags & 0x1) != 0,
|
||||
},
|
||||
block,
|
||||
version,
|
||||
metadata_sm_root: metadata_sm_root.to_vec(),
|
||||
data_block_size,
|
||||
nr_blocks,
|
||||
current_era,
|
||||
current_writeset: Writeset { nr_bits, root },
|
||||
writeset_tree_root,
|
||||
era_array_root,
|
||||
metadata_snap,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn read_superblock(engine: &dyn IoEngine, loc: u64) -> Result<Superblock> {
|
||||
let b = engine.read(loc)?;
|
||||
|
||||
if metadata_block_type(b.get_data()) != BT::ERA_SUPERBLOCK {
|
||||
return Err(anyhow!("bad checksum in superblock"));
|
||||