Merge tag 'for-5.18/drivers-2022-04-01' of git://git.kernel.dk/linux-block
[sfrench/cifs-2.6.git] / drivers / block / drbd / drbd_req.c
index c04394518b07f53b98722e32ede77aeb6e965f6d..75be0e16770a090f99e1573140520a30651b54ff 100644 (file)
@@ -180,7 +180,8 @@ void start_new_tl_epoch(struct drbd_connection *connection)
 void complete_master_bio(struct drbd_device *device,
                struct bio_and_error *m)
 {
-       m->bio->bi_status = errno_to_blk_status(m->error);
+       if (unlikely(m->error))
+               m->bio->bi_status = errno_to_blk_status(m->error);
        bio_endio(m->bio);
        dec_ap_bio(device);
 }
@@ -332,17 +333,21 @@ static void set_if_null_req_next(struct drbd_peer_device *peer_device, struct dr
 static void advance_conn_req_next(struct drbd_peer_device *peer_device, struct drbd_request *req)
 {
        struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
+       struct drbd_request *iter = req;
        if (!connection)
                return;
        if (connection->req_next != req)
                return;
-       list_for_each_entry_continue(req, &connection->transfer_log, tl_requests) {
-               const unsigned s = req->rq_state;
-               if (s & RQ_NET_QUEUED)
+
+       req = NULL;
+       list_for_each_entry_continue(iter, &connection->transfer_log, tl_requests) {
+               const unsigned int s = iter->rq_state;
+
+               if (s & RQ_NET_QUEUED) {
+                       req = iter;
                        break;
+               }
        }
-       if (&req->tl_requests == &connection->transfer_log)
-               req = NULL;
        connection->req_next = req;
 }
 
@@ -358,17 +363,21 @@ static void set_if_null_req_ack_pending(struct drbd_peer_device *peer_device, st
 static void advance_conn_req_ack_pending(struct drbd_peer_device *peer_device, struct drbd_request *req)
 {
        struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
+       struct drbd_request *iter = req;
        if (!connection)
                return;
        if (connection->req_ack_pending != req)
                return;
-       list_for_each_entry_continue(req, &connection->transfer_log, tl_requests) {
-               const unsigned s = req->rq_state;
-               if ((s & RQ_NET_SENT) && (s & RQ_NET_PENDING))
+
+       req = NULL;
+       list_for_each_entry_continue(iter, &connection->transfer_log, tl_requests) {
+               const unsigned int s = iter->rq_state;
+
+               if ((s & RQ_NET_SENT) && (s & RQ_NET_PENDING)) {
+                       req = iter;
                        break;
+               }
        }
-       if (&req->tl_requests == &connection->transfer_log)
-               req = NULL;
        connection->req_ack_pending = req;
 }
 
@@ -384,17 +393,21 @@ static void set_if_null_req_not_net_done(struct drbd_peer_device *peer_device, s
 static void advance_conn_req_not_net_done(struct drbd_peer_device *peer_device, struct drbd_request *req)
 {
        struct drbd_connection *connection = peer_device ? peer_device->connection : NULL;
+       struct drbd_request *iter = req;
        if (!connection)
                return;
        if (connection->req_not_net_done != req)
                return;
-       list_for_each_entry_continue(req, &connection->transfer_log, tl_requests) {
-               const unsigned s = req->rq_state;
-               if ((s & RQ_NET_SENT) && !(s & RQ_NET_DONE))
+
+       req = NULL;
+       list_for_each_entry_continue(iter, &connection->transfer_log, tl_requests) {
+               const unsigned int s = iter->rq_state;
+
+               if ((s & RQ_NET_SENT) && !(s & RQ_NET_DONE)) {
+                       req = iter;
                        break;
+               }
        }
-       if (&req->tl_requests == &connection->transfer_log)
-               req = NULL;
        connection->req_not_net_done = req;
 }