Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "IncrementalService" |
| 18 | |
| 19 | #include "IncrementalService.h" |
| 20 | |
| 21 | #include <android-base/file.h> |
| 22 | #include <android-base/logging.h> |
| 23 | #include <android-base/properties.h> |
| 24 | #include <android-base/stringprintf.h> |
| 25 | #include <android-base/strings.h> |
| 26 | #include <android/content/pm/IDataLoaderStatusListener.h> |
| 27 | #include <android/os/IVold.h> |
| 28 | #include <androidfw/ZipFileRO.h> |
| 29 | #include <androidfw/ZipUtils.h> |
| 30 | #include <binder/BinderService.h> |
| 31 | #include <binder/ParcelFileDescriptor.h> |
| 32 | #include <binder/Status.h> |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 33 | #include <openssl/sha.h> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 34 | #include <sys/stat.h> |
| 35 | #include <uuid/uuid.h> |
| 36 | #include <zlib.h> |
| 37 | |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame^] | 38 | #include <ctime> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 39 | #include <iterator> |
| 40 | #include <span> |
| 41 | #include <stack> |
| 42 | #include <thread> |
| 43 | #include <type_traits> |
| 44 | |
| 45 | #include "Metadata.pb.h" |
| 46 | |
| 47 | using namespace std::literals; |
| 48 | using namespace android::content::pm; |
| 49 | |
| 50 | namespace android::incremental { |
| 51 | |
| 52 | namespace { |
| 53 | |
| 54 | using IncrementalFileSystemControlParcel = |
| 55 | ::android::os::incremental::IncrementalFileSystemControlParcel; |
| 56 | |
| 57 | struct Constants { |
| 58 | static constexpr auto backing = "backing_store"sv; |
| 59 | static constexpr auto mount = "mount"sv; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 60 | static constexpr auto storagePrefix = "st"sv; |
| 61 | static constexpr auto mountpointMdPrefix = ".mountpoint."sv; |
| 62 | static constexpr auto infoMdName = ".info"sv; |
| 63 | }; |
| 64 | |
| 65 | static const Constants& constants() { |
| 66 | static Constants c; |
| 67 | return c; |
| 68 | } |
| 69 | |
| 70 | template <base::LogSeverity level = base::ERROR> |
| 71 | bool mkdirOrLog(std::string_view name, int mode = 0770, bool allowExisting = true) { |
| 72 | auto cstr = path::c_str(name); |
| 73 | if (::mkdir(cstr, mode)) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 74 | if (!allowExisting || errno != EEXIST) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 75 | PLOG(level) << "Can't create directory '" << name << '\''; |
| 76 | return false; |
| 77 | } |
| 78 | struct stat st; |
| 79 | if (::stat(cstr, &st) || !S_ISDIR(st.st_mode)) { |
| 80 | PLOG(level) << "Path exists but is not a directory: '" << name << '\''; |
| 81 | return false; |
| 82 | } |
| 83 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 84 | if (::chmod(cstr, mode)) { |
| 85 | PLOG(level) << "Changing permission failed for '" << name << '\''; |
| 86 | return false; |
| 87 | } |
| 88 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 89 | return true; |
| 90 | } |
| 91 | |
| 92 | static std::string toMountKey(std::string_view path) { |
| 93 | if (path.empty()) { |
| 94 | return "@none"; |
| 95 | } |
| 96 | if (path == "/"sv) { |
| 97 | return "@root"; |
| 98 | } |
| 99 | if (path::isAbsolute(path)) { |
| 100 | path.remove_prefix(1); |
| 101 | } |
| 102 | std::string res(path); |
| 103 | std::replace(res.begin(), res.end(), '/', '_'); |
| 104 | std::replace(res.begin(), res.end(), '@', '_'); |
| 105 | return res; |
| 106 | } |
| 107 | |
| 108 | static std::pair<std::string, std::string> makeMountDir(std::string_view incrementalDir, |
| 109 | std::string_view path) { |
| 110 | auto mountKey = toMountKey(path); |
| 111 | const auto prefixSize = mountKey.size(); |
| 112 | for (int counter = 0; counter < 1000; |
| 113 | mountKey.resize(prefixSize), base::StringAppendF(&mountKey, "%d", counter++)) { |
| 114 | auto mountRoot = path::join(incrementalDir, mountKey); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 115 | if (mkdirOrLog(mountRoot, 0777, false)) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 116 | return {mountKey, mountRoot}; |
| 117 | } |
| 118 | } |
| 119 | return {}; |
| 120 | } |
| 121 | |
| 122 | template <class ProtoMessage, class Control> |
| 123 | static ProtoMessage parseFromIncfs(const IncFsWrapper* incfs, Control&& control, |
| 124 | std::string_view path) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 125 | auto md = incfs->getMetadata(control, path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 126 | ProtoMessage message; |
| 127 | return message.ParseFromArray(md.data(), md.size()) ? message : ProtoMessage{}; |
| 128 | } |
| 129 | |
| 130 | static bool isValidMountTarget(std::string_view path) { |
| 131 | return path::isAbsolute(path) && path::isEmptyDir(path).value_or(true); |
| 132 | } |
| 133 | |
| 134 | std::string makeBindMdName() { |
| 135 | static constexpr auto uuidStringSize = 36; |
| 136 | |
| 137 | uuid_t guid; |
| 138 | uuid_generate(guid); |
| 139 | |
| 140 | std::string name; |
| 141 | const auto prefixSize = constants().mountpointMdPrefix.size(); |
| 142 | name.reserve(prefixSize + uuidStringSize); |
| 143 | |
| 144 | name = constants().mountpointMdPrefix; |
| 145 | name.resize(prefixSize + uuidStringSize); |
| 146 | uuid_unparse(guid, name.data() + prefixSize); |
| 147 | |
| 148 | return name; |
| 149 | } |
| 150 | } // namespace |
| 151 | |
| 152 | IncrementalService::IncFsMount::~IncFsMount() { |
| 153 | incrementalService.mIncrementalManager->destroyDataLoader(mountId); |
| 154 | control.reset(); |
| 155 | LOG(INFO) << "Unmounting and cleaning up mount " << mountId << " with root '" << root << '\''; |
| 156 | for (auto&& [target, _] : bindPoints) { |
| 157 | LOG(INFO) << "\tbind: " << target; |
| 158 | incrementalService.mVold->unmountIncFs(target); |
| 159 | } |
| 160 | LOG(INFO) << "\troot: " << root; |
| 161 | incrementalService.mVold->unmountIncFs(path::join(root, constants().mount)); |
| 162 | cleanupFilesystem(root); |
| 163 | } |
| 164 | |
| 165 | auto IncrementalService::IncFsMount::makeStorage(StorageId id) -> StorageMap::iterator { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 166 | std::string name; |
| 167 | for (int no = nextStorageDirNo.fetch_add(1, std::memory_order_relaxed), i = 0; |
| 168 | i < 1024 && no >= 0; no = nextStorageDirNo.fetch_add(1, std::memory_order_relaxed), ++i) { |
| 169 | name.clear(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 170 | base::StringAppendF(&name, "%.*s_%d_%d", int(constants().storagePrefix.size()), |
| 171 | constants().storagePrefix.data(), id, no); |
| 172 | auto fullName = path::join(root, constants().mount, name); |
| 173 | if (auto err = incrementalService.mIncFs->makeDir(control, fullName); !err) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 174 | std::lock_guard l(lock); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 175 | return storages.insert_or_assign(id, Storage{std::move(fullName)}).first; |
| 176 | } else if (err != EEXIST) { |
| 177 | LOG(ERROR) << __func__ << "(): failed to create dir |" << fullName << "| " << err; |
| 178 | break; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | nextStorageDirNo = 0; |
| 182 | return storages.end(); |
| 183 | } |
| 184 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 185 | static std::unique_ptr<DIR, decltype(&::closedir)> openDir(const char* path) { |
| 186 | return {::opendir(path), ::closedir}; |
| 187 | } |
| 188 | |
| 189 | static int rmDirContent(const char* path) { |
| 190 | auto dir = openDir(path); |
| 191 | if (!dir) { |
| 192 | return -EINVAL; |
| 193 | } |
| 194 | while (auto entry = ::readdir(dir.get())) { |
| 195 | if (entry->d_name == "."sv || entry->d_name == ".."sv) { |
| 196 | continue; |
| 197 | } |
| 198 | auto fullPath = android::base::StringPrintf("%s/%s", path, entry->d_name); |
| 199 | if (entry->d_type == DT_DIR) { |
| 200 | if (const auto err = rmDirContent(fullPath.c_str()); err != 0) { |
| 201 | PLOG(WARNING) << "Failed to delete " << fullPath << " content"; |
| 202 | return err; |
| 203 | } |
| 204 | if (const auto err = ::rmdir(fullPath.c_str()); err != 0) { |
| 205 | PLOG(WARNING) << "Failed to rmdir " << fullPath; |
| 206 | return err; |
| 207 | } |
| 208 | } else { |
| 209 | if (const auto err = ::unlink(fullPath.c_str()); err != 0) { |
| 210 | PLOG(WARNING) << "Failed to delete " << fullPath; |
| 211 | return err; |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | return 0; |
| 216 | } |
| 217 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 218 | void IncrementalService::IncFsMount::cleanupFilesystem(std::string_view root) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 219 | rmDirContent(path::join(root, constants().backing).c_str()); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 220 | ::rmdir(path::join(root, constants().backing).c_str()); |
| 221 | ::rmdir(path::join(root, constants().mount).c_str()); |
| 222 | ::rmdir(path::c_str(root)); |
| 223 | } |
| 224 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 225 | IncrementalService::IncrementalService(ServiceManagerWrapper&& sm, std::string_view rootDir) |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 226 | : mVold(sm.getVoldService()), |
| 227 | mIncrementalManager(sm.getIncrementalManager()), |
| 228 | mIncFs(sm.getIncFs()), |
| 229 | mIncrementalDir(rootDir) { |
| 230 | if (!mVold) { |
| 231 | LOG(FATAL) << "Vold service is unavailable"; |
| 232 | } |
| 233 | if (!mIncrementalManager) { |
| 234 | LOG(FATAL) << "IncrementalManager service is unavailable"; |
| 235 | } |
| 236 | // TODO(b/136132412): check that root dir should already exist |
| 237 | // TODO(b/136132412): enable mount existing dirs after SELinux rules are merged |
| 238 | // mountExistingImages(); |
| 239 | } |
| 240 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 241 | FileId IncrementalService::idFromMetadata(std::span<const uint8_t> metadata) { |
| 242 | incfs::FileId id = {}; |
| 243 | if (size_t(metadata.size()) <= sizeof(id)) { |
| 244 | memcpy(&id, metadata.data(), metadata.size()); |
| 245 | } else { |
| 246 | uint8_t buffer[SHA_DIGEST_LENGTH]; |
| 247 | static_assert(sizeof(buffer) >= sizeof(id)); |
| 248 | |
| 249 | SHA_CTX ctx; |
| 250 | SHA1_Init(&ctx); |
| 251 | SHA1_Update(&ctx, metadata.data(), metadata.size()); |
| 252 | SHA1_Final(buffer, &ctx); |
| 253 | memcpy(&id, buffer, sizeof(id)); |
| 254 | } |
| 255 | return id; |
| 256 | } |
| 257 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 258 | IncrementalService::~IncrementalService() = default; |
| 259 | |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame^] | 260 | inline const char* toString(TimePoint t) { |
| 261 | using SystemClock = std::chrono::system_clock; |
| 262 | time_t time = SystemClock::to_time_t(SystemClock::now() + std::chrono::duration_cast<SystemClock::duration>(t - Clock::now())); |
| 263 | return std::ctime(&time); |
| 264 | } |
| 265 | |
| 266 | inline const char* toString(IncrementalService::BindKind kind) { |
| 267 | switch (kind) { |
| 268 | case IncrementalService::BindKind::Temporary: |
| 269 | return "Temporary"; |
| 270 | case IncrementalService::BindKind::Permanent: |
| 271 | return "Permanent"; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | void IncrementalService::onDump(int fd) { |
| 276 | dprintf(fd, "Incremental is %s\n", incfs::enabled() ? "ENABLED" : "DISABLED"); |
| 277 | dprintf(fd, "Incremental dir: %s\n", mIncrementalDir.c_str()); |
| 278 | |
| 279 | std::unique_lock l(mLock); |
| 280 | |
| 281 | dprintf(fd, "Mounts (%d):\n", int(mMounts.size())); |
| 282 | for (auto&& [id, ifs] : mMounts) { |
| 283 | const IncFsMount& mnt = *ifs.get(); |
| 284 | dprintf(fd, "\t[%d]:\n", id); |
| 285 | dprintf(fd, "\t\tmountId: %d\n", mnt.mountId); |
| 286 | dprintf(fd, "\t\tnextStorageDirNo: %d\n", mnt.nextStorageDirNo.load()); |
| 287 | dprintf(fd, "\t\tdataLoaderStatus: %d\n", mnt.dataLoaderStatus.load()); |
| 288 | dprintf(fd, "\t\tconnectionLostTime: %s\n", toString(mnt.connectionLostTime)); |
| 289 | if (mnt.savedDataLoaderParams) { |
| 290 | const auto& params = mnt.savedDataLoaderParams.value(); |
| 291 | dprintf(fd, "\t\tsavedDataLoaderParams:\n"); |
| 292 | dprintf(fd, "\t\t\ttype: %s\n", toString(params.type).c_str()); |
| 293 | dprintf(fd, "\t\t\tpackageName: %s\n", params.packageName.c_str()); |
| 294 | dprintf(fd, "\t\t\tclassName: %s\n", params.className.c_str()); |
| 295 | dprintf(fd, "\t\t\targuments: %s\n", params.arguments.c_str()); |
| 296 | dprintf(fd, "\t\t\tdynamicArgs: %d\n", int(params.dynamicArgs.size())); |
| 297 | } |
| 298 | dprintf(fd, "\t\tstorages (%d):\n", int(mnt.storages.size())); |
| 299 | for (auto&& [storageId, storage] : mnt.storages) { |
| 300 | dprintf(fd, "\t\t\t[%d] -> [%s]\n", storageId, storage.name.c_str()); |
| 301 | } |
| 302 | |
| 303 | dprintf(fd, "\t\tbindPoints (%d):\n", int(mnt.bindPoints.size())); |
| 304 | for (auto&& [target, bind] : mnt.bindPoints) { |
| 305 | dprintf(fd, "\t\t\t[%s]->[%d]:\n", target.c_str(), bind.storage); |
| 306 | dprintf(fd, "\t\t\t\tsavedFilename: %s\n", bind.savedFilename.c_str()); |
| 307 | dprintf(fd, "\t\t\t\tsourceDir: %s\n", bind.sourceDir.c_str()); |
| 308 | dprintf(fd, "\t\t\t\tkind: %s\n", toString(bind.kind)); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | dprintf(fd, "Sorted binds (%d):\n", int(mBindsByPath.size())); |
| 313 | for (auto&& [target, mountPairIt] : mBindsByPath) { |
| 314 | const auto& bind = mountPairIt->second; |
| 315 | dprintf(fd, "\t\t[%s]->[%d]:\n", target.c_str(), bind.storage); |
| 316 | dprintf(fd, "\t\t\tsavedFilename: %s\n", bind.savedFilename.c_str()); |
| 317 | dprintf(fd, "\t\t\tsourceDir: %s\n", bind.sourceDir.c_str()); |
| 318 | dprintf(fd, "\t\t\tkind: %s\n", toString(bind.kind)); |
| 319 | } |
| 320 | } |
| 321 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 322 | std::optional<std::future<void>> IncrementalService::onSystemReady() { |
| 323 | std::promise<void> threadFinished; |
| 324 | if (mSystemReady.exchange(true)) { |
| 325 | return {}; |
| 326 | } |
| 327 | |
| 328 | std::vector<IfsMountPtr> mounts; |
| 329 | { |
| 330 | std::lock_guard l(mLock); |
| 331 | mounts.reserve(mMounts.size()); |
| 332 | for (auto&& [id, ifs] : mMounts) { |
| 333 | if (ifs->mountId == id) { |
| 334 | mounts.push_back(ifs); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | std::thread([this, mounts = std::move(mounts)]() { |
| 340 | std::vector<IfsMountPtr> failedLoaderMounts; |
| 341 | for (auto&& ifs : mounts) { |
| 342 | if (prepareDataLoader(*ifs, nullptr)) { |
| 343 | LOG(INFO) << "Successfully started data loader for mount " << ifs->mountId; |
| 344 | } else { |
| 345 | LOG(WARNING) << "Failed to start data loader for mount " << ifs->mountId; |
| 346 | failedLoaderMounts.push_back(std::move(ifs)); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | while (!failedLoaderMounts.empty()) { |
| 351 | LOG(WARNING) << "Deleting failed mount " << failedLoaderMounts.back()->mountId; |
| 352 | deleteStorage(*failedLoaderMounts.back()); |
| 353 | failedLoaderMounts.pop_back(); |
| 354 | } |
| 355 | mPrepareDataLoaders.set_value_at_thread_exit(); |
| 356 | }).detach(); |
| 357 | return mPrepareDataLoaders.get_future(); |
| 358 | } |
| 359 | |
| 360 | auto IncrementalService::getStorageSlotLocked() -> MountMap::iterator { |
| 361 | for (;;) { |
| 362 | if (mNextId == kMaxStorageId) { |
| 363 | mNextId = 0; |
| 364 | } |
| 365 | auto id = ++mNextId; |
| 366 | auto [it, inserted] = mMounts.try_emplace(id, nullptr); |
| 367 | if (inserted) { |
| 368 | return it; |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | StorageId IncrementalService::createStorage(std::string_view mountPoint, |
| 374 | DataLoaderParamsParcel&& dataLoaderParams, |
| 375 | CreateOptions options) { |
| 376 | LOG(INFO) << "createStorage: " << mountPoint << " | " << int(options); |
| 377 | if (!path::isAbsolute(mountPoint)) { |
| 378 | LOG(ERROR) << "path is not absolute: " << mountPoint; |
| 379 | return kInvalidStorageId; |
| 380 | } |
| 381 | |
| 382 | auto mountNorm = path::normalize(mountPoint); |
| 383 | { |
| 384 | const auto id = findStorageId(mountNorm); |
| 385 | if (id != kInvalidStorageId) { |
| 386 | if (options & CreateOptions::OpenExisting) { |
| 387 | LOG(INFO) << "Opened existing storage " << id; |
| 388 | return id; |
| 389 | } |
| 390 | LOG(ERROR) << "Directory " << mountPoint << " is already mounted at storage " << id; |
| 391 | return kInvalidStorageId; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | if (!(options & CreateOptions::CreateNew)) { |
| 396 | LOG(ERROR) << "not requirested create new storage, and it doesn't exist: " << mountPoint; |
| 397 | return kInvalidStorageId; |
| 398 | } |
| 399 | |
| 400 | if (!path::isEmptyDir(mountNorm)) { |
| 401 | LOG(ERROR) << "Mounting over existing non-empty directory is not supported: " << mountNorm; |
| 402 | return kInvalidStorageId; |
| 403 | } |
| 404 | auto [mountKey, mountRoot] = makeMountDir(mIncrementalDir, mountNorm); |
| 405 | if (mountRoot.empty()) { |
| 406 | LOG(ERROR) << "Bad mount point"; |
| 407 | return kInvalidStorageId; |
| 408 | } |
| 409 | // Make sure the code removes all crap it may create while still failing. |
| 410 | auto firstCleanup = [](const std::string* ptr) { IncFsMount::cleanupFilesystem(*ptr); }; |
| 411 | auto firstCleanupOnFailure = |
| 412 | std::unique_ptr<std::string, decltype(firstCleanup)>(&mountRoot, firstCleanup); |
| 413 | |
| 414 | auto mountTarget = path::join(mountRoot, constants().mount); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 415 | const auto backing = path::join(mountRoot, constants().backing); |
| 416 | if (!mkdirOrLog(backing, 0777) || !mkdirOrLog(mountTarget)) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 417 | return kInvalidStorageId; |
| 418 | } |
| 419 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 420 | IncFsMount::Control control; |
| 421 | { |
| 422 | std::lock_guard l(mMountOperationLock); |
| 423 | IncrementalFileSystemControlParcel controlParcel; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 424 | |
| 425 | if (auto err = rmDirContent(backing.c_str())) { |
| 426 | LOG(ERROR) << "Coudn't clean the backing directory " << backing << ": " << err; |
| 427 | return kInvalidStorageId; |
| 428 | } |
| 429 | if (!mkdirOrLog(path::join(backing, ".index"), 0777)) { |
| 430 | return kInvalidStorageId; |
| 431 | } |
| 432 | auto status = mVold->mountIncFs(backing, mountTarget, 0, &controlParcel); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 433 | if (!status.isOk()) { |
| 434 | LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8(); |
| 435 | return kInvalidStorageId; |
| 436 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 437 | if (controlParcel.cmd.get() < 0 || controlParcel.pendingReads.get() < 0 || |
| 438 | controlParcel.log.get() < 0) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 439 | LOG(ERROR) << "Vold::mountIncFs() returned invalid control parcel."; |
| 440 | return kInvalidStorageId; |
| 441 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 442 | control.cmd = controlParcel.cmd.release().release(); |
| 443 | control.pendingReads = controlParcel.pendingReads.release().release(); |
| 444 | control.logs = controlParcel.log.release().release(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | std::unique_lock l(mLock); |
| 448 | const auto mountIt = getStorageSlotLocked(); |
| 449 | const auto mountId = mountIt->first; |
| 450 | l.unlock(); |
| 451 | |
| 452 | auto ifs = |
| 453 | std::make_shared<IncFsMount>(std::move(mountRoot), mountId, std::move(control), *this); |
| 454 | // Now it's the |ifs|'s responsibility to clean up after itself, and the only cleanup we need |
| 455 | // is the removal of the |ifs|. |
| 456 | firstCleanupOnFailure.release(); |
| 457 | |
| 458 | auto secondCleanup = [this, &l](auto itPtr) { |
| 459 | if (!l.owns_lock()) { |
| 460 | l.lock(); |
| 461 | } |
| 462 | mMounts.erase(*itPtr); |
| 463 | }; |
| 464 | auto secondCleanupOnFailure = |
| 465 | std::unique_ptr<decltype(mountIt), decltype(secondCleanup)>(&mountIt, secondCleanup); |
| 466 | |
| 467 | const auto storageIt = ifs->makeStorage(ifs->mountId); |
| 468 | if (storageIt == ifs->storages.end()) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 469 | LOG(ERROR) << "Can't create a default storage directory"; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 470 | return kInvalidStorageId; |
| 471 | } |
| 472 | |
| 473 | { |
| 474 | metadata::Mount m; |
| 475 | m.mutable_storage()->set_id(ifs->mountId); |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 476 | m.mutable_loader()->set_type((int)dataLoaderParams.type); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 477 | m.mutable_loader()->set_package_name(dataLoaderParams.packageName); |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 478 | m.mutable_loader()->set_class_name(dataLoaderParams.className); |
| 479 | m.mutable_loader()->set_arguments(dataLoaderParams.arguments); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 480 | const auto metadata = m.SerializeAsString(); |
| 481 | m.mutable_loader()->release_arguments(); |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 482 | m.mutable_loader()->release_class_name(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 483 | m.mutable_loader()->release_package_name(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 484 | if (auto err = |
| 485 | mIncFs->makeFile(ifs->control, |
| 486 | path::join(ifs->root, constants().mount, |
| 487 | constants().infoMdName), |
| 488 | 0777, idFromMetadata(metadata), |
| 489 | {.metadata = {metadata.data(), (IncFsSize)metadata.size()}})) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 490 | LOG(ERROR) << "Saving mount metadata failed: " << -err; |
| 491 | return kInvalidStorageId; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | const auto bk = |
| 496 | (options & CreateOptions::PermanentBind) ? BindKind::Permanent : BindKind::Temporary; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 497 | if (auto err = addBindMount(*ifs, storageIt->first, storageIt->second.name, |
| 498 | std::string(storageIt->second.name), std::move(mountNorm), bk, l); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 499 | err < 0) { |
| 500 | LOG(ERROR) << "adding bind mount failed: " << -err; |
| 501 | return kInvalidStorageId; |
| 502 | } |
| 503 | |
| 504 | // Done here as well, all data structures are in good state. |
| 505 | secondCleanupOnFailure.release(); |
| 506 | |
| 507 | if (!prepareDataLoader(*ifs, &dataLoaderParams)) { |
| 508 | LOG(ERROR) << "prepareDataLoader() failed"; |
| 509 | deleteStorageLocked(*ifs, std::move(l)); |
| 510 | return kInvalidStorageId; |
| 511 | } |
| 512 | |
| 513 | mountIt->second = std::move(ifs); |
| 514 | l.unlock(); |
| 515 | LOG(INFO) << "created storage " << mountId; |
| 516 | return mountId; |
| 517 | } |
| 518 | |
| 519 | StorageId IncrementalService::createLinkedStorage(std::string_view mountPoint, |
| 520 | StorageId linkedStorage, |
| 521 | IncrementalService::CreateOptions options) { |
| 522 | if (!isValidMountTarget(mountPoint)) { |
| 523 | LOG(ERROR) << "Mount point is invalid or missing"; |
| 524 | return kInvalidStorageId; |
| 525 | } |
| 526 | |
| 527 | std::unique_lock l(mLock); |
| 528 | const auto& ifs = getIfsLocked(linkedStorage); |
| 529 | if (!ifs) { |
| 530 | LOG(ERROR) << "Ifs unavailable"; |
| 531 | return kInvalidStorageId; |
| 532 | } |
| 533 | |
| 534 | const auto mountIt = getStorageSlotLocked(); |
| 535 | const auto storageId = mountIt->first; |
| 536 | const auto storageIt = ifs->makeStorage(storageId); |
| 537 | if (storageIt == ifs->storages.end()) { |
| 538 | LOG(ERROR) << "Can't create a new storage"; |
| 539 | mMounts.erase(mountIt); |
| 540 | return kInvalidStorageId; |
| 541 | } |
| 542 | |
| 543 | l.unlock(); |
| 544 | |
| 545 | const auto bk = |
| 546 | (options & CreateOptions::PermanentBind) ? BindKind::Permanent : BindKind::Temporary; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 547 | if (auto err = addBindMount(*ifs, storageIt->first, storageIt->second.name, |
| 548 | std::string(storageIt->second.name), path::normalize(mountPoint), |
| 549 | bk, l); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 550 | err < 0) { |
| 551 | LOG(ERROR) << "bindMount failed with error: " << err; |
| 552 | return kInvalidStorageId; |
| 553 | } |
| 554 | |
| 555 | mountIt->second = ifs; |
| 556 | return storageId; |
| 557 | } |
| 558 | |
| 559 | IncrementalService::BindPathMap::const_iterator IncrementalService::findStorageLocked( |
| 560 | std::string_view path) const { |
| 561 | auto bindPointIt = mBindsByPath.upper_bound(path); |
| 562 | if (bindPointIt == mBindsByPath.begin()) { |
| 563 | return mBindsByPath.end(); |
| 564 | } |
| 565 | --bindPointIt; |
| 566 | if (!path::startsWith(path, bindPointIt->first)) { |
| 567 | return mBindsByPath.end(); |
| 568 | } |
| 569 | return bindPointIt; |
| 570 | } |
| 571 | |
| 572 | StorageId IncrementalService::findStorageId(std::string_view path) const { |
| 573 | std::lock_guard l(mLock); |
| 574 | auto it = findStorageLocked(path); |
| 575 | if (it == mBindsByPath.end()) { |
| 576 | return kInvalidStorageId; |
| 577 | } |
| 578 | return it->second->second.storage; |
| 579 | } |
| 580 | |
| 581 | void IncrementalService::deleteStorage(StorageId storageId) { |
| 582 | const auto ifs = getIfs(storageId); |
| 583 | if (!ifs) { |
| 584 | return; |
| 585 | } |
| 586 | deleteStorage(*ifs); |
| 587 | } |
| 588 | |
| 589 | void IncrementalService::deleteStorage(IncrementalService::IncFsMount& ifs) { |
| 590 | std::unique_lock l(ifs.lock); |
| 591 | deleteStorageLocked(ifs, std::move(l)); |
| 592 | } |
| 593 | |
| 594 | void IncrementalService::deleteStorageLocked(IncrementalService::IncFsMount& ifs, |
| 595 | std::unique_lock<std::mutex>&& ifsLock) { |
| 596 | const auto storages = std::move(ifs.storages); |
| 597 | // Don't move the bind points out: Ifs's dtor will use them to unmount everything. |
| 598 | const auto bindPoints = ifs.bindPoints; |
| 599 | ifsLock.unlock(); |
| 600 | |
| 601 | std::lock_guard l(mLock); |
| 602 | for (auto&& [id, _] : storages) { |
| 603 | if (id != ifs.mountId) { |
| 604 | mMounts.erase(id); |
| 605 | } |
| 606 | } |
| 607 | for (auto&& [path, _] : bindPoints) { |
| 608 | mBindsByPath.erase(path); |
| 609 | } |
| 610 | mMounts.erase(ifs.mountId); |
| 611 | } |
| 612 | |
| 613 | StorageId IncrementalService::openStorage(std::string_view pathInMount) { |
| 614 | if (!path::isAbsolute(pathInMount)) { |
| 615 | return kInvalidStorageId; |
| 616 | } |
| 617 | |
| 618 | return findStorageId(path::normalize(pathInMount)); |
| 619 | } |
| 620 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 621 | FileId IncrementalService::nodeFor(StorageId storage, std::string_view subpath) const { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 622 | const auto ifs = getIfs(storage); |
| 623 | if (!ifs) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 624 | return kIncFsInvalidFileId; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 625 | } |
| 626 | std::unique_lock l(ifs->lock); |
| 627 | auto storageIt = ifs->storages.find(storage); |
| 628 | if (storageIt == ifs->storages.end()) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 629 | return kIncFsInvalidFileId; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 630 | } |
| 631 | if (subpath.empty() || subpath == "."sv) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 632 | return kIncFsInvalidFileId; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 633 | } |
| 634 | auto path = path::join(ifs->root, constants().mount, storageIt->second.name, subpath); |
| 635 | l.unlock(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 636 | return mIncFs->getFileId(ifs->control, path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 637 | } |
| 638 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 639 | std::pair<FileId, std::string_view> IncrementalService::parentAndNameFor( |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 640 | StorageId storage, std::string_view subpath) const { |
| 641 | auto name = path::basename(subpath); |
| 642 | if (name.empty()) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 643 | return {kIncFsInvalidFileId, {}}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 644 | } |
| 645 | auto dir = path::dirname(subpath); |
| 646 | if (dir.empty() || dir == "/"sv) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 647 | return {kIncFsInvalidFileId, {}}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 648 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 649 | auto id = nodeFor(storage, dir); |
| 650 | return {id, name}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | IncrementalService::IfsMountPtr IncrementalService::getIfs(StorageId storage) const { |
| 654 | std::lock_guard l(mLock); |
| 655 | return getIfsLocked(storage); |
| 656 | } |
| 657 | |
| 658 | const IncrementalService::IfsMountPtr& IncrementalService::getIfsLocked(StorageId storage) const { |
| 659 | auto it = mMounts.find(storage); |
| 660 | if (it == mMounts.end()) { |
| 661 | static const IfsMountPtr kEmpty = {}; |
| 662 | return kEmpty; |
| 663 | } |
| 664 | return it->second; |
| 665 | } |
| 666 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 667 | int IncrementalService::bind(StorageId storage, std::string_view source, std::string_view target, |
| 668 | BindKind kind) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 669 | if (!isValidMountTarget(target)) { |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | |
| 673 | const auto ifs = getIfs(storage); |
| 674 | if (!ifs) { |
| 675 | return -EINVAL; |
| 676 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 677 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 678 | std::unique_lock l(ifs->lock); |
| 679 | const auto storageInfo = ifs->storages.find(storage); |
| 680 | if (storageInfo == ifs->storages.end()) { |
| 681 | return -EINVAL; |
| 682 | } |
Songchun Fan | 54c6aed | 2020-01-31 16:52:41 -0800 | [diff] [blame] | 683 | std::string normSource; |
| 684 | if (path::isAbsolute(source)) { |
| 685 | normSource = path::normalize(source); |
| 686 | } else { |
| 687 | normSource = path::normalize(path::join(storageInfo->second.name, source)); |
| 688 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 689 | if (!path::startsWith(normSource, storageInfo->second.name)) { |
| 690 | return -EINVAL; |
| 691 | } |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 692 | l.unlock(); |
| 693 | std::unique_lock l2(mLock, std::defer_lock); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 694 | return addBindMount(*ifs, storage, storageInfo->second.name, std::move(normSource), |
| 695 | path::normalize(target), kind, l2); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | int IncrementalService::unbind(StorageId storage, std::string_view target) { |
| 699 | if (!path::isAbsolute(target)) { |
| 700 | return -EINVAL; |
| 701 | } |
| 702 | |
| 703 | LOG(INFO) << "Removing bind point " << target; |
| 704 | |
| 705 | // Here we should only look up by the exact target, not by a subdirectory of any existing mount, |
| 706 | // otherwise there's a chance to unmount something completely unrelated |
| 707 | const auto norm = path::normalize(target); |
| 708 | std::unique_lock l(mLock); |
| 709 | const auto storageIt = mBindsByPath.find(norm); |
| 710 | if (storageIt == mBindsByPath.end() || storageIt->second->second.storage != storage) { |
| 711 | return -EINVAL; |
| 712 | } |
| 713 | const auto bindIt = storageIt->second; |
| 714 | const auto storageId = bindIt->second.storage; |
| 715 | const auto ifs = getIfsLocked(storageId); |
| 716 | if (!ifs) { |
| 717 | LOG(ERROR) << "Internal error: storageId " << storageId << " for bound path " << target |
| 718 | << " is missing"; |
| 719 | return -EFAULT; |
| 720 | } |
| 721 | mBindsByPath.erase(storageIt); |
| 722 | l.unlock(); |
| 723 | |
| 724 | mVold->unmountIncFs(bindIt->first); |
| 725 | std::unique_lock l2(ifs->lock); |
| 726 | if (ifs->bindPoints.size() <= 1) { |
| 727 | ifs->bindPoints.clear(); |
| 728 | deleteStorageLocked(*ifs, std::move(l2)); |
| 729 | } else { |
| 730 | const std::string savedFile = std::move(bindIt->second.savedFilename); |
| 731 | ifs->bindPoints.erase(bindIt); |
| 732 | l2.unlock(); |
| 733 | if (!savedFile.empty()) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 734 | mIncFs->unlink(ifs->control, path::join(ifs->root, constants().mount, savedFile)); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | return 0; |
| 738 | } |
| 739 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 740 | int IncrementalService::makeFile(StorageId storage, std::string_view path, int mode, FileId id, |
| 741 | incfs::NewFileParams params) { |
| 742 | if (auto ifs = getIfs(storage)) { |
Songchun Fan | 54c6aed | 2020-01-31 16:52:41 -0800 | [diff] [blame] | 743 | const auto storageInfo = ifs->storages.find(storage); |
| 744 | if (storageInfo == ifs->storages.end()) { |
| 745 | return -EINVAL; |
| 746 | } |
| 747 | std::string normPath; |
| 748 | if (path::isAbsolute(path)) { |
| 749 | normPath = path::normalize(path); |
| 750 | } else { |
| 751 | normPath = path::normalize(path::join(storageInfo->second.name, path)); |
| 752 | } |
| 753 | if (!path::startsWith(normPath, storageInfo->second.name)) { |
| 754 | return -EINVAL; |
| 755 | } |
| 756 | auto err = mIncFs->makeFile(ifs->control, normPath, mode, id, params); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 757 | if (err) { |
| 758 | return err; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 759 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 760 | std::vector<uint8_t> metadataBytes; |
| 761 | if (params.metadata.data && params.metadata.size > 0) { |
| 762 | metadataBytes.assign(params.metadata.data, params.metadata.data + params.metadata.size); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 763 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 764 | mIncrementalManager->newFileForDataLoader(ifs->mountId, id, metadataBytes); |
| 765 | return 0; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 766 | } |
| 767 | return -EINVAL; |
| 768 | } |
| 769 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 770 | int IncrementalService::makeDir(StorageId storageId, std::string_view path, int mode) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 771 | if (auto ifs = getIfs(storageId)) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 772 | return mIncFs->makeDir(ifs->control, path, mode); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 773 | } |
| 774 | return -EINVAL; |
| 775 | } |
| 776 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 777 | int IncrementalService::makeDirs(StorageId storageId, std::string_view path, int mode) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 778 | const auto ifs = getIfs(storageId); |
| 779 | if (!ifs) { |
| 780 | return -EINVAL; |
| 781 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 782 | |
| 783 | auto err = mIncFs->makeDir(ifs->control, path, mode); |
| 784 | if (err == -EEXIST) { |
| 785 | return 0; |
| 786 | } else if (err != -ENOENT) { |
| 787 | return err; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 788 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 789 | if (auto err = makeDirs(storageId, path::dirname(path), mode)) { |
| 790 | return err; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 791 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 792 | return mIncFs->makeDir(ifs->control, path, mode); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 795 | int IncrementalService::link(StorageId sourceStorageId, std::string_view oldPath, |
| 796 | StorageId destStorageId, std::string_view newPath) { |
| 797 | if (auto ifsSrc = getIfs(sourceStorageId), ifsDest = getIfs(destStorageId); |
| 798 | ifsSrc && ifsSrc == ifsDest) { |
| 799 | return mIncFs->link(ifsSrc->control, oldPath, newPath); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 800 | } |
| 801 | return -EINVAL; |
| 802 | } |
| 803 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 804 | int IncrementalService::unlink(StorageId storage, std::string_view path) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 805 | if (auto ifs = getIfs(storage)) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 806 | return mIncFs->unlink(ifs->control, path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 807 | } |
| 808 | return -EINVAL; |
| 809 | } |
| 810 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 811 | int IncrementalService::addBindMount(IncFsMount& ifs, StorageId storage, |
| 812 | std::string_view storageRoot, std::string&& source, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 813 | std::string&& target, BindKind kind, |
| 814 | std::unique_lock<std::mutex>& mainLock) { |
| 815 | if (!isValidMountTarget(target)) { |
| 816 | return -EINVAL; |
| 817 | } |
| 818 | |
| 819 | std::string mdFileName; |
| 820 | if (kind != BindKind::Temporary) { |
| 821 | metadata::BindPoint bp; |
| 822 | bp.set_storage_id(storage); |
| 823 | bp.set_allocated_dest_path(&target); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 824 | bp.set_source_subdir(std::string(path::relativize(storageRoot, source))); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 825 | const auto metadata = bp.SerializeAsString(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 826 | bp.release_dest_path(); |
| 827 | mdFileName = makeBindMdName(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 828 | auto node = |
| 829 | mIncFs->makeFile(ifs.control, path::join(ifs.root, constants().mount, mdFileName), |
| 830 | 0444, idFromMetadata(metadata), |
| 831 | {.metadata = {metadata.data(), (IncFsSize)metadata.size()}}); |
| 832 | if (node) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 833 | return int(node); |
| 834 | } |
| 835 | } |
| 836 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 837 | return addBindMountWithMd(ifs, storage, std::move(mdFileName), std::move(source), |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 838 | std::move(target), kind, mainLock); |
| 839 | } |
| 840 | |
| 841 | int IncrementalService::addBindMountWithMd(IncrementalService::IncFsMount& ifs, StorageId storage, |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 842 | std::string&& metadataName, std::string&& source, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 843 | std::string&& target, BindKind kind, |
| 844 | std::unique_lock<std::mutex>& mainLock) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 845 | { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 846 | std::lock_guard l(mMountOperationLock); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 847 | const auto status = mVold->bindMount(source, target); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 848 | if (!status.isOk()) { |
| 849 | LOG(ERROR) << "Calling Vold::bindMount() failed: " << status.toString8(); |
| 850 | return status.exceptionCode() == binder::Status::EX_SERVICE_SPECIFIC |
| 851 | ? status.serviceSpecificErrorCode() > 0 ? -status.serviceSpecificErrorCode() |
| 852 | : status.serviceSpecificErrorCode() == 0 |
| 853 | ? -EFAULT |
| 854 | : status.serviceSpecificErrorCode() |
| 855 | : -EIO; |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | if (!mainLock.owns_lock()) { |
| 860 | mainLock.lock(); |
| 861 | } |
| 862 | std::lock_guard l(ifs.lock); |
| 863 | const auto [it, _] = |
| 864 | ifs.bindPoints.insert_or_assign(target, |
| 865 | IncFsMount::Bind{storage, std::move(metadataName), |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 866 | std::move(source), kind}); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 867 | mBindsByPath[std::move(target)] = it; |
| 868 | return 0; |
| 869 | } |
| 870 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 871 | RawMetadata IncrementalService::getMetadata(StorageId storage, FileId node) const { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 872 | const auto ifs = getIfs(storage); |
| 873 | if (!ifs) { |
| 874 | return {}; |
| 875 | } |
| 876 | return mIncFs->getMetadata(ifs->control, node); |
| 877 | } |
| 878 | |
| 879 | std::vector<std::string> IncrementalService::listFiles(StorageId storage) const { |
| 880 | const auto ifs = getIfs(storage); |
| 881 | if (!ifs) { |
| 882 | return {}; |
| 883 | } |
| 884 | |
| 885 | std::unique_lock l(ifs->lock); |
| 886 | auto subdirIt = ifs->storages.find(storage); |
| 887 | if (subdirIt == ifs->storages.end()) { |
| 888 | return {}; |
| 889 | } |
| 890 | auto dir = path::join(ifs->root, constants().mount, subdirIt->second.name); |
| 891 | l.unlock(); |
| 892 | |
| 893 | const auto prefixSize = dir.size() + 1; |
| 894 | std::vector<std::string> todoDirs{std::move(dir)}; |
| 895 | std::vector<std::string> result; |
| 896 | do { |
| 897 | auto currDir = std::move(todoDirs.back()); |
| 898 | todoDirs.pop_back(); |
| 899 | |
| 900 | auto d = |
| 901 | std::unique_ptr<DIR, decltype(&::closedir)>(::opendir(currDir.c_str()), ::closedir); |
| 902 | while (auto e = ::readdir(d.get())) { |
| 903 | if (e->d_type == DT_REG) { |
| 904 | result.emplace_back( |
| 905 | path::join(std::string_view(currDir).substr(prefixSize), e->d_name)); |
| 906 | continue; |
| 907 | } |
| 908 | if (e->d_type == DT_DIR) { |
| 909 | if (e->d_name == "."sv || e->d_name == ".."sv) { |
| 910 | continue; |
| 911 | } |
| 912 | todoDirs.emplace_back(path::join(currDir, e->d_name)); |
| 913 | continue; |
| 914 | } |
| 915 | } |
| 916 | } while (!todoDirs.empty()); |
| 917 | return result; |
| 918 | } |
| 919 | |
| 920 | bool IncrementalService::startLoading(StorageId storage) const { |
| 921 | const auto ifs = getIfs(storage); |
| 922 | if (!ifs) { |
| 923 | return false; |
| 924 | } |
| 925 | bool started = false; |
| 926 | std::unique_lock l(ifs->lock); |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 927 | if (ifs->dataLoaderStatus != IDataLoaderStatusListener::DATA_LOADER_CREATED) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 928 | if (ifs->dataLoaderReady.wait_for(l, Seconds(5)) == std::cv_status::timeout) { |
| 929 | LOG(ERROR) << "Timeout waiting for data loader to be ready"; |
| 930 | return false; |
| 931 | } |
| 932 | } |
| 933 | auto status = mIncrementalManager->startDataLoader(ifs->mountId, &started); |
| 934 | if (!status.isOk()) { |
| 935 | return false; |
| 936 | } |
| 937 | return started; |
| 938 | } |
| 939 | |
| 940 | void IncrementalService::mountExistingImages() { |
| 941 | auto d = std::unique_ptr<DIR, decltype(&::closedir)>(::opendir(mIncrementalDir.c_str()), |
| 942 | ::closedir); |
| 943 | while (auto e = ::readdir(d.get())) { |
| 944 | if (e->d_type != DT_DIR) { |
| 945 | continue; |
| 946 | } |
| 947 | if (e->d_name == "."sv || e->d_name == ".."sv) { |
| 948 | continue; |
| 949 | } |
| 950 | auto root = path::join(mIncrementalDir, e->d_name); |
| 951 | if (!mountExistingImage(root, e->d_name)) { |
| 952 | IncFsMount::cleanupFilesystem(root); |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | bool IncrementalService::mountExistingImage(std::string_view root, std::string_view key) { |
| 958 | LOG(INFO) << "Trying to mount: " << key; |
| 959 | |
| 960 | auto mountTarget = path::join(root, constants().mount); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 961 | const auto backing = path::join(root, constants().backing); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 962 | |
| 963 | IncFsMount::Control control; |
| 964 | IncrementalFileSystemControlParcel controlParcel; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 965 | auto status = mVold->mountIncFs(backing, mountTarget, 0, &controlParcel); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 966 | if (!status.isOk()) { |
| 967 | LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8(); |
| 968 | return false; |
| 969 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 970 | control.cmd = controlParcel.cmd.release().release(); |
| 971 | control.pendingReads = controlParcel.pendingReads.release().release(); |
| 972 | control.logs = controlParcel.log.release().release(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 973 | |
| 974 | auto ifs = std::make_shared<IncFsMount>(std::string(root), -1, std::move(control), *this); |
| 975 | |
| 976 | auto m = parseFromIncfs<metadata::Mount>(mIncFs.get(), ifs->control, |
| 977 | path::join(mountTarget, constants().infoMdName)); |
| 978 | if (!m.has_loader() || !m.has_storage()) { |
| 979 | LOG(ERROR) << "Bad mount metadata in mount at " << root; |
| 980 | return false; |
| 981 | } |
| 982 | |
| 983 | ifs->mountId = m.storage().id(); |
| 984 | mNextId = std::max(mNextId, ifs->mountId + 1); |
| 985 | |
| 986 | std::vector<std::pair<std::string, metadata::BindPoint>> bindPoints; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 987 | auto d = openDir(path::c_str(mountTarget)); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 988 | while (auto e = ::readdir(d.get())) { |
| 989 | if (e->d_type == DT_REG) { |
| 990 | auto name = std::string_view(e->d_name); |
| 991 | if (name.starts_with(constants().mountpointMdPrefix)) { |
| 992 | bindPoints.emplace_back(name, |
| 993 | parseFromIncfs<metadata::BindPoint>(mIncFs.get(), |
| 994 | ifs->control, |
| 995 | path::join(mountTarget, |
| 996 | name))); |
| 997 | if (bindPoints.back().second.dest_path().empty() || |
| 998 | bindPoints.back().second.source_subdir().empty()) { |
| 999 | bindPoints.pop_back(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 1000 | mIncFs->unlink(ifs->control, path::join(ifs->root, constants().mount, name)); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | } else if (e->d_type == DT_DIR) { |
| 1004 | if (e->d_name == "."sv || e->d_name == ".."sv) { |
| 1005 | continue; |
| 1006 | } |
| 1007 | auto name = std::string_view(e->d_name); |
| 1008 | if (name.starts_with(constants().storagePrefix)) { |
| 1009 | auto md = parseFromIncfs<metadata::Storage>(mIncFs.get(), ifs->control, |
| 1010 | path::join(mountTarget, name)); |
| 1011 | auto [_, inserted] = mMounts.try_emplace(md.id(), ifs); |
| 1012 | if (!inserted) { |
| 1013 | LOG(WARNING) << "Ignoring storage with duplicate id " << md.id() |
| 1014 | << " for mount " << root; |
| 1015 | continue; |
| 1016 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 1017 | ifs->storages.insert_or_assign(md.id(), IncFsMount::Storage{std::string(name)}); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1018 | mNextId = std::max(mNextId, md.id() + 1); |
| 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | if (ifs->storages.empty()) { |
| 1024 | LOG(WARNING) << "No valid storages in mount " << root; |
| 1025 | return false; |
| 1026 | } |
| 1027 | |
| 1028 | int bindCount = 0; |
| 1029 | for (auto&& bp : bindPoints) { |
| 1030 | std::unique_lock l(mLock, std::defer_lock); |
| 1031 | bindCount += !addBindMountWithMd(*ifs, bp.second.storage_id(), std::move(bp.first), |
| 1032 | std::move(*bp.second.mutable_source_subdir()), |
| 1033 | std::move(*bp.second.mutable_dest_path()), |
| 1034 | BindKind::Permanent, l); |
| 1035 | } |
| 1036 | |
| 1037 | if (bindCount == 0) { |
| 1038 | LOG(WARNING) << "No valid bind points for mount " << root; |
| 1039 | deleteStorage(*ifs); |
| 1040 | return false; |
| 1041 | } |
| 1042 | |
| 1043 | DataLoaderParamsParcel dlParams; |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 1044 | dlParams.type = (DataLoaderType)m.loader().type(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1045 | dlParams.packageName = std::move(*m.mutable_loader()->mutable_package_name()); |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 1046 | dlParams.className = std::move(*m.mutable_loader()->mutable_class_name()); |
| 1047 | dlParams.arguments = std::move(*m.mutable_loader()->mutable_arguments()); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1048 | if (!prepareDataLoader(*ifs, &dlParams)) { |
| 1049 | deleteStorage(*ifs); |
| 1050 | return false; |
| 1051 | } |
| 1052 | |
| 1053 | mMounts[ifs->mountId] = std::move(ifs); |
| 1054 | return true; |
| 1055 | } |
| 1056 | |
| 1057 | bool IncrementalService::prepareDataLoader(IncrementalService::IncFsMount& ifs, |
| 1058 | DataLoaderParamsParcel* params) { |
| 1059 | if (!mSystemReady.load(std::memory_order_relaxed)) { |
| 1060 | std::unique_lock l(ifs.lock); |
| 1061 | if (params) { |
| 1062 | if (ifs.savedDataLoaderParams) { |
| 1063 | LOG(WARNING) << "Trying to pass second set of data loader parameters, ignored it"; |
| 1064 | } else { |
| 1065 | ifs.savedDataLoaderParams = std::move(*params); |
| 1066 | } |
| 1067 | } else { |
| 1068 | if (!ifs.savedDataLoaderParams) { |
| 1069 | LOG(ERROR) << "Mount " << ifs.mountId |
| 1070 | << " is broken: no data loader params (system is not ready yet)"; |
| 1071 | return false; |
| 1072 | } |
| 1073 | } |
| 1074 | return true; // eventually... |
| 1075 | } |
| 1076 | if (base::GetBoolProperty("incremental.skip_loader", false)) { |
| 1077 | LOG(INFO) << "Skipped data loader because of incremental.skip_loader property"; |
| 1078 | std::unique_lock l(ifs.lock); |
| 1079 | ifs.savedDataLoaderParams.reset(); |
| 1080 | return true; |
| 1081 | } |
| 1082 | |
| 1083 | std::unique_lock l(ifs.lock); |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 1084 | if (ifs.dataLoaderStatus == IDataLoaderStatusListener::DATA_LOADER_CREATED) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1085 | LOG(INFO) << "Skipped data loader preparation because it already exists"; |
| 1086 | return true; |
| 1087 | } |
| 1088 | |
| 1089 | auto* dlp = params ? params |
| 1090 | : ifs.savedDataLoaderParams ? &ifs.savedDataLoaderParams.value() : nullptr; |
| 1091 | if (!dlp) { |
| 1092 | LOG(ERROR) << "Mount " << ifs.mountId << " is broken: no data loader params"; |
| 1093 | return false; |
| 1094 | } |
| 1095 | FileSystemControlParcel fsControlParcel; |
| 1096 | fsControlParcel.incremental = std::make_unique<IncrementalFileSystemControlParcel>(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 1097 | fsControlParcel.incremental->cmd.reset(base::unique_fd(::dup(ifs.control.cmd))); |
| 1098 | fsControlParcel.incremental->pendingReads.reset( |
| 1099 | base::unique_fd(::dup(ifs.control.pendingReads))); |
| 1100 | fsControlParcel.incremental->log.reset(base::unique_fd(::dup(ifs.control.logs))); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1101 | sp<IncrementalDataLoaderListener> listener = new IncrementalDataLoaderListener(*this); |
| 1102 | bool created = false; |
| 1103 | auto status = mIncrementalManager->prepareDataLoader(ifs.mountId, fsControlParcel, *dlp, |
| 1104 | listener, &created); |
| 1105 | if (!status.isOk() || !created) { |
| 1106 | LOG(ERROR) << "Failed to create a data loader for mount " << ifs.mountId; |
| 1107 | return false; |
| 1108 | } |
| 1109 | ifs.savedDataLoaderParams.reset(); |
| 1110 | return true; |
| 1111 | } |
| 1112 | |
| 1113 | binder::Status IncrementalService::IncrementalDataLoaderListener::onStatusChanged(MountId mountId, |
| 1114 | int newStatus) { |
| 1115 | std::unique_lock l(incrementalService.mLock); |
| 1116 | const auto& ifs = incrementalService.getIfsLocked(mountId); |
| 1117 | if (!ifs) { |
| 1118 | LOG(WARNING) << "Received data loader status " << int(newStatus) << " for unknown mount " |
| 1119 | << mountId; |
| 1120 | return binder::Status::ok(); |
| 1121 | } |
| 1122 | ifs->dataLoaderStatus = newStatus; |
| 1123 | switch (newStatus) { |
| 1124 | case IDataLoaderStatusListener::DATA_LOADER_NO_CONNECTION: { |
| 1125 | auto now = Clock::now(); |
| 1126 | if (ifs->connectionLostTime.time_since_epoch().count() == 0) { |
| 1127 | ifs->connectionLostTime = now; |
| 1128 | break; |
| 1129 | } |
| 1130 | auto duration = |
| 1131 | std::chrono::duration_cast<Seconds>(now - ifs->connectionLostTime).count(); |
| 1132 | if (duration >= 10) { |
| 1133 | incrementalService.mIncrementalManager->showHealthBlockedUI(mountId); |
| 1134 | } |
| 1135 | break; |
| 1136 | } |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 1137 | case IDataLoaderStatusListener::DATA_LOADER_CONNECTION_OK: { |
| 1138 | ifs->dataLoaderStatus = IDataLoaderStatusListener::DATA_LOADER_STARTED; |
| 1139 | break; |
| 1140 | } |
| 1141 | case IDataLoaderStatusListener::DATA_LOADER_CREATED: { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1142 | ifs->dataLoaderReady.notify_one(); |
| 1143 | break; |
| 1144 | } |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 1145 | case IDataLoaderStatusListener::DATA_LOADER_DESTROYED: { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1146 | ifs->dataLoaderStatus = IDataLoaderStatusListener::DATA_LOADER_STOPPED; |
| 1147 | incrementalService.deleteStorageLocked(*ifs, std::move(l)); |
| 1148 | break; |
| 1149 | } |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 1150 | case IDataLoaderStatusListener::DATA_LOADER_STARTED: { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1151 | break; |
| 1152 | } |
| 1153 | case IDataLoaderStatusListener::DATA_LOADER_STOPPED: { |
| 1154 | break; |
| 1155 | } |
| 1156 | default: { |
| 1157 | LOG(WARNING) << "Unknown data loader status: " << newStatus |
| 1158 | << " for mount: " << mountId; |
| 1159 | break; |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | return binder::Status::ok(); |
| 1164 | } |
| 1165 | |
| 1166 | } // namespace android::incremental |