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" |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 20 | #include "IncrementalServiceValidation.h" |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 21 | |
| 22 | #include <android-base/file.h> |
| 23 | #include <android-base/logging.h> |
| 24 | #include <android-base/properties.h> |
| 25 | #include <android-base/stringprintf.h> |
| 26 | #include <android-base/strings.h> |
| 27 | #include <android/content/pm/IDataLoaderStatusListener.h> |
| 28 | #include <android/os/IVold.h> |
| 29 | #include <androidfw/ZipFileRO.h> |
| 30 | #include <androidfw/ZipUtils.h> |
| 31 | #include <binder/BinderService.h> |
Jooyung Han | 66c567a | 2020-03-07 21:47:09 +0900 | [diff] [blame] | 32 | #include <binder/Nullable.h> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 33 | #include <binder/ParcelFileDescriptor.h> |
| 34 | #include <binder/Status.h> |
| 35 | #include <sys/stat.h> |
| 36 | #include <uuid/uuid.h> |
| 37 | #include <zlib.h> |
| 38 | |
Yurii Zubrytskyi | 107ae35 | 2020-04-03 13:12:51 -0700 | [diff] [blame] | 39 | #include <charconv> |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame] | 40 | #include <ctime> |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 41 | #include <filesystem> |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 42 | #include <iterator> |
| 43 | #include <span> |
| 44 | #include <stack> |
| 45 | #include <thread> |
| 46 | #include <type_traits> |
| 47 | |
| 48 | #include "Metadata.pb.h" |
| 49 | |
| 50 | using namespace std::literals; |
| 51 | using namespace android::content::pm; |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 52 | namespace fs = std::filesystem; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 53 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 54 | constexpr const char* kDataUsageStats = "android.permission.LOADER_USAGE_STATS"; |
| 55 | constexpr const char* kOpUsage = "android:get_usage_stats"; |
| 56 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 57 | namespace android::incremental { |
| 58 | |
| 59 | namespace { |
| 60 | |
| 61 | using IncrementalFileSystemControlParcel = |
| 62 | ::android::os::incremental::IncrementalFileSystemControlParcel; |
| 63 | |
| 64 | struct Constants { |
| 65 | static constexpr auto backing = "backing_store"sv; |
| 66 | static constexpr auto mount = "mount"sv; |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 67 | static constexpr auto mountKeyPrefix = "MT_"sv; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 68 | static constexpr auto storagePrefix = "st"sv; |
| 69 | static constexpr auto mountpointMdPrefix = ".mountpoint."sv; |
| 70 | static constexpr auto infoMdName = ".info"sv; |
Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 71 | static constexpr auto libDir = "lib"sv; |
| 72 | static constexpr auto libSuffix = ".so"sv; |
| 73 | static constexpr auto blockSize = 4096; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | static const Constants& constants() { |
| 77 | static Constants c; |
| 78 | return c; |
| 79 | } |
| 80 | |
| 81 | template <base::LogSeverity level = base::ERROR> |
| 82 | bool mkdirOrLog(std::string_view name, int mode = 0770, bool allowExisting = true) { |
| 83 | auto cstr = path::c_str(name); |
| 84 | if (::mkdir(cstr, mode)) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 85 | if (!allowExisting || errno != EEXIST) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 86 | PLOG(level) << "Can't create directory '" << name << '\''; |
| 87 | return false; |
| 88 | } |
| 89 | struct stat st; |
| 90 | if (::stat(cstr, &st) || !S_ISDIR(st.st_mode)) { |
| 91 | PLOG(level) << "Path exists but is not a directory: '" << name << '\''; |
| 92 | return false; |
| 93 | } |
| 94 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 95 | if (::chmod(cstr, mode)) { |
| 96 | PLOG(level) << "Changing permission failed for '" << name << '\''; |
| 97 | return false; |
| 98 | } |
| 99 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 100 | return true; |
| 101 | } |
| 102 | |
| 103 | static std::string toMountKey(std::string_view path) { |
| 104 | if (path.empty()) { |
| 105 | return "@none"; |
| 106 | } |
| 107 | if (path == "/"sv) { |
| 108 | return "@root"; |
| 109 | } |
| 110 | if (path::isAbsolute(path)) { |
| 111 | path.remove_prefix(1); |
| 112 | } |
| 113 | std::string res(path); |
| 114 | std::replace(res.begin(), res.end(), '/', '_'); |
| 115 | std::replace(res.begin(), res.end(), '@', '_'); |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 116 | return std::string(constants().mountKeyPrefix) + res; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static std::pair<std::string, std::string> makeMountDir(std::string_view incrementalDir, |
| 120 | std::string_view path) { |
| 121 | auto mountKey = toMountKey(path); |
| 122 | const auto prefixSize = mountKey.size(); |
| 123 | for (int counter = 0; counter < 1000; |
| 124 | mountKey.resize(prefixSize), base::StringAppendF(&mountKey, "%d", counter++)) { |
| 125 | auto mountRoot = path::join(incrementalDir, mountKey); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 126 | if (mkdirOrLog(mountRoot, 0777, false)) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 127 | return {mountKey, mountRoot}; |
| 128 | } |
| 129 | } |
| 130 | return {}; |
| 131 | } |
| 132 | |
| 133 | template <class ProtoMessage, class Control> |
| 134 | static ProtoMessage parseFromIncfs(const IncFsWrapper* incfs, Control&& control, |
| 135 | std::string_view path) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 136 | auto md = incfs->getMetadata(control, path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 137 | ProtoMessage message; |
| 138 | return message.ParseFromArray(md.data(), md.size()) ? message : ProtoMessage{}; |
| 139 | } |
| 140 | |
| 141 | static bool isValidMountTarget(std::string_view path) { |
| 142 | return path::isAbsolute(path) && path::isEmptyDir(path).value_or(true); |
| 143 | } |
| 144 | |
| 145 | std::string makeBindMdName() { |
| 146 | static constexpr auto uuidStringSize = 36; |
| 147 | |
| 148 | uuid_t guid; |
| 149 | uuid_generate(guid); |
| 150 | |
| 151 | std::string name; |
| 152 | const auto prefixSize = constants().mountpointMdPrefix.size(); |
| 153 | name.reserve(prefixSize + uuidStringSize); |
| 154 | |
| 155 | name = constants().mountpointMdPrefix; |
| 156 | name.resize(prefixSize + uuidStringSize); |
| 157 | uuid_unparse(guid, name.data() + prefixSize); |
| 158 | |
| 159 | return name; |
| 160 | } |
| 161 | } // namespace |
| 162 | |
| 163 | IncrementalService::IncFsMount::~IncFsMount() { |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 164 | incrementalService.mDataLoaderManager->destroyDataLoader(mountId); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 165 | LOG(INFO) << "Unmounting and cleaning up mount " << mountId << " with root '" << root << '\''; |
| 166 | for (auto&& [target, _] : bindPoints) { |
| 167 | LOG(INFO) << "\tbind: " << target; |
| 168 | incrementalService.mVold->unmountIncFs(target); |
| 169 | } |
| 170 | LOG(INFO) << "\troot: " << root; |
| 171 | incrementalService.mVold->unmountIncFs(path::join(root, constants().mount)); |
| 172 | cleanupFilesystem(root); |
| 173 | } |
| 174 | |
| 175 | auto IncrementalService::IncFsMount::makeStorage(StorageId id) -> StorageMap::iterator { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 176 | std::string name; |
| 177 | for (int no = nextStorageDirNo.fetch_add(1, std::memory_order_relaxed), i = 0; |
| 178 | i < 1024 && no >= 0; no = nextStorageDirNo.fetch_add(1, std::memory_order_relaxed), ++i) { |
| 179 | name.clear(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 180 | base::StringAppendF(&name, "%.*s_%d_%d", int(constants().storagePrefix.size()), |
| 181 | constants().storagePrefix.data(), id, no); |
| 182 | auto fullName = path::join(root, constants().mount, name); |
Songchun Fan | 9610093 | 2020-02-03 19:20:58 -0800 | [diff] [blame] | 183 | if (auto err = incrementalService.mIncFs->makeDir(control, fullName, 0755); !err) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 184 | std::lock_guard l(lock); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 185 | return storages.insert_or_assign(id, Storage{std::move(fullName)}).first; |
| 186 | } else if (err != EEXIST) { |
| 187 | LOG(ERROR) << __func__ << "(): failed to create dir |" << fullName << "| " << err; |
| 188 | break; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | nextStorageDirNo = 0; |
| 192 | return storages.end(); |
| 193 | } |
| 194 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 195 | static std::unique_ptr<DIR, decltype(&::closedir)> openDir(const char* path) { |
| 196 | return {::opendir(path), ::closedir}; |
| 197 | } |
| 198 | |
| 199 | static int rmDirContent(const char* path) { |
| 200 | auto dir = openDir(path); |
| 201 | if (!dir) { |
| 202 | return -EINVAL; |
| 203 | } |
| 204 | while (auto entry = ::readdir(dir.get())) { |
| 205 | if (entry->d_name == "."sv || entry->d_name == ".."sv) { |
| 206 | continue; |
| 207 | } |
| 208 | auto fullPath = android::base::StringPrintf("%s/%s", path, entry->d_name); |
| 209 | if (entry->d_type == DT_DIR) { |
| 210 | if (const auto err = rmDirContent(fullPath.c_str()); err != 0) { |
| 211 | PLOG(WARNING) << "Failed to delete " << fullPath << " content"; |
| 212 | return err; |
| 213 | } |
| 214 | if (const auto err = ::rmdir(fullPath.c_str()); err != 0) { |
| 215 | PLOG(WARNING) << "Failed to rmdir " << fullPath; |
| 216 | return err; |
| 217 | } |
| 218 | } else { |
| 219 | if (const auto err = ::unlink(fullPath.c_str()); err != 0) { |
| 220 | PLOG(WARNING) << "Failed to delete " << fullPath; |
| 221 | return err; |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | return 0; |
| 226 | } |
| 227 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 228 | void IncrementalService::IncFsMount::cleanupFilesystem(std::string_view root) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 229 | rmDirContent(path::join(root, constants().backing).c_str()); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 230 | ::rmdir(path::join(root, constants().backing).c_str()); |
| 231 | ::rmdir(path::join(root, constants().mount).c_str()); |
| 232 | ::rmdir(path::c_str(root)); |
| 233 | } |
| 234 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 235 | IncrementalService::IncrementalService(ServiceManagerWrapper&& sm, std::string_view rootDir) |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 236 | : mVold(sm.getVoldService()), |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 237 | mDataLoaderManager(sm.getDataLoaderManager()), |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 238 | mIncFs(sm.getIncFs()), |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 239 | mAppOpsManager(sm.getAppOpsManager()), |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 240 | mIncrementalDir(rootDir) { |
| 241 | if (!mVold) { |
| 242 | LOG(FATAL) << "Vold service is unavailable"; |
| 243 | } |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 244 | if (!mDataLoaderManager) { |
| 245 | LOG(FATAL) << "DataLoaderManagerService is unavailable"; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 246 | } |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 247 | if (!mAppOpsManager) { |
| 248 | LOG(FATAL) << "AppOpsManager is unavailable"; |
| 249 | } |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 250 | mountExistingImages(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 253 | FileId IncrementalService::idFromMetadata(std::span<const uint8_t> metadata) { |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 254 | return IncFs_FileIdFromMetadata({(const char*)metadata.data(), metadata.size()}); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 257 | IncrementalService::~IncrementalService() = default; |
| 258 | |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame] | 259 | inline const char* toString(TimePoint t) { |
| 260 | using SystemClock = std::chrono::system_clock; |
Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 261 | time_t time = SystemClock::to_time_t( |
| 262 | SystemClock::now() + |
| 263 | std::chrono::duration_cast<SystemClock::duration>(t - Clock::now())); |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame] | 264 | return std::ctime(&time); |
| 265 | } |
| 266 | |
| 267 | inline const char* toString(IncrementalService::BindKind kind) { |
| 268 | switch (kind) { |
Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 269 | case IncrementalService::BindKind::Temporary: |
| 270 | return "Temporary"; |
| 271 | case IncrementalService::BindKind::Permanent: |
| 272 | return "Permanent"; |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | |
| 276 | void IncrementalService::onDump(int fd) { |
| 277 | dprintf(fd, "Incremental is %s\n", incfs::enabled() ? "ENABLED" : "DISABLED"); |
| 278 | dprintf(fd, "Incremental dir: %s\n", mIncrementalDir.c_str()); |
| 279 | |
| 280 | std::unique_lock l(mLock); |
| 281 | |
| 282 | dprintf(fd, "Mounts (%d):\n", int(mMounts.size())); |
| 283 | for (auto&& [id, ifs] : mMounts) { |
| 284 | const IncFsMount& mnt = *ifs.get(); |
| 285 | dprintf(fd, "\t[%d]:\n", id); |
| 286 | dprintf(fd, "\t\tmountId: %d\n", mnt.mountId); |
Yurii Zubrytskyi | 107ae35 | 2020-04-03 13:12:51 -0700 | [diff] [blame] | 287 | dprintf(fd, "\t\troot: %s\n", mnt.root.c_str()); |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame] | 288 | dprintf(fd, "\t\tnextStorageDirNo: %d\n", mnt.nextStorageDirNo.load()); |
| 289 | dprintf(fd, "\t\tdataLoaderStatus: %d\n", mnt.dataLoaderStatus.load()); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 290 | { |
| 291 | const auto& params = mnt.dataLoaderParams; |
| 292 | dprintf(fd, "\t\tdataLoaderParams:\n"); |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame] | 293 | dprintf(fd, "\t\t\ttype: %s\n", toString(params.type).c_str()); |
| 294 | dprintf(fd, "\t\t\tpackageName: %s\n", params.packageName.c_str()); |
| 295 | dprintf(fd, "\t\t\tclassName: %s\n", params.className.c_str()); |
| 296 | dprintf(fd, "\t\t\targuments: %s\n", params.arguments.c_str()); |
Alex Buynytskyy | 18b07a4 | 2020-02-03 20:06:00 -0800 | [diff] [blame] | 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)]() { |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 340 | /* TODO(b/151241369): restore data loaders on reboot. |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 341 | for (auto&& ifs : mounts) { |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 342 | if (prepareDataLoader(*ifs)) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 343 | LOG(INFO) << "Successfully started data loader for mount " << ifs->mountId; |
| 344 | } else { |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 345 | // TODO(b/133435829): handle data loader start failures |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 346 | LOG(WARNING) << "Failed to start data loader for mount " << ifs->mountId; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 347 | } |
| 348 | } |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 349 | */ |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 350 | mPrepareDataLoaders.set_value_at_thread_exit(); |
| 351 | }).detach(); |
| 352 | return mPrepareDataLoaders.get_future(); |
| 353 | } |
| 354 | |
| 355 | auto IncrementalService::getStorageSlotLocked() -> MountMap::iterator { |
| 356 | for (;;) { |
| 357 | if (mNextId == kMaxStorageId) { |
| 358 | mNextId = 0; |
| 359 | } |
| 360 | auto id = ++mNextId; |
| 361 | auto [it, inserted] = mMounts.try_emplace(id, nullptr); |
| 362 | if (inserted) { |
| 363 | return it; |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 368 | StorageId IncrementalService::createStorage( |
| 369 | std::string_view mountPoint, DataLoaderParamsParcel&& dataLoaderParams, |
| 370 | const DataLoaderStatusListener& dataLoaderStatusListener, CreateOptions options) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 371 | LOG(INFO) << "createStorage: " << mountPoint << " | " << int(options); |
| 372 | if (!path::isAbsolute(mountPoint)) { |
| 373 | LOG(ERROR) << "path is not absolute: " << mountPoint; |
| 374 | return kInvalidStorageId; |
| 375 | } |
| 376 | |
| 377 | auto mountNorm = path::normalize(mountPoint); |
| 378 | { |
| 379 | const auto id = findStorageId(mountNorm); |
| 380 | if (id != kInvalidStorageId) { |
| 381 | if (options & CreateOptions::OpenExisting) { |
| 382 | LOG(INFO) << "Opened existing storage " << id; |
| 383 | return id; |
| 384 | } |
| 385 | LOG(ERROR) << "Directory " << mountPoint << " is already mounted at storage " << id; |
| 386 | return kInvalidStorageId; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | if (!(options & CreateOptions::CreateNew)) { |
| 391 | LOG(ERROR) << "not requirested create new storage, and it doesn't exist: " << mountPoint; |
| 392 | return kInvalidStorageId; |
| 393 | } |
| 394 | |
| 395 | if (!path::isEmptyDir(mountNorm)) { |
| 396 | LOG(ERROR) << "Mounting over existing non-empty directory is not supported: " << mountNorm; |
| 397 | return kInvalidStorageId; |
| 398 | } |
| 399 | auto [mountKey, mountRoot] = makeMountDir(mIncrementalDir, mountNorm); |
| 400 | if (mountRoot.empty()) { |
| 401 | LOG(ERROR) << "Bad mount point"; |
| 402 | return kInvalidStorageId; |
| 403 | } |
| 404 | // Make sure the code removes all crap it may create while still failing. |
| 405 | auto firstCleanup = [](const std::string* ptr) { IncFsMount::cleanupFilesystem(*ptr); }; |
| 406 | auto firstCleanupOnFailure = |
| 407 | std::unique_ptr<std::string, decltype(firstCleanup)>(&mountRoot, firstCleanup); |
| 408 | |
| 409 | auto mountTarget = path::join(mountRoot, constants().mount); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 410 | const auto backing = path::join(mountRoot, constants().backing); |
| 411 | if (!mkdirOrLog(backing, 0777) || !mkdirOrLog(mountTarget)) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 412 | return kInvalidStorageId; |
| 413 | } |
| 414 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 415 | IncFsMount::Control control; |
| 416 | { |
| 417 | std::lock_guard l(mMountOperationLock); |
| 418 | IncrementalFileSystemControlParcel controlParcel; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 419 | |
| 420 | if (auto err = rmDirContent(backing.c_str())) { |
| 421 | LOG(ERROR) << "Coudn't clean the backing directory " << backing << ": " << err; |
| 422 | return kInvalidStorageId; |
| 423 | } |
| 424 | if (!mkdirOrLog(path::join(backing, ".index"), 0777)) { |
| 425 | return kInvalidStorageId; |
| 426 | } |
| 427 | auto status = mVold->mountIncFs(backing, mountTarget, 0, &controlParcel); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 428 | if (!status.isOk()) { |
| 429 | LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8(); |
| 430 | return kInvalidStorageId; |
| 431 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 432 | if (controlParcel.cmd.get() < 0 || controlParcel.pendingReads.get() < 0 || |
| 433 | controlParcel.log.get() < 0) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 434 | LOG(ERROR) << "Vold::mountIncFs() returned invalid control parcel."; |
| 435 | return kInvalidStorageId; |
| 436 | } |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 437 | int cmd = controlParcel.cmd.release().release(); |
| 438 | int pendingReads = controlParcel.pendingReads.release().release(); |
| 439 | int logs = controlParcel.log.release().release(); |
| 440 | control = mIncFs->createControl(cmd, pendingReads, logs); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | std::unique_lock l(mLock); |
| 444 | const auto mountIt = getStorageSlotLocked(); |
| 445 | const auto mountId = mountIt->first; |
| 446 | l.unlock(); |
| 447 | |
| 448 | auto ifs = |
| 449 | std::make_shared<IncFsMount>(std::move(mountRoot), mountId, std::move(control), *this); |
| 450 | // Now it's the |ifs|'s responsibility to clean up after itself, and the only cleanup we need |
| 451 | // is the removal of the |ifs|. |
| 452 | firstCleanupOnFailure.release(); |
| 453 | |
| 454 | auto secondCleanup = [this, &l](auto itPtr) { |
| 455 | if (!l.owns_lock()) { |
| 456 | l.lock(); |
| 457 | } |
| 458 | mMounts.erase(*itPtr); |
| 459 | }; |
| 460 | auto secondCleanupOnFailure = |
| 461 | std::unique_ptr<decltype(mountIt), decltype(secondCleanup)>(&mountIt, secondCleanup); |
| 462 | |
| 463 | const auto storageIt = ifs->makeStorage(ifs->mountId); |
| 464 | if (storageIt == ifs->storages.end()) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 465 | LOG(ERROR) << "Can't create a default storage directory"; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 466 | return kInvalidStorageId; |
| 467 | } |
| 468 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 469 | ifs->dataLoaderParams = std::move(dataLoaderParams); |
| 470 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 471 | { |
| 472 | metadata::Mount m; |
| 473 | m.mutable_storage()->set_id(ifs->mountId); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 474 | m.mutable_loader()->set_type((int)ifs->dataLoaderParams.type); |
| 475 | m.mutable_loader()->set_package_name(ifs->dataLoaderParams.packageName); |
| 476 | m.mutable_loader()->set_class_name(ifs->dataLoaderParams.className); |
| 477 | m.mutable_loader()->set_arguments(ifs->dataLoaderParams.arguments); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 478 | const auto metadata = m.SerializeAsString(); |
| 479 | m.mutable_loader()->release_arguments(); |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 480 | m.mutable_loader()->release_class_name(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 481 | m.mutable_loader()->release_package_name(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 482 | if (auto err = |
| 483 | mIncFs->makeFile(ifs->control, |
| 484 | path::join(ifs->root, constants().mount, |
| 485 | constants().infoMdName), |
| 486 | 0777, idFromMetadata(metadata), |
| 487 | {.metadata = {metadata.data(), (IncFsSize)metadata.size()}})) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 488 | LOG(ERROR) << "Saving mount metadata failed: " << -err; |
| 489 | return kInvalidStorageId; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | const auto bk = |
| 494 | (options & CreateOptions::PermanentBind) ? BindKind::Permanent : BindKind::Temporary; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 495 | if (auto err = addBindMount(*ifs, storageIt->first, storageIt->second.name, |
| 496 | std::string(storageIt->second.name), std::move(mountNorm), bk, l); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 497 | err < 0) { |
| 498 | LOG(ERROR) << "adding bind mount failed: " << -err; |
| 499 | return kInvalidStorageId; |
| 500 | } |
| 501 | |
| 502 | // Done here as well, all data structures are in good state. |
| 503 | secondCleanupOnFailure.release(); |
| 504 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 505 | if (!prepareDataLoader(*ifs, &dataLoaderStatusListener)) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 506 | LOG(ERROR) << "prepareDataLoader() failed"; |
| 507 | deleteStorageLocked(*ifs, std::move(l)); |
| 508 | return kInvalidStorageId; |
| 509 | } |
| 510 | |
| 511 | mountIt->second = std::move(ifs); |
| 512 | l.unlock(); |
| 513 | LOG(INFO) << "created storage " << mountId; |
| 514 | return mountId; |
| 515 | } |
| 516 | |
| 517 | StorageId IncrementalService::createLinkedStorage(std::string_view mountPoint, |
| 518 | StorageId linkedStorage, |
| 519 | IncrementalService::CreateOptions options) { |
| 520 | if (!isValidMountTarget(mountPoint)) { |
| 521 | LOG(ERROR) << "Mount point is invalid or missing"; |
| 522 | return kInvalidStorageId; |
| 523 | } |
| 524 | |
| 525 | std::unique_lock l(mLock); |
| 526 | const auto& ifs = getIfsLocked(linkedStorage); |
| 527 | if (!ifs) { |
| 528 | LOG(ERROR) << "Ifs unavailable"; |
| 529 | return kInvalidStorageId; |
| 530 | } |
| 531 | |
| 532 | const auto mountIt = getStorageSlotLocked(); |
| 533 | const auto storageId = mountIt->first; |
| 534 | const auto storageIt = ifs->makeStorage(storageId); |
| 535 | if (storageIt == ifs->storages.end()) { |
| 536 | LOG(ERROR) << "Can't create a new storage"; |
| 537 | mMounts.erase(mountIt); |
| 538 | return kInvalidStorageId; |
| 539 | } |
| 540 | |
| 541 | l.unlock(); |
| 542 | |
| 543 | const auto bk = |
| 544 | (options & CreateOptions::PermanentBind) ? BindKind::Permanent : BindKind::Temporary; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 545 | if (auto err = addBindMount(*ifs, storageIt->first, storageIt->second.name, |
| 546 | std::string(storageIt->second.name), path::normalize(mountPoint), |
| 547 | bk, l); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 548 | err < 0) { |
| 549 | LOG(ERROR) << "bindMount failed with error: " << err; |
| 550 | return kInvalidStorageId; |
| 551 | } |
| 552 | |
| 553 | mountIt->second = ifs; |
| 554 | return storageId; |
| 555 | } |
| 556 | |
| 557 | IncrementalService::BindPathMap::const_iterator IncrementalService::findStorageLocked( |
| 558 | std::string_view path) const { |
| 559 | auto bindPointIt = mBindsByPath.upper_bound(path); |
| 560 | if (bindPointIt == mBindsByPath.begin()) { |
| 561 | return mBindsByPath.end(); |
| 562 | } |
| 563 | --bindPointIt; |
| 564 | if (!path::startsWith(path, bindPointIt->first)) { |
| 565 | return mBindsByPath.end(); |
| 566 | } |
| 567 | return bindPointIt; |
| 568 | } |
| 569 | |
| 570 | StorageId IncrementalService::findStorageId(std::string_view path) const { |
| 571 | std::lock_guard l(mLock); |
| 572 | auto it = findStorageLocked(path); |
| 573 | if (it == mBindsByPath.end()) { |
| 574 | return kInvalidStorageId; |
| 575 | } |
| 576 | return it->second->second.storage; |
| 577 | } |
| 578 | |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 579 | int IncrementalService::setStorageParams(StorageId storageId, bool enableReadLogs) { |
| 580 | const auto ifs = getIfs(storageId); |
| 581 | if (!ifs) { |
| 582 | return -EINVAL; |
| 583 | } |
| 584 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 585 | ifs->dataLoaderFilesystemParams.readLogsEnabled = enableReadLogs; |
| 586 | if (enableReadLogs) { |
| 587 | // We never unregister the callbacks, but given a restricted number of data loaders and even fewer asking for read log access, should be ok. |
| 588 | registerAppOpsCallback(ifs->dataLoaderParams.packageName); |
| 589 | } |
| 590 | |
| 591 | return applyStorageParams(*ifs); |
| 592 | } |
| 593 | |
| 594 | int IncrementalService::applyStorageParams(IncFsMount& ifs) { |
| 595 | const bool enableReadLogs = ifs.dataLoaderFilesystemParams.readLogsEnabled; |
| 596 | if (enableReadLogs) { |
| 597 | if (auto status = CheckPermissionForDataDelivery(kDataUsageStats, kOpUsage); |
| 598 | !status.isOk()) { |
| 599 | LOG(ERROR) << "CheckPermissionForDataDelivery failed: " << status.toString8(); |
| 600 | return fromBinderStatus(status); |
| 601 | } |
| 602 | } |
| 603 | |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 604 | using unique_fd = ::android::base::unique_fd; |
| 605 | ::android::os::incremental::IncrementalFileSystemControlParcel control; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 606 | control.cmd.reset(unique_fd(dup(ifs.control.cmd()))); |
| 607 | control.pendingReads.reset(unique_fd(dup(ifs.control.pendingReads()))); |
| 608 | auto logsFd = ifs.control.logs(); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 609 | if (logsFd >= 0) { |
| 610 | control.log.reset(unique_fd(dup(logsFd))); |
| 611 | } |
| 612 | |
| 613 | std::lock_guard l(mMountOperationLock); |
| 614 | const auto status = mVold->setIncFsMountOptions(control, enableReadLogs); |
| 615 | if (!status.isOk()) { |
| 616 | LOG(ERROR) << "Calling Vold::setIncFsMountOptions() failed: " << status.toString8(); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 617 | return fromBinderStatus(status); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | return 0; |
| 621 | } |
| 622 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 623 | void IncrementalService::deleteStorage(StorageId storageId) { |
| 624 | const auto ifs = getIfs(storageId); |
| 625 | if (!ifs) { |
| 626 | return; |
| 627 | } |
| 628 | deleteStorage(*ifs); |
| 629 | } |
| 630 | |
| 631 | void IncrementalService::deleteStorage(IncrementalService::IncFsMount& ifs) { |
| 632 | std::unique_lock l(ifs.lock); |
| 633 | deleteStorageLocked(ifs, std::move(l)); |
| 634 | } |
| 635 | |
| 636 | void IncrementalService::deleteStorageLocked(IncrementalService::IncFsMount& ifs, |
| 637 | std::unique_lock<std::mutex>&& ifsLock) { |
| 638 | const auto storages = std::move(ifs.storages); |
| 639 | // Don't move the bind points out: Ifs's dtor will use them to unmount everything. |
| 640 | const auto bindPoints = ifs.bindPoints; |
| 641 | ifsLock.unlock(); |
| 642 | |
| 643 | std::lock_guard l(mLock); |
| 644 | for (auto&& [id, _] : storages) { |
| 645 | if (id != ifs.mountId) { |
| 646 | mMounts.erase(id); |
| 647 | } |
| 648 | } |
| 649 | for (auto&& [path, _] : bindPoints) { |
| 650 | mBindsByPath.erase(path); |
| 651 | } |
| 652 | mMounts.erase(ifs.mountId); |
| 653 | } |
| 654 | |
| 655 | StorageId IncrementalService::openStorage(std::string_view pathInMount) { |
| 656 | if (!path::isAbsolute(pathInMount)) { |
| 657 | return kInvalidStorageId; |
| 658 | } |
| 659 | |
| 660 | return findStorageId(path::normalize(pathInMount)); |
| 661 | } |
| 662 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 663 | FileId IncrementalService::nodeFor(StorageId storage, std::string_view subpath) const { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 664 | const auto ifs = getIfs(storage); |
| 665 | if (!ifs) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 666 | return kIncFsInvalidFileId; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 667 | } |
| 668 | std::unique_lock l(ifs->lock); |
| 669 | auto storageIt = ifs->storages.find(storage); |
| 670 | if (storageIt == ifs->storages.end()) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 671 | return kIncFsInvalidFileId; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 672 | } |
| 673 | if (subpath.empty() || subpath == "."sv) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 674 | return kIncFsInvalidFileId; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 675 | } |
| 676 | auto path = path::join(ifs->root, constants().mount, storageIt->second.name, subpath); |
| 677 | l.unlock(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 678 | return mIncFs->getFileId(ifs->control, path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 679 | } |
| 680 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 681 | std::pair<FileId, std::string_view> IncrementalService::parentAndNameFor( |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 682 | StorageId storage, std::string_view subpath) const { |
| 683 | auto name = path::basename(subpath); |
| 684 | if (name.empty()) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 685 | return {kIncFsInvalidFileId, {}}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 686 | } |
| 687 | auto dir = path::dirname(subpath); |
| 688 | if (dir.empty() || dir == "/"sv) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 689 | return {kIncFsInvalidFileId, {}}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 690 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 691 | auto id = nodeFor(storage, dir); |
| 692 | return {id, name}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | IncrementalService::IfsMountPtr IncrementalService::getIfs(StorageId storage) const { |
| 696 | std::lock_guard l(mLock); |
| 697 | return getIfsLocked(storage); |
| 698 | } |
| 699 | |
| 700 | const IncrementalService::IfsMountPtr& IncrementalService::getIfsLocked(StorageId storage) const { |
| 701 | auto it = mMounts.find(storage); |
| 702 | if (it == mMounts.end()) { |
| 703 | static const IfsMountPtr kEmpty = {}; |
| 704 | return kEmpty; |
| 705 | } |
| 706 | return it->second; |
| 707 | } |
| 708 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 709 | int IncrementalService::bind(StorageId storage, std::string_view source, std::string_view target, |
| 710 | BindKind kind) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 711 | if (!isValidMountTarget(target)) { |
| 712 | return -EINVAL; |
| 713 | } |
| 714 | |
| 715 | const auto ifs = getIfs(storage); |
| 716 | if (!ifs) { |
| 717 | return -EINVAL; |
| 718 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 719 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 720 | std::unique_lock l(ifs->lock); |
| 721 | const auto storageInfo = ifs->storages.find(storage); |
| 722 | if (storageInfo == ifs->storages.end()) { |
| 723 | return -EINVAL; |
| 724 | } |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 725 | std::string normSource = normalizePathToStorage(ifs, storage, source); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 726 | l.unlock(); |
| 727 | std::unique_lock l2(mLock, std::defer_lock); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 728 | return addBindMount(*ifs, storage, storageInfo->second.name, std::move(normSource), |
| 729 | path::normalize(target), kind, l2); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | int IncrementalService::unbind(StorageId storage, std::string_view target) { |
| 733 | if (!path::isAbsolute(target)) { |
| 734 | return -EINVAL; |
| 735 | } |
| 736 | |
| 737 | LOG(INFO) << "Removing bind point " << target; |
| 738 | |
| 739 | // Here we should only look up by the exact target, not by a subdirectory of any existing mount, |
| 740 | // otherwise there's a chance to unmount something completely unrelated |
| 741 | const auto norm = path::normalize(target); |
| 742 | std::unique_lock l(mLock); |
| 743 | const auto storageIt = mBindsByPath.find(norm); |
| 744 | if (storageIt == mBindsByPath.end() || storageIt->second->second.storage != storage) { |
| 745 | return -EINVAL; |
| 746 | } |
| 747 | const auto bindIt = storageIt->second; |
| 748 | const auto storageId = bindIt->second.storage; |
| 749 | const auto ifs = getIfsLocked(storageId); |
| 750 | if (!ifs) { |
| 751 | LOG(ERROR) << "Internal error: storageId " << storageId << " for bound path " << target |
| 752 | << " is missing"; |
| 753 | return -EFAULT; |
| 754 | } |
| 755 | mBindsByPath.erase(storageIt); |
| 756 | l.unlock(); |
| 757 | |
| 758 | mVold->unmountIncFs(bindIt->first); |
| 759 | std::unique_lock l2(ifs->lock); |
| 760 | if (ifs->bindPoints.size() <= 1) { |
| 761 | ifs->bindPoints.clear(); |
| 762 | deleteStorageLocked(*ifs, std::move(l2)); |
| 763 | } else { |
| 764 | const std::string savedFile = std::move(bindIt->second.savedFilename); |
| 765 | ifs->bindPoints.erase(bindIt); |
| 766 | l2.unlock(); |
| 767 | if (!savedFile.empty()) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 768 | mIncFs->unlink(ifs->control, path::join(ifs->root, constants().mount, savedFile)); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | return 0; |
| 772 | } |
| 773 | |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 774 | std::string IncrementalService::normalizePathToStorage(const IncrementalService::IfsMountPtr ifs, |
| 775 | StorageId storage, std::string_view path) { |
| 776 | const auto storageInfo = ifs->storages.find(storage); |
| 777 | if (storageInfo == ifs->storages.end()) { |
| 778 | return {}; |
| 779 | } |
| 780 | std::string normPath; |
| 781 | if (path::isAbsolute(path)) { |
| 782 | normPath = path::normalize(path); |
| 783 | } else { |
| 784 | normPath = path::normalize(path::join(storageInfo->second.name, path)); |
| 785 | } |
| 786 | if (!path::startsWith(normPath, storageInfo->second.name)) { |
| 787 | return {}; |
| 788 | } |
| 789 | return normPath; |
| 790 | } |
| 791 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 792 | int IncrementalService::makeFile(StorageId storage, std::string_view path, int mode, FileId id, |
| 793 | incfs::NewFileParams params) { |
| 794 | if (auto ifs = getIfs(storage)) { |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 795 | std::string normPath = normalizePathToStorage(ifs, storage, path); |
| 796 | if (normPath.empty()) { |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 797 | LOG(ERROR) << "Internal error: storageId " << storage << " failed to normalize: " << path; |
Songchun Fan | 54c6aed | 2020-01-31 16:52:41 -0800 | [diff] [blame] | 798 | return -EINVAL; |
| 799 | } |
| 800 | auto err = mIncFs->makeFile(ifs->control, normPath, mode, id, params); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 801 | if (err) { |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 802 | LOG(ERROR) << "Internal error: storageId " << storage << " failed to makeFile: " << err; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 803 | return err; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 804 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 805 | std::vector<uint8_t> metadataBytes; |
| 806 | if (params.metadata.data && params.metadata.size > 0) { |
| 807 | metadataBytes.assign(params.metadata.data, params.metadata.data + params.metadata.size); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 808 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 809 | return 0; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 810 | } |
| 811 | return -EINVAL; |
| 812 | } |
| 813 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 814 | int IncrementalService::makeDir(StorageId storageId, std::string_view path, int mode) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 815 | if (auto ifs = getIfs(storageId)) { |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 816 | std::string normPath = normalizePathToStorage(ifs, storageId, path); |
| 817 | if (normPath.empty()) { |
| 818 | return -EINVAL; |
| 819 | } |
| 820 | return mIncFs->makeDir(ifs->control, normPath, mode); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 821 | } |
| 822 | return -EINVAL; |
| 823 | } |
| 824 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 825 | int IncrementalService::makeDirs(StorageId storageId, std::string_view path, int mode) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 826 | const auto ifs = getIfs(storageId); |
| 827 | if (!ifs) { |
| 828 | return -EINVAL; |
| 829 | } |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 830 | std::string normPath = normalizePathToStorage(ifs, storageId, path); |
| 831 | if (normPath.empty()) { |
| 832 | return -EINVAL; |
| 833 | } |
| 834 | auto err = mIncFs->makeDir(ifs->control, normPath, mode); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 835 | if (err == -EEXIST) { |
| 836 | return 0; |
| 837 | } else if (err != -ENOENT) { |
| 838 | return err; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 839 | } |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 840 | if (auto err = makeDirs(storageId, path::dirname(normPath), mode)) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 841 | return err; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 842 | } |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 843 | return mIncFs->makeDir(ifs->control, normPath, mode); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 846 | int IncrementalService::link(StorageId sourceStorageId, std::string_view oldPath, |
| 847 | StorageId destStorageId, std::string_view newPath) { |
| 848 | if (auto ifsSrc = getIfs(sourceStorageId), ifsDest = getIfs(destStorageId); |
| 849 | ifsSrc && ifsSrc == ifsDest) { |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 850 | std::string normOldPath = normalizePathToStorage(ifsSrc, sourceStorageId, oldPath); |
| 851 | std::string normNewPath = normalizePathToStorage(ifsDest, destStorageId, newPath); |
| 852 | if (normOldPath.empty() || normNewPath.empty()) { |
| 853 | return -EINVAL; |
| 854 | } |
| 855 | return mIncFs->link(ifsSrc->control, normOldPath, normNewPath); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 856 | } |
| 857 | return -EINVAL; |
| 858 | } |
| 859 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 860 | int IncrementalService::unlink(StorageId storage, std::string_view path) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 861 | if (auto ifs = getIfs(storage)) { |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 862 | std::string normOldPath = normalizePathToStorage(ifs, storage, path); |
| 863 | return mIncFs->unlink(ifs->control, normOldPath); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 864 | } |
| 865 | return -EINVAL; |
| 866 | } |
| 867 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 868 | int IncrementalService::addBindMount(IncFsMount& ifs, StorageId storage, |
| 869 | std::string_view storageRoot, std::string&& source, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 870 | std::string&& target, BindKind kind, |
| 871 | std::unique_lock<std::mutex>& mainLock) { |
| 872 | if (!isValidMountTarget(target)) { |
| 873 | return -EINVAL; |
| 874 | } |
| 875 | |
| 876 | std::string mdFileName; |
| 877 | if (kind != BindKind::Temporary) { |
| 878 | metadata::BindPoint bp; |
| 879 | bp.set_storage_id(storage); |
| 880 | bp.set_allocated_dest_path(&target); |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 881 | bp.set_allocated_source_subdir(&source); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 882 | const auto metadata = bp.SerializeAsString(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 883 | bp.release_dest_path(); |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 884 | bp.release_source_subdir(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 885 | mdFileName = makeBindMdName(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 886 | auto node = |
| 887 | mIncFs->makeFile(ifs.control, path::join(ifs.root, constants().mount, mdFileName), |
| 888 | 0444, idFromMetadata(metadata), |
| 889 | {.metadata = {metadata.data(), (IncFsSize)metadata.size()}}); |
| 890 | if (node) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 891 | return int(node); |
| 892 | } |
| 893 | } |
| 894 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 895 | return addBindMountWithMd(ifs, storage, std::move(mdFileName), std::move(source), |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 896 | std::move(target), kind, mainLock); |
| 897 | } |
| 898 | |
| 899 | int IncrementalService::addBindMountWithMd(IncrementalService::IncFsMount& ifs, StorageId storage, |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 900 | std::string&& metadataName, std::string&& source, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 901 | std::string&& target, BindKind kind, |
| 902 | std::unique_lock<std::mutex>& mainLock) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 903 | { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 904 | std::lock_guard l(mMountOperationLock); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 905 | const auto status = mVold->bindMount(source, target); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 906 | if (!status.isOk()) { |
| 907 | LOG(ERROR) << "Calling Vold::bindMount() failed: " << status.toString8(); |
| 908 | return status.exceptionCode() == binder::Status::EX_SERVICE_SPECIFIC |
| 909 | ? status.serviceSpecificErrorCode() > 0 ? -status.serviceSpecificErrorCode() |
| 910 | : status.serviceSpecificErrorCode() == 0 |
| 911 | ? -EFAULT |
| 912 | : status.serviceSpecificErrorCode() |
| 913 | : -EIO; |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | if (!mainLock.owns_lock()) { |
| 918 | mainLock.lock(); |
| 919 | } |
| 920 | std::lock_guard l(ifs.lock); |
| 921 | const auto [it, _] = |
| 922 | ifs.bindPoints.insert_or_assign(target, |
| 923 | IncFsMount::Bind{storage, std::move(metadataName), |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 924 | std::move(source), kind}); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 925 | mBindsByPath[std::move(target)] = it; |
| 926 | return 0; |
| 927 | } |
| 928 | |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 929 | RawMetadata IncrementalService::getMetadata(StorageId storage, FileId node) const { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 930 | const auto ifs = getIfs(storage); |
| 931 | if (!ifs) { |
| 932 | return {}; |
| 933 | } |
| 934 | return mIncFs->getMetadata(ifs->control, node); |
| 935 | } |
| 936 | |
| 937 | std::vector<std::string> IncrementalService::listFiles(StorageId storage) const { |
| 938 | const auto ifs = getIfs(storage); |
| 939 | if (!ifs) { |
| 940 | return {}; |
| 941 | } |
| 942 | |
| 943 | std::unique_lock l(ifs->lock); |
| 944 | auto subdirIt = ifs->storages.find(storage); |
| 945 | if (subdirIt == ifs->storages.end()) { |
| 946 | return {}; |
| 947 | } |
| 948 | auto dir = path::join(ifs->root, constants().mount, subdirIt->second.name); |
| 949 | l.unlock(); |
| 950 | |
| 951 | const auto prefixSize = dir.size() + 1; |
| 952 | std::vector<std::string> todoDirs{std::move(dir)}; |
| 953 | std::vector<std::string> result; |
| 954 | do { |
| 955 | auto currDir = std::move(todoDirs.back()); |
| 956 | todoDirs.pop_back(); |
| 957 | |
| 958 | auto d = |
| 959 | std::unique_ptr<DIR, decltype(&::closedir)>(::opendir(currDir.c_str()), ::closedir); |
| 960 | while (auto e = ::readdir(d.get())) { |
| 961 | if (e->d_type == DT_REG) { |
| 962 | result.emplace_back( |
| 963 | path::join(std::string_view(currDir).substr(prefixSize), e->d_name)); |
| 964 | continue; |
| 965 | } |
| 966 | if (e->d_type == DT_DIR) { |
| 967 | if (e->d_name == "."sv || e->d_name == ".."sv) { |
| 968 | continue; |
| 969 | } |
| 970 | todoDirs.emplace_back(path::join(currDir, e->d_name)); |
| 971 | continue; |
| 972 | } |
| 973 | } |
| 974 | } while (!todoDirs.empty()); |
| 975 | return result; |
| 976 | } |
| 977 | |
| 978 | bool IncrementalService::startLoading(StorageId storage) const { |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 979 | { |
| 980 | std::unique_lock l(mLock); |
| 981 | const auto& ifs = getIfsLocked(storage); |
| 982 | if (!ifs) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 983 | return false; |
| 984 | } |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 985 | if (ifs->dataLoaderStatus != IDataLoaderStatusListener::DATA_LOADER_CREATED) { |
| 986 | ifs->dataLoaderStartRequested = true; |
| 987 | return true; |
| 988 | } |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 989 | } |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 990 | return startDataLoader(storage); |
| 991 | } |
| 992 | |
| 993 | bool IncrementalService::startDataLoader(MountId mountId) const { |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 994 | sp<IDataLoader> dataloader; |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 995 | auto status = mDataLoaderManager->getDataLoader(mountId, &dataloader); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 996 | if (!status.isOk()) { |
| 997 | return false; |
| 998 | } |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 999 | if (!dataloader) { |
| 1000 | return false; |
| 1001 | } |
Alex Buynytskyy | b6e02f7 | 2020-03-17 18:12:23 -0700 | [diff] [blame] | 1002 | status = dataloader->start(mountId); |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 1003 | if (!status.isOk()) { |
| 1004 | return false; |
| 1005 | } |
| 1006 | return true; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | void IncrementalService::mountExistingImages() { |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 1010 | for (const auto& entry : fs::directory_iterator(mIncrementalDir)) { |
| 1011 | const auto path = entry.path().u8string(); |
| 1012 | const auto name = entry.path().filename().u8string(); |
| 1013 | if (!base::StartsWith(name, constants().mountKeyPrefix)) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1014 | continue; |
| 1015 | } |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 1016 | const auto root = path::join(mIncrementalDir, name); |
Yurii Zubrytskyi | 107ae35 | 2020-04-03 13:12:51 -0700 | [diff] [blame] | 1017 | if (!mountExistingImage(root)) { |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 1018 | IncFsMount::cleanupFilesystem(path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | |
Yurii Zubrytskyi | 107ae35 | 2020-04-03 13:12:51 -0700 | [diff] [blame] | 1023 | bool IncrementalService::mountExistingImage(std::string_view root) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1024 | auto mountTarget = path::join(root, constants().mount); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 1025 | const auto backing = path::join(root, constants().backing); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1026 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1027 | IncrementalFileSystemControlParcel controlParcel; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 1028 | auto status = mVold->mountIncFs(backing, mountTarget, 0, &controlParcel); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1029 | if (!status.isOk()) { |
| 1030 | LOG(ERROR) << "Vold::mountIncFs() failed: " << status.toString8(); |
| 1031 | return false; |
| 1032 | } |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 1033 | |
| 1034 | int cmd = controlParcel.cmd.release().release(); |
| 1035 | int pendingReads = controlParcel.pendingReads.release().release(); |
| 1036 | int logs = controlParcel.log.release().release(); |
| 1037 | IncFsMount::Control control = mIncFs->createControl(cmd, pendingReads, logs); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1038 | |
| 1039 | auto ifs = std::make_shared<IncFsMount>(std::string(root), -1, std::move(control), *this); |
| 1040 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 1041 | auto mount = parseFromIncfs<metadata::Mount>(mIncFs.get(), ifs->control, |
| 1042 | path::join(mountTarget, constants().infoMdName)); |
| 1043 | if (!mount.has_loader() || !mount.has_storage()) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1044 | LOG(ERROR) << "Bad mount metadata in mount at " << root; |
| 1045 | return false; |
| 1046 | } |
| 1047 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 1048 | ifs->mountId = mount.storage().id(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1049 | mNextId = std::max(mNextId, ifs->mountId + 1); |
| 1050 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 1051 | // DataLoader params |
| 1052 | { |
| 1053 | auto& dlp = ifs->dataLoaderParams; |
| 1054 | const auto& loader = mount.loader(); |
| 1055 | dlp.type = (android::content::pm::DataLoaderType)loader.type(); |
| 1056 | dlp.packageName = loader.package_name(); |
| 1057 | dlp.className = loader.class_name(); |
| 1058 | dlp.arguments = loader.arguments(); |
| 1059 | } |
| 1060 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1061 | std::vector<std::pair<std::string, metadata::BindPoint>> bindPoints; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 1062 | auto d = openDir(path::c_str(mountTarget)); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1063 | while (auto e = ::readdir(d.get())) { |
| 1064 | if (e->d_type == DT_REG) { |
| 1065 | auto name = std::string_view(e->d_name); |
| 1066 | if (name.starts_with(constants().mountpointMdPrefix)) { |
| 1067 | bindPoints.emplace_back(name, |
| 1068 | parseFromIncfs<metadata::BindPoint>(mIncFs.get(), |
| 1069 | ifs->control, |
| 1070 | path::join(mountTarget, |
| 1071 | name))); |
| 1072 | if (bindPoints.back().second.dest_path().empty() || |
| 1073 | bindPoints.back().second.source_subdir().empty()) { |
| 1074 | bindPoints.pop_back(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 1075 | mIncFs->unlink(ifs->control, path::join(ifs->root, constants().mount, name)); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1076 | } |
| 1077 | } |
| 1078 | } else if (e->d_type == DT_DIR) { |
| 1079 | if (e->d_name == "."sv || e->d_name == ".."sv) { |
| 1080 | continue; |
| 1081 | } |
| 1082 | auto name = std::string_view(e->d_name); |
| 1083 | if (name.starts_with(constants().storagePrefix)) { |
Yurii Zubrytskyi | 107ae35 | 2020-04-03 13:12:51 -0700 | [diff] [blame] | 1084 | int storageId; |
| 1085 | const auto res = std::from_chars(name.data() + constants().storagePrefix.size() + 1, |
| 1086 | name.data() + name.size(), storageId); |
| 1087 | if (res.ec != std::errc{} || *res.ptr != '_') { |
| 1088 | LOG(WARNING) << "Ignoring storage with invalid name '" << name << "' for mount " |
| 1089 | << root; |
| 1090 | continue; |
| 1091 | } |
| 1092 | auto [_, inserted] = mMounts.try_emplace(storageId, ifs); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1093 | if (!inserted) { |
Yurii Zubrytskyi | 107ae35 | 2020-04-03 13:12:51 -0700 | [diff] [blame] | 1094 | LOG(WARNING) << "Ignoring storage with duplicate id " << storageId |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1095 | << " for mount " << root; |
| 1096 | continue; |
| 1097 | } |
Yurii Zubrytskyi | 107ae35 | 2020-04-03 13:12:51 -0700 | [diff] [blame] | 1098 | ifs->storages.insert_or_assign(storageId, |
| 1099 | IncFsMount::Storage{ |
| 1100 | path::join(root, constants().mount, name)}); |
| 1101 | mNextId = std::max(mNextId, storageId + 1); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | if (ifs->storages.empty()) { |
| 1107 | LOG(WARNING) << "No valid storages in mount " << root; |
| 1108 | return false; |
| 1109 | } |
| 1110 | |
| 1111 | int bindCount = 0; |
| 1112 | for (auto&& bp : bindPoints) { |
| 1113 | std::unique_lock l(mLock, std::defer_lock); |
| 1114 | bindCount += !addBindMountWithMd(*ifs, bp.second.storage_id(), std::move(bp.first), |
| 1115 | std::move(*bp.second.mutable_source_subdir()), |
| 1116 | std::move(*bp.second.mutable_dest_path()), |
| 1117 | BindKind::Permanent, l); |
| 1118 | } |
| 1119 | |
| 1120 | if (bindCount == 0) { |
| 1121 | LOG(WARNING) << "No valid bind points for mount " << root; |
| 1122 | deleteStorage(*ifs); |
| 1123 | return false; |
| 1124 | } |
| 1125 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1126 | mMounts[ifs->mountId] = std::move(ifs); |
| 1127 | return true; |
| 1128 | } |
| 1129 | |
| 1130 | bool IncrementalService::prepareDataLoader(IncrementalService::IncFsMount& ifs, |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 1131 | const DataLoaderStatusListener* externalListener) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1132 | if (!mSystemReady.load(std::memory_order_relaxed)) { |
| 1133 | std::unique_lock l(ifs.lock); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1134 | return true; // eventually... |
| 1135 | } |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1136 | |
| 1137 | std::unique_lock l(ifs.lock); |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 1138 | if (ifs.dataLoaderStatus != -1) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1139 | LOG(INFO) << "Skipped data loader preparation because it already exists"; |
| 1140 | return true; |
| 1141 | } |
| 1142 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1143 | FileSystemControlParcel fsControlParcel; |
Jooyung Han | 66c567a | 2020-03-07 21:47:09 +0900 | [diff] [blame] | 1144 | fsControlParcel.incremental = aidl::make_nullable<IncrementalFileSystemControlParcel>(); |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 1145 | fsControlParcel.incremental->cmd.reset(base::unique_fd(::dup(ifs.control.cmd()))); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 1146 | fsControlParcel.incremental->pendingReads.reset( |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 1147 | base::unique_fd(::dup(ifs.control.pendingReads()))); |
| 1148 | fsControlParcel.incremental->log.reset(base::unique_fd(::dup(ifs.control.logs()))); |
Songchun Fan | 1124fd3 | 2020-02-10 12:49:41 -0800 | [diff] [blame] | 1149 | sp<IncrementalDataLoaderListener> listener = |
Songchun Fan | 306b7df | 2020-03-17 12:37:07 -0700 | [diff] [blame] | 1150 | new IncrementalDataLoaderListener(*this, |
| 1151 | externalListener ? *externalListener |
| 1152 | : DataLoaderStatusListener()); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1153 | bool created = false; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 1154 | auto status = mDataLoaderManager->initializeDataLoader(ifs.mountId, ifs.dataLoaderParams, fsControlParcel, listener, &created); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1155 | if (!status.isOk() || !created) { |
| 1156 | LOG(ERROR) << "Failed to create a data loader for mount " << ifs.mountId; |
| 1157 | return false; |
| 1158 | } |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1159 | return true; |
| 1160 | } |
| 1161 | |
Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 1162 | // Extract lib filse from zip, create new files in incfs and write data to them |
| 1163 | bool IncrementalService::configureNativeBinaries(StorageId storage, std::string_view apkFullPath, |
| 1164 | std::string_view libDirRelativePath, |
| 1165 | std::string_view abi) { |
| 1166 | const auto ifs = getIfs(storage); |
| 1167 | // First prepare target directories if they don't exist yet |
| 1168 | if (auto res = makeDirs(storage, libDirRelativePath, 0755)) { |
| 1169 | LOG(ERROR) << "Failed to prepare target lib directory " << libDirRelativePath |
| 1170 | << " errno: " << res; |
| 1171 | return false; |
| 1172 | } |
| 1173 | |
| 1174 | std::unique_ptr<ZipFileRO> zipFile(ZipFileRO::open(apkFullPath.data())); |
| 1175 | if (!zipFile) { |
| 1176 | LOG(ERROR) << "Failed to open zip file at " << apkFullPath; |
| 1177 | return false; |
| 1178 | } |
| 1179 | void* cookie = nullptr; |
| 1180 | const auto libFilePrefix = path::join(constants().libDir, abi); |
| 1181 | if (!zipFile.get()->startIteration(&cookie, libFilePrefix.c_str() /* prefix */, |
| 1182 | constants().libSuffix.data() /* suffix */)) { |
| 1183 | LOG(ERROR) << "Failed to start zip iteration for " << apkFullPath; |
| 1184 | return false; |
| 1185 | } |
| 1186 | ZipEntryRO entry = nullptr; |
| 1187 | bool success = true; |
| 1188 | while ((entry = zipFile.get()->nextEntry(cookie)) != nullptr) { |
| 1189 | char fileName[PATH_MAX]; |
| 1190 | if (zipFile.get()->getEntryFileName(entry, fileName, sizeof(fileName))) { |
| 1191 | continue; |
| 1192 | } |
| 1193 | const auto libName = path::basename(fileName); |
| 1194 | const auto targetLibPath = path::join(libDirRelativePath, libName); |
| 1195 | const auto targetLibPathAbsolute = normalizePathToStorage(ifs, storage, targetLibPath); |
| 1196 | // If the extract file already exists, skip |
| 1197 | struct stat st; |
| 1198 | if (stat(targetLibPathAbsolute.c_str(), &st) == 0) { |
| 1199 | LOG(INFO) << "Native lib file already exists: " << targetLibPath |
| 1200 | << "; skipping extraction"; |
| 1201 | continue; |
| 1202 | } |
| 1203 | |
| 1204 | uint32_t uncompressedLen; |
| 1205 | if (!zipFile.get()->getEntryInfo(entry, nullptr, &uncompressedLen, nullptr, nullptr, |
| 1206 | nullptr, nullptr)) { |
| 1207 | LOG(ERROR) << "Failed to read native lib entry: " << fileName; |
| 1208 | success = false; |
| 1209 | break; |
| 1210 | } |
| 1211 | |
| 1212 | // Create new lib file without signature info |
George Burgess IV | dd5275d | 2020-02-10 11:18:07 -0800 | [diff] [blame] | 1213 | incfs::NewFileParams libFileParams{}; |
Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 1214 | libFileParams.size = uncompressedLen; |
Alex Buynytskyy | f5e605a | 2020-03-13 13:31:12 -0700 | [diff] [blame] | 1215 | libFileParams.signature = {}; |
Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 1216 | // Metadata of the new lib file is its relative path |
| 1217 | IncFsSpan libFileMetadata; |
| 1218 | libFileMetadata.data = targetLibPath.c_str(); |
| 1219 | libFileMetadata.size = targetLibPath.size(); |
| 1220 | libFileParams.metadata = libFileMetadata; |
| 1221 | incfs::FileId libFileId = idFromMetadata(targetLibPath); |
| 1222 | if (auto res = makeFile(storage, targetLibPath, 0777, libFileId, libFileParams)) { |
| 1223 | LOG(ERROR) << "Failed to make file for: " << targetLibPath << " errno: " << res; |
| 1224 | success = false; |
| 1225 | // If one lib file fails to be created, abort others as well |
| 1226 | break; |
| 1227 | } |
Songchun Fan | afaf6e9 | 2020-03-18 14:12:20 -0700 | [diff] [blame] | 1228 | // If it is a zero-byte file, skip data writing |
| 1229 | if (uncompressedLen == 0) { |
| 1230 | continue; |
| 1231 | } |
Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 1232 | |
| 1233 | // Write extracted data to new file |
| 1234 | std::vector<uint8_t> libData(uncompressedLen); |
| 1235 | if (!zipFile.get()->uncompressEntry(entry, &libData[0], uncompressedLen)) { |
| 1236 | LOG(ERROR) << "Failed to extract native lib zip entry: " << fileName; |
| 1237 | success = false; |
| 1238 | break; |
| 1239 | } |
Yurii Zubrytskyi | e82cdd7 | 2020-04-01 12:19:26 -0700 | [diff] [blame] | 1240 | const auto writeFd = mIncFs->openForSpecialOps(ifs->control, libFileId); |
| 1241 | if (!writeFd.ok()) { |
Songchun Fan | 0f8b6fe | 2020-02-05 17:41:25 -0800 | [diff] [blame] | 1242 | LOG(ERROR) << "Failed to open write fd for: " << targetLibPath << " errno: " << writeFd; |
| 1243 | success = false; |
| 1244 | break; |
| 1245 | } |
| 1246 | const int numBlocks = uncompressedLen / constants().blockSize + 1; |
| 1247 | std::vector<IncFsDataBlock> instructions; |
| 1248 | auto remainingData = std::span(libData); |
| 1249 | for (int i = 0; i < numBlocks - 1; i++) { |
| 1250 | auto inst = IncFsDataBlock{ |
| 1251 | .fileFd = writeFd, |
| 1252 | .pageIndex = static_cast<IncFsBlockIndex>(i), |
| 1253 | .compression = INCFS_COMPRESSION_KIND_NONE, |
| 1254 | .kind = INCFS_BLOCK_KIND_DATA, |
| 1255 | .dataSize = static_cast<uint16_t>(constants().blockSize), |
| 1256 | .data = reinterpret_cast<const char*>(remainingData.data()), |
| 1257 | }; |
| 1258 | instructions.push_back(inst); |
| 1259 | remainingData = remainingData.subspan(constants().blockSize); |
| 1260 | } |
| 1261 | // Last block |
| 1262 | auto inst = IncFsDataBlock{ |
| 1263 | .fileFd = writeFd, |
| 1264 | .pageIndex = static_cast<IncFsBlockIndex>(numBlocks - 1), |
| 1265 | .compression = INCFS_COMPRESSION_KIND_NONE, |
| 1266 | .kind = INCFS_BLOCK_KIND_DATA, |
| 1267 | .dataSize = static_cast<uint16_t>(remainingData.size()), |
| 1268 | .data = reinterpret_cast<const char*>(remainingData.data()), |
| 1269 | }; |
| 1270 | instructions.push_back(inst); |
| 1271 | size_t res = mIncFs->writeBlocks(instructions); |
| 1272 | if (res != instructions.size()) { |
| 1273 | LOG(ERROR) << "Failed to write data into: " << targetLibPath; |
| 1274 | success = false; |
| 1275 | } |
| 1276 | instructions.clear(); |
| 1277 | } |
| 1278 | zipFile.get()->endIteration(cookie); |
| 1279 | return success; |
| 1280 | } |
| 1281 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 1282 | void IncrementalService::registerAppOpsCallback(const std::string& packageName) { |
| 1283 | if (packageName.empty()) { |
| 1284 | return; |
| 1285 | } |
| 1286 | |
| 1287 | { |
| 1288 | std::unique_lock lock{mCallbacksLock}; |
| 1289 | if (!mCallbackRegistered.insert(packageName).second) { |
| 1290 | return; |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | /* TODO(b/152633648): restore callback after it's not crashing Binder anymore. |
| 1295 | sp<AppOpsListener> listener = new AppOpsListener(*this, packageName); |
| 1296 | mAppOpsManager->startWatchingMode(AppOpsManager::OP_GET_USAGE_STATS, String16(packageName.c_str()), listener); |
| 1297 | */ |
| 1298 | } |
| 1299 | |
| 1300 | void IncrementalService::onAppOppChanged(const std::string& packageName) { |
| 1301 | std::vector<IfsMountPtr> affected; |
| 1302 | { |
| 1303 | std::lock_guard l(mLock); |
| 1304 | affected.reserve(mMounts.size()); |
| 1305 | for (auto&& [id, ifs] : mMounts) { |
| 1306 | if (ifs->dataLoaderFilesystemParams.readLogsEnabled && ifs->dataLoaderParams.packageName == packageName) { |
| 1307 | affected.push_back(ifs); |
| 1308 | } |
| 1309 | } |
| 1310 | } |
| 1311 | /* TODO(b/152633648): restore callback after it's not crashing Kernel anymore. |
| 1312 | for (auto&& ifs : affected) { |
| 1313 | applyStorageParams(*ifs); |
| 1314 | } |
| 1315 | */ |
| 1316 | } |
| 1317 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1318 | binder::Status IncrementalService::IncrementalDataLoaderListener::onStatusChanged(MountId mountId, |
| 1319 | int newStatus) { |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 1320 | if (externalListener) { |
| 1321 | // Give an external listener a chance to act before we destroy something. |
| 1322 | externalListener->onStatusChanged(mountId, newStatus); |
| 1323 | } |
| 1324 | |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 1325 | bool startRequested = false; |
| 1326 | { |
| 1327 | std::unique_lock l(incrementalService.mLock); |
| 1328 | const auto& ifs = incrementalService.getIfsLocked(mountId); |
| 1329 | if (!ifs) { |
Songchun Fan | 306b7df | 2020-03-17 12:37:07 -0700 | [diff] [blame] | 1330 | LOG(WARNING) << "Received data loader status " << int(newStatus) |
| 1331 | << " for unknown mount " << mountId; |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 1332 | return binder::Status::ok(); |
| 1333 | } |
| 1334 | ifs->dataLoaderStatus = newStatus; |
| 1335 | |
| 1336 | if (newStatus == IDataLoaderStatusListener::DATA_LOADER_DESTROYED) { |
| 1337 | ifs->dataLoaderStatus = IDataLoaderStatusListener::DATA_LOADER_STOPPED; |
| 1338 | incrementalService.deleteStorageLocked(*ifs, std::move(l)); |
| 1339 | return binder::Status::ok(); |
| 1340 | } |
| 1341 | |
| 1342 | startRequested = ifs->dataLoaderStartRequested; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1343 | } |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 1344 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1345 | switch (newStatus) { |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 1346 | case IDataLoaderStatusListener::DATA_LOADER_CREATED: { |
Alex Buynytskyy | bf1c063 | 2020-03-10 15:49:29 -0700 | [diff] [blame] | 1347 | if (startRequested) { |
| 1348 | incrementalService.startDataLoader(mountId); |
| 1349 | } |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1350 | break; |
| 1351 | } |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 1352 | case IDataLoaderStatusListener::DATA_LOADER_DESTROYED: { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1353 | break; |
| 1354 | } |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 1355 | case IDataLoaderStatusListener::DATA_LOADER_STARTED: { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1356 | break; |
| 1357 | } |
| 1358 | case IDataLoaderStatusListener::DATA_LOADER_STOPPED: { |
| 1359 | break; |
| 1360 | } |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 1361 | case IDataLoaderStatusListener::DATA_LOADER_IMAGE_READY: { |
| 1362 | break; |
| 1363 | } |
| 1364 | case IDataLoaderStatusListener::DATA_LOADER_IMAGE_NOT_READY: { |
| 1365 | break; |
| 1366 | } |
Alex Buynytskyy | 2cf1d18 | 2020-03-17 09:33:45 -0700 | [diff] [blame] | 1367 | case IDataLoaderStatusListener::DATA_LOADER_UNRECOVERABLE: { |
| 1368 | // Nothing for now. Rely on externalListener to handle this. |
| 1369 | break; |
| 1370 | } |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1371 | default: { |
| 1372 | LOG(WARNING) << "Unknown data loader status: " << newStatus |
| 1373 | << " for mount: " << mountId; |
| 1374 | break; |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | return binder::Status::ok(); |
| 1379 | } |
| 1380 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 1381 | void IncrementalService::AppOpsListener::opChanged(int32_t op, const String16&) { |
| 1382 | incrementalService.onAppOppChanged(packageName); |
| 1383 | } |
| 1384 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1385 | } // namespace android::incremental |