Skip to content

Commit

Permalink
concierge: Support passing multiple fds to StartVm
Browse files Browse the repository at this point in the history
Concierge can accept arbitrarily many fds for the kernel, initramfs,
firmware etc, but the chrome client code currently only supports
passing a single fd. Installing bruschetta requires (at least for the
time being) passing in two fds, so expand the client code accordingly.

Bug: b:233289313
Change-Id: I43f582632de038e88917cfed6ae7af4ad3d20ed3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3831616
Reviewed-by: David Munro <davidmunro@google.com>
Commit-Queue: Fergus Dall <sidereal@google.com>
Cr-Commit-Position: refs/heads/main@{#1034989}
  • Loading branch information
fergus-dall authored and Chromium LUCI CQ committed Aug 15, 2022
1 parent 843efff commit 49644bb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
33 changes: 27 additions & 6 deletions chromeos/ash/components/dbus/concierge/concierge_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ class ConciergeClientImpl : public ConciergeClient {
std::move(callback));
}

void StartVmWithFds(std::vector<base::ScopedFD> fds,
const vm_tools::concierge::StartVmRequest& request,
DBusMethodCallback<vm_tools::concierge::StartVmResponse>
callback) override {
CallMethodWithFds(concierge::kStartVmMethod, request, std::move(fds),
std::move(callback));
}

void StopVm(const concierge::StopVmRequest& request,
DBusMethodCallback<concierge::StopVmResponse> callback) override {
CallMethod(concierge::kStopVmMethod, request, std::move(callback));
Expand Down Expand Up @@ -290,10 +298,10 @@ class ConciergeClientImpl : public ConciergeClient {

private:
template <typename RequestProto, typename ResponseProto>
void CallMethodWithFd(const std::string& method_name,
const RequestProto& request,
base::ScopedFD fd,
DBusMethodCallback<ResponseProto> callback) {
void CallMethodWithFds(const std::string& method_name,
const RequestProto& request,
std::vector<base::ScopedFD> fds,
DBusMethodCallback<ResponseProto> callback) {
dbus::MethodCall method_call(concierge::kVmConciergeInterface, method_name);
dbus::MessageWriter writer(&method_call);

Expand All @@ -304,15 +312,28 @@ class ConciergeClientImpl : public ConciergeClient {
return;
}

if (fd.is_valid())
writer.AppendFileDescriptor(fd.get());
for (auto& fd : fds) {
if (fd.is_valid())
writer.AppendFileDescriptor(fd.get());
}

concierge_proxy_->CallMethod(
&method_call, kConciergeDBusTimeoutMs,
base::BindOnce(&ConciergeClientImpl::OnDBusProtoResponse<ResponseProto>,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}

template <typename RequestProto, typename ResponseProto>
void CallMethodWithFd(const std::string& method_name,
const RequestProto& request,
base::ScopedFD fd,
DBusMethodCallback<ResponseProto> callback) {
std::vector<base::ScopedFD> fds;
fds.push_back(std::move(fd));
CallMethodWithFds(method_name, request, std::move(fds),
std::move(callback));
}

template <typename RequestProto, typename ResponseProto>
void CallMethod(const std::string& method_name,
const RequestProto& request,
Expand Down
11 changes: 10 additions & 1 deletion chromeos/ash/components/dbus/concierge/concierge_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,22 @@ class COMPONENT_EXPORT(CONCIERGE) ConciergeClient : public DBusClient {
DBusMethodCallback<vm_tools::concierge::StartVmResponse> callback) = 0;

// Starts a Termina VM if there is not already one running.
// |fd| references an extra image for concierge to use.
// |fds| references an extra image for concierge to use.
// |callback| is called after the method call finishes.
virtual void StartVmWithFd(
base::ScopedFD fd,
const vm_tools::concierge::StartVmRequest& request,
DBusMethodCallback<vm_tools::concierge::StartVmResponse> callback) = 0;

// Starts a Termina VM if there is not already one running.
// |fds| contains any number of file descriptors to be passed to concierge in
// |the order they appear in the vector.
// |callback| is called after the method call finishes.
virtual void StartVmWithFds(
std::vector<base::ScopedFD> fds,
const vm_tools::concierge::StartVmRequest& request,
DBusMethodCallback<vm_tools::concierge::StartVmResponse> callback) = 0;

// Stops the named Termina VM if it is running.
// |callback| is called after the method call finishes.
virtual void StopVm(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ void FakeConciergeClient::StartVmWithFd(
StartVm(std::move(request), std::move(callback));
}

void FakeConciergeClient::StartVmWithFds(
std::vector<base::ScopedFD> fds,
const vm_tools::concierge::StartVmRequest& request,
DBusMethodCallback<vm_tools::concierge::StartVmResponse> callback) {
StartVm(std::move(request), std::move(callback));
}

void FakeConciergeClient::NotifyTremplinStarted(
const vm_tools::cicerone::TremplinStartedSignal& signal) {
DCHECK(fake_cicerone_client_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class COMPONENT_EXPORT(CONCIERGE) FakeConciergeClient : public ConciergeClient {
const vm_tools::concierge::StartVmRequest& request,
DBusMethodCallback<vm_tools::concierge::StartVmResponse>
callback) override;
void StartVmWithFds(std::vector<base::ScopedFD> fd,
const vm_tools::concierge::StartVmRequest& request,
DBusMethodCallback<vm_tools::concierge::StartVmResponse>
callback) override;
void StopVm(const vm_tools::concierge::StopVmRequest& request,
DBusMethodCallback<vm_tools::concierge::StopVmResponse> callback)
override;
Expand Down

0 comments on commit 49644bb

Please sign in to comment.