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

Side by Side Diff: filesystem_copier_action.h

Issue 5516009: AU: Split applied update verification into a separate step. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: review comments Created 10 years 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 | « download_action.cc ('k') | filesystem_copier_action.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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__ 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__ 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__
7 7
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
(...skipping 19 matching lines...) Expand all
30 class ActionTraits<FilesystemCopierAction> { 30 class ActionTraits<FilesystemCopierAction> {
31 public: 31 public:
32 // Takes the install plan as input 32 // Takes the install plan as input
33 typedef InstallPlan InputObjectType; 33 typedef InstallPlan InputObjectType;
34 // Passes the install plan as output 34 // Passes the install plan as output
35 typedef InstallPlan OutputObjectType; 35 typedef InstallPlan OutputObjectType;
36 }; 36 };
37 37
38 class FilesystemCopierAction : public Action<FilesystemCopierAction> { 38 class FilesystemCopierAction : public Action<FilesystemCopierAction> {
39 public: 39 public:
40 explicit FilesystemCopierAction(bool copying_kernel_install_path); 40 FilesystemCopierAction(bool copying_kernel_install_path,
41 bool verify_hash);
41 42
42 typedef ActionTraits<FilesystemCopierAction>::InputObjectType 43 typedef ActionTraits<FilesystemCopierAction>::InputObjectType
43 InputObjectType; 44 InputObjectType;
44 typedef ActionTraits<FilesystemCopierAction>::OutputObjectType 45 typedef ActionTraits<FilesystemCopierAction>::OutputObjectType
45 OutputObjectType; 46 OutputObjectType;
46 void PerformAction(); 47 void PerformAction();
47 void TerminateProcessing(); 48 void TerminateProcessing();
48 49
49 // Used for testing, so we can copy from somewhere other than root 50 // Used for testing, so we can copy from somewhere other than root
50 void set_copy_source(const std::string& path) { copy_source_ = path; } 51 void set_copy_source(const std::string& path) { copy_source_ = path; }
51 52
52 // Debugging/logging 53 // Debugging/logging
53 static std::string StaticType() { return "FilesystemCopierAction"; } 54 static std::string StaticType() { return "FilesystemCopierAction"; }
54 std::string Type() const { return StaticType(); } 55 std::string Type() const { return StaticType(); }
55 56
56 private: 57 private:
57 friend class FilesystemCopierActionTest; 58 friend class FilesystemCopierActionTest;
58 FRIEND_TEST(FilesystemCopierActionTest, RunAsRootDetermineFilesystemSizeTest); 59 FRIEND_TEST(FilesystemCopierActionTest, RunAsRootDetermineFilesystemSizeTest);
59 60
60 // Ping-pong buffers generally cycle through the following states: 61 // Ping-pong buffers generally cycle through the following states:
61 // Empty->Reading->Full->Writing->Empty. 62 // Empty->Reading->Full->Writing->Empty. In hash verification mode the state
63 // is never set to Writing.
62 enum BufferState { 64 enum BufferState {
63 kBufferStateEmpty, 65 kBufferStateEmpty,
64 kBufferStateReading, 66 kBufferStateReading,
65 kBufferStateFull, 67 kBufferStateFull,
66 kBufferStateWriting 68 kBufferStateWriting
67 }; 69 };
68 70
69 // Callbacks from glib when the read/write operation is done. 71 // Callbacks from glib when the read/write operation is done.
70 void AsyncReadReadyCallback(GObject *source_object, GAsyncResult *res); 72 void AsyncReadReadyCallback(GObject *source_object, GAsyncResult *res);
71 static void StaticAsyncReadReadyCallback(GObject *source_object, 73 static void StaticAsyncReadReadyCallback(GObject *source_object,
72 GAsyncResult *res, 74 GAsyncResult *res,
73 gpointer user_data); 75 gpointer user_data);
74 76
75 void AsyncWriteReadyCallback(GObject *source_object, GAsyncResult *res); 77 void AsyncWriteReadyCallback(GObject *source_object, GAsyncResult *res);
76 static void StaticAsyncWriteReadyCallback(GObject *source_object, 78 static void StaticAsyncWriteReadyCallback(GObject *source_object,
77 GAsyncResult *res, 79 GAsyncResult *res,
78 gpointer user_data); 80 gpointer user_data);
79 81
80 // Based on the state of the ping-pong buffers spawns appropriate read/write 82 // Based on the state of the ping-pong buffers spawns appropriate read/write
81 // actions asynchronously. 83 // actions asynchronously.
82 void SpawnAsyncActions(); 84 void SpawnAsyncActions();
83 85
84 // Cleans up all the variables we use for async operations and tells the 86 // Cleans up all the variables we use for async operations and tells the
85 // ActionProcessor we're done w/ success as passed in. |cancelled_| should be 87 // ActionProcessor we're done w/ |code| as passed in. |cancelled_| should be
86 // true if TerminateProcessing() was called. 88 // true if TerminateProcessing() was called.
87 void Cleanup(bool success); 89 void Cleanup(ActionExitCode code);
88 90
89 // Determine, if possible, the source file system size to avoid copying the 91 // Determine, if possible, the source file system size to avoid copying the
90 // whole partition. Currently this supports only the root file system assuming 92 // whole partition. Currently this supports only the root file system assuming
91 // it's ext3-compatible. 93 // it's ext3-compatible.
92 void DetermineFilesystemSize(int fd); 94 void DetermineFilesystemSize(int fd);
93 95
94 // Returns the number of bytes to read based on the size of the buffer and the
95 // filesystem size.
96 int64_t GetBytesToRead();
97
98 // If true, this action is copying to the kernel_install_path from 96 // If true, this action is copying to the kernel_install_path from
99 // the install plan, otherwise it's copying just to the install_path. 97 // the install plan, otherwise it's copying just to the install_path.
100 const bool copying_kernel_install_path_; 98 const bool copying_kernel_install_path_;
101 99
100 // If true, this action is running in applied update hash verification mode --
101 // it computes a hash for the target install path and compares it against the
102 // expected value.
103 const bool verify_hash_;
104
102 // The path to copy from. If empty (the default), the source is from the 105 // The path to copy from. If empty (the default), the source is from the
103 // passed in InstallPlan. 106 // passed in InstallPlan.
104 std::string copy_source_; 107 std::string copy_source_;
105 108
106 // If non-NULL, these are GUnixInputStream objects for the opened 109 // If non-NULL, these are GUnixInputStream objects for the opened
107 // source/destination partitions. 110 // source/destination partitions.
108 GInputStream* src_stream_; 111 GInputStream* src_stream_;
109 GOutputStream* dst_stream_; 112 GOutputStream* dst_stream_;
110 113
111 // Ping-pong buffers for storing data we read/write. Only one buffer is being 114 // Ping-pong buffers for storing data we read/write. Only one buffer is being
(...skipping 23 matching lines...) Expand all
135 // field is initialized when the action is started and decremented as more 138 // field is initialized when the action is started and decremented as more
136 // bytes get copied. 139 // bytes get copied.
137 int64_t filesystem_size_; 140 int64_t filesystem_size_;
138 141
139 DISALLOW_COPY_AND_ASSIGN(FilesystemCopierAction); 142 DISALLOW_COPY_AND_ASSIGN(FilesystemCopierAction);
140 }; 143 };
141 144
142 } // namespace chromeos_update_engine 145 } // namespace chromeos_update_engine
143 146
144 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__ 147 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILESYSTEM_COPIER_ACTION_H__
OLDNEW
« no previous file with comments | « download_action.cc ('k') | filesystem_copier_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698