Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09b63599 authored by Murali Nalajala's avatar Murali Nalajala
Browse files

vservices: block: Port virtual block drivers to 4.14



Virtual block drivers are broken for4.14 due to block
level framework primitives change. Port the virtual
block drivers to build and compile for 4.14.

Change-Id: I50808765b4b1bf817db06d523d17fb2a87e80ddc
Signed-off-by: default avatarMurali Nalajala <mnalajal@codeaurora.org>
Signed-off-by: default avatarPrakruthi Deepak Heragu <pheragu@codeaurora.org>
parent 4bfd2011
Loading
Loading
Loading
Loading
+12 −91
Original line number Diff line number Diff line
@@ -39,21 +39,11 @@
#include <vservices/session.h>
#include <vservices/wait.h>

/*
 * BLK_DEF_MAX_SECTORS was replaced with the hard-coded number 1024 in 3.19,
 * and restored in 4.3
 */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && \
        (LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0))
#define BLK_DEF_MAX_SECTORS 1024
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
#define bio_sector(bio) (bio)->bi_iter.bi_sector
#define bio_size(bio) (bio)->bi_iter.bi_size
#else
#define bio_sector(bio) (bio)->bi_sector
#define bio_size(bio) (bio)->bi_size

#if !defined(bio_flags)
#define bio_flags(bio) bio->bi_opf
#endif

#define CLIENT_BLKDEV_NAME		"vblock"
@@ -171,27 +161,15 @@ static void vs_block_device_put(struct vs_block_device *blkdev)
	kref_put(&blkdev->kref, vs_block_device_kfree);
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
static void
#else
static int
#endif
vs_block_client_blkdev_release(struct gendisk *disk, fmode_t mode)
{
	struct vs_block_device *blkdev = disk->private_data;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
	if (WARN_ON(!blkdev))
		return;
#else
	if (WARN_ON(!blkdev))
		return -ENXIO;
#endif

	vs_block_device_put(blkdev);
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
	return 0;
#endif
}

static int vs_block_client_blkdev_open(struct block_device *bdev, fmode_t mode)
@@ -288,12 +266,8 @@ static int block_client_send_write_req(struct block_client *client,
	struct bio_vec *bvec;
	int err;
	bool flush, nodelay, commit;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
	struct bvec_iter iter;
	struct bio_vec bvec_local;
#else
	int i;
#endif

	err = vs_block_client_check_sector_size(client, bio);
	if (err < 0)
@@ -323,12 +297,8 @@ static int block_client_send_write_req(struct block_client *client,

	vs_pbuf_resize(&pbuf, 0);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
	bvec = &bvec_local;
	bio_for_each_segment(bvec_local, bio, iter)
#else
	bio_for_each_segment(bvec, bio, i)
#endif
	{
		unsigned long flags;
		void *buf = bvec_kmap_irq(bvec, &flags);
@@ -350,15 +320,10 @@ static int block_client_send_write_req(struct block_client *client,
		err = -EIO;
		goto fail_free_write;
	}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)

	flush = (bio_flags(bio) & REQ_PREFLUSH);
	commit = (bio_flags(bio) & REQ_FUA);
	nodelay = (bio_flags(bio) & REQ_SYNC);
#else
	flush = (bio->bi_rw & REQ_FLUSH);
	commit = (bio->bi_rw & REQ_FUA);
	nodelay = (bio->bi_rw & REQ_SYNC);
#endif
	err = vs_client_block_io_req_write(state, bio, bio_sector(bio),
			bio_sectors(bio), nodelay, flush, commit, pbuf, mbuf);

@@ -386,13 +351,8 @@ static int block_client_send_read_req(struct block_client *client,
	err = vs_block_client_check_sector_size(client, bio);
	if (err < 0)
		return err;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)
	flush = (bio_flags(bio) & REQ_PREFLUSH);
	nodelay = (bio_flags(bio) & REQ_SYNC);
#else
	flush = (bio->bi_rw & REQ_FLUSH);
	nodelay = (bio->bi_rw & REQ_SYNC);
#endif
	do {
		/* Wait until it's possible to send a read request */
		err = vs_wait_state_nointr(state,
@@ -413,15 +373,10 @@ static int block_client_send_read_req(struct block_client *client,
	return err;
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
static blk_qc_t
#else
static void
#endif
vs_block_client_make_request(struct request_queue *q, struct bio *bio)
{
	struct block_device *bdev = bio->bi_bdev;
	struct vs_block_device *blkdev = bdev->bd_disk->private_data;
	struct vs_block_device *blkdev = bio->bi_disk->private_data;
	struct block_client *client;
	int err = 0;

@@ -431,9 +386,7 @@ vs_block_client_make_request(struct request_queue *q, struct bio *bio)
		goto fail_get_client;
	}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
	blk_queue_split(q, &bio, q->bio_split);
#endif
	blk_queue_split(q, &bio);

	if (!vs_state_lock_safe(&client->client)) {
		err = -ENODEV;
@@ -459,18 +412,13 @@ vs_block_client_make_request(struct request_queue *q, struct bio *bio)
fail_lock_client:
	vs_block_client_put(client);
fail_get_client:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)

	if (err < 0) {
		bio->bi_error = err;
		bio->bi_status = err;
		bio_endio(bio);
	}
#else
	if (err < 0)
		bio_endio(bio, err);
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)

	return BLK_QC_T_NONE;
#endif
}

static int vs_block_client_get_blkdev_id(struct block_client *client)
@@ -567,9 +515,6 @@ static int vs_block_client_disk_add(struct block_client *client)
	blkdev->disk->major = block_client_major;
	blkdev->disk->first_minor = blkdev->id * PERDEV_MINORS;
	blkdev->disk->fops         = &block_client_ops;
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,7,0)
	blkdev->disk->driverfs_dev = &client->service->dev;
#endif
	blkdev->disk->private_data = blkdev;
	blkdev->disk->queue        = blkdev->queue;
	blkdev->disk->flags       |= GENHD_FL_EXT_DEVT;
@@ -605,11 +550,7 @@ static int vs_block_client_disk_add(struct block_client *client)
	client->blkdev = blkdev;
	vs_service_state_unlock(client->service);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0)
	device_add_disk(&client->service->dev, blkdev->disk);
#else
	add_disk(blkdev->disk);
#endif
	dev_dbg(&client->service->dev, "added block disk '%s'\n",
			blkdev->disk->disk_name);

@@ -781,19 +722,11 @@ static int vs_block_client_ack_read(struct vs_client_block_state *state,
	struct bio_vec *bvec;
	int err = 0;
	size_t bytes_read = 0;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
	struct bio_vec bvec_local;
	struct bvec_iter iter;
#else
	int i;
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
	bvec = &bvec_local;
	bio_for_each_segment(bvec_local, bio, iter)
#else
	bio_for_each_segment(bvec, bio, i)
#endif
	{
		unsigned long flags;
		void *buf;
@@ -814,13 +747,8 @@ static int vs_block_client_ack_read(struct vs_client_block_state *state,

	vs_client_block_io_free_ack_read(state, &pbuf, mbuf);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
	if (err < 0)
		bio->bi_error = err;
	bio->bi_status = err;
	bio_endio(bio);
#else
	bio_endio(bio, err);
#endif

	return 0;
}
@@ -877,11 +805,8 @@ static int vs_block_client_ack_write(struct vs_client_block_state *state,
	if (WARN_ON(!bio))
		return -EPROTO;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
	bio->bi_status = 0;
	bio_endio(bio);
#else
	bio_endio(bio, 0);
#endif

	wake_up(&state->service->quota_wq);

@@ -896,12 +821,8 @@ static int vs_block_client_nack_io(struct vs_client_block_state *state,
	if (WARN_ON(!bio))
		return -EPROTO;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
	bio->bi_error = block_client_vs_to_linux_error(err);
	bio->bi_status = block_client_vs_to_linux_error(err);
	bio_endio(bio);
#else
	bio_endio(bio, block_client_vs_to_linux_error(err));
#endif

	wake_up(&state->service->quota_wq);

+7 −71
Original line number Diff line number Diff line
@@ -120,11 +120,7 @@ static inline u32 vs_req_num_sectors(struct block_server *server,

static inline u64 vs_req_sector_index(struct block_server_request *req)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
	return req->bio.bi_iter.bi_sector;
#else
	return req->bio.bi_sector;
#endif
}

static void vs_block_server_closed(struct vs_server_block_state *state)
@@ -425,11 +421,7 @@ static int vs_block_server_complete_req(struct block_server *server,
{
	int err;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
	req->bio.bi_iter.bi_idx = 0;
#else
	req->bio.bi_idx = 0;
#endif
	if (!vs_state_lock_safe(&server->server))
		return -ENOLINK;

@@ -544,16 +536,10 @@ static int vs_block_bio_map_pbuf(struct bio *bio, struct vs_pbuf *pbuf)
}

/* Read request handling */
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
static void vs_block_server_read_done(struct bio *bio, int err)
#else
static void vs_block_server_read_done(struct bio *bio)
#endif
{
	unsigned long flags;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
	int err = bio->bi_error;
#endif
	int err = blk_status_to_errno(bio->bi_status);
	struct block_server_request *req = container_of(bio,
			struct block_server_request, bio);
	struct block_server *server = req->server;
@@ -599,11 +585,7 @@ static int vs_block_submit_read(struct block_server *server,
			err = vs_block_bio_map_pbuf(bio, &req->pbuf);
	} else {
		/* We need a bounce buffer. First set up the bvecs. */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
		bio->bi_iter.bi_size = size;
#else
		bio->bi_size = size;
#endif

		while (size > 0) {
			struct bio_vec *bvec = &bio->bi_io_vec[bio->bi_vcnt];
@@ -626,12 +608,8 @@ static int vs_block_submit_read(struct block_server *server,
	}

	if (err) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
		bio->bi_error = err;
		bio->bi_status = err;
		bio_endio(bio);
#else
		bio_endio(bio, err);
#endif
	} else {
		dev_vdbg(&server->service->dev,
				"submit read req sector %#llx count %#x\n",
@@ -678,27 +656,15 @@ static int vs_block_server_io_req_read(struct vs_server_block_state *state,
	req->submitted = false;

	if (flush) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)
		op_flags |= REQ_PREFLUSH;
#else
		op_flags |= REQ_FLUSH;
#endif
	}
	if (nodelay) {
		op_flags |= REQ_SYNC;
	}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
	bio->bi_iter.bi_sector = (sector_t)sector_index;
#else
	bio->bi_sector = (sector_t)sector_index;
#endif
	bio->bi_bdev = server->bdev;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
	bio_set_dev(bio, server->bdev);
	bio_set_op_attrs(bio, REQ_OP_READ, op_flags);
#else
	bio->bi_rw = READ | op_flags;
#endif
	bio->bi_end_io = vs_block_server_read_done;

	req->mbuf = vs_server_block_io_alloc_ack_read(state, &req->pbuf,
@@ -707,12 +673,8 @@ static int vs_block_server_io_req_read(struct vs_server_block_state *state,
		/* Fall back to a bounce buffer */
		req->mbuf = NULL;
	} else if (IS_ERR(req->mbuf)) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
		bio->bi_error = PTR_ERR(req->mbuf);
		bio->bi_status = PTR_ERR(req->mbuf);
		bio_endio(bio);
#else
		bio_endio(bio, PTR_ERR(req->mbuf));
#endif
		return 0;
	}

@@ -783,16 +745,10 @@ static void vs_block_server_write_bounce_work(struct work_struct *work)
	spin_unlock(&server->bounce_req_lock);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
static void vs_block_server_write_done(struct bio *bio, int err)
#else
static void vs_block_server_write_done(struct bio *bio)
#endif
{
	unsigned long flags;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
	int err = bio->bi_error;
#endif
	int err = blk_status_to_errno(bio->bi_status);
	struct block_server_request *req = container_of(bio,
			struct block_server_request, bio);
	struct block_server *server = req->server;
@@ -850,11 +806,7 @@ static int vs_block_server_io_req_write(struct vs_server_block_state *state,
	req->submitted = false;

	if (flush) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)
		op_flags |= REQ_PREFLUSH;
#else
		op_flags |= REQ_FLUSH;
#endif
	}
	if (commit) {
		op_flags |= REQ_FUA;
@@ -863,17 +815,9 @@ static int vs_block_server_io_req_write(struct vs_server_block_state *state,
		op_flags |= REQ_SYNC;
	}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
	bio->bi_iter.bi_sector = (sector_t)sector_index;
#else
	bio->bi_sector = (sector_t)sector_index;
#endif
	bio->bi_bdev = server->bdev;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
	bio_set_dev(bio, server->bdev);
	bio_set_op_attrs(bio, REQ_OP_WRITE, op_flags);
#else
	bio->bi_rw = WRITE | op_flags;
#endif
	bio->bi_end_io = vs_block_server_write_done;

	if (pbuf.size < req->size) {
@@ -892,11 +836,7 @@ static int vs_block_server_io_req_write(struct vs_server_block_state *state,
		/* We need a bounce buffer. First set up the bvecs. */
		int size = pbuf.size;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
		bio->bi_iter.bi_size = size;
#else
		bio->bi_size = size;
#endif

		while (size > 0) {
			struct bio_vec *bvec = &bio->bi_io_vec[bio->bi_vcnt];
@@ -939,12 +879,8 @@ static int vs_block_server_io_req_write(struct vs_server_block_state *state,
	return 0;

fail_bio:
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
	bio->bi_error = err;
	bio->bi_status = err;
	bio_endio(bio);
#else
	bio_endio(bio, err);
#endif
	return 0;
}