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 +++++++++++++++++++++++++++++++++++ api/src/glfs.h | 3 +++ 2 files changed, 38 insertions(+) (limited to 'api') diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index fbc9f4b49e4..e30a3548ad0 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) diff --git a/api/src/glfs.h b/api/src/glfs.h index 700e10f17c9..d9c1202cd4c 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -452,6 +452,9 @@ int glfs_fallocate(glfs_fd_t *fd, int keep_size, off_t offset, size_t len); int glfs_discard(glfs_fd_t *fd, off_t offset, size_t len); +int glfs_discard_async (glfs_fd_t *fd, off_t length, size_t lent, + glfs_io_cbk fn, void *data); + char *glfs_getcwd (glfs_t *fs, char *buf, size_t size); int glfs_chdir (glfs_t *fs, const char *path); -- cgit