Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[platform/kernel/linux-starfive.git] / drivers / block / drbd / drbd_receiver.c
index 20b0714..08da922 100644 (file)
@@ -1279,16 +1279,16 @@ static void one_flush_endio(struct bio *bio)
 
 static void submit_one_flush(struct drbd_device *device, struct issue_flush_context *ctx)
 {
-       struct bio *bio = bio_alloc(GFP_NOIO, 0);
+       struct bio *bio = bio_alloc(device->ldev->backing_bdev, 0,
+                                   REQ_OP_FLUSH | REQ_PREFLUSH, GFP_NOIO);
        struct one_flush_context *octx = kmalloc(sizeof(*octx), GFP_NOIO);
-       if (!bio || !octx) {
-               drbd_warn(device, "Could not allocate a bio, CANNOT ISSUE FLUSH\n");
+
+       if (!octx) {
+               drbd_warn(device, "Could not allocate a octx, CANNOT ISSUE FLUSH\n");
                /* FIXME: what else can I do now?  disconnecting or detaching
                 * really does not help to improve the state of the world, either.
                 */
-               kfree(octx);
-               if (bio)
-                       bio_put(bio);
+               bio_put(bio);
 
                ctx->error = -ENOMEM;
                put_ldev(device);
@@ -1298,10 +1298,8 @@ static void submit_one_flush(struct drbd_device *device, struct issue_flush_cont
 
        octx->device = device;
        octx->ctx = ctx;
-       bio_set_dev(bio, device->ldev->backing_bdev);
        bio->bi_private = octx;
        bio->bi_end_io = one_flush_endio;
-       bio->bi_opf = REQ_OP_FLUSH | REQ_PREFLUSH;
 
        device->flush_jif = jiffies;
        set_bit(FLUSH_PENDING, &device->flags);
@@ -1634,7 +1632,6 @@ int drbd_submit_peer_request(struct drbd_device *device,
        unsigned data_size = peer_req->i.size;
        unsigned n_bios = 0;
        unsigned nr_pages = (data_size + PAGE_SIZE -1) >> PAGE_SHIFT;
-       int err = -ENOMEM;
 
        /* TRIM/DISCARD: for now, always use the helper function
         * blkdev_issue_zeroout(..., discard=true).
@@ -1672,15 +1669,10 @@ int drbd_submit_peer_request(struct drbd_device *device,
         * generated bio, but a bio allocated on behalf of the peer.
         */
 next_bio:
-       bio = bio_alloc(GFP_NOIO, nr_pages);
-       if (!bio) {
-               drbd_err(device, "submit_ee: Allocation of a bio failed (nr_pages=%u)\n", nr_pages);
-               goto fail;
-       }
+       bio = bio_alloc(device->ldev->backing_bdev, nr_pages, op | op_flags,
+                       GFP_NOIO);
        /* > peer_req->i.sector, unless this is the first bio */
        bio->bi_iter.bi_sector = sector;
-       bio_set_dev(bio, device->ldev->backing_bdev);
-       bio_set_op_attrs(bio, op, op_flags);
        bio->bi_private = peer_req;
        bio->bi_end_io = drbd_peer_request_endio;
 
@@ -1711,14 +1703,6 @@ next_bio:
                drbd_submit_bio_noacct(device, fault_type, bio);
        } while (bios);
        return 0;
-
-fail:
-       while (bios) {
-               bio = bios;
-               bios = bios->bi_next;
-               bio_put(bio);
-       }
-       return err;
 }
 
 static void drbd_remove_epoch_entry_interval(struct drbd_device *device,
@@ -2003,10 +1987,10 @@ static int recv_dless_read(struct drbd_peer_device *peer_device, struct drbd_req
        D_ASSERT(peer_device->device, sector == bio->bi_iter.bi_sector);
 
        bio_for_each_segment(bvec, bio, iter) {
-               void *mapped = kmap(bvec.bv_page) + bvec.bv_offset;
+               void *mapped = bvec_kmap_local(&bvec);
                expect = min_t(int, data_size, bvec.bv_len);
                err = drbd_recv_all_warn(peer_device->connection, mapped, expect);
-               kunmap(bvec.bv_page);
+               kunmap_local(mapped);
                if (err)
                        return err;
                data_size -= expect;