static int init_static_vars(int argc, char ** args) { GError *err; if (argc<4) { g_printerr("Failed to init the address and container_id : 4 tokens expected (IP, PORT, CONTAINER_ID, SERVICE_NAME)\r\n"); abort(); } err = NULL; if (!metacnx_init(&cnx, args[0], atoi(args[1]), &err)) { g_printerr("Failed to init address : %s\r\n", gerror_get_message(err)); abort(); } cnx.timeout.req = cnx.timeout.cnx = 5000; if (!container_id_hex2bin(args[2],strlen(args[2]),&cid,&err)) { g_printerr("Failed to read the container_id : %s\r\n", gerror_get_message(err)); abort(); } else { gchar str_cid[STRLEN_CONTAINERID]; container_id_to_string(cid,str_cid,sizeof(str_cid)); g_printerr("Using container [%s]\n", str_cid); } g_strlcpy(service_name,args[3],sizeof(service_name)); return 4; }
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; }
gs_status_t rawx_set_corrupted(gs_chunk_t *chunk, GError **err) { gchar cid_hex[66] = {'/', 0}; gchar host[128] = {0}; gint port = 0; g_assert(chunk != NULL); g_assert(err != NULL); g_clear_error(err); addr_info_get_addr(&(chunk->ci->id.addr), host, sizeof(host), (guint16*)&port); container_id_to_string(chunk->ci->id.id, cid_hex+1, sizeof(cid_hex)-1); _rawx_set_corrupted(host, port, cid_hex, err); return (*err == NULL)? GS_OK:GS_ERROR; }
static gboolean meta1_dispatch_UPDATECONTAINERS(struct gridd_reply_ctx_s *reply, struct meta1_backend_s *m1, gpointer ignored) { GError *err = NULL; GSList *list_of_cinfo = NULL, *l; (void) ignored; err = message_extract_body_encoded(reply->request, &list_of_cinfo, container_info_unmarshall); if (NULL != err) { reply->send_error(0, err); return TRUE; } if (!list_of_cinfo) reply->subject("empty"); else if (!list_of_cinfo->next) { gchar strcid[65]; container_id_to_string(CINFO(list_of_cinfo->data)->id, strcid, sizeof(strcid)); reply->subject("%s|%"G_GINT64_FORMAT, strcid, CINFO(list_of_cinfo->data)->size); } else reply->subject("%u", g_slist_length(list_of_cinfo)); for (l=list_of_cinfo; l ;l=l->next) { if (NULL != (err = _update_container_quota(m1, l->data))) { reply->send_error(0, err); break; } } if (list_of_cinfo) { g_slist_foreach(list_of_cinfo, g_free1, NULL); g_slist_free(list_of_cinfo); list_of_cinfo = NULL; } if (!err) reply->send_reply(200, "OK"); return TRUE; }
static void __out_start(struct chunk_transfer_s *ct) { gint64 header_size = 0; int dst_fd; struct evkeyval *kv; struct evkeyvalq *src; GSList *dsts_out = NULL; /* struct evbuffer */ GSList *lc = NULL; GSList *lb = NULL; struct timeval tv_read, tv_write; GSList *l = NULL; if (chunk_transfer_get_dst_status(ct) != CNX_NONE) return; GRID_DEBUG("Starting the output..."); const char *content_length = chunk_transfer_find_req_header(ct, "Content-Length"); ct->dst_size = ct->dst_size_remaining = g_ascii_strtoll(content_length, NULL, 10); if(chunk_transfer_get_target_rawx_count(ct) < 1) { GRID_ERROR("ERROR, no destination rawx..."); return; } GRID_DEBUG("ok we have targets, prepare to send data"); for(l = ct->dst_rawx; l && l->data; l = l->next) { gchar dst[128]; gchar port_str[16]; guint16 port = 0; struct bufferevent* bevent = NULL; addr_info_get_addr(&(((service_info_t*)l->data)->addr), dst, sizeof(dst), &port); bzero(port_str, sizeof(port_str)); g_snprintf(port_str, sizeof(port_str), "%d", port); GRID_DEBUG("addr extracted: %s %s", dst, port_str); dst_fd = tcpip_open(dst, port_str); GRID_DEBUG("Destination opened"); /* ***** */ bevent = bufferevent_socket_new(ct->evt_base, dst_fd, 0); GRID_DEBUG("buffer event created"); tv_write.tv_sec = 3; tv_write.tv_usec = 0; tv_read.tv_sec = 3; tv_read.tv_usec = 0; bufferevent_set_timeouts(bevent, &tv_read, &tv_write); bufferevent_setcb(bevent, __dst_cb_in, __dst_cb_out, __dst_cb_error, ct); bufferevent_disable(bevent, EV_READ|EV_WRITE); /* Write the HTTP request and the grid headers */ /* WARN: don't do prepend if you want to keep all in good order !! */ dsts_out = g_slist_append(dsts_out, bufferevent_get_output(bevent)); ct->dst_bevents = g_slist_append(ct->dst_bevents, bevent); } if(ct->dst_chunks) { GRID_DEBUG("dst_chunks filled, its ok"); } else { GRID_DEBUG("no dst_chunks defined"); } for (lc = ct->dst_chunks, lb = dsts_out; lc && lc->data && lb && lb->data; lc = lc->next, lb = lb->next) { gchar idstr[65]; bzero(idstr, sizeof(idstr)); container_id_to_string(lc->data, idstr, sizeof(idstr)); evbuffer_add_printf(lb->data, "PUT /%s HTTP/1.0\r\n", idstr); GRID_DEBUG("Sending put order"); /* Add missing headers (xattr not returned by rawx) */ evbuffer_add_printf(lb->data, "chunkid: %s\n", idstr); evbuffer_add_printf(lb->data, "chunkpos: %"G_GUINT32_FORMAT"\n", ct->source_chunk->position); evbuffer_add_printf(lb->data, "chunksize: %"G_GINT64_FORMAT"\n", ct->source_chunk->size); /* container id str */ gchar cidstr[65]; bzero(cidstr, sizeof(cidstr)); container_id_t cid; chunk_transfer_get_container_id(ct, cid); container_id_to_string(cid, cidstr, sizeof(cidstr)); evbuffer_add_printf(lb->data, "containerid: %s\n", cidstr); evbuffer_add_printf(lb->data, "contentpath: %s\n", chunk_transfer_get_content_path(ct)); evbuffer_add_printf(lb->data, "chunknb: %"G_GUINT32_FORMAT"\n", chunk_transfer_get_content_nb_chunks(ct)); evbuffer_add_printf(lb->data, "contentsize: %"G_GINT64_FORMAT"\n", chunk_transfer_get_content_size(ct)); if(ct->attrs->usr_metadata) evbuffer_add_printf(lb->data, "contentmetadata: %s\n", ct->attrs->usr_metadata); if(ct->attrs->sys_metadata) evbuffer_add_printf(lb->data, "contentmetadata-sys: %s\n", ct->attrs->sys_metadata); /* **** */ evbuffer_add_printf(lb->data, "Connection: close\r\n"); evbuffer_add_printf(lb->data, "Content-Type: application/octet-stream\r\n"); evbuffer_add_printf(lb->data, "Content-Length: %"G_GINT64_FORMAT"\r\n", ct->dst_size); } src = ct->src_req->input_headers; TAILQ_FOREACH(kv, src, next) { GRID_DEBUG("headers found : %s | %s", kv->key, kv->value); if (g_str_has_prefix(kv->key, "X-Grid-") || g_str_has_prefix(kv->key, "container") || g_str_has_prefix(kv->key, "content") || g_str_has_prefix(kv->key, "chunk")) { for(lb = dsts_out; lb && lb->data; lb = lb->next) { evbuffer_add_printf(lb->data, "%s: %s\r\n", kv->key, kv->value); } } }