示例#1
0
gs_content_t*
gs_container_get_content_from_raw(gs_grid_storage_t *client,
		struct meta2_raw_content_s *raw, gs_error_t **gserr)
{
	gchar str_hex[STRLEN_CONTAINERID];
	struct gs_container_location_s *location;
	gs_content_t *result = NULL;

	if (!client || !raw) {
		GSERRORSET(gserr, "Invalid parameter (%p %p)", client, raw);
		return NULL;
	}

	/* Now locates the content's container */
	container_id_to_string(raw->container_id, str_hex, sizeof(str_hex));
	location = gs_locate_container_by_hexid(client, str_hex, gserr);
	if (!location) {
		GSERRORSET(gserr, "Container reference not found for CID[%s]", str_hex);
		return NULL;
	}

	/* Container found, alright ... */

	result = calloc(1, sizeof(gs_content_t));
	if (!result) {
		gs_container_location_free(location);
		GSERRORCODE(gserr, ENOMEM, "Memory allocation failure");
		return NULL;
	}

	/* Initiates the content part */
	g_strlcpy(result->info.path, raw->path, MIN(sizeof(result->info.path)-1,sizeof(raw->path)));
	result->info.size = raw->size;
	map_content_from_raw(result, raw);

	/* Initiates the container part */
	result->info.container = gs_container_init_from_location(client, location, gserr);
	if (!result->info.container) {
		gs_container_location_free(location);
		gs_content_free(result);
		GSERRORCODE(gserr, ENOMEM, "Memory allocation failure");
		return NULL;
	}

	DEBUG("Resolved container ID[%s]", location->container_hexid);
	gs_container_location_free(location);
	return result;
}
示例#2
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;
}
示例#3
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;
}