OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "update_engine/delta_performer.h" | 5 #include "update_engine/delta_performer.h" |
6 | 6 |
7 #include <endian.h> | 7 #include <endian.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <cstring> | 11 #include <cstring> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include <base/scoped_ptr.h> | 15 #include <base/scoped_ptr.h> |
16 #include <base/string_util.h> | 16 #include <base/string_util.h> |
17 #include <google/protobuf/repeated_field.h> | 17 #include <google/protobuf/repeated_field.h> |
18 | 18 |
19 #include "update_engine/bzip_extent_writer.h" | 19 #include "update_engine/bzip_extent_writer.h" |
20 #include "update_engine/delta_diff_generator.h" | 20 #include "update_engine/delta_diff_generator.h" |
21 #include "update_engine/extent_writer.h" | 21 #include "update_engine/extent_writer.h" |
22 #include "update_engine/graph_types.h" | 22 #include "update_engine/graph_types.h" |
23 #include "update_engine/payload_signer.h" | 23 #include "update_engine/payload_signer.h" |
24 #include "update_engine/prefs_interface.h" | 24 #include "update_engine/prefs_interface.h" |
25 #include "update_engine/subprocess.h" | 25 #include "update_engine/subprocess.h" |
| 26 #include "update_engine/terminator.h" |
26 | 27 |
27 using std::min; | 28 using std::min; |
28 using std::string; | 29 using std::string; |
29 using std::vector; | 30 using std::vector; |
30 using google::protobuf::RepeatedPtrField; | 31 using google::protobuf::RepeatedPtrField; |
31 | 32 |
32 namespace chromeos_update_engine { | 33 namespace chromeos_update_engine { |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 ssize_t total_operations = manifest_.install_operations_size() + | 204 ssize_t total_operations = manifest_.install_operations_size() + |
204 manifest_.kernel_install_operations_size(); | 205 manifest_.kernel_install_operations_size(); |
205 while (next_operation_num_ < total_operations) { | 206 while (next_operation_num_ < total_operations) { |
206 const DeltaArchiveManifest_InstallOperation &op = | 207 const DeltaArchiveManifest_InstallOperation &op = |
207 next_operation_num_ < manifest_.install_operations_size() ? | 208 next_operation_num_ < manifest_.install_operations_size() ? |
208 manifest_.install_operations(next_operation_num_) : | 209 manifest_.install_operations(next_operation_num_) : |
209 manifest_.kernel_install_operations( | 210 manifest_.kernel_install_operations( |
210 next_operation_num_ - manifest_.install_operations_size()); | 211 next_operation_num_ - manifest_.install_operations_size()); |
211 if (!CanPerformInstallOperation(op)) | 212 if (!CanPerformInstallOperation(op)) |
212 break; | 213 break; |
| 214 ScopedTerminatorExitUnblocker exit_unblocker = |
| 215 ScopedTerminatorExitUnblocker(); // Avoids a compiler unused var bug. |
213 // Log every thousandth operation, and also the first and last ones | 216 // Log every thousandth operation, and also the first and last ones |
214 if ((next_operation_num_ % 1000 == 0) || | 217 if ((next_operation_num_ % 1000 == 0) || |
215 (next_operation_num_ + 1 == total_operations)) { | 218 (next_operation_num_ + 1 == total_operations)) { |
216 LOG(INFO) << "Performing operation " << (next_operation_num_ + 1) << "/" | 219 LOG(INFO) << "Performing operation " << (next_operation_num_ + 1) << "/" |
217 << total_operations; | 220 << total_operations; |
218 } | 221 } |
219 bool is_kernel_partition = | 222 bool is_kernel_partition = |
220 (next_operation_num_ >= manifest_.install_operations_size()); | 223 (next_operation_num_ >= manifest_.install_operations_size()); |
221 // If about to start a non-idempotent operation, clear the update state so | 224 // If about to start a non-idempotent operation, clear the update state so |
222 // that if the operation gets interrupted, we don't try to resume the | 225 // that if the operation gets interrupted, we don't try to resume the |
223 // update. | 226 // update. |
224 if (!IsIdempotentOperation(op)) { | 227 if (!IsIdempotentOperation(op)) { |
| 228 Terminator::set_exit_blocked(true); |
225 ResetUpdateProgress(prefs_); | 229 ResetUpdateProgress(prefs_); |
226 } | 230 } |
227 if (op.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE || | 231 if (op.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE || |
228 op.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ) { | 232 op.type() == DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ) { |
229 if (!PerformReplaceOperation(op, is_kernel_partition)) { | 233 if (!PerformReplaceOperation(op, is_kernel_partition)) { |
230 LOG(ERROR) << "Failed to perform replace operation " | 234 LOG(ERROR) << "Failed to perform replace operation " |
231 << next_operation_num_; | 235 << next_operation_num_; |
232 return -EINVAL; | 236 return -EINVAL; |
233 } | 237 } |
234 } else if (op.type() == DeltaArchiveManifest_InstallOperation_Type_MOVE) { | 238 } else if (op.type() == DeltaArchiveManifest_InstallOperation_Type_MOVE) { |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 return true; | 550 return true; |
547 } | 551 } |
548 | 552 |
549 bool DeltaPerformer::ResetUpdateProgress(PrefsInterface* prefs) { | 553 bool DeltaPerformer::ResetUpdateProgress(PrefsInterface* prefs) { |
550 TEST_AND_RETURN_FALSE(prefs->SetInt64(kPrefsUpdateStateNextOperation, | 554 TEST_AND_RETURN_FALSE(prefs->SetInt64(kPrefsUpdateStateNextOperation, |
551 kUpdateStateOperationInvalid)); | 555 kUpdateStateOperationInvalid)); |
552 return true; | 556 return true; |
553 } | 557 } |
554 | 558 |
555 bool DeltaPerformer::CheckpointUpdateProgress() { | 559 bool DeltaPerformer::CheckpointUpdateProgress() { |
556 // First reset the progress in case we die in the middle of the state update. | 560 Terminator::set_exit_blocked(true); |
557 ResetUpdateProgress(prefs_); | |
558 if (last_updated_buffer_offset_ != buffer_offset_) { | 561 if (last_updated_buffer_offset_ != buffer_offset_) { |
| 562 // Resets the progress in case we die in the middle of the state update. |
| 563 ResetUpdateProgress(prefs_); |
559 TEST_AND_RETURN_FALSE( | 564 TEST_AND_RETURN_FALSE( |
560 prefs_->SetString(kPrefsUpdateStateSignedSHA256Context, | 565 prefs_->SetString(kPrefsUpdateStateSignedSHA256Context, |
561 hash_calculator_.GetContext())); | 566 hash_calculator_.GetContext())); |
562 TEST_AND_RETURN_FALSE(prefs_->SetInt64(kPrefsUpdateStateNextDataOffset, | 567 TEST_AND_RETURN_FALSE(prefs_->SetInt64(kPrefsUpdateStateNextDataOffset, |
563 buffer_offset_)); | 568 buffer_offset_)); |
564 last_updated_buffer_offset_ = buffer_offset_; | 569 last_updated_buffer_offset_ = buffer_offset_; |
565 } | 570 } |
566 TEST_AND_RETURN_FALSE(prefs_->SetInt64(kPrefsUpdateStateNextOperation, | 571 TEST_AND_RETURN_FALSE(prefs_->SetInt64(kPrefsUpdateStateNextOperation, |
567 next_operation_num_)); | 572 next_operation_num_)); |
568 return true; | 573 return true; |
569 } | 574 } |
570 | 575 |
571 } // namespace chromeos_update_engine | 576 } // namespace chromeos_update_engine |
OLD | NEW |