Darin Petkov | c0b7a53 | 2010-09-29 15:18:14 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/delta_diff_generator.h" |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 6 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 7 | #include <errno.h> |
| 8 | #include <fcntl.h> |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 9 | #include <inttypes.h> |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 10 | #include <sys/stat.h> |
| 11 | #include <sys/types.h> |
| 12 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 13 | #include <algorithm> |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 14 | #include <map> |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 15 | #include <set> |
| 16 | #include <string> |
| 17 | #include <utility> |
| 18 | #include <vector> |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 19 | |
| 20 | #include <base/logging.h> |
| 21 | #include <base/string_util.h> |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 22 | #include <bzlib.h> |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 23 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 24 | #include "update_engine/bzip.h" |
| 25 | #include "update_engine/cycle_breaker.h" |
| 26 | #include "update_engine/extent_mapper.h" |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 27 | #include "update_engine/extent_ranges.h" |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 28 | #include "update_engine/file_writer.h" |
| 29 | #include "update_engine/filesystem_iterator.h" |
| 30 | #include "update_engine/graph_types.h" |
| 31 | #include "update_engine/graph_utils.h" |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 32 | #include "update_engine/omaha_hash_calculator.h" |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 33 | #include "update_engine/payload_signer.h" |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 34 | #include "update_engine/subprocess.h" |
| 35 | #include "update_engine/topological_sort.h" |
| 36 | #include "update_engine/update_metadata.pb.h" |
| 37 | #include "update_engine/utils.h" |
| 38 | |
| 39 | using std::make_pair; |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 40 | using std::map; |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 41 | using std::max; |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 42 | using std::min; |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 43 | using std::pair; |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 44 | using std::set; |
| 45 | using std::string; |
| 46 | using std::vector; |
| 47 | |
| 48 | namespace chromeos_update_engine { |
| 49 | |
| 50 | typedef DeltaDiffGenerator::Block Block; |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 51 | typedef map<const DeltaArchiveManifest_InstallOperation*, |
| 52 | const string*> OperationNameMap; |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 53 | |
| 54 | namespace { |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 55 | const size_t kBlockSize = 4096; // bytes |
Darin Petkov | 9eadd64 | 2010-10-14 15:20:57 -0700 | [diff] [blame] | 56 | const size_t kRootFSPartitionSize = 1 * 1024 * 1024 * 1024; // bytes |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 57 | const uint64_t kVersionNumber = 1; |
Darin Petkov | 9eadd64 | 2010-10-14 15:20:57 -0700 | [diff] [blame] | 58 | const uint64_t kFullUpdateChunkSize = 1024 * 1024; // bytes |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 59 | |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 60 | static const char* kInstallOperationTypes[] = { |
| 61 | "REPLACE", |
| 62 | "REPLACE_BZ", |
| 63 | "MOVE", |
| 64 | "BSDIFF" |
| 65 | }; |
| 66 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 67 | // Stores all Extents for a file into 'out'. Returns true on success. |
| 68 | bool GatherExtents(const string& path, |
| 69 | google::protobuf::RepeatedPtrField<Extent>* out) { |
| 70 | vector<Extent> extents; |
| 71 | TEST_AND_RETURN_FALSE(extent_mapper::ExtentsForFileFibmap(path, &extents)); |
| 72 | DeltaDiffGenerator::StoreExtents(extents, out); |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | // Runs the bsdiff tool on two files and returns the resulting delta in |
| 77 | // 'out'. Returns true on success. |
| 78 | bool BsdiffFiles(const string& old_file, |
| 79 | const string& new_file, |
| 80 | vector<char>* out) { |
| 81 | const string kPatchFile = "/tmp/delta.patchXXXXXX"; |
| 82 | string patch_file_path; |
| 83 | |
| 84 | TEST_AND_RETURN_FALSE( |
| 85 | utils::MakeTempFile(kPatchFile, &patch_file_path, NULL)); |
| 86 | |
| 87 | vector<string> cmd; |
| 88 | cmd.push_back(kBsdiffPath); |
| 89 | cmd.push_back(old_file); |
| 90 | cmd.push_back(new_file); |
| 91 | cmd.push_back(patch_file_path); |
| 92 | |
| 93 | int rc = 1; |
| 94 | vector<char> patch_file; |
| 95 | TEST_AND_RETURN_FALSE(Subprocess::SynchronousExec(cmd, &rc)); |
| 96 | TEST_AND_RETURN_FALSE(rc == 0); |
| 97 | TEST_AND_RETURN_FALSE(utils::ReadFile(patch_file_path, out)); |
| 98 | unlink(patch_file_path.c_str()); |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | // The blocks vector contains a reader and writer for each block on the |
| 103 | // filesystem that's being in-place updated. We populate the reader/writer |
| 104 | // fields of blocks by calling this function. |
| 105 | // For each block in 'operation' that is read or written, find that block |
| 106 | // in 'blocks' and set the reader/writer field to the vertex passed. |
| 107 | // 'graph' is not strictly necessary, but useful for printing out |
| 108 | // error messages. |
| 109 | bool AddInstallOpToBlocksVector( |
| 110 | const DeltaArchiveManifest_InstallOperation& operation, |
| 111 | vector<Block>* blocks, |
| 112 | const Graph& graph, |
| 113 | Vertex::Index vertex) { |
| 114 | LOG(INFO) << "AddInstallOpToBlocksVector(" << vertex << "), " |
| 115 | << graph[vertex].file_name; |
| 116 | // See if this is already present. |
| 117 | TEST_AND_RETURN_FALSE(operation.dst_extents_size() > 0); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 118 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 119 | enum BlockField { READER = 0, WRITER, BLOCK_FIELD_COUNT }; |
| 120 | for (int field = READER; field < BLOCK_FIELD_COUNT; field++) { |
| 121 | const int extents_size = |
| 122 | (field == READER) ? operation.src_extents_size() : |
| 123 | operation.dst_extents_size(); |
| 124 | const char* past_participle = (field == READER) ? "read" : "written"; |
| 125 | const google::protobuf::RepeatedPtrField<Extent>& extents = |
| 126 | (field == READER) ? operation.src_extents() : operation.dst_extents(); |
| 127 | Vertex::Index Block::*access_type = |
| 128 | (field == READER) ? &Block::reader : &Block::writer; |
| 129 | |
| 130 | for (int i = 0; i < extents_size; i++) { |
| 131 | const Extent& extent = extents.Get(i); |
| 132 | if (extent.start_block() == kSparseHole) { |
| 133 | // Hole in sparse file. skip |
| 134 | continue; |
| 135 | } |
| 136 | for (uint64_t block = extent.start_block(); |
| 137 | block < (extent.start_block() + extent.num_blocks()); block++) { |
| 138 | LOG(INFO) << "ext: " << i << " block: " << block; |
| 139 | if ((*blocks)[block].*access_type != Vertex::kInvalidIndex) { |
| 140 | LOG(FATAL) << "Block " << block << " is already " |
| 141 | << past_participle << " by " |
| 142 | << (*blocks)[block].*access_type << "(" |
| 143 | << graph[(*blocks)[block].*access_type].file_name |
| 144 | << ") and also " << vertex << "(" |
| 145 | << graph[vertex].file_name << ")"; |
| 146 | } |
| 147 | (*blocks)[block].*access_type = vertex; |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | return true; |
| 152 | } |
| 153 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 154 | // For a given regular file which must exist at new_root + path, and |
| 155 | // may exist at old_root + path, creates a new InstallOperation and |
| 156 | // adds it to the graph. Also, populates the |blocks| array as |
| 157 | // necessary, if |blocks| is non-NULL. Also, writes the data |
| 158 | // necessary to send the file down to the client into data_fd, which |
| 159 | // has length *data_file_size. *data_file_size is updated |
| 160 | // appropriately. If |existing_vertex| is no kInvalidIndex, use that |
| 161 | // rather than allocating a new vertex. Returns true on success. |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 162 | bool DeltaReadFile(Graph* graph, |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 163 | Vertex::Index existing_vertex, |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 164 | vector<Block>* blocks, |
| 165 | const string& old_root, |
| 166 | const string& new_root, |
| 167 | const string& path, // within new_root |
| 168 | int data_fd, |
| 169 | off_t* data_file_size) { |
| 170 | vector<char> data; |
| 171 | DeltaArchiveManifest_InstallOperation operation; |
| 172 | |
| 173 | TEST_AND_RETURN_FALSE(DeltaDiffGenerator::ReadFileToDiff(old_root + path, |
| 174 | new_root + path, |
| 175 | &data, |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 176 | &operation, |
| 177 | true)); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 178 | |
| 179 | // Write the data |
| 180 | if (operation.type() != DeltaArchiveManifest_InstallOperation_Type_MOVE) { |
| 181 | operation.set_data_offset(*data_file_size); |
| 182 | operation.set_data_length(data.size()); |
| 183 | } |
| 184 | |
| 185 | TEST_AND_RETURN_FALSE(utils::WriteAll(data_fd, &data[0], data.size())); |
| 186 | *data_file_size += data.size(); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 187 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 188 | // Now, insert into graph and blocks vector |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 189 | Vertex::Index vertex = existing_vertex; |
| 190 | if (vertex == Vertex::kInvalidIndex) { |
| 191 | graph->resize(graph->size() + 1); |
| 192 | vertex = graph->size() - 1; |
| 193 | } |
| 194 | (*graph)[vertex].op = operation; |
| 195 | CHECK((*graph)[vertex].op.has_type()); |
| 196 | (*graph)[vertex].file_name = path; |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 197 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 198 | if (blocks) |
| 199 | TEST_AND_RETURN_FALSE(AddInstallOpToBlocksVector((*graph)[vertex].op, |
| 200 | blocks, |
| 201 | *graph, |
| 202 | vertex)); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 203 | return true; |
| 204 | } |
| 205 | |
| 206 | // For each regular file within new_root, creates a node in the graph, |
| 207 | // determines the best way to compress it (REPLACE, REPLACE_BZ, COPY, BSDIFF), |
| 208 | // and writes any necessary data to the end of data_fd. |
| 209 | bool DeltaReadFiles(Graph* graph, |
| 210 | vector<Block>* blocks, |
| 211 | const string& old_root, |
| 212 | const string& new_root, |
| 213 | int data_fd, |
| 214 | off_t* data_file_size) { |
| 215 | set<ino_t> visited_inodes; |
| 216 | for (FilesystemIterator fs_iter(new_root, |
| 217 | utils::SetWithValue<string>("/lost+found")); |
| 218 | !fs_iter.IsEnd(); fs_iter.Increment()) { |
| 219 | if (!S_ISREG(fs_iter.GetStat().st_mode)) |
| 220 | continue; |
| 221 | |
| 222 | // Make sure we visit each inode only once. |
| 223 | if (utils::SetContainsKey(visited_inodes, fs_iter.GetStat().st_ino)) |
| 224 | continue; |
| 225 | visited_inodes.insert(fs_iter.GetStat().st_ino); |
| 226 | if (fs_iter.GetStat().st_size == 0) |
| 227 | continue; |
| 228 | |
| 229 | LOG(INFO) << "Encoding file " << fs_iter.GetPartialPath(); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 230 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 231 | TEST_AND_RETURN_FALSE(DeltaReadFile(graph, |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 232 | Vertex::kInvalidIndex, |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 233 | blocks, |
| 234 | old_root, |
| 235 | new_root, |
| 236 | fs_iter.GetPartialPath(), |
| 237 | data_fd, |
| 238 | data_file_size)); |
| 239 | } |
| 240 | return true; |
| 241 | } |
| 242 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 243 | // This class allocates non-existent temp blocks, starting from |
| 244 | // kTempBlockStart. Other code is responsible for converting these |
| 245 | // temp blocks into real blocks, as the client can't read or write to |
| 246 | // these blocks. |
| 247 | class DummyExtentAllocator { |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 248 | public: |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 249 | explicit DummyExtentAllocator() |
| 250 | : next_block_(kTempBlockStart) {} |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 251 | vector<Extent> Allocate(const uint64_t block_count) { |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 252 | vector<Extent> ret(1); |
| 253 | ret[0].set_start_block(next_block_); |
| 254 | ret[0].set_num_blocks(block_count); |
| 255 | next_block_ += block_count; |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 256 | return ret; |
| 257 | } |
| 258 | private: |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 259 | uint64_t next_block_; |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
| 262 | // Reads blocks from image_path that are not yet marked as being written |
| 263 | // in the blocks array. These blocks that remain are non-file-data blocks. |
| 264 | // In the future we might consider intelligent diffing between this data |
| 265 | // and data in the previous image, but for now we just bzip2 compress it |
| 266 | // and include it in the update. |
| 267 | // Creates a new node in the graph to write these blocks and writes the |
| 268 | // appropriate blob to blobs_fd. Reads and updates blobs_length; |
| 269 | bool ReadUnwrittenBlocks(const vector<Block>& blocks, |
| 270 | int blobs_fd, |
| 271 | off_t* blobs_length, |
| 272 | const string& image_path, |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 273 | Vertex* vertex) { |
Darin Petkov | abe7cc9 | 2010-10-08 12:29:32 -0700 | [diff] [blame] | 274 | vertex->file_name = "<rootfs-non-file-data>"; |
| 275 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 276 | DeltaArchiveManifest_InstallOperation* out_op = &vertex->op; |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 277 | int image_fd = open(image_path.c_str(), O_RDONLY, 000); |
| 278 | TEST_AND_RETURN_FALSE_ERRNO(image_fd >= 0); |
| 279 | ScopedFdCloser image_fd_closer(&image_fd); |
| 280 | |
| 281 | string temp_file_path; |
| 282 | TEST_AND_RETURN_FALSE(utils::MakeTempFile("/tmp/CrAU_temp_data.XXXXXX", |
| 283 | &temp_file_path, |
| 284 | NULL)); |
| 285 | |
| 286 | FILE* file = fopen(temp_file_path.c_str(), "w"); |
| 287 | TEST_AND_RETURN_FALSE(file); |
| 288 | int err = BZ_OK; |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 289 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 290 | BZFILE* bz_file = BZ2_bzWriteOpen(&err, |
| 291 | file, |
| 292 | 9, // max compression |
| 293 | 0, // verbosity |
| 294 | 0); // default work factor |
| 295 | TEST_AND_RETURN_FALSE(err == BZ_OK); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 296 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 297 | vector<Extent> extents; |
| 298 | vector<Block>::size_type block_count = 0; |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 299 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 300 | LOG(INFO) << "Appending left over blocks to extents"; |
| 301 | for (vector<Block>::size_type i = 0; i < blocks.size(); i++) { |
| 302 | if (blocks[i].writer != Vertex::kInvalidIndex) |
| 303 | continue; |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 304 | if (blocks[i].reader != Vertex::kInvalidIndex) { |
| 305 | graph_utils::AddReadBeforeDep(vertex, blocks[i].reader, i); |
| 306 | } |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 307 | graph_utils::AppendBlockToExtents(&extents, i); |
| 308 | block_count++; |
| 309 | } |
| 310 | |
| 311 | // Code will handle 'buf' at any size that's a multiple of kBlockSize, |
| 312 | // so we arbitrarily set it to 1024 * kBlockSize. |
| 313 | vector<char> buf(1024 * kBlockSize); |
| 314 | |
| 315 | LOG(INFO) << "Reading left over blocks"; |
| 316 | vector<Block>::size_type blocks_copied_count = 0; |
| 317 | |
| 318 | // For each extent in extents, write the data into BZ2_bzWrite which |
| 319 | // sends it to an output file. |
| 320 | // We use the temporary buffer 'buf' to hold the data, which may be |
| 321 | // smaller than the extent, so in that case we have to loop to get |
| 322 | // the extent's data (that's the inner while loop). |
| 323 | for (vector<Extent>::const_iterator it = extents.begin(); |
| 324 | it != extents.end(); ++it) { |
| 325 | vector<Block>::size_type blocks_read = 0; |
| 326 | while (blocks_read < it->num_blocks()) { |
| 327 | const int copy_block_cnt = |
| 328 | min(buf.size() / kBlockSize, |
| 329 | static_cast<vector<char>::size_type>( |
| 330 | it->num_blocks() - blocks_read)); |
| 331 | ssize_t rc = pread(image_fd, |
| 332 | &buf[0], |
| 333 | copy_block_cnt * kBlockSize, |
| 334 | (it->start_block() + blocks_read) * kBlockSize); |
| 335 | TEST_AND_RETURN_FALSE_ERRNO(rc >= 0); |
| 336 | TEST_AND_RETURN_FALSE(static_cast<size_t>(rc) == |
| 337 | copy_block_cnt * kBlockSize); |
| 338 | BZ2_bzWrite(&err, bz_file, &buf[0], copy_block_cnt * kBlockSize); |
| 339 | TEST_AND_RETURN_FALSE(err == BZ_OK); |
| 340 | blocks_read += copy_block_cnt; |
| 341 | blocks_copied_count += copy_block_cnt; |
| 342 | LOG(INFO) << "progress: " << ((float)blocks_copied_count)/block_count; |
| 343 | } |
| 344 | } |
| 345 | BZ2_bzWriteClose(&err, bz_file, 0, NULL, NULL); |
| 346 | TEST_AND_RETURN_FALSE(err == BZ_OK); |
| 347 | bz_file = NULL; |
| 348 | TEST_AND_RETURN_FALSE_ERRNO(0 == fclose(file)); |
| 349 | file = NULL; |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 350 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 351 | vector<char> compressed_data; |
| 352 | LOG(INFO) << "Reading compressed data off disk"; |
| 353 | TEST_AND_RETURN_FALSE(utils::ReadFile(temp_file_path, &compressed_data)); |
| 354 | TEST_AND_RETURN_FALSE(unlink(temp_file_path.c_str()) == 0); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 355 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 356 | // Add node to graph to write these blocks |
| 357 | out_op->set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ); |
| 358 | out_op->set_data_offset(*blobs_length); |
| 359 | out_op->set_data_length(compressed_data.size()); |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 360 | LOG(INFO) << "Rootfs non-data blocks compressed take up " |
| 361 | << compressed_data.size(); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 362 | *blobs_length += compressed_data.size(); |
| 363 | out_op->set_dst_length(kBlockSize * block_count); |
| 364 | DeltaDiffGenerator::StoreExtents(extents, out_op->mutable_dst_extents()); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 365 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 366 | TEST_AND_RETURN_FALSE(utils::WriteAll(blobs_fd, |
| 367 | &compressed_data[0], |
| 368 | compressed_data.size())); |
| 369 | LOG(INFO) << "done with extra blocks"; |
| 370 | return true; |
| 371 | } |
| 372 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 373 | // Writes the uint64_t passed in in host-endian to the file as big-endian. |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 374 | // Returns true on success. |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 375 | bool WriteUint64AsBigEndian(FileWriter* writer, const uint64_t value) { |
| 376 | uint64_t value_be = htobe64(value); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 377 | TEST_AND_RETURN_FALSE(writer->Write(&value_be, sizeof(value_be)) == |
| 378 | sizeof(value_be)); |
| 379 | return true; |
| 380 | } |
| 381 | |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 382 | // Adds each operation from |graph| to |out_manifest| in the order specified by |
| 383 | // |order| while building |out_op_name_map| with operation to name |
| 384 | // mappings. Adds all |kernel_ops| to |out_manifest|. Filters out no-op |
| 385 | // operations. |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 386 | void InstallOperationsToManifest( |
| 387 | const Graph& graph, |
| 388 | const vector<Vertex::Index>& order, |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 389 | const vector<DeltaArchiveManifest_InstallOperation>& kernel_ops, |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 390 | DeltaArchiveManifest* out_manifest, |
| 391 | OperationNameMap* out_op_name_map) { |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 392 | for (vector<Vertex::Index>::const_iterator it = order.begin(); |
| 393 | it != order.end(); ++it) { |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 394 | const Vertex& vertex = graph[*it]; |
| 395 | const DeltaArchiveManifest_InstallOperation& add_op = vertex.op; |
| 396 | if (DeltaDiffGenerator::IsNoopOperation(add_op)) { |
| 397 | continue; |
| 398 | } |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 399 | DeltaArchiveManifest_InstallOperation* op = |
| 400 | out_manifest->add_install_operations(); |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 401 | *op = add_op; |
| 402 | (*out_op_name_map)[op] = &vertex.file_name; |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 403 | } |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 404 | for (vector<DeltaArchiveManifest_InstallOperation>::const_iterator it = |
| 405 | kernel_ops.begin(); it != kernel_ops.end(); ++it) { |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 406 | const DeltaArchiveManifest_InstallOperation& add_op = *it; |
| 407 | if (DeltaDiffGenerator::IsNoopOperation(add_op)) { |
| 408 | continue; |
| 409 | } |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 410 | DeltaArchiveManifest_InstallOperation* op = |
| 411 | out_manifest->add_kernel_install_operations(); |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 412 | *op = add_op; |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 413 | } |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void CheckGraph(const Graph& graph) { |
| 417 | for (Graph::const_iterator it = graph.begin(); it != graph.end(); ++it) { |
| 418 | CHECK(it->op.has_type()); |
| 419 | } |
| 420 | } |
| 421 | |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 422 | // Delta compresses a kernel partition |new_kernel_part| with knowledge of the |
| 423 | // old kernel partition |old_kernel_part|. If |old_kernel_part| is an empty |
| 424 | // string, generates a full update of the partition. |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 425 | bool DeltaCompressKernelPartition( |
| 426 | const string& old_kernel_part, |
| 427 | const string& new_kernel_part, |
| 428 | vector<DeltaArchiveManifest_InstallOperation>* ops, |
| 429 | int blobs_fd, |
| 430 | off_t* blobs_length) { |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 431 | LOG(INFO) << "Delta compressing kernel partition..."; |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 432 | LOG_IF(INFO, old_kernel_part.empty()) << "Generating full kernel update..."; |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 433 | |
| 434 | // Add a new install operation |
| 435 | ops->resize(1); |
| 436 | DeltaArchiveManifest_InstallOperation* op = &(*ops)[0]; |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 437 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 438 | vector<char> data; |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 439 | TEST_AND_RETURN_FALSE(DeltaDiffGenerator::ReadFileToDiff(old_kernel_part, |
| 440 | new_kernel_part, |
| 441 | &data, |
| 442 | op, |
| 443 | false)); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 444 | |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 445 | // Write the data |
| 446 | if (op->type() != DeltaArchiveManifest_InstallOperation_Type_MOVE) { |
| 447 | op->set_data_offset(*blobs_length); |
| 448 | op->set_data_length(data.size()); |
| 449 | } |
Andrew de los Reyes | 36f3736 | 2010-09-03 09:20:04 -0700 | [diff] [blame] | 450 | |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 451 | TEST_AND_RETURN_FALSE(utils::WriteAll(blobs_fd, &data[0], data.size())); |
| 452 | *blobs_length += data.size(); |
Andrew de los Reyes | 36f3736 | 2010-09-03 09:20:04 -0700 | [diff] [blame] | 453 | |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 454 | LOG(INFO) << "Done delta compressing kernel partition: " |
| 455 | << kInstallOperationTypes[op->type()]; |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 456 | return true; |
| 457 | } |
| 458 | |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 459 | struct DeltaObject { |
| 460 | DeltaObject(const string& in_name, const int in_type, const off_t in_size) |
| 461 | : name(in_name), |
| 462 | type(in_type), |
| 463 | size(in_size) {} |
| 464 | bool operator <(const DeltaObject& object) const { |
Darin Petkov | d43d690 | 2010-10-14 11:17:50 -0700 | [diff] [blame] | 465 | return (size != object.size) ? (size < object.size) : (name < object.name); |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 466 | } |
| 467 | string name; |
| 468 | int type; |
| 469 | off_t size; |
| 470 | }; |
| 471 | |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 472 | void ReportPayloadUsage(const DeltaArchiveManifest& manifest, |
| 473 | const int64_t manifest_metadata_size, |
| 474 | const OperationNameMap& op_name_map) { |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 475 | vector<DeltaObject> objects; |
| 476 | off_t total_size = 0; |
| 477 | |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 478 | // Rootfs install operations. |
| 479 | for (int i = 0; i < manifest.install_operations_size(); ++i) { |
| 480 | const DeltaArchiveManifest_InstallOperation& op = |
| 481 | manifest.install_operations(i); |
| 482 | objects.push_back(DeltaObject(*op_name_map.find(&op)->second, |
| 483 | op.type(), |
| 484 | op.data_length())); |
| 485 | total_size += op.data_length(); |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 488 | // Kernel install operations. |
| 489 | for (int i = 0; i < manifest.kernel_install_operations_size(); ++i) { |
| 490 | const DeltaArchiveManifest_InstallOperation& op = |
| 491 | manifest.kernel_install_operations(i); |
| 492 | objects.push_back(DeltaObject(StringPrintf("<kernel-operation-%d>", i), |
| 493 | op.type(), |
| 494 | op.data_length())); |
| 495 | total_size += op.data_length(); |
| 496 | } |
| 497 | |
Darin Petkov | 95cf01f | 2010-10-12 14:59:13 -0700 | [diff] [blame] | 498 | objects.push_back(DeltaObject("<manifest-metadata>", |
| 499 | -1, |
| 500 | manifest_metadata_size)); |
| 501 | total_size += manifest_metadata_size; |
| 502 | |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 503 | std::sort(objects.begin(), objects.end()); |
| 504 | |
| 505 | static const char kFormatString[] = "%6.2f%% %10llu %-10s %s\n"; |
| 506 | for (vector<DeltaObject>::const_iterator it = objects.begin(); |
| 507 | it != objects.end(); ++it) { |
| 508 | const DeltaObject& object = *it; |
| 509 | fprintf(stderr, kFormatString, |
| 510 | object.size * 100.0 / total_size, |
| 511 | object.size, |
Darin Petkov | 95cf01f | 2010-10-12 14:59:13 -0700 | [diff] [blame] | 512 | object.type >= 0 ? kInstallOperationTypes[object.type] : "-", |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 513 | object.name.c_str()); |
| 514 | } |
| 515 | fprintf(stderr, kFormatString, 100.0, total_size, "", "<total>"); |
| 516 | } |
| 517 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 518 | } // namespace {} |
| 519 | |
| 520 | bool DeltaDiffGenerator::ReadFileToDiff( |
| 521 | const string& old_filename, |
| 522 | const string& new_filename, |
| 523 | vector<char>* out_data, |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 524 | DeltaArchiveManifest_InstallOperation* out_op, |
| 525 | bool gather_extents) { |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 526 | // Read new data in |
| 527 | vector<char> new_data; |
| 528 | TEST_AND_RETURN_FALSE(utils::ReadFile(new_filename, &new_data)); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 529 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 530 | TEST_AND_RETURN_FALSE(!new_data.empty()); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 531 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 532 | vector<char> new_data_bz; |
| 533 | TEST_AND_RETURN_FALSE(BzipCompress(new_data, &new_data_bz)); |
| 534 | CHECK(!new_data_bz.empty()); |
| 535 | |
| 536 | vector<char> data; // Data blob that will be written to delta file. |
| 537 | |
| 538 | DeltaArchiveManifest_InstallOperation operation; |
| 539 | size_t current_best_size = 0; |
| 540 | if (new_data.size() <= new_data_bz.size()) { |
| 541 | operation.set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE); |
| 542 | current_best_size = new_data.size(); |
| 543 | data = new_data; |
| 544 | } else { |
| 545 | operation.set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ); |
| 546 | current_best_size = new_data_bz.size(); |
| 547 | data = new_data_bz; |
| 548 | } |
| 549 | |
| 550 | // Do we have an original file to consider? |
| 551 | struct stat old_stbuf; |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 552 | bool no_original = old_filename.empty(); |
| 553 | if (!no_original && 0 != stat(old_filename.c_str(), &old_stbuf)) { |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 554 | // If stat-ing the old file fails, it should be because it doesn't exist. |
| 555 | TEST_AND_RETURN_FALSE(errno == ENOTDIR || errno == ENOENT); |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 556 | no_original = true; |
| 557 | } |
| 558 | if (!no_original) { |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 559 | // Read old data |
| 560 | vector<char> old_data; |
| 561 | TEST_AND_RETURN_FALSE(utils::ReadFile(old_filename, &old_data)); |
| 562 | if (old_data == new_data) { |
| 563 | // No change in data. |
| 564 | operation.set_type(DeltaArchiveManifest_InstallOperation_Type_MOVE); |
| 565 | current_best_size = 0; |
| 566 | data.clear(); |
| 567 | } else { |
| 568 | // Try bsdiff of old to new data |
| 569 | vector<char> bsdiff_delta; |
| 570 | TEST_AND_RETURN_FALSE( |
| 571 | BsdiffFiles(old_filename, new_filename, &bsdiff_delta)); |
| 572 | CHECK_GT(bsdiff_delta.size(), 0); |
| 573 | if (bsdiff_delta.size() < current_best_size) { |
| 574 | operation.set_type(DeltaArchiveManifest_InstallOperation_Type_BSDIFF); |
| 575 | current_best_size = bsdiff_delta.size(); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 576 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 577 | data = bsdiff_delta; |
| 578 | } |
| 579 | } |
| 580 | } |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 581 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 582 | // Set parameters of the operations |
| 583 | CHECK_EQ(data.size(), current_best_size); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 584 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 585 | if (operation.type() == DeltaArchiveManifest_InstallOperation_Type_MOVE || |
| 586 | operation.type() == DeltaArchiveManifest_InstallOperation_Type_BSDIFF) { |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 587 | if (gather_extents) { |
| 588 | TEST_AND_RETURN_FALSE( |
| 589 | GatherExtents(old_filename, operation.mutable_src_extents())); |
| 590 | } else { |
| 591 | Extent* src_extent = operation.add_src_extents(); |
| 592 | src_extent->set_start_block(0); |
| 593 | src_extent->set_num_blocks( |
| 594 | (old_stbuf.st_size + kBlockSize - 1) / kBlockSize); |
| 595 | } |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 596 | operation.set_src_length(old_stbuf.st_size); |
| 597 | } |
| 598 | |
Darin Petkov | 68c10d1 | 2010-10-14 09:24:37 -0700 | [diff] [blame] | 599 | if (gather_extents) { |
| 600 | TEST_AND_RETURN_FALSE( |
| 601 | GatherExtents(new_filename, operation.mutable_dst_extents())); |
| 602 | } else { |
| 603 | Extent* dst_extent = operation.add_dst_extents(); |
| 604 | dst_extent->set_start_block(0); |
| 605 | dst_extent->set_num_blocks((new_data.size() + kBlockSize - 1) / kBlockSize); |
| 606 | } |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 607 | operation.set_dst_length(new_data.size()); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 608 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 609 | out_data->swap(data); |
| 610 | *out_op = operation; |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 611 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 612 | return true; |
| 613 | } |
| 614 | |
Andrew de los Reyes | 89f17be | 2010-10-22 13:39:09 -0700 | [diff] [blame] | 615 | bool DeltaDiffGenerator::InitializePartitionInfo(bool is_kernel, |
| 616 | const string& partition, |
| 617 | PartitionInfo* info) { |
Darin Petkov | 7ea3233 | 2010-10-13 10:46:11 -0700 | [diff] [blame] | 618 | int64_t size = 0; |
| 619 | if (is_kernel) { |
| 620 | size = utils::FileSize(partition); |
| 621 | } else { |
| 622 | int block_count = 0, block_size = 0; |
| 623 | TEST_AND_RETURN_FALSE(utils::GetFilesystemSize(partition, |
| 624 | &block_count, |
| 625 | &block_size)); |
| 626 | size = static_cast<int64_t>(block_count) * block_size; |
| 627 | } |
| 628 | TEST_AND_RETURN_FALSE(size > 0); |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 629 | info->set_size(size); |
| 630 | OmahaHashCalculator hasher; |
Darin Petkov | 7ea3233 | 2010-10-13 10:46:11 -0700 | [diff] [blame] | 631 | TEST_AND_RETURN_FALSE(hasher.UpdateFile(partition, size) == size); |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 632 | TEST_AND_RETURN_FALSE(hasher.Finalize()); |
| 633 | const vector<char>& hash = hasher.raw_hash(); |
| 634 | info->set_hash(hash.data(), hash.size()); |
Darin Petkov | d43d690 | 2010-10-14 11:17:50 -0700 | [diff] [blame] | 635 | LOG(INFO) << partition << ": size=" << size << " hash=" << hasher.hash(); |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 636 | return true; |
| 637 | } |
| 638 | |
| 639 | bool InitializePartitionInfos(const string& old_kernel, |
| 640 | const string& new_kernel, |
| 641 | const string& old_rootfs, |
| 642 | const string& new_rootfs, |
| 643 | DeltaArchiveManifest* manifest) { |
Darin Petkov | d43d690 | 2010-10-14 11:17:50 -0700 | [diff] [blame] | 644 | if (!old_kernel.empty()) { |
Andrew de los Reyes | 89f17be | 2010-10-22 13:39:09 -0700 | [diff] [blame] | 645 | TEST_AND_RETURN_FALSE(DeltaDiffGenerator::InitializePartitionInfo( |
| 646 | true, |
| 647 | old_kernel, |
| 648 | manifest->mutable_old_kernel_info())); |
Darin Petkov | d43d690 | 2010-10-14 11:17:50 -0700 | [diff] [blame] | 649 | } |
Andrew de los Reyes | 89f17be | 2010-10-22 13:39:09 -0700 | [diff] [blame] | 650 | TEST_AND_RETURN_FALSE(DeltaDiffGenerator::InitializePartitionInfo( |
| 651 | true, |
| 652 | new_kernel, |
| 653 | manifest->mutable_new_kernel_info())); |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 654 | if (!old_rootfs.empty()) { |
Andrew de los Reyes | 89f17be | 2010-10-22 13:39:09 -0700 | [diff] [blame] | 655 | TEST_AND_RETURN_FALSE(DeltaDiffGenerator::InitializePartitionInfo( |
| 656 | false, |
| 657 | old_rootfs, |
| 658 | manifest->mutable_old_rootfs_info())); |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 659 | } |
Andrew de los Reyes | 89f17be | 2010-10-22 13:39:09 -0700 | [diff] [blame] | 660 | TEST_AND_RETURN_FALSE(DeltaDiffGenerator::InitializePartitionInfo( |
| 661 | false, |
| 662 | new_rootfs, |
| 663 | manifest->mutable_new_rootfs_info())); |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 664 | return true; |
| 665 | } |
| 666 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 667 | namespace { |
| 668 | |
| 669 | // Takes a collection (vector or RepeatedPtrField) of Extent and |
| 670 | // returns a vector of the blocks referenced, in order. |
| 671 | template<typename T> |
| 672 | vector<uint64_t> ExpandExtents(const T& extents) { |
| 673 | vector<uint64_t> ret; |
| 674 | for (size_t i = 0, e = static_cast<size_t>(extents.size()); i != e; ++i) { |
| 675 | const Extent extent = graph_utils::GetElement(extents, i); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 676 | if (extent.start_block() == kSparseHole) { |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 677 | ret.resize(ret.size() + extent.num_blocks(), kSparseHole); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 678 | } else { |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 679 | for (uint64_t block = extent.start_block(); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 680 | block < (extent.start_block() + extent.num_blocks()); block++) { |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 681 | ret.push_back(block); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | } |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 685 | return ret; |
| 686 | } |
| 687 | |
| 688 | // Takes a vector of blocks and returns an equivalent vector of Extent |
| 689 | // objects. |
| 690 | vector<Extent> CompressExtents(const vector<uint64_t>& blocks) { |
| 691 | vector<Extent> new_extents; |
| 692 | for (vector<uint64_t>::const_iterator it = blocks.begin(), e = blocks.end(); |
| 693 | it != e; ++it) { |
| 694 | graph_utils::AppendBlockToExtents(&new_extents, *it); |
| 695 | } |
| 696 | return new_extents; |
| 697 | } |
| 698 | |
| 699 | } // namespace {} |
| 700 | |
| 701 | void DeltaDiffGenerator::SubstituteBlocks( |
| 702 | Vertex* vertex, |
| 703 | const vector<Extent>& remove_extents, |
| 704 | const vector<Extent>& replace_extents) { |
| 705 | // First, expand out the blocks that op reads from |
| 706 | vector<uint64_t> read_blocks = ExpandExtents(vertex->op.src_extents()); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 707 | { |
| 708 | // Expand remove_extents and replace_extents |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 709 | vector<uint64_t> remove_extents_expanded = |
| 710 | ExpandExtents(remove_extents); |
| 711 | vector<uint64_t> replace_extents_expanded = |
| 712 | ExpandExtents(replace_extents); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 713 | CHECK_EQ(remove_extents_expanded.size(), replace_extents_expanded.size()); |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 714 | map<uint64_t, uint64_t> conversion; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 715 | for (vector<uint64_t>::size_type i = 0; |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 716 | i < replace_extents_expanded.size(); i++) { |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 717 | conversion[remove_extents_expanded[i]] = replace_extents_expanded[i]; |
| 718 | } |
| 719 | utils::ApplyMap(&read_blocks, conversion); |
| 720 | for (Vertex::EdgeMap::iterator it = vertex->out_edges.begin(), |
| 721 | e = vertex->out_edges.end(); it != e; ++it) { |
| 722 | vector<uint64_t> write_before_deps_expanded = |
| 723 | ExpandExtents(it->second.write_extents); |
| 724 | utils::ApplyMap(&write_before_deps_expanded, conversion); |
| 725 | it->second.write_extents = CompressExtents(write_before_deps_expanded); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | // Convert read_blocks back to extents |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 729 | vertex->op.clear_src_extents(); |
| 730 | vector<Extent> new_extents = CompressExtents(read_blocks); |
| 731 | DeltaDiffGenerator::StoreExtents(new_extents, |
| 732 | vertex->op.mutable_src_extents()); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | bool DeltaDiffGenerator::CutEdges(Graph* graph, |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 736 | const set<Edge>& edges, |
| 737 | vector<CutEdgeVertexes>* out_cuts) { |
| 738 | DummyExtentAllocator scratch_allocator; |
| 739 | vector<CutEdgeVertexes> cuts; |
| 740 | cuts.reserve(edges.size()); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 741 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 742 | uint64_t scratch_blocks_used = 0; |
| 743 | for (set<Edge>::const_iterator it = edges.begin(); |
| 744 | it != edges.end(); ++it) { |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 745 | cuts.resize(cuts.size() + 1); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 746 | vector<Extent> old_extents = |
| 747 | (*graph)[it->first].out_edges[it->second].extents; |
| 748 | // Choose some scratch space |
| 749 | scratch_blocks_used += graph_utils::EdgeWeight(*graph, *it); |
| 750 | LOG(INFO) << "using " << graph_utils::EdgeWeight(*graph, *it) |
| 751 | << " scratch blocks (" |
| 752 | << scratch_blocks_used << ")"; |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 753 | cuts.back().tmp_extents = |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 754 | scratch_allocator.Allocate(graph_utils::EdgeWeight(*graph, *it)); |
| 755 | // create vertex to copy original->scratch |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 756 | cuts.back().new_vertex = graph->size(); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 757 | graph->resize(graph->size() + 1); |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 758 | cuts.back().old_src = it->first; |
| 759 | cuts.back().old_dst = it->second; |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 760 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 761 | EdgeProperties& cut_edge_properties = |
| 762 | (*graph)[it->first].out_edges.find(it->second)->second; |
| 763 | |
| 764 | // This should never happen, as we should only be cutting edges between |
| 765 | // real file nodes, and write-before relationships are created from |
| 766 | // a real file node to a temp copy node: |
| 767 | CHECK(cut_edge_properties.write_extents.empty()) |
| 768 | << "Can't cut edge that has write-before relationship."; |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 769 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 770 | // make node depend on the copy operation |
| 771 | (*graph)[it->first].out_edges.insert(make_pair(graph->size() - 1, |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 772 | cut_edge_properties)); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 773 | |
| 774 | // Set src/dst extents and other proto variables for copy operation |
| 775 | graph->back().op.set_type(DeltaArchiveManifest_InstallOperation_Type_MOVE); |
| 776 | DeltaDiffGenerator::StoreExtents( |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 777 | cut_edge_properties.extents, |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 778 | graph->back().op.mutable_src_extents()); |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 779 | DeltaDiffGenerator::StoreExtents(cuts.back().tmp_extents, |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 780 | graph->back().op.mutable_dst_extents()); |
| 781 | graph->back().op.set_src_length( |
| 782 | graph_utils::EdgeWeight(*graph, *it) * kBlockSize); |
| 783 | graph->back().op.set_dst_length(graph->back().op.src_length()); |
| 784 | |
| 785 | // make the dest node read from the scratch space |
| 786 | DeltaDiffGenerator::SubstituteBlocks( |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 787 | &((*graph)[it->second]), |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 788 | (*graph)[it->first].out_edges[it->second].extents, |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 789 | cuts.back().tmp_extents); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 790 | |
| 791 | // delete the old edge |
| 792 | CHECK_EQ(1, (*graph)[it->first].out_edges.erase(it->second)); |
Chris Masone | 790e62e | 2010-08-12 10:41:18 -0700 | [diff] [blame] | 793 | |
Andrew de los Reyes | d12784c | 2010-07-26 13:55:14 -0700 | [diff] [blame] | 794 | // Add an edge from dst to copy operation |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 795 | EdgeProperties write_before_edge_properties; |
| 796 | write_before_edge_properties.write_extents = cuts.back().tmp_extents; |
| 797 | (*graph)[it->second].out_edges.insert( |
| 798 | make_pair(graph->size() - 1, write_before_edge_properties)); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 799 | } |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 800 | out_cuts->swap(cuts); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 801 | return true; |
| 802 | } |
| 803 | |
| 804 | // Stores all Extents in 'extents' into 'out'. |
| 805 | void DeltaDiffGenerator::StoreExtents( |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 806 | const vector<Extent>& extents, |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 807 | google::protobuf::RepeatedPtrField<Extent>* out) { |
| 808 | for (vector<Extent>::const_iterator it = extents.begin(); |
| 809 | it != extents.end(); ++it) { |
| 810 | Extent* new_extent = out->Add(); |
| 811 | *new_extent = *it; |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | // Creates all the edges for the graph. Writers of a block point to |
| 816 | // readers of the same block. This is because for an edge A->B, B |
| 817 | // must complete before A executes. |
| 818 | void DeltaDiffGenerator::CreateEdges(Graph* graph, |
| 819 | const vector<Block>& blocks) { |
| 820 | for (vector<Block>::size_type i = 0; i < blocks.size(); i++) { |
| 821 | // Blocks with both a reader and writer get an edge |
| 822 | if (blocks[i].reader == Vertex::kInvalidIndex || |
| 823 | blocks[i].writer == Vertex::kInvalidIndex) |
| 824 | continue; |
| 825 | // Don't have a node depend on itself |
| 826 | if (blocks[i].reader == blocks[i].writer) |
| 827 | continue; |
| 828 | // See if there's already an edge we can add onto |
| 829 | Vertex::EdgeMap::iterator edge_it = |
| 830 | (*graph)[blocks[i].writer].out_edges.find(blocks[i].reader); |
| 831 | if (edge_it == (*graph)[blocks[i].writer].out_edges.end()) { |
| 832 | // No existing edge. Create one |
| 833 | (*graph)[blocks[i].writer].out_edges.insert( |
| 834 | make_pair(blocks[i].reader, EdgeProperties())); |
| 835 | edge_it = (*graph)[blocks[i].writer].out_edges.find(blocks[i].reader); |
Chris Masone | 790e62e | 2010-08-12 10:41:18 -0700 | [diff] [blame] | 836 | CHECK(edge_it != (*graph)[blocks[i].writer].out_edges.end()); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 837 | } |
| 838 | graph_utils::AppendBlockToExtents(&edge_it->second.extents, i); |
| 839 | } |
| 840 | } |
| 841 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 842 | namespace { |
| 843 | |
| 844 | class SortCutsByTopoOrderLess { |
| 845 | public: |
| 846 | SortCutsByTopoOrderLess(vector<vector<Vertex::Index>::size_type>& table) |
| 847 | : table_(table) {} |
| 848 | bool operator()(const CutEdgeVertexes& a, const CutEdgeVertexes& b) { |
| 849 | return table_[a.old_dst] < table_[b.old_dst]; |
| 850 | } |
| 851 | private: |
| 852 | vector<vector<Vertex::Index>::size_type>& table_; |
| 853 | }; |
| 854 | |
| 855 | } // namespace {} |
| 856 | |
| 857 | void DeltaDiffGenerator::GenerateReverseTopoOrderMap( |
| 858 | vector<Vertex::Index>& op_indexes, |
| 859 | vector<vector<Vertex::Index>::size_type>* reverse_op_indexes) { |
| 860 | vector<vector<Vertex::Index>::size_type> table(op_indexes.size()); |
| 861 | for (vector<Vertex::Index>::size_type i = 0, e = op_indexes.size(); |
| 862 | i != e; ++i) { |
| 863 | Vertex::Index node = op_indexes[i]; |
| 864 | if (table.size() < (node + 1)) { |
| 865 | table.resize(node + 1); |
| 866 | } |
| 867 | table[node] = i; |
| 868 | } |
| 869 | reverse_op_indexes->swap(table); |
| 870 | } |
| 871 | |
| 872 | void DeltaDiffGenerator::SortCutsByTopoOrder(vector<Vertex::Index>& op_indexes, |
| 873 | vector<CutEdgeVertexes>* cuts) { |
| 874 | // first, make a reverse lookup table. |
| 875 | vector<vector<Vertex::Index>::size_type> table; |
| 876 | GenerateReverseTopoOrderMap(op_indexes, &table); |
| 877 | SortCutsByTopoOrderLess less(table); |
| 878 | sort(cuts->begin(), cuts->end(), less); |
| 879 | } |
| 880 | |
| 881 | void DeltaDiffGenerator::MoveFullOpsToBack(Graph* graph, |
| 882 | vector<Vertex::Index>* op_indexes) { |
| 883 | vector<Vertex::Index> ret; |
| 884 | vector<Vertex::Index> full_ops; |
| 885 | ret.reserve(op_indexes->size()); |
| 886 | for (vector<Vertex::Index>::size_type i = 0, e = op_indexes->size(); i != e; |
| 887 | ++i) { |
| 888 | DeltaArchiveManifest_InstallOperation_Type type = |
| 889 | (*graph)[(*op_indexes)[i]].op.type(); |
| 890 | if (type == DeltaArchiveManifest_InstallOperation_Type_REPLACE || |
| 891 | type == DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ) { |
| 892 | full_ops.push_back((*op_indexes)[i]); |
| 893 | } else { |
| 894 | ret.push_back((*op_indexes)[i]); |
| 895 | } |
| 896 | } |
| 897 | LOG(INFO) << "Stats: " << full_ops.size() << " full ops out of " |
| 898 | << (full_ops.size() + ret.size()) << " total ops."; |
| 899 | ret.insert(ret.end(), full_ops.begin(), full_ops.end()); |
| 900 | op_indexes->swap(ret); |
| 901 | } |
| 902 | |
| 903 | namespace { |
| 904 | |
| 905 | template<typename T> |
| 906 | bool TempBlocksExistInExtents(const T& extents) { |
| 907 | for (int i = 0, e = extents.size(); i < e; ++i) { |
| 908 | Extent extent = graph_utils::GetElement(extents, i); |
| 909 | uint64_t start = extent.start_block(); |
| 910 | uint64_t num = extent.num_blocks(); |
| 911 | if (start == kSparseHole) |
| 912 | continue; |
| 913 | if (start >= kTempBlockStart || |
| 914 | (start + num) >= kTempBlockStart) { |
| 915 | LOG(ERROR) << "temp block!"; |
| 916 | LOG(ERROR) << "start: " << start << ", num: " << num; |
| 917 | LOG(ERROR) << "kTempBlockStart: " << kTempBlockStart; |
| 918 | LOG(ERROR) << "returning true"; |
| 919 | return true; |
| 920 | } |
| 921 | // check for wrap-around, which would be a bug: |
| 922 | CHECK(start <= (start + num)); |
| 923 | } |
| 924 | return false; |
| 925 | } |
| 926 | |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 927 | // Convertes the cuts, which must all have the same |old_dst| member, |
| 928 | // to full. It does this by converting the |old_dst| to REPLACE or |
| 929 | // REPLACE_BZ, dropping all incoming edges to |old_dst|, and marking |
| 930 | // all temp nodes invalid. |
| 931 | bool ConvertCutsToFull( |
| 932 | Graph* graph, |
| 933 | const string& new_root, |
| 934 | int data_fd, |
| 935 | off_t* data_file_size, |
| 936 | vector<Vertex::Index>* op_indexes, |
| 937 | vector<vector<Vertex::Index>::size_type>* reverse_op_indexes, |
| 938 | const vector<CutEdgeVertexes>& cuts) { |
| 939 | CHECK(!cuts.empty()); |
| 940 | set<Vertex::Index> deleted_nodes; |
| 941 | for (vector<CutEdgeVertexes>::const_iterator it = cuts.begin(), |
| 942 | e = cuts.end(); it != e; ++it) { |
| 943 | TEST_AND_RETURN_FALSE(DeltaDiffGenerator::ConvertCutToFullOp( |
| 944 | graph, |
| 945 | *it, |
| 946 | new_root, |
| 947 | data_fd, |
| 948 | data_file_size)); |
| 949 | deleted_nodes.insert(it->new_vertex); |
| 950 | } |
| 951 | deleted_nodes.insert(cuts[0].old_dst); |
Darin Petkov | bc58a7b | 2010-11-03 11:52:53 -0700 | [diff] [blame^] | 952 | |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 953 | vector<Vertex::Index> new_op_indexes; |
| 954 | new_op_indexes.reserve(op_indexes->size()); |
| 955 | for (vector<Vertex::Index>::iterator it = op_indexes->begin(), |
| 956 | e = op_indexes->end(); it != e; ++it) { |
| 957 | if (utils::SetContainsKey(deleted_nodes, *it)) |
| 958 | continue; |
| 959 | new_op_indexes.push_back(*it); |
| 960 | } |
| 961 | new_op_indexes.push_back(cuts[0].old_dst); |
| 962 | op_indexes->swap(new_op_indexes); |
| 963 | DeltaDiffGenerator::GenerateReverseTopoOrderMap(*op_indexes, |
| 964 | reverse_op_indexes); |
| 965 | return true; |
| 966 | } |
| 967 | |
| 968 | // Tries to assign temp blocks for a collection of cuts, all of which share |
| 969 | // the same old_dst member. If temp blocks can't be found, old_dst will be |
| 970 | // converted to a REPLACE or REPLACE_BZ operation. Returns true on success, |
| 971 | // which can happen even if blocks are converted to full. Returns false |
| 972 | // on exceptional error cases. |
| 973 | bool AssignBlockForAdjoiningCuts( |
| 974 | Graph* graph, |
| 975 | const string& new_root, |
| 976 | int data_fd, |
| 977 | off_t* data_file_size, |
| 978 | vector<Vertex::Index>* op_indexes, |
| 979 | vector<vector<Vertex::Index>::size_type>* reverse_op_indexes, |
| 980 | const vector<CutEdgeVertexes>& cuts) { |
| 981 | CHECK(!cuts.empty()); |
| 982 | const Vertex::Index old_dst = cuts[0].old_dst; |
| 983 | // Calculate # of blocks needed |
| 984 | uint64_t blocks_needed = 0; |
| 985 | map<const CutEdgeVertexes*, uint64_t> cuts_blocks_needed; |
| 986 | for (vector<CutEdgeVertexes>::const_iterator it = cuts.begin(), |
| 987 | e = cuts.end(); it != e; ++it) { |
| 988 | uint64_t cut_blocks_needed = 0; |
| 989 | for (vector<Extent>::const_iterator jt = it->tmp_extents.begin(), |
| 990 | je = it->tmp_extents.end(); jt != je; ++jt) { |
| 991 | cut_blocks_needed += jt->num_blocks(); |
| 992 | } |
| 993 | blocks_needed += cut_blocks_needed; |
| 994 | cuts_blocks_needed[&*it] = cut_blocks_needed; |
| 995 | } |
| 996 | LOG(INFO) << "Need to find " << blocks_needed << " blocks for " |
| 997 | << cuts.size() << " cuts"; |
Darin Petkov | bc58a7b | 2010-11-03 11:52:53 -0700 | [diff] [blame^] | 998 | |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 999 | // Find enough blocks |
| 1000 | ExtentRanges scratch_ranges; |
| 1001 | // Each block that's supplying temp blocks and the corresponding blocks: |
| 1002 | typedef vector<pair<Vertex::Index, ExtentRanges> > SupplierVector; |
| 1003 | SupplierVector block_suppliers; |
| 1004 | uint64_t scratch_blocks_found = 0; |
| 1005 | LOG(INFO) << "scan from " << (*reverse_op_indexes)[old_dst] + 1 |
| 1006 | << " to " << op_indexes->size(); |
| 1007 | for (vector<Vertex::Index>::size_type i = (*reverse_op_indexes)[old_dst] + 1, |
| 1008 | e = op_indexes->size(); i < e; ++i) { |
| 1009 | Vertex::Index test_node = (*op_indexes)[i]; |
| 1010 | if (!(*graph)[test_node].valid) |
| 1011 | continue; |
| 1012 | // See if this node has sufficient blocks |
| 1013 | ExtentRanges ranges; |
| 1014 | ranges.AddRepeatedExtents((*graph)[test_node].op.dst_extents()); |
| 1015 | ranges.SubtractExtent(ExtentForRange( |
| 1016 | kTempBlockStart, kSparseHole - kTempBlockStart)); |
| 1017 | ranges.SubtractRepeatedExtents((*graph)[test_node].op.src_extents()); |
| 1018 | // For now, for simplicity, subtract out all blocks in read-before |
| 1019 | // dependencies. |
| 1020 | for (Vertex::EdgeMap::const_iterator edge_i = |
| 1021 | (*graph)[test_node].out_edges.begin(), |
| 1022 | edge_e = (*graph)[test_node].out_edges.end(); |
| 1023 | edge_i != edge_e; ++edge_i) { |
| 1024 | ranges.SubtractExtents(edge_i->second.extents); |
| 1025 | } |
| 1026 | if (ranges.blocks() == 0) |
| 1027 | continue; |
| 1028 | |
| 1029 | if (ranges.blocks() + scratch_blocks_found > blocks_needed) { |
| 1030 | // trim down ranges |
| 1031 | vector<Extent> new_ranges = ranges.GetExtentsForBlockCount( |
| 1032 | blocks_needed - scratch_blocks_found); |
| 1033 | ranges = ExtentRanges(); |
| 1034 | ranges.AddExtents(new_ranges); |
| 1035 | } |
| 1036 | scratch_ranges.AddRanges(ranges); |
| 1037 | block_suppliers.push_back(make_pair(test_node, ranges)); |
| 1038 | scratch_blocks_found += ranges.blocks(); |
| 1039 | LOG(INFO) << "Adding " << ranges.blocks() << " blocks. Now have " |
| 1040 | << scratch_ranges.blocks(); |
| 1041 | if (scratch_ranges.blocks() >= blocks_needed) |
| 1042 | break; |
| 1043 | } |
| 1044 | if (scratch_ranges.blocks() < blocks_needed) { |
| 1045 | LOG(INFO) << "Unable to find sufficient scratch"; |
| 1046 | TEST_AND_RETURN_FALSE(ConvertCutsToFull(graph, |
| 1047 | new_root, |
| 1048 | data_fd, |
| 1049 | data_file_size, |
| 1050 | op_indexes, |
| 1051 | reverse_op_indexes, |
| 1052 | cuts)); |
| 1053 | return true; |
| 1054 | } |
| 1055 | // Use the scratch we found |
| 1056 | TEST_AND_RETURN_FALSE(scratch_ranges.blocks() == scratch_blocks_found); |
| 1057 | |
| 1058 | // Make all the suppliers depend on this node |
| 1059 | for (SupplierVector::iterator it = block_suppliers.begin(), |
| 1060 | e = block_suppliers.end(); it != e; ++it) { |
| 1061 | graph_utils::AddReadBeforeDepExtents( |
| 1062 | &(*graph)[it->first], |
| 1063 | old_dst, |
| 1064 | it->second.GetExtentsForBlockCount(it->second.blocks())); |
| 1065 | } |
Darin Petkov | bc58a7b | 2010-11-03 11:52:53 -0700 | [diff] [blame^] | 1066 | |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1067 | // Replace temp blocks in each cut |
| 1068 | for (vector<CutEdgeVertexes>::const_iterator it = cuts.begin(), |
| 1069 | e = cuts.end(); it != e; ++it) { |
| 1070 | vector<Extent> real_extents = |
| 1071 | scratch_ranges.GetExtentsForBlockCount(cuts_blocks_needed[&*it]); |
| 1072 | scratch_ranges.SubtractExtents(real_extents); |
| 1073 | |
| 1074 | // Fix the old dest node w/ the real blocks |
| 1075 | DeltaDiffGenerator::SubstituteBlocks(&(*graph)[old_dst], |
| 1076 | it->tmp_extents, |
| 1077 | real_extents); |
| 1078 | |
| 1079 | // Fix the new node w/ the real blocks. Since the new node is just a |
| 1080 | // copy operation, we can replace all the dest extents w/ the real |
| 1081 | // blocks. |
| 1082 | DeltaArchiveManifest_InstallOperation *op = |
| 1083 | &(*graph)[it->new_vertex].op; |
| 1084 | op->clear_dst_extents(); |
| 1085 | DeltaDiffGenerator::StoreExtents(real_extents, op->mutable_dst_extents()); |
| 1086 | } |
| 1087 | LOG(INFO) << "Done subbing in for cut set"; |
| 1088 | return true; |
| 1089 | } |
| 1090 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1091 | } // namespace {} |
| 1092 | |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 1093 | // Returns true if |op| is a no-op operation that doesn't do any useful work |
| 1094 | // (e.g., a move operation that copies blocks onto themselves). |
| 1095 | bool DeltaDiffGenerator::IsNoopOperation( |
| 1096 | const DeltaArchiveManifest_InstallOperation& op) { |
| 1097 | return (op.type() == DeltaArchiveManifest_InstallOperation_Type_MOVE && |
| 1098 | ExpandExtents(op.src_extents()) == ExpandExtents(op.dst_extents())); |
| 1099 | } |
| 1100 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1101 | bool DeltaDiffGenerator::AssignTempBlocks( |
| 1102 | Graph* graph, |
| 1103 | const string& new_root, |
| 1104 | int data_fd, |
| 1105 | off_t* data_file_size, |
| 1106 | vector<Vertex::Index>* op_indexes, |
| 1107 | vector<vector<Vertex::Index>::size_type>* reverse_op_indexes, |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1108 | const vector<CutEdgeVertexes>& cuts) { |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1109 | CHECK(!cuts.empty()); |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1110 | |
| 1111 | // group of cuts w/ the same old_dst: |
| 1112 | vector<CutEdgeVertexes> cuts_group; |
| 1113 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1114 | for (vector<CutEdgeVertexes>::size_type i = cuts.size() - 1, e = 0; |
| 1115 | true ; --i) { |
| 1116 | LOG(INFO) << "Fixing temp blocks in cut " << i |
| 1117 | << ": old dst: " << cuts[i].old_dst << " new vertex: " |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1118 | << cuts[i].new_vertex << " path: " |
| 1119 | << (*graph)[cuts[i].old_dst].file_name; |
| 1120 | |
| 1121 | if (cuts_group.empty() || (cuts_group[0].old_dst == cuts[i].old_dst)) { |
| 1122 | cuts_group.push_back(cuts[i]); |
| 1123 | } else { |
| 1124 | CHECK(!cuts_group.empty()); |
| 1125 | TEST_AND_RETURN_FALSE(AssignBlockForAdjoiningCuts(graph, |
| 1126 | new_root, |
| 1127 | data_fd, |
| 1128 | data_file_size, |
| 1129 | op_indexes, |
| 1130 | reverse_op_indexes, |
| 1131 | cuts_group)); |
| 1132 | cuts_group.clear(); |
| 1133 | cuts_group.push_back(cuts[i]); |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1134 | } |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 1135 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1136 | if (i == e) { |
| 1137 | // break out of for() loop |
| 1138 | break; |
| 1139 | } |
| 1140 | } |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1141 | CHECK(!cuts_group.empty()); |
| 1142 | TEST_AND_RETURN_FALSE(AssignBlockForAdjoiningCuts(graph, |
| 1143 | new_root, |
| 1144 | data_fd, |
| 1145 | data_file_size, |
| 1146 | op_indexes, |
| 1147 | reverse_op_indexes, |
| 1148 | cuts_group)); |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1149 | return true; |
| 1150 | } |
| 1151 | |
| 1152 | bool DeltaDiffGenerator::NoTempBlocksRemain(const Graph& graph) { |
| 1153 | size_t idx = 0; |
| 1154 | for (Graph::const_iterator it = graph.begin(), e = graph.end(); it != e; |
| 1155 | ++it, ++idx) { |
| 1156 | if (!it->valid) |
| 1157 | continue; |
| 1158 | const DeltaArchiveManifest_InstallOperation& op = it->op; |
| 1159 | if (TempBlocksExistInExtents(op.dst_extents()) || |
| 1160 | TempBlocksExistInExtents(op.src_extents())) { |
| 1161 | LOG(INFO) << "bad extents in node " << idx; |
| 1162 | LOG(INFO) << "so yeah"; |
| 1163 | return false; |
| 1164 | } |
| 1165 | |
| 1166 | // Check out-edges: |
| 1167 | for (Vertex::EdgeMap::const_iterator jt = it->out_edges.begin(), |
| 1168 | je = it->out_edges.end(); jt != je; ++jt) { |
| 1169 | if (TempBlocksExistInExtents(jt->second.extents) || |
| 1170 | TempBlocksExistInExtents(jt->second.write_extents)) { |
| 1171 | LOG(INFO) << "bad out edge in node " << idx; |
| 1172 | LOG(INFO) << "so yeah"; |
| 1173 | return false; |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | return true; |
| 1178 | } |
| 1179 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1180 | bool DeltaDiffGenerator::ReorderDataBlobs( |
| 1181 | DeltaArchiveManifest* manifest, |
| 1182 | const std::string& data_blobs_path, |
| 1183 | const std::string& new_data_blobs_path) { |
| 1184 | int in_fd = open(data_blobs_path.c_str(), O_RDONLY, 0); |
| 1185 | TEST_AND_RETURN_FALSE_ERRNO(in_fd >= 0); |
| 1186 | ScopedFdCloser in_fd_closer(&in_fd); |
Chris Masone | 790e62e | 2010-08-12 10:41:18 -0700 | [diff] [blame] | 1187 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1188 | DirectFileWriter writer; |
| 1189 | TEST_AND_RETURN_FALSE( |
| 1190 | writer.Open(new_data_blobs_path.c_str(), |
| 1191 | O_WRONLY | O_TRUNC | O_CREAT, |
| 1192 | 0644) == 0); |
| 1193 | ScopedFileWriterCloser writer_closer(&writer); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 1194 | uint64_t out_file_size = 0; |
Chris Masone | 790e62e | 2010-08-12 10:41:18 -0700 | [diff] [blame] | 1195 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 1196 | for (int i = 0; i < (manifest->install_operations_size() + |
| 1197 | manifest->kernel_install_operations_size()); i++) { |
| 1198 | DeltaArchiveManifest_InstallOperation* op = NULL; |
| 1199 | if (i < manifest->install_operations_size()) { |
| 1200 | op = manifest->mutable_install_operations(i); |
| 1201 | } else { |
| 1202 | op = manifest->mutable_kernel_install_operations( |
| 1203 | i - manifest->install_operations_size()); |
| 1204 | } |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1205 | if (!op->has_data_offset()) |
| 1206 | continue; |
| 1207 | CHECK(op->has_data_length()); |
| 1208 | vector<char> buf(op->data_length()); |
| 1209 | ssize_t rc = pread(in_fd, &buf[0], buf.size(), op->data_offset()); |
| 1210 | TEST_AND_RETURN_FALSE(rc == static_cast<ssize_t>(buf.size())); |
| 1211 | |
| 1212 | op->set_data_offset(out_file_size); |
| 1213 | TEST_AND_RETURN_FALSE(writer.Write(&buf[0], buf.size()) == |
| 1214 | static_cast<ssize_t>(buf.size())); |
| 1215 | out_file_size += buf.size(); |
| 1216 | } |
| 1217 | return true; |
| 1218 | } |
| 1219 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1220 | bool DeltaDiffGenerator::ConvertCutToFullOp(Graph* graph, |
| 1221 | const CutEdgeVertexes& cut, |
| 1222 | const string& new_root, |
| 1223 | int data_fd, |
| 1224 | off_t* data_file_size) { |
| 1225 | // Drop all incoming edges, keep all outgoing edges |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 1226 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1227 | // Keep all outgoing edges |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1228 | if ((*graph)[cut.old_dst].op.type() != |
| 1229 | DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ && |
| 1230 | (*graph)[cut.old_dst].op.type() != |
| 1231 | DeltaArchiveManifest_InstallOperation_Type_REPLACE) { |
| 1232 | Vertex::EdgeMap out_edges = (*graph)[cut.old_dst].out_edges; |
| 1233 | graph_utils::DropWriteBeforeDeps(&out_edges); |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 1234 | |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1235 | TEST_AND_RETURN_FALSE(DeltaReadFile(graph, |
| 1236 | cut.old_dst, |
| 1237 | NULL, |
| 1238 | "/-!@:&*nonexistent_path", |
| 1239 | new_root, |
| 1240 | (*graph)[cut.old_dst].file_name, |
| 1241 | data_fd, |
| 1242 | data_file_size)); |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 1243 | |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1244 | (*graph)[cut.old_dst].out_edges = out_edges; |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1245 | |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1246 | // Right now we don't have doubly-linked edges, so we have to scan |
| 1247 | // the whole graph. |
| 1248 | graph_utils::DropIncomingEdgesTo(graph, cut.old_dst); |
| 1249 | } |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1250 | |
| 1251 | // Delete temp node |
| 1252 | (*graph)[cut.old_src].out_edges.erase(cut.new_vertex); |
| 1253 | CHECK((*graph)[cut.old_dst].out_edges.find(cut.new_vertex) == |
| 1254 | (*graph)[cut.old_dst].out_edges.end()); |
| 1255 | (*graph)[cut.new_vertex].valid = false; |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1256 | LOG(INFO) << "marked node invalid: " << cut.new_vertex; |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1257 | return true; |
| 1258 | } |
| 1259 | |
| 1260 | bool DeltaDiffGenerator::ConvertGraphToDag(Graph* graph, |
| 1261 | const string& new_root, |
| 1262 | int fd, |
| 1263 | off_t* data_file_size, |
| 1264 | vector<Vertex::Index>* final_order) { |
| 1265 | CycleBreaker cycle_breaker; |
| 1266 | LOG(INFO) << "Finding cycles..."; |
| 1267 | set<Edge> cut_edges; |
| 1268 | cycle_breaker.BreakCycles(*graph, &cut_edges); |
| 1269 | LOG(INFO) << "done finding cycles"; |
| 1270 | CheckGraph(*graph); |
| 1271 | |
| 1272 | // Calculate number of scratch blocks needed |
| 1273 | |
| 1274 | LOG(INFO) << "Cutting cycles..."; |
| 1275 | vector<CutEdgeVertexes> cuts; |
| 1276 | TEST_AND_RETURN_FALSE(CutEdges(graph, cut_edges, &cuts)); |
| 1277 | LOG(INFO) << "done cutting cycles"; |
| 1278 | LOG(INFO) << "There are " << cuts.size() << " cuts."; |
| 1279 | CheckGraph(*graph); |
| 1280 | |
| 1281 | LOG(INFO) << "Creating initial topological order..."; |
| 1282 | TopologicalSort(*graph, final_order); |
| 1283 | LOG(INFO) << "done with initial topo order"; |
| 1284 | CheckGraph(*graph); |
| 1285 | |
| 1286 | LOG(INFO) << "Moving full ops to the back"; |
| 1287 | MoveFullOpsToBack(graph, final_order); |
| 1288 | LOG(INFO) << "done moving full ops to back"; |
| 1289 | |
| 1290 | vector<vector<Vertex::Index>::size_type> inverse_final_order; |
| 1291 | GenerateReverseTopoOrderMap(*final_order, &inverse_final_order); |
| 1292 | |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1293 | SortCutsByTopoOrder(*final_order, &cuts); |
| 1294 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1295 | if (!cuts.empty()) |
| 1296 | TEST_AND_RETURN_FALSE(AssignTempBlocks(graph, |
| 1297 | new_root, |
| 1298 | fd, |
| 1299 | data_file_size, |
| 1300 | final_order, |
| 1301 | &inverse_final_order, |
| 1302 | cuts)); |
| 1303 | LOG(INFO) << "Making sure all temp blocks have been allocated"; |
Andrew de los Reyes | 4ba850d | 2010-10-25 12:12:40 -0700 | [diff] [blame] | 1304 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1305 | graph_utils::DumpGraph(*graph); |
| 1306 | CHECK(NoTempBlocksRemain(*graph)); |
| 1307 | LOG(INFO) << "done making sure all temp blocks are allocated"; |
| 1308 | return true; |
| 1309 | } |
| 1310 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1311 | bool DeltaDiffGenerator::ReadFullUpdateFromDisk( |
| 1312 | Graph* graph, |
| 1313 | const std::string& new_kernel_part, |
| 1314 | const std::string& new_image, |
Darin Petkov | 7ea3233 | 2010-10-13 10:46:11 -0700 | [diff] [blame] | 1315 | off_t image_size, |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1316 | int fd, |
| 1317 | off_t* data_file_size, |
| 1318 | off_t chunk_size, |
| 1319 | vector<DeltaArchiveManifest_InstallOperation>* kernel_ops, |
| 1320 | std::vector<Vertex::Index>* final_order) { |
| 1321 | TEST_AND_RETURN_FALSE(chunk_size > 0); |
| 1322 | TEST_AND_RETURN_FALSE((chunk_size % kBlockSize) == 0); |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 1323 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1324 | // Get the sizes early in the function, so we can fail fast if the user |
| 1325 | // passed us bad paths. |
Darin Petkov | 7ea3233 | 2010-10-13 10:46:11 -0700 | [diff] [blame] | 1326 | TEST_AND_RETURN_FALSE(image_size >= 0 && |
| 1327 | image_size <= utils::FileSize(new_image)); |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1328 | const off_t kernel_size = utils::FileSize(new_kernel_part); |
| 1329 | TEST_AND_RETURN_FALSE(kernel_size >= 0); |
| 1330 | |
| 1331 | off_t part_sizes[] = { image_size, kernel_size }; |
| 1332 | string paths[] = { new_image, new_kernel_part }; |
| 1333 | |
| 1334 | for (int partition = 0; partition < 2; ++partition) { |
| 1335 | const string& path = paths[partition]; |
| 1336 | LOG(INFO) << "compressing " << path; |
| 1337 | |
| 1338 | int in_fd = open(path.c_str(), O_RDONLY, 0); |
| 1339 | TEST_AND_RETURN_FALSE(in_fd >= 0); |
| 1340 | ScopedFdCloser in_fd_closer(&in_fd); |
| 1341 | |
| 1342 | for (off_t bytes_left = part_sizes[partition], counter = 0, offset = 0; |
| 1343 | bytes_left > 0; |
| 1344 | bytes_left -= chunk_size, ++counter, offset += chunk_size) { |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1345 | DeltaArchiveManifest_InstallOperation* op = NULL; |
| 1346 | if (partition == 0) { |
| 1347 | graph->resize(graph->size() + 1); |
| 1348 | graph->back().file_name = path + StringPrintf("-%" PRIi64, counter); |
| 1349 | op = &graph->back().op; |
| 1350 | final_order->push_back(graph->size() - 1); |
| 1351 | } else { |
| 1352 | kernel_ops->resize(kernel_ops->size() + 1); |
| 1353 | op = &kernel_ops->back(); |
| 1354 | } |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 1355 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1356 | vector<char> buf(min(bytes_left, chunk_size)); |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1357 | ssize_t bytes_read = -1; |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 1358 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1359 | TEST_AND_RETURN_FALSE(utils::PReadAll( |
| 1360 | in_fd, &buf[0], buf.size(), offset, &bytes_read)); |
| 1361 | TEST_AND_RETURN_FALSE(bytes_read == static_cast<ssize_t>(buf.size())); |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 1362 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1363 | vector<char> buf_compressed; |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 1364 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1365 | TEST_AND_RETURN_FALSE(BzipCompress(buf, &buf_compressed)); |
| 1366 | const bool compress = buf_compressed.size() < buf.size(); |
| 1367 | const vector<char>& use_buf = compress ? buf_compressed : buf; |
| 1368 | if (compress) { |
| 1369 | op->set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ); |
| 1370 | } else { |
| 1371 | op->set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE); |
| 1372 | } |
| 1373 | op->set_data_offset(*data_file_size); |
Andrew de los Reyes | f88144f | 2010-10-11 10:32:59 -0700 | [diff] [blame] | 1374 | TEST_AND_RETURN_FALSE(utils::WriteAll(fd, &use_buf[0], use_buf.size())); |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1375 | *data_file_size += use_buf.size(); |
| 1376 | op->set_data_length(use_buf.size()); |
| 1377 | Extent* dst_extent = op->add_dst_extents(); |
| 1378 | dst_extent->set_start_block(offset / kBlockSize); |
| 1379 | dst_extent->set_num_blocks(chunk_size / kBlockSize); |
Darin Petkov | bc58a7b | 2010-11-03 11:52:53 -0700 | [diff] [blame^] | 1380 | |
| 1381 | LOG(INFO) << StringPrintf("%.1f", offset * 100.0 / part_sizes[partition]) |
| 1382 | << "% complete (offset: " << offset << ", buf size: " |
| 1383 | << buf.size() << ")"; |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | return true; |
| 1388 | } |
| 1389 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 1390 | bool DeltaDiffGenerator::GenerateDeltaUpdateFile( |
| 1391 | const string& old_root, |
| 1392 | const string& old_image, |
| 1393 | const string& new_root, |
| 1394 | const string& new_image, |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1395 | const string& old_kernel_part, |
| 1396 | const string& new_kernel_part, |
| 1397 | const string& output_path, |
| 1398 | const string& private_key_path) { |
Darin Petkov | 7ea3233 | 2010-10-13 10:46:11 -0700 | [diff] [blame] | 1399 | int old_image_block_count = 0, old_image_block_size = 0; |
| 1400 | int new_image_block_count = 0, new_image_block_size = 0; |
| 1401 | TEST_AND_RETURN_FALSE(utils::GetFilesystemSize(new_image, |
| 1402 | &new_image_block_count, |
| 1403 | &new_image_block_size)); |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1404 | if (!old_image.empty()) { |
Darin Petkov | 7ea3233 | 2010-10-13 10:46:11 -0700 | [diff] [blame] | 1405 | TEST_AND_RETURN_FALSE(utils::GetFilesystemSize(old_image, |
| 1406 | &old_image_block_count, |
| 1407 | &old_image_block_size)); |
| 1408 | TEST_AND_RETURN_FALSE(old_image_block_size == new_image_block_size); |
| 1409 | LOG_IF(WARNING, old_image_block_count != new_image_block_count) |
| 1410 | << "Old and new images have different block counts."; |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1411 | } |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 1412 | // Sanity check kernel partition arg |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 1413 | TEST_AND_RETURN_FALSE(utils::FileSize(new_kernel_part) >= 0); |
| 1414 | |
Darin Petkov | 7ea3233 | 2010-10-13 10:46:11 -0700 | [diff] [blame] | 1415 | vector<Block> blocks(max(old_image_block_count, new_image_block_count)); |
| 1416 | LOG(INFO) << "Invalid block index: " << Vertex::kInvalidIndex; |
| 1417 | LOG(INFO) << "Block count: " << blocks.size(); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1418 | for (vector<Block>::size_type i = 0; i < blocks.size(); i++) { |
| 1419 | CHECK(blocks[i].reader == Vertex::kInvalidIndex); |
| 1420 | CHECK(blocks[i].writer == Vertex::kInvalidIndex); |
| 1421 | } |
| 1422 | Graph graph; |
| 1423 | CheckGraph(graph); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1424 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1425 | const string kTempFileTemplate("/tmp/CrAU_temp_data.XXXXXX"); |
| 1426 | string temp_file_path; |
| 1427 | off_t data_file_size = 0; |
| 1428 | |
| 1429 | LOG(INFO) << "Reading files..."; |
| 1430 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 1431 | vector<DeltaArchiveManifest_InstallOperation> kernel_ops; |
| 1432 | |
Andrew de los Reyes | ef01755 | 2010-10-06 17:57:52 -0700 | [diff] [blame] | 1433 | vector<Vertex::Index> final_order; |
Andrew de los Reyes | f88144f | 2010-10-11 10:32:59 -0700 | [diff] [blame] | 1434 | { |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1435 | int fd; |
| 1436 | TEST_AND_RETURN_FALSE( |
| 1437 | utils::MakeTempFile(kTempFileTemplate, &temp_file_path, &fd)); |
| 1438 | TEST_AND_RETURN_FALSE(fd >= 0); |
| 1439 | ScopedFdCloser fd_closer(&fd); |
Andrew de los Reyes | f88144f | 2010-10-11 10:32:59 -0700 | [diff] [blame] | 1440 | if (!old_image.empty()) { |
| 1441 | // Delta update |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1442 | |
Andrew de los Reyes | f88144f | 2010-10-11 10:32:59 -0700 | [diff] [blame] | 1443 | TEST_AND_RETURN_FALSE(DeltaReadFiles(&graph, |
| 1444 | &blocks, |
| 1445 | old_root, |
| 1446 | new_root, |
| 1447 | fd, |
| 1448 | &data_file_size)); |
| 1449 | LOG(INFO) << "done reading normal files"; |
| 1450 | CheckGraph(graph); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1451 | |
Andrew de los Reyes | f88144f | 2010-10-11 10:32:59 -0700 | [diff] [blame] | 1452 | graph.resize(graph.size() + 1); |
| 1453 | TEST_AND_RETURN_FALSE(ReadUnwrittenBlocks(blocks, |
| 1454 | fd, |
| 1455 | &data_file_size, |
| 1456 | new_image, |
| 1457 | &graph.back())); |
| 1458 | |
| 1459 | // Read kernel partition |
| 1460 | TEST_AND_RETURN_FALSE(DeltaCompressKernelPartition(old_kernel_part, |
| 1461 | new_kernel_part, |
| 1462 | &kernel_ops, |
| 1463 | fd, |
| 1464 | &data_file_size)); |
| 1465 | |
| 1466 | LOG(INFO) << "done reading kernel"; |
| 1467 | CheckGraph(graph); |
| 1468 | |
| 1469 | LOG(INFO) << "Creating edges..."; |
| 1470 | CreateEdges(&graph, blocks); |
| 1471 | LOG(INFO) << "Done creating edges"; |
| 1472 | CheckGraph(graph); |
| 1473 | |
| 1474 | TEST_AND_RETURN_FALSE(ConvertGraphToDag(&graph, |
| 1475 | new_root, |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1476 | fd, |
| 1477 | &data_file_size, |
Andrew de los Reyes | f88144f | 2010-10-11 10:32:59 -0700 | [diff] [blame] | 1478 | &final_order)); |
| 1479 | } else { |
| 1480 | // Full update |
Darin Petkov | 7ea3233 | 2010-10-13 10:46:11 -0700 | [diff] [blame] | 1481 | off_t new_image_size = |
| 1482 | static_cast<off_t>(new_image_block_count) * new_image_block_size; |
Andrew de los Reyes | f88144f | 2010-10-11 10:32:59 -0700 | [diff] [blame] | 1483 | TEST_AND_RETURN_FALSE(ReadFullUpdateFromDisk(&graph, |
| 1484 | new_kernel_part, |
| 1485 | new_image, |
Darin Petkov | 7ea3233 | 2010-10-13 10:46:11 -0700 | [diff] [blame] | 1486 | new_image_size, |
Andrew de los Reyes | f88144f | 2010-10-11 10:32:59 -0700 | [diff] [blame] | 1487 | fd, |
| 1488 | &data_file_size, |
| 1489 | kFullUpdateChunkSize, |
| 1490 | &kernel_ops, |
| 1491 | &final_order)); |
| 1492 | } |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1493 | } |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1494 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1495 | // Convert to protobuf Manifest object |
| 1496 | DeltaArchiveManifest manifest; |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 1497 | OperationNameMap op_name_map; |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1498 | CheckGraph(graph); |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 1499 | InstallOperationsToManifest(graph, |
| 1500 | final_order, |
| 1501 | kernel_ops, |
| 1502 | &manifest, |
| 1503 | &op_name_map); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1504 | CheckGraph(graph); |
| 1505 | manifest.set_block_size(kBlockSize); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1506 | |
| 1507 | // Reorder the data blobs with the newly ordered manifest |
| 1508 | string ordered_blobs_path; |
| 1509 | TEST_AND_RETURN_FALSE(utils::MakeTempFile( |
| 1510 | "/tmp/CrAU_temp_data.ordered.XXXXXX", |
| 1511 | &ordered_blobs_path, |
| 1512 | false)); |
| 1513 | TEST_AND_RETURN_FALSE(ReorderDataBlobs(&manifest, |
| 1514 | temp_file_path, |
| 1515 | ordered_blobs_path)); |
| 1516 | |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 1517 | // Check that install op blobs are in order. |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1518 | uint64_t next_blob_offset = 0; |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1519 | { |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 1520 | for (int i = 0; i < (manifest.install_operations_size() + |
| 1521 | manifest.kernel_install_operations_size()); i++) { |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1522 | DeltaArchiveManifest_InstallOperation* op = |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 1523 | i < manifest.install_operations_size() ? |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1524 | manifest.mutable_install_operations(i) : |
| 1525 | manifest.mutable_kernel_install_operations( |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 1526 | i - manifest.install_operations_size()); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1527 | if (op->has_data_offset()) { |
| 1528 | if (op->data_offset() != next_blob_offset) { |
| 1529 | LOG(FATAL) << "bad blob offset! " << op->data_offset() << " != " |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1530 | << next_blob_offset; |
| 1531 | } |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1532 | next_blob_offset += op->data_length(); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1533 | } |
| 1534 | } |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1537 | // Signatures appear at the end of the blobs. Note the offset in the |
| 1538 | // manifest |
| 1539 | if (!private_key_path.empty()) { |
| 1540 | LOG(INFO) << "Making room for signature in file"; |
| 1541 | manifest.set_signatures_offset(next_blob_offset); |
| 1542 | LOG(INFO) << "set? " << manifest.has_signatures_offset(); |
| 1543 | // Add a dummy op at the end to appease older clients |
| 1544 | DeltaArchiveManifest_InstallOperation* dummy_op = |
| 1545 | manifest.add_kernel_install_operations(); |
| 1546 | dummy_op->set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE); |
| 1547 | dummy_op->set_data_offset(next_blob_offset); |
| 1548 | manifest.set_signatures_offset(next_blob_offset); |
| 1549 | uint64_t signature_blob_length = 0; |
| 1550 | TEST_AND_RETURN_FALSE( |
| 1551 | PayloadSigner::SignatureBlobLength(private_key_path, |
| 1552 | &signature_blob_length)); |
| 1553 | dummy_op->set_data_length(signature_blob_length); |
| 1554 | manifest.set_signatures_size(signature_blob_length); |
| 1555 | Extent* dummy_extent = dummy_op->add_dst_extents(); |
| 1556 | // Tell the dummy op to write this data to a big sparse hole |
| 1557 | dummy_extent->set_start_block(kSparseHole); |
| 1558 | dummy_extent->set_num_blocks((signature_blob_length + kBlockSize - 1) / |
| 1559 | kBlockSize); |
| 1560 | } |
| 1561 | |
Darin Petkov | 36a5822 | 2010-10-07 22:00:09 -0700 | [diff] [blame] | 1562 | TEST_AND_RETURN_FALSE(InitializePartitionInfos(old_kernel_part, |
| 1563 | new_kernel_part, |
| 1564 | old_image, |
| 1565 | new_image, |
| 1566 | &manifest)); |
| 1567 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1568 | // Serialize protobuf |
| 1569 | string serialized_manifest; |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1570 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1571 | CheckGraph(graph); |
| 1572 | TEST_AND_RETURN_FALSE(manifest.AppendToString(&serialized_manifest)); |
| 1573 | CheckGraph(graph); |
| 1574 | |
| 1575 | LOG(INFO) << "Writing final delta file header..."; |
| 1576 | DirectFileWriter writer; |
| 1577 | TEST_AND_RETURN_FALSE_ERRNO(writer.Open(output_path.c_str(), |
| 1578 | O_WRONLY | O_CREAT | O_TRUNC, |
| 1579 | 0644) == 0); |
| 1580 | ScopedFileWriterCloser writer_closer(&writer); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1581 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1582 | // Write header |
| 1583 | TEST_AND_RETURN_FALSE(writer.Write(kDeltaMagic, strlen(kDeltaMagic)) == |
Andrew de los Reyes | 08c4e27 | 2010-04-15 14:02:17 -0700 | [diff] [blame] | 1584 | static_cast<ssize_t>(strlen(kDeltaMagic))); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1585 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1586 | // Write version number |
| 1587 | TEST_AND_RETURN_FALSE(WriteUint64AsBigEndian(&writer, kVersionNumber)); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1588 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1589 | // Write protobuf length |
| 1590 | TEST_AND_RETURN_FALSE(WriteUint64AsBigEndian(&writer, |
| 1591 | serialized_manifest.size())); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1592 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1593 | // Write protobuf |
| 1594 | LOG(INFO) << "Writing final delta file protobuf... " |
| 1595 | << serialized_manifest.size(); |
| 1596 | TEST_AND_RETURN_FALSE(writer.Write(serialized_manifest.data(), |
| 1597 | serialized_manifest.size()) == |
| 1598 | static_cast<ssize_t>(serialized_manifest.size())); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1599 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1600 | // Append the data blobs |
| 1601 | LOG(INFO) << "Writing final delta file data blobs..."; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 1602 | int blobs_fd = open(ordered_blobs_path.c_str(), O_RDONLY, 0); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1603 | ScopedFdCloser blobs_fd_closer(&blobs_fd); |
| 1604 | TEST_AND_RETURN_FALSE(blobs_fd >= 0); |
| 1605 | for (;;) { |
| 1606 | char buf[kBlockSize]; |
| 1607 | ssize_t rc = read(blobs_fd, buf, sizeof(buf)); |
| 1608 | if (0 == rc) { |
| 1609 | // EOF |
| 1610 | break; |
| 1611 | } |
| 1612 | TEST_AND_RETURN_FALSE_ERRNO(rc > 0); |
| 1613 | TEST_AND_RETURN_FALSE(writer.Write(buf, rc) == rc); |
| 1614 | } |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 1615 | |
| 1616 | // Write signature blob. |
| 1617 | if (!private_key_path.empty()) { |
| 1618 | LOG(INFO) << "Signing the update..."; |
| 1619 | vector<char> signature_blob; |
| 1620 | TEST_AND_RETURN_FALSE(PayloadSigner::SignPayload(output_path, |
| 1621 | private_key_path, |
| 1622 | &signature_blob)); |
| 1623 | TEST_AND_RETURN_FALSE(writer.Write(&signature_blob[0], |
| 1624 | signature_blob.size()) == |
| 1625 | static_cast<ssize_t>(signature_blob.size())); |
| 1626 | } |
| 1627 | |
Darin Petkov | 95cf01f | 2010-10-12 14:59:13 -0700 | [diff] [blame] | 1628 | int64_t manifest_metadata_size = |
| 1629 | strlen(kDeltaMagic) + 2 * sizeof(uint64_t) + serialized_manifest.size(); |
Darin Petkov | 9fa7ec5 | 2010-10-18 11:45:23 -0700 | [diff] [blame] | 1630 | ReportPayloadUsage(manifest, manifest_metadata_size, op_name_map); |
Darin Petkov | 880335c | 2010-10-01 15:52:53 -0700 | [diff] [blame] | 1631 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1632 | LOG(INFO) << "All done. Successfully created delta file."; |
| 1633 | return true; |
| 1634 | } |
| 1635 | |
Andrew de los Reyes | 50f3649 | 2010-11-01 13:57:12 -0700 | [diff] [blame] | 1636 | const char* const kBsdiffPath = "bsdiff"; |
| 1637 | const char* const kBspatchPath = "bspatch"; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 1638 | const char* const kDeltaMagic = "CrAU"; |
| 1639 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 1640 | }; // namespace chromeos_update_engine |