update_engine: Use FileStream in FilesystemVerifierAction.
Instead of dealing manually with the read from the partition while
verifying the filesystem, this patch uses chromeos::FileStream to do
that.
The base::MessageLoopForIO can't wait on regular files because libevent
will fail when trying to watch for such file descriptor. While
chromeos::Stream will still attempt to wait on the file descriptor in
such situation, that will be fixed in chromeos::Streams in a different
CL.
BUG=chromium:499886
TEST=Unittests still pass.
Change-Id: Icd6a031ac1137b1b5746a5c3413506ece79223cc
Reviewed-on: https://chromium-review.googlesource.com/290542
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Trybot-Ready: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/filesystem_verifier_action.h b/filesystem_verifier_action.h
index 69e4972..731790a 100644
--- a/filesystem_verifier_action.h
+++ b/filesystem_verifier_action.h
@@ -11,7 +11,7 @@
#include <string>
#include <vector>
-#include <chromeos/message_loops/message_loop.h>
+#include <chromeos/streams/stream.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
#include "update_engine/action.h"
@@ -56,13 +56,17 @@
FRIEND_TEST(FilesystemVerifierActionTest,
RunAsRootDetermineFilesystemSizeTest);
- // Callback from the main loop when there's data to read from the file
- // descriptor.
- void OnReadReadyCallback();
+ // Schedules the asynchronous read of the filesystem.
+ void ScheduleRead();
- // Based on the state of the read buffers, terminates read process and the
- // action.
- void CheckTerminationConditions();
+ // Called from the main loop when a single read from |src_stream_| succeeds or
+ // fails, calling OnReadDoneCallback() and OnReadErrorCallback() respectively.
+ void OnReadDoneCallback(size_t bytes_read);
+ void OnReadErrorCallback(const chromeos::Error* error);
+
+ // Based on the state of the read buffer, terminates read process and the
+ // action. Return whether the action was terminated.
+ bool CheckTerminationConditions();
// Cleans up all the variables we use for async operations and tells the
// ActionProcessor we're done w/ |code| as passed in. |cancelled_| should be
@@ -72,23 +76,18 @@
// Determine, if possible, the source file system size to avoid copying the
// whole partition. Currently this supports only the root file system assuming
// it's ext3-compatible.
- void DetermineFilesystemSize(int fd);
+ void DetermineFilesystemSize(const std::string& path);
// The type of the partition that we are verifying.
PartitionType partition_type_;
- // If non-null, this is the GUnixInputStream object for the opened source
- // partition.
- int src_fd_{-1};
+ // If not null, the FileStream used to read from the device.
+ chromeos::StreamPtr src_stream_;
// Buffer for storing data we read.
chromeos::Blob buffer_;
- // The task id for the the in-flight async call.
- chromeos::MessageLoop::TaskId read_task_{chromeos::MessageLoop::kTaskIdNull};
-
bool read_done_{false}; // true if reached EOF on the input stream.
- bool failed_{false}; // true if the action has failed.
bool cancelled_{false}; // true if the action has been cancelled.
// The install plan we're passed in via the input pipe.