From 8516ffb72740fd08201a75e8520b4b3f76f4cdd4 Mon Sep 17 00:00:00 2001 From: Felipe Franciosi Date: Tue, 3 Mar 2015 12:06:20 +0000 Subject: [PATCH 1/3] CP-11368: Enabling interface for oflags retrieval This commit implements the interface for retrieving the flags used by the driver to open an image. --- drivers/tapdisk-interface.c | 18 ++++++++++++++++++ drivers/tapdisk-interface.h | 1 + drivers/tapdisk.h | 1 + 3 files changed, 20 insertions(+) diff --git a/drivers/tapdisk-interface.c b/drivers/tapdisk-interface.c index 661ebcbe..6fdf998c 100644 --- a/drivers/tapdisk-interface.c +++ b/drivers/tapdisk-interface.c @@ -120,6 +120,24 @@ td_close(td_image_t *image) return 0; } +int +td_get_oflags(td_image_t *image, int *flags) +{ + td_driver_t *driver; + + driver = image->driver; + if (!driver) + return -ENODEV; + + if (!td_flag_test(driver->state, TD_DRIVER_OPEN)) + return -EBADF; + + if (!driver->ops->td_get_oflags) + return -ENOTSUP; + + return driver->ops->td_get_oflags(driver, flags); +} + int td_get_parent_id(td_image_t *image, td_disk_id_t *id) { diff --git a/drivers/tapdisk-interface.h b/drivers/tapdisk-interface.h index 7ec40188..b61d49e3 100644 --- a/drivers/tapdisk-interface.h +++ b/drivers/tapdisk-interface.h @@ -27,6 +27,7 @@ int td_open(td_image_t *); int __td_open(td_image_t *, td_disk_info_t *); int td_load(td_image_t *); int td_close(td_image_t *); +int td_get_oflags(td_image_t *, int *); int td_get_parent_id(td_image_t *, td_disk_id_t *); int td_validate_parent(td_image_t *, td_image_t *); diff --git a/drivers/tapdisk.h b/drivers/tapdisk.h index bddedbfc..3e4ff75d 100644 --- a/drivers/tapdisk.h +++ b/drivers/tapdisk.h @@ -182,6 +182,7 @@ struct tap_disk { int private_data_size; int (*td_open) (td_driver_t *, const char *, td_flag_t); int (*td_close) (td_driver_t *); + int (*td_get_oflags) (td_driver_t *, int *); int (*td_get_parent_id) (td_driver_t *, td_disk_id_t *); int (*td_validate_parent) (td_driver_t *, td_driver_t *, td_flag_t); void (*td_queue_read) (td_driver_t *, td_request_t); From 09a24c394c65d35b4b902a248d977305c3f4d7a0 Mon Sep 17 00:00:00 2001 From: Felipe Franciosi Date: Mon, 2 Mar 2015 16:59:55 +0000 Subject: [PATCH 2/3] CP-11369: Implement td_get_oflags for the vhd driver --- drivers/block-vhd.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/block-vhd.c b/drivers/block-vhd.c index 9cdc1a7e..b4ad4cf6 100644 --- a/drivers/block-vhd.c +++ b/drivers/block-vhd.c @@ -832,6 +832,21 @@ _vhd_close(td_driver_t *driver) return 0; } +static int +vhd_get_oflags(td_driver_t *driver, int *flags) +{ + struct vhd_state *s = driver->data; + + *flags = fcntl(s->vhd.fd, F_GETFL, 0); + if (*flags == -1){ + *flags = 0; + ERR(s, -errno, "fcntl failed\n"); + return -errno; + } + + return 0; +} + int vhd_validate_parent(td_driver_t *child_driver, td_driver_t *parent_driver, td_flag_t flags) @@ -2479,6 +2494,7 @@ struct tap_disk tapdisk_vhd = { .private_data_size = sizeof(struct vhd_state), .td_open = _vhd_open, .td_close = _vhd_close, + .td_get_oflags = vhd_get_oflags, .td_queue_read = vhd_queue_read, .td_queue_write = vhd_queue_write, .td_get_parent_id = vhd_get_parent_id, From 9d879bd7342bf8455cb4b6741bc08544ebeb2c2c Mon Sep 17 00:00:00 2001 From: Felipe Franciosi Date: Mon, 2 Mar 2015 17:00:22 +0000 Subject: [PATCH 3/3] CA-162087: Update o_direct flag after opening image This fixes the issue where "read_caching" is incorrectly reported by tap-ctl stats. --- drivers/tapdisk-vbd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/tapdisk-vbd.c b/drivers/tapdisk-vbd.c index ed73c464..51304940 100644 --- a/drivers/tapdisk-vbd.c +++ b/drivers/tapdisk-vbd.c @@ -538,6 +538,31 @@ tapdisk_vbd_add_dirty_log(td_vbd_t *vbd) return err; } +int +tapdisk_vbd_update_o_direct(td_vbd_t *vbd) +{ + td_image_t *image, *next; + int no_o_direct = 0, oflags, err; + + tapdisk_vbd_for_each_image(vbd, image, next){ + err = td_get_oflags(image, &oflags); + if (err == -ENOTSUP) + continue; + if (err < 0) + return err; + if (!(oflags & O_DIRECT)){ + no_o_direct = 1; + break; + } + } + + td_flag_clear(vbd->flags, TD_OPEN_NO_O_DIRECT); + if (no_o_direct) + td_flag_set(vbd->flags, TD_OPEN_NO_O_DIRECT); + + return 0; +} + int tapdisk_vbd_open_vdi(td_vbd_t *vbd, const char *name, td_flag_t flags, int prt_devnum) { @@ -601,6 +626,10 @@ tapdisk_vbd_open_vdi(td_vbd_t *vbd, const char *name, td_flag_t flags, int prt_d } } + err = tapdisk_vbd_update_o_direct(vbd); + if (err) + goto fail; + err = vbd_stats_create(vbd); if (err) goto fail;