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;
#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;
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
{
unsigned i;
struct fcb_contract *fc;
- struct res_key key;
for (i=0; i<num; i++) {
struct fres_contract *c = contracts[i];
if (!fc)
return errno;
fcb_contracts[i] = fc;
- if (!get_res_key(c, &key)) {
- return FRSH_ERR_RESOURCE_ID_INVALID;
- }
log_contract("Negotiation request", i, c);
} else {
fc = fcb_contract_find(fcb, &c->id);
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);
}
}
for (i=0; i<num; i++) {
struct fcb_contract *fc = fcb_contracts[i];
- struct fres_contract *c = fc->requested_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;
}
/**
+ * 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
*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,
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;
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: