void ListMgr_FreeAttrs( attr_set_t * p_set ) { int i; int mask = 1; /* Free stripe count attributes */ for ( i = 0; i < ATTR_COUNT; i++, mask <<= 1 ) { if ( ( field_infos[i].db_type == DB_STRIPE_ITEMS ) && ( p_set->attr_mask & mask ) ) { free_stripe_items( ( stripe_items_t * ) ( ( char * ) &p_set->attr_values + field_infos[i].offset ) ); } } }
int get_stripe_info(lmgr_t *p_mgr, PK_ARG_T pk, stripe_info_t *p_stripe_info, stripe_items_t *p_items) { /* stripe_count, stripe_size, pool_name, validator => 4 */ #define STRIPE_INFO_COUNT 4 char *res[STRIPE_INFO_COUNT]; result_handle_t result; int i; int rc = DB_SUCCESS; GString *req; /* retrieve basic stripe info */ req = g_string_new ("SELECT stripe_count, stripe_size, pool_name,validator FROM " STRIPE_INFO_TABLE " WHERE id="); g_string_append_printf(req, DPK, pk); rc = db_exec_sql(&p_mgr->conn, req->str, &result); if (rc) goto out; rc = db_next_record(&p_mgr->conn, &result, res, STRIPE_INFO_COUNT); if (rc == DB_END_OF_LIST) rc = DB_NOT_EXISTS; if (rc) goto res_free; for (i = 0; i < STRIPE_INFO_COUNT; i++) { DisplayLog(LVL_FULL, LISTMGR_TAG, "stripe_res[%u] = %s", i, res[i] ? res[i] : "<null>"); if (res[i] == NULL) { rc = DB_ATTR_MISSING; goto res_free; } } p_stripe_info->stripe_count = atoi(res[0]); p_stripe_info->stripe_size = atoi(res[1]); rh_strncpy(p_stripe_info->pool_name, res[2], MAX_POOL_LEN); #ifdef HAVE_LLAPI_FSWAP_LAYOUTS p_stripe_info->validator = atoi(res[3]); #endif db_result_free(&p_mgr->conn, &result); if (p_items) { /* retrieve stripe list */ g_string_printf(req, "SELECT stripe_index,ostidx,details FROM " STRIPE_ITEMS_TABLE " WHERE id=" DPK " ORDER BY stripe_index ASC", pk); rc = db_exec_sql(&p_mgr->conn, req->str, &result); if (rc) goto out; #ifndef _LUSTRE_HSM /* this is abnormal if LUSTRE/HSM feature is not present */ if (p_stripe_info->stripe_count != db_result_nb_records(&p_mgr->conn, &result)) { DisplayLog(LVL_MAJOR, LISTMGR_TAG, "Warning: the number of stripe items (%d) doesn't match stripe count (%u)! (Pk=" DPK ")", db_result_nb_records(&p_mgr->conn, &result), p_stripe_info->stripe_count, pk); } #endif p_items->count = db_result_nb_records(&p_mgr->conn, &result); if (p_items->count > 0) { /* allocate stripe array */ p_items->stripe = MemCalloc(p_items->count, sizeof(stripe_item_t)); if (!p_items->stripe) { rc = DB_NO_MEMORY; goto res_free; } /* fill stripe units */ for (i = 0; i < p_items->count; i++) { rc = db_next_record(&p_mgr->conn, &result, res, STRIPE_INFO_COUNT); if (rc) goto stripe_free; if (res[0] == NULL) { rc = DB_ATTR_MISSING; goto stripe_free; } if (i != atoi(res[0])) { DisplayLog(LVL_MAJOR, LISTMGR_TAG, "Warning: inconsistent stripe order: stripe %s returned in position %u", res[0], i); } p_items->stripe[i].ost_idx = atoi(res[1]); /* raw copy of binary buffer (last 3 fields of stripe_item_t * = address of ost_gen field) */ memcpy(&p_items->stripe[i].ost_gen, res[2], STRIPE_DETAIL_SZ); } } else p_items->stripe = NULL; /* last query result must be freed */ rc = DB_SUCCESS; goto res_free; } rc = DB_SUCCESS; /* result is already freed */ goto out; stripe_free: free_stripe_items(p_items); res_free: db_result_free(&p_mgr->conn, &result); out: g_string_free(req, TRUE); return rc; }