static gboolean dump_container_properties(gs_container_t * container) { GSList *properties = NULL, *list = NULL; struct metacnx_ctx_s cnx; gchar path[1024]; int output_fd; GError *error = NULL; metacnx_clear(&cnx); if (!metacnx_init_with_addr(&cnx, &(container->meta2_addr), &error)) { PRINT_ERROR("Invalid META2 address : %s", error->message); g_clear_error(&error); return FALSE; } /* Change default timeout */ cnx.timeout.req = 10000; cnx.timeout.cnx = 10000; if (!meta2_remote_list_all_container_properties(&cnx, container->cID, &properties, &error)) { PRINT_ERROR("Failed to list container properties : %s", error->message); g_clear_error(&error); return FALSE; } metacnx_close(&cnx); metacnx_clear(&cnx); /* open container properties file */ memset(path, '\0', sizeof(path)); g_snprintf(path, sizeof(path), "%s/container.properties", base_dir); output_fd = open(path, O_EXCL | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); if (output_fd < 0) { PRINT_ERROR("Failed to open [%s] as the container properties target : %s\n", path, strerror(errno)); return FALSE; } /* Print container properties to file */ if (g_slist_length(properties)>0) { for (list = properties; list && list->data; list = list->next) { gchar *txt = g_strdup_printf("%s\n", (char*)list->data); write_to_fd(&output_fd, txt, strlen(txt)); g_free(txt); } } /*then adjust the file rights */ fchmod(output_fd, S_IRGRP | S_IRUSR | S_IWUSR); close(output_fd); g_slist_foreach(properties, gslist_free_element, g_free); g_slist_free(properties); return TRUE; }
static status_t _get_container_global_property(gs_grid_storage_t *hc, struct metacnx_ctx_s *cnx, container_id_t cid, GHashTable **ht, gs_error_t **gserr) { GSList *prop_list = NULL, *l = NULL; GError *gerr = NULL; // get all properties with current meta2 if (!meta2_remote_list_all_container_properties(cnx, cid, &prop_list, &gerr)) { GSList *m2_list = NULL; addr_info_t *addr = NULL; GSList *m2 = NULL; gchar str_addr[STRLEN_ADDRINFO]; struct metacnx_ctx_s cnxOther; gs_error_t *e = NULL; gboolean bResult = FALSE; // search all meta2 fo current contener m2_list = gs_resolve_meta2(hc, cid, &gerr); if (!m2_list) { GSERRORCAUSE(gserr, gerr, "Failed to get container admin entries, Cannot find meta2(s)"); if (gerr) g_error_free(gerr); return 0; } // test each meta2... for (m2=m2_list; m2 ;m2=m2->next) { addr = m2->data; if (addr) { addr_info_to_string(addr, str_addr, sizeof(str_addr)); DEBUG("Failed to get container admin entries -> test with next meta2 [%s]", str_addr); if (!_open_meta2_connection(&cnxOther, str_addr/*ctx->loc->m2_url[0]*/, &e)) { GSERRORCODE(gserr, e->code, "Failed to open connection to meta2 (%s)\n", str_addr); gs_error_free(e); continue; } if (!meta2_remote_list_all_container_properties(&cnxOther, cid, &prop_list, &gerr)) { _close_meta2_connection(&cnxOther); GSERRORCAUSE(gserr, gerr, "Failed to get container admin entries: %s\n",str_addr); continue; } else { _close_meta2_connection(&cnxOther); // no error bResult = TRUE; break; } } } if (m2_list) { g_slist_foreach(m2_list, addr_info_gclean, NULL); g_slist_free(m2_list); } if (gerr) g_error_free(gerr); if (bResult == FALSE) return 0; } // here: reading properties ok *ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); for (l = prop_list; l && l->data; l = l->next) { gchar *tmp = l->data; gchar **tok = g_strsplit(tmp, "=", 2); if (tok[0] && tok[1]) g_hash_table_insert(*ht, g_strdup(tok[0]), g_strdup(tok[1])); g_strfreev(tok); } g_slist_free_full(prop_list, g_free); /* Ensure we have some mandatory properties */ if(!g_hash_table_lookup(*ht, M2V2_ADMIN_STORAGE_POLICY)) g_hash_table_insert(*ht, g_strdup(M2V2_ADMIN_STORAGE_POLICY), g_strdup("namespace default")); if(!g_hash_table_lookup(*ht, M2V2_ADMIN_VERSIONING_POLICY)) g_hash_table_insert(*ht, g_strdup(M2V2_ADMIN_VERSIONING_POLICY), g_strdup("namespace default")); if(!g_hash_table_lookup(*ht, M2V2_ADMIN_QUOTA)) g_hash_table_insert(*ht, g_strdup(M2V2_ADMIN_QUOTA), g_strdup("namespace default")); return 1; }