else if (op == REQ_OP_WRITE_SAME)
                special_cmd_max_sectors = q->limits.max_write_same_sectors;
        if ((op == REQ_OP_DISCARD || op == REQ_OP_WRITE_ZEROES ||
 -           op == REQ_OP_WRITE_SAME)  &&
 -          special_cmd_max_sectors == 0) {
 +           op == REQ_OP_WRITE_SAME) && special_cmd_max_sectors == 0) {
 +              atomic_inc(&io->count);
-               dec_count(io, region, -EOPNOTSUPP);
+               dec_count(io, region, BLK_STS_NOTSUPP);
                return;
        }
  
 
                if (!(bio->bi_opf & REQ_PREFLUSH) &&
                    bio_op(bio) != REQ_OP_DISCARD)
                        dm_rh_dec(ms->rh, bio_record->write_region);
-               return error;
+               return DM_ENDIO_DONE;
        }
  
-       if (error == -EOPNOTSUPP)
+       if (*error == BLK_STS_NOTSUPP)
 -              return DM_ENDIO_DONE;
 +              goto out;
  
-       if ((error == -EWOULDBLOCK) && (bio->bi_opf & REQ_RAHEAD))
+       if (bio->bi_opf & REQ_RAHEAD)
 -              return DM_ENDIO_DONE;
 +              goto out;
  
-       if (unlikely(error)) {
+       if (unlikely(*error)) {
 +              if (!bio_record->details.bi_bdev) {
 +                      /*
 +                       * There wasn't enough memory to record necessary
 +                       * information for a retry or there was no other
 +                       * mirror in-sync.
 +                       */
 +                      DMERR_LIMIT("Mirror read failed.");
-                       return -EIO;
++                      return DM_ENDIO_DONE;
 +              }
 +
                m = bio_record->m;
  
                DMERR("Mirror read failed from %s. Trying alternative device.",
                        bd = &bio_record->details;
  
                        dm_bio_restore(bd, bio);
-                       bio->bi_error = 0;
 +                      bio_record->details.bi_bdev = NULL;
+                       bio->bi_status = 0;
  
                        queue_bio(ms, bio, rw);
                        return DM_ENDIO_INCOMPLETE;
                DMERR("All replicated volumes dead, failing I/O");
        }
  
-       return error;
 +out:
 +      bio_record->details.bi_bdev = NULL;
 +
+       return DM_ENDIO_DONE;
  }
  
  static void mirror_presuspend(struct dm_target *ti)
 
        if (vecs != inline_vecs)
                kfree(vecs);
  
-       if (unlikely(bio.bi_error))
-               ret = bio.bi_error;
+       if (unlikely(bio.bi_status))
 -              return blk_status_to_errno(bio.bi_status);
++              ret = blk_status_to_errno(bio.bi_status);
 +
 +      bio_uninit(&bio);
 +
        return ret;
  }