Skip to content

Commit f43b9f9

Browse files
James SullivanRebase bot
authored andcommitted
[gpt] Provide hardware.block.volume.VolumeManager
Implements a subset of the VolumeManager interface for the GPT driver, allowing runtime allocation of GPT partitions. The GPT device tree now contains a `gpt` node which offers the VolumeManager protocol. Note that partitions are *not* moved to children beneath the `gpt` node, since doing so would require extensive refactoring of the system (i.e. removing hard-coded GPT paths). The `gpt` device is a peer of the partition devices. Newly allocated partitions are immediately bound, and other partitions are unaffected (which is unlike the `gpt` host tool which rebinds all GPT drivers upon any header modifications). This is intended to support the storage-benchmark tests on systems which do not have an FVM. This change required refactoring the GptDevice library to receive a BlockDevice rather than a BlockProxy, since we can't create a BlockProxy for driver->driver communication. The GPT driver provides an implementation of the BlockDevice interface which directly communicates using the inter-driver Banjo block protocol. Bug: 126938 Change-Id: Ibe6717cf458dfad7fcc35f10fe8dc33adde3b103 Tested: Manually paved a NUC to ensure paving works with this change. Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/868940 Size-Review: James Sullivan <[email protected]> Reviewed-by: Chris Suter <[email protected]> Commit-Queue: James Sullivan <[email protected]> Reviewed-by: Suraj Malhotra <[email protected]>
1 parent 1f6f1cb commit f43b9f9

File tree

26 files changed

+890
-270
lines changed

26 files changed

+890
-270
lines changed

src/devices/block/bin/gpt/gpt.cc

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <gpt/gpt.h>
2323
#include <gpt/guid.h>
2424

25+
#include "src/lib/storage/block_client/cpp/remote_block_device.h"
26+
2527
using gpt::GptDevice;
2628
using gpt::GuidProperties;
2729
using gpt::KnownGuid;
@@ -114,7 +116,7 @@ char* FlagsToCString(char* dst, size_t dst_len, const uint8_t* guid, uint64_t fl
114116
}
115117

116118
std::unique_ptr<GptDevice> Init(const char* dev) {
117-
zx::result block = component::Connect<fuchsia_hardware_block::Block>(dev);
119+
zx::result block = component::Connect<fuchsia_hardware_block_volume::Volume>(dev);
118120
if (block.is_error()) {
119121
fprintf(stderr, "gpt: error opening %s: %s\n", dev, block.status_string());
120122
return nullptr;
@@ -144,9 +146,14 @@ std::unique_ptr<GptDevice> Init(const char* dev) {
144146
return nullptr;
145147
}
146148

149+
auto device = block_client::RemoteBlockDevice::Create(std::move(block.value()));
150+
if (device.is_error()) {
151+
fprintf(stderr, "Failed to create block client: %s\n", device.status_string());
152+
return nullptr;
153+
}
147154
std::unique_ptr<GptDevice> gpt;
148155
if (zx_status_t status =
149-
GptDevice::Create(std::move(block.value()), std::move(controller.value()),
156+
GptDevice::Create(std::move(device.value()), std::move(controller.value()),
150157
info.block_size, info.block_count, &gpt);
151158
status != ZX_OK) {
152159
fprintf(stderr, "gpt: error initializing GPT from %s: %s\n", dev, zx_status_get_string(status));
@@ -262,10 +269,8 @@ zx_status_t Commit(GptDevice* gpt, const char* dev) {
262269
return status;
263270
}
264271

265-
// TODO(https://fxbug.dev/112484): this relies on multiplexing.
266-
const fidl::WireResult result = fidl::WireCall(fidl::UnownedClientEnd<fuchsia_device::Controller>(
267-
gpt->device().channel().borrow()))
268-
->Rebind({});
272+
fidl::UnownedClientEnd<fuchsia_device::Controller> controller = gpt->device().Controller();
273+
const fidl::WireResult result = fidl::WireCall(controller)->Rebind({});
269274
if (!result.ok()) {
270275
fprintf(stderr, "gpt: gpt updated but device %s could not be rebound: %s. Please reboot.\n",
271276
dev, result.FormatDescription().c_str());
@@ -313,7 +318,7 @@ zx_status_t AddPartition(const char* dev, uint64_t start, uint64_t end, const ch
313318

314319
uint8_t type[GPT_GUID_LEN];
315320
memset(type, 0xff, GPT_GUID_LEN);
316-
zx_status_t rc = gpt->AddPartition(name, type, guid, start, end - start + 1, 0);
321+
zx_status_t rc = gpt->AddPartition(name, type, guid, start, end - start + 1, 0).status_value();
317322
if (rc != ZX_OK) {
318323
fprintf(stderr, "Add partition failed: %s\n", zx_status_get_string(rc));
319324
return rc;
@@ -719,7 +724,7 @@ zx_status_t Repartition(int argc, char** argv, std::optional<PartitionScheme> sc
719724

720725
printf("%s: %" PRIu64 " bytes, %" PRIu64 " blocks, %" PRIu64 "-%" PRIu64 "\n", name,
721726
byte_size, nblocks, start, end);
722-
ZX_ASSERT(gpt->AddPartition(name, type, guid, start, end - start, 0) == ZX_OK);
727+
ZX_ASSERT(gpt->AddPartition(name, type, guid, start, end - start, 0).status_value() == ZX_OK);
723728

724729
start = end + 1;
725730
}

src/devices/block/drivers/gpt/BUILD.gn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ fuchsia_driver("gpt-driver") {
3232
deps = [
3333
":gpt_bind",
3434
"//sdk/banjo/fuchsia.hardware.block.partition:fuchsia.hardware.block.partition_banjo_cpp",
35+
"//sdk/banjo/fuchsia.hardware.block.volume:fuchsia.hardware.block.volume_banjo_cpp",
3536
"//sdk/fidl/fuchsia.hardware.block.driver:fuchsia.hardware.block.driver_banjo_cpp",
37+
"//sdk/fidl/fuchsia.hardware.block.volume:fuchsia.hardware.block.volume_cpp_wire",
3638
"//sdk/fidl/fuchsia.hardware.gpt.metadata:fuchsia.hardware.gpt.metadata_cpp_wire",
3739
"//sdk/lib/fit",
3840
"//sdk/lib/syslog/cpp:backend",
@@ -41,10 +43,13 @@ fuchsia_driver("gpt-driver") {
4143
"//src/devices/block/lib/common",
4244
"//src/devices/lib/driver",
4345
"//src/lib/ddk",
46+
"//src/lib/fidl/cpp",
47+
"//src/lib/storage/block_client/cpp",
4448
"//src/storage/gpt",
4549
"//zircon/system/ulib/fbl",
4650
"//zircon/system/ulib/sync",
4751
"//zircon/third_party/ulib/cksum",
52+
"//zircon/third_party/ulib/safemath",
4853
]
4954
}
5055

@@ -74,12 +79,14 @@ test("gpt-device-test-bin") {
7479
"//src/lib/ddk",
7580
"//src/lib/ddktl",
7681
"//src/storage/gpt",
82+
"//zircon/system/ulib/async-loop:async-loop-cpp",
7783
"//zircon/system/ulib/fbl",
7884
"//zircon/system/ulib/sync",
7985
"//zircon/system/ulib/zircon-internal",
8086
"//zircon/system/ulib/zx",
8187
"//zircon/system/ulib/zxtest",
8288
"//zircon/third_party/ulib/cksum",
89+
"//zircon/third_party/ulib/safemath",
8390
]
8491
}
8592

0 commit comments

Comments
 (0)