Gilad Arnold | 6dbbd39 | 2012-07-10 16:19:11 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 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/filesystem_copier_action.h" |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 6 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 7 | #include <sys/stat.h> |
| 8 | #include <sys/types.h> |
| 9 | #include <errno.h> |
| 10 | #include <fcntl.h> |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 11 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 12 | #include <algorithm> |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 13 | #include <cstdlib> |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 14 | #include <map> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 17 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 18 | #include <gio/gio.h> |
| 19 | #include <gio/gunixinputstream.h> |
| 20 | #include <gio/gunixoutputstream.h> |
| 21 | #include <glib.h> |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 22 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 23 | #include "update_engine/filesystem_iterator.h" |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 24 | #include "update_engine/hardware_interface.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 25 | #include "update_engine/subprocess.h" |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 26 | #include "update_engine/system_state.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 27 | #include "update_engine/utils.h" |
| 28 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 29 | using std::map; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 30 | using std::min; |
| 31 | using std::string; |
| 32 | using std::vector; |
| 33 | |
| 34 | namespace chromeos_update_engine { |
| 35 | |
| 36 | namespace { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 37 | const off_t kCopyFileBufferSize = 128 * 1024; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 38 | } // namespace {} |
| 39 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 40 | FilesystemCopierAction::FilesystemCopierAction( |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 41 | SystemState* system_state, |
Gilad Arnold | 581c2ea | 2012-07-19 12:33:49 -0700 | [diff] [blame] | 42 | bool copying_kernel_install_path, |
| 43 | bool verify_hash) |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 44 | : copying_kernel_install_path_(copying_kernel_install_path), |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 45 | verify_hash_(verify_hash), |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 46 | src_stream_(NULL), |
| 47 | dst_stream_(NULL), |
| 48 | read_done_(false), |
| 49 | failed_(false), |
| 50 | cancelled_(false), |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 51 | filesystem_size_(kint64max), |
| 52 | system_state_(system_state) { |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 53 | // A lot of code works on the implicit assumption that processing is done on |
| 54 | // exactly 2 ping-pong buffers. |
| 55 | COMPILE_ASSERT(arraysize(buffer_) == 2 && |
| 56 | arraysize(buffer_state_) == 2 && |
| 57 | arraysize(buffer_valid_size_) == 2 && |
| 58 | arraysize(canceller_) == 2, |
| 59 | ping_pong_buffers_not_two); |
| 60 | for (int i = 0; i < 2; ++i) { |
| 61 | buffer_state_[i] = kBufferStateEmpty; |
| 62 | buffer_valid_size_[i] = 0; |
| 63 | canceller_[i] = NULL; |
| 64 | } |
| 65 | } |
| 66 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 67 | void FilesystemCopierAction::PerformAction() { |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 68 | // Will tell the ActionProcessor we've failed if we return. |
| 69 | ScopedActionCompleter abort_action_completer(processor_, this); |
| 70 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 71 | if (!HasInputObject()) { |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 72 | LOG(ERROR) << "FilesystemCopierAction missing input object."; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 73 | return; |
| 74 | } |
| 75 | install_plan_ = GetInputObject(); |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 76 | if (!verify_hash_ && |
| 77 | (install_plan_.is_resume || install_plan_.is_full_update)) { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 78 | // No copy or hash verification needed. Done! |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 79 | LOG(INFO) << "filesystem copying skipped: " |
| 80 | << (install_plan_.is_resume ? "resumed" : "full") << " update"; |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 81 | if (HasOutputPipe()) |
| 82 | SetOutputObject(install_plan_); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 83 | abort_action_completer.set_code(kErrorCodeSuccess); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 84 | return; |
| 85 | } |
| 86 | |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 87 | const string destination = copying_kernel_install_path_ ? |
| 88 | install_plan_.kernel_install_path : |
| 89 | install_plan_.install_path; |
| 90 | string source = verify_hash_ ? destination : copy_source_; |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 91 | if (source.empty()) { |
| 92 | source = copying_kernel_install_path_ ? |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 93 | system_state_->hardware()->KernelDeviceOfBootDevice( |
| 94 | system_state_->hardware()->BootDevice()) : |
| 95 | system_state_->hardware()->BootDevice(); |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 96 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 97 | int src_fd = open(source.c_str(), O_RDONLY); |
| 98 | if (src_fd < 0) { |
| 99 | PLOG(ERROR) << "Unable to open " << source << " for reading:"; |
| 100 | return; |
| 101 | } |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 102 | |
| 103 | if (!verify_hash_) { |
| 104 | int dst_fd = open(destination.c_str(), |
| 105 | O_WRONLY | O_TRUNC | O_CREAT, |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 106 | 0644); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 107 | if (dst_fd < 0) { |
| 108 | close(src_fd); |
| 109 | PLOG(ERROR) << "Unable to open " << install_plan_.install_path |
| 110 | << " for writing:"; |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | dst_stream_ = g_unix_output_stream_new(dst_fd, TRUE); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 117 | DetermineFilesystemSize(src_fd); |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 118 | src_stream_ = g_unix_input_stream_new(src_fd, TRUE); |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 119 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 120 | for (int i = 0; i < 2; i++) { |
| 121 | buffer_[i].resize(kCopyFileBufferSize); |
| 122 | canceller_[i] = g_cancellable_new(); |
| 123 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 124 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 125 | // Start the first read. |
| 126 | SpawnAsyncActions(); |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 127 | |
| 128 | abort_action_completer.set_should_complete(false); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void FilesystemCopierAction::TerminateProcessing() { |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 132 | for (int i = 0; i < 2; i++) { |
| 133 | if (canceller_[i]) { |
| 134 | g_cancellable_cancel(canceller_[i]); |
| 135 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Ben Chan | 2add7d7 | 2012-10-08 19:28:37 -0700 | [diff] [blame] | 139 | bool FilesystemCopierAction::IsCleanupPending() const { |
| 140 | return (src_stream_ != NULL); |
| 141 | } |
| 142 | |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 143 | void FilesystemCopierAction::Cleanup(ErrorCode code) { |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 144 | for (int i = 0; i < 2; i++) { |
| 145 | g_object_unref(canceller_[i]); |
| 146 | canceller_[i] = NULL; |
| 147 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 148 | g_object_unref(src_stream_); |
| 149 | src_stream_ = NULL; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 150 | if (dst_stream_) { |
| 151 | g_object_unref(dst_stream_); |
| 152 | dst_stream_ = NULL; |
| 153 | } |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 154 | if (cancelled_) |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 155 | return; |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 156 | if (code == kErrorCodeSuccess && HasOutputPipe()) |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 157 | SetOutputObject(install_plan_); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 158 | processor_->ActionComplete(this, code); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 161 | void FilesystemCopierAction::AsyncReadReadyCallback(GObject *source_object, |
| 162 | GAsyncResult *res) { |
| 163 | int index = buffer_state_[0] == kBufferStateReading ? 0 : 1; |
| 164 | CHECK(buffer_state_[index] == kBufferStateReading); |
| 165 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 166 | GError* error = NULL; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 167 | CHECK(canceller_[index]); |
| 168 | cancelled_ = g_cancellable_is_cancelled(canceller_[index]) == TRUE; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 169 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 170 | ssize_t bytes_read = g_input_stream_read_finish(src_stream_, res, &error); |
| 171 | if (bytes_read < 0) { |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 172 | LOG(ERROR) << "Read failed: " << utils::GetAndFreeGError(&error); |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 173 | failed_ = true; |
| 174 | buffer_state_[index] = kBufferStateEmpty; |
| 175 | } else if (bytes_read == 0) { |
| 176 | read_done_ = true; |
| 177 | buffer_state_[index] = kBufferStateEmpty; |
| 178 | } else { |
| 179 | buffer_valid_size_[index] = bytes_read; |
| 180 | buffer_state_[index] = kBufferStateFull; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 181 | filesystem_size_ -= bytes_read; |
| 182 | } |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 183 | SpawnAsyncActions(); |
| 184 | |
| 185 | if (bytes_read > 0) { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 186 | // If read_done_ is set, SpawnAsyncActions may finalize the hash so the hash |
| 187 | // update below would happen too late. |
| 188 | CHECK(!read_done_); |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 189 | if (!hasher_.Update(buffer_[index].data(), bytes_read)) { |
| 190 | LOG(ERROR) << "Unable to update the hash."; |
| 191 | failed_ = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 192 | } |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 193 | if (verify_hash_) { |
| 194 | buffer_state_[index] = kBufferStateEmpty; |
| 195 | } |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 196 | } |
| 197 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 198 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 199 | void FilesystemCopierAction::StaticAsyncReadReadyCallback( |
| 200 | GObject *source_object, |
| 201 | GAsyncResult *res, |
| 202 | gpointer user_data) { |
| 203 | reinterpret_cast<FilesystemCopierAction*>(user_data)-> |
| 204 | AsyncReadReadyCallback(source_object, res); |
| 205 | } |
| 206 | |
| 207 | void FilesystemCopierAction::AsyncWriteReadyCallback(GObject *source_object, |
| 208 | GAsyncResult *res) { |
| 209 | int index = buffer_state_[0] == kBufferStateWriting ? 0 : 1; |
| 210 | CHECK(buffer_state_[index] == kBufferStateWriting); |
Gilad Arnold | 581c2ea | 2012-07-19 12:33:49 -0700 | [diff] [blame] | 211 | buffer_state_[index] = kBufferStateEmpty; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 212 | |
| 213 | GError* error = NULL; |
| 214 | CHECK(canceller_[index]); |
| 215 | cancelled_ = g_cancellable_is_cancelled(canceller_[index]) == TRUE; |
| 216 | |
| 217 | ssize_t bytes_written = g_output_stream_write_finish(dst_stream_, |
| 218 | res, |
| 219 | &error); |
Gilad Arnold | 6dbbd39 | 2012-07-10 16:19:11 -0700 | [diff] [blame] | 220 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 221 | if (bytes_written < static_cast<ssize_t>(buffer_valid_size_[index])) { |
| 222 | if (bytes_written < 0) { |
Gilad Arnold | 6dbbd39 | 2012-07-10 16:19:11 -0700 | [diff] [blame] | 223 | LOG(ERROR) << "Write error: " << utils::GetAndFreeGError(&error); |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 224 | } else { |
Gilad Arnold | 6dbbd39 | 2012-07-10 16:19:11 -0700 | [diff] [blame] | 225 | LOG(ERROR) << "Wrote too few bytes: " << bytes_written |
Gilad Arnold | 581c2ea | 2012-07-19 12:33:49 -0700 | [diff] [blame] | 226 | << " < " << buffer_valid_size_[index]; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 227 | } |
Gilad Arnold | 581c2ea | 2012-07-19 12:33:49 -0700 | [diff] [blame] | 228 | failed_ = true; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | SpawnAsyncActions(); |
| 232 | } |
| 233 | |
| 234 | void FilesystemCopierAction::StaticAsyncWriteReadyCallback( |
| 235 | GObject *source_object, |
| 236 | GAsyncResult *res, |
| 237 | gpointer user_data) { |
| 238 | reinterpret_cast<FilesystemCopierAction*>(user_data)-> |
| 239 | AsyncWriteReadyCallback(source_object, res); |
| 240 | } |
| 241 | |
| 242 | void FilesystemCopierAction::SpawnAsyncActions() { |
| 243 | bool reading = false; |
| 244 | bool writing = false; |
| 245 | for (int i = 0; i < 2; i++) { |
| 246 | if (buffer_state_[i] == kBufferStateReading) { |
| 247 | reading = true; |
| 248 | } |
| 249 | if (buffer_state_[i] == kBufferStateWriting) { |
| 250 | writing = true; |
| 251 | } |
| 252 | } |
| 253 | if (failed_ || cancelled_) { |
| 254 | if (!reading && !writing) { |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 255 | Cleanup(kErrorCodeError); |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 256 | } |
| 257 | return; |
| 258 | } |
| 259 | for (int i = 0; i < 2; i++) { |
| 260 | if (!reading && !read_done_ && buffer_state_[i] == kBufferStateEmpty) { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 261 | int64_t bytes_to_read = std::min(static_cast<int64_t>(buffer_[0].size()), |
| 262 | filesystem_size_); |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 263 | g_input_stream_read_async( |
| 264 | src_stream_, |
| 265 | buffer_[i].data(), |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 266 | bytes_to_read, |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 267 | G_PRIORITY_DEFAULT, |
| 268 | canceller_[i], |
| 269 | &FilesystemCopierAction::StaticAsyncReadReadyCallback, |
| 270 | this); |
| 271 | reading = true; |
| 272 | buffer_state_[i] = kBufferStateReading; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 273 | } else if (!writing && !verify_hash_ && |
| 274 | buffer_state_[i] == kBufferStateFull) { |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 275 | g_output_stream_write_async( |
| 276 | dst_stream_, |
| 277 | buffer_[i].data(), |
| 278 | buffer_valid_size_[i], |
| 279 | G_PRIORITY_DEFAULT, |
| 280 | canceller_[i], |
| 281 | &FilesystemCopierAction::StaticAsyncWriteReadyCallback, |
| 282 | this); |
| 283 | writing = true; |
| 284 | buffer_state_[i] = kBufferStateWriting; |
| 285 | } |
| 286 | } |
| 287 | if (!reading && !writing) { |
| 288 | // We're done! |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 289 | ErrorCode code = kErrorCodeSuccess; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 290 | if (hasher_.Finalize()) { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 291 | LOG(INFO) << "Hash: " << hasher_.hash(); |
| 292 | if (verify_hash_) { |
| 293 | if (copying_kernel_install_path_) { |
| 294 | if (install_plan_.kernel_hash != hasher_.raw_hash()) { |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 295 | code = kErrorCodeNewKernelVerificationError; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 296 | LOG(ERROR) << "New kernel verification failed."; |
| 297 | } |
| 298 | } else { |
| 299 | if (install_plan_.rootfs_hash != hasher_.raw_hash()) { |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 300 | code = kErrorCodeNewRootfsVerificationError; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 301 | LOG(ERROR) << "New rootfs verification failed."; |
| 302 | } |
| 303 | } |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 304 | } else { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 305 | if (copying_kernel_install_path_) { |
| 306 | install_plan_.kernel_hash = hasher_.raw_hash(); |
| 307 | } else { |
| 308 | install_plan_.rootfs_hash = hasher_.raw_hash(); |
| 309 | } |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 310 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 311 | } else { |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 312 | LOG(ERROR) << "Unable to finalize the hash."; |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 313 | code = kErrorCodeError; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 314 | } |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 315 | Cleanup(code); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 316 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 317 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 318 | |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 319 | void FilesystemCopierAction::DetermineFilesystemSize(int fd) { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 320 | if (verify_hash_) { |
| 321 | filesystem_size_ = copying_kernel_install_path_ ? |
| 322 | install_plan_.kernel_size : install_plan_.rootfs_size; |
| 323 | LOG(INFO) << "Filesystem size: " << filesystem_size_; |
| 324 | return; |
| 325 | } |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 326 | filesystem_size_ = kint64max; |
| 327 | int block_count = 0, block_size = 0; |
| 328 | if (!copying_kernel_install_path_ && |
| 329 | utils::GetFilesystemSizeFromFD(fd, &block_count, &block_size)) { |
| 330 | filesystem_size_ = static_cast<int64_t>(block_count) * block_size; |
| 331 | LOG(INFO) << "Filesystem size: " << filesystem_size_ << " bytes (" |
| 332 | << block_count << "x" << block_size << ")."; |
| 333 | } |
| 334 | } |
| 335 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 336 | } // namespace chromeos_update_engine |