Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to resolve the read cache status as reported by tap-ctl stats #157

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions drivers/block-vhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions drivers/tapdisk-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions drivers/tapdisk-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down
29 changes: 29 additions & 0 deletions drivers/tapdisk-vbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions drivers/tapdisk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down