Loading drivers/block/vs_block_client.c +23 −99 Original line number Diff line number Diff line Loading @@ -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" Loading Loading @@ -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) Loading Loading @@ -255,19 +233,16 @@ static int vs_block_client_blkdev_getgeo(struct block_device *bdev, static int vs_block_client_check_sector_size(struct block_client *client, struct bio *bio) { unsigned int expected_bytes; if (unlikely(!bio_sectors(bio))) { dev_err(&client->service->dev, "zero-length bio\n"); return -EIO; } expected_bytes = bio_sectors(bio) * client->client.sector_size; if (unlikely(bio_size(bio) != expected_bytes)) { if (unlikely(bio_size(bio) % client->client.sector_size)) { dev_err(&client->service->dev, "bio has %zd bytes, which is unexpected " "for %d sectors of %zd bytes each\n", (size_t)bio_size(bio), bio_sectors(bio), "for sector_size of %zd bytes\n", (size_t)bio_size(bio), (size_t)client->client.sector_size); return -EIO; } Loading @@ -291,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) Loading Loading @@ -326,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); Loading @@ -353,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); Loading Loading @@ -389,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, Loading @@ -416,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; Loading @@ -434,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; Loading @@ -462,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) Loading Loading @@ -550,6 +495,10 @@ static int vs_block_client_disk_add(struct block_client *client) client->client.segment_size / client->client.sector_size); blk_queue_max_hw_sectors(blkdev->queue, max_hw_sectors); blk_queue_logical_block_size(blkdev->queue, client->client.sector_size); blk_queue_physical_block_size(blkdev->queue, client->client.sector_size); blkdev->disk = alloc_disk(PERDEV_MINORS); if (!blkdev->disk) { Loading @@ -566,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; Loading @@ -585,7 +531,8 @@ static int vs_block_client_disk_add(struct block_client *client) */ snprintf(blkdev->disk->disk_name, sizeof(blkdev->disk->disk_name), "%s%d", CLIENT_BLKDEV_NAME, blkdev->id); set_capacity(blkdev->disk, client->client.device_sectors); set_capacity(blkdev->disk, client->client.device_sectors * (client->client.sector_size >> 9)); /* * We need to hold a reference on blkdev across add_disk(), to make Loading @@ -603,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); Loading Loading @@ -752,7 +695,8 @@ static void vs_block_client_opened(struct vs_client_block_state *state) struct block_client *client = state_to_block_client(state); #if !defined(CONFIG_LBDAF) && !defined(CONFIG_64BIT) if (state->device_sectors >> (sizeof(sector_t) * 8)) { if ((state->device_sectors * (state->sector_size >> 9)) >> (sizeof(sector_t) * 8)) { dev_err(&client->service->dev, "Client doesn't support full capacity large block devices\n"); vs_client_block_close(state); Loading @@ -778,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; Loading @@ -811,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; } Loading Loading @@ -874,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); Loading @@ -893,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); Loading drivers/block/vs_block_server.c +15 −73 Original line number Diff line number Diff line Loading @@ -32,7 +32,10 @@ #include "../drivers/md/bcache/util.c" #define VS_BLOCK_BLKDEV_DEFAULT_MODE FMODE_READ /* Must match Linux bio sector_size (512 bytes) */ #define VS_BLOCK_BLK_DEF_SECTOR_SIZE 512 /* XXX should lookup block device physical_block_size */ #define VS_BLOCK_BLK_DEF_MIN_SECTORS 8 /* * Metadata for a request. Note that the bio must be embedded at the end of Loading Loading @@ -117,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) Loading Loading @@ -422,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; Loading Loading @@ -541,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; Loading Loading @@ -596,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]; Loading @@ -623,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", Loading Loading @@ -675,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, Loading @@ -704,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; } Loading Loading @@ -780,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; Loading Loading @@ -847,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; Loading @@ -860,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) { Loading @@ -889,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]; Loading Loading @@ -936,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; } Loading Loading @@ -1036,12 +975,15 @@ vs_block_server_attach_block_device(struct block_server *server) if (IS_ERR(bdev)) return bdev; // XXX get block device physical block size server->sector_size = VS_BLOCK_BLK_DEF_SECTOR_SIZE; server->server.segment_size = round_down( vs_service_max_mbuf_size(server->service) - sizeof(vs_message_id_t), server->sector_size); server->server.sector_size = server->sector_size; server->server.device_sectors = bdev->bd_part->nr_sects; server->server.sector_size = server->sector_size * VS_BLOCK_BLK_DEF_MIN_SECTORS; server->server.device_sectors = bdev->bd_part->nr_sects / VS_BLOCK_BLK_DEF_MIN_SECTORS; if (bdev_read_only(bdev)) server->server.readonly = true; server->server.flushable = true; Loading drivers/vservices/protocol/block/client.c +5 −5 Original line number Diff line number Diff line Loading @@ -93,7 +93,7 @@ static void block_handle_start(struct vs_service_device *service) to_client_driver(vsdrv)->client; vs_service_state_lock(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); _vs_client_block_req_open(state); Loading @@ -119,7 +119,7 @@ static void block_handle_reset(struct vs_service_device *service) if (client->closed) client->closed(state); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock(service); } Loading @@ -134,7 +134,7 @@ static void block_handle_start_bh(struct vs_service_device *service) to_client_driver(vsdrv)->client; vs_service_state_lock_bh(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); _vs_client_block_req_open(state); Loading @@ -160,7 +160,7 @@ static void block_handle_reset_bh(struct vs_service_device *service) if (client->closed) client->closed(state); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock_bh(service); } Loading Loading @@ -265,7 +265,7 @@ static int block_client_probe(struct vs_service_device *service) return PTR_ERR(state); state->service = vs_get_service(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); dev_set_drvdata(&service->dev, state); Loading drivers/vservices/protocol/block/server.c +5 −6 Original line number Diff line number Diff line Loading @@ -59,8 +59,7 @@ static void block_handle_start(struct vs_service_device *service) to_server_driver(vsdrv)->server; vs_service_state_lock(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock(service); } Loading @@ -83,7 +82,7 @@ static void block_handle_reset(struct vs_service_device *service) if (server->closed) server->closed(state); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock(service); } Loading @@ -98,7 +97,7 @@ static void block_handle_start_bh(struct vs_service_device *service) to_server_driver(vsdrv)->server; vs_service_state_lock_bh(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock_bh(service); } Loading @@ -122,7 +121,7 @@ static void block_handle_reset_bh(struct vs_service_device *service) if (server->closed) server->closed(state); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock_bh(service); } Loading Loading @@ -237,7 +236,7 @@ static int block_server_probe(struct vs_service_device *service) return PTR_ERR(state); state->service = vs_get_service(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); dev_set_drvdata(&service->dev, state); Loading Loading
drivers/block/vs_block_client.c +23 −99 Original line number Diff line number Diff line Loading @@ -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" Loading Loading @@ -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) Loading Loading @@ -255,19 +233,16 @@ static int vs_block_client_blkdev_getgeo(struct block_device *bdev, static int vs_block_client_check_sector_size(struct block_client *client, struct bio *bio) { unsigned int expected_bytes; if (unlikely(!bio_sectors(bio))) { dev_err(&client->service->dev, "zero-length bio\n"); return -EIO; } expected_bytes = bio_sectors(bio) * client->client.sector_size; if (unlikely(bio_size(bio) != expected_bytes)) { if (unlikely(bio_size(bio) % client->client.sector_size)) { dev_err(&client->service->dev, "bio has %zd bytes, which is unexpected " "for %d sectors of %zd bytes each\n", (size_t)bio_size(bio), bio_sectors(bio), "for sector_size of %zd bytes\n", (size_t)bio_size(bio), (size_t)client->client.sector_size); return -EIO; } Loading @@ -291,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) Loading Loading @@ -326,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); Loading @@ -353,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); Loading Loading @@ -389,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, Loading @@ -416,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; Loading @@ -434,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; Loading @@ -462,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) Loading Loading @@ -550,6 +495,10 @@ static int vs_block_client_disk_add(struct block_client *client) client->client.segment_size / client->client.sector_size); blk_queue_max_hw_sectors(blkdev->queue, max_hw_sectors); blk_queue_logical_block_size(blkdev->queue, client->client.sector_size); blk_queue_physical_block_size(blkdev->queue, client->client.sector_size); blkdev->disk = alloc_disk(PERDEV_MINORS); if (!blkdev->disk) { Loading @@ -566,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; Loading @@ -585,7 +531,8 @@ static int vs_block_client_disk_add(struct block_client *client) */ snprintf(blkdev->disk->disk_name, sizeof(blkdev->disk->disk_name), "%s%d", CLIENT_BLKDEV_NAME, blkdev->id); set_capacity(blkdev->disk, client->client.device_sectors); set_capacity(blkdev->disk, client->client.device_sectors * (client->client.sector_size >> 9)); /* * We need to hold a reference on blkdev across add_disk(), to make Loading @@ -603,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); Loading Loading @@ -752,7 +695,8 @@ static void vs_block_client_opened(struct vs_client_block_state *state) struct block_client *client = state_to_block_client(state); #if !defined(CONFIG_LBDAF) && !defined(CONFIG_64BIT) if (state->device_sectors >> (sizeof(sector_t) * 8)) { if ((state->device_sectors * (state->sector_size >> 9)) >> (sizeof(sector_t) * 8)) { dev_err(&client->service->dev, "Client doesn't support full capacity large block devices\n"); vs_client_block_close(state); Loading @@ -778,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; Loading @@ -811,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; } Loading Loading @@ -874,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); Loading @@ -893,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); Loading
drivers/block/vs_block_server.c +15 −73 Original line number Diff line number Diff line Loading @@ -32,7 +32,10 @@ #include "../drivers/md/bcache/util.c" #define VS_BLOCK_BLKDEV_DEFAULT_MODE FMODE_READ /* Must match Linux bio sector_size (512 bytes) */ #define VS_BLOCK_BLK_DEF_SECTOR_SIZE 512 /* XXX should lookup block device physical_block_size */ #define VS_BLOCK_BLK_DEF_MIN_SECTORS 8 /* * Metadata for a request. Note that the bio must be embedded at the end of Loading Loading @@ -117,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) Loading Loading @@ -422,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; Loading Loading @@ -541,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; Loading Loading @@ -596,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]; Loading @@ -623,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", Loading Loading @@ -675,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, Loading @@ -704,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; } Loading Loading @@ -780,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; Loading Loading @@ -847,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; Loading @@ -860,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) { Loading @@ -889,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]; Loading Loading @@ -936,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; } Loading Loading @@ -1036,12 +975,15 @@ vs_block_server_attach_block_device(struct block_server *server) if (IS_ERR(bdev)) return bdev; // XXX get block device physical block size server->sector_size = VS_BLOCK_BLK_DEF_SECTOR_SIZE; server->server.segment_size = round_down( vs_service_max_mbuf_size(server->service) - sizeof(vs_message_id_t), server->sector_size); server->server.sector_size = server->sector_size; server->server.device_sectors = bdev->bd_part->nr_sects; server->server.sector_size = server->sector_size * VS_BLOCK_BLK_DEF_MIN_SECTORS; server->server.device_sectors = bdev->bd_part->nr_sects / VS_BLOCK_BLK_DEF_MIN_SECTORS; if (bdev_read_only(bdev)) server->server.readonly = true; server->server.flushable = true; Loading
drivers/vservices/protocol/block/client.c +5 −5 Original line number Diff line number Diff line Loading @@ -93,7 +93,7 @@ static void block_handle_start(struct vs_service_device *service) to_client_driver(vsdrv)->client; vs_service_state_lock(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); _vs_client_block_req_open(state); Loading @@ -119,7 +119,7 @@ static void block_handle_reset(struct vs_service_device *service) if (client->closed) client->closed(state); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock(service); } Loading @@ -134,7 +134,7 @@ static void block_handle_start_bh(struct vs_service_device *service) to_client_driver(vsdrv)->client; vs_service_state_lock_bh(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); _vs_client_block_req_open(state); Loading @@ -160,7 +160,7 @@ static void block_handle_reset_bh(struct vs_service_device *service) if (client->closed) client->closed(state); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock_bh(service); } Loading Loading @@ -265,7 +265,7 @@ static int block_client_probe(struct vs_service_device *service) return PTR_ERR(state); state->service = vs_get_service(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); dev_set_drvdata(&service->dev, state); Loading
drivers/vservices/protocol/block/server.c +5 −6 Original line number Diff line number Diff line Loading @@ -59,8 +59,7 @@ static void block_handle_start(struct vs_service_device *service) to_server_driver(vsdrv)->server; vs_service_state_lock(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock(service); } Loading @@ -83,7 +82,7 @@ static void block_handle_reset(struct vs_service_device *service) if (server->closed) server->closed(state); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock(service); } Loading @@ -98,7 +97,7 @@ static void block_handle_start_bh(struct vs_service_device *service) to_server_driver(vsdrv)->server; vs_service_state_lock_bh(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock_bh(service); } Loading @@ -122,7 +121,7 @@ static void block_handle_reset_bh(struct vs_service_device *service) if (server->closed) server->closed(state); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); vs_service_state_unlock_bh(service); } Loading Loading @@ -237,7 +236,7 @@ static int block_server_probe(struct vs_service_device *service) return PTR_ERR(state); state->service = vs_get_service(service); state->state = VSERVICE_BLOCK_RESET_STATE; memset(&(state->state), 0, sizeof(state->state)); dev_set_drvdata(&service->dev, state); Loading