Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: delta_performer.cc

Issue 3575024: AU: Fall back to a new update after a certain number of failed resume attempts. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | prefs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 22 matching lines...) Expand all
33 33
34 namespace chromeos_update_engine { 34 namespace chromeos_update_engine {
35 35
36 namespace { 36 namespace {
37 37
38 const int kDeltaVersionLength = 8; 38 const int kDeltaVersionLength = 8;
39 const int kDeltaProtobufLengthLength = 8; 39 const int kDeltaProtobufLengthLength = 8;
40 const char kUpdatePayloadPublicKeyPath[] = 40 const char kUpdatePayloadPublicKeyPath[] =
41 "/usr/share/update_engine/update-payload-key.pub.pem"; 41 "/usr/share/update_engine/update-payload-key.pub.pem";
42 const int kUpdateStateOperationInvalid = -1; 42 const int kUpdateStateOperationInvalid = -1;
43 const int kMaxResumedUpdateFailures = 10;
43 44
44 // Converts extents to a human-readable string, for use by DumpUpdateProto(). 45 // Converts extents to a human-readable string, for use by DumpUpdateProto().
45 string ExtentsToString(const RepeatedPtrField<Extent>& extents) { 46 string ExtentsToString(const RepeatedPtrField<Extent>& extents) {
46 string ret; 47 string ret;
47 for (int i = 0; i < extents.size(); i++) { 48 for (int i = 0; i < extents.size(); i++) {
48 const Extent& extent = extents.Get(i); 49 const Extent& extent = extents.Get(i);
49 if (extent.start_block() == kSparseHole) { 50 if (extent.start_block() == kSparseHole) {
50 ret += StringPrintf("{kSparseHole, %" PRIu64 "}, ", extent.num_blocks()); 51 ret += StringPrintf("{kSparseHole, %" PRIu64 "}, ", extent.num_blocks());
51 } else { 52 } else {
52 ret += StringPrintf("{%" PRIu64 ", %" PRIu64 "}, ", 53 ret += StringPrintf("{%" PRIu64 ", %" PRIu64 "}, ",
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 &next_operation) && 557 &next_operation) &&
557 next_operation != kUpdateStateOperationInvalid && 558 next_operation != kUpdateStateOperationInvalid &&
558 next_operation > 0); 559 next_operation > 0);
559 560
560 string interrupted_hash; 561 string interrupted_hash;
561 TEST_AND_RETURN_FALSE(prefs->GetString(kPrefsUpdateCheckResponseHash, 562 TEST_AND_RETURN_FALSE(prefs->GetString(kPrefsUpdateCheckResponseHash,
562 &interrupted_hash) && 563 &interrupted_hash) &&
563 !interrupted_hash.empty() && 564 !interrupted_hash.empty() &&
564 interrupted_hash == update_check_response_hash); 565 interrupted_hash == update_check_response_hash);
565 566
567 int64_t resumed_update_failures;
568 TEST_AND_RETURN_FALSE(!prefs->GetInt64(kPrefsResumedUpdateFailures,
569 &resumed_update_failures) ||
570 resumed_update_failures <= kMaxResumedUpdateFailures);
571
566 // Sanity check the rest. 572 // Sanity check the rest.
567 int64_t next_data_offset = -1; 573 int64_t next_data_offset = -1;
568 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsUpdateStateNextDataOffset, 574 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsUpdateStateNextDataOffset,
569 &next_data_offset) && 575 &next_data_offset) &&
570 next_data_offset >= 0); 576 next_data_offset >= 0);
571 577
572 string sha256_context; 578 string sha256_context;
573 TEST_AND_RETURN_FALSE( 579 TEST_AND_RETURN_FALSE(
574 prefs->GetString(kPrefsUpdateStateSHA256Context, &sha256_context) && 580 prefs->GetString(kPrefsUpdateStateSHA256Context, &sha256_context) &&
575 !sha256_context.empty()); 581 !sha256_context.empty());
576 582
577 int64_t manifest_metadata_size = 0; 583 int64_t manifest_metadata_size = 0;
578 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsManifestMetadataSize, 584 TEST_AND_RETURN_FALSE(prefs->GetInt64(kPrefsManifestMetadataSize,
579 &manifest_metadata_size) && 585 &manifest_metadata_size) &&
580 manifest_metadata_size > 0); 586 manifest_metadata_size > 0);
581 587
582 return true; 588 return true;
583 } 589 }
584 590
585 bool DeltaPerformer::ResetUpdateProgress(PrefsInterface* prefs, bool quick) { 591 bool DeltaPerformer::ResetUpdateProgress(PrefsInterface* prefs, bool quick) {
586 TEST_AND_RETURN_FALSE(prefs->SetInt64(kPrefsUpdateStateNextOperation, 592 TEST_AND_RETURN_FALSE(prefs->SetInt64(kPrefsUpdateStateNextOperation,
587 kUpdateStateOperationInvalid)); 593 kUpdateStateOperationInvalid));
588 if (!quick) { 594 if (!quick) {
589 prefs->SetString(kPrefsUpdateCheckResponseHash, ""); 595 prefs->SetString(kPrefsUpdateCheckResponseHash, "");
590 prefs->SetInt64(kPrefsUpdateStateNextDataOffset, -1); 596 prefs->SetInt64(kPrefsUpdateStateNextDataOffset, -1);
591 prefs->SetString(kPrefsUpdateStateSHA256Context, ""); 597 prefs->SetString(kPrefsUpdateStateSHA256Context, "");
592 prefs->SetString(kPrefsUpdateStateSignedSHA256Context, ""); 598 prefs->SetString(kPrefsUpdateStateSignedSHA256Context, "");
593 prefs->SetInt64(kPrefsManifestMetadataSize, -1); 599 prefs->SetInt64(kPrefsManifestMetadataSize, -1);
600 prefs->SetInt64(kPrefsResumedUpdateFailures, 0);
594 } 601 }
595 return true; 602 return true;
596 } 603 }
597 604
598 bool DeltaPerformer::CheckpointUpdateProgress() { 605 bool DeltaPerformer::CheckpointUpdateProgress() {
599 Terminator::set_exit_blocked(true); 606 Terminator::set_exit_blocked(true);
600 if (last_updated_buffer_offset_ != buffer_offset_) { 607 if (last_updated_buffer_offset_ != buffer_offset_) {
601 // Resets the progress in case we die in the middle of the state update. 608 // Resets the progress in case we die in the middle of the state update.
602 ResetUpdateProgress(prefs_, true); 609 ResetUpdateProgress(prefs_, true);
603 TEST_AND_RETURN_FALSE( 610 TEST_AND_RETURN_FALSE(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 TEST_AND_RETURN_FALSE(prefs_->GetString(kPrefsUpdateStateSHA256Context, 648 TEST_AND_RETURN_FALSE(prefs_->GetString(kPrefsUpdateStateSHA256Context,
642 &hash_context) && 649 &hash_context) &&
643 hash_calculator_.SetContext(hash_context)); 650 hash_calculator_.SetContext(hash_context));
644 651
645 int64_t manifest_metadata_size = 0; 652 int64_t manifest_metadata_size = 0;
646 TEST_AND_RETURN_FALSE(prefs_->GetInt64(kPrefsManifestMetadataSize, 653 TEST_AND_RETURN_FALSE(prefs_->GetInt64(kPrefsManifestMetadataSize,
647 &manifest_metadata_size) && 654 &manifest_metadata_size) &&
648 manifest_metadata_size > 0); 655 manifest_metadata_size > 0);
649 manifest_metadata_size_ = manifest_metadata_size; 656 manifest_metadata_size_ = manifest_metadata_size;
650 657
658 // Speculatively count the resume as a failure.
659 int64_t resumed_update_failures;
660 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) {
661 resumed_update_failures++;
662 } else {
663 resumed_update_failures = 1;
664 }
665 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures);
651 return true; 666 return true;
652 } 667 }
653 668
654 } // namespace chromeos_update_engine 669 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « no previous file | prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698