summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-01-28 13:33:25 +0530
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-01-30 19:31:50 +0530
commit930150bf6fee26624129692baad074c1f1b66dd3 (patch)
tree46707f2a64f3bf636fa753ab228eb5b5339857c4
parent073f871b1714f09382575b4afcd7a8e34c755625 (diff)
gluster-blockd: introduce rewind on partial success
This patch also brings changes in the info output. It adds BLOCK config hosts in the output. Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
-rw-r--r--glfs-operations.c3
-rw-r--r--glfs-operations.h1
-rw-r--r--gluster-blockd.c233
-rw-r--r--utils.h18
4 files changed, 145 insertions, 110 deletions
diff --git a/glfs-operations.c b/glfs-operations.c
index d530096..1f6352c 100644
--- a/glfs-operations.c
+++ b/glfs-operations.c
@@ -167,6 +167,9 @@ blockStuffMetaInfo(MetaInfo *info, char *line)
size_t i;
switch (blockMetaKeyEnumParse(opt)) {
+ case VOLUME:
+ strcpy(info->volume, strchr(line, ' ')+1);
+ break;
case GBID:
strcpy(info->gbid, strchr(line, ' ')+1);
break;
diff --git a/glfs-operations.h b/glfs-operations.h
index abfcb27..3c2e4c9 100644
--- a/glfs-operations.h
+++ b/glfs-operations.h
@@ -29,6 +29,7 @@ typedef struct NodeInfo {
} NodeInfo;
typedef struct MetaInfo {
+ char volume[255];
char gbid[38];
size_t size;
size_t mpath;
diff --git a/gluster-blockd.c b/gluster-blockd.c
index 9bd865c..f12eee8 100644
--- a/gluster-blockd.c
+++ b/gluster-blockd.c
@@ -269,6 +269,118 @@ block_cross_check_request(struct glfs *glfs,
}
+static int
+block_delete_remote(struct glfs_fd *tgfd, blockDelete *cobj, char *addr, char **reply)
+{
+ char *write = NULL;
+ char *out = NULL;
+ char *tmp = NULL;
+ int ret;
+
+ METAUPDATE(tgfd, write, "%s: CLEANUPINPROGRES\n", addr);
+ ret = gluster_block_1(addr, cobj, DELETE_SRV, &out);
+ if (ret) {
+ METAUPDATE(tgfd, write, "%s: CLEANUPFAIL\n", addr);
+ ERROR("%s on host: %s",
+ FAILED_GATHERING_INFO, addr);
+ goto out;
+ }
+ METAUPDATE(tgfd, write, "%s: CLEANUPSUCCESS\n", addr);
+
+ asprintf(reply, "%s%s\n", (tmp==NULL?"":tmp), out);
+ if (tmp)
+ GB_FREE(tmp);
+ tmp = *reply;
+ GB_FREE(out);
+
+ out:
+ return ret;
+}
+
+
+static int
+blockCleanUp(struct glfs *glfs, char *blockname,
+ bool deleteall, char **reply)
+{
+ MetaInfo *info = NULL;
+ int ret = -1;
+ static blockDelete *cobj;
+ size_t i = 0;
+ struct glfs_fd *tgfd;
+ size_t cleanup_success = 0;
+
+if (GB_ALLOC(info) < 0)
+ goto out;
+
+ ret = blockGetMetaInfo(glfs, blockname, info);
+ if(ret)
+ goto out;
+
+ if(GB_ALLOC(cobj) < 0)
+ goto out;
+
+ strcpy(cobj->block_name, blockname);
+ strcpy(cobj->gbid, info->gbid);
+
+ tgfd = glfs_open(glfs, blockname, O_RDWR);
+ if (!tgfd) {
+ ERROR("%s", "glfs_open: failed");
+ goto out;
+ }
+ glfs_lseek (tgfd, 0, SEEK_END); /* append at end of file */
+
+ for (i = 0; i < info->nhosts; i++) {
+ switch (blockMetaStatusEnumParse(info->list[i]->status)) {
+ case CLEANUPINPROGRES:
+ case CLEANUPFAIL:
+ case CONFIGFAIL:
+ case CONFIGINPROGRESS:
+ ret = block_delete_remote(tgfd, cobj, info->list[i]->addr, reply);
+ break;
+ }
+ if(deleteall &&
+ blockMetaStatusEnumParse(info->list[i]->status) == CONFIGSUCCESS) {
+ ret = block_delete_remote(tgfd, cobj, info->list[i]->addr, reply);
+ }
+ }
+ blockFreeMetaInfo(info);
+
+ if (GB_ALLOC(info) < 0)
+ goto out;
+
+ ret = blockGetMetaInfo(glfs, blockname, info);
+ if(ret)
+ goto out;
+
+ for (i = 0; i < info->nhosts; i++) {
+ if(blockMetaStatusEnumParse(info->list[i]->status) == CLEANUPSUCCESS)
+ cleanup_success++;
+ }
+
+ if( cleanup_success == info->nhosts) {
+ if (glusterBlockDeleteEntry(info->volume, info->gbid)) {
+ ERROR("%s volume: %s host: %s",
+ FAILED_DELETING_FILE, info->volume, "localhost");
+ }
+ ret = glfs_unlink(glfs, blockname);
+ if (ret && errno != ENOENT) {
+ ERROR("%s", "glfs_unlink: failed");
+ goto out;
+ }
+ }
+
+ out:
+ blockFreeMetaInfo(info);
+
+ if (glfs_close(tgfd) != 0)
+ ERROR("%s", "glfs_close: failed");
+
+ GB_FREE(cobj);
+
+ return ret;
+}
+
+
blockResponse *
block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
{
@@ -315,9 +427,9 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
goto out;
}
- METAUPDATE(tgfd, write,
+ METAUPDATE(tgfd, write, "VOLUME: %s\n"
"GBID: %s\nSIZE: %zu\nHA: %d\nENTRYCREATE: INPROGRESS\n",
- gbid, blk->size, blk->mpath);
+ blk->volume, gbid, blk->size, blk->mpath);
ret = glusterBlockCreateEntry(blk, gbid);
if (ret) {
@@ -341,13 +453,15 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
list = blockServerParse(blk->block_hosts);
/* TODO: Fail if mpath > list->nhosts */
-
for (i = 0; i < blk->mpath; i++) {
block_create_remote(tgfd, cobj, list->hosts[i], &savereply);
}
/* Check Point */
ret = block_cross_check_request(glfs, tgfd, blk, cobj, list, &savereply);
+ if(ret) {
+ ret = blockCleanUp(glfs, blk->block_name, FALSE, &savereply);
+ }
out:
if(GB_ALLOC(reply) < 0)
@@ -426,53 +540,18 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp)
GB_FREE(backstore);
return obj;
-
-}
-
-
-static int
-block_delete_remote(struct glfs_fd *tgfd, blockDelete *cobj, char *addr, char **reply)
-{
- char *write = NULL;
- char *out = NULL;
- char *tmp = NULL;
- int ret;
-
- METAUPDATE(tgfd, write, "%s: CLEANUPINPROGRES\n", addr);
- ret = gluster_block_1(addr, cobj, DELETE_SRV, &out);
- if (ret) {
- METAUPDATE(tgfd, write, "%s: CLEANUPFAIL\n", addr);
- ERROR("%s on host: %s",
- FAILED_GATHERING_INFO, addr);
- goto out;
- }
- METAUPDATE(tgfd, write, "%s: CLEANUPSUCCESS\n", addr);
-
- asprintf(reply, "%s%s\n", (tmp==NULL?"":tmp), out);
- if (tmp)
- GB_FREE(tmp);
- tmp = *reply;
- GB_FREE(out);
-
- out:
- return ret;
}
blockResponse *
block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp)
{
- size_t i = 0;
int ret = -1;
char *savereply = NULL;
- static blockDelete *cobj;
static blockResponse *reply = NULL;
struct glfs *glfs = NULL;
struct glfs_fd *lkfd;
- struct glfs_fd *tgfd;
struct flock lock = {0, };
- MetaInfo *info = NULL;
- size_t cleanup_success = 0;
glfs = glusterBlockVolumeInit(blk->volume, "localhost");
if (!glfs) {
@@ -494,63 +573,7 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp)
goto out;
}
- tgfd = glfs_open(glfs, blk->block_name, O_RDWR);
- if (!tgfd) {
- ERROR("%s", "glfs_open: failed");
- goto out;
- }
- glfs_lseek (tgfd, 0, SEEK_END);
-
- if (GB_ALLOC(info) < 0)
- goto out;
-
- ret = blockGetMetaInfo(glfs, blk->block_name, info);
- if(ret)
- goto out;
-
- if(GB_ALLOC(cobj) < 0)
- goto out;
-
- strcpy(cobj->block_name, blk->block_name);
-
- strcpy(cobj->gbid, info->gbid);
-
- for (i = 0; i < info->nhosts; i++) {
- switch (blockMetaStatusEnumParse(info->list[i]->status)) {
- case CLEANUPINPROGRES:
- case CLEANUPFAIL:
- case CONFIGSUCCESS:
- case CONFIGFAIL:
- case CONFIGINPROGRESS:
- ret = block_delete_remote(tgfd, cobj, info->list[i]->addr, &savereply);
- break;
- }
- }
- blockFreeMetaInfo(info);
-
- if (GB_ALLOC(info) < 0)
- goto out;
-
- ret = blockGetMetaInfo(glfs, blk->block_name, info);
- if(ret)
- goto out;
-
- for (i = 0; i < info->nhosts; i++) {
- if(blockMetaStatusEnumParse(info->list[i]->status) == CLEANUPSUCCESS)
- cleanup_success++;
- }
-
- if( cleanup_success == info->nhosts) {
- if (glusterBlockDeleteEntry(blk->volume, info->gbid)) {
- ERROR("%s volume: %s host: %s",
- FAILED_DELETING_FILE, blk->volume, "localhost");
- }
- ret = glfs_unlink(glfs, blk->block_name);
- if (ret && errno != ENOENT) {
- ERROR("%s", "glfs_unlink: failed");
- goto out;
- }
- }
+ret = blockCleanUp(glfs, blk->block_name, TRUE, &savereply);
out:
if (GB_ALLOC(reply) < 0)
@@ -559,9 +582,6 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp)
reply->out = savereply;
reply->exit = ret;
- if (glfs_close(tgfd) != 0)
- ERROR("%s", "glfs_close: failed");
-
METAUNLOCK(lock, lkfd);
if (glfs_close(lkfd) != 0)
@@ -569,8 +589,6 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp)
glfs_fini(glfs);
- GB_FREE(cobj);
-
return reply;
}
@@ -691,11 +709,13 @@ block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp)
{
blockResponse *reply = NULL;
char *out = NULL;
+ char *tmp = NULL;
struct glfs *glfs;
struct glfs_fd *lkfd;
struct flock lock = {0, };
MetaInfo *info = NULL;
int ret = -1;
+ size_t i;
glfs = glusterBlockVolumeInit(blk->volume, "localhost");
if (!glfs) {
@@ -718,8 +738,17 @@ block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp)
if(ret)
goto out;
- asprintf(&out, "NAME: %s\nVOLUME: %s\nGBID: %s\nSIZE: %zu\nMULTIPATH: %zu\n",
- blk->block_name, blk->volume, info->gbid, info->size, info->mpath);
+ asprintf(&tmp, "NAME: %s\nVOLUME: %s\nGBID: %s\nSIZE: %zu\nMULTIPATH: %zu\n"
+ "BLOCK CONFIG NODE(S):",
+ blk->block_name, info->volume, info->gbid, info->size, info->mpath);
+ for (i = 0; i < info->nhosts; i++) {
+ if (blockMetaStatusEnumParse(info->list[i]->status) == CONFIGSUCCESS) {
+ asprintf(&out, "%s %s", (tmp==NULL?"":tmp), info->list[i]->addr);
+ if (tmp)
+ GB_FREE(tmp);
+ tmp = out;
+ }
+ }
ret = 0;
out:
diff --git a/utils.h b/utils.h
index 6a98e67..590eec9 100644
--- a/utils.h
+++ b/utils.h
@@ -92,18 +92,20 @@
# define GB_FREE(ptr) gbFree(1 ? (void *) &(ptr) : (ptr))
typedef enum Metakey {
- GBID = 0,
- SIZE = 1,
- HA = 2,
- ENTRYCREATE = 3,
+ VOLUME = 0,
+ GBID = 1,
+ SIZE = 2,
+ HA = 3,
+ ENTRYCREATE = 4,
- METAKEY__MAX = 4 /* Updata this when add new Key */
+ METAKEY__MAX = 5 /* Updata this when add new Key */
} Metakey;
static const char *const MetakeyLookup[] = {
- [GBID] = "GBID",
- [SIZE] = "SIZE",
- [HA] = "HA",
+ [VOLUME] = "VOLUME",
+ [GBID] = "GBID",
+ [SIZE] = "SIZE",
+ [HA] = "HA",
[ENTRYCREATE] = "ENTRYCREATE",
[METAKEY__MAX] = NULL,
};