Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ cf_cc_library(
deps = [
"//cuttlefish/common/libs/utils:json",
"//cuttlefish/common/libs/utils:result",
"//cuttlefish/host/commands/run_cvd/launch:cvdalloc",
"//cuttlefish/host/commands/run_cvd/launch:log_tee_creator",
"//cuttlefish/host/commands/run_cvd/launch:wmediumd_server",
"//cuttlefish/host/libs/command_util",
Expand Down
23 changes: 18 additions & 5 deletions base/cvd/cuttlefish/host/commands/run_cvd/launch/cvdalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <sys/stat.h>

#include <chrono>
#include <mutex>
#include <string>
#include <string_view>
#include <unordered_set>
Expand All @@ -46,8 +47,14 @@ namespace cuttlefish {
constexpr std::chrono::seconds kCvdAllocateTimeout = std::chrono::seconds(30);
constexpr std::chrono::seconds kCvdTeardownTimeout = std::chrono::seconds(2);

enum class CvdallocStatus {
kUnknown = 0,
kAvailable,
kFailed
};

Cvdalloc::Cvdalloc(const CuttlefishConfig::InstanceSpecific& instance)
: instance_(instance) {}
: instance_(instance), status_(CvdallocStatus::kUnknown) {}

Result<std::vector<MonitorCommand>> Cvdalloc::Commands() {
std::string path = CvdallocBinary();
Expand All @@ -67,10 +74,16 @@ bool Cvdalloc::Enabled() const { return instance_.use_cvdalloc(); }
std::unordered_set<SetupFeature *> Cvdalloc::Dependencies() const { return {}; }

Result<void> Cvdalloc::WaitForAvailability() {
LOG(INFO) << "cvdalloc (run_cvd): waiting to finish allocation.";
CF_EXPECT(cvdalloc::Wait(socket_, kCvdAllocateTimeout),
"cvdalloc (run_cvd): Wait failed");
LOG(INFO) << "cvdalloc (run_cvd): allocation is done.";
std::lock_guard<std::mutex> lock(availability_mutex_);
CF_EXPECT(status_ != CvdallocStatus::kFailed);
if (status_ == CvdallocStatus::kUnknown) {
LOG(INFO) << "cvdalloc (run_cvd): waiting to finish allocation.";
status_ = CvdallocStatus::kFailed;
CF_EXPECT(cvdalloc::Wait(socket_, kCvdAllocateTimeout),
"cvdalloc (run_cvd): Wait failed");
LOG(INFO) << "cvdalloc (run_cvd): allocation is done.";
status_ = CvdallocStatus::kAvailable;
}

return {};
}
Expand Down
4 changes: 4 additions & 0 deletions base/cvd/cuttlefish/host/commands/run_cvd/launch/cvdalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

namespace cuttlefish {

enum class CvdallocStatus;

class Cvdalloc : public vm_manager::VmmDependencyCommand {
public:
INJECT(Cvdalloc(const CuttlefishConfig::InstanceSpecific &instance));
Expand All @@ -49,6 +51,8 @@ class Cvdalloc : public vm_manager::VmmDependencyCommand {

const CuttlefishConfig::InstanceSpecific &instance_;
SharedFD socket_, their_socket_;
std::mutex availability_mutex_;
CvdallocStatus status_;
};

fruit::Component<fruit::Required<const CuttlefishConfig::InstanceSpecific>>
Expand Down
22 changes: 16 additions & 6 deletions base/cvd/cuttlefish/host/commands/run_cvd/launch/open_wrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "cuttlefish/common/libs/utils/json.h"
#include "cuttlefish/common/libs/utils/result.h"
#include "cuttlefish/host/commands/run_cvd/launch/cvdalloc.h"
#include "cuttlefish/host/commands/run_cvd/launch/log_tee_creator.h"
#include "cuttlefish/host/commands/run_cvd/launch/wmediumd_server.h"
#include "cuttlefish/host/libs/command_util/snapshot_utils.h"
Expand All @@ -48,12 +49,14 @@ class OpenWrt : public CommandSource {
INJECT(OpenWrt(const CuttlefishConfig& config,
const CuttlefishConfig::EnvironmentSpecific& environment,
const CuttlefishConfig::InstanceSpecific& instance,
LogTeeCreator& log_tee, WmediumdServer& wmediumd_server))
LogTeeCreator& log_tee, WmediumdServer& wmediumd_server,
Cvdalloc& cvdalloc))
: config_(config),
environment_(environment),
instance_(instance),
log_tee_(log_tee),
wmediumd_server_(wmediumd_server) {}
wmediumd_server_(wmediumd_server),
cvdalloc_(cvdalloc) {}

// CommandSource
Result<std::vector<MonitorCommand>> Commands() override {
Expand All @@ -62,7 +65,12 @@ class OpenWrt : public CommandSource {
CrosvmBuilder ap_cmd;

ap_cmd.Cmd().AddPrerequisite([this]() -> Result<void> {
return wmediumd_server_.WaitForAvailability();
if (cvdalloc_.Enabled()) {
CF_EXPECT(cvdalloc_.WaitForAvailability());
LOG(INFO) << "openwrt (run_cvd): cvdalloc is available.";
}
CF_EXPECT(wmediumd_server_.WaitForAvailability());
return {};
});

std::string first_time_argument;
Expand Down Expand Up @@ -183,15 +191,17 @@ class OpenWrt : public CommandSource {
const CuttlefishConfig::InstanceSpecific& instance_;
LogTeeCreator& log_tee_;
WmediumdServer& wmediumd_server_;
Cvdalloc& cvdalloc_;

static constexpr int kOpenwrtVmResetExitCode = 32;
};

} // namespace

fruit::Component<fruit::Required<
const CuttlefishConfig, const CuttlefishConfig::EnvironmentSpecific,
const CuttlefishConfig::InstanceSpecific, LogTeeCreator, WmediumdServer>>
fruit::Component<fruit::Required<const CuttlefishConfig,
const CuttlefishConfig::EnvironmentSpecific,
const CuttlefishConfig::InstanceSpecific,
LogTeeCreator, WmediumdServer, Cvdalloc>>
OpenWrtComponent() {
return fruit::createComponent()
.addMultibinding<CommandSource, OpenWrt>()
Expand Down
8 changes: 5 additions & 3 deletions base/cvd/cuttlefish/host/commands/run_cvd/launch/open_wrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@

#include <fruit/fruit.h>

#include "cuttlefish/host/commands/run_cvd/launch/cvdalloc.h"
#include "cuttlefish/host/commands/run_cvd/launch/log_tee_creator.h"
#include "cuttlefish/host/commands/run_cvd/launch/wmediumd_server.h"
#include "cuttlefish/host/libs/config/cuttlefish_config.h"

namespace cuttlefish {

fruit::Component<fruit::Required<
const CuttlefishConfig, const CuttlefishConfig::EnvironmentSpecific,
const CuttlefishConfig::InstanceSpecific, LogTeeCreator, WmediumdServer>>
fruit::Component<fruit::Required<const CuttlefishConfig,
const CuttlefishConfig::EnvironmentSpecific,
const CuttlefishConfig::InstanceSpecific,
LogTeeCreator, WmediumdServer, Cvdalloc>>
OpenWrtComponent();

} // namespace cuttlefish
Loading