diff options
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/common-utils.c | 12 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 5 | ||||
-rw-r--r-- | libglusterfs/src/ctx.c | 1 | ||||
-rw-r--r-- | libglusterfs/src/glusterfs.h | 11 | ||||
-rw-r--r-- | libglusterfs/src/graph.c | 129 | ||||
-rw-r--r-- | libglusterfs/src/mem-types.h | 1 | ||||
-rw-r--r-- | libglusterfs/src/xlator.c | 26 | ||||
-rw-r--r-- | libglusterfs/src/xlator.h | 11 |
8 files changed, 186 insertions, 10 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index e5e08909ac7..c93b3667ad9 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -4950,3 +4950,15 @@ gf_getgrouplist (const char *user, gid_t group, gid_t **groups) } return ret; } + +int +glusterfs_compute_sha256 (const unsigned char *content, size_t size, + char *sha256_hash) { + SHA256_CTX sha256; + + SHA256_Init (&sha256); + SHA256_Update (&sha256, (const unsigned char *) (content), size); + SHA256_Final ((unsigned char *) sha256_hash, &sha256); + + return 0; +} diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 6a260c090c8..86b7ec6c3d6 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -921,4 +921,9 @@ close_fds_except (int *fdv, size_t count); int gf_getgrouplist (const char *user, gid_t group, gid_t **groups); + +int +glusterfs_compute_sha256 (const unsigned char *content, size_t size, + char *sha256_hash); + #endif /* _COMMON_UTILS_H */ diff --git a/libglusterfs/src/ctx.c b/libglusterfs/src/ctx.c index 1cf1b988590..365c6c087ee 100644 --- a/libglusterfs/src/ctx.c +++ b/libglusterfs/src/ctx.c @@ -32,6 +32,7 @@ glusterfs_ctx_new () INIT_LIST_HEAD (&ctx->graphs); INIT_LIST_HEAD (&ctx->mempool_list); + INIT_LIST_HEAD (&ctx->volfile_list); ctx->daemon_pipe[0] = -1; ctx->daemon_pipe[1] = -1; diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 2cd1f363b3b..fa3828365f7 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -28,6 +28,7 @@ #include <sys/poll.h> #include <pthread.h> #include <limits.h> /* For PATH_MAX */ +#include <openssl/sha.h> #include "glusterfs-fops.h" /* generated XDR values for FOPs */ @@ -532,9 +533,19 @@ struct _glusterfs_ctx { gf_atomic_t total_pairs_used; gf_atomic_t total_dicts_used; } stats; + + struct list_head volfile_list; }; typedef struct _glusterfs_ctx glusterfs_ctx_t; +typedef struct { + char volfile_checksum[SHA256_DIGEST_LENGTH]; + char vol_id[NAME_MAX+1]; + struct list_head volfile_list; + +} gf_volfile_t; + + glusterfs_ctx_t *glusterfs_ctx_new (void); struct gf_flock { diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c index 11d2a0adf1e..738cd9688db 100644 --- a/libglusterfs/src/graph.c +++ b/libglusterfs/src/graph.c @@ -832,8 +832,70 @@ out: * return -1(or -ve) =======> Some Internal Error occurred during the operation */ int -glusterfs_volfile_reconfigure (int oldvollen, FILE *newvolfile_fp, - glusterfs_ctx_t *ctx, const char *oldvolfile) +glusterfs_volfile_reconfigure (FILE *newvolfile_fp, glusterfs_ctx_t *ctx) +{ + glusterfs_graph_t *oldvolfile_graph = NULL; + glusterfs_graph_t *newvolfile_graph = NULL; + + int ret = -1; + + if (!ctx) { + gf_msg ("glusterfsd-mgmt", GF_LOG_ERROR, 0, LG_MSG_CTX_NULL, + "ctx is NULL"); + goto out; + } + + oldvolfile_graph = ctx->active; + if (!oldvolfile_graph) { + ret = 1; + goto out; + } + + newvolfile_graph = glusterfs_graph_construct (newvolfile_fp); + + if (!newvolfile_graph) { + goto out; + } + + glusterfs_graph_prepare (newvolfile_graph, ctx, + ctx->cmd_args.volume_name); + + if (!is_graph_topology_equal (oldvolfile_graph, + newvolfile_graph)) { + + ret = 1; + gf_msg_debug ("glusterfsd-mgmt", 0, "Graph topology not " + "equal(should call INIT)"); + goto out; + } + + gf_msg_debug ("glusterfsd-mgmt", 0, "Only options have changed in the" + " new graph"); + + ret = glusterfs_graph_reconfigure (oldvolfile_graph, + newvolfile_graph); + if (ret) { + gf_msg_debug ("glusterfsd-mgmt", 0, "Could not reconfigure " + "new options in old graph"); + goto out; + } + + ret = 0; +out: + + if (newvolfile_graph) + glusterfs_graph_destroy (newvolfile_graph); + + return ret; +} + +/* This function need to remove. This added to support gfapi volfile + * reconfigure. + */ + +int +gf_volfile_reconfigure (int oldvollen, FILE *newvolfile_fp, + glusterfs_ctx_t *ctx, const char *oldvolfile) { glusterfs_graph_t *oldvolfile_graph = NULL; glusterfs_graph_t *newvolfile_graph = NULL; @@ -855,9 +917,9 @@ glusterfs_volfile_reconfigure (int oldvollen, FILE *newvolfile_fp, if (!ctx) { gf_msg ("glusterfsd-mgmt", GF_LOG_ERROR, 0, LG_MSG_CTX_NULL, - "ctx is NULL"); - goto out; - } + "ctx is NULL"); + goto out; + } oldvolfile_graph = ctx->active; if (!oldvolfile_graph) { @@ -908,7 +970,7 @@ glusterfs_volfile_reconfigure (int oldvollen, FILE *newvolfile_fp, goto out; } - glusterfs_graph_prepare (newvolfile_graph, ctx, + glusterfs_graph_prepare (newvolfile_graph, ctx, ctx->cmd_args.volume_name); if (!is_graph_topology_equal (oldvolfile_graph, @@ -952,7 +1014,6 @@ out: return ret; } - int glusterfs_graph_reconfigure (glusterfs_graph_t *oldgraph, glusterfs_graph_t *newgraph) @@ -1056,19 +1117,56 @@ glusterfs_graph_attach (glusterfs_graph_t *orig_graph, char *path, FILE *fp; glusterfs_graph_t *graph; xlator_t *xl; - char *volfile_id; + char *volfile_id = NULL; + char *volfile_content = NULL; + struct stat stbuf = {0,}; + size_t file_len = -1; + gf_volfile_t *volfile_obj = NULL; + int ret = -1; + char sha256_hash[SHA256_DIGEST_LENGTH] = {0, }; if (!orig_graph) { return -EINVAL; } + ret = sys_stat (path, &stbuf); + if (ret < 0) { + gf_log (THIS->name, GF_LOG_ERROR, "Unable to stat %s (%s)", + path, strerror (errno)); + return -EINVAL; + } + + file_len = stbuf.st_size; + if (file_len) { + volfile_content = GF_CALLOC (file_len+1, sizeof (char), + gf_common_mt_char); + if (!volfile_content) { + return -ENOMEM; + } + } + fp = fopen (path, "r"); if (!fp) { gf_log (THIS->name, GF_LOG_WARNING, "oops, %s disappeared on us", path); + GF_FREE (volfile_content); return -EIO; } + ret = fread (volfile_content, sizeof (char), file_len, fp); + if (ret == file_len) { + glusterfs_compute_sha256 ((const unsigned char *) volfile_content, + file_len, sha256_hash); + } else { + gf_log (THIS->name, GF_LOG_ERROR, + "read failed on path %s. File size=%"GF_PRI_SIZET + "read size=%d", path, file_len, ret); + GF_FREE (volfile_content); + return -EIO; + } + + GF_FREE (volfile_content); + graph = glusterfs_graph_construct (fp); fclose(fp); if (!graph) { @@ -1117,5 +1215,20 @@ glusterfs_graph_attach (glusterfs_graph_t *orig_graph, char *path, return -EIO; } + if (!volfile_obj) { + volfile_obj = GF_CALLOC (1, sizeof (gf_volfile_t), + gf_common_volfile_t); + if (!volfile_obj) { + return -EIO; + } + } + + INIT_LIST_HEAD (&volfile_obj->volfile_list); + snprintf (volfile_obj->vol_id, sizeof (volfile_obj->vol_id), + "%s", xl->volfile_id); + strncpy (volfile_obj->volfile_checksum, sha256_hash, + sizeof (volfile_obj->volfile_checksum)); + list_add (&volfile_obj->volfile_list, &this->ctx->volfile_list); + return 0; } diff --git a/libglusterfs/src/mem-types.h b/libglusterfs/src/mem-types.h index d5b2fcd64bd..c2ac088f639 100644 --- a/libglusterfs/src/mem-types.h +++ b/libglusterfs/src/mem-types.h @@ -174,6 +174,7 @@ enum gf_common_mem_types_ { gf_common_mt_tbf_throttle_t, gf_common_mt_pthread_t, gf_common_ping_local_t, + gf_common_volfile_t, gf_common_mt_end }; #endif diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index 9da6d657707..de97dff6dfe 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -1195,3 +1195,29 @@ copy_opts_to_child (xlator_t *src, xlator_t *dst, char *glob) return dict_foreach_fnmatch (src->options, glob, _copy_opt_to_child, dst); } + +int +glusterfs_delete_volfile_checksum (glusterfs_ctx_t *ctx, + const char *volfile_id) { + + gf_volfile_t *volfile_tmp = NULL; + gf_volfile_t *volfile_obj = NULL; + + list_for_each_entry (volfile_tmp, &ctx->volfile_list, + volfile_list) { + if (!strcmp (volfile_id, volfile_tmp->vol_id)) { + list_del_init (&volfile_tmp->volfile_list); + volfile_obj = volfile_tmp; + break; + } + } + + if (volfile_obj) { + GF_FREE (volfile_obj); + } else { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get volfile " + "checksum for volfile id %s.", volfile_id); + } + + return 0; +} diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index 06e7241bb8e..26d2cc5b595 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -1043,8 +1043,11 @@ enum gf_hdsk_event_notify_op { gf_boolean_t is_graph_topology_equal (glusterfs_graph_t *graph1, glusterfs_graph_t *graph2); int -glusterfs_volfile_reconfigure (int oldvollen, FILE *newvolfile_fp, - glusterfs_ctx_t *ctx, const char *oldvolfile); +glusterfs_volfile_reconfigure (FILE *newvolfile_fp, glusterfs_ctx_t *ctx); + +int +gf_volfile_reconfigure (int oldvollen, FILE *newvolfile_fp, + glusterfs_ctx_t *ctx, const char *oldvolfile); int loc_touchup (loc_t *loc, const char *name); @@ -1063,4 +1066,8 @@ void xlator_init_unlock (void); int copy_opts_to_child (xlator_t *src, xlator_t *dst, char *glob); +int +glusterfs_delete_volfile_checksum (glusterfs_ctx_t *ctx, + const char *volfile_id); + #endif /* _XLATOR_H */ |