/xlators/bindings/python/src/

#ifndef _CONFIG_H #define _CONFIG_H #include "config.h" #endif #include "server.h" #include "server-helpers.h" #include "glusterfs3-xdr.h" #include "compat-errno.h" #include "glusterfs3.h" #include "authenticate.h" struct __get_xl_struct { const char *name; xlator_t *reply; }; int gf_compare_client_version (rpcsvc_request_t *req, int fop_prognum, int mgmt_prognum) { int ret = -1; /* TODO: think.. */ if (glusterfs3_1_fop_prog.prognum == fop_prognum) ret = 0; return ret; } void __check_and_set (xlator_t *each, void *data) { if (!strcmp (each->name, ((struct __get_xl_struct *) data)->name)) ((struct __get_xl_struct *) data)->reply = each; } static xlator_t * get_xlator_by_name (xlator_t *some_xl, const char *name) { struct __get_xl_struct get = { .name = name, .reply = NULL }; xlator_foreach (some_xl, __check_and_set, &get); return get.reply; } int _volfile_update_checksum (xlator_t *this, char *key, uint32_t checksum) { server_conf_t *conf = NULL; struct _volfile_ctx *temp_volfile = NULL; conf = this->private; temp_volfile = conf->volfile; while (temp_volfile) { if ((NULL == key) && (NULL == temp_volfile->key)) break; if ((NULL == key) || (NULL == temp_volfile->key)) { temp_volfile = temp_volfile->next; continue; } if (strcmp (temp_volfile->key, key) == 0) break; temp_volfile = temp_volfile->next; } if (!temp_volfile) { temp_volfile = GF_CALLOC (1, sizeof (struct _volfile_ctx), gf_server_mt_volfile_ctx_t); if (!temp_volfile) goto out; temp_volfile->next = conf->volfile; temp_volfile->key = (key)? gf_strdup (key): NULL; temp_volfile->checksum = checksum; conf->volfile = temp_volfile; goto out; } if (temp_volfile->checksum != checksum) { gf_log (this->name, GF_LOG_INFO, "the volume file got modified between earlier access " "and now, this may lead to inconsistency between " "clients, advised to remount client"); temp_volfile->checksum = checksum; } out: return 0; } static size_t getspec_build_volfile_path (xlator_t *this, const char *key, char *path, size_t path_len) { int ret = -1; int free_filename = 0; char *filename = NULL; server_conf_t *conf = NULL; char data_key[256] = {0,}; conf = this->private; /* Inform users that this option is changed now */ ret = dict_get_str (this->options, "client-volume-filename", &filename); if (ret == 0) { gf_log (this->name, GF_LOG_WARNING, "option 'client-volume-filename' is changed to " "'volume-filename.' which now takes 'key' as an " "option to choose/fetch different files from server. " "Refer documentation or contact developers for more " "info. Currently defaulting to given file '%s'", filename); } if (key && !filename) { sprintf (data_key, "volume-filename.%s", key); ret = dict_get_str (this->options, data_key, &filename); if (ret < 0) { /* Make sure that key doesn't contain "../" in path */ if ((gf_strstr (key, "/", "..")) == -1) { gf_log (this->name, GF_LOG_ERROR, "%s: invalid key", key); goto out; } } } if (!filename) { ret = dict_get_str (this->options, "volume-filename.default", &filename); if (ret < 0) { gf_log (this->name, GF_LOG_DEBUG, "no default volume filename given, " "defaulting to %s", DEFAULT_VOLUME_FILE_PATH); } } if (!filename && key) { ret = gf_asprintf (&filename, "%s/%s.vol", conf->conf_dir, key); if (-1 == ret) goto out; free_filename = 1; } if (!filename) filename = DEFAULT_VOLUME_FILE_PATH; ret = -1; if ((filename) && (path_len > strlen (filename))) { strcpy (path, filename); ret = strlen (filename); } out: if (free_filename) GF_FREE (filename); return ret; } int _validate_volfile_checksum (xlator_t *this, char *key, uint32_t checksum) { char filename[ZR_PATH_MAX] = {0,}; server_conf_t *conf = NULL; struct _volfile_ctx *temp_volfile = NULL; int ret = 0; int fd = 0; uint32_t local_checksum = 0; conf = this->private; temp_volfile = conf->volfile; if (!checksum) goto out; if (!temp_volfile) { ret = getspec_build_volfile_path (this, key, filename, sizeof (filename)); if (ret <= 0) goto out; fd = open (filename, O_RDONLY); if (-1 == fd) { ret = 0; gf_log (this->name, GF_LOG_INFO, "failed to open volume file (%s) : %s", filename, strerror (errno)); goto out; } get_checksum_for_file (fd, &local_checksum); _volfile_update_checksum (this, key, local_checksum); close (fd); } temp_volfile = conf->volfile; while (temp_volfile) { if ((NULL == key) && (NULL == temp_volfile->key)) break; if ((NULL == key) || (NULL == temp_volfile->key)) { temp_volfile = temp_volfile->next; continue; } if (strcmp (temp_volfile->key, key) == 0) break;