From cede8eb3d0007dcd6eb8929d5031ff25be955ed6 Mon Sep 17 00:00:00 2001 From: Brian Foster Date: Tue, 4 Jun 2013 11:54:43 -0400 Subject: gfapi: async discard support From: Bharata B Rao Add glfs_discard_async() to meet QEMU's discard requirements. BUG: 963678 Change-Id: I97723107fca88dd96cddc08cd67a286645a37922 Signed-off-by: Bharata B Rao Signed-off-by: Brian Foster Reviewed-on: http://review.gluster.org/5144 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- api/src/glfs-fops.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'api/src/glfs-fops.c') diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index fbc9f4b4..e30a3548 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -592,6 +592,9 @@ glfs_io_async_task (void *data) else ret = glfs_fsync (gio->glfd); break; + case GF_FOP_DISCARD: + ret = glfs_discard (gio->glfd, gio->offset, gio->count); + break; } return (int) ret; @@ -1742,6 +1745,38 @@ glfs_seekdir (struct glfs_fd *fd, long offset) */ } +int +glfs_discard_async (struct glfs_fd *glfd, off_t offset, size_t len, + glfs_io_cbk fn, void *data) +{ + struct glfs_io *gio = NULL; + int ret = 0; + + gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + return -1; + } + + gio->op = GF_FOP_DISCARD; + gio->glfd = glfd; + gio->offset = offset; + gio->count = len; + gio->fn = fn; + gio->data = data; + + ret = synctask_new (glfs_from_glfd (glfd)->ctx->env, + glfs_io_async_task, glfs_io_async_cbk, + NULL, gio); + + if (ret) { + GF_FREE (gio->iov); + GF_FREE (gio); + } + + return ret; +} + void gf_dirent_to_dirent (gf_dirent_t *gf_dirent, struct dirent *dirent) -- cgit