From 94c79620db4451bf804d6ab631c9ca59759dbc21 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Mon, 12 Jun 2017 11:59:13 +0530 Subject: block: add support to prealloc = full | no option currently we allocate sparse files for block backends in the gluster volume, with 'prealloc = full' option introduced by this patch we should be able to fully preallocate the backend block file. Change-Id: Ibf32df5f978f732a3fd248693170463da6d08268 Signed-off-by: Prasanna Kumar Kalever --- rpc/glfs-operations.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'rpc/glfs-operations.c') diff --git a/rpc/glfs-operations.c b/rpc/glfs-operations.c index 72de38f..db02620 100644 --- a/rpc/glfs-operations.c +++ b/rpc/glfs-operations.c @@ -126,37 +126,40 @@ glusterBlockCreateEntry(struct glfs *glfs, blockCreateCli *blk, char *gbid, if (ret) { *errCode = errno; LOG("gfapi", GB_LOG_ERROR, - "glfs_ftruncate(%s): on volume %s for block %s" + "glfs_ftruncate(%s): on volume %s for block %s " "of size %zu failed[%s]", gbid, blk->volume, blk->block_name, blk->size, strerror(errno)); - - if (tgfd && glfs_close(tgfd) != 0) { - LOG("gfapi", GB_LOG_ERROR, - "glfs_close(%s): on volume %s for block %s failed[%s]", - gbid, blk->volume, blk->block_name, strerror(errno)); - } - - ret = glfs_unlink(glfs, gbid); - if (ret && errno != ENOENT) { - LOG("gfapi", GB_LOG_ERROR, - "glfs_unlink(%s) on volume %s for block %s failed[%s]", - gbid, blk->volume, blk->block_name, strerror(errno)); - } - - ret = -1; - goto out; + goto unlink; } - if (tgfd && glfs_close(tgfd) != 0) { + if (blk->prealloc && glfs_zerofill(tgfd, 0, blk->size)) { *errCode = errno; LOG("gfapi", GB_LOG_ERROR, - "glfs_close(%s): on volume %s for block %s failed[%s]", - gbid, blk->volume, blk->block_name, strerror(errno)); + "glfs_zerofill(%s): on volume %s for block %s " + "of size %zu failed[%s]", gbid, blk->volume, blk->block_name, + blk->size, strerror(errno)); ret = -1; - goto out; + goto unlink; } } + +unlink: + if (tgfd && glfs_close(tgfd) != 0) { + *errCode = errno; + LOG("gfapi", GB_LOG_ERROR, + "glfs_close(%s): on volume %s for block %s failed[%s]", + gbid, blk->volume, blk->block_name, strerror(errno)); + ret = -1; + } + + if (ret && glfs_unlink(glfs, gbid) && errno != ENOENT) { + *errCode = errno; + LOG("gfapi", GB_LOG_ERROR, + "glfs_unlink(%s) on volume %s for block %s failed[%s]", + gbid, blk->volume, blk->block_name, strerror(errno)); + } + out: if (ret) { GB_ASPRINTF (errMsg, "Not able to create metadata for %s/%s[%s]", blk->volume, -- cgit