Skip to content

Commit aea7730

Browse files
committed
Change the cvd directory location to /var/tmp/cvd
It was at /tmp/cvd, but that directory is typically mounted with a tmpfs system not suitable for the large ammounts of storage the cvd directory requires. To avoid leaving running instances behind after an update the old path is still used when it already exists. Since it's under the /tmp directory it will be deleted on the next system reboot and, of course, won't exists after a clean re-image. Bug: b/458388172
1 parent f4f0f10 commit aea7730

File tree

1 file changed

+32
-1
lines changed
  • base/cvd/cuttlefish/host/commands/cvd/utils

1 file changed

+32
-1
lines changed

base/cvd/cuttlefish/host/commands/cvd/utils/common.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ namespace cuttlefish {
3838

3939
namespace {
4040

41+
constexpr char kDefaultCvdDir[] = "/var/tmp/cvd";
42+
constexpr char kPreviousDefaultCvdDir[] = "/tmp/cvd";
43+
4144
std::string DefaultBaseDir() {
4245
auto time = std::chrono::system_clock::now().time_since_epoch().count();
4346
return fmt::format("{}/{}", PerUserDir(), time);
@@ -54,6 +57,29 @@ Result<void> LinkOrMakeDir(const std::string& path,
5457
return {};
5558
}
5659

60+
bool ShouldUsePreviousCvdLocation() {
61+
// Don't use the old one if the new one already exists
62+
if (DirectoryExists(kDefaultCvdDir)) {
63+
return false;
64+
}
65+
// Check the locks directory. Even if /tmp/cvd exists it would only be a
66+
// problem if an instance exists, but existing instances would have their
67+
// corresponding lock file.
68+
// It's still possible for a long running cvd create command to have started
69+
// before cvd was updated and not yet gotten to create the instance lock file,
70+
// in which case it will wrongfully create it under /tmp. If that happens it
71+
// can only be addressed by manually killing the running instance and deleting
72+
// /tmp/cvd, or just rebooting. This is hopefully unlikely to occur since cvd
73+
// would have to be updated at the same time the first cvd load command after
74+
// the last boot runs.
75+
const std::string old_locks_path =
76+
fmt::format("{}/{}", kPreviousDefaultCvdDir, "lock");
77+
if (!DirectoryExists(old_locks_path)) {
78+
return false;
79+
}
80+
Result<bool> is_empty_res = IsDirectoryEmpty(old_locks_path);
81+
return is_empty_res.ok() && !is_empty_res.value();
82+
}
5783
} // namespace
5884

5985
/*
@@ -155,7 +181,12 @@ android::base::LogSeverity GetMinimumVerbosity() {
155181
return android::base::GetMinimumLogSeverity();
156182
}
157183

158-
std::string CvdDir() { return "/tmp/cvd"; }
184+
std::string CvdDir() {
185+
if (ShouldUsePreviousCvdLocation()) {
186+
return kPreviousDefaultCvdDir;
187+
}
188+
return kDefaultCvdDir;
189+
}
159190

160191
std::string PerUserDir() { return fmt::format("{}/{}", CvdDir(), getuid()); }
161192

0 commit comments

Comments
 (0)