From 06c73ab845b0dcf1fa73a0a0c770d212aee9ed7c Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Thu, 24 Jun 2010 01:23:00 +0200 Subject: [PATCH] fcb: Work on transaction support continues --- fres/cbroker/fcb.c | 83 ++++++++++++++++++++++++++++---------- fres/contract/fres_error.c | 1 + fres/contract/fres_error.h | 1 + 3 files changed, 64 insertions(+), 21 deletions(-) diff --git a/fres/cbroker/fcb.c b/fres/cbroker/fcb.c index 4aa3ec0..b039ac2 100644 --- a/fres/cbroker/fcb.c +++ b/fres/cbroker/fcb.c @@ -138,7 +138,8 @@ struct fcb { gavl_cust_root_field_t contracts; /**< Contracts negotiated by this FCB */ }; -/** List of contracts to be reserved during spare capacity rebalancing */ +/** List of contracts to be newly reserved or changed during spare + * capacity rebalancing */ struct reservation_list { ul_list_head_t fcb_contracts; unsigned length; @@ -268,7 +269,7 @@ GAVL_CUST_NODE_INT_IMP(fcb_contract /* cust_prefix */, \ #define o2fcb(o) (struct fcb*)forb_instance_data(o) -struct res_key* +static struct res_key* get_res_key(const struct fres_contract *contract, struct res_key *key) { fres_block_resource *block_res; @@ -284,6 +285,16 @@ get_res_key(const struct fres_contract *contract, struct res_key *key) return key; } +static struct res_key* +get_fc_res_key(const struct fcb_contract *fc, struct res_key *key) +{ + if (fc->user_contract) + get_res_key(fc->user_contract, key); + else + get_res_key(fc->requested_contract, key); + return key; +} + /** * Fills in an array of fcb_contracts according to requests submited * by an application through negotiate_contracts() or @@ -303,7 +314,6 @@ prepare_fcb_contracts(struct fcb *fcb, struct fcb_contract *fcb_contracts[], { unsigned i; struct fcb_contract *fc; - struct res_key key; for (i=0; iid); @@ -330,13 +337,9 @@ prepare_fcb_contracts(struct fcb *fcb, struct fcb_contract *fcb_contracts[], fcb_contracts[i] = fc; if (fres_contract_get_num_blocks(c) == 0) { /* Cancelation */ - get_res_key(fc->user_contract, &key); log_contract("Cancelation request", i, fc->user_contract); } else { /* Renegotiation */ - if (!get_res_key(c, &key)) { - return FRSH_ERR_RESOURCE_ID_INVALID; - } log_contract("Renegotiation request", i, fc->user_contract); } } @@ -368,18 +371,10 @@ check_and_setup_resource(struct fcb *fcb, struct fcb_contract *fcb_contracts[], for (i=0; irequested_contract; - if (fres_contract_get_num_blocks(c) == 0) { - /* Cancelation */ - get_res_key(fc->user_contract, &key); - log_contract("Cancelation request", i, fc->user_contract); - } else { - /* (Re)Negotiation */ - if (!get_res_key(c, &key)) { - return FRSH_ERR_RESOURCE_ID_INVALID; - } - } + if (!get_fc_res_key(fc, &key)) + return FRSH_ERR_RESOURCE_ID_INVALID; + /* Check that all contracts are for the same resource */ if (i==0) { key2 = key; @@ -410,6 +405,10 @@ check_and_setup_resource(struct fcb *fcb, struct fcb_contract *fcb_contracts[], } /** + * Prepares a list of contracts to pass to resource manager for (re)reserving. + * + * @todo Needs to be changed for compatibility with transactions. + * * @param resource Resource for which to rebalance capacity and negotiate new contracts * @param fcb_contract New requests to negotiate * @param num The number of elements in @a fcb_contract @@ -948,6 +947,41 @@ void get_resources(fres_contract_broker obj, fres_resource_seq** resources, CORB *resources = seq; } +static bool +transaction_has_spare_capacity(const fres_transaction_t* transaction) +{ + struct fres_contract **c; + forb_sequence_foreach(&transaction->contracts, c) + if (fres_contract_get_spare_capacity(*c)) + return true; + return false; +} + +static int +transaction_get_resources(struct fcb *fcb, struct fcb_contract *fc[], + int num, struct resource **resources[]) +{ + int i, j, r, alloc; + struct resource **res; + struct resource *resource; + struct res_key key; + + alloc = 10; + res = malloc(alloc*sizeof(*res)); + if (!res) + return errno; + res[0] = NULL; + for (r = 0, i = 0; i < num; i++) { + get_fc_res_key(fc[i], &key); + resource = fcb_resource_find(fcb, &key); + /* TODO: Check whether to use GSA for resources. */ + } + res[r] = NULL; + return 0; +} + + + CORBA_long negotiate_transaction(fres_contract_broker _obj, const fres_transaction_t* transaction, @@ -959,6 +993,11 @@ negotiate_transaction(fres_contract_broker _obj, int num = contracts->_length; int ret; + if (transaction_has_spare_capacity(transaction)) { + ret = FRES_ERR_SPARE_CAPACITY_NOT_SUPPORTED; + goto err; + } + fcb_contracts = malloc(sizeof(*fcb_contracts)*num); if (!fcb_contracts) { ret = errno; @@ -970,6 +1009,8 @@ negotiate_transaction(fres_contract_broker _obj, contracts->_buffer, num); if (ret) goto err_free_fcb_contracts; + + //ret = transaction_get_resources(fcb_contracts, num, &resources); return FRSH_ERR_NOT_IMPLEMENTED; err_free_fcb_contracts: diff --git a/fres/contract/fres_error.c b/fres/contract/fres_error.c index ec331b7..c66d893 100644 --- a/fres/contract/fres_error.c +++ b/fres/contract/fres_error.c @@ -126,6 +126,7 @@ int fres_strerror (int error, char *message, size_t size) MSG(ALLOCATOR_ALREADY_REGISTERED); MSG(VRES_ALREADY_ALLOCATED); MSG(VRES_PART_OF_TRANSACTION); + MSG(SPARE_CAPACITY_NOT_SUPPORTED); } if (s == NULL) return FRSH_ERR_BAD_ARGUMENT; diff --git a/fres/contract/fres_error.h b/fres/contract/fres_error.h index 9c7b234..29f1430 100644 --- a/fres/contract/fres_error.h +++ b/fres/contract/fres_error.h @@ -95,6 +95,7 @@ enum fres_error { FRES_ERR_ALLOCATOR_ALREADY_REGISTERED, FRES_ERR_VRES_ALREADY_ALLOCATED, FRES_ERR_VRES_PART_OF_TRANSACTION, + FRES_ERR_SPARE_CAPACITY_NOT_SUPPORTED, }; int fres_strerror (int error, char *message, size_t size); -- 2.39.2