Merge changes I80af5f4b,I2fd0034e

* changes:
  adbd: listen to all functionfs events.
  adbd: increment writes_submitted_ before submitting writes.
This commit is contained in:
Josh Gao 2019-03-27 00:24:43 +00:00 committed by Gerrit Code Review
commit 2decb2fc3a

View file

@ -267,7 +267,7 @@ struct UsbFfsConnection : public Connection {
adb_thread_setname("UsbFfs-monitor"); adb_thread_setname("UsbFfs-monitor");
bool bound = false; bool bound = false;
bool started = false; bool enabled = false;
bool running = true; bool running = true;
while (running) { while (running) {
adb_pollfd pfd[2] = { adb_pollfd pfd[2] = {
@ -298,16 +298,32 @@ struct UsbFfsConnection : public Connection {
switch (event.type) { switch (event.type) {
case FUNCTIONFS_BIND: case FUNCTIONFS_BIND:
CHECK(!bound) << "received FUNCTIONFS_BIND while already bound?"; CHECK(!bound) << "received FUNCTIONFS_BIND while already bound?";
CHECK(!enabled) << "received FUNCTIONFS_BIND while already enabled?";
bound = true; bound = true;
break; break;
case FUNCTIONFS_ENABLE: case FUNCTIONFS_ENABLE:
CHECK(!started) << "received FUNCTIONFS_ENABLE while already running?"; CHECK(bound) << "received FUNCTIONFS_ENABLE while not bound?";
started = true; CHECK(!enabled) << "received FUNCTIONFS_ENABLE while already enabled?";
enabled = true;
StartWorker(); StartWorker();
break; break;
case FUNCTIONFS_DISABLE: case FUNCTIONFS_DISABLE:
CHECK(bound) << "received FUNCTIONFS_DISABLE while not bound?";
CHECK(enabled) << "received FUNCTIONFS_DISABLE while not enabled?";
enabled = false;
running = false;
break;
case FUNCTIONFS_UNBIND:
CHECK(!enabled) << "received FUNCTIONFS_UNBIND while still enabled?";
CHECK(bound) << "received FUNCTIONFS_UNBIND when not bound?";
bound = false;
running = false; running = false;
break; break;
} }
@ -339,7 +355,7 @@ struct UsbFfsConnection : public Connection {
LOG(FATAL) << "hit EOF on eventfd"; LOG(FATAL) << "hit EOF on eventfd";
} }
WaitForEvents(); ReadEvents();
} }
}); });
} }
@ -389,7 +405,7 @@ struct UsbFfsConnection : public Connection {
return block; return block;
} }
void WaitForEvents() { void ReadEvents() {
static constexpr size_t kMaxEvents = kUsbReadQueueDepth + kUsbWriteQueueDepth; static constexpr size_t kMaxEvents = kUsbReadQueueDepth + kUsbWriteQueueDepth;
struct io_event events[kMaxEvents]; struct io_event events[kMaxEvents];
struct timespec timeout = {.tv_sec = 0, .tv_nsec = 0}; struct timespec timeout = {.tv_sec = 0, .tv_nsec = 0};
@ -552,6 +568,8 @@ struct UsbFfsConnection : public Connection {
LOG(VERBOSE) << "submitting write_request " << static_cast<void*>(iocbs[i]); LOG(VERBOSE) << "submitting write_request " << static_cast<void*>(iocbs[i]);
} }
writes_submitted_ += writes_to_submit;
int rc = io_submit(aio_context_.get(), writes_to_submit, iocbs); int rc = io_submit(aio_context_.get(), writes_to_submit, iocbs);
if (rc == -1) { if (rc == -1) {
HandleError(StringPrintf("failed to submit write requests: %s", strerror(errno))); HandleError(StringPrintf("failed to submit write requests: %s", strerror(errno)));
@ -560,8 +578,6 @@ struct UsbFfsConnection : public Connection {
LOG(FATAL) << "failed to submit all writes: wanted to submit " << writes_to_submit LOG(FATAL) << "failed to submit all writes: wanted to submit " << writes_to_submit
<< ", actually submitted " << rc; << ", actually submitted " << rc;
} }
writes_submitted_ += rc;
} }
void HandleError(const std::string& error) { void HandleError(const std::string& error) {