Пример #1
0
static int
parse_namespace_info(worker_t *worker, GError **error)
{
	gchar *ns_name;
	asn1_session_t *asn1_session;
	namespace_data_t *ns_data;
	namespace_info_t *ns_info = NULL;


	asn1_session = asn1_worker_get_session(worker);
	ns_name = asn1_worker_get_session_data(worker);
	if (!ns_name || !asn1_session) {
		GSETERROR(error,"Invalid worker : no session data");
		return 0;
	}
	ns_data = g_hash_table_lookup(namespaces,ns_name);
	if (!ns_data) {
		GSETERROR(error,"Namespace '%s' does not exist", ns_name);
		return 0;
	}

	if (asn1_session->resp_body != NULL) {
		ns_info = namespace_info_unmarshall(asn1_session->resp_body,
				asn1_session->resp_body_size, error);
		if (ns_info == NULL) {
			GSETERROR(error, "Failed to unmarshall namespace_info from ASN1 data");
			return 0;
		}

		memcpy(&(ns_info->addr), &(ns_data->ns_info.addr), sizeof(addr_info_t));
		
		/* Check that we have the same name */
		if (strcmp(ns_info->name, ns_data->name)) {
			ERROR("Namespace name [%s] in /etc/gridstorage does not match name [%s] in conscience !",
				ns_data->name, ns_info->name);
			namespace_info_free(ns_info);
			return(0);
		}

		DEBUG("Infos of namespace [%s] updated with value name [%s] / chunk_size[%"G_GINT64_FORMAT"]",
			ns_data->ns_info.name, ns_info->name, ns_info->chunk_size);

		namespace_info_clear(&(ns_data->ns_info));
		namespace_info_copy(ns_info, &(ns_data->ns_info));
		namespace_info_free(ns_info);

		/* Flag namespace if it's the first config */
		ns_data->configured = TRUE;
	}

	return(1);
}
Пример #2
0
    enum http_rc_e
action_cs_info (struct req_args_s *args)
{
    GError *err;
    if (NULL != (err = _cs_check_tokens(args)))
        return _reply_notfound_error (args, err);

    struct namespace_info_s ni;
    memset (&ni, 0, sizeof (ni));
    NSINFO_DO(namespace_info_copy (&nsinfo, &ni, NULL));

    GString *gstr = g_string_new ("");
    namespace_info_encode_json (gstr, &ni);
    namespace_info_clear (&ni);
    return _reply_success_json (args, gstr);
}
Пример #3
0
static gs_error_t *
_dl_nocache(gs_container_t *c, struct hc_url_s *url,
		gs_download_info_t *dlinfo, gchar *stgpol)
{
	gs_error_t *e = NULL;
	GError *err = NULL;
	gs_content_t *content = NULL;
	namespace_info_t *ni = NULL;
	GSList *filtered = NULL, *beans = NULL;

	/*find the content*/
	content  = gs_get_content_from_path_full(c, hc_url_get(url, HCURL_PATH),
			hc_url_get(url, HCURL_SNAPORVERS), &filtered, &beans, &e);

	if(NULL != content) {
		GRID_DEBUG("Content %s found in container %s\n",
				hc_url_get(url, HCURL_PATH), hc_url_get(url, HCURL_REFERENCE));

		ni = get_namespace_info(hc_url_get(url, HCURL_NS), &err);
		if (!ni) {
			GSERRORCAUSE(&e, err, "Cannot get namespace info for NS [%s]",
					hc_url_get(url, HCURL_NS));
			g_clear_error(&err);
			return e;
		}

		namespace_info_copy(ni, &(content->info.container->info.gs->ni), &err);

		/*download the content*/
		(void) gs_download_content_full (content, dlinfo, stgpol, filtered,
				beans, &e);
		namespace_info_clear(ni);
		g_free(ni);
		gs_content_free (content);
		g_slist_free(filtered);
		_bean_cleanl2(beans);
		return e;
	}

	g_printerr("'%s' not found in '%s'\n", hc_url_get(url, HCURL_PATH),
			hc_url_get(url, HCURL_REFERENCE));
	return e;
}
Пример #4
0
gs_grid_storage_t*
gs_grid_storage_init_flags(const gchar *ns, uint32_t flags,
		int to_cnx, int to_req, gs_error_t **err)
{
	gs_grid_storage_t *gs=NULL;
	register const gchar *sep;
	namespace_info_t *ni;

	env_init();

	/*parse the arguments*/
	if (!ns || !*ns) {
		GSERRORSET(err,"Invalid parameter");
		return NULL;
	}

	DEBUG("Creating a new GridStorage client for namespace [%s]", ns);

	/*inits a new gs_grid_storage_t*/
	gs = calloc (1, sizeof(gs_grid_storage_t));
	if (!gs) {
		GSERRORSET(err,"Memory allocation failure");
		return NULL;
	}

	if (!(flags & GSCLIENT_NOINIT)) {
		GError *gErr = NULL;
		ni = get_namespace_info(ns, &gErr);
		if (!ni) {
			GSERRORCAUSE(err,gErr,"Cannot get namespace info");
			if (gErr)
				g_clear_error(&gErr);
			free(gs);
			return NULL;
		}
		namespace_info_copy(ni, &(gs->ni), &gErr);
		namespace_info_free(ni);
		if (gErr != NULL) {
			GSERRORCAUSE(err, gErr, "Failed to copy namespace info");
			g_clear_error(&gErr);
			free(gs);
			return NULL;
		}
	}

	if (NULL != (sep = strchr(ns, '.'))) {
		gs->physical_namespace = g_strndup(ns, sep-ns);
	}
	else {
		gs->physical_namespace = g_strdup(ns);
	}
	gs->full_vns = g_strdup(ns);

	if (!(flags & GSCLIENT_NOINIT)) {
		GError *gErr = NULL;
		gs->metacd_resolver = resolver_metacd_create (ns, &gErr);
		if (!gs->metacd_resolver) {
			GSERRORCAUSE(err,gErr,"Cannot init the metacd");
			if (gErr)
				g_clear_error(&gErr);
			free(gs);
			return NULL;
		}

		gs->direct_resolver = resolver_direct_create_with_metacd (ns,
				gs->metacd_resolver, to_cnx, to_req, &gErr);
		if (!gs->direct_resolver) {
			GSERRORCAUSE(err,gErr,"Cannot init the direct resolver");
			if (gErr)
				g_clear_error(&gErr);
			resolver_metacd_free(gs->metacd_resolver);
			free(gs);
			return NULL;
		}
	}

	gs->timeout.rawx.op =  RAWX_TOREQ_DEFAULT;
	gs->timeout.rawx.cnx = RAWX_TOCNX_DEFAULT;
	gs->timeout.m2.op =   M2_TOREQ_DEFAULT;
	gs->timeout.m2.cnx =  M2_TOCNX_DEFAULT;
	g_strlcpy(gs->ni.name, ns, sizeof(gs->ni.name));

	if (NULL != strchr(gs->ni.name, '.'))
		* (strchr(gs->ni.name, '.')) = '\0';

	return gs;
}