00001
00002
00003
00004
00005 #include "resource.h"
00006 #include "genQuery.h"
00007 #include "rodsClient.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 int
00019 getRescInfo (rsComm_t *rsComm, char *defaultResc, keyValPair_t *condInput,
00020 rescGrpInfo_t **rescGrpInfo)
00021 {
00022 char *rescName;
00023 int status;
00024
00025 if ((rescName = getValByKey (condInput, BACKUP_RESC_NAME_KW)) == NULL &&
00026 (rescName = getValByKey (condInput, DEST_RESC_NAME_KW)) == NULL &&
00027 (rescName = getValByKey (condInput, DEF_RESC_NAME_KW)) == NULL &&
00028 (rescName = getValByKey (condInput, RESC_NAME_KW)) == NULL &&
00029 ((rescName = defaultResc) == NULL || strcmp (defaultResc, "null") == 0)) {
00030 return (USER_NO_RESC_INPUT_ERR);
00031 }
00032 status = _getRescInfo (rsComm, rescName, rescGrpInfo);
00033
00034 return (status);
00035 }
00036
00037
00038
00039
00040
00041
00042
00043
00044 int
00045 _getRescInfo (rsComm_t *rsComm, char *rescGroupName,
00046 rescGrpInfo_t **rescGrpInfo)
00047 {
00048 int status;
00049
00050 *rescGrpInfo = NULL;
00051
00052
00053
00054 status = resolveAndQueResc (rescGroupName, NULL, rescGrpInfo);
00055 if (status >= 0 || status == SYS_RESC_IS_DOWN) {
00056 return (status);
00057 }
00058
00059
00060 status = resolveRescGrp (rsComm, rescGroupName, rescGrpInfo);
00061
00062 return (status);
00063 }
00064
00065
00066
00067
00068
00069 int
00070 getRescStatus (rsComm_t *rsComm, char *inpRescName, keyValPair_t *condInput)
00071 {
00072 char *rescName;
00073 int status;
00074 rescGrpInfo_t *rescGrpInfo = NULL;
00075
00076 if (inpRescName == NULL) {
00077 if ((rescName = getValByKey (condInput, BACKUP_RESC_NAME_KW)) == NULL &&
00078 (rescName = getValByKey (condInput, DEST_RESC_NAME_KW)) == NULL &&
00079 (rescName = getValByKey (condInput, DEF_RESC_NAME_KW)) == NULL) {
00080 return (INT_RESC_STATUS_DOWN);
00081 }
00082 } else {
00083 rescName = inpRescName;
00084 }
00085 status = _getRescInfo (rsComm, rescName, &rescGrpInfo);
00086
00087 freeAllRescGrpInfo (rescGrpInfo);
00088
00089 if (status < 0) {
00090 return INT_RESC_STATUS_DOWN;
00091 } else {
00092 return INT_RESC_STATUS_UP;
00093 }
00094 }
00095
00096
00097
00098
00099
00100
00101 int
00102 resolveRescGrp (rsComm_t *rsComm, char *rescGroupName,
00103 rescGrpInfo_t **rescGrpInfo)
00104 {
00105 rescGrpInfo_t *tmpRescGrpInfo;
00106 int status;
00107
00108 if ((status = initRescGrp (rsComm)) < 0) return status;
00109
00110
00111
00112 tmpRescGrpInfo = CachedRescGrpInfo;
00113
00114 while (tmpRescGrpInfo != NULL) {
00115 if (strcmp (rescGroupName, tmpRescGrpInfo->rescGroupName)
00116 == 0) {
00117 replRescGrpInfo (tmpRescGrpInfo, rescGrpInfo);
00118
00119 return (0);
00120 }
00121 tmpRescGrpInfo = tmpRescGrpInfo->cacheNext;
00122 }
00123
00124 return CAT_NO_ROWS_FOUND;
00125 }
00126
00127
00128
00129
00130
00131 int
00132 replRescGrpInfo (rescGrpInfo_t *srcRescGrpInfo, rescGrpInfo_t **destRescGrpInfo)
00133 {
00134 rescGrpInfo_t *tmpSrcRescGrpInfo, *tmpDestRescGrpInfo,
00135 *lastDestRescGrpInfo;
00136
00137 *destRescGrpInfo = lastDestRescGrpInfo = NULL;
00138
00139 tmpSrcRescGrpInfo = srcRescGrpInfo;
00140 while (tmpSrcRescGrpInfo != NULL) {
00141 tmpDestRescGrpInfo = (rescGrpInfo_t *) malloc (sizeof (rescGrpInfo_t));
00142 memset (tmpDestRescGrpInfo, 0, sizeof (rescGrpInfo_t));
00143 tmpDestRescGrpInfo->status = tmpSrcRescGrpInfo->status;
00144 tmpDestRescGrpInfo->rescInfo = tmpSrcRescGrpInfo->rescInfo;
00145 rstrcpy (tmpDestRescGrpInfo->rescGroupName,
00146 tmpSrcRescGrpInfo->rescGroupName, NAME_LEN);
00147 if (*destRescGrpInfo == NULL) {
00148 *destRescGrpInfo = tmpDestRescGrpInfo;
00149 } else {
00150 lastDestRescGrpInfo->next = tmpDestRescGrpInfo;
00151 }
00152 lastDestRescGrpInfo = tmpDestRescGrpInfo;
00153 tmpSrcRescGrpInfo = tmpSrcRescGrpInfo->next;
00154 }
00155
00156 return (0);
00157 }
00158 #if 0 // JMC - UNUSED
00159
00160
00161
00162
00163
00164 int
00165 queryRescInRescGrp (rsComm_t *rsComm, char *rescGroupName,
00166 genQueryOut_t **genQueryOut)
00167 {
00168 genQueryInp_t genQueryInp;
00169 char tmpStr[NAME_LEN];
00170 int status;
00171
00172 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00173
00174 snprintf (tmpStr, NAME_LEN, "='%s'", rescGroupName);
00175 addInxVal (&genQueryInp.sqlCondInp, COL_RESC_GROUP_NAME, tmpStr);
00176 addInxIval (&genQueryInp.selectInp, COL_R_RESC_NAME, 1);
00177
00178 genQueryInp.maxRows = MAX_SQL_ROWS;
00179
00180 status = rsGenQuery (rsComm, &genQueryInp, genQueryOut);
00181
00182 clearGenQueryInp (&genQueryInp);
00183
00184 return (status);
00185
00186 }
00187 #endif // JMC - UNUSED
00188
00189
00190
00191
00192
00193 int
00194 resolveAndQueResc (char *rescName, char *rescGroupName,
00195 rescGrpInfo_t **rescGrpInfo)
00196 {
00197 rescInfo_t *myRescInfo;
00198 int status;
00199
00200 status = resolveResc (rescName, &myRescInfo);
00201
00202 if (status < 0) {
00203 return (status);
00204 } else if (myRescInfo->rescStatus == INT_RESC_STATUS_DOWN) {
00205 return SYS_RESC_IS_DOWN;
00206 } else {
00207 queResc (myRescInfo, rescGroupName, rescGrpInfo, BY_TYPE_FLAG);
00208 return (0);
00209 }
00210 }
00211
00212
00213
00214
00215
00216 int
00217 resolveResc (char *rescName, rescInfo_t **rescInfo)
00218 {
00219 rescInfo_t *myRescInfo;
00220 rescGrpInfo_t *tmpRescGrpInfo;
00221
00222
00223 *rescInfo = NULL;
00224
00225
00226
00227 tmpRescGrpInfo = RescGrpInfo;
00228
00229 while (tmpRescGrpInfo != NULL) {
00230 myRescInfo = tmpRescGrpInfo->rescInfo;
00231 if (strcmp (rescName, myRescInfo->rescName) == 0) {
00232 *rescInfo = myRescInfo;
00233 return (0);
00234 }
00235 tmpRescGrpInfo = tmpRescGrpInfo->next;
00236 }
00237
00238 #if 0 // JMC - backport 4632
00239 if (strcmp (rescName, BUNDLE_RESC) == 0) {
00240
00241 rescInfo_t *myRescInfo;
00242 myRescInfo = ( rescInfo_t* )malloc (sizeof (rescInfo_t));
00243 memset (myRescInfo, 0, sizeof (rescInfo_t));
00244 myRescInfo->rodsServerHost = ServerHostHead;
00245 rstrcpy (myRescInfo->zoneName, ZoneInfoHead->zoneName, NAME_LEN);
00246 rstrcpy (myRescInfo->rescName, BUNDLE_RESC, NAME_LEN);
00247 rstrcpy (myRescInfo->rescLoc, "localhost", NAME_LEN);
00248 rstrcpy (myRescInfo->rescType, "unix file system", NAME_LEN);
00249 myRescInfo->rescTypeInx = getRescTypeInx (myRescInfo->rescType);
00250 rstrcpy (myRescInfo->rescClass, "bundle", NAME_LEN);
00251 myRescInfo->rescClassInx = getRescClassInx (myRescInfo->rescClass);
00252 rstrcpy (myRescInfo->rescVaultPath, "/bundle", MAX_NAME_LEN);
00253 myRescInfo->quotaLimit = RESC_QUOTA_UNINIT;
00254 queResc (myRescInfo, NULL, &RescGrpInfo, BOTTOM_FLAG);
00255 *rescInfo = myRescInfo;
00256 return 0;
00257 }
00258 #endif
00259 rodsLog (LOG_DEBUG1,
00260 "resolveResc: resource %s not configured in RCAT", rescName);
00261 return (SYS_INVALID_RESC_INPUT);
00262 }
00263
00264 #if 0
00265
00266
00267
00268 int
00269 getNumResc (rescGrpInfo_t *rescGrpInfo)
00270 {
00271 rescGrpInfo_t *tmpRescGrpInfo;
00272 int numResc = 0;
00273
00274 tmpRescGrpInfo = rescGrpInfo;
00275 while (tmpRescGrpInfo != NULL) {
00276 numResc++;
00277 tmpRescGrpInfo = tmpRescGrpInfo->next;
00278 }
00279 return (numResc);
00280 }
00281 #endif
00282
00283
00284
00285
00286
00287
00288
00289 int
00290 sortResc (rsComm_t *rsComm, rescGrpInfo_t **rescGrpInfo,
00291 char *sortScheme)
00292 {
00293 int numResc;
00294
00295 if (sortScheme == NULL) {
00296 return (0);
00297 }
00298
00299 if (rescGrpInfo == NULL || *rescGrpInfo == NULL) {
00300 return (0);
00301 }
00302
00303 numResc = getRescCnt (*rescGrpInfo);
00304
00305 if (numResc <= 1) {
00306 return (0);
00307 }
00308
00309 if (sortScheme == NULL) {
00310 return (0);
00311 }
00312
00313 if (strcmp (sortScheme, "random") == 0) {
00314 sortRescRandom (rescGrpInfo);
00315 } else if (strcmp (sortScheme, "byRescClass") == 0) {
00316 sortRescByType (rescGrpInfo);
00317 } else if (strcmp (sortScheme, "byLoad") == 0) {
00318 sortRescByLoad (rsComm, rescGrpInfo);
00319 } else {
00320 rodsLog (LOG_ERROR,
00321 "sortResc: unknown sortScheme %s", sortScheme);
00322 }
00323
00324 return (0);
00325 }
00326
00327
00328
00329
00330
00331 int
00332 sortRescRandom (rescGrpInfo_t **rescGrpInfo)
00333 {
00334 int *randomArray;
00335 int numResc;
00336 int i, j, status;
00337 rescGrpInfo_t *tmpRescGrpInfo;
00338 rescInfo_t **rescInfoArray;
00339
00340
00341 tmpRescGrpInfo = *rescGrpInfo;
00342 numResc = getRescCnt (tmpRescGrpInfo);
00343
00344 if (numResc <= 1) {
00345 return (0);
00346 }
00347 if ((status = getRandomArray (&randomArray, numResc)) < 0) return status;
00348 rescInfoArray = ( rescInfo_t** )malloc (numResc * sizeof (rescInfo_t *));
00349 for (i = 0; i < numResc; i++) {
00350 j = randomArray[i] - 1;
00351 rescInfoArray[j] = tmpRescGrpInfo->rescInfo;
00352 tmpRescGrpInfo = tmpRescGrpInfo->next;
00353 }
00354 tmpRescGrpInfo = *rescGrpInfo;
00355 for (i = 0; i < numResc; i++) {
00356 tmpRescGrpInfo->rescInfo = rescInfoArray[i];
00357 tmpRescGrpInfo = tmpRescGrpInfo->next;
00358 }
00359 free (rescInfoArray);
00360 free (randomArray);
00361 return 0;
00362 }
00363
00364
00365
00366
00367
00368 int
00369 sortRescByType (rescGrpInfo_t **rescGrpInfo)
00370 {
00371 rescGrpInfo_t *tmpRescGrpInfo, *tmp1RescGrpInfo;
00372 rescInfo_t *tmpRescInfo, *tmp1RescInfo;
00373
00374 tmpRescGrpInfo = *rescGrpInfo;
00375
00376
00377
00378 while (tmpRescGrpInfo != NULL) {
00379 tmpRescInfo = tmpRescGrpInfo->rescInfo;
00380 if (RescClass[tmpRescInfo->rescClassInx].classType == CACHE_CL) {
00381
00382 tmp1RescGrpInfo = *rescGrpInfo;
00383 while (tmp1RescGrpInfo != NULL) {
00384 if (tmp1RescGrpInfo == tmpRescGrpInfo) break;
00385 tmp1RescInfo = tmp1RescGrpInfo->rescInfo;
00386 if (RescClass[tmp1RescInfo->rescClassInx].classType > CACHE_CL) {
00387 tmpRescGrpInfo->rescInfo = tmp1RescInfo;
00388 tmp1RescGrpInfo->rescInfo = tmpRescInfo;
00389 break;
00390 }
00391 tmp1RescGrpInfo = tmp1RescGrpInfo->next;
00392 }
00393 }
00394 tmpRescGrpInfo = tmpRescGrpInfo->next;
00395 }
00396
00397
00398
00399 while (tmpRescGrpInfo != NULL) {
00400 tmpRescInfo = tmpRescGrpInfo->rescInfo;
00401 if (RescClass[tmpRescInfo->rescClassInx].classType == ARCHIVAL_CL) {
00402
00403 tmp1RescGrpInfo = *rescGrpInfo;
00404 while (tmp1RescGrpInfo != NULL) {
00405 if (tmp1RescGrpInfo == tmpRescGrpInfo) break;
00406 tmp1RescInfo = tmp1RescGrpInfo->rescInfo;
00407 if (RescClass[tmp1RescInfo->rescClassInx].classType >
00408 ARCHIVAL_CL) {
00409 tmpRescGrpInfo->rescInfo = tmp1RescInfo;
00410 tmp1RescGrpInfo->rescInfo = tmpRescInfo;
00411 break;
00412 }
00413 tmp1RescGrpInfo = tmp1RescGrpInfo->next;
00414 }
00415 }
00416 tmpRescGrpInfo = tmpRescGrpInfo->next;
00417 }
00418
00419 return 0;
00420 }
00421
00422
00423
00424
00425
00426 int
00427 sortRescByLoad (rsComm_t *rsComm, rescGrpInfo_t **rescGrpInfo)
00428 {
00429 int i, j, loadmin, loadList[MAX_NSERVERS], nresc, status,
00430 timeList[MAX_NSERVERS];
00431 char rescList[MAX_NSERVERS][MAX_NAME_LEN], *tResult;
00432 rescGrpInfo_t *tmpRescGrpInfo, *tmp1RescGrpInfo;
00433 rescInfo_t *tmpRescInfo;
00434 genQueryInp_t genQueryInp;
00435 genQueryOut_t *genQueryOut = NULL;
00436 time_t timenow;
00437
00438
00439
00440 memset(&genQueryInp, 0, sizeof (genQueryInp));
00441 addInxIval(&genQueryInp.selectInp, COL_SLD_RESC_NAME, 1);
00442 addInxIval(&genQueryInp.selectInp, COL_SLD_LOAD_FACTOR, 1);
00443 addInxIval(&genQueryInp.selectInp, COL_SLD_CREATE_TIME, SELECT_MAX);
00444
00445 genQueryInp.maxRows = MAX_SQL_ROWS * 10;
00446 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00447 if ( status == 0 && NULL != genQueryOut) {
00448 nresc = genQueryOut->rowCnt;
00449 for (i=0; i<genQueryOut->attriCnt; i++) {
00450 for (j=0; j<nresc; j++) {
00451 tResult = genQueryOut->sqlResult[i].value;
00452 tResult += j*genQueryOut->sqlResult[i].len;
00453 switch (i) {
00454 case 0:
00455 rstrcpy(rescList[j], tResult,
00456 genQueryOut->sqlResult[i].len);
00457 break;
00458 case 1:
00459 loadList[j] = atoi(tResult);
00460 break;
00461 case 2:
00462 timeList[j] = atoi(tResult);
00463 break;
00464 }
00465 }
00466 }
00467 } else {
00468 return (0);
00469 }
00470 clearGenQueryInp(&genQueryInp);
00471 freeGenQueryOut(&genQueryOut);
00472
00473
00474
00475 tmpRescGrpInfo = *rescGrpInfo;
00476 tmpRescInfo = tmpRescGrpInfo->rescInfo;
00477 tmp1RescGrpInfo = tmpRescGrpInfo;
00478 loadmin = 100;
00479
00480
00481 (void) time(&timenow);
00482 while (tmpRescGrpInfo != NULL) {
00483 for (i=0; i<nresc; i++) {
00484 if (strcmp(rescList[i], tmpRescGrpInfo->rescInfo->rescName) == 0) {
00485 if ( loadList[i] >= 0 && loadmin > loadList[i] &&
00486 (timenow - timeList[i]) < MAX_ELAPSE_TIME ) {
00487 loadmin = loadList[i];
00488 tmpRescInfo = tmpRescGrpInfo->rescInfo;
00489 tmp1RescGrpInfo = tmpRescGrpInfo;
00490 }
00491 }
00492 }
00493 tmpRescGrpInfo = tmpRescGrpInfo->next;
00494 }
00495
00496 tmp1RescGrpInfo->rescInfo = (*rescGrpInfo)->rescInfo;
00497 (*rescGrpInfo)->rescInfo = tmpRescInfo;
00498
00499 return 0;
00500 }
00501
00502
00503 int
00504 sortRescByLocation (rescGrpInfo_t **rescGrpInfo)
00505 {
00506 rescGrpInfo_t *tmpRescGrpInfo, *tmp1RescGrpInfo;
00507 rescInfo_t *tmpRescInfo, *tmp1RescInfo;
00508
00509 tmpRescGrpInfo = *rescGrpInfo;
00510
00511
00512
00513 while (tmpRescGrpInfo != NULL) {
00514 int tmpClass, tmp1Class;
00515 tmpRescInfo = tmpRescGrpInfo->rescInfo;
00516 if (isLocalHost (tmpRescInfo->rescLoc)) {
00517 tmpClass = RescClass[tmpRescInfo->rescClassInx].classType;
00518
00519 tmp1RescGrpInfo = *rescGrpInfo;
00520 while (tmp1RescGrpInfo != NULL) {
00521 if (tmp1RescGrpInfo == tmpRescGrpInfo) break;
00522 tmp1RescInfo = tmp1RescGrpInfo->rescInfo;
00523 tmp1Class = RescClass[tmp1RescInfo->rescClassInx].classType;
00524 if (tmp1Class > tmpClass ||
00525 (tmp1Class == tmpClass &&
00526 isLocalHost (tmp1RescInfo->rescLoc) == 0)) {
00527 tmpRescGrpInfo->rescInfo = tmp1RescInfo;
00528 tmp1RescGrpInfo->rescInfo = tmpRescInfo;
00529 break;
00530 }
00531 tmp1RescGrpInfo = tmp1RescGrpInfo->next;
00532 }
00533 }
00534 tmpRescGrpInfo = tmpRescGrpInfo->next;
00535 }
00536
00537 return 0;
00538 }
00539
00540
00541
00542
00543 int
00544 getRescClass (rescInfo_t *rescInfo)
00545 {
00546 int classType;
00547
00548 if (rescInfo == NULL) return USER__NULL_INPUT_ERR;
00549
00550 classType = RescClass[rescInfo->rescClassInx].classType;
00551
00552 return classType;
00553 }
00554
00555
00556
00557
00558
00559
00560 int
00561 getRescGrpClass (rescGrpInfo_t *rescGrpInfo, rescInfo_t **outRescInfo)
00562 {
00563 rescInfo_t *tmpRescInfo;
00564 rescGrpInfo_t *tmpRescGrpInfo = rescGrpInfo;
00565
00566 while (tmpRescGrpInfo != NULL) {
00567 tmpRescInfo = tmpRescGrpInfo->rescInfo;
00568 if (getRescClass (tmpRescInfo) == COMPOUND_CL) {
00569 *outRescInfo = tmpRescInfo;
00570 return COMPOUND_CL;
00571 }
00572 tmpRescGrpInfo = tmpRescGrpInfo->next;
00573 }
00574 *outRescInfo = NULL;
00575
00576 return (getRescClass(rescGrpInfo->rescInfo));
00577 }
00578 #if 0 // JMC - UNUSED
00579
00580
00581
00582
00583 int
00584 compareRescAddr (rescInfo_t *srcRescInfo, rescInfo_t *destRescInfo)
00585 {
00586 rodsHostAddr_t srcAddr;
00587 rodsHostAddr_t destAddr;
00588 rodsServerHost_t *srcServerHost = NULL;
00589 rodsServerHost_t *destServerHost = NULL;
00590
00591 bzero (&srcAddr, sizeof (srcAddr));
00592 bzero (&destAddr, sizeof (destAddr));
00593
00594 rstrcpy (srcAddr.hostAddr, srcRescInfo->rescLoc, NAME_LEN);
00595 rstrcpy (destAddr.hostAddr, destRescInfo->rescLoc, NAME_LEN);
00596
00597 resolveHost (&srcAddr, &srcServerHost);
00598 resolveHost (&destAddr, &destServerHost);
00599
00600 if (srcServerHost == destServerHost)
00601 return 1;
00602 else
00603 return 0;
00604 }
00605 #endif // JMC - UNUSED
00606
00607
00608
00609
00610
00611 int
00612 getCacheRescInGrp (rsComm_t *rsComm, char *rescGroupName,
00613 rescInfo_t *memberRescInfo, rescInfo_t **outCacheResc)
00614 {
00615 int status;
00616 rescGrpInfo_t *myRescGrpInfo = NULL;
00617 rescGrpInfo_t *tmpRescGrpInfo;
00618
00619 *outCacheResc = NULL;
00620
00621 if (rescGroupName == NULL || strlen (rescGroupName) == 0) {
00622
00623 if (memberRescInfo == NULL) {
00624 rodsLog (LOG_ERROR,
00625 "getCacheRescInGrp: no rescGroupName input");
00626 return SYS_NO_CACHE_RESC_IN_GRP;
00627 }
00628
00629
00630 status = getRescGrpOfResc (rsComm, memberRescInfo, &myRescGrpInfo);
00631 if (status < 0 || NULL == myRescGrpInfo ) {
00632 rodsLog (LOG_NOTICE,
00633 "getCacheRescInGrp:getRescGrpOfResc err for %s. stat=%d",
00634 memberRescInfo->rescName, status);
00635 return status;
00636 } else if (rescGroupName != NULL) {
00637 rstrcpy (rescGroupName, myRescGrpInfo->rescGroupName, NAME_LEN);
00638 }
00639 } else {
00640 status = resolveRescGrp (rsComm, rescGroupName, &myRescGrpInfo);
00641 if (status < 0) return status;
00642 }
00643 tmpRescGrpInfo = myRescGrpInfo;
00644 while (tmpRescGrpInfo != NULL) {
00645 rescInfo_t *tmpRescInfo;
00646 tmpRescInfo = tmpRescGrpInfo->rescInfo;
00647 if (RescClass[tmpRescInfo->rescClassInx].classType == CACHE_CL) {
00648 *outCacheResc = tmpRescInfo;
00649 freeAllRescGrpInfo (myRescGrpInfo);
00650 return 0;
00651 }
00652 tmpRescGrpInfo = tmpRescGrpInfo->next;
00653 }
00654 freeAllRescGrpInfo (myRescGrpInfo);
00655 return SYS_NO_CACHE_RESC_IN_GRP;
00656 }
00657
00658 int
00659 getRescInGrpByClass (rsComm_t *rsComm, char *rescGroupName,
00660 int rescClass, rescInfo_t **outCacheResc, rescGrpInfo_t **outRescGrp)
00661 {
00662 int status;
00663 rescGrpInfo_t *myRescGrpInfo = NULL;
00664 rescGrpInfo_t *tmpRescGrpInfo;
00665
00666 *outCacheResc = NULL;
00667
00668 if (rescGroupName == NULL || strlen (rescGroupName) == 0) {
00669 rodsLog (LOG_NOTICE,
00670 "getRescInGrpByClass: NULL rescGroupName input");
00671 return USER__NULL_INPUT_ERR;
00672 }
00673 status = resolveRescGrp (rsComm, rescGroupName, &myRescGrpInfo);
00674 if (status < 0) return status;
00675 tmpRescGrpInfo = myRescGrpInfo;
00676 while (tmpRescGrpInfo != NULL) {
00677 rescInfo_t *tmpRescInfo;
00678 tmpRescInfo = tmpRescGrpInfo->rescInfo;
00679 if (RescClass[tmpRescInfo->rescClassInx].classType == rescClass) {
00680 *outCacheResc = tmpRescInfo;
00681 if (outRescGrp != NULL) {
00682 *outRescGrp = myRescGrpInfo;
00683 } else {
00684 freeAllRescGrpInfo (myRescGrpInfo);
00685 }
00686
00687 return 0;
00688 }
00689 tmpRescGrpInfo = tmpRescGrpInfo->next;
00690 }
00691 freeAllRescGrpInfo (myRescGrpInfo);
00692 return SYS_NO_CACHE_RESC_IN_GRP;
00693 }
00694
00695
00696
00697
00698
00699
00700 int
00701 getRescInGrp (rsComm_t *rsComm, char *rescName, char *rescGroupName,
00702 rescInfo_t **outRescInfo)
00703 {
00704 int status;
00705 rescGrpInfo_t *myRescGrpInfo = NULL;
00706 rescGrpInfo_t *tmpRescGrpInfo;
00707
00708 if (rescGroupName == NULL || strlen (rescGroupName) == 0)
00709 return USER__NULL_INPUT_ERR;
00710
00711
00712 status = resolveRescGrp (rsComm, rescGroupName, &myRescGrpInfo);
00713
00714 if (status < 0) return status;
00715
00716 tmpRescGrpInfo = myRescGrpInfo;
00717 while (tmpRescGrpInfo != NULL) {
00718 rescInfo_t *tmpRescInfo;
00719 tmpRescInfo = tmpRescGrpInfo->rescInfo;
00720 if (strcmp (tmpRescInfo->rescName, rescName) == 0) {
00721 if (outRescInfo != NULL)
00722 *outRescInfo = tmpRescInfo;
00723 freeAllRescGrpInfo (myRescGrpInfo);
00724 return 0;
00725 }
00726 tmpRescGrpInfo = tmpRescGrpInfo->next;
00727 }
00728 freeAllRescGrpInfo (myRescGrpInfo);
00729 return SYS_UNMATCHED_RESC_IN_RESC_GRP;
00730 }
00731
00732
00733
00734
00735
00736
00737 int
00738 getRescGrpOfResc (rsComm_t *rsComm, rescInfo_t * rescInfo,
00739 rescGrpInfo_t **rescGrpInfo)
00740 {
00741 rescGrpInfo_t *tmpRescGrpInfo, *myRescGrpInfo;
00742 rescGrpInfo_t *outRescGrpInfo = NULL;
00743 rescInfo_t *myRescInfo;
00744 int status;
00745
00746 *rescGrpInfo = NULL;
00747
00748 if ((status = initRescGrp (rsComm)) < 0) return status;
00749
00750
00751 tmpRescGrpInfo = CachedRescGrpInfo;
00752 while (tmpRescGrpInfo != NULL) {
00753 myRescGrpInfo = tmpRescGrpInfo;
00754 while (myRescGrpInfo != NULL) {
00755 myRescInfo = myRescGrpInfo->rescInfo;
00756 if (strcmp (rescInfo->rescName, myRescInfo->rescName) == 0) {
00757 replRescGrpInfo (tmpRescGrpInfo, &outRescGrpInfo);
00758 outRescGrpInfo->cacheNext = *rescGrpInfo;
00759 *rescGrpInfo = outRescGrpInfo;
00760 break;
00761 }
00762 myRescGrpInfo = myRescGrpInfo->next;
00763 }
00764
00765 tmpRescGrpInfo = tmpRescGrpInfo->cacheNext;
00766 }
00767
00768 if (*rescGrpInfo == NULL)
00769 return SYS_NO_CACHE_RESC_IN_GRP;
00770 else
00771 return 0;
00772 }
00773
00774
00775
00776
00777
00778 int
00779 isRescsInSameGrp (rsComm_t *rsComm, char *rescName1, char *rescName2,
00780 rescGrpInfo_t **outRescGrpInfo)
00781 {
00782 rescGrpInfo_t *tmpRescGrpInfo, *myRescGrpInfo;
00783 rescInfo_t *myRescInfo;
00784 int status;
00785 int match1, match2;
00786
00787 if (outRescGrpInfo != NULL)
00788 *outRescGrpInfo = NULL;
00789
00790 if ((status = initRescGrp (rsComm)) < 0) return status;
00791
00792
00793 tmpRescGrpInfo = CachedRescGrpInfo;
00794 while (tmpRescGrpInfo != NULL) {
00795 myRescGrpInfo = tmpRescGrpInfo;
00796 match1 = match2 = 0;
00797 while (myRescGrpInfo != NULL) {
00798 myRescInfo = myRescGrpInfo->rescInfo;
00799 if (match1 == 0 &&
00800 strcmp (rescName1, myRescInfo->rescName) == 0) {
00801 match1 = 1;
00802 } else if (match2 == 0 &&
00803 strcmp (rescName2, myRescInfo->rescName) == 0) {
00804 match2 = 1;
00805 }
00806 if (match1 == 1 && match2 == 1) {
00807 if (outRescGrpInfo != NULL) *outRescGrpInfo = tmpRescGrpInfo;
00808 return 1;
00809 }
00810 myRescGrpInfo = myRescGrpInfo->next;
00811 }
00812
00813 tmpRescGrpInfo = tmpRescGrpInfo->cacheNext;
00814 }
00815 return 0;
00816 }
00817
00818
00819
00820
00821
00822
00823 int
00824 initRescGrp (rsComm_t *rsComm)
00825 {
00826 genQueryInp_t genQueryInp;
00827 rescGrpInfo_t *tmpRescGrpInfo;
00828 genQueryOut_t *genQueryOut = NULL;
00829 sqlResult_t *rescName, *rescGrpName;
00830 char *rescNameStr, *rescGrpNameStr;
00831 char *curRescGrpNameStr = NULL;
00832 int i;
00833 int status = 0;
00834 int savedRescGrpStatus = 0;
00835
00836 if (RescGrpInit > 0) return 0;
00837
00838 RescGrpInit = 1;
00839
00840
00841 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00842
00843 addInxIval (&genQueryInp.selectInp, COL_R_RESC_NAME, 1);
00844 addInxIval (&genQueryInp.selectInp, COL_RESC_GROUP_NAME, ORDER_BY);
00845
00846
00847 genQueryInp.maxRows = MAX_SQL_ROWS * 10;
00848
00849 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00850
00851 clearGenQueryInp (&genQueryInp);
00852
00853 if (status < 0) {
00854 if (status == CAT_NO_ROWS_FOUND)
00855 return 0;
00856 else
00857 return status;
00858 }
00859
00860 if ((rescName = getSqlResultByInx (genQueryOut, COL_R_RESC_NAME)) ==
00861 NULL) {
00862 rodsLog (LOG_NOTICE,
00863 "initRescGrp: getSqlResultByInx for COL_R_RESC_NAME failed");
00864 return (UNMATCHED_KEY_OR_INDEX);
00865 }
00866
00867 if ((rescGrpName = getSqlResultByInx (genQueryOut, COL_RESC_GROUP_NAME)) ==
00868 NULL) {
00869 rodsLog (LOG_NOTICE,
00870 "initRescGrp: getSqlResultByInx for COL_RESC_GROUP_NAME failed");
00871 return (UNMATCHED_KEY_OR_INDEX);
00872 }
00873
00874 tmpRescGrpInfo = NULL;
00875 for (i = 0;i < genQueryOut->rowCnt; i++) {
00876 rescNameStr = &rescName->value[rescName->len * i];
00877 rescGrpNameStr = &rescGrpName->value[rescGrpName->len * i];
00878 if (tmpRescGrpInfo != NULL && curRescGrpNameStr != NULL) {
00879 if (strcmp (rescGrpNameStr, curRescGrpNameStr) != 0) {
00880 rescGrpInfo_t *myRescGrpInfo;
00881
00882 tmpRescGrpInfo->cacheNext = CachedRescGrpInfo;
00883 if (savedRescGrpStatus != 0) {
00884 myRescGrpInfo = tmpRescGrpInfo;
00885 while (myRescGrpInfo != NULL) {
00886 myRescGrpInfo->status = savedRescGrpStatus;
00887 myRescGrpInfo = myRescGrpInfo->next;
00888 }
00889 }
00890 savedRescGrpStatus = 0;
00891 CachedRescGrpInfo = tmpRescGrpInfo;
00892 tmpRescGrpInfo = NULL;
00893 }
00894 }
00895 curRescGrpNameStr = rescGrpNameStr;
00896 status = resolveAndQueResc (rescNameStr, rescGrpNameStr,
00897 &tmpRescGrpInfo);
00898 if (status < 0) {
00899 if (status == SYS_RESC_IS_DOWN) {
00900 savedRescGrpStatus = SYS_RESC_IS_DOWN;
00901 } else {
00902 rodsLog (LOG_NOTICE,
00903 "initRescGrp: resolveAndQueResc error for %s. status = %d",
00904 rescNameStr, status);
00905 freeGenQueryOut (&genQueryOut);
00906 return (status);
00907 }
00908 }
00909 }
00910
00911 if (tmpRescGrpInfo != NULL) {
00912 tmpRescGrpInfo->status = savedRescGrpStatus;
00913 tmpRescGrpInfo->cacheNext = CachedRescGrpInfo;
00914 CachedRescGrpInfo = tmpRescGrpInfo;
00915 }
00916 if (genQueryOut != NULL && genQueryOut->continueInx > 0) {
00917 rodsLog (LOG_NOTICE,
00918 "initRescGrp: number of resources in resc groups exceed 2560");
00919 freeGenQueryOut (&genQueryOut);
00920 return SYS_INVALID_RESC_INPUT;
00921 } else {
00922 freeGenQueryOut (&genQueryOut);
00923 return 0;
00924 }
00925 }
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940 int
00941 setDefaultResc (rsComm_t *rsComm, char *defaultRescList, char *optionStr,
00942 keyValPair_t *condInput, rescGrpInfo_t **outRescGrpInfo)
00943 {
00944 rescGrpInfo_t *myRescGrpInfo = NULL;
00945 rescGrpInfo_t *defRescGrpInfo = NULL;
00946 rescGrpInfo_t *tmpRescGrpInfo, *prevRescGrpInfo;
00947 char *value = NULL;
00948 strArray_t strArray;
00949 int i, status;
00950 char *defaultResc;
00951 int startInx;
00952
00953 if (defaultRescList != NULL && strcmp (defaultRescList, "null") != 0 &&
00954 optionStr != NULL && strcmp (optionStr, "forced") == 0 &&
00955 rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
00956 condInput = NULL;
00957 }
00958
00959 memset (&strArray, 0, sizeof (strArray));
00960
00961 status = parseMultiStr (defaultRescList, &strArray);
00962
00963 #if 0
00964 if (status <= 0)
00965 return (0);
00966 #endif
00967
00968 value = strArray.value;
00969 if (strArray.len <= 1) {
00970 startInx = 0;
00971 defaultResc = value;
00972 } else {
00973
00974 startInx = random() % strArray.len;
00975 defaultResc = &value[startInx * strArray.size];
00976 }
00977 status = getRescInfoAndStatus (rsComm, defaultResc, NULL, &defRescGrpInfo);
00978 if (status < 0) {
00979
00980 if (strArray.len <= 1) {
00981 defaultResc = NULL;
00982 } else {
00983 for (i = 0; i < strArray.len; i++) {
00984 defaultResc = &value[i * strArray.size];
00985 status = getRescInfoAndStatus (rsComm, defaultResc, NULL,
00986 &defRescGrpInfo);
00987 if (status >= 0) break;
00988 }
00989 if (status < 0) defaultResc = NULL;
00990 }
00991 }
00992
00993 if (strcmp (optionStr, "preferred") == 0) {
00994
00995 status = getRescInfoAndStatus (rsComm, NULL, condInput,
00996 &myRescGrpInfo);
00997 if (status >= 0) {
00998 freeAllRescGrpInfo (defRescGrpInfo);
00999 if (strlen (myRescGrpInfo->rescGroupName) > 0) {
01000 for (i = 0; i < strArray.len; i++) {
01001 int j;
01002 j = startInx + i;
01003 if (j >= strArray.len) {
01004
01005 j = strArray.len - j;
01006 }
01007 tmpRescGrpInfo = myRescGrpInfo;
01008 prevRescGrpInfo = NULL;
01009 while (tmpRescGrpInfo != NULL) {
01010 rescInfo_t *myResc = tmpRescGrpInfo->rescInfo;
01011 if (strcmp (&value[j * strArray.size],
01012 myResc->rescName) == 0 &&
01013 myResc->rescStatus != INT_RESC_STATUS_DOWN) {
01014
01015 if (prevRescGrpInfo != NULL) {
01016 prevRescGrpInfo->next = tmpRescGrpInfo->next;
01017 tmpRescGrpInfo->next = myRescGrpInfo;
01018 myRescGrpInfo = tmpRescGrpInfo;
01019 }
01020 break;
01021 }
01022 prevRescGrpInfo = tmpRescGrpInfo;
01023 tmpRescGrpInfo = tmpRescGrpInfo->next;
01024 }
01025 }
01026 }
01027 } else {
01028
01029
01030 if (defRescGrpInfo != NULL) {
01031 myRescGrpInfo = defRescGrpInfo;
01032 status = 0;
01033 }
01034 }
01035 } else if (strcmp (optionStr, "forced") == 0 &&
01036 rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH ) {
01037 if (defRescGrpInfo != NULL) {
01038 myRescGrpInfo = defRescGrpInfo;
01039 }
01040 } else {
01041
01042 status = getRescInfo (rsComm, NULL, condInput,
01043 &myRescGrpInfo);
01044 if (status < 0) {
01045 if (status == USER_NO_RESC_INPUT_ERR && defRescGrpInfo != NULL) {
01046
01047 myRescGrpInfo = defRescGrpInfo;
01048 status = 0;
01049 } else {
01050 freeAllRescGrpInfo (defRescGrpInfo);
01051 }
01052 } else {
01053 freeAllRescGrpInfo (defRescGrpInfo);
01054 }
01055 }
01056
01057 if (status == CAT_NO_ROWS_FOUND)
01058 status = SYS_RESC_DOES_NOT_EXIST;
01059
01060
01061 if (value != NULL)
01062 free (value);
01063
01064 if (status >= 0) {
01065 *outRescGrpInfo = myRescGrpInfo;
01066 } else {
01067 *outRescGrpInfo = NULL;
01068 }
01069
01070 return (status);
01071 }
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081 int
01082 getRescInfoAndStatus (rsComm_t *rsComm, char *rescName, keyValPair_t *condInput,
01083 rescGrpInfo_t **rescGrpInfo)
01084 {
01085 int status;
01086 rescGrpInfo_t *myRescGrpInfo = NULL;
01087 rescGrpInfo_t *tmpRescGrpInfo;
01088
01089 status = getRescInfo (rsComm, rescName, condInput, &myRescGrpInfo);
01090 if (status >= 0 && *myRescGrpInfo->rescGroupName != '\0') {
01091
01092 tmpRescGrpInfo = myRescGrpInfo;
01093 while (tmpRescGrpInfo != NULL) {
01094 if (tmpRescGrpInfo->rescInfo->rescStatus != INT_RESC_STATUS_DOWN)
01095 break;
01096 tmpRescGrpInfo = tmpRescGrpInfo->next;
01097 }
01098 if (tmpRescGrpInfo == NULL) {
01099 status = SYS_RESC_IS_DOWN;
01100 if (myRescGrpInfo != NULL) freeAllRescGrpInfo (myRescGrpInfo);
01101 }
01102 }
01103 if (status >= 0) {
01104 *rescGrpInfo = myRescGrpInfo;
01105 } else {
01106 *rescGrpInfo = NULL;
01107 }
01108 return status;
01109 }
01110
01111
01112
01113
01114
01115 int
01116 initResc (rsComm_t *rsComm)
01117 {
01118 genQueryInp_t genQueryInp;
01119 genQueryOut_t *genQueryOut = NULL;
01120 int status;
01121 int continueInx;
01122
01123 memset (&genQueryInp, 0, sizeof (genQueryInp));
01124
01125 addInxIval (&genQueryInp.selectInp, COL_R_RESC_ID, 1);
01126 addInxIval (&genQueryInp.selectInp, COL_R_RESC_NAME, 1);
01127 addInxIval (&genQueryInp.selectInp, COL_R_ZONE_NAME, 1);
01128 addInxIval (&genQueryInp.selectInp, COL_R_TYPE_NAME, 1);
01129 addInxIval (&genQueryInp.selectInp, COL_R_CLASS_NAME, 1);
01130 addInxIval (&genQueryInp.selectInp, COL_R_LOC, 1);
01131 addInxIval (&genQueryInp.selectInp, COL_R_VAULT_PATH, 1);
01132 addInxIval (&genQueryInp.selectInp, COL_R_FREE_SPACE, 1);
01133 addInxIval (&genQueryInp.selectInp, COL_R_RESC_INFO, 1);
01134 addInxIval (&genQueryInp.selectInp, COL_R_RESC_COMMENT, 1);
01135 addInxIval (&genQueryInp.selectInp, COL_R_CREATE_TIME, 1);
01136 addInxIval (&genQueryInp.selectInp, COL_R_MODIFY_TIME, 1);
01137 addInxIval (&genQueryInp.selectInp, COL_R_RESC_STATUS, 1);
01138
01139 genQueryInp.maxRows = MAX_SQL_ROWS;
01140
01141 if (RescGrpInfo != NULL) {
01142
01143 freeAllRescGrp (RescGrpInfo);
01144 RescGrpInfo = NULL;
01145 }
01146
01147 continueInx = 1;
01148 while (continueInx > 0) {
01149 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
01150
01151 if (status < 0) {
01152 if (status !=CAT_NO_ROWS_FOUND) {
01153 rodsLog (LOG_NOTICE,
01154 "initResc: rsGenQuery error, status = %d",
01155 status);
01156 }
01157 clearGenQueryInp (&genQueryInp);
01158 return (status);
01159 }
01160
01161 status = procAndQueRescResult (genQueryOut);
01162
01163 if (status < 0) {
01164 rodsLog (LOG_NOTICE,
01165 "initResc: rsGenQuery error, status = %d", status);
01166 freeGenQueryOut (&genQueryOut);
01167 break;
01168 } else {
01169 if (genQueryOut != NULL) {
01170 continueInx = genQueryInp.continueInx =
01171 genQueryOut->continueInx;
01172 freeGenQueryOut (&genQueryOut);
01173 } else {
01174 continueInx = 0;
01175 }
01176 }
01177 }
01178 clearGenQueryInp (&genQueryInp);
01179 return (status);
01180 }
01181
01182
01183
01184
01185
01186 int
01187 procAndQueRescResult (genQueryOut_t *genQueryOut)
01188 {
01189 sqlResult_t *rescId, *rescName, *zoneName, *rescType, *rescClass;
01190 sqlResult_t *rescLoc, *rescVaultPath, *freeSpace, *rescInfo;
01191 sqlResult_t *rescComments, *rescCreate, *rescModify, *rescStatus;
01192 char *tmpRescId, *tmpRescName, *tmpZoneName, *tmpRescType, *tmpRescClass;
01193 char *tmpRescLoc, *tmpRescVaultPath, *tmpFreeSpace, *tmpRescInfo;
01194 char *tmpRescComments, *tmpRescCreate, *tmpRescModify, *tmpRescStatus;
01195 int i, status;
01196 rodsHostAddr_t addr;
01197 rodsServerHost_t *tmpRodsServerHost;
01198 rescInfo_t *myRescInfo;
01199
01200 if (genQueryOut == NULL) {
01201 rodsLog (LOG_NOTICE,
01202 "procAndQueResResult: NULL genQueryOut");
01203 return (0);
01204 }
01205
01206 if ((rescId = getSqlResultByInx (genQueryOut, COL_R_RESC_ID)) == NULL) {
01207 rodsLog (LOG_NOTICE,
01208 "procAndQueResResult: getSqlResultByInx for COL_R_RESC_ID failed");
01209 return (UNMATCHED_KEY_OR_INDEX);
01210 }
01211
01212 if ((rescName = getSqlResultByInx(genQueryOut, COL_R_RESC_NAME)) == NULL) {
01213 rodsLog (LOG_NOTICE,
01214 "procAndQueResResult: getSqlResultByInx for COL_R_RESC_NAME failed");
01215 return (UNMATCHED_KEY_OR_INDEX);
01216 }
01217 if ((zoneName = getSqlResultByInx(genQueryOut, COL_R_ZONE_NAME)) == NULL) {
01218 rodsLog (LOG_NOTICE,
01219 "procAndQueResResult: getSqlResultByInx for COL_R_ZONE_NAME failed");
01220 return (UNMATCHED_KEY_OR_INDEX);
01221 }
01222 if ((rescType = getSqlResultByInx(genQueryOut, COL_R_TYPE_NAME)) == NULL) {
01223 rodsLog (LOG_NOTICE,
01224 "procAndQueResResult: getSqlResultByInx for COL_R_TYPE_NAME failed");
01225 return (UNMATCHED_KEY_OR_INDEX);
01226 }
01227 if ((rescClass = getSqlResultByInx(genQueryOut,COL_R_CLASS_NAME))==NULL) {
01228 rodsLog (LOG_NOTICE,
01229 "procAndQueResResult: getSqlResultByInx for COL_R_CLASS_NAME failed");
01230 return (UNMATCHED_KEY_OR_INDEX);
01231 }
01232 if ((rescLoc = getSqlResultByInx (genQueryOut, COL_R_LOC)) == NULL) {
01233 rodsLog (LOG_NOTICE,
01234 "procAndQueResResult: getSqlResultByInx for COL_R_LOC failed");
01235 return (UNMATCHED_KEY_OR_INDEX);
01236 }
01237 if ((rescVaultPath = getSqlResultByInx (genQueryOut, COL_R_VAULT_PATH))
01238 == NULL) {
01239 rodsLog (LOG_NOTICE,
01240 "procAndQueResResult: getSqlResultByInx for COL_R_VAULT_PATH failed");
01241 return (UNMATCHED_KEY_OR_INDEX);
01242 }
01243 if ((freeSpace = getSqlResultByInx (genQueryOut, COL_R_FREE_SPACE)) ==
01244 NULL) {
01245 rodsLog (LOG_NOTICE,
01246 "procAndQueResResult: getSqlResultByInx for COL_R_FREE_SPACE failed");
01247 return (UNMATCHED_KEY_OR_INDEX);
01248 }
01249 if ((rescInfo = getSqlResultByInx (genQueryOut, COL_R_RESC_INFO)) ==
01250 NULL) {
01251 rodsLog (LOG_NOTICE,
01252 "procAndQueResResult: getSqlResultByInx for COL_R_RESC_INFO failed");
01253 return (UNMATCHED_KEY_OR_INDEX);
01254 }
01255 if ((rescComments = getSqlResultByInx (genQueryOut, COL_R_RESC_COMMENT))
01256 == NULL) {
01257 rodsLog (LOG_NOTICE,
01258 "procAndQueResResult:getSqlResultByInx for COL_R_RESC_COMMENT failed");
01259 return (UNMATCHED_KEY_OR_INDEX);
01260 }
01261 if ((rescCreate = getSqlResultByInx (genQueryOut, COL_R_CREATE_TIME))
01262 == NULL) {
01263 rodsLog (LOG_NOTICE,
01264 "procAndQueResResult:getSqlResultByInx for COL_R_CREATE_TIME failed");
01265 return (UNMATCHED_KEY_OR_INDEX);
01266 }
01267 if ((rescModify = getSqlResultByInx (genQueryOut, COL_R_MODIFY_TIME))
01268 == NULL) {
01269 rodsLog (LOG_NOTICE,
01270 "procAndQueResResult:getSqlResultByInx for COL_R_MODIFY_TIME failed");
01271 return (UNMATCHED_KEY_OR_INDEX);
01272 }
01273
01274 if ((rescStatus = getSqlResultByInx (genQueryOut, COL_R_RESC_STATUS))
01275 == NULL) {
01276 rodsLog (LOG_NOTICE,
01277 "procAndQueResResult:getSqlResultByInx for COL_R_RESC_STATUS failed");
01278 return (UNMATCHED_KEY_OR_INDEX);
01279 }
01280
01281 #if 0
01282 if (RescGrpInfo != NULL) {
01283
01284 freeAllRescGrp (RescGrpInfo);
01285 RescGrpInfo = NULL;
01286 }
01287 #endif
01288 for (i = 0;i < genQueryOut->rowCnt; i++) {
01289 tmpRescId = &rescId->value[rescId->len * i];
01290 tmpRescName = &rescName->value[rescName->len * i];
01291 tmpZoneName = &zoneName->value[zoneName->len * i];
01292 tmpRescType = &rescType->value[rescType->len * i];
01293 tmpRescClass = &rescClass->value[rescClass->len * i];
01294 tmpRescLoc = &rescLoc->value[rescLoc->len * i];
01295 tmpRescVaultPath = &rescVaultPath->value[rescVaultPath->len * i];
01296 tmpFreeSpace = &freeSpace->value[freeSpace->len * i];
01297 tmpRescInfo = &rescInfo->value[rescInfo->len * i];
01298 tmpRescComments = &rescComments->value[rescComments->len * i];
01299 tmpRescCreate = &rescCreate->value[rescCreate->len * i];
01300 tmpRescModify = &rescModify->value[rescModify->len * i];
01301 tmpRescStatus = &rescStatus->value[rescStatus->len * i];
01302
01303
01304
01305 memset (&addr, 0, sizeof (addr));
01306 rstrcpy (addr.hostAddr, tmpRescLoc, LONG_NAME_LEN);
01307 rstrcpy (addr.zoneName, tmpZoneName, NAME_LEN);
01308 status = resolveHost (&addr, &tmpRodsServerHost);
01309 if (status < 0) {
01310 rodsLog (LOG_NOTICE,
01311 "procAndQueRescResult: resolveHost error for %s",
01312 addr.hostAddr);
01313 }
01314
01315 myRescInfo = ( rescInfo_t* )malloc (sizeof (rescInfo_t));
01316 memset (myRescInfo, 0, sizeof (rescInfo_t));
01317 myRescInfo->rodsServerHost = tmpRodsServerHost;
01318 myRescInfo->rescId = strtoll (tmpRescId, 0, 0);
01319 rstrcpy (myRescInfo->zoneName, tmpZoneName, NAME_LEN);
01320 rstrcpy (myRescInfo->rescName, tmpRescName, NAME_LEN);
01321 rstrcpy (myRescInfo->rescLoc, tmpRescLoc, NAME_LEN);
01322 rstrcpy (myRescInfo->rescType, tmpRescType, NAME_LEN);
01323
01324 myRescInfo->rescTypeInx = getRescTypeInx (tmpRescType);
01325 if (myRescInfo->rescTypeInx < 0) {
01326 rodsLog (LOG_ERROR,
01327 "procAndQueResResult: Unknown rescType %s. Resource %s will not be configured",
01328 tmpRescType, myRescInfo->rescName);
01329 continue;
01330 }
01331 rstrcpy (myRescInfo->rescClass, tmpRescClass, NAME_LEN);
01332 myRescInfo->rescClassInx = getRescClassInx (tmpRescClass);
01333 if (myRescInfo->rescClassInx < 0) {
01334 rodsLog (LOG_ERROR,
01335 "procAndQueResResult: Unknown rescClass %s. Resource %s will not be configured",
01336 tmpRescClass, myRescInfo->rescName);
01337 continue;
01338 }
01339 rstrcpy (myRescInfo->rescVaultPath, tmpRescVaultPath, MAX_NAME_LEN);
01340 if (RescTypeDef[myRescInfo->rescTypeInx].driverType == WOS_FILE_TYPE &&
01341 tmpRodsServerHost->localFlag == LOCAL_HOST) {
01342
01343 char wosHost[MAX_NAME_LEN], wosPolicy[MAX_NAME_LEN];
01344 char *tmpStr;
01345 if (splitPathByKey (tmpRescVaultPath, wosHost, wosPolicy, '/') < 0)
01346 {
01347 rodsLog (LOG_ERROR,
01348 "procAndQueResResult:splitPathByKey of wosHost error for %s",
01349 wosHost, wosPolicy);
01350 } else {
01351
01352
01353
01354
01355 static char tmpStr[MAX_NAME_LEN];
01356 static char tmpStr1[MAX_NAME_LEN];
01357 snprintf (tmpStr, MAX_NAME_LEN, "%s=%s", WOS_HOST_ENV, wosHost);
01358 putenv (tmpStr);
01359 snprintf (tmpStr1, MAX_NAME_LEN, "%s=%s", WOS_POLICY_ENV, wosPolicy);
01360 putenv (tmpStr1);
01361 if (ProcessType == SERVER_PT) {
01362 rodsLog (LOG_NOTICE,
01363 "Set WOS env wosHost=%s, wosPolicy=%s",
01364 wosHost, wosPolicy);
01365 }
01366 }
01367 }
01368 rstrcpy (myRescInfo->rescInfo, tmpRescInfo, LONG_NAME_LEN);
01369 rstrcpy (myRescInfo->rescComments, tmpRescComments, LONG_NAME_LEN);
01370 myRescInfo->freeSpace = strtoll (tmpFreeSpace, 0, 0);
01371 rstrcpy (myRescInfo->rescCreate, tmpRescCreate, TIME_LEN);
01372 rstrcpy (myRescInfo->rescModify, tmpRescModify, TIME_LEN);
01373 if (strstr (tmpRescStatus, RESC_DOWN) != NULL) {
01374 myRescInfo->rescStatus = INT_RESC_STATUS_DOWN;
01375 } else {
01376 myRescInfo->rescStatus = INT_RESC_STATUS_UP;
01377 }
01378 myRescInfo->quotaLimit = RESC_QUOTA_UNINIT;
01379 queResc (myRescInfo, NULL, &RescGrpInfo, BOTTOM_FLAG);
01380 }
01381 return (0);
01382 }
01383
01384
01385 int
01386 getHostStatusByRescInfo (rodsServerHost_t *rodsServerHost)
01387 {
01388 rescGrpInfo_t *tmpRescGrpInfo;
01389 rescInfo_t *myRescInfo;
01390 int match = 0;
01391
01392 tmpRescGrpInfo = RescGrpInfo;
01393 while (tmpRescGrpInfo != NULL) {
01394 myRescInfo = tmpRescGrpInfo->rescInfo;
01395 if (myRescInfo->rodsServerHost == rodsServerHost) {
01396 if (myRescInfo->rescStatus == INT_RESC_STATUS_UP) {
01397 return INT_RESC_STATUS_UP;
01398 }
01399 match = 1;
01400 }
01401 tmpRescGrpInfo = tmpRescGrpInfo->next;
01402 }
01403
01404 if (match == 0) {
01405
01406 return INT_RESC_STATUS_UP;
01407 } else {
01408 return INT_RESC_STATUS_DOWN;
01409 }
01410 }
01411
01412
01413
01414
01415
01416
01417 int
01418 printLocalResc ()
01419 {
01420 rescInfo_t *myRescInfo;
01421 rescGrpInfo_t *tmpRescGrpInfo;
01422 rodsServerHost_t *tmpRodsServerHost;
01423 int localRescCnt = 0;
01424
01425 #ifndef windows_platform
01426 #ifdef IRODS_SYSLOG
01427 rodsLog (LOG_NOTICE,"Local Resource configuration: \n");
01428 #else
01429 fprintf (stderr, "Local Resource configuration: \n");
01430 #endif
01431 #else
01432 rodsLog (LOG_NOTICE,"Local Resource configuration: \n");
01433 #endif
01434
01435
01436
01437 tmpRescGrpInfo = RescGrpInfo;
01438
01439 while (tmpRescGrpInfo != NULL) {
01440 myRescInfo = tmpRescGrpInfo->rescInfo;
01441 tmpRodsServerHost = (rodsServerHost_t*)myRescInfo->rodsServerHost;
01442 if (tmpRodsServerHost->localFlag == LOCAL_HOST) {
01443 #ifndef windows_platform
01444 #ifdef IRODS_SYSLOG
01445 rodsLog (LOG_NOTICE," RescName: %s, VaultPath: %s\n",
01446 myRescInfo->rescName, myRescInfo->rescVaultPath);
01447 #else
01448 fprintf (stderr, " RescName: %s, VaultPath: %s\n",
01449 myRescInfo->rescName, myRescInfo->rescVaultPath);
01450 #endif
01451 #else
01452 rodsLog (LOG_NOTICE," RescName: %s, VaultPath: %s\n",
01453 myRescInfo->rescName, myRescInfo->rescVaultPath);
01454 #endif
01455 localRescCnt ++;
01456 }
01457 tmpRescGrpInfo = tmpRescGrpInfo->next;
01458 }
01459
01460 #ifndef windows_platform
01461 #ifdef IRODS_SYSLOG
01462 rodsLog (LOG_NOTICE,"\n");
01463 #else
01464 fprintf (stderr, "\n");
01465 #endif
01466 #else
01467 rodsLog (LOG_NOTICE,"\n");
01468 #endif
01469
01470 if (localRescCnt == 0) {
01471 #ifndef windows_platform
01472 #ifdef IRODS_SYSLOG
01473 rodsLog (LOG_NOTICE," No Local Resource Configured\n");
01474 #else
01475 fprintf (stderr, " No Local Resource Configured\n");
01476 #endif
01477 #else
01478 rodsLog (LOG_NOTICE," No Local Resource Configured\n");
01479 #endif
01480 }
01481
01482 return (0);
01483 }
01484
01485
01486
01487
01488
01489
01490
01491 int
01492 queResc (rescInfo_t *myRescInfo, char *rescGroupName,
01493 rescGrpInfo_t **rescGrpInfoHead, int topFlag)
01494 {
01495 rescGrpInfo_t *myRescGrpInfo;
01496 int status;
01497
01498 if (myRescInfo == NULL)
01499 return (0);
01500
01501 myRescGrpInfo = (rescGrpInfo_t *) malloc (sizeof (rescGrpInfo_t));
01502 memset (myRescGrpInfo, 0, sizeof (rescGrpInfo_t));
01503
01504 myRescGrpInfo->rescInfo = myRescInfo;
01505
01506 if (rescGroupName != NULL) {
01507 rstrcpy (myRescGrpInfo->rescGroupName, rescGroupName, NAME_LEN);
01508 }
01509
01510 status = queRescGrp (rescGrpInfoHead, myRescGrpInfo, topFlag);
01511
01512 return (status);
01513
01514 }
01515
01516
01517
01518
01519
01520
01521 int
01522 queRescGrp (rescGrpInfo_t **rescGrpInfoHead, rescGrpInfo_t *myRescGrpInfo,
01523 int flag)
01524 {
01525 rescInfo_t *tmpRescInfo, *myRescInfo;
01526 rescGrpInfo_t *tmpRescGrpInfo, *lastRescGrpInfo = NULL;
01527
01528 myRescInfo = myRescGrpInfo->rescInfo;
01529 tmpRescGrpInfo = *rescGrpInfoHead;
01530 if (flag == TOP_FLAG) {
01531 *rescGrpInfoHead = myRescGrpInfo;
01532 myRescGrpInfo->next = tmpRescGrpInfo;
01533 } else {
01534 while (tmpRescGrpInfo != NULL) {
01535 tmpRescInfo = tmpRescGrpInfo->rescInfo;
01536 if (flag == BY_TYPE_FLAG && myRescInfo != NULL &&
01537 tmpRescInfo != NULL) {
01538 if (RescClass[myRescInfo->rescClassInx].classType <
01539 RescClass[tmpRescInfo->rescClassInx].classType) {
01540 break;
01541 }
01542 }
01543 lastRescGrpInfo = tmpRescGrpInfo;
01544 tmpRescGrpInfo = tmpRescGrpInfo->next;
01545 }
01546
01547 if (lastRescGrpInfo == NULL) {
01548 *rescGrpInfoHead = myRescGrpInfo;
01549 } else {
01550 lastRescGrpInfo->next = myRescGrpInfo;
01551 }
01552 myRescGrpInfo->next = tmpRescGrpInfo;
01553 }
01554
01555 return (0);
01556 }
01557
01558
01559
01560
01561 int
01562 freeAllRescGrp (rescGrpInfo_t *rescGrpHead)
01563 {
01564 rescGrpInfo_t *tmpRrescGrp, *nextRrescGrp;
01565
01566 tmpRrescGrp = rescGrpHead;
01567 while (tmpRrescGrp != NULL) {
01568 nextRrescGrp = tmpRrescGrp->next;
01569 if (tmpRrescGrp->rescInfo != NULL) free (tmpRrescGrp->rescInfo);
01570 free (tmpRrescGrp);
01571 tmpRrescGrp = tmpRrescGrp->next;
01572 }
01573 return 0;
01574 }
01575
01576
01577
01578
01579
01580 int
01581 getRescType (rescInfo_t *rescInfo)
01582 {
01583 int rescTypeInx;
01584
01585 if (rescInfo == NULL) return USER__NULL_INPUT_ERR;
01586 rescTypeInx = rescInfo->rescTypeInx;
01587 if (rescTypeInx >= NumRescTypeDef) return RESCTYPEINX_EMPTY_IN_STRUCT_ERR;
01588 return (RescTypeDef[rescTypeInx].driverType);
01589 }
01590
01591
01592
01593
01594
01595
01596 int
01597 getRescTypeInx (char *rescType)
01598 {
01599 int i;
01600
01601 if (rescType == NULL) {
01602 return SYS_INTERNAL_NULL_INPUT_ERR;
01603 }
01604
01605 for (i = 0; i < NumRescTypeDef; i++) {
01606 if (strstr (rescType, RescTypeDef[i].typeName) != NULL) {
01607 return (i);
01608 }
01609 }
01610 rodsLog (LOG_NOTICE,
01611 "getRescTypeInx: No match for input rescType %s", rescType);
01612
01613 return (UNMATCHED_KEY_OR_INDEX);
01614 }
01615
01616
01617
01618
01619
01620
01621 int
01622 getRescClassInx (char *rescClass)
01623 {
01624 int i;
01625
01626 if (rescClass == NULL) {
01627 return SYS_INTERNAL_NULL_INPUT_ERR;
01628 }
01629
01630 for (i = 0; i < NumRescClass; i++) {
01631 if (strstr (rescClass, RescClass[i].className) != NULL) {
01632
01633 if (strstr (rescClass, "primary") != NULL) {
01634 return (i | PRIMARY_FLAG);
01635 } else {
01636 return (i);
01637 }
01638 }
01639 }
01640 rodsLog (LOG_NOTICE,
01641 "getRescClassInx: No match for input rescClass %s", rescClass);
01642
01643 return (UNMATCHED_KEY_OR_INDEX);
01644 }
01645
01646
01647
01648
01649
01650
01651 int
01652 getMultiCopyPerResc ( rsComm_t *rsComm )
01653 {
01654 ruleExecInfo_t rei;
01655
01656 memset (&rei, 0, sizeof (rei));
01657 rei.rsComm = rsComm;
01658 applyRule ("acSetMultiReplPerResc", NULL, &rei, NO_SAVE_REI);
01659 if (strcmp (rei.statusStr, MULTI_COPIES_PER_RESC) == 0) {
01660 return 1;
01661 } else {
01662 return 0;
01663 }
01664 }
01665
01666
01667
01668
01669 int
01670 getRescCnt (rescGrpInfo_t *myRescGrpInfo)
01671 {
01672 rescGrpInfo_t *tmpRescGrpInfo;
01673 int rescCnt = 0;
01674
01675 tmpRescGrpInfo = myRescGrpInfo;
01676
01677 while (tmpRescGrpInfo != NULL) {
01678 rescCnt ++;
01679 tmpRescGrpInfo = tmpRescGrpInfo->next;
01680 }
01681
01682 return (rescCnt);
01683 }
01684
01685 int
01686 updateResc (rsComm_t *rsComm)
01687 {
01688 int status;
01689
01690 rescGrpInfo_t *tmpRescGrpInfo, *nextRescGrpInfo;
01691
01692
01693 freeAllRescGrpInfo (CachedRescGrpInfo);
01694 CachedRescGrpInfo = NULL;
01695 RescGrpInit = 0;
01696
01697
01698 tmpRescGrpInfo = RescGrpInfo;
01699 while (tmpRescGrpInfo != NULL) {
01700 nextRescGrpInfo = tmpRescGrpInfo->next;
01701 free (tmpRescGrpInfo->rescInfo);
01702 free (tmpRescGrpInfo);
01703 tmpRescGrpInfo = nextRescGrpInfo;
01704 }
01705 RescGrpInfo = NULL;
01706 status = initResc (rsComm);
01707
01708 return status;
01709 }
01710
01711 #if 0 // JMC - UNUSED
01712
01713
01714
01715
01716 rescInfo_t *
01717 matchSameHostRescByType (rescInfo_t *myRescInfo, int driverType)
01718 {
01719 rescInfo_t *tmpRescInfo;
01720 rescGrpInfo_t *tmpRescGrpInfo;
01721
01722 tmpRescGrpInfo = RescGrpInfo;
01723
01724 while (tmpRescGrpInfo != NULL) {
01725 tmpRescInfo = tmpRescGrpInfo->rescInfo;
01726
01727 if (strcmp (myRescInfo->rescLoc, tmpRescInfo->rescLoc) == 0) {
01728
01729 int rescTypeInx = tmpRescInfo->rescTypeInx;
01730 if (RescTypeDef[rescTypeInx].driverType == driverType) {
01731 return tmpRescInfo;
01732 }
01733 }
01734 tmpRescGrpInfo = tmpRescGrpInfo->next;
01735 }
01736 return NULL;
01737 }
01738 #endif // JMC - UNUSED
01739
01740
01741