diff options
author | Jeff Darcy <jdarcy@redhat.com> | 2014-04-22 15:37:09 +0000 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2014-04-22 15:37:09 +0000 |
commit | a827c5eab32a43ade5551259ea56a6a1af7e861b (patch) | |
tree | e6707df68f72baa8645210ba931272285116ad85 /xlators/mgmt/glusterd/src/glusterd-volgen.c | |
parent | 46d333783a968ab39e0beade9c7a1eec8035f8b1 (diff) | |
parent | 99bfc2a2a1689da1e173cb2f8ef54d2b09ef3a5d (diff) |
Merge branch 'upstream'
Conflicts:
glusterfs.spec.in
xlators/mgmt/glusterd/src/Makefile.am
xlators/mgmt/glusterd/src/glusterd-utils.c
xlators/mgmt/glusterd/src/glusterd.h
Change-Id: I27bdcf42b003cfc42d6ad981bd2bf8180176806d
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-volgen.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 221 |
1 files changed, 213 insertions, 8 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 8a94309ed..332c3d359 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -28,6 +28,8 @@ #include "logging.h" #include "dict.h" #include "graph-utils.h" +#include "glusterd-store.h" +#include "glusterd-hooks.h" #include "trie.h" #include "glusterd-mem-types.h" #include "cli1-xdr.h" @@ -1324,6 +1326,44 @@ sys_loglevel_option_handler (volgen_graph_t *graph, } static int +logger_option_handler (volgen_graph_t *graph, struct volopt_map_entry *vme, + void *param) +{ + char *role = NULL; + struct volopt_map_entry vme2 = {0,}; + + role = (char *) param; + + if (strcmp (vme->option, "!logger") != 0 || + !strstr (vme->key, role)) + return 0; + + memcpy (&vme2, vme, sizeof (vme2)); + vme2.option = "logger"; + + return basic_option_handler (graph, &vme2, NULL); +} + +static int +log_format_option_handler (volgen_graph_t *graph, struct volopt_map_entry *vme, + void *param) +{ + char *role = NULL; + struct volopt_map_entry vme2 = {0,}; + + role = (char *) param; + + if (strcmp (vme->option, "!log-format") != 0 || + !strstr (vme->key, role)) + return 0; + + memcpy (&vme2, vme, sizeof (vme2)); + vme2.option = "log-format"; + + return basic_option_handler (graph, &vme2, NULL); +} + +static int volgen_graph_set_xl_options (volgen_graph_t *graph, dict_t *dict) { int32_t ret = -1; @@ -1375,6 +1415,12 @@ server_spec_option_handler (volgen_graph_t *graph, if (!ret) ret = sys_loglevel_option_handler (graph, vme, "brick"); + if (!ret) + ret = logger_option_handler (graph, vme, "brick"); + + if (!ret) + ret = log_format_option_handler (graph, vme, "brick"); + return ret; } @@ -1969,7 +2015,8 @@ server_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, } /* Check for read-only volume option, and add it to the graph */ - if (dict_get_str_boolean (set_dict, "features.read-only", 0)) { + if (dict_get_str_boolean (set_dict, "features.read-only", 0) + || volinfo -> is_snap_volume) { xl = volgen_graph_add (graph, "features/read-only", volname); if (!xl) { ret = -1; @@ -2839,7 +2886,7 @@ static int client_graph_set_perf_options(volgen_graph_t *graph, tmp_data = dict_get (set_dict, "nfs-volume-file"); if (!tmp_data) return volgen_graph_set_options_generic(graph, set_dict, - volname, + volinfo, &perfxl_option_handler); else return volgen_graph_set_options_generic(graph, set_dict, @@ -2858,7 +2905,9 @@ client_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char *tmp = NULL; gf_boolean_t var = _gf_false; gf_boolean_t ob = _gf_false; + xlator_t *this = THIS; + GF_ASSERT (this); GF_ASSERT (conf); volname = volinfo->volname; @@ -2935,7 +2984,7 @@ client_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, ob = _gf_false; ret = gf_string2boolean (tmp, &ob); if (!ret && ob) { - gf_log (THIS->name, GF_LOG_WARNING, + gf_log (this->name, GF_LOG_WARNING, "root-squash is enabled. Please turn it" " off to change read-after-open " "option"); @@ -3004,7 +3053,7 @@ client_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, ret = 0; } if (ret) { - gf_log (THIS->name, GF_LOG_WARNING, "setting " + gf_log (this->name, GF_LOG_WARNING, "setting " "open behind option as part of root " "squash failed"); goto out; @@ -3030,14 +3079,28 @@ client_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, &loglevel_option_handler); if (ret) - gf_log (THIS->name, GF_LOG_WARNING, "changing client log level" + gf_log (this->name, GF_LOG_WARNING, "changing client log level" " failed"); ret = volgen_graph_set_options_generic (graph, set_dict, "client", &sys_loglevel_option_handler); if (ret) - gf_log (THIS->name, GF_LOG_WARNING, "changing client syslog " + gf_log (this->name, GF_LOG_WARNING, "changing client syslog " "level failed"); + + ret = volgen_graph_set_options_generic (graph, set_dict, "client", + &logger_option_handler); + + if (ret) + gf_log (this->name, GF_LOG_WARNING, "changing client logger" + " failed"); + + ret = volgen_graph_set_options_generic (graph, set_dict, "client", + &log_format_option_handler); + if (ret) + gf_log (this->name, GF_LOG_WARNING, "changing client log format" + " failed"); + out: return ret; } @@ -3374,16 +3437,31 @@ build_shd_graph (volgen_graph_t *graph, dict_t *mod_dict) &loglevel_option_handler); if (ret) - gf_log (THIS->name, GF_LOG_WARNING, "changing loglevel " + gf_log (this->name, GF_LOG_WARNING, "changing loglevel " "of self-heal daemon failed"); ret = volgen_graph_set_options_generic (graph, set_dict, "client", &sys_loglevel_option_handler); if (ret) - gf_log (THIS->name, GF_LOG_WARNING, "changing syslog " + gf_log (this->name, GF_LOG_WARNING, "changing syslog " "level of self-heal daemon failed"); + ret = volgen_graph_set_options_generic (graph, set_dict, + "client", + &logger_option_handler); + + if (ret) + gf_log (this->name, GF_LOG_WARNING, "changing logger " + "of self-heal daemon failed"); + + ret = volgen_graph_set_options_generic (graph, set_dict, + "client", + &log_format_option_handler); + if (ret) + gf_log (this->name, GF_LOG_WARNING, "changing log " + "format level of self-heal daemon failed"); + ret = dict_reset (set_dict); if (ret) goto out; @@ -3882,6 +3960,8 @@ generate_client_volfiles (glusterd_volinfo_t *volinfo, out: if (dict) dict_unref (dict); + + gf_log ("", GF_LOG_TRACE, "Returning %d", ret); return ret; } @@ -4511,3 +4591,128 @@ gd_is_boolean_option (char *key) return _gf_false; } + +/* This function will restore origin volume to it's snap. + * The restore operation will simply replace the Gluster origin + * volume with the snap volume. + * TODO: Multi-volume delete to be done. + * Cleanup in case of restore failure is pending. + * + * @param orig_vol volinfo of origin volume + * @param snap_vol volinfo of snapshot volume + * + * @return 0 on success and negative value on error + */ +int +gd_restore_snap_volume (dict_t *rsp_dict, + glusterd_volinfo_t *orig_vol, + glusterd_volinfo_t *snap_vol) +{ + int ret = -1; + glusterd_volinfo_t *new_volinfo = NULL; + glusterd_snap_t *snap = NULL; + xlator_t *this = NULL; + glusterd_conf_t *conf = NULL; + glusterd_volinfo_t *temp_volinfo = NULL; + glusterd_volinfo_t *voliter = NULL; + + this = THIS; + GF_ASSERT (this); + GF_ASSERT (rsp_dict); + conf = this->private; + GF_ASSERT (conf); + + GF_VALIDATE_OR_GOTO (this->name, orig_vol, out); + GF_VALIDATE_OR_GOTO (this->name, snap_vol, out); + snap = snap_vol->snapshot; + GF_VALIDATE_OR_GOTO (this->name, snap, out); + + /* Snap volume must be stoped before performing the + * restore operation. + */ + ret = glusterd_stop_volume (snap_vol); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to stop " + "snap volume(%s)", snap_vol->volname); + goto out; + } + + /* Create a new volinfo for the restored volume */ + ret = glusterd_volinfo_dup (snap_vol, &new_volinfo, _gf_true); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to create volinfo"); + goto out; + } + + /* Following entries need to be derived from origin volume. */ + strcpy (new_volinfo->volname, orig_vol->volname); + uuid_copy (new_volinfo->volume_id, orig_vol->volume_id); + new_volinfo->snap_count = orig_vol->snap_count; + new_volinfo->snap_max_hard_limit = orig_vol->snap_max_hard_limit; + new_volinfo->is_volume_restored = _gf_true; + + /* Bump the version of the restored volume, so that nodes * + * which are done can sync during handshake */ + new_volinfo->version = orig_vol->version; + + list_for_each_entry_safe (voliter, temp_volinfo, + &orig_vol->snap_volumes, snapvol_list) { + list_add_tail (&voliter->snapvol_list, + &new_volinfo->snap_volumes); + } + /* Copy the snap vol info to the new_volinfo.*/ + ret = glusterd_snap_volinfo_restore (rsp_dict, new_volinfo, snap_vol); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to restore snap"); + (void)glusterd_volinfo_delete (new_volinfo); + goto out; + } + + /* If the orig_vol is already restored then we should delete + * the backend LVMs */ + if (orig_vol->is_volume_restored) { + ret = glusterd_lvm_snapshot_remove (rsp_dict, orig_vol); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to remove " + "LVM backend"); + (void)glusterd_volinfo_delete (new_volinfo); + goto out; + } + } + + /* Once the new_volinfo is completely constructed then delete + * the orinal volinfo + */ + ret = glusterd_volinfo_delete (orig_vol); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to delete volinfo"); + (void)glusterd_volinfo_delete (new_volinfo); + goto out; + } + /* New volinfo always shows the status as created. Therefore + * set the status to stop. */ + glusterd_set_volume_status (new_volinfo, GLUSTERD_STATUS_STOPPED); + + list_add_tail (&new_volinfo->vol_list, &conf->volumes); + + /* Now delete the snap entry. As a first step delete the snap + * volume information stored in store. */ + ret = glusterd_snap_remove (rsp_dict, snap, _gf_false, _gf_true); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "Failed to delete " + "snap %s", snap->snapname); + goto out; + } + + ret = glusterd_store_volinfo (new_volinfo, + GLUSTERD_VOLINFO_VER_AC_INCREMENT); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to store volinfo"); + goto out; + } + + ret = 0; +out: + + return ret; +} |