From 9f570a3967c0a4ebbe35a04284181406faf8fe36 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Wed, 8 Feb 2017 21:18:20 +0530 Subject: gluster-block: create block files in '/block-store' dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit till now we have '/block-meta' dir for meta files and actual block files used to reside in '/' dir. From now, lets place block files in '/block-store' So, this is how it looks like: $ tree /mnt/ /mnt/ ├── block-meta │   ├── meta.lock │   └── TARGET └── block-store └── 103e4cf1-bf41-404a-9fe1-b7c70fc33b3e Signed-off-by: Prasanna Kumar Kalever --- rpc/block_svc_routines.c | 12 ++++---- rpc/glfs-operations.c | 72 +++++++++++++++++++++++++++++++++++++++++------- rpc/glfs-operations.h | 3 ++ utils/common.h | 4 +++ utils/utils.h | 2 +- 5 files changed, 76 insertions(+), 17 deletions(-) diff --git a/rpc/block_svc_routines.c b/rpc/block_svc_routines.c index 7d7080c..ca2fef6 100644 --- a/rpc/block_svc_routines.c +++ b/rpc/block_svc_routines.c @@ -388,9 +388,9 @@ glusterBlockCleanUp(struct glfs *glfs, char *blockname, LOG("mgmt", GB_LOG_ERROR, "%s volume: %s host: %s", FAILED_DELETING_FILE, info->volume, "localhost"); } - ret = glfs_unlink(glfs, blockname); - if (ret && errno != ENOENT) { - LOG("mgmt", GB_LOG_ERROR, "%s", "glfs_unlink: failed"); + ret = glusterBlockDeleteMetaLockFile(glfs, info->volume, blockname); + if (ret) { + LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockDeleteMetaLockFile: failed"); goto out; } } @@ -554,9 +554,9 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp) goto out; } - if (asprintf(&backstore, "%s %s %s %zu %s@%s/%s %s", TARGETCLI_GLFS, + if (asprintf(&backstore, "%s %s %s %zu %s@%s%s/%s %s", TARGETCLI_GLFS, CREATE, blk->block_name, blk->size, blk->volume, - blk->volfileserver, blk->gbid, blk->gbid) == -1) { + blk->volfileserver, GB_STOREDIR, blk->gbid, blk->gbid) == -1) { reply->exit = -1; goto out; } @@ -754,7 +754,7 @@ block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp) GB_METALOCK_OR_GOTO(lkfd, blk->volume, ret, out); - tgmfd = glfs_opendir (glfs, "/block-meta"); + tgmfd = glfs_opendir (glfs, GB_METADIR); if (!tgmfd) { LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockVolumeInit failed"); goto out; diff --git a/rpc/glfs-operations.c b/rpc/glfs-operations.c index 0e3787c..4a7e081 100644 --- a/rpc/glfs-operations.c +++ b/rpc/glfs-operations.c @@ -12,9 +12,6 @@ # include "common.h" # include "glfs-operations.h" -# define METADIR "/block-meta" -# define TXLOCKFILE "meta.lock" - struct glfs * @@ -67,9 +64,23 @@ glusterBlockCreateEntry(struct glfs *glfs, char *gbid) { struct glfs_fd *tgfd; - int ret = -1; + int ret; + ret = glfs_mkdir (glfs, GB_STOREDIR, 0); + if (ret && errno != EEXIST) { + LOG("gfapi", GB_LOG_ERROR, "glfs_mkdir(%s) on volume %s failed[%s]", + GB_STOREDIR, blk->volume, strerror(errno)); + goto out; + } + + ret = glfs_chdir (glfs, GB_STOREDIR); + if (ret) { + LOG("gfapi", GB_LOG_ERROR, "glfs_chdir(%s) on volume %s failed[%s]", + GB_STOREDIR, blk->volume, strerror(errno)); + goto out; + } + tgfd = glfs_creat(glfs, gbid, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); @@ -103,12 +114,20 @@ glusterBlockDeleteEntry(struct glfs *glfs, char *volume, char *gbid) int ret; + ret = glfs_chdir (glfs, GB_STOREDIR); + if (ret) { + LOG("gfapi", GB_LOG_ERROR, "glfs_chdir(%s) on volume %s failed[%s]", + GB_STOREDIR, volume, strerror(errno)); + goto out; + } + ret = glfs_unlink(glfs, gbid); if (ret) { LOG("gfapi", GB_LOG_ERROR, "glfs_unlink(%s) on volume %s failed[%s]", gbid, volume, strerror(errno)); } + out: return ret; } @@ -120,24 +139,24 @@ glusterBlockCreateMetaLockFile(struct glfs *glfs, char *volume) int ret; - ret = glfs_mkdir (glfs, METADIR, 0); + ret = glfs_mkdir (glfs, GB_METADIR, 0); if (ret && errno != EEXIST) { LOG("gfapi", GB_LOG_ERROR, "glfs_mkdir(%s) on volume %s failed[%s]", - METADIR, volume, strerror(errno)); + GB_METADIR, volume, strerror(errno)); goto out; } - ret = glfs_chdir (glfs, METADIR); + ret = glfs_chdir (glfs, GB_METADIR); if (ret) { LOG("gfapi", GB_LOG_ERROR, "glfs_chdir(%s) on volume %s failed[%s]", - METADIR, volume, strerror(errno)); + GB_METADIR, volume, strerror(errno)); goto out; } - lkfd = glfs_creat(glfs, TXLOCKFILE, O_RDWR, S_IRUSR | S_IWUSR); + lkfd = glfs_creat(glfs, GB_TXLOCKFILE, O_RDWR, S_IRUSR | S_IWUSR); if (!lkfd) { LOG("gfapi", GB_LOG_ERROR, "glfs_creat(%s) on volume %s failed[%s]", - TXLOCKFILE, volume, strerror(errno)); + GB_TXLOCKFILE, volume, strerror(errno)); goto out; } @@ -147,6 +166,31 @@ glusterBlockCreateMetaLockFile(struct glfs *glfs, char *volume) return NULL; } +int +glusterBlockDeleteMetaLockFile(struct glfs *glfs, + char *volume, char *blockname) +{ + int ret; + + + ret = glfs_chdir (glfs, GB_METADIR); + if (ret) { + LOG("gfapi", GB_LOG_ERROR, "glfs_chdir(%s) on volume %s failed[%s]", + GB_METADIR, volume, strerror(errno)); + goto out; + } + + ret = glfs_unlink(glfs, blockname); + if (ret && errno != ENOENT) { + LOG("gfapi", GB_LOG_ERROR, "glfs_unlink(%s) on volume %s failed[%s]", + blockname, volume, strerror(errno)); + goto out; + } + + out: + return ret; +} + void blockFreeMetaInfo(MetaInfo *info) @@ -232,7 +276,15 @@ blockGetMetaInfo(struct glfs* glfs, char* metafile, MetaInfo *info) struct glfs_fd *tgmfd; char line[1024]; char *tmp; + int ret; + + ret = glfs_chdir (glfs, GB_METADIR); + if (ret) { + LOG("gfapi", GB_LOG_ERROR, "glfs_chdir(%s) on volume %s failed[%s]", + GB_METADIR, info->volume, strerror(errno)); + return ret; + } tgmfd = glfs_open(glfs, metafile, O_RDONLY); if (!tgmfd) { diff --git a/rpc/glfs-operations.h b/rpc/glfs-operations.h index a03741e..5d617e6 100644 --- a/rpc/glfs-operations.h +++ b/rpc/glfs-operations.h @@ -52,6 +52,9 @@ glusterBlockDeleteEntry(struct glfs *glfs, char *volume, char *gbid); struct glfs_fd * glusterBlockCreateMetaLockFile(struct glfs *glfs, char *volume); +int +glusterBlockDeleteMetaLockFile(struct glfs *glfs, char *volume, char *blockname); + int blockGetMetaInfo(struct glfs *glfs, char *metafile, MetaInfo *info); diff --git a/utils/common.h b/utils/common.h index 6b0983d..90372ed 100644 --- a/utils/common.h +++ b/utils/common.h @@ -20,6 +20,10 @@ # define GFAPI_LOG_FILE "/var/log/gluster-block/gluster-block-gfapi.log" # define GFAPI_LOG_LEVEL 7 +# define GB_METADIR "/block-meta" +# define GB_STOREDIR "/block-store" +# define GB_TXLOCKFILE "meta.lock" + ssize_t glusterBlockCreateParseSize(char *value); diff --git a/utils/utils.h b/utils/utils.h index 2323418..0545219 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -198,7 +198,7 @@ static const char *const gbCmdlineCreateOptLookup[] = { [GB_CLI_CREATE_VOLSERVER] = "volserver", [GB_CLI_CREATE_SIZE] = "size", [GB_CLI_CREATE_MULTIPATH] = "mpath", - [GB_CLI_CREATE_BACKEND_SERVESRS] = "backend-servers", + [GB_CLI_CREATE_BACKEND_SERVESRS] = "servers", [GB_CLI_CREATE_OPT_MAX] = NULL -- cgit