irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rsGetRescQuota.cpp
Go to the documentation of this file.
1 
4 /* See genQuery.h for a description of this API call.*/
5 
6 #include "rcMisc.h"
7 #include "getRescQuota.h"
8 #include "miscUtil.h"
9 
10 #include "objMetaOpr.hpp"
11 #include "resource.hpp"
12 #include "rsGetRescQuota.hpp"
13 #include "genQuery.h"
14 #include "rsGenQuery.hpp"
15 
16 // =-=-=-=-=-=-=-
18 
19 
20 int
24  int status = 0;
25 
27  rsComm,
28  SLAVE_RCAT,
29  ( const char* )getRescQuotaInp->zoneHint,
30  &rodsServerHost );
31 
32  if ( status < 0 ) {
33  return status;
34  }
35 
38  }
39  else {
41  rescQuota );
42  }
43 
44  return status;
45 }
46 
48  rsComm_t* rsComm,
51  int status = 0;
52 
53  genQueryOut_t* genQueryOut = NULL;
54 
55  if ( rescQuota == NULL ) {
56  return USER__NULL_INPUT_ERR;
57  }
58 
59  *rescQuota = NULL;
60 
62  rsComm,
65  &genQueryOut );
66  if ( status >= 0 ) {
67  queRescQuota( rescQuota, genQueryOut );
68  }
69 
70  freeGenQueryOut( &genQueryOut );
71 
72  return 0;
73 
74 }
75 
76 /* getQuotaByResc - get the quoto for an individual resource. The code is
77  * mostly from doTest7 of iTestGenQuery.c
78  */
79 
81  rsComm_t* rsComm,
82  char* userName,
83  char* rescName,
84  genQueryOut_t** genQueryOut ) {
85  int status;
86  genQueryInp_t genQueryInp;
87  char condition1[MAX_NAME_LEN];
88  char condition2[MAX_NAME_LEN];
89 
90  if ( genQueryOut == NULL ) {
91  return USER__NULL_INPUT_ERR;
92  }
93 
94  *genQueryOut = NULL;
95  memset( &genQueryInp, 0, sizeof( genQueryInp ) );
96 
97  genQueryInp.options = QUOTA_QUERY;
98 
99  snprintf(
100  condition1,
101  MAX_NAME_LEN, "%s",
102  userName );
103  addInxVal(
104  &genQueryInp.sqlCondInp,
106  condition1 );
107  if ( rescName != NULL && strlen( rescName ) > 0 ) {
108  snprintf(
109  condition2,
110  MAX_NAME_LEN, "%s",
111  rescName );
112  addInxVal(
113  &genQueryInp.sqlCondInp,
115  condition2 );
116  }
117 
118  genQueryInp.maxRows = MAX_SQL_ROWS;
119  status = rsGenQuery(
120  rsComm,
121  &genQueryInp,
122  genQueryOut );
123  clearGenQueryInp( &genQueryInp );
124 
125  return status;
126 }
127 
129  rescQuota_t** rescQuotaHead,
130  genQueryOut_t* genQueryOut ) {
131 
132  sqlResult_t *quotaLimit, *quotaOver, *rescName, *quotaRescId, *quotaUserId;
133  char *tmpQuotaLimit, *tmpQuotaOver, *tmpRescName, *tmpQuotaRescId,
134  *tmpQuotaUserId;
135  int i;
136  rescQuota_t *tmpRescQuota;
137 
138  if ( ( quotaLimit = getSqlResultByInx( genQueryOut, COL_QUOTA_LIMIT ) ) ==
139  NULL ) {
141  "queRescQuota: getSqlResultByInx for COL_QUOTA_LIMIT failed" );
142  return UNMATCHED_KEY_OR_INDEX;
143  }
144 
145  if ( ( quotaOver = getSqlResultByInx( genQueryOut, COL_QUOTA_OVER ) ) == NULL ) {
147  "queRescQuota: getSqlResultByInx for COL_QUOTA_OVER failed" );
148  return UNMATCHED_KEY_OR_INDEX;
149  }
150 
151  if ( ( rescName = getSqlResultByInx( genQueryOut, COL_R_RESC_NAME ) ) == NULL ) {
153  "queRescQuota: getSqlResultByInx for COL_R_RESC_NAME failed" );
154  return UNMATCHED_KEY_OR_INDEX;
155  }
156 
157  if ( ( quotaRescId = getSqlResultByInx( genQueryOut, COL_QUOTA_RESC_ID ) ) ==
158  NULL ) {
160  "queRescQuota: getSqlResultByInx for COL_QUOTA_RESC_ID failed" );
161  return UNMATCHED_KEY_OR_INDEX;
162  }
163 
164  if ( ( quotaUserId = getSqlResultByInx( genQueryOut, COL_QUOTA_USER_ID ) ) ==
165  NULL ) {
167  "queRescQuota: getSqlResultByInx for COL_QUOTA_USER_ID failed" );
168  return UNMATCHED_KEY_OR_INDEX;
169  }
170 
171  for ( i = 0; i < genQueryOut->rowCnt; i++ ) {
172  tmpQuotaLimit = &quotaLimit->value[quotaLimit->len * i];
173  tmpQuotaOver = &quotaOver->value[quotaOver->len * i];
174  tmpRescName = &rescName->value[rescName->len * i];
175  tmpQuotaRescId = &quotaRescId->value[quotaRescId->len * i];
176  tmpQuotaUserId = &quotaUserId->value[quotaUserId->len * i];
177  tmpRescQuota = ( rescQuota_t* )malloc( sizeof( rescQuota_t ) );
178  fillRescQuotaStruct( tmpRescQuota, tmpQuotaLimit, tmpQuotaOver,
179  tmpRescName, tmpQuotaRescId, tmpQuotaUserId );
180  tmpRescQuota->next = *rescQuotaHead;
181  *rescQuotaHead = tmpRescQuota;
182  }
183 
184  return 0;
185 }
186 
189  char* tmpQuotaLimit,
190  char* tmpQuotaOver,
191  char* tmpRescName,
192  char* tmpQuotaRescId,
193  char* tmpQuotaUserId ) {
194 
195  bzero( rescQuota, sizeof( rescQuota_t ) );
196 
197  rescQuota->quotaLimit = strtoll( tmpQuotaLimit, 0, 0 );
198  rescQuota->quotaOverrun = strtoll( tmpQuotaOver, 0, 0 );
199 
200  if ( strtoll( tmpQuotaRescId, 0, 0 ) > 0 ) {
201  /* quota by resource */
202  rstrcpy( rescQuota->rescName, tmpRescName, NAME_LEN );
203  }
204  else {
206  }
207 
208  rstrcpy( rescQuota->userId, tmpQuotaUserId, NAME_LEN );
209 
210  return 0;
211 }
212 
214  rsComm_t* _comm,
215  const char* _obj_path,
216  const char* _resc_name,
217  rodsLong_t _data_size ) {
218  int status = chkRescQuotaPolicy( _comm );
219  if ( status != RESC_QUOTA_ON ) {
220  return 0;
221  }
222 
223  rodsLong_t resc_id = 0;
224  irods::error ret = resc_mgr.hier_to_leaf_id(_resc_name,resc_id);
225  if ( !ret.ok() ) {
226  irods::log( PASS( ret ) );
227  return ret.code();
228  }
229 
230  rodsLong_t resc_overrun = 0;
231  ret = irods::get_resource_property<rodsLong_t>(
232  resc_id,
234  resc_overrun );
235 
236  // fetch a global quota for the user if it exists
237  getRescQuotaInp_t get_resc_quota_inp;
238  bzero(&get_resc_quota_inp,
239  sizeof( get_resc_quota_inp ) );
240  rstrcpy(
241  get_resc_quota_inp.zoneHint,
242  _obj_path,
243  MAX_NAME_LEN );
244  snprintf(
245  get_resc_quota_inp.userName,
246  NAME_LEN, "%s#%s",
247  _comm->clientUser.userName,
248  _comm->clientUser.rodsZone );
249 
250  rescQuota_t *total_quota = NULL;
252  _comm,
253  &get_resc_quota_inp,
254  &total_quota );
255  if ( status >= 0 && total_quota ) {
256  rodsLong_t compare_overrun = total_quota->quotaOverrun;
257  freeAllRescQuota(total_quota);
258  if ( compare_overrun != 0 && // disabled if 0
259  compare_overrun + resc_overrun + _data_size > 0 ) {
261  }
262  } else {
263  rodsLog(
264  LOG_DEBUG,
265  "%s rsGetRescQuota for total quota - status %d",
266  __FUNCTION__,
267  status );
268  }
269 
270  // if no global enforcement was successful try per resource
271  rstrcpy(
272  get_resc_quota_inp.rescName,
273  _resc_name,
274  NAME_LEN );
275 
276  rescQuota_t *resc_quota = NULL;
278  _comm,
279  &get_resc_quota_inp,
280  &resc_quota );
281  if( status < 0 || !resc_quota ) {
282  return status;
283  }
284 
285  rodsLong_t compare_overrun = resc_quota->quotaOverrun;
286  freeAllRescQuota(resc_quota);
287  if ( compare_overrun != 0 && // disabled if 0
288  compare_overrun + resc_overrun + _data_size > 0 ) {
290  }
291 
292  return 0;
293 
294 } // setRescQuota
295 
297  const char* _resc_hier,
298  rodsLong_t _data_size,
299  int _flags ) {
300  if( ( _flags & GLB_QUOTA ) > 0 ) {
301  GlobalQuotaOverrun += _data_size;
302  }
303 
304  if( ( _flags & RESC_QUOTA ) > 0 ) {
306  parser.set_string( _resc_hier );
307 
308  std::string root;
309  parser.first_resc( root );
310 
311  rodsLong_t resc_id = 0;
312  irods::error ret = resc_mgr.hier_to_leaf_id(root, resc_id);
313  if ( !ret.ok() ) {
314  irods::log( PASS( ret ) );
315  return ret.code();
316  }
317 
318  rodsLong_t over_run = 0;
319  ret = irods::get_resource_property<rodsLong_t>(
320  resc_id,
322  over_run );
323  // property may not be set yet so skip error
324  over_run += _data_size;
325  ret = irods::set_resource_property<rodsLong_t>(
326  root,
328  over_run );
329  if( !ret.ok() ) {
330  irods::log(PASS(ret));
331  return ret.code();
332  }
333  }
334  return 0;
335 }
336 
337 int chkRescQuotaPolicy( rsComm_t *rsComm ) {
339  ruleExecInfo_t rei;
340  initReiWithDataObjInp( &rei, rsComm, NULL );
341  int status = applyRule(
342  "acRescQuotaPolicy",
343  NULL, &rei,
344  NO_SAVE_REI );
346  free(rei.condInputData);
347  if ( status < 0 ) {
348  rodsLog(
349  LOG_ERROR,
350  "queRescQuota: acRescQuotaPolicy error status = %d",
351  status );
353  }
354  }
355  return RescQuotaPolicy;
356 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
MAX_SQL_ROWS
#define MAX_SQL_ROWS
Definition: rodsGenQuery.h:16
NULL
#define NULL
Definition: rodsDef.h:70
COL_R_RESC_NAME
#define COL_R_RESC_NAME
Definition: rodsGenQuery.h:144
rsComm_t
Definition: rcConnect.h:145
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
getRescQuotaInp::rescName
char rescName[64]
Definition: getRescQuota.h:19
getRescQuotaInp::zoneHint
char zoneHint[(1024+64)]
Definition: getRescQuota.h:21
_rsGetRescQuota
int _rsGetRescQuota(rsComm_t *rsComm, getRescQuotaInp_t *getRescQuotaInp, rescQuota_t **rescQuota)
Definition: rsGetRescQuota.cpp:47
rsGetRescQuota.hpp
rescQuota::next
struct rescQuota * next
Definition: getRescQuota.h:35
UNMATCHED_KEY_OR_INDEX
@ UNMATCHED_KEY_OR_INDEX
Definition: rodsErrorTable.h:244
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
userInfo_t::userName
char userName[64]
Definition: rodsUser.h:66
rescQuota::quotaOverrun
rodsLong_t quotaOverrun
Definition: getRescQuota.h:34
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
resc_mgr
irods::resource_manager resc_mgr
Definition: irods_resource_manager.cpp:31
updatequotaOverrun
int updatequotaOverrun(const char *_resc_hier, rodsLong_t _data_size, int _flags)
Definition: rsGetRescQuota.cpp:296
NO_SAVE_REI
#define NO_SAVE_REI
Definition: rodsDef.h:103
GenQueryInp
Definition: rodsGenQuery.h:24
irods::hierarchy_parser
Definition: irods_hierarchy_parser.hpp:14
rcMisc.h
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
queRescQuota
int queRescQuota(rescQuota_t **rescQuotaHead, genQueryOut_t *genQueryOut)
Definition: rsGetRescQuota.cpp:128
irods_resource_backport.hpp
GLOBAL_QUOTA
#define GLOBAL_QUOTA
Definition: getRescQuota.h:40
getRescQuotaInp::userName
char userName[64]
Definition: getRescQuota.h:20
COL_QUOTA_LIMIT
#define COL_QUOTA_LIMIT
Definition: rodsGenQuery.h:470
deploy_schemas_locally.parser
parser
Definition: deploy_schemas_locally.py:59
addInxVal
int addInxVal(inxValPair_t *inxValPair, int inx, const char *value)
Definition: rcMisc.cpp:921
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
getQuotaByResc
int getQuotaByResc(rsComm_t *rsComm, char *userName, char *rescName, genQueryOut_t **genQueryOut)
Definition: rsGetRescQuota.cpp:80
GenQueryInp::maxRows
int maxRows
Definition: rodsGenQuery.h:25
initReiWithDataObjInp
int initReiWithDataObjInp(ruleExecInfo_t *rei, rsComm_t *rsComm, dataObjInp_t *dataObjIn)
Definition: irods_re_structs.cpp:164
RuleExecInfo::condInputData
keyValPair_t * condInputData
Definition: irods_re_structs.hpp:34
irods::error::code
long long code() const
Definition: irods_error.cpp:194
GlobalQuotaOverrun
rodsLong_t GlobalQuotaOverrun
Definition: irods_server_globals.cpp:63
getSqlResultByInx
sqlResult_t * getSqlResultByInx(genQueryOut_t *genQueryOut, int attriInx)
Definition: rcMisc.cpp:1387
RESC_QUOTA_UNINIT
#define RESC_QUOTA_UNINIT
Definition: getRescQuota.h:9
LOG_DEBUG
#define LOG_DEBUG
Definition: rodsLog.h:23
COL_USER_NAME
#define COL_USER_NAME
Definition: rodsGenQuery.h:132
getRescQuotaInp
Definition: getRescQuota.h:18
SYS_RESC_QUOTA_EXCEEDED
@ SYS_RESC_QUOTA_EXCEEDED
Definition: rodsErrorTable.h:175
GenQueryInp::sqlCondInp
inxValPair_t sqlCondInp
Definition: rodsGenQuery.h:56
genQuery.h
rescQuota
Definition: getRescQuota.h:28
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
getRescQuota.h
RESC_QUOTA
#define RESC_QUOTA
Definition: getRescQuota.h:15
RescQuotaPolicy
int RescQuotaPolicy
Definition: irods_server_globals.cpp:64
GenQueryOut
Definition: rodsGenQuery.h:67
RESC_QUOTA_OFF
#define RESC_QUOTA_OFF
Definition: getRescQuota.h:10
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
userInfo_t::rodsZone
char rodsZone[64]
Definition: rodsUser.h:67
GenQueryOut::rowCnt
int rowCnt
Definition: rodsGenQuery.h:68
irods::log
void log(const error &)
Definition: irods_log.cpp:13
rsComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:153
rescQuota::quotaLimit
rodsLong_t quotaLimit
Definition: getRescQuota.h:33
irods::error
Definition: irods_error.hpp:23
getAndConnRcatHost
int getAndConnRcatHost(rsComm_t *rsComm, int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:26
SqlResult::value
char * value
Definition: rodsGenQuery.h:64
irods::resource_manager::hier_to_leaf_id
error hier_to_leaf_id(const std::string &, rodsLong_t &)
Definition: irods_resource_manager.cpp:1082
rodsServerHost
Definition: rodsConnect.h:62
SqlResult
Definition: rodsGenQuery.h:61
rescQuota::flags
int flags
Definition: getRescQuota.h:31
RuleExecInfo
Definition: irods_re_structs.hpp:18
applyRule
int applyRule(char *inAction, msParamArray_t *inMsParamArray, ruleExecInfo_t *rei, int reiSaveFlag)
Definition: irods_re_structs.cpp:65
setRescQuota
int setRescQuota(rsComm_t *_comm, const char *_obj_path, const char *_resc_name, rodsLong_t _data_size)
Definition: rsGetRescQuota.cpp:213
COL_QUOTA_RESC_ID
#define COL_QUOTA_RESC_ID
Definition: rodsGenQuery.h:469
resource.hpp
irods::RESOURCE_QUOTA_OVERRUN
const std::string RESOURCE_QUOTA_OVERRUN("resource_property_quota_overrun")
SqlResult::len
int len
Definition: rodsGenQuery.h:63
QUOTA_QUERY
#define QUOTA_QUERY
Definition: rodsGenQuery.h:88
SLAVE_RCAT
#define SLAVE_RCAT
Definition: rodsDef.h:86
fillRescQuotaStruct
int fillRescQuotaStruct(rescQuota_t *rescQuota, char *tmpQuotaLimit, char *tmpQuotaOver, char *tmpRescName, char *tmpQuotaRescId, char *tmpQuotaUserId)
Definition: rsGetRescQuota.cpp:187
GLB_QUOTA
#define GLB_QUOTA
Definition: getRescQuota.h:14
rescQuota::rescName
char rescName[64]
Definition: getRescQuota.h:29
COL_QUOTA_USER_ID
#define COL_QUOTA_USER_ID
Definition: rodsGenQuery.h:468
rsGenQuery.hpp
rcGetRescQuota
int rcGetRescQuota(rcComm_t *conn, getRescQuotaInp_t *getRescQuotaInp, rescQuota_t **rescQuota)
Definition: rcGetRescQuota.cpp:33
miscUtil.h
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
rescQuota::userId
char userId[64]
Definition: getRescQuota.h:30
freeGenQueryOut
int freeGenQueryOut(genQueryOut_t **genQueryOut)
Definition: rcMisc.cpp:1133
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
rsGetRescQuota
int rsGetRescQuota(rsComm_t *rsComm, getRescQuotaInp_t *getRescQuotaInp, rescQuota_t **rescQuota)
Definition: rsGetRescQuota.cpp:21
COL_QUOTA_OVER
#define COL_QUOTA_OVER
Definition: rodsGenQuery.h:471
clearKeyVal
int clearKeyVal(keyValPair_t *condInput)
Definition: rcMisc.cpp:1047
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
clearGenQueryInp
void clearGenQueryInp(void *voidInp)
Definition: rcMisc.cpp:1118
rsGenQuery
int rsGenQuery(rsComm_t *rsComm, genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut)
Definition: rsGenQuery.cpp:604
GenQueryInp::options
int options
Definition: rodsGenQuery.h:34
RESC_QUOTA_ON
#define RESC_QUOTA_ON
Definition: getRescQuota.h:11
rodsLong_t
long long rodsLong_t
Definition: rodsType.h:32
objMetaOpr.hpp
chkRescQuotaPolicy
int chkRescQuotaPolicy(rsComm_t *rsComm)
Definition: rsGetRescQuota.cpp:337
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247
freeAllRescQuota
int freeAllRescQuota(rescQuota_t *rescQuotaHead)
Definition: rcMisc.cpp:1526