Beispiel #1
0
static GError *
_resolve_meta1(struct hc_resolver_s *r, struct hc_url_s *u, gchar ***result)
{
	struct hashstr_s *hk;
	GError *err = NULL;

	GRID_TRACE2("%s(%s)", __FUNCTION__, hc_url_get(u, HCURL_WHOLE));

	hk = hashstr_printf("meta1|%s|%.4s",
			hc_url_get(u, HCURL_NSPHYS),
			hc_url_get(u, HCURL_HEXID));

	/* Try to hit the cache */
	if (!(*result = hc_resolver_get_cached(r, r->csm0.cache, hk))) {
		/* get a meta0, then store it in the cache */
		gchar **m0urlv = NULL;

		err = _resolve_meta0(r, hc_url_get(u, HCURL_NSPHYS), &m0urlv);
		if (err != NULL)
			g_prefix_error(&err, "M0 resolution error: ");
		else {
			err = _resolve_m1_through_many_m0(m0urlv, hc_url_get_id(u), result);
			if (!err)
				hc_resolver_store(r, r->csm0.cache, hk, *result);
			g_strfreev(m0urlv);
		}
	}

	g_free(hk);
	return err;
}
Beispiel #2
0
GError*
hc_resolve_reference_service(struct hc_resolver_s *r, struct hc_url_s *url,
		const gchar *srvtype, gchar ***result)
{
	GError *err;
	struct hashstr_s *hk;

	GRID_TRACE2("%s(%s,%s)", __FUNCTION__, hc_url_get(url, HCURL_WHOLE), srvtype);
	g_assert(r != NULL);
	g_assert(url != NULL);
	g_assert(srvtype != NULL);
	g_assert(result != NULL);
	g_assert(*result == NULL);

	if (!hc_url_get_id(url) || !hc_url_has(url, HCURL_NS))
		return NEWERROR(400, "Incomplete URL [%s]", hc_url_get(url, HCURL_WHOLE));

	hk = hashstr_printf("%s|%s|%s", srvtype,
			hc_url_get(url, HCURL_NSPHYS),
			hc_url_get(url, HCURL_HEXID));
	err = _resolve_reference_service(r, hk, url, srvtype, result);
	g_free(hk);

	return err;
}
Beispiel #3
0
GError*
hc_resolve_reference_directory(struct hc_resolver_s *r, struct hc_url_s *url,
		gchar ***result)
{
	GRID_TRACE2("%s(%s)", __FUNCTION__, hc_url_get(url, HCURL_WHOLE));
	EXTRA_ASSERT(r != NULL);
	EXTRA_ASSERT(url != NULL);
	EXTRA_ASSERT(result != NULL);
	if (!hc_url_get_id(url) || !hc_url_has(url, HCURL_NS))
		return NEWERROR(CODE_BAD_REQUEST, "Incomplete URL [%s]", hc_url_get(url, HCURL_WHOLE));

	GError *err = NULL;
	gchar **m1v = NULL, **m0v = NULL;

	if (!(err = _resolve_meta0(r, hc_url_get(url, HCURL_NS), &m0v)))
		err = _resolve_meta1(r, url, &m1v);

	if (err) {
		if (m0v) g_strfreev (m0v);
		if (m1v) g_strfreev (m1v);
		return err;
	}

	*result = g_malloc0(sizeof(gchar*) *
			(g_strv_length(m0v) + g_strv_length(m1v) + 1));
	gchar **d = *result;
	for (gchar **p=m0v; *p ;++p) { *(d++) = *p; }
	g_free (m0v); // pointers reused
	for (gchar **p=m1v; *p ;++p) { *(d++) = *p; }
	g_free (m1v); // pointers reused
	return NULL;
}
Beispiel #4
0
gs_error_t *
hc_func_delete_property(gs_grid_storage_t *hc, struct hc_url_s *url, char **keys)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;
	gs_content_t *content = NULL;

	c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE), NULL, 0,
			&e);
	if (NULL != c) {
		if (hc_url_has(url, HCURL_PATH)) {
			content = gs_get_content_from_path_and_version (c,
					hc_url_get(url, HCURL_PATH), hc_url_get(url, HCURL_VERSION),
					&e);
			if (NULL != content) {
				hc_delete_content_property(content, keys, &e);
				gs_content_free(content);
			}
		} else {
			e = hc_del_container_global_property(c, keys[0]);
		}
		gs_container_free(c);
	}
	return e;
}
int
meta2_filter_action_has_container(struct gridd_filter_ctx_s *ctx,
		struct gridd_reply_ctx_s *reply)
{
	(void) reply;
	struct meta2_backend_s *m2b = meta2_filter_ctx_get_backend(ctx);
	struct hc_url_s *url = meta2_filter_ctx_get_url(ctx);

	if (!url) {
		GRID_WARN("BUG : Checking container's presence : URL not set");
		return FILTER_OK;
	}

	GError *e = meta2_backend_has_container(m2b, url);
	if(NULL != e) {
		if (e->code == CODE_UNAVAILABLE)
			GRID_DEBUG("Container %s exists but could not open it: %s",
					hc_url_get(url, HCURL_WHOLE), e->message);
		else
			GRID_DEBUG("No such container (%s)", hc_url_get(url, HCURL_WHOLE));
		if (e->code == CODE_CONTAINER_NOTFOUND) {
			hc_decache_reference_service(m2b->resolver, url, META2_TYPE_NAME);
		}
		meta2_filter_ctx_set_error(ctx, e);
		return FILTER_KO;
	}
	return FILTER_OK;
}
static int
_list_NORMAL(struct gridd_filter_ctx_s *ctx, struct gridd_reply_ctx_s *reply,
		struct list_params_s *lp)
{
	GError *e = NULL;
	struct meta2_backend_s *m2b = meta2_filter_ctx_get_backend(ctx);
	struct hc_url_s *url = meta2_filter_ctx_get_url(ctx);
	struct on_bean_ctx_s *obc = _on_bean_ctx_init(ctx, reply);

	if (hc_url_has(url, HCURL_SNAPSHOT)) {
		lp->snapshot_name = hc_url_get(url, HCURL_SNAPSHOT);
	} else if (hc_url_has(url, HCURL_VERSION)) {
		lp->snapshot_name = hc_url_get(url, HCURL_VERSION);
	}

	e = meta2_backend_list_aliases(m2b, url, lp, _get_cb, obc);
	if (NULL != e) {
		GRID_DEBUG("Fail to return alias for url: %s",
				hc_url_get(url, HCURL_WHOLE));
		_on_bean_ctx_clean(obc);
		meta2_filter_ctx_set_error(ctx, e);
		return FILTER_KO;
	}

	_on_bean_ctx_send_list(obc, TRUE);
	_on_bean_ctx_clean(obc);
	return FILTER_OK;
}
Beispiel #7
0
gs_error_t *
hc_delete_content(gs_grid_storage_t *hc, struct hc_url_s *url)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;
	gs_content_t *content = NULL;

	c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE),NULL, 0, &e);
	if(NULL != c) {
		const gchar *version = hc_url_get(url, HCURL_VERSION);
		// First try
		content = gs_get_content_from_path_and_version (c, hc_url_get(url, HCURL_PATH), version, &e);
		if (content == NULL && e != NULL && e->code == CODE_CONTENT_NOTFOUND && !version) {
			// Last version is probably marked deleted, so a "get" without
			// version fails. We need to specify we want the latest, even
			// if it's deleted, so we can undelete it.
			version = HCURL_LATEST_VERSION;
			gs_error_free(e);
			e = NULL;
			// Second try
			content = gs_get_content_from_path_and_version (c, hc_url_get(url, HCURL_PATH), version, &e);
		}
		if (NULL != content) {
			if(gs_destroy_content (content, &e)) {
				GRID_DEBUG("Content %s deleted\n", hc_url_get(url, HCURL_PATH));
			}
			gs_content_free(content);
		}
		gs_container_free(c);
	}
	return e;
}
Beispiel #8
0
gs_error_t *
hc_func_list_snapshots(gs_grid_storage_t *hc, struct hc_url_s *url,
		int output_xml, int show_info, char **result)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;
	struct list_content_s lc;
	redc_snapshot_t **snapshots = NULL;

	c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE),
			NULL, 0, &e);
	if (c != NULL) {
		lc.nb_elts = 0;
		lc.xml = output_xml;
		lc.show_info = show_info;
		lc.buffer = g_string_new("");
		lc.listed = NULL;

		e = redc_list_snapshots(c, &snapshots);
		if (e == NULL) {
			int i = 0;
			redc_snapshot_t *snap = snapshots[i];
			if (output_xml) {
				g_string_append_printf(lc.buffer,
						"<Container>\n"
						" <Name>%s</Name>\n"
						" <Snapshots>\n",
					hc_url_get(url, HCURL_REFERENCE));
			} else {
				g_string_append_printf(lc.buffer,
						"#Listing snapshots of container=[%s]\n",
						hc_url_get(url, HCURL_REFERENCE));
			}
			for (; snap != NULL; ++i, snap = snapshots[i]) {
				const char *name = redc_snapshot_get_name(snap);
				lc.nb_elts++;
				if (lc.xml) {
					g_string_append_printf(lc.buffer, "  <Snapshot>\n");
					g_string_append_printf(lc.buffer, "   <Name>%s</Name>\n"
							"  </Snapshot>\n", name);
				} else {
					g_string_append_printf(lc.buffer, "%s\n", name);
				}
			}
			if (output_xml) {
				g_string_append_printf(lc.buffer,
						" </Snapshots>\n"
						"</Container>\n");
			} else {
				g_string_append_printf(lc.buffer,
						"#Total in [%s]: %i elements\n",
						hc_url_get(url, HCURL_REFERENCE), lc.nb_elts);
			}
			*result = g_string_free(lc.buffer, FALSE);
			redc_snapshot_array_clean(snapshots);
		}
		gs_container_free(c);
	}
	return e;
}
Beispiel #9
0
gs_error_t *
hc_func_set_property(gs_grid_storage_t *hc, struct hc_url_s *url,
	char ** args)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;
	gs_content_t *content = NULL;

	c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE),
			NULL, 0, &e);
	if (NULL != c) {
		if (hc_url_has(url, HCURL_PATH)) {
			content = gs_get_content_from_path_and_version (c,
					hc_url_get(url, HCURL_PATH), hc_url_get(url, HCURL_VERSION),
					&e);
			if (NULL != content) {
				gchar **props = g_malloc0(sizeof(gchar*) * 2);
				props[0] = g_strdup_printf("%s=%s", args[0], args[1]);
				props[1] = NULL;
				hc_set_content_property(content, props, &e);
				gs_content_free(content);
				g_strfreev(props);
			}
		} else {
			e = hc_set_container_global_property(c, args[0], args[1]);
		}
		gs_container_free(c);
	}
	return e;
}
Beispiel #10
0
static status_t
_get_container_user_properties(gs_grid_storage_t *hc, struct hc_url_s *url,
		char ***props, gs_error_t **gserr)
{
	GError *gerr = NULL;
	gboolean rc;
	addr_info_t *m1 = NULL;
	GSList *excluded = NULL;

	gs_container_t *c = gs_get_container(hc, hc_url_get(url, HCURL_USER), 0, gserr);
	if(!c)
		return 0;
	for (;;) {

		m1 = gs_resolve_meta1v2(hc, hc_url_get_id(url), c->info.name, 1, &excluded, &gerr);

		if (!m1) {
			*gserr = gs_error_new(CODE_INTERNAL_ERROR, "No META1 found for [%s]", hc_url_get(url, HCURL_USER));
			break;
		}

		rc = meta1v2_remote_reference_get_property (m1, &gerr, url, NULL, props);

		if (!rc) {
			excluded = g_slist_prepend(excluded, m1);
			m1=NULL;
			if (gerr) {
				if (CODE_IS_NETWORK_ERROR(gerr->code)) {
					g_error_free(gerr);
					gerr = NULL;
				} else {
					GSERRORCAUSE(gserr, gerr, "Cannot get container user properties");
					break;
				}
			}
		} else {
			break;
		}
	}
	if (excluded) {
		g_slist_foreach(excluded, addr_info_gclean, NULL);
		g_slist_free(excluded);
	}
	if (m1)
		g_free(m1);

	gs_container_free(c);

	if (gerr)
		g_error_free(gerr);

	return rc;
}
Beispiel #11
0
gs_error_t *
hc_func_copy_content(gs_grid_storage_t *hc, struct hc_url_s *url, const char *source)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;

	c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE), NULL, 0, &e);
	if(NULL != c) {
		hc_copy_content(c, source, hc_url_get(url, HCURL_PATH), &e); 
		gs_container_free(c);
	}
	return e;
}
Beispiel #12
0
GError*
hc_resolve_reference_directory(struct hc_resolver_s *r, struct hc_url_s *url,
		gchar ***result)
{
	GRID_TRACE2("%s(%s)", __FUNCTION__, hc_url_get(url, HCURL_WHOLE));
	g_assert(r != NULL);
	g_assert(url != NULL);
	g_assert(result != NULL);
	if (!hc_url_get_id(url) || !hc_url_has(url, HCURL_NS))
		return NEWERROR(400, "Incomplete URL [%s]", hc_url_get(url, HCURL_WHOLE));

	return _resolve_meta1(r, url, result);
}
Beispiel #13
0
gs_error_t *
hc_list_contents(gs_grid_storage_t *hc, struct hc_url_s *url, int output_xml, int show_info,
		char **result)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;
	const gchar *snapshot = hc_url_get(url, HCURL_SNAPORVERS);
	struct list_content_s lc;

	c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE), NULL, 0, &e);

	if (NULL != c) {
		GRID_DEBUG("%s found\n", hc_url_get(url, HCURL_REFERENCE));

		lc.nb_elts = 0;
		lc.xml = output_xml;
		lc.show_info = show_info;
		lc.buffer = g_string_new("");
		lc.listed = NULL;

		if(output_xml) {
			g_string_append_printf(lc.buffer,
					"<Container>\n"
					" <Name>%s</Name>\n"
					" <Contents>\n",
					hc_url_get(url, HCURL_REFERENCE));
		} else {
			g_string_append_printf(lc.buffer, "#Listing container=[%s]\n", hc_url_get(url, HCURL_REFERENCE));
		}

		if (!gs_list_container_snapshot(c, NULL, _my_content_filter, &lc,
				snapshot, &e)) {
			g_printerr("Cannot list %s\n", hc_url_get(url, HCURL_REFERENCE));
			g_string_free(lc.buffer, TRUE);
		} else {
			_sort_listed(&lc);
			GRID_DEBUG("%s listed\n", hc_url_get(url, HCURL_REFERENCE));
			if(output_xml) {
				lc.buffer = g_string_append(lc.buffer,
					" </Contents>\n"
					"</Container>\n");
			} else {
				g_string_append_printf(lc.buffer, "#Total in [%s]: %i elements\n",
						hc_url_get(url, HCURL_REFERENCE), lc.nb_elts);
			}
			*result = g_string_free(lc.buffer, FALSE);
		}

		gs_container_free(c);
		return e;
	}

	g_printerr("Cannot find %s\n", hc_url_get(url, HCURL_REFERENCE));
	return e;
}
Beispiel #14
0
static GError *
_m1_action (struct req_args_s *args, gchar ** m1v,
	GError * (*hook) (const gchar * m1))
{
	for (gchar ** pm1 = m1v; *pm1; ++pm1) {
		struct meta1_service_url_s *m1 = meta1_unpack_url (*pm1);
		if (!m1)
			continue;
		if (0 != g_ascii_strcasecmp(m1->srvtype, "meta1")) {
			meta1_service_url_clean (m1);
			continue;
		}

		struct addr_info_s m1a;
		if (!grid_string_to_addrinfo (m1->host, NULL, &m1a)) {
			GRID_INFO ("Invalid META1 [%s] for [%s]",
				m1->host, hc_url_get (args->url, HCURL_WHOLE));
			meta1_service_url_clean (m1);
			continue;
		}

		GError *err = hook (m1->host);
		meta1_service_url_clean (m1);
		if (!err)
			return NULL;
		else if (err->code == CODE_REDIRECT)
			g_clear_error (&err);
		else {
			g_prefix_error (&err, "META1 error: ");
			return err;
		}
	}
	return NEWERROR (CODE_UNAVAILABLE, "No meta1 answered");
}
Beispiel #15
0
static int
_meta2_filter_check_ns_name(struct gridd_filter_ctx_s *ctx,
		struct gridd_reply_ctx_s *reply, int optional)
{
	(void) reply;
	TRACE_FILTER();
	const struct meta2_backend_s *backend = meta2_filter_ctx_get_backend(ctx);
	const char *req_ns = hc_url_get(meta2_filter_ctx_get_url(ctx), HCURL_NS);

	if (!backend || !backend->backend.ns_name[0]) {
		GRID_DEBUG("Missing information for namespace checking");
		meta2_filter_ctx_set_error(ctx, NEWERROR(CODE_INTERNAL_ERROR,
					"Missing backend information, cannot check namespace"));
		return FILTER_KO;
	}

	if (!req_ns) {
		if (optional)
			return FILTER_OK;
		GRID_DEBUG("Missing namespace name in request");
		meta2_filter_ctx_set_error(ctx, NEWERROR(CODE_BAD_REQUEST,
					"Bad Request: Missing namespace name information"));
		return FILTER_KO;
	}

	if (0 != g_ascii_strcasecmp(backend->backend.ns_name, req_ns)) {
		meta2_filter_ctx_set_error(ctx, NEWERROR(CODE_BAD_REQUEST,
					"Request namespace [%s] does not match server namespace [%s]",
					req_ns, backend->backend.ns_name));
		return FILTER_KO;
	}

	return FILTER_OK;
}
GError *
meta1_backend_user_info(struct meta1_backend_s *m1,
                        struct hc_url_s *url, gchar ***result)
{
    struct sqlx_sqlite3_s *sq3 = NULL;
    GError *err = _open_and_lock(m1, url, SQLX_OPEN_MASTERSLAVE, &sq3);
    if (!err) {
        struct hc_url_s **urls = NULL;
        if (!(err = __info_user(sq3, url, FALSE, &urls))) {
            if (result) {
                if (!urls)
                    *result = g_malloc0(sizeof(struct hc_url_s*));
                else {
                    *result = g_malloc0(sizeof(gchar*) * (1+g_strv_length((gchar**)urls)));
                    for (int i=0; urls[i] ; ++i)
                        (*result)[i] = g_strdup(hc_url_get(urls[i], HCURL_WHOLE));
                }
            }
        }
        hc_url_cleanv (urls);
        sqlx_repository_unlock_and_close_noerror(sq3);
    }

    return err;
}
Beispiel #17
0
void
sqlx_name_fill  (struct sqlx_name_mutable_s *n, struct hc_url_s *url,
		const char *srvtype, gint64 seq)
{
	EXTRA_ASSERT (n != NULL);
	EXTRA_ASSERT (url != NULL);
	EXTRA_ASSERT (srvtype != NULL);
	const gchar *subtype = hc_url_get (url, HCURL_TYPE);

	n->ns = g_strdup(hc_url_get (url, HCURL_NS));
	n->base = g_strdup_printf ("%s.%"G_GINT64_FORMAT, hc_url_get (url, HCURL_HEXID), seq);
	if (subtype && 0 != strcmp(subtype, HCURL_DEFAULT_TYPE))
		n->type = g_strdup_printf ("%s.%s", srvtype, subtype);
	else
		n->type = g_strdup (srvtype);
}
int
meta2_filter_action_has_container(struct gridd_filter_ctx_s *ctx,
		struct gridd_reply_ctx_s *reply)
{
	(void) reply;
	struct meta2_backend_s *m2b = meta2_filter_ctx_get_backend(ctx);
	struct hc_url_s *url = meta2_filter_ctx_get_url(ctx);

	if (!url) {
		GRID_WARN("BUG : Checking container's presence : URL not set");
		meta2_filter_ctx_set_error (ctx, NEWERROR(CODE_BAD_REQUEST, "No URL"));
		return FILTER_KO;
	}

	GError *e = meta2_backend_has_container(m2b, url);
	if (NULL != e) {
		GRID_DEBUG("Container test error for [%s] : (%d) %s",
					hc_url_get(url, HCURL_WHOLE), e->code, e->message);
		if (e->code == CODE_CONTAINER_NOTFOUND)
			hc_decache_reference_service(m2b->resolver, url, NAME_SRVTYPE_META2);
		meta2_filter_ctx_set_error(ctx, e);
		return FILTER_KO;
	}

	return FILTER_OK;
}
Beispiel #19
0
static GError *
_resolve_service_through_many_meta1(gchar **urlv, struct hc_url_s *u,
		const gchar *s, gchar ***result)
{
	guint i, last;
	gchar *url;

	GRID_TRACE2("%s(%s,%s)", __FUNCTION__, hc_url_get(u, HCURL_WHOLE), s);

	for (last=g_strv_length(urlv); last ;last--) {
		/* pick a random URL */
		i = rand() % last;
		url = urlv[i];

		GError *err = _resolve_service_through_one_m1(url, u, s, result);
		g_assert((err!=NULL) ^ (*result!=NULL));

		if (!err)
			return NULL;
		if (err->code >= 100)
			return err;
		g_clear_error(&err);

		/* swap 'i' and 'last' */
		urlv[i] = urlv[last-1];
		urlv[last-1] = url;
	}

	return NEWERROR(500, "No META0 answered");
}
Beispiel #20
0
static GError*
_resolve_reference_service(struct hc_resolver_s *r, struct hashstr_s *hk,
		struct hc_url_s *u, const gchar *s, gchar ***result)
{
	GError *err;
	gchar **m1urlv = NULL;

	GRID_TRACE2("%s(%s,%s,%s)", __FUNCTION__, hashstr_str(hk),
			hc_url_get(u, HCURL_WHOLE), s);

	/* Try to hit the cache for the service itself */
	*result = hc_resolver_get_cached(r, r->services.cache, hk);
	if (NULL != *result) {
		return NULL;
	}

	/* now attempt a real resolution */
	err = _resolve_meta1(r, u, &m1urlv);
	g_assert((err!=NULL) ^ (m1urlv!=NULL));
	if (NULL != err)
		return err;

	err = _resolve_service_through_many_meta1(m1urlv, u, s, result);
	g_assert((err!=NULL) ^ (*result!=NULL));
	if (!err) {
		/* fill the cache */
		if (!(r->flags & HC_RESOLVER_NOCACHE))
			hc_resolver_store(r, r->services.cache, hk, *result);
	}

	g_strfreev(m1urlv);
	return err;
}
Beispiel #21
0
	void test(struct meta2_backend_s *m2, struct hc_url_s *url) {
		GError *err;
		/* Generate a list of beans */
		GSList *beans = create_alias(m2, url, NULL);
		/* Change the hash of the chunk beans (0 by default) */
		change_chunk_hash(beans, 0);
		/* Put the beans in the database */
		err = meta2_backend_put_alias(m2, url, beans, NULL, NULL);
		g_assert_no_error(err);
		_bean_cleanl2(beans);

		/* Generate other contents with same hashes */
		for (guint counter = 1; counter <= num_duplicates; counter++) {
			/* Suffix the base url */
			gchar *url_str = g_strdup_printf("%s_%d", hc_url_get(url, HCURL_WHOLE),
					counter);
			struct hc_url_s *url2 = hc_url_oldinit(url_str);
			g_free(url_str);
			GSList *beans2 = create_alias(m2, url2, NULL);
			change_chunk_hash(beans2, counter);
			err = meta2_backend_put_alias(m2, url2, beans2, NULL, NULL);
			g_assert_no_error(err);
			_bean_cleanl2(beans2);
		}

		err = meta2_backend_deduplicate_chunks(m2, url);
		g_assert_no_error(err);
	}
Beispiel #22
0
gs_error_t *
hc_delete_container(gs_grid_storage_t *hc, struct hc_url_s *url, int force, int flush)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;
	unsigned int flags = 0;

	if (force) flags |= M2V2_DESTROY_FORCE;

	// to flush by meta2, but without event generated
	//if (flush) flags |= M2V2_DESTROY_FLUSH;

	c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE), NULL, 0, &e);
	if(NULL != c) {

		// to flush by this process, but with event generated
		if (flush) {
			if (gs_flush_container(c, &e)) {
				GRID_DEBUG("Container flushed\n");
		    }
		}

		// destroy container
		if (!e) {
			if (gs_destroy_container_flags (c, flags, &e)) {
				GRID_DEBUG("Container deleted\n");
			}
		}
		gs_container_free(c);
	}
	return e;
}
Beispiel #23
0
static GError *
_resolve_service_through_one_m1(const gchar *m1, struct hc_url_s *u,
		const gchar *s, gchar ***result)
{
	GError *err = NULL;
	struct addr_info_s ai;

	GRID_TRACE2("%s(%s,%s,%s)", __FUNCTION__, m1, hc_url_get(u, HCURL_WHOLE), s);
	meta1_strurl_get_address(m1, &ai);

	*result = meta1v2_remote_list_reference_services(&ai, &err,
			hc_url_get(u, HCURL_NS), hc_url_get_id(u), s,
			_timeout(&rc_resolver_timeout_m1, 30.0),
			_timeout(&rc_resolver_timeout_m1, 30.0));
	g_assert((err!=NULL) ^ (*result!=NULL));

	return err;
}
Beispiel #24
0
/* Generic function to avoid code duplication */
static gs_error_t *
_hc_func_snapshot_generic(snap_func func, gs_grid_storage_t *hc,
		struct hc_url_s *url, void *param)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;
	const gchar *snap_name = hc_url_get(url, HCURL_SNAPORVERS);
	if (snap_name == NULL) {
		GSERRORSET(&e, ERR_MISSING_SNAPSHOT_IN_URL);
	} else {
		c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE),
				NULL, 0, &e);
		if (c != NULL) {
			e = func(c, snap_name, param);
			gs_container_free(c);
		}
	}
	return e;
}
Beispiel #25
0
void
hc_decache_reference_service(struct hc_resolver_s *r, struct hc_url_s *url,
		const gchar *srvtype)
{
	struct hashstr_s *hk;

	GRID_TRACE2("%s(%s,%s)", __FUNCTION__, hc_url_get(url, HCURL_WHOLE), srvtype);
	EXTRA_ASSERT(r != NULL);
	EXTRA_ASSERT(url != NULL);
	EXTRA_ASSERT(srvtype != NULL);

	if (r->flags & HC_RESOLVER_NOCACHE)
		return;

	hk = hashstr_printf("%s|%s|%s", srvtype,
			hc_url_get(url, HCURL_NS), hc_url_get(url, HCURL_HEXID));
	hc_resolver_forget(r, r->services.cache, hk);
	g_free(hk);
}
Beispiel #26
0
static void
wrapper(void (*cb)(void))
{
	gboolean rc = FALSE;
	GError *err = NULL;

	g_printerr("\n");
	hc_url_set(url, HCURL_REFERENCE, next_name("container"));
	hc_url_set(url, HCURL_PATH, next_name("content"));
	g_debug("ROUND with [%s] %s", hc_url_get(url, HCURL_HEXID),
			hc_url_get(url, HCURL_WHOLE));

	rc = meta2_remote_container_create(&addr, timeout, &err, hc_url_get_id(url),
			hc_url_get(url, HCURL_REFERENCE));
	CHECK_RC_ERR(rc, err, "CREATE");

	if (cb)
		cb();
}
Beispiel #27
0
gs_error_t *
hc_get_content(gs_grid_storage_t *hc, struct hc_url_s *url, const char *local_path, int force, int cache, gchar *stgpol)
{
	gs_error_t *e = NULL;
	/* download a content */
	gs_download_info_t dl_info;
	int out = 0;

	memset(&dl_info, 0x00, sizeof(dl_info));

	if(_open_destination(local_path, force, &out)) {
		GRID_DEBUG("Destination file descriptor ready fd=%d path=%s\n", out, local_path ? local_path : "<stdout>");
		/*download the content */
		dl_info.offset = 0;
		dl_info.size = 0;
		dl_info.writer = _write_to_fd;
		dl_info.user_data = &out;
		e = hc_dl_content(hc, url, &dl_info, cache, stgpol);
		if (out >= 0) {
			metautils_pclose(&out);
		}
		if (e) {
			g_printerr("Cannot download %s from %s (into %s)\n",
					hc_url_get(url, HCURL_PATH),
					hc_url_get(url, HCURL_REFERENCE),
					local_path ? local_path : "<stdout>");
		} else {
			GRID_DEBUG("Download done from %s to %s\n",
					hc_url_get(url, HCURL_PATH),
					local_path ? local_path : "<stdout>");
		}
	} else {
		gchar tmp[256];
		bzero(tmp, sizeof(tmp));
		g_snprintf(tmp, sizeof(tmp), "Failed to open the destination file descriptor to path=%s\n", local_path ? local_path : "<stdout>");
		e = g_malloc0(sizeof(gs_error_t));
		e->code = 0;
		e->msg = g_strdup(tmp);
	}

	return e;
}
Beispiel #28
0
void
hc_decache_reference(struct hc_resolver_s *r, struct hc_url_s *url)
{
	struct hashstr_s *hk;

	GRID_TRACE2("%s(%s)", __FUNCTION__, hc_url_get(url, HCURL_WHOLE));
	g_assert(r != NULL);
	g_assert(url != NULL);

	if (r->flags & HC_RESOLVER_NOCACHE)
		return;

	hk = hashstr_printf("meta0|%s", hc_url_get(url, HCURL_NSPHYS));
	hc_resolver_forget(r, r->csm0.cache, hk);
	g_free(hk);

	hk = hashstr_printf("meta1|%s|%.4s", hc_url_get(url, HCURL_NSPHYS),
			hc_url_get(url, HCURL_HEXID));
	hc_resolver_forget(r, r->csm0.cache, hk);
	g_free(hk);
}
Beispiel #29
0
static gs_error_t *
hc_upload_content(gs_grid_storage_t *hc, struct hc_url_s *url, const char *local_path,
		const char *stgpol, const char *sys_metadata, int ac, gboolean is_append)
{
	int in = -1;
	struct stat64 s;
	gs_container_t *c = NULL;
	gs_error_t *e = NULL;

	/*init the local path */
	if (-1 == stat64(local_path, &s)) {
		e = g_malloc0(sizeof(gs_error_t));
		e->code = errno;
		e->msg = g_strdup_printf("Cannot stat the local file (%s)\n", strerror(errno));
		return e;
	}
	GRID_DEBUG("Local path %s found\n", local_path);

	if (-1 == (in = open(local_path, O_RDONLY|O_LARGEFILE))) {
		e = g_malloc0(sizeof(gs_error_t));
		e->code = errno;
		e->msg = g_strdup_printf("Cannot open the local file (%s)\n", strerror(errno));
		goto end_put;
	}
	GRID_DEBUG("Local path %s found and opened\n", local_path);

	if(!(c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE), NULL, ac, &e))) {
		g_printerr("Failed to resolve and/or create meta2 entry for reference %s\n",
				hc_url_get(url, HCURL_REFERENCE));
		goto end_put;
	}

	/*upload the content */
	if (is_append) {
		if (!gs_append_content(c, hc_url_get(url, HCURL_PATH), s.st_size, _feed_from_fd, &in, &e)) {
			goto end_put;
		}
	} else {
		if (!gs_upload(c, hc_url_get(url, HCURL_PATH), s.st_size, _feed_from_fd,
				&in, NULL, sys_metadata, stgpol, &e)) {
			goto end_put;
		}
	}
	GRID_INFO("Uploaded a new version of content [%s] in container [%s]\n\n",
			hc_url_get(url, HCURL_PATH), hc_url_get(url, HCURL_REFERENCE));
	GRID_DEBUG("Content successfully uploaded!\n");

end_put:

	/** FIXME TODO XXX why not (in >= 0) or (in > -1) ? */
	if (in > 1)
		metautils_pclose(&in);

	if(NULL != c) {
		gs_container_free(c);
		c = NULL;
	}

	return e;
}
Beispiel #30
0
gs_error_t *
hc_dl_content(gs_grid_storage_t *hc, struct hc_url_s *url, gs_download_info_t *dl_info, int cache, gchar *stgpol)
{
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;

	c = gs_get_storage_container(hc, hc_url_get(url, HCURL_REFERENCE), NULL, 0, &e);
	if (c) {
		if (cache) {
			gs_download_content_by_name_full(c, hc_url_get(url, HCURL_PATH),
					hc_url_get(url, HCURL_SNAPORVERS), stgpol, dl_info, &e);
		} else {
			e = _dl_nocache(c, url, dl_info, stgpol);
		}
		gs_container_free(c);
	} else {
		g_printerr("Failed to resolve meta2 entry for reference %s\n",
				hc_url_get(url, HCURL_REFERENCE));
	}

	return e;
}