]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
fcb: Work on transaction support continues
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 23 Jun 2010 23:23:00 +0000 (01:23 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 23 Jun 2010 23:23:00 +0000 (01:23 +0200)
fres/cbroker/fcb.c
fres/contract/fres_error.c
fres/contract/fres_error.h

index 4aa3ec0df05afe0dccb14a8f10efa8396c03ec7a..b039ac2b7d3d4bdf9e37ef8e90bc517603bbcc9e 100644 (file)
@@ -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; i<num; i++) {
                struct fres_contract *c = contracts[i];
@@ -315,9 +325,6 @@ prepare_fcb_contracts(struct fcb *fcb, struct fcb_contract *fcb_contracts[],
                        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);
@@ -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; 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;
@@ -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:
index ec331b761d21c183376089e4dac9c20d7804155c..c66d8930fbd7d3629ab199cb81251fc57bdaced2 100644 (file)
@@ -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;
index 9c7b23470ffdaa52280d272dc732c7a3e7f1f86b..29f1430bcf02f2c4ac8d6ef232dd348017439117 100644 (file)
@@ -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);