From 9520a10941547bc20155db319fe0588b391f8e1e Mon Sep 17 00:00:00 2001 From: Alex Lanzano Date: Wed, 19 Sep 2018 15:31:32 -0400 Subject: [PATCH 1/2] add discard support for vhd --- control/tap-ctl-info.c | 4 +- drivers/block-vhd.c | 207 +++++++++++++++++++++++++++++++++++- drivers/tapdisk-filter.c | 6 ++ drivers/tapdisk-image.c | 8 +- drivers/tapdisk-interface.c | 34 ++++++ drivers/tapdisk-interface.h | 1 + drivers/tapdisk-queue.c | 22 +++- drivers/tapdisk-queue.h | 7 +- drivers/tapdisk-server.c | 3 +- drivers/tapdisk-vbd.c | 58 +++++++++- drivers/tapdisk.h | 8 +- drivers/td-blkif.h | 1 + drivers/td-ctx.c | 21 ++-- drivers/td-req.c | 50 ++++++++- include/tap-ctl.h | 5 +- include/tapdisk-message.h | 2 + include/xen_blkif.h | 41 +++++++ tapback/backend.c | 2 +- tapback/frontend.c | 26 +++++ tapback/tapback.c | 12 ++- tapback/tapback.h | 10 ++ 21 files changed, 498 insertions(+), 30 deletions(-) diff --git a/control/tap-ctl-info.c b/control/tap-ctl-info.c index a6768d20..021196a3 100644 --- a/control/tap-ctl-info.c +++ b/control/tap-ctl-info.c @@ -36,7 +36,8 @@ #include "tap-ctl.h" int tap_ctl_info(pid_t pid, unsigned long long *sectors, - unsigned int *sector_size, unsigned int *info, const int minor) + unsigned int *sector_size, unsigned int *info, + bool *discard, const int minor) { tapdisk_message_t message; int err; @@ -60,6 +61,7 @@ int tap_ctl_info(pid_t pid, unsigned long long *sectors, *sectors = message.u.image.sectors; *sector_size = message.u.image.sector_size; *info = message.u.image.info; + *discard = message.u.image.discard; return 0; } else if (TAPDISK_MESSAGE_ERROR == message.type) { return -message.u.response.error; diff --git a/drivers/block-vhd.c b/drivers/block-vhd.c index e9f5f071..fee10c8f 100644 --- a/drivers/block-vhd.c +++ b/drivers/block-vhd.c @@ -107,12 +107,13 @@ unsigned int SPB; #endif /******VHD DEFINES******/ -#define VHD_CACHE_SIZE 32 +#define VHD_CACHE_SIZE TAPDISK_DATA_REQUESTS #define VHD_REQS_DATA TAPDISK_DATA_REQUESTS #define VHD_REQS_META (VHD_CACHE_SIZE + 2) #define VHD_REQS_TOTAL (VHD_REQS_DATA + VHD_REQS_META) + #define VHD_OP_BAT_WRITE 0 #define VHD_OP_DATA_READ 1 #define VHD_OP_DATA_WRITE 2 @@ -120,6 +121,7 @@ unsigned int SPB; #define VHD_OP_BITMAP_WRITE 4 #define VHD_OP_ZERO_BM_WRITE 5 #define VHD_OP_REDUNDANT_BM_WRITE 6 +#define VHD_OP_DISCARD 7 #define VHD_BM_BAT_LOCKED 0 #define VHD_BM_BAT_CLEAR 1 @@ -718,6 +720,7 @@ __vhd_open(td_driver_t *driver, const char *name, vhd_flag_t flags) driver->info.size = s->vhd.footer.curr_size >> VHD_SECTOR_SHIFT; driver->info.sector_size = VHD_SECTOR_SIZE; driver->info.info = 0; + driver->info.discard = true; DBG(TLOG_INFO, "vhd_open: done (sz:%"PRIu64", sct:%lu, inf:%u)\n", driver->info.size, driver->info.sector_size, driver->info.info); @@ -1240,7 +1243,7 @@ read_bitmap_cache(struct vhd_state *s, uint64_t sector, uint8_t op) return VHD_BM_BAT_CLEAR; } - if (test_batmap(s, blk)) { + if (test_batmap(s, blk) && op != VHD_OP_DISCARD) { DBG(TLOG_DBG, "batmap set for 0x%04x\n", blk); return VHD_BM_BIT_SET; } @@ -1315,6 +1318,8 @@ aio_read(struct vhd_state *s, struct vhd_request *req, uint64_t offset) { struct tiocb *tiocb = &req->tiocb; + tiocb->op = TIO_CMD_READ; + td_prep_read(tiocb, s->vhd.fd, req->treq.buf, vhd_sectors_to_bytes(req->treq.secs), offset, vhd_complete, req); @@ -1331,6 +1336,8 @@ aio_write(struct vhd_state *s, struct vhd_request *req, uint64_t offset) { struct tiocb *tiocb = &req->tiocb; + tiocb->op = TIO_CMD_WRITE; + td_prep_write(tiocb, s->vhd.fd, req->treq.buf, vhd_sectors_to_bytes(req->treq.secs), offset, vhd_complete, req); @@ -1342,6 +1349,22 @@ aio_write(struct vhd_state *s, struct vhd_request *req, uint64_t offset) TRACE(s); } +static inline void +aio_discard(struct vhd_state *s, struct vhd_request *req, uint64_t offset) +{ + struct tiocb *tiocb = &req->tiocb; + + tiocb->op = TIO_CMD_DISCARD; + + td_prep_write(tiocb, s->vhd.fd, req->treq.buf, + vhd_sectors_to_bytes(req->treq.secs), + offset, vhd_complete, req); + tiocb->iocb.aio_lio_opcode = IO_CMD_NOOP; + td_queue_tiocb(s->driver, tiocb); + s->queued++; + +} + /** * Reserves a new extent. * @@ -1704,6 +1727,50 @@ schedule_data_write(struct vhd_state *s, td_request_t treq, vhd_flag_t flags) return 0; } +static int +schedule_discard(struct vhd_state *s, td_request_t treq, vhd_flag_t flags) +{ + uint64_t offset; + uint32_t blk = 0, sec = 0; + struct vhd_bitmap *bm = NULL; + struct vhd_request *req; + + blk = treq.sec / s->spb; + sec = treq.sec % s->spb; + + offset = bat_entry(s, blk); + offset += s->bm_secs + sec; + offset = vhd_sectors_to_bytes(offset); + + req = alloc_vhd_request(s); + if (!req) { + return -EBUSY; + } + + req->treq = treq; + req->op = VHD_OP_DISCARD; + req->next = NULL; + + + if (test_vhd_flag(flags, VHD_FLAG_REQ_UPDATE_BITMAP)) { + bm = get_bitmap(s, blk); + ASSERT(bm && bitmap_valid(bm)); + lock_bitmap(bm); + + if (bm->tx.closed) { + add_to_tail(&bm->queue, req); + set_vhd_flag(req->flags, VHD_FLAG_REQ_QUEUED); + } else + add_to_transaction(&bm->tx, req); + } else if (sec == 0 && /* first sector inside data block */ + s->vhd.footer.type != HD_TYPE_FIXED && + bat_entry(s, blk) != s->first_db && + test_batmap(s, blk)) + schedule_redundant_bm_write(s, blk); + aio_discard(s, req, offset); + return 0; +} + static int schedule_bitmap_read(struct vhd_state *s, uint32_t blk) { @@ -1982,6 +2049,92 @@ vhd_queue_write(td_driver_t *driver, td_request_t treq) } } +static void +vhd_queue_discard(td_driver_t *driver, td_request_t treq) +{ + struct vhd_state *s = (struct vhd_state *)driver->data; + + DBG(TLOG_DBG, "%s: lsec: 0x%08"PRIx64", secs: 0x%04x, (seg: %d)\n", + s->vhd.file, treq.sec, treq.secs, treq.sidx); + + if (s->vhd.footer.type == HD_TYPE_FIXED) + return; + + while (treq.secs) { + int err; + uint8_t flags; + td_request_t clone; + + err = 0; + flags = 0; + clone = treq; + + switch (read_bitmap_cache(s, clone.sec, VHD_OP_DISCARD)) { + case -EINVAL: + err = -EINVAL; + goto fail; + + case VHD_BM_BAT_LOCKED: + err = -EBUSY; + goto fail; + + case VHD_BM_BAT_CLEAR: + clone.secs = MIN(clone.secs, s->spb - (clone.sec % s->spb)); + break; + + case VHD_BM_BIT_CLEAR: + clone.secs = read_bitmap_cache_span(s, clone.sec, clone.secs, 0); + err = schedule_discard(s, clone, 0); + if (err) + goto fail; + break; + + case VHD_BM_BIT_SET: + flags = VHD_FLAG_REQ_UPDATE_BITMAP; + clone.secs = read_bitmap_cache_span(s, clone.sec, clone.secs, 1); + err = schedule_discard(s, clone, flags); + if (err) + goto fail; + break; + + case VHD_BM_NOT_CACHED: + clone.secs = MIN(clone.secs, s->spb - (clone.sec % s->spb)); + err = schedule_bitmap_read(s, clone.sec / s->spb); + if (err) + goto fail; + + err = __vhd_queue_request(s, VHD_OP_DISCARD, clone); + if (err) + goto fail; + break; + + case VHD_BM_READ_PENDING: + clone.secs = MIN(clone.secs, s->spb - (clone.sec % s->spb)); + err = __vhd_queue_request(s, VHD_OP_DISCARD, clone); + if (err) + goto fail; + break; + + default: + ASSERT(0); + break; + } + + treq.sec += clone.secs; + treq.secs -= clone.secs; + continue; + + fail: + DPRINTF("FAIL!"); + clone.secs = treq.secs; + td_complete_request(clone, err); + break; + } + + //td_complete_request(treq, err); + +} + static inline void signal_completion(struct vhd_request *list, int error) { @@ -2263,12 +2416,15 @@ finish_bitmap_read(struct vhd_request *req) free_vhd_request(s, r); ASSERT(tmp.op == VHD_OP_DATA_READ || - tmp.op == VHD_OP_DATA_WRITE); + tmp.op == VHD_OP_DATA_WRITE || + tmp.op == VHD_OP_DISCARD); if (tmp.op == VHD_OP_DATA_READ) vhd_queue_read(s->driver, tmp.treq); else if (tmp.op == VHD_OP_DATA_WRITE) vhd_queue_write(s->driver, tmp.treq); + else if (tmp.op == VHD_OP_DISCARD) + vhd_queue_discard(s->driver, tmp.treq); r = next; } @@ -2359,6 +2515,46 @@ finish_data_write(struct vhd_request *req) } } +static void +finish_discard(struct vhd_request *req) +{ + int i; + struct vhd_transaction *tx = req->tx; + struct vhd_state *s = (struct vhd_state *)req->state; + + set_vhd_flag(req->flags, VHD_FLAG_REQ_FINISHED); + + if (tx) { + uint32_t blk, sec; + struct vhd_bitmap *bm; + + blk = req->treq.sec / s->spb; + sec = req->treq.sec % s->spb; + bm = get_bitmap(s, blk); + + ASSERT(bm && bitmap_valid(bm) && bitmap_locked(bm)); + + tx->finished++; + + DBG(TLOG_DBG, "lsec: 0x%08"PRIx64", blk: 0x04%"PRIx64", " + "tx->started: %d, tx->finished: %d\n", req->treq.sec, + req->treq.sec / s->spb, tx->started, tx->finished); + + if (!req->error) + for (i = 0; i < req->treq.secs; i++) + vhd_bitmap_clear(&s->vhd, bm->shadow, sec + i); + + if (transaction_completed(tx)) + finish_data_transaction(s, bm); + + } else if (!test_vhd_flag(req->flags, VHD_FLAG_REQ_QUEUED)) { + ASSERT(!req->next); + DBG(TLOG_DBG, "lsec: 0x%08"PRIx64", blk: 0x%04"PRIx64"\n", + req->treq.sec, req->treq.sec / s->spb); + signal_completion(req, 0); + } +} + void vhd_complete(void *arg, struct tiocb *tiocb, int err) { @@ -2407,6 +2603,10 @@ vhd_complete(void *arg, struct tiocb *tiocb, int err) finish_bat_write(req); break; + case VHD_OP_DISCARD: + finish_discard(req); + break; + default: ASSERT(0); break; @@ -2494,6 +2694,7 @@ struct tap_disk tapdisk_vhd = { .td_close = _vhd_close, .td_queue_read = vhd_queue_read, .td_queue_write = vhd_queue_write, + .td_queue_discard = vhd_queue_discard, .td_get_parent_id = vhd_get_parent_id, .td_validate_parent = vhd_validate_parent, .td_debug = vhd_debug, diff --git a/drivers/tapdisk-filter.c b/drivers/tapdisk-filter.c index 221d5bf7..f2c25d94 100644 --- a/drivers/tapdisk-filter.c +++ b/drivers/tapdisk-filter.c @@ -237,6 +237,9 @@ tapdisk_filter_iocbs(struct tfilter *filter, struct iocb **iocbs, int num) for (i = 0; i < num; i++) { struct iocb *io = iocbs[i]; + if (io->aio_lio_opcode == IO_CMD_NOOP) + continue; + if (filter->mode & TD_INJECT_FAULTS) { if ((random() % 100) <= TD_FAULT_RATE) { inject_fault(filter, io); @@ -260,6 +263,9 @@ tapdisk_filter_events(struct tfilter *filter, struct io_event *events, int num) for (i = 0; i < num; i++) { struct iocb *io = events[i].obj; + if (io->aio_lio_opcode == IO_CMD_NOOP) + continue; + if (filter->mode & TD_INJECT_FAULTS) { if (fault_injected(filter, io)) { recover_fault(filter, io); diff --git a/drivers/tapdisk-image.c b/drivers/tapdisk-image.c index 974575b2..e8747c4e 100644 --- a/drivers/tapdisk-image.c +++ b/drivers/tapdisk-image.c @@ -107,7 +107,8 @@ tapdisk_image_check_td_request(td_image_t *image, td_request_t treq) info = &image->info; rdonly = td_flag_test(image->flags, TD_OPEN_RDONLY); - if (treq.op != TD_OP_READ && treq.op != TD_OP_WRITE) + if (treq.op != TD_OP_READ && treq.op != TD_OP_WRITE && + treq.op != TD_OP_DISCARD) goto fail; if (treq.op == TD_OP_WRITE && rdonly) { @@ -115,7 +116,8 @@ tapdisk_image_check_td_request(td_image_t *image, td_request_t treq) goto fail; } - if (treq.secs <= 0 || treq.sec + treq.secs > info->size) + if ((treq.secs <= 0 || treq.sec + treq.secs > info->size) && + treq.op != TD_OP_DISCARD) goto fail; return 0; @@ -153,6 +155,8 @@ tapdisk_image_check_request(td_image_t *image, td_vbd_request_t *vreq) secs += vreq->iov[i].secs; switch (vreq->op) { + case TD_OP_DISCARD: + /* falls through */ case TD_OP_WRITE: if (rdonly) { err = -EPERM; diff --git a/drivers/tapdisk-interface.c b/drivers/tapdisk-interface.c index ed861b96..b08fc9e4 100644 --- a/drivers/tapdisk-interface.c +++ b/drivers/tapdisk-interface.c @@ -234,6 +234,40 @@ td_queue_read(td_image_t *image, td_request_t treq) td_complete_request(treq, err); } +void +td_queue_discard(td_image_t *image, td_request_t treq) +{ + int err; + td_driver_t *driver; + + driver = image->driver; + if (!driver) { + err = -ENODEV; + goto fail; + } + + if (!td_flag_test(driver->state, TD_DRIVER_OPEN)) { + err = -EBADF; + goto fail; + } + + if (!driver->ops->td_queue_discard) { + err = -EOPNOTSUPP; + goto fail; + } + + err = tapdisk_image_check_td_request(image, treq); + if (err) + goto fail; + + driver->ops->td_queue_discard(driver, treq); + + return; + +fail: + td_complete_request(treq, err); +} + void td_forward_request(td_request_t treq) { diff --git a/drivers/tapdisk-interface.h b/drivers/tapdisk-interface.h index 87c4bcd0..ba72d9a3 100644 --- a/drivers/tapdisk-interface.h +++ b/drivers/tapdisk-interface.h @@ -45,6 +45,7 @@ int td_validate_parent(td_image_t *, td_image_t *); void td_queue_write(td_image_t *, td_request_t); void td_queue_read(td_image_t *, td_request_t); +void td_queue_discard(td_image_t *, td_request_t); void td_forward_request(td_request_t); void td_complete_request(td_request_t, int); diff --git a/drivers/tapdisk-queue.c b/drivers/tapdisk-queue.c index 400e941d..ba4737b9 100644 --- a/drivers/tapdisk-queue.c +++ b/drivers/tapdisk-queue.c @@ -129,13 +129,16 @@ complete_tiocb(struct tqueue *queue, struct tiocb *tiocb, unsigned long res) int err; struct iocb *iocb = &tiocb->iocb; + if (tiocb->op == TIO_CMD_DISCARD) { + err = res; + } else { if (res == iocb->u.c.nbytes) err = 0; else if ((int)res < 0) err = (int)res; else err = -EIO; - + } tiocb->cb(tiocb->arg, tiocb, err); } @@ -228,6 +231,19 @@ tapdisk_rwio_rw(const struct iocb *iocb) return size; } +static inline ssize_t +tapdisk_rwio_discard(const struct iocb *iocb) +{ + int fd = iocb->aio_fildes; + int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE; + long long off = iocb->u.c.offset; + size_t size = iocb->u.c.nbytes; + + if (fallocate(fd, mode, off, size)) + return -errno; + return 0; +} + static int tapdisk_rwio_submit(struct tqueue *queue) { @@ -248,7 +264,11 @@ tapdisk_rwio_submit(struct tqueue *queue) for (i = 0; i < merged; i++) { ep = rwio->aio_events + i; iocb = queue->iocbs[i]; + tiocb = iocb->data; ep->obj = iocb; + if (tiocb->op == TIO_CMD_DISCARD) + ep->res = tapdisk_rwio_discard(iocb); + else ep->res = tapdisk_rwio_rw(iocb); } diff --git a/drivers/tapdisk-queue.h b/drivers/tapdisk-queue.h index f11cfc66..983a2c7e 100644 --- a/drivers/tapdisk-queue.h +++ b/drivers/tapdisk-queue.h @@ -36,16 +36,19 @@ #include "io-optimize.h" #include "scheduler.h" +#define TIO_CMD_READ 0 +#define TIO_CMD_WRITE 1 +#define TIO_CMD_DISCARD 2 + struct tiocb; struct tfilter; typedef void (*td_queue_callback_t)(void *arg, struct tiocb *, int err); - struct tiocb { td_queue_callback_t cb; void *arg; - + int op; struct iocb iocb; struct tiocb *next; }; diff --git a/drivers/tapdisk-server.c b/drivers/tapdisk-server.c index 49ecd8e0..3b534fec 100644 --- a/drivers/tapdisk-server.c +++ b/drivers/tapdisk-server.c @@ -292,7 +292,7 @@ static int tapdisk_server_init_aio(void) { return tapdisk_init_queue(&server.aio_queue, TAPDISK_TIOCBS, - TIO_DRV_LIO, NULL); + TIO_DRV_RWIO, NULL); } static void @@ -821,4 +821,3 @@ int tapdisk_server_event_set_timeout(event_id_t event_id, struct timeval timeo) { return scheduler_event_set_timeout(&server.scheduler, event_id, timeo); } - diff --git a/drivers/tapdisk-vbd.c b/drivers/tapdisk-vbd.c index c9ddd194..394310bc 100644 --- a/drivers/tapdisk-vbd.c +++ b/drivers/tapdisk-vbd.c @@ -1246,7 +1246,7 @@ __tapdisk_vbd_complete_td_request(td_vbd_t *vbd, td_vbd_request_t *vreq, vbd->vdi_stats.stats->read_reqs_completed++; vbd->vdi_stats.stats->read_sectors += treq.secs; vbd->vdi_stats.stats->read_total_ticks += interval; - }else{ + }else if (treq.op == TD_OP_WRITE){ vbd->vdi_stats.stats->write_reqs_completed++; vbd->vdi_stats.stats->write_sectors += treq.secs; vbd->vdi_stats.stats->write_total_ticks += interval; @@ -1501,6 +1501,56 @@ tapdisk_vbd_issue_request(td_vbd_t *vbd, td_vbd_request_t *vreq) goto out; } +static int +tapdisk_vbd_issue_request_discard(td_vbd_t *vbd, td_vbd_request_t *vreq) +{ + td_image_t *image; + td_request_t treq; + td_sector_t sec; + int err; + + sec = vreq->sec; + image = tapdisk_vbd_first_image(vbd); + + vreq->submitting = 1; + + tapdisk_vbd_mark_progress(vbd); + vreq->last_try = vbd->ts; + + tapdisk_vbd_move_request(vreq, &vbd->pending_requests); + + err = tapdisk_vbd_check_queue(vbd); + if (err) { + vreq->error = err; + goto out; + } + + err = tapdisk_image_check_request(image, vreq); + if (err) { + vreq->error = err; + goto out; + } + + treq.sidx = 0; + treq.sec = sec; + treq.secs = vreq->nr_sectors; + treq.image = image; + treq.cb = tapdisk_vbd_complete_td_request; + treq.cb_data = NULL; + treq.vreq = vreq; + treq.op = TD_OP_DISCARD; + td_queue_discard(treq.image, treq); + + out: + vreq->submitting--; + if (!vreq->secs_pending) { + err = (err ? : vreq->error); + tapdisk_vbd_complete_vbd_request(vbd, vreq); + } + + return err; +} + static int tapdisk_vbd_request_completed(td_vbd_t *vbd, td_vbd_request_t *vreq) { @@ -1540,6 +1590,9 @@ tapdisk_vbd_reissue_failed_requests(td_vbd_t *vbd) "sec 0x%08"PRIx64", iovcnt: %d\n", vreq->num_retries, vreq->name, vreq->sec, vreq->iovcnt); + if (vreq->op == TD_OP_DISCARD) + err = tapdisk_vbd_issue_request_discard(vbd, vreq); + else err = tapdisk_vbd_issue_request(vbd, vreq); /* * if this request failed, but was not completed, @@ -1571,6 +1624,9 @@ tapdisk_vbd_issue_new_requests(td_vbd_t *vbd) td_vbd_request_t *vreq, *tmp; tapdisk_vbd_for_each_request(vreq, tmp, &vbd->new_requests) { + if (vreq->op == TD_OP_DISCARD) + err = tapdisk_vbd_issue_request_discard(vbd, vreq); + else err = tapdisk_vbd_issue_request(vbd, vreq); /* * if this request failed, but was not completed, diff --git a/drivers/tapdisk.h b/drivers/tapdisk.h index f93932ed..2632f9a4 100644 --- a/drivers/tapdisk.h +++ b/drivers/tapdisk.h @@ -62,6 +62,7 @@ #include #include +#include #include "list.h" #include "compiler.h" @@ -74,7 +75,7 @@ extern unsigned int PAGE_MASK; extern unsigned int PAGE_SHIFT; #define MAX_SEGMENTS_PER_REQ 11 -#define MAX_REQUESTS 32U +#define MAX_REQUESTS 128U #define SECTOR_SHIFT 9 #define DEFAULT_SECTOR_SIZE 512 @@ -87,6 +88,7 @@ extern unsigned int PAGE_SHIFT; #define TD_OP_READ 0 #define TD_OP_WRITE 1 +#define TD_OP_DISCARD 2 #define TD_OPEN_QUIET 0x00001 #define TD_OPEN_QUERY 0x00002 @@ -138,6 +140,7 @@ struct td_disk_info { td_sector_t size; long sector_size; uint32_t info; + bool discard; }; struct td_iovec { @@ -148,6 +151,8 @@ struct td_iovec { struct td_vbd_request { int op; td_sector_t sec; + uint64_t nr_sectors; + struct td_iovec *iov; int iovcnt; @@ -199,6 +204,7 @@ struct tap_disk { int (*td_validate_parent) (td_driver_t *, td_driver_t *, td_flag_t); void (*td_queue_read) (td_driver_t *, td_request_t); void (*td_queue_write) (td_driver_t *, td_request_t); + void (*td_queue_discard) (td_driver_t *, td_request_t); void (*td_debug) (td_driver_t *); void (*td_stats) (td_driver_t *, td_stats_t *); diff --git a/drivers/td-blkif.h b/drivers/td-blkif.h index 0d16a95e..780de973 100644 --- a/drivers/td-blkif.h +++ b/drivers/td-blkif.h @@ -125,6 +125,7 @@ struct td_xenblkif { */ int n_reqs_free; + blkif_request_t **reqs_free; /** diff --git a/drivers/td-ctx.c b/drivers/td-ctx.c index 1a5956df..e30d4a4b 100644 --- a/drivers/td-ctx.c +++ b/drivers/td-ctx.c @@ -147,7 +147,7 @@ xenio_pending_blkif(struct td_xenio_ctx * const ctx) */ static inline void xenio_blkif_get_request(struct td_xenblkif * const blkif, - blkif_request_t *const dst, const RING_IDX idx) + void *dst, const RING_IDX idx) { blkif_back_rings_t * rings; @@ -167,17 +167,23 @@ xenio_blkif_get_request(struct td_xenblkif * const blkif, case BLKIF_PROTOCOL_X86_32: { - blkif_x86_32_request_t *src; + void *src; src = RING_GET_REQUEST(&rings->x86_32, idx); - blkif_get_req(dst, src); + if (((blkif_request_t *)(src))->operation == BLKIF_OP_DISCARD) + blkif_get_x86_32_req_discard(dst, src); + else + blkif_get_x86_32_req(dst, src); break; } case BLKIF_PROTOCOL_X86_64: { - blkif_x86_64_request_t *src; + void *src; src = RING_GET_REQUEST(&rings->x86_64, idx); - blkif_get_req(dst, src); + if (((blkif_request_t *)(src))->operation == BLKIF_OP_DISCARD) + blkif_get_x86_64_req_discard(dst, src); + else + blkif_get_x86_64_req(dst, src); break; } @@ -225,11 +231,12 @@ __xenio_blkif_get_requests(struct td_xenblkif * const blkif, rc != rp && n < count && !barrier; rc++, n++) { - blkif_request_t *dst = reqs[n]; + void *dst = reqs[n]; xenio_blkif_get_request(blkif, dst, rc); - if (unlikely(dst->operation == BLKIF_OP_WRITE_BARRIER)) + if (unlikely(((blkif_request_t *)(dst))->operation == BLKIF_OP_WRITE_BARRIER)) + barrier = true; } diff --git a/drivers/td-req.c b/drivers/td-req.c index 44ca1028..60ed7d6b 100644 --- a/drivers/td-req.c +++ b/drivers/td-req.c @@ -718,6 +718,37 @@ tapdisk_xenblkif_parse_request(struct td_xenblkif * const blkif, return err; } +static inline int +tapdisk_xenblkif_parse_request_discard(struct td_xenblkif * const blkif, + struct td_xenblkif_req * const req) +{ + td_vbd_request_t *vreq; + blkif_request_discard_t *req_discard; + int err = 0; + + ASSERT(blkif); + ASSERT(req); + + vreq = &req->vreq; + ASSERT(vreq); + + req_discard = (blkif_request_discard_t *)&req->msg; + vreq->sec = req_discard->sector_number; + vreq->nr_sectors = req_discard->nr_sectors; + + /* + * TODO Isn't this kind of expensive to do for each requests? Why does + * the tapdisk need this in the first place? + */ + snprintf(req->name, sizeof(req->name), "xenvbd-%d-%d.%"SCNx64"", + blkif->domid, blkif->devid, req->msg.id); + + vreq->name = req->name; + vreq->token = blkif; + vreq->cb = __tapdisk_xenblkif_request_cb; + + return err; +} /** * Initialises the standard tapdisk request (td_vbd_request_t) from the @@ -758,6 +789,12 @@ tapdisk_xenblkif_make_vbd_request(struct td_xenblkif * const blkif, tapreq->prot = PROT_READ; vreq->op = TD_OP_WRITE; break; + case BLKIF_OP_DISCARD: + blkif->stats.xenvbd->st_ds_req++; + //blkif->vbd_stats.stats->discard_reqs_submitted++; + tapreq->prot = PROT_READ; + vreq->op = TD_OP_DISCARD; + break; default: RING_ERR(blkif, "req %lu: invalid request type %d\n", tapreq->msg.id, tapreq->msg.operation); @@ -771,7 +808,8 @@ tapdisk_xenblkif_make_vbd_request(struct td_xenblkif * const blkif, * Check that the number of segments is sane. */ if (unlikely((tapreq->msg.nr_segments == 0 && - tapreq->msg.operation != BLKIF_OP_WRITE_BARRIER) || + tapreq->msg.operation != BLKIF_OP_WRITE_BARRIER && + tapreq->msg.operation != BLKIF_OP_DISCARD) || tapreq->msg.nr_segments > BLKIF_MAX_SEGMENTS_PER_REQUEST)) { RING_ERR(blkif, "req %lu: bad number of segments in request (%d)\n", tapreq->msg.id, tapreq->msg.nr_segments); @@ -779,8 +817,14 @@ tapdisk_xenblkif_make_vbd_request(struct td_xenblkif * const blkif, goto out; } - if (likely(tapreq->msg.nr_segments)) + if (unlikely(tapreq->msg.operation == BLKIF_OP_DISCARD)) { + err = tapdisk_xenblkif_parse_request_discard(blkif, tapreq); + goto out; + } + + if (likely(tapreq->msg.nr_segments)) { err = tapdisk_xenblkif_parse_request(blkif, tapreq); + } /* * If we only got one request from the ring and that was a barrier one, * check whether the barrier requests completion conditions are satisfied @@ -798,7 +842,6 @@ tapdisk_xenblkif_make_vbd_request(struct td_xenblkif * const blkif, return err; } - /** * Queues a ring request, after it prepares it, to the standard taodisk queue * for processing. @@ -841,7 +884,6 @@ tapdisk_xenblkif_queue_request(struct td_xenblkif * const blkif, return 0; } - void tapdisk_xenblkif_queue_requests(struct td_xenblkif * const blkif, blkif_request_t *reqs[], const int nr_reqs) diff --git a/include/tap-ctl.h b/include/tap-ctl.h index fec1b10f..86aac7f7 100644 --- a/include/tap-ctl.h +++ b/include/tap-ctl.h @@ -193,8 +193,9 @@ int tap_ctl_disconnect_xenblkif(const pid_t pid, const domid_t domid, * @param minor * */ -int tap_ctl_info(pid_t pid, unsigned long long *sectors, unsigned int - *sector_size, unsigned int *info, const int minor); +int tap_ctl_info(pid_t pid, unsigned long long *sectors, + unsigned int *sector_size, unsigned int *info, + bool *discard, const int minor); /** * Parses a type:/path/to/file string, storing the type and path to the output diff --git a/include/tapdisk-message.h b/include/tapdisk-message.h index e9504b0e..bc171f0f 100644 --- a/include/tapdisk-message.h +++ b/include/tapdisk-message.h @@ -32,6 +32,7 @@ #define _TAPDISK_MESSAGE_H_ #include +#include #include /* @@ -81,6 +82,7 @@ struct tapdisk_message_image { uint64_t sectors; uint32_t sector_size; uint32_t info; + bool discard; }; struct tapdisk_message_string { diff --git a/include/xen_blkif.h b/include/xen_blkif.h index 1402f4db..ae8ae4eb 100644 --- a/include/xen_blkif.h +++ b/include/xen_blkif.h @@ -46,6 +46,8 @@ struct blkif_common_response { char dummy; }; +typedef union blkif_request_common blkif_request_common_t; + /* i386 protocol version */ #pragma pack(push, 4) struct blkif_x86_32_request { @@ -56,12 +58,21 @@ struct blkif_x86_32_request { blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; }; +struct blkif_x86_32_request_discard { + uint8_t operation; /* BLKIF_OP_??? */ + uint8_t flags; /* BLKIF_DISCARD_SECURE or zero */ + blkif_vdev_t handle; /* only for read/write requests */ + uint64_t id; /* private guest value, echoed in resp */ + blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ + uint64_t nr_sectors; /* number of contiguous sectors to discard */ +}; struct blkif_x86_32_response { uint64_t id; /* copied from request */ uint8_t operation; /* copied from request */ int16_t status; /* BLKIF_RSP_??? */ }; typedef struct blkif_x86_32_request blkif_x86_32_request_t; +typedef struct blkif_x86_32_request_discard blkif_x86_32_request_discard_t; typedef struct blkif_x86_32_response blkif_x86_32_response_t; #pragma pack(pop) @@ -74,12 +85,22 @@ struct blkif_x86_64_request { blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; }; +struct blkif_x86_64_request_discard { + uint8_t operation; /* BLKIF_OP_??? */ + uint8_t flags; /* BLKIF_DISCARD_SECURE or zero */ + blkif_vdev_t handle; /* only for read/write requests */ + uint32_t pad; + uint64_t id; /* private guest value, echoed in resp */ + blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ + uint64_t nr_sectors; /* number of contiguous sectors to discard */ +}; struct blkif_x86_64_response { uint64_t __attribute__((__aligned__(8))) id; uint8_t operation; /* copied from request */ int16_t status; /* BLKIF_RSP_??? */ }; typedef struct blkif_x86_64_request blkif_x86_64_request_t; +typedef struct blkif_x86_64_request_discard blkif_x86_64_request_discard_t; typedef struct blkif_x86_64_response blkif_x86_64_response_t; DEFINE_RING_TYPES(blkif_common, struct blkif_common_request, struct blkif_common_response); @@ -130,4 +151,24 @@ static inline void blkif_get_x86_64_req(blkif_request_t *dst, blkif_x86_64_reque dst->seg[i] = src->seg[i]; } +static inline void +blkif_get_x86_32_req_discard(blkif_request_discard_t *dst, + blkif_x86_32_request_discard_t *src) +{ + dst->operation = src->operation; + dst->nr_sectors = src->nr_sectors; + dst->handle = src->handle; + dst->id = src->id; + dst->sector_number = src->sector_number; +} + +static inline void blkif_get_x86_64_req_discard(blkif_request_discard_t *dst, + blkif_x86_64_request_discard_t *src) +{ + dst->operation = src->operation; + dst->nr_sectors = src->nr_sectors; + dst->handle = src->handle; + dst->id = src->id; + dst->sector_number = src->sector_number; +} #endif /* __XEN_BLKIF_H__ */ diff --git a/tapback/backend.c b/tapback/backend.c index b84393e2..3783bab5 100644 --- a/tapback/backend.c +++ b/tapback/backend.c @@ -358,7 +358,7 @@ physical_device_changed(vbd_t *device) { */ if ((err = tap_ctl_info(device->tap->pid, &device->sectors, &device->sector_size, &info, - device->minor))) { + &device->discard, device->minor))) { WARN(device, "error retrieving disk characteristics: %s\n", strerror(-err)); goto out; diff --git a/tapback/frontend.c b/tapback/frontend.c index 9109a508..984fc167 100644 --- a/tapback/frontend.c +++ b/tapback/frontend.c @@ -300,6 +300,32 @@ connect_frontend(vbd_t *device) { break; } + if (device->backend->discard && + device->mode == true && + device->cdrom == false) { + + if ((err = tapback_device_printf(device, xst, "discard-granularity", + true, "%u", device->sector_size))) { + WARN(device, "failed to write discard-granularity: %s\n", + strerror(-err)); + break; + } + + if ((err = tapback_device_printf(device, xst, "discard-alignment", + true, "%u", 0))) { + WARN(device, "failed to write discard-alignment: %s\n", + strerror(-err)); + break; + } + + if ((err = tapback_device_printf(device, xst, "feature-discard", + true, "%u", 1))) { + WARN(device, "failed to write feature-discard: %s\n", + strerror(-err)); + break; + } + } + if ((err = tapback_device_printf(device, xst, "sector-size", true, "%u", device->sector_size))) { WARN(device, "failed to write sector-size: %s\n", strerror(-err)); diff --git a/tapback/tapback.c b/tapback/tapback.c index fe04d177..4ce9caca 100644 --- a/tapback/tapback.c +++ b/tapback/tapback.c @@ -230,7 +230,7 @@ tapback_write_pid(const char *pidfile) */ static inline backend_t * tapback_backend_create(const char *name, const char *pidfile, - const domid_t domid, const bool barrier) + const domid_t domid, const bool barrier, const bool discard) { int err; int len; @@ -269,6 +269,8 @@ tapback_backend_create(const char *name, const char *pidfile, backend->path = NULL; + backend->discard = discard; + INIT_LIST_HEAD(&backend->entry); if (domid) { @@ -586,6 +588,7 @@ int main(int argc, char **argv) backend_t *backend = NULL; domid_t opt_domid = 0; bool opt_barrier = true; + bool opt_discard = true; if (access("/dev/xen/gntdev", F_OK ) == -1) { WARN(NULL, "grant device does not exist\n"); @@ -613,11 +616,12 @@ int main(int argc, char **argv) {"pidfile", 0, NULL, 'p'}, {"domain", 0, NULL, 'x'}, {"nobarrier", 0, NULL, 'b'}, + {"nodiscard", 0, NULL, 's'}, }; int c; - c = getopt_long(argc, argv, "hdvn:p:x:b", longopts, NULL); + c = getopt_long(argc, argv, "hdvn:p:x:b:s", longopts, NULL); if (c < 0) break; @@ -657,6 +661,8 @@ int main(int argc, char **argv) case 'b': opt_barrier = false; break; + case 's': + opt_discard = false; case '?': goto usage; } @@ -691,7 +697,7 @@ int main(int argc, char **argv) } backend = tapback_backend_create(opt_name, opt_pidfile, opt_domid, - opt_barrier); + opt_barrier, opt_discard); if (!backend) { err = errno; WARN(NULL, "error creating back-end: %s\n", strerror(err)); diff --git a/tapback/tapback.h b/tapback/tapback.h index da116632..4168145a 100644 --- a/tapback/tapback.h +++ b/tapback/tapback.h @@ -208,6 +208,11 @@ typedef struct backend { * Tells whether we support write I/O barriers. */ bool barrier; + + /** + * Tells whether we support discard. + */ + bool discard; } backend_t; /** @@ -284,6 +289,11 @@ typedef struct vbd { */ unsigned long long sectors; + /** + * Whether the backing driver supports discard + */ + bool discard; + /** * VDISK_???, defined in include/xen/interface/io/blkif.h. */ From 9a63b93afd0e7a1106908526c246b787f42323df Mon Sep 17 00:00:00 2001 From: Alex Lanzano Date: Wed, 19 Sep 2018 15:33:42 -0400 Subject: [PATCH 2/2] whitespace changes --- drivers/block-vhd.c | 98 ++++++++++++++++++++-------------------- drivers/tapdisk-filter.c | 6 +-- drivers/tapdisk-image.c | 6 +-- drivers/tapdisk-queue.c | 32 ++++++------- drivers/tapdisk-queue.h | 10 ++-- drivers/tapdisk-server.c | 6 +-- drivers/tapdisk-vbd.c | 36 +++++++-------- drivers/td-blkif.c | 6 +-- drivers/td-blkif.h | 6 +-- drivers/td-ctx.c | 6 +-- drivers/td-req.c | 12 ++--- include/xen_blkif.h | 6 +-- tapback/backend.c | 8 ++-- tapback/tapback.c | 6 +-- 14 files changed, 122 insertions(+), 122 deletions(-) diff --git a/drivers/block-vhd.c b/drivers/block-vhd.c index fee10c8f..647a106a 100644 --- a/drivers/block-vhd.c +++ b/drivers/block-vhd.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -203,12 +203,12 @@ struct vhd_bitmap { char *map; /* map should only be modified * in finish_bitmap_write */ - char *shadow; /* in-memory bitmap changes are + char *shadow; /* in-memory bitmap changes are * made to shadow and copied to * map only after having been * flushed to disk */ struct vhd_transaction tx; /* transaction data structure - * encapsulating data, bitmap, + * encapsulating data, bitmap, * and bat writes */ struct vhd_req_list queue; /* data writes waiting for next * transaction */ @@ -677,7 +677,7 @@ __vhd_open(td_driver_t *driver, const char *name, vhd_flag_t flags) if (err) return err; - o_flags = ((test_vhd_flag(flags, VHD_FLAG_OPEN_RDONLY)) ? + o_flags = ((test_vhd_flag(flags, VHD_FLAG_OPEN_RDONLY)) ? VHD_OPEN_RDONLY : VHD_OPEN_RDWR); if ((test_vhd_flag(flags, VHD_FLAG_OPEN_RDONLY) || test_vhd_flag(flags, VHD_FLAG_OPEN_LOCAL_CACHE)) && @@ -725,7 +725,7 @@ __vhd_open(td_driver_t *driver, const char *name, vhd_flag_t flags) DBG(TLOG_INFO, "vhd_open: done (sz:%"PRIu64", sct:%lu, inf:%u)\n", driver->info.size, driver->info.sector_size, driver->info.info); - if (test_vhd_flag(flags, VHD_FLAG_OPEN_STRICT) && + if (test_vhd_flag(flags, VHD_FLAG_OPEN_STRICT) && !test_vhd_flag(flags, VHD_FLAG_OPEN_RDONLY)) { err = vhd_kill_footer(s); if (err) { @@ -803,21 +803,21 @@ _vhd_close(td_driver_t *driver) { int err; struct vhd_state *s; - + DBG(TLOG_WARN, "vhd_close\n"); s = (struct vhd_state *)driver->data; - DPRINTF("gaps written/skipped: %ld/%ld\n", + DPRINTF("gaps written/skipped: %ld/%ld\n", s->debug_done_redundant_writes, s->debug_skipped_redundant_writes); /* don't write footer if tapdisk is read-only */ if (test_vhd_flag(s->flags, VHD_FLAG_OPEN_RDONLY)) goto free; - - /* + + /* * write footer if: - * - we killed it on open (opened with strict) + * - we killed it on open (opened with strict) * - we've written data since opening */ if (test_vhd_flag(s->flags, VHD_FLAG_OPEN_STRICT) || s->writes) { @@ -867,7 +867,7 @@ vhd_validate_parent(td_driver_t *child_driver, parent = (struct vhd_state *)parent_driver->data; - /* + /* * This check removed because of cases like: * - parent VHD marked as 'hidden' * - parent VHD modified during coalesce @@ -893,7 +893,7 @@ vhd_validate_parent(td_driver_t *child_driver, } /* TODO: compare sizes */ - + return 0; } @@ -934,9 +934,9 @@ clear_req_list(struct vhd_req_list *list) static inline void add_to_tail(struct vhd_req_list *list, struct vhd_request *e) { - if (!list->head) + if (!list->head) list->head = list->tail = e; - else + else list->tail = list->tail->next = e; } @@ -1136,7 +1136,7 @@ static int alloc_vhd_bitmap(struct vhd_state *s, struct vhd_bitmap **bitmap, uint32_t blk) { struct vhd_bitmap *bm; - + *bitmap = NULL; if (s->bm_free_count > 0) { @@ -1220,7 +1220,7 @@ read_bitmap_cache(struct vhd_state *s, uint64_t sector, uint8_t op) struct vhd_bitmap *bm; /* in fixed disks, every block is present */ - if (s->vhd.footer.type == HD_TYPE_FIXED) + if (s->vhd.footer.type == HD_TYPE_FIXED) return VHD_BM_BIT_SET; /* the extent the logical sector falls in */ @@ -1258,12 +1258,12 @@ read_bitmap_cache(struct vhd_state *s, uint64_t sector, uint8_t op) if (test_vhd_flag(bm->status, VHD_FLAG_BM_READ_PENDING)) return VHD_BM_READ_PENDING; - return ((vhd_bitmap_test(&s->vhd, bm->map, sec)) ? + return ((vhd_bitmap_test(&s->vhd, bm->map, sec)) ? VHD_BM_BIT_SET : VHD_BM_BIT_CLEAR); } static int -read_bitmap_cache_span(struct vhd_state *s, +read_bitmap_cache_span(struct vhd_state *s, uint64_t sector, int nr_secs, int value) { int ret; @@ -1271,7 +1271,7 @@ read_bitmap_cache_span(struct vhd_state *s, struct vhd_bitmap *bm; /* in fixed disks, every block is present */ - if (s->vhd.footer.type == HD_TYPE_FIXED) + if (s->vhd.footer.type == HD_TYPE_FIXED) return nr_secs; sec = sector % s->spb; @@ -1281,7 +1281,7 @@ read_bitmap_cache_span(struct vhd_state *s, return MIN(nr_secs, s->spb - sec); bm = get_bitmap(s, blk); - + ASSERT(bm && bitmap_valid(bm)); for (ret = 0; sec < s->spb && ret < nr_secs; sec++, ret++) @@ -1295,7 +1295,7 @@ static inline struct vhd_request * alloc_vhd_request(struct vhd_state *s) { struct vhd_request *req = NULL; - + if (s->vreq_free_count > 0) { req = s->vreq_free[--s->vreq_free_count]; ASSERT(req->treq.secs == 0); @@ -1455,22 +1455,22 @@ schedule_zero_bm_write(struct vhd_state *s, aio_write(s, req, offset); } -/* This is a performance optimization. When writing sequentially into full - * blocks, skipping (up-to-date) bitmaps causes an approx. 25% reduction in - * throughput. To prevent skipping, we issue redundant writes into the (padded) - * bitmap area just to make all writes sequential. This will help VHDs on raw +/* This is a performance optimization. When writing sequentially into full + * blocks, skipping (up-to-date) bitmaps causes an approx. 25% reduction in + * throughput. To prevent skipping, we issue redundant writes into the (padded) + * bitmap area just to make all writes sequential. This will help VHDs on raw * block devices, while the FS-based VHDs shouldn't suffer much. * - * Note that it only makes sense to perform this reduntant bitmap write if the - * block is completely full (i.e. the batmap entry is set). If the block is not + * Note that it only makes sense to perform this reduntant bitmap write if the + * block is completely full (i.e. the batmap entry is set). If the block is not * completely full then one of the following two things will be true: * 1. we'll either be allocating new sectors in this block and writing its * bitmap transactionally, which will be slow anyways; or * 2. the IO will be skipping over the unallocated sectors again, so the * pattern will not be sequential anyways - * In either case a redundant bitmap write becomes pointless. This fact - * simplifies the implementation of redundant writes: since we know the bitmap - * cannot be updated by anyone else, we don't have to worry about transactions + * In either case a redundant bitmap write becomes pointless. This fact + * simplifies the implementation of redundant writes: since we know the bitmap + * cannot be updated by anyone else, we don't have to worry about transactions * or potential write conflicts. * */ static void @@ -1483,7 +1483,7 @@ schedule_redundant_bm_write(struct vhd_state *s, uint32_t blk) ASSERT(test_batmap(s, blk)); req = alloc_vhd_request(s); - if (!req) + if (!req) return; req->treq.buf = s->padbm_buf; @@ -1512,7 +1512,7 @@ update_bat(struct vhd_state *s, uint32_t blk) struct vhd_bitmap *bm; ASSERT(bat_entry(s, blk) == DD_BLK_UNUSED); - + if (bat_locked(s)) { ASSERT(s->bat.pbw_blk == blk); return 0; @@ -1524,7 +1524,7 @@ update_bat(struct vhd_state *s, uint32_t blk) if (!bm) { /* install empty bitmap in cache */ err = alloc_vhd_bitmap(s, &bm, blk); - if (err) + if (err) return err; install_bitmap(s, bm); @@ -1601,7 +1601,7 @@ allocate_block(struct vhd_state *s, uint32_t blk) if (!bm) { /* install empty bitmap in cache */ err = alloc_vhd_bitmap(s, &bm, blk); - if (err) + if (err) return err; install_bitmap(s, bm); @@ -1615,7 +1615,7 @@ allocate_block(struct vhd_state *s, uint32_t blk) return 0; } -static int +static int schedule_data_read(struct vhd_state *s, td_request_t treq, vhd_flag_t flags) { uint64_t offset; @@ -1641,7 +1641,7 @@ schedule_data_read(struct vhd_state *s, td_request_t treq, vhd_flag_t flags) make_request: req = alloc_vhd_request(s); - if (!req) + if (!req) return -EBUSY; req->treq = treq; @@ -1713,7 +1713,7 @@ schedule_data_write(struct vhd_state *s, td_request_t treq, vhd_flag_t flags) } else add_to_transaction(&bm->tx, req); } else if (sec == 0 && /* first sector inside data block */ - s->vhd.footer.type != HD_TYPE_FIXED && + s->vhd.footer.type != HD_TYPE_FIXED && bat_entry(s, blk) != s->first_db && test_batmap(s, blk)) schedule_redundant_bm_write(s, blk); @@ -1771,7 +1771,7 @@ schedule_discard(struct vhd_state *s, td_request_t treq, vhd_flag_t flags) return 0; } -static int +static int schedule_bitmap_read(struct vhd_state *s, uint32_t blk) { int err; @@ -1832,7 +1832,7 @@ schedule_bitmap_write(struct vhd_state *s, uint32_t blk) ASSERT(bat_locked(s) && s->bat.pbw_blk == blk); offset = s->bat.pbw_offset; } - + offset = vhd_sectors_to_bytes(offset); req = &bm->req; @@ -1855,9 +1855,9 @@ schedule_bitmap_write(struct vhd_state *s, uint32_t blk) req->treq.secs, offset); } -/* +/* * queued requests will be submitted once the bitmap - * describing them is read and the requests are validated. + * describing them is read and the requests are validated. */ static int __vhd_queue_request(struct vhd_state *s, uint8_t op, td_request_t treq) @@ -2246,7 +2246,7 @@ finish_bitmap_transaction(struct vhd_state *s, if (test_vhd_flag(tx->status, VHD_FLAG_TX_UPDATE_BAT)) { /* still waiting for bat write */ ASSERT(bm->blk == s->bat.pbw_blk); - ASSERT(test_vhd_flag(s->bat.status, + ASSERT(test_vhd_flag(s->bat.status, VHD_FLAG_BAT_WRITE_STARTED)); s->bat.req.tx = tx; return; @@ -2371,7 +2371,7 @@ finish_redundant_bm_write(struct vhd_request *req) struct vhd_state *s = (struct vhd_state *) req->state; s->returned++; - TRACE(s); + TRACE(s); /* blk = req->treq.sec / s->spb; DBG(TLOG_DBG, "blk: %u\n", blk); */ @@ -2415,7 +2415,7 @@ finish_bitmap_read(struct vhd_request *req) next = r->next; free_vhd_request(s, r); - ASSERT(tmp.op == VHD_OP_DATA_READ || + ASSERT(tmp.op == VHD_OP_DATA_READ || tmp.op == VHD_OP_DATA_WRITE || tmp.op == VHD_OP_DISCARD); @@ -2470,7 +2470,7 @@ finish_data_read(struct vhd_request *req) { struct vhd_state *s = req->state; - DBG(TLOG_DBG, "lsec 0x%08"PRIx64", blk: 0x%04"PRIx64"\n", + DBG(TLOG_DBG, "lsec 0x%08"PRIx64", blk: 0x%04"PRIx64"\n", req->treq.sec, req->treq.sec / s->spb); signal_completion(req, 0); } @@ -2509,7 +2509,7 @@ finish_data_write(struct vhd_request *req) } else if (!test_vhd_flag(req->flags, VHD_FLAG_REQ_QUEUED)) { ASSERT(!req->next); - DBG(TLOG_DBG, "lsec: 0x%08"PRIx64", blk: 0x%04"PRIx64"\n", + DBG(TLOG_DBG, "lsec: 0x%08"PRIx64", blk: 0x%04"PRIx64"\n", req->treq.sec, req->treq.sec / s->spb); signal_completion(req, 0); } @@ -2613,7 +2613,7 @@ vhd_complete(void *arg, struct tiocb *tiocb, int err) } } -void +void vhd_debug(td_driver_t *driver) { int i; diff --git a/drivers/tapdisk-filter.c b/drivers/tapdisk-filter.c index f2c25d94..28499095 100644 --- a/drivers/tapdisk-filter.c +++ b/drivers/tapdisk-filter.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS diff --git a/drivers/tapdisk-image.c b/drivers/tapdisk-image.c index e8747c4e..3ab66adc 100644 --- a/drivers/tapdisk-image.c +++ b/drivers/tapdisk-image.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS diff --git a/drivers/tapdisk-queue.c b/drivers/tapdisk-queue.c index ba4737b9..4927a7ce 100644 --- a/drivers/tapdisk-queue.c +++ b/drivers/tapdisk-queue.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -132,12 +132,12 @@ complete_tiocb(struct tqueue *queue, struct tiocb *tiocb, unsigned long res) if (tiocb->op == TIO_CMD_DISCARD) { err = res; } else { - if (res == iocb->u.c.nbytes) - err = 0; - else if ((int)res < 0) - err = (int)res; - else - err = -EIO; + if (res == iocb->u.c.nbytes) + err = 0; + else if ((int)res < 0) + err = (int)res; + else + err = -EIO; } tiocb->cb(tiocb->arg, tiocb, err); } @@ -151,11 +151,11 @@ cancel_tiocbs(struct tqueue *queue, int err) if (!queue->queued) return 0; - /* + /* * td_complete may queue more tiocbs, which * will overwrite the contents of queue->iocbs. * use a private linked list to keep track - * of the tiocbs we're cancelling. + * of the tiocbs we're cancelling. */ tiocb = queue->iocbs[0]->data; queued = queue->queued; @@ -173,7 +173,7 @@ fail_tiocbs(struct tqueue *queue, int succeeded, int total, int err) ERR(err, "io_submit error: %d of %d failed", total - succeeded, total); - /* take any non-submitted, merged iocbs + /* take any non-submitted, merged iocbs * off of the queue, split them, and fail them */ queue->queued = io_expand_iocbs(&queue->opioctx, queue->iocbs, succeeded, total); @@ -219,7 +219,7 @@ tapdisk_rwio_rw(const struct iocb *iocb) char *buf = iocb->u.c.buf; long long off = iocb->u.c.offset; size_t size = iocb->u.c.nbytes; - ssize_t (*func)(int, void *, size_t) = + ssize_t (*func)(int, void *, size_t) = (iocb->aio_lio_opcode == IO_CMD_PWRITE ? vwrite : read); if (lseek64(fd, off, SEEK_SET) == (off64_t)-1) @@ -269,7 +269,7 @@ tapdisk_rwio_submit(struct tqueue *queue) if (tiocb->op == TIO_CMD_DISCARD) ep->res = tapdisk_rwio_discard(iocb); else - ep->res = tapdisk_rwio_rw(iocb); + ep->res = tapdisk_rwio_rw(iocb); } split = io_split(&queue->opioctx, rwio->aio_events, merged); @@ -559,7 +559,7 @@ tapdisk_lio_submit(struct tqueue *queue) queue->queued = 0; if (err) - queue->tiocbs_pending -= + queue->tiocbs_pending -= fail_tiocbs(queue, submitted, merged, err); return submitted; @@ -676,7 +676,7 @@ tapdisk_free_queue(struct tqueue *queue) opio_free(&queue->opioctx); } -void +void tapdisk_debug_queue(struct tqueue *queue) { struct tiocb *tiocb = queue->deferred.head; diff --git a/drivers/tapdisk-queue.h b/drivers/tapdisk-queue.h index 983a2c7e..181c3eb1 100644 --- a/drivers/tapdisk-queue.h +++ b/drivers/tapdisk-queue.h @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -72,8 +72,8 @@ struct tqueue { /* number of iocbs pending in the aio layer */ int iocbs_pending; - /* number of tiocbs pending in the queue -- - * this is likely to be larger than iocbs_pending + /* number of tiocbs pending in the queue -- + * this is likely to be larger than iocbs_pending * due to request coalescing */ int tiocbs_pending; diff --git a/drivers/tapdisk-server.c b/drivers/tapdisk-server.c index 3b534fec..c673bd4e 100644 --- a/drivers/tapdisk-server.c +++ b/drivers/tapdisk-server.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS diff --git a/drivers/tapdisk-vbd.c b/drivers/tapdisk-vbd.c index 394310bc..057b88ea 100644 --- a/drivers/tapdisk-vbd.c +++ b/drivers/tapdisk-vbd.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -426,7 +426,7 @@ tapdisk_vbd_add_secondary(td_vbd_t *vbd) vbd->secondary=NULL; vbd->secondary_mode=TD_VBD_SECONDARY_DISABLED; - + goto fail; } @@ -446,7 +446,7 @@ tapdisk_vbd_add_secondary(td_vbd_t *vbd) DPRINTF("In mirror mode\n"); vbd->secondary_mode = TD_VBD_SECONDARY_MIRROR; /* - * we actually need this image to also be part of the chain, + * we actually need this image to also be part of the chain, * since it may already contain data */ list_add(&second->next, &leaf->next); @@ -750,7 +750,7 @@ tapdisk_vbd_shutdown(td_vbd_t *vbd) tapdisk_vbd_queue_count(vbd, &new, &pending, &failed, &completed); DPRINTF("%s: state: 0x%08x, new: 0x%02x, pending: 0x%02x, " - "failed: 0x%02x, completed: 0x%02x\n", + "failed: 0x%02x, completed: 0x%02x\n", vbd->name, vbd->state, new, pending, failed, completed); DPRINTF("last activity: %010ld.%06ld, errors: 0x%04"PRIx64", " "retries: 0x%04"PRIx64", received: 0x%08"PRIx64", " @@ -777,7 +777,7 @@ tapdisk_vbd_close(td_vbd_t *vbd) if (!list_empty(&vbd->pending_requests)) goto fail; - /* + /* * if the queue is still active and we have more * requests, try to complete them before closing. */ @@ -1144,7 +1144,7 @@ tapdisk_vbd_check_progress(td_vbd_t *vbd) } /* - * request submission + * request submission */ static int @@ -1371,8 +1371,8 @@ tapdisk_vbd_complete_td_request(td_request_t treq, int res) } } - if (res != 0 && image->type == DISK_TYPE_NBD && - ((image == vbd->secondary) || + if (res != 0 && image->type == DISK_TYPE_NBD && + ((image == vbd->secondary) || (image == vbd->retired))) { ERROR("Got non-zero res for NBD secondary - disabling " "mirroring: %s",vreq->name); @@ -1459,12 +1459,12 @@ tapdisk_vbd_issue_request(td_vbd_t *vbd, td_vbd_request_t *vreq) treq.op = TD_OP_WRITE; vbd->vdi_stats.stats->write_reqs_submitted++; /* - * it's important to queue the mirror request before - * queuing the main one. If the main image runs into - * ENOSPC, the mirroring could be disabled before - * td_queue_write returns, so if the mirror request was - * queued after (which would then not happen), we'd - * lose that write and cause the process to hang with + * it's important to queue the mirror request before + * queuing the main one. If the main image runs into + * ENOSPC, the mirroring could be disabled before + * td_queue_write returns, so if the mirror request was + * queued after (which would then not happen), we'd + * lose that write and cause the process to hang with * unacknowledged writes */ if (vbd->secondary_mode == TD_VBD_SECONDARY_MIRROR) @@ -1593,7 +1593,7 @@ tapdisk_vbd_reissue_failed_requests(td_vbd_t *vbd) if (vreq->op == TD_OP_DISCARD) err = tapdisk_vbd_issue_request_discard(vbd, vreq); else - err = tapdisk_vbd_issue_request(vbd, vreq); + err = tapdisk_vbd_issue_request(vbd, vreq); /* * if this request failed, but was not completed, * we'll back off for a while. @@ -1627,7 +1627,7 @@ tapdisk_vbd_issue_new_requests(td_vbd_t *vbd) if (vreq->op == TD_OP_DISCARD) err = tapdisk_vbd_issue_request_discard(vbd, vreq); else - err = tapdisk_vbd_issue_request(vbd, vreq); + err = tapdisk_vbd_issue_request(vbd, vreq); /* * if this request failed, but was not completed, * we'll back off for a while. diff --git a/drivers/td-blkif.c b/drivers/td-blkif.c index 31a105bd..a704471a 100644 --- a/drivers/td-blkif.c +++ b/drivers/td-blkif.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS diff --git a/drivers/td-blkif.h b/drivers/td-blkif.h index 780de973..ca43884e 100644 --- a/drivers/td-blkif.h +++ b/drivers/td-blkif.h @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS diff --git a/drivers/td-ctx.c b/drivers/td-ctx.c index e30d4a4b..05d2961e 100644 --- a/drivers/td-ctx.c +++ b/drivers/td-ctx.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS diff --git a/drivers/td-req.c b/drivers/td-req.c index 60ed7d6b..dd0122dc 100644 --- a/drivers/td-req.c +++ b/drivers/td-req.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -701,7 +701,7 @@ tapdisk_xenblkif_parse_request(struct td_xenblkif * const blkif, } else { blkif->stats.xenvbd->st_rd_sect += nr_sect; blkif->vbd_stats.stats->read_sectors += nr_sect; - } + } /* * TODO Isn't this kind of expensive to do for each requests? Why does @@ -914,8 +914,8 @@ tapdisk_xenblkif_queue_requests(struct td_xenblkif * const blkif, } } - /* there is a possibility of blkif getting freed if ring is - dead and current request is the last one, hence adding + /* there is a possibility of blkif getting freed if ring is + dead and current request is the last one, hence adding this check to avoid seg fault */ if (nr_errors && blkif) diff --git a/include/xen_blkif.h b/include/xen_blkif.h index ae8ae4eb..182b4e8c 100644 --- a/include/xen_blkif.h +++ b/include/xen_blkif.h @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS diff --git a/tapback/backend.c b/tapback/backend.c index 3783bab5..f2a59431 100644 --- a/tapback/backend.c +++ b/tapback/backend.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS @@ -357,7 +357,7 @@ physical_device_changed(vbd_t *device) { * get the VBD parameters from the tapdisk */ if ((err = tap_ctl_info(device->tap->pid, &device->sectors, - &device->sector_size, &info, + &device->sector_size, &info, &device->discard, device->minor))) { WARN(device, "error retrieving disk characteristics: %s\n", strerror(-err)); diff --git a/tapback/tapback.c b/tapback/tapback.c index 4ce9caca..52da018e 100644 --- a/tapback/tapback.c +++ b/tapback/tapback.c @@ -5,14 +5,14 @@ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS