]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - frsh_api/frsh_vres.c
fcb: Work on transaction support continues
[frescor/frsh.git] / frsh_api / frsh_vres.c
1 /**************************************************************************/
2 /* ---------------------------------------------------------------------- */
3 /* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                 */
4 /*                                                                        */
5 /*   Universidad de Cantabria,              SPAIN                         */
6 /*   University of York,                    UK                            */
7 /*   Scuola Superiore Sant'Anna,            ITALY                         */
8 /*   Kaiserslautern University,             GERMANY                       */
9 /*   Univ. Politécnica  Valencia,           SPAIN                        */
10 /*   Czech Technical University in Prague,  CZECH REPUBLIC                */
11 /*   ENEA                                   SWEDEN                        */
12 /*   Thales Communication S.A.              FRANCE                        */
13 /*   Visual Tools S.A.                      SPAIN                         */
14 /*   Rapita Systems Ltd                     UK                            */
15 /*   Evidence                               ITALY                         */
16 /*                                                                        */
17 /*   See http://www.frescor.org for a link to partners' websites          */
18 /*                                                                        */
19 /*          FRESCOR project (FP6/2005/IST/5-034026) is funded             */
20 /*       in part by the European Union Sixth Framework Programme          */
21 /*       The European Union is not liable of any use that may be          */
22 /*       made of this code.                                               */
23 /*                                                                        */
24 /*                                                                        */
25 /*  This file is part of FRSH (FRescor ScHeduler)                         */
26 /*                                                                        */
27 /* FRSH is free software; you can redistribute it and/or modify it        */
28 /* under terms of the GNU General Public License as published by the      */
29 /* Free Software Foundation; either version 2, or (at your option) any    */
30 /* later version.  FRSH is distributed in the hope that it will be        */
31 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
32 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
33 /* General Public License for more details. You should have received a    */
34 /* copy of the GNU General Public License along with FRSH; see file       */
35 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
36 /* Cambridge, MA 02139, USA.                                              */
37 /*                                                                        */
38 /* As a special exception, including FRSH header files in a file,         */
39 /* instantiating FRSH generics or templates, or linking other files       */
40 /* with FRSH objects to produce an executable application, does not       */
41 /* by itself cause the resulting executable application to be covered     */
42 /* by the GNU General Public License. This exception does not             */
43 /* however invalidate any other reasons why the executable file might be  */
44 /* covered by the GNU Public License.                                     */
45 /**************************************************************************/
46
47 /**
48  * @file   frsh_vres.c
49  * @author Dario Faggioli <faggioli@gandalf.sssup.it>
50  * @date   Wed Feb 20 14:53:22 2009
51  * 
52  * @brief  Core of FRSH_FORB framework
53  * 
54  */
55
56
57 #include <frsh_core.h>
58 #include <fra_generic.h>
59 #include <frsh_resources.h>
60
61 #include "frsh_forb.h"
62
63 #ifdef CONFIG_AQUOSA
64 #include <aqcpu_res.h>
65 #endif
66 #ifdef CONFIG_CPUCG
67 #include <cpucg_res.h>
68 #endif
69 #ifdef CONFIG_DISKBFQ
70 #include <diskbfq_res.h>
71 #endif
72
73 int frsh_vres_get_priority
74   (frsh_vres_id_t vres_id,
75    int *priority)
76 {
77         return FRSH_ERR_NOT_IMPLEMENTED;
78 }
79
80 int frsh_vres_get_contract
81   (const frsh_vres_id_t vres,
82    frsh_contract_t *contract)
83 {
84         if (!vres) return FRSH_ERR_BAD_ARGUMENT;
85
86         /* TODO: Reference counting */
87         *contract = vres->perceived;
88
89         return 0;
90 }
91
92 int frsh_resource_get_vres_from_label
93   (const char *contract_label,
94    const frsh_resource_type_t resource_type,
95    const frsh_resource_id_t resource_id,
96    frsh_vres_id_t *vres)
97 {
98         fres_block_resource *r;
99         fres_block_label *label;
100
101         if (!contract_label || !vres) {
102                 return FRSH_ERR_BAD_ARGUMENT;
103         }
104         r = malloc(sizeof(*r));
105         if (!r) return ENOMEM;
106         r->resource_type = resource_type;
107         r->resource_id = resource_id;
108
109         label = malloc(sizeof(*label));
110         if (!label) {
111                 free(r);
112                 return ENOMEM;
113         }
114         strncpy(label->label, contract_label, sizeof(label->label));
115         label->label[sizeof(label->label)-1] = '\0';
116
117         *vres = fres_vreses_find_label(label, r);
118         if (*vres) return FRSH_NO_ERROR;
119
120         return FRSH_ERR_CONTRACT_LABEL_UNKNOWN;
121 }
122
123 int frsh_vres_get_renegotiation_status
124   (const frsh_vres_id_t vres,
125    frsh_renegotiation_status_t *renegotiation_status)
126 {
127         return FRSH_ERR_NOT_IMPLEMENTED;
128 }
129
130 int frsh_group_get_status
131   (const frsh_group_id_t       group,
132    frsh_renegotiation_status_t *status,
133    frsh_vres_group_t           *new_vres)
134 {
135         return FRSH_ERR_NOT_IMPLEMENTED;
136 }
137
138 int frsh_vres_get_budget_and_period
139   (const frsh_vres_id_t vres,
140    frsh_rel_time_t *budget,
141    frsh_rel_time_t *period)
142 {
143         fres_block_basic *basic;
144
145         if (!vres) return FRSH_ERR_BAD_ARGUMENT;
146
147         /* TODO: Reference counting */
148         basic = fres_contract_get_basic(vres->perceived);
149         if (!basic) return FRSH_ERR_NOT_INITIALIZED;
150
151         if (budget)
152                 *budget = basic->budget;
153         if (period)
154                 *period = basic->period;
155
156         return 0;
157 }
158
159 int frsh_vres_get_usage
160   (const frsh_vres_id_t vres,
161    frsh_rel_time_t *spent)
162 {
163         if (!vres || !spent) {
164                 return FRSH_ERR_BAD_ARGUMENT;
165         }
166         if (vres->allocator->vres_get_usage) {
167                 return vres->allocator->vres_get_usage(vres, spent);
168         } else {
169                 return FRSH_ERR_NOT_IMPLEMENTED;
170         }
171 }
172
173 int frsh_vres_get_job_usage
174   (const frsh_vres_id_t vres,
175    frsh_rel_time_t *spent)
176 {
177         if (!vres || !spent) {
178                 return FRSH_ERR_BAD_ARGUMENT;
179         }
180         if (vres->allocator->vres_get_job_usage) {
181                 return vres->allocator->vres_get_job_usage(vres, spent);
182         } else {
183                 return FRSH_ERR_NOT_IMPLEMENTED;
184         }
185 }
186
187 int frsh_vres_get_remaining_budget
188   (const frsh_vres_id_t vres,
189    frsh_rel_time_t *budget)
190 {
191         if (!vres || !budget) {
192                 return FRSH_ERR_BAD_ARGUMENT;
193         }
194         if (vres->allocator->vres_get_remaining_budget) {
195                 return vres->allocator->vres_get_remaining_budget(vres, budget);
196         } else {
197                 return FRSH_ERR_NOT_IMPLEMENTED;
198         }
199 }
200