Support for striped in libdm

Add dm stripe in dmctl framework to support stripe on two block devices.

Bug: 321628121
Change-Id: I2f326f19f7ccff1ee03598743022fb702b3e8d6a
Signed-off-by: Ed Tsai <ed.tsai@mediatek.com>
This commit is contained in:
Ed Tsai 2024-01-19 08:13:12 +08:00
parent 80b2bf16c9
commit 43de4ef22d
4 changed files with 44 additions and 0 deletions

View file

@ -61,6 +61,10 @@ std::string DmTargetLinear::GetParameterString() const {
return block_device_ + " " + std::to_string(physical_sector_);
}
std::string DmTargetStripe::GetParameterString() const {
return "2 " + std::to_string(chunksize) + " " + block_device0_ + " 0 " + block_device1_ + " 0";
}
DmTargetVerity::DmTargetVerity(uint64_t start, uint64_t length, uint32_t version,
const std::string& block_device, const std::string& hash_device,
uint32_t data_block_size, uint32_t hash_block_size,

View file

@ -181,6 +181,13 @@ TEST_F(DmTest, DmSuspendResume) {
ASSERT_EQ(dm.GetState(dev.name()), DmDeviceState::ACTIVE);
}
TEST_F(DmTest, StripeArgs) {
DmTargetStripe target(0, 4096, 1024, "/dev/loop0", "/dev/loop1");
ASSERT_EQ(target.name(), "striped");
ASSERT_TRUE(target.Valid());
ASSERT_EQ(target.GetParameterString(), "2 1024 /dev/loop0 0 /dev/loop1 0");
}
TEST_F(DmTest, DmVerityArgsAvb2) {
std::string device = "/dev/block/platform/soc/1da4000.ufshc/by-name/vendor_a";
std::string algorithm = "sha1";

View file

@ -116,6 +116,24 @@ class DmTargetLinear final : public DmTarget {
uint64_t physical_sector_;
};
class DmTargetStripe final : public DmTarget {
public:
DmTargetStripe(uint64_t start, uint64_t length, uint64_t chunksize,
const std::string& block_device0, const std::string& block_device1)
: DmTarget(start, length),
chunksize(chunksize),
block_device0_(block_device0),
block_device1_(block_device1) {}
std::string name() const override { return "striped"; }
std::string GetParameterString() const override;
private:
uint64_t chunksize;
std::string block_device0_;
std::string block_device1_;
};
class DmTargetVerity final : public DmTarget {
public:
DmTargetVerity(uint64_t start, uint64_t length, uint32_t version,

View file

@ -115,6 +115,21 @@ class TargetParser final {
std::string block_device = NextArg();
return std::make_unique<DmTargetAndroidVerity>(start_sector, num_sectors, keyid,
block_device);
} else if (target_type == "striped") {
if (!HasArgs(3)) {
std::cerr << "Expected \"striped\" <block_device0> <block_device1> <chunksize>"
<< std::endl;
return nullptr;
}
std::string block_device0 = NextArg();
std::string block_device1 = NextArg();
uint64_t chunk_size;
if (!android::base::ParseUint(NextArg(), &chunk_size)) {
std::cerr << "Expected start sector, got: " << PreviousArg() << std::endl;
return nullptr;
}
return std::make_unique<DmTargetStripe>(start_sector, num_sectors, chunk_size,
block_device0, block_device1);
} else if (target_type == "bow") {
if (!HasArgs(1)) {
std::cerr << "Expected \"bow\" <block_device>" << std::endl;