Skip to content

Commit b5bcc2b

Browse files
committed
Use incremental locking when use_cvdalloc.
The existing locking scheme examines the number of preexisting tap interfaces on the system as created by cuttlefish-host-resources, then acquires the number of locks as there are tap interfaces. This scheme won't work when we want to incrementally create tap interfaces. Instead, acquire as many instance locks as requested when we use_cvdalloc. The case where instance numbers can be explicitly requested is slightly interesting; here we just use TryAcquireLocks.
1 parent f49224e commit b5bcc2b

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

base/cvd/cuttlefish/host/commands/cvd/cli/selector/creation_analyzer.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ CreationAnalyzer::AnalyzeInstanceIdsInternal(
157157
}
158158
return instance_info;
159159
}
160+
161+
std::set<int> requested(requested_instance_ids.begin(),
162+
requested_instance_ids.end());
160163
auto acquired_all_file_locks =
161-
CF_EXPECT(instance_lock_file_manager_.LockAllAvailable());
164+
CF_EXPECT(instance_lock_file_manager_.TryAcquireLocks(requested));
162165
auto id_to_lockfile_map =
163166
ConstructIdLockFileMap(std::move(acquired_all_file_locks));
164167
for (const auto& [id, instance_name] : id_name_pairs) {
@@ -177,10 +180,13 @@ CreationAnalyzer::AnalyzeInstanceIdsInternal(bool acquire_file_locks) {
177180
"For now, cvd server always acquire the file locks "
178181
<< "when IDs are automatically allocated.");
179182

183+
const auto incremental = selector_options_parser_.UseCvdalloc();
180184
// As this test was done earlier, this line must not fail
181185
const auto n_instances = selector_options_parser_.RequestedNumInstances();
182186
auto acquired_all_file_locks =
183-
CF_EXPECT(instance_lock_file_manager_.LockAllAvailable());
187+
incremental ? CF_EXPECT(instance_lock_file_manager_.AcquireUnusedLocks(
188+
n_instances))
189+
: CF_EXPECT(instance_lock_file_manager_.LockAllAvailable());
184190
auto id_to_lockfile_map =
185191
ConstructIdLockFileMap(std::move(acquired_all_file_locks));
186192

base/cvd/cuttlefish/host/commands/cvd/cli/selector/start_selector_parser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ bool StartSelectorParser::CalcMayBeDefaultGroup() {
248248
Result<void> StartSelectorParser::ParseOptions() {
249249
may_be_default_group_ = CalcMayBeDefaultGroup();
250250

251+
std::optional<bool> use_cvdalloc;
252+
CF_EXPECT(FilterSelectorFlag(cmd_args_, "use_cvdalloc", use_cvdalloc));
253+
use_cvdalloc_ = use_cvdalloc.value_or(false);
254+
251255
std::optional<std::string> num_instances;
252256
std::optional<std::string> instance_nums;
253257
std::optional<std::string> base_instance_num;

base/cvd/cuttlefish/host/commands/cvd/cli/selector/start_selector_parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class StartSelectorParser {
5454
}
5555
unsigned RequestedNumInstances() const { return requested_num_instances_; }
5656
bool IsMaybeDefaultGroup() const { return may_be_default_group_; }
57+
bool UseCvdalloc() const { return use_cvdalloc_; }
5758

5859
private:
5960
StartSelectorParser(const std::string& system_wide_user_home,
@@ -138,6 +139,7 @@ class StartSelectorParser {
138139
std::optional<std::vector<unsigned>> instance_ids_;
139140
unsigned requested_num_instances_;
140141
bool may_be_default_group_;
142+
bool use_cvdalloc_;
141143

142144
// temporarily keeps the leftover of the input cmd_args
143145
const std::string client_user_home_;

0 commit comments

Comments
 (0)