If there an error, cqe field is not allocated by io_uring_wait_cqe(); return
the error immediately.

Bug: 223308671
Test: OTA
Signed-off-by: Akilesh Kailash <akailash@google.com>
Change-Id: Ib485bb767ad58e6a0849fb2431b563e6e7f04cfd
diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_merge.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_merge.cpp
index 0cb41d3..c26a2cd 100644
--- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_merge.cpp
+++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_merge.cpp
@@ -288,9 +288,6 @@
                 while (pending_ios_to_complete) {
                     struct io_uring_cqe* cqe;
 
-                    // We need to make sure to reap all the I/O's submitted
-                    // even if there are any errors observed.
-                    //
                     // io_uring_wait_cqe can potentially return -EAGAIN or -EINTR;
                     // these error codes are not truly I/O errors; we can retry them
                     // by re-populating the SQE entries and submitting the I/O
@@ -300,11 +297,13 @@
                     if (ret) {
                         SNAP_LOG(ERROR) << "Merge: io_uring_wait_cqe failed: " << ret;
                         status = false;
+                        break;
                     }
 
                     if (cqe->res < 0) {
                         SNAP_LOG(ERROR) << "Merge: io_uring_wait_cqe failed with res: " << cqe->res;
                         status = false;
+                        break;
                     }
 
                     io_uring_cqe_seen(ring_.get(), cqe);
diff --git a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_readahead.cpp b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_readahead.cpp
index 7d9d392..fa2866f 100644
--- a/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_readahead.cpp
+++ b/fs_mgr/libsnapshot/snapuserd/user-space-merge/snapuserd_readahead.cpp
@@ -395,9 +395,6 @@
     while (pending_ios_to_complete) {
         struct io_uring_cqe* cqe;
 
-        // We need to make sure to reap all the I/O's submitted
-        // even if there are any errors observed.
-        //
         // io_uring_wait_cqe can potentially return -EAGAIN or -EINTR;
         // these error codes are not truly I/O errors; we can retry them
         // by re-populating the SQE entries and submitting the I/O
@@ -407,11 +404,13 @@
         if (ret) {
             SNAP_LOG(ERROR) << "Read-ahead - io_uring_wait_cqe failed: " << ret;
             status = false;
+            break;
         }
 
         if (cqe->res < 0) {
             SNAP_LOG(ERROR) << "Read-ahead - io_uring_Wait_cqe failed with res: " << cqe->res;
             status = false;
+            break;
         }
 
         io_uring_cqe_seen(ring_.get(), cqe);