00001
00002
00003
00004
00005
00006 #include <SUM.h>
00007 #include <sys/time.h>
00008 #include <sys/errno.h>
00009 #include <rpc/rpc.h>
00010 #include <soi_key.h>
00011 #include <soi_error.h>
00012 #include <sum_rpc.h>
00013
00014 #include "serverdefs.h"
00015 #include "drmssite_info.h"
00016
00017 extern int errno;
00018 extern int write_log(const char *fmt, ...);
00019 extern void StartTimer(int n);
00020 extern float StopTimer(int n);
00021 extern CLIENT *current_client, *clnttape, *clnttape_old;
00022 extern SVCXPRT *glb_transp;
00023 extern uint32_t rinfo;
00024 extern uint32_t sumprog;
00025 extern uint32_t sumvers;
00026 extern int debugflg;
00027 extern int rrid;
00028 extern float ftmp;
00029 extern char logname[];
00030 extern char jsoc_machine[];
00031 static int NO_OPEN = 0;
00032 static char callername[MAX_STR];
00033 static char nametmp[80];
00034 static int numSUM;
00035
00036 void write_time();
00037 void logkey();
00038 char *trimwhitespace(char *str);
00039
00040
00041
00042 static char *datestring()
00043 {
00044 static char datestr[32];
00045 struct timeval tvalr;
00046 struct tm *t_ptr;
00047
00048 gettimeofday(&tvalr, NULL);
00049 t_ptr = localtime((const time_t *)&tvalr);
00050 sprintf(datestr, "%s", asctime(t_ptr));
00051 datestr[19] = (char)NULL;
00052 return(&datestr[4]);
00053 }
00054
00055 static KEY *retlist;
00056 SUMOPENED *sumopened_hdr = NULL;
00057
00058
00059
00060
00061
00062
00063
00064 CLIENT *set_client_handle(uint32_t prognum, uint32_t versnum)
00065 {
00066 static CLIENT *client;
00067 struct sockaddr_in *sock_in;
00068 int sock = RPC_ANYSOCK;
00069
00070
00071
00072
00073
00074 sock_in = svc_getcaller(glb_transp);
00075 sock_in->sin_port = 0;
00076 client = clnttcp_create(sock_in,prognum,versnum,&sock,0,0);
00077 if(!client) {
00078 clnt_pcreateerror("Can't do a clnttcp_create to send a response");
00079 write_time();
00080 write_log("**** Can't do a clnttcp_create to send a response ****\n");
00081 write_log("**** Did someone remove us from the portmapper? ****\n");
00082 return(0);
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 current_client = client;
00108 return(client);
00109 }
00110
00111
00112
00113
00114
00115
00116 void send_ack()
00117 {
00118
00119 if (!svc_sendreply(glb_transp, (xdrproc_t)xdr_uint32_t, (char *)&rinfo)) {
00120 write_log("***Error on immed ack back to client. FATAL???\n");
00121 svcerr_systemerr(glb_transp);
00122 }
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 KEY *opendo_1(KEY *params)
00135 {
00136 char *user;
00137
00138 if(findkey(params, "DEBUGFLG")) {
00139 debugflg = getkey_int(params, "DEBUGFLG");
00140 if(debugflg) {
00141 write_log("!!Keylist in opendo_1() is:\n");
00142 keyiterate(logkey, params);
00143 }
00144 }
00145 user = GETKEY_str(params, "USER");
00146 if(NO_OPEN) {
00147 write_time();
00148 write_log("No SUM_open() for %s allowed during SUM shutdown\n", user);
00149 rinfo = 0;
00150 send_ack();
00151 return((KEY *)1);
00152 }
00153 rinfo = SUMLIB_Open();
00154 if(rinfo) {
00155 write_time();
00156 write_log("Successful SUMLIB_Open id=%d for user=%s uid=%d\n",rrid,user,rinfo);
00157
00158
00159
00160 }
00161 send_ack();
00162 return((KEY *)1);
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172 KEY *configdo_1(KEY *params)
00173 {
00174 char *user;
00175
00176 if(findkey(params, "DEBUGFLG")) {
00177 debugflg = getkey_int(params, "DEBUGFLG");
00178 if(debugflg) {
00179 write_log("!!Keylist in configdo_1() is:\n");
00180 keyiterate(logkey, params);
00181 }
00182 }
00183 user = GETKEY_str(params, "USER");
00184 if(NO_OPEN) {
00185 write_time();
00186 write_log("No SUM_open() for %s allowed during SUM shutdown\n", user);
00187 rinfo = 0;
00188 send_ack();
00189 return((KEY *)1);
00190 }
00191 numSUM = SUM_NUMSUM;
00192 rinfo = (uint32_t)numSUM;
00193 if(rinfo) {
00194 write_time();
00195 write_log("Successful CONFIGDO id=%d for user=%s numSUM=%d\n",rrid,user,rinfo);
00196 }
00197 send_ack();
00198 return((KEY *)1);
00199 }
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 KEY *repartndo_1(KEY *params)
00210 {
00211 int stat;
00212
00213 stat = DS_PavailRequest2();
00214 if(!stat) {
00215 write_time();
00216 write_log("Successful reread of sum_partn_avail DB table\n");
00217 rinfo = 0;
00218 }
00219 else {
00220 write_log("Unsuccessful reread of sum_partn_avail DB table\n");
00221 rinfo = 1;
00222 }
00223 send_ack();
00224 return((KEY *)1);
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 KEY *shutdo_1(KEY *params)
00239 {
00240 SUMOPENED *walk = sumopened_hdr;
00241 int query;
00242
00243 query = getkey_int(params, "QUERY");
00244 if(!query)
00245 NO_OPEN = 1;
00246 else
00247 NO_OPEN = 0;
00248 if(walk == NULL) {
00249 if(NO_OPEN)
00250 write_log("SUM_shutdown() call with no opened SUM users. New opens not allowed\n");
00251 else
00252 write_log("SUM_shutdown() call with no opened SUM users. New opens still allowed\n");
00253 rinfo = 1;
00254 }
00255 else {
00256 write_log("SUM_shutdown() call with opened users & uid:\n");
00257 rinfo = 0;
00258 while(walk) {
00259 write_log(" %s %lu\n", walk->user, walk->uid);
00260 walk = walk->next;
00261 }
00262 if(NO_OPEN)
00263 write_log("New opens not allowed\n");
00264 else
00265 write_log("New opens still allowed\n");
00266 }
00267 send_ack();
00268 return((KEY *)1);
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 KEY *getdo_1(KEY *params)
00287 {
00288
00289
00290
00291 static struct timeval TIMEOUT = { 50, 0 };
00292 static CLIENT *clresp;
00293 uint32_t tapeback;
00294 uint64_t uid, sunum;
00295 enum clnt_stat status;
00296 int reqcnt, i, offline, storeset, offcnt, getvers;
00297 char *call_err, *cptr, *wd;
00298 char scmd[96], errstr[80];
00299 double bytes;
00300
00301 sprintf(callername, "getdo_1");
00302 if(findkey(params, "DEBUGFLG")) {
00303 debugflg = getkey_int(params, "DEBUGFLG");
00304 if(debugflg) {
00305 write_log("!!Keylist in getdo_1() is:\n");
00306 keyiterate(logkey, params);
00307 }
00308 }
00309 reqcnt = getkey_int(params, "reqcnt");
00310 uid = getkey_uint64(params, "uid");
00311 sunum = getkey_uint64(params, "dsix_0");
00312 if(sunum > LLONG_MAX) {
00313 write_log("**Error: getdo_1() called with sunum > LLONG_MAX uid=%lu\n", uid);
00314 rinfo = 1;
00315 send_ack();
00316 return((KEY *)1);
00317 }
00318
00319
00320 retlist=newkeylist();
00321
00322
00323
00324
00325
00326
00327 add_keys(params, &retlist);
00328
00329 if(!(clresp = set_client_handle(RESPPROG, (uint32_t)uid))) {
00330 write_log("SUM_get() id=%d for user=%s sunum=%lu cnt=%d uid=%lu\n**Error: getdo_1() can't set_client_handle for response\n",
00331 rrid, GETKEY_str(params, "username"), sunum, reqcnt, uid);
00332
00333 freekeylist(&retlist);
00334 rinfo = 1;
00335 send_ack();
00336 return((KEY *)1);
00337 }
00338
00339 setkey_fileptr(&retlist, "current_client", (FILE *)clresp);
00340 if(DS_DataRequest(params, &retlist)) {
00341 write_log("SUM_get() id=%d for user=%s sunum=%lu cnt=%d uid=%lu\n**Error: DS_DataRequest() returns error\n",
00342 rrid, GETKEY_str(params, "username"), sunum, reqcnt, uid);
00343 freekeylist(&retlist);
00344 rinfo = 1;
00345 send_ack();
00346 clnt_destroy(clresp);
00347 return((KEY *)1);
00348 }
00349 offline = getkey_int(retlist, "offline");
00350 write_log("SUM_get() id=%d for user=%s sunum=%lu cnt=%d uid=%lu rtrv=%d\n",
00351 rrid, GETKEY_str(params, "username"), sunum, reqcnt, uid, offline);
00352
00353 if(offline) {
00354
00355 if(findkey(params, "newflg")) {
00356 getvers = getkey_int(params, "newflg");
00357 }
00358 else getvers = 0;
00359 if(getvers != GET_FIX_VER) {
00360 rinfo = 0;
00361 send_ack();
00362 setkey_int(&retlist, "STATUS", 1);
00363 sprintf(errstr, "Caller is old DRMS version. No tape read allowed. Remake your code\n");
00364 setkey_str(&retlist, "ERRSTR", errstr);
00365 write_log("No tape read for old DRMS version. id=%d for user=%s sunum=%lu cnt=%d uid=%lu\n",
00366 rrid, GETKEY_str(params, "username"), sunum, reqcnt, uid);
00367 return(retlist);
00368 }
00369 offcnt = 0;
00370 for(i=0; i < reqcnt; i++) {
00371 sprintf(nametmp, "online_status_%d", i);
00372 cptr = GETKEY_str(retlist, nametmp);
00373
00374 if(strcmp(cptr, "N") == 0) {
00375 sprintf(nametmp, "archive_status_%d", i);
00376 cptr = GETKEY_str(retlist, nametmp);
00377 if(strcmp(cptr, "Y") == 0) {
00378 offcnt++;
00379 sprintf(nametmp, "bytes_%d", i);
00380 bytes = getkey_double(retlist, nametmp);
00381 storeset = JSOC;
00382 if((status=SUMLIB_PavailGet(bytes,storeset,uid,0,&retlist))) {
00383 write_log("***Can't alloc storage for retrieve uid = %lu\n", uid);
00384 freekeylist(&retlist);
00385 rinfo = 1;
00386 send_ack();
00387 clnt_destroy(clresp);
00388 return((KEY *)1);
00389 }
00390 wd = GETKEY_str(retlist, "partn_name");
00391
00392 sprintf(scmd, "chmod g-s %s", wd);
00393 if(system(scmd)) {
00394 write_log("**Warning: Error on: %s. errno=%d\n", scmd,errno);
00395 }
00396 sprintf(nametmp, "rootwd_%d", i);
00397 setkey_str(&retlist, nametmp, wd);
00398 write_log("\nAlloc for retrieve wd = %s for sumid = %lu\n", wd, uid);
00399 }
00400 }
00401 }
00402 setkey_int(&retlist, "offcnt", offcnt);
00403
00404 if(debugflg) {
00405 write_log("Calling tape_svc to bring data unit online\n");
00406 }
00407
00408 if(clnttape == 0) {
00409 rinfo = 2;
00410 send_ack();
00411 freekeylist(&retlist);
00412 write_log("**Error in READDO to tape_svc. sum_svc has been disconnected\n");
00413 return((KEY *)1);
00414 }
00415 rinfo = RESULT_PEND;
00416 tapeback = 0;
00417
00418 write_log("SUM_get() id=%d for SPROG=%u SVERS=%u uid=%lu rtrv=%d\n",
00419 rrid, sumprog, sumvers, uid, offline);
00420 setkey_uint32(&retlist, "SPROG", sumprog);
00421 setkey_uint32(&retlist, "SVERS", sumvers);
00422 status = clnt_call(clnttape,READDO, (xdrproc_t)xdr_Rkey, (char *)retlist,
00423 (xdrproc_t)xdr_uint32_t, (char *)&tapeback, TIMEOUT);
00424 if(status != RPC_SUCCESS) {
00425 if(status != RPC_TIMEDOUT) {
00426
00427 rinfo = 5;
00428 send_ack();
00429 call_err = clnt_sperror(clnttape, "Error clnt_call for READDO");
00430 write_log("%s %d %s\n", datestring(), status, call_err);
00431 freekeylist(&retlist);
00432 return((KEY *)1);
00433 } else {
00434 write_log("%s timeout ignored in getdo_1()\n", datestring());
00435 }
00436 }
00437 if(tapeback == 1) {
00438 rinfo = 1;
00439 send_ack();
00440 freekeylist(&retlist);
00441 write_log("**Error in READDO call to tape_svc in sum_svc_proc.c\n");
00442 return((KEY *)1);
00443 }
00444 send_ack();
00445
00446
00447
00449
00450 }
00451 else {
00452 rinfo = 0;
00453 send_ack();
00454 }
00455 if(offline) {
00456 freekeylist(&retlist);
00457 return((KEY *)1);
00458 }
00459 setkey_int(&retlist, "STATUS", 0);
00460 return(retlist);
00461 }
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 KEY *allocdo_1(KEY *params)
00476 {
00477 int status, reqcnt, group;
00478 int storeset = 0;
00479 uint64_t uid;
00480 uint64_t sunum = 0;
00481 double bytes;
00482 char *wd;
00483 char errstr[80];
00484
00485 sprintf(callername, "allocdo_1");
00486 if(findkey(params, "DEBUGFLG")) {
00487 debugflg = getkey_int(params, "DEBUGFLG");
00488 if(debugflg) {
00489 write_log("!!Keylist in allocdo_1() is:\n");
00490 keyiterate(logkey, params);
00491 }
00492 }
00493 if(findkey(params, "SUNUM")) {
00494 sunum = getkey_uint64(params, "SUNUM");
00495 }
00496 #if defined(SUMS_MULTIPLE_PARTNSETS) && SUMS_MULTIPLE_PARTNSETS
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506 if(!findkey(params, "group")) {
00507 storeset = 0;
00508 }
00509 else {
00510 group = getkey_int(params, "group");
00511 status = SUMLIB_SumsetGet(group, &storeset);
00512 if(!status) {
00513 write_log("Error ret from SUMLIB_SumsetGet() for group=%d, user=%s\n",
00514 group, GETKEY_str(params, "USER"));
00515 }
00516 }
00517 #endif
00518 uid = getkey_uint64(params, "uid");
00519
00520
00521
00522
00523
00524
00525 retlist = newkeylist();
00526 add_keys(params, &retlist);
00527 reqcnt = getkey_int(params, "reqcnt");
00528 bytes = getkey_double(params, "bytes");
00529
00530 if(!(status=SUMLIB_PavailGet(bytes, storeset, uid, sunum, &retlist))) {
00531 wd = getkey_str(retlist, "partn_name");
00532 write_log("Alloc bytes=%e id=%d wd=%s for user=%s sumid=%lu\n", bytes, rrid, wd,
00533 GETKEY_str(retlist, "USER"), uid);
00534 if(!(set_client_handle(RESPPROG, (uint32_t)uid))) {
00535 write_log("Alloc Error Can't set client handle id=%d user=%s sumid=%lu\n", rrid, GETKEY_str(retlist, "USER"), uid);
00536 free(wd);
00537 freekeylist(&retlist);
00538 rinfo = 1;
00539 send_ack();
00540 return((KEY *)1);
00541 }
00542
00543 if(NC_PaUpdate(wd, uid, bytes, DARW, 0, NULL, 0, 0, 0, 1, 1)) {
00544 write_log("WARN: can't make DARW entry in sum_partn_alloc for\n");
00545 write_log(" allocated storage. Proceed anyway...\n");
00546 }
00547 rinfo = 0;
00548 send_ack();
00549 setkey_int(&retlist, "STATUS", 0);
00550 free(wd);
00551 return(retlist);
00552 }
00553 sprintf(errstr, "Error ret from SUMLIB_PavailGet() sumuid=%lu user=%s\n",
00554 uid, GETKEY_str(params, "USER"));
00555 setkey_str(&retlist, "ERRSTR", errstr);
00556 rinfo = status;
00557 send_ack();
00558 freekeylist(&retlist);
00559 return((KEY *)1);
00560 }
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570 KEY *infodo_1(KEY *params)
00571 {
00572 int status;
00573 uint64_t uid;
00574 uint64_t sunum = 0;
00575
00576 sprintf(callername, "infodo_1");
00577 if(findkey(params, "DEBUGFLG")) {
00578 debugflg = getkey_int(params, "DEBUGFLG");
00579 if(debugflg) {
00580 write_log("!!Keylist in infodo_1() is:\n");
00581 keyiterate(logkey, params);
00582 }
00583 }
00584 sunum = getkey_uint64(params, "SUNUM");
00585 uid = getkey_uint64(params, "uid");
00586 write_log("SUM_Info() for user=%s sunum=%lu\n",
00587 GETKEY_str(params, "username"), sunum);
00588
00589
00590
00591
00592
00593
00594 retlist = newkeylist();
00595 add_keys(params, &retlist);
00596
00597 if(!(status=SUMLIB_InfoGet(sunum, &retlist))) {
00598 if(!(set_client_handle(RESPPROG, (uint32_t)uid))) {
00599 freekeylist(&retlist);
00600
00601 rinfo = SUM_RESPPROG_ERR;
00602 send_ack();
00603 return((KEY *)1);
00604 }
00605 rinfo = 0;
00606 send_ack();
00607 setkey_int(&retlist, "STATUS", 0);
00608 return(retlist);
00609 }
00610 rinfo = status;
00611 freekeylist(&retlist);
00612 if(!drmssite_sunum_is_local(sunum))
00613 rinfo = SUM_SUNUM_NOT_LOCAL;
00614 send_ack();
00615 return((KEY *)1);
00616 }
00617
00618
00619
00620
00621 KEY *infodoArray_1(Sunumarray *params)
00622 {
00623 int reqcnt, i, status, filemode;
00624 double bytes = 10000000.0;
00625 char *partname, *effective_date;
00626 char filename[128], cmd[92];
00627
00628
00629 reqcnt = params->reqcnt;
00630 retlist = newkeylist();
00631 write_log("SUM_infoArray() id=%d for user=%s uid=%lu 1st sunum=%lu cnt=%d\n",
00632 rrid, params->username, params->uid, *params->sunums, reqcnt);
00633 if((status=SUMLIB_PavailGet(bytes,0,params->uid,0,&retlist))) {
00634 write_log("Can't alloc storage for %s in infodoArray_1()\n", params->username);
00635 freekeylist(&retlist);
00636 rinfo = status;
00637 send_ack();
00638 return((KEY *)1);
00639 }
00640 partname = getkey_str(retlist, "partn_name");
00641
00642
00643
00644
00645 sprintf(filename, "%s/infoarray.ans", partname);
00646 effective_date = (char *)get_effdate(0);
00647
00648
00649
00650
00651
00652
00653
00654
00655 free(partname);
00656 free(effective_date);
00657 freekeylist(&retlist);
00658 if(!(status=SUMLIB_InfoGetArray(params, filename, &filemode))) {
00659 if(!(set_client_handle(RESPPROG, (uint32_t)params->uid))) {
00660 write_log("**Error: infodoArray_1() can't set_client_handle for response\n");
00661 rinfo = SUM_RESPPROG_ERR;
00662 send_ack();
00663 return((KEY *)1);
00664 }
00665 rinfo = 0;
00666 send_ack();
00667 retlist = newkeylist();
00668 setkey_int(&retlist, "STATUS", 0);
00669 setkey_str(&retlist, "FILE", filename);
00670 setkey_int(&retlist, "filemode", filemode);
00671 setkey_uint64(&retlist, "uid", params->uid);
00672 setkey_int(&retlist, "reqcnt", reqcnt);
00673 return(retlist);
00674 }
00675 rinfo = status;
00676 send_ack();
00677 return((KEY *)1);
00678 }
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690 KEY *infodoX_1(KEY *params)
00691 {
00692 int status, reqcnt;
00693 uint64_t uid;
00694 uint64_t sunum = 0;
00695 sprintf(callername, "infodoX_1");
00696 if(findkey(params, "DEBUGFLG")) {
00697 debugflg = getkey_int(params, "DEBUGFLG");
00698 if(debugflg) {
00699 write_log("!!Keylist in infodoX_1() is:\n");
00700 keyiterate(logkey, params);
00701 }
00702 }
00703 sunum = getkey_uint64(params, "dsix_0");
00704 reqcnt = getkey_int(params, "reqcnt");
00705 uid = getkey_uint64(params, "uid");
00706
00707
00708
00709
00710
00711
00712 write_log("SUM_infoEx() id=%d for user=%s 1st sunum=%lu cnt=%d\n",
00713 rrid, GETKEY_str(params, "username"), sunum, reqcnt);
00714 retlist = newkeylist();
00715 add_keys(params, &retlist);
00716 if(!(status=SUMLIB_InfoGetEx(params, &retlist))) {
00717 if(!(set_client_handle(RESPPROG, (uint32_t)uid))) {
00718 write_log("**Error: infodoX_1() can't set_client_handle for response\n");
00719 freekeylist(&retlist);
00720
00721 rinfo = SUM_RESPPROG_ERR;
00722 send_ack();
00723 return((KEY *)1);
00724 }
00725 rinfo = 0;
00726 send_ack();
00727 setkey_int(&retlist, "STATUS", 0);
00728 return(retlist);
00729 }
00730 rinfo = status;
00731
00732
00733 send_ack();
00734 freekeylist(&retlist);
00735 return((KEY *)1);
00736 }
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756 KEY *putdo_1(KEY *params)
00757 {
00758 int status, i, reqcnt;
00759 uint64_t sunum = 0;
00760 uint64_t uid;
00761 char sysstr[128];
00762 char *cptr, *wd;
00763
00764 sprintf(callername, "putdo_1");
00765 if(findkey(params, "DEBUGFLG")) {
00766 debugflg = getkey_int(params, "DEBUGFLG");
00767 if(debugflg) {
00768 write_log("!!Keylist in putdo_1() is:\n");
00769 keyiterate(logkey, params);
00770 }
00771 }
00772 uid = getkey_uint64(params, "uid");
00773 reqcnt = getkey_int(params, "reqcnt");
00774 sunum = getkey_uint64(params, "dsix_0");
00775 write_log("SUM_put() id=%d for user=%s 1st sunum=%lu reqcnt=%d\n",
00776 rrid, GETKEY_str(params, "username"), sunum, reqcnt);
00777
00778
00779
00780
00781
00782
00783 retlist = newkeylist();
00784 add_keys(params, &retlist);
00785
00786
00787 for(i=0; i < reqcnt; i++) {
00788 sprintf(nametmp, "wd_%d", i);
00789 cptr = GETKEY_str(params, nametmp);
00790 sprintf(nametmp, "%s.chmown", logname);
00791 sprintf(sysstr, "%s/sum_chmown %s 1>> %s 2>&1",
00792 SUMBIN_BASEDIR, cptr, nametmp);
00793
00794
00795 if(system(sysstr)) {
00796 write_log("**Warning: Error on: %s. errno=%d\n", sysstr,errno);
00797 rinfo = 1;
00798 send_ack();
00799 freekeylist(&retlist);
00800 return((KEY *)1);
00801 }
00802
00803
00804 }
00805
00806
00807 if(!(status=SUM_Main_Update(params, &retlist))) {
00808 if(!(set_client_handle(RESPPROG, (uint32_t)uid))) {
00809 freekeylist(&retlist);
00810 rinfo = 1;
00811 send_ack();
00812 return((KEY *)1);
00813 }
00814 rinfo = 0;
00815 send_ack();
00816 setkey_int(&retlist, "STATUS", 0);
00817 return(retlist);
00818 }
00819 rinfo = status;
00820 send_ack();
00821 freekeylist(&retlist);
00822 return((KEY *)1);
00823 }
00824
00825
00826
00827
00828
00829
00830
00831
00832 KEY *closedo_1(KEY *params)
00833 {
00834 uint64_t uid;
00835 uint32_t tapeback;
00836 enum clnt_stat status;
00837 char *call_err;
00838 static struct timeval TIMEOUT = { 50, 0 };
00839
00840 if(findkey(params, "DEBUGFLG")) {
00841 debugflg = getkey_int(params, "DEBUGFLG");
00842 if(debugflg) {
00843 write_log("!!Keylist in closedo_1() is:\n");
00844 keyiterate(logkey, params);
00845 }
00846 }
00847 uid = getkey_uint64(params, "uid");
00848 if(findkey(params, "TAPERDACTIVE")) {
00849
00850 if(clnttape != 0) {
00851 retlist=newkeylist();
00852 add_keys(params, &retlist);
00853 write_log("Calling CLNTGONE from closedo_1() in sums uid=%lu\n", uid);
00854 status = clnt_call(clnttape,CLNTGONE, (xdrproc_t)xdr_Rkey, (char *)retlist,
00855 (xdrproc_t)xdr_uint32_t, (char *)&tapeback, TIMEOUT);
00856 if(status != RPC_SUCCESS) {
00857 if(status != RPC_TIMEDOUT) {
00858 call_err = clnt_sperror(clnttape, "Error clnt_call for CLNTGONE");
00859 write_log("%s %d %s\n", datestring(), status, call_err);
00860 } else {
00861 write_log("%s timeout ignored in closedo_1() CLNTGONE\n", datestring());
00862 }
00863 }
00864 if(tapeback == 1) {
00865 write_log("**Error in CLNTGONE call to tape_svc in sum_svc_proc.c\n");
00866 }
00867 freekeylist(&retlist);
00868 }
00869 }
00870
00871
00872
00873
00874
00875
00876 remsumopened(&sumopened_hdr, (uint32_t)uid);
00877 rinfo = SUMLIB_Close(params);
00878 write_log("SUM_close for user=%s uid=%lu\n",
00879 GETKEY_str(params, "USER"), getkey_uint64(params, "uid"));
00880 send_ack();
00881 return((KEY *)1);
00882 }
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896 KEY *nopdo_1(KEY *params)
00897 {
00898
00899 struct timeval NOPTIMEOUT = { 15, 0 };
00900 uint64_t uid;
00901 KEY *klist;
00902 char *call_err;
00903 char *usr;
00904 int ans;
00905 enum clnt_stat status;
00906
00907
00908 if(findkey(params, "DEBUGFLG")) {
00909 debugflg = getkey_int(params, "DEBUGFLG");
00910 if(debugflg) {
00911 write_log("!!Keylist in nopdo_1() is:\n");
00912 keyiterate(logkey, params);
00913 }
00914 }
00915 rinfo = 0;
00916 uid = getkey_uint64(params, "uid");
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950 write_log("SUM_nop for user=%s uid=%lu\n",
00951 GETKEY_str(params, "USER"), uid);
00952 send_ack();
00953 return((KEY *)1);
00954 }
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967 KEY *tapereconnectdo_1(KEY *params)
00968 {
00969 uint64_t uid;
00970 char *cptr, *dptr;
00971 char *user;
00972
00973 rinfo = 0;
00974 user = getkey_str(params, "USER");
00975 write_log("Tape reconnect for user=%s action=%s\n", user, GETKEY_str(params, "ACTION"));
00976 cptr = GETKEY_str(params, "ACTION");
00977 if(!strcmp(cptr, "close")) {
00978 write_log("sum_svc is closing on tape_svc about to be restarted\n");
00979 if(clnttape) clnt_destroy(clnttape);
00980 clnttape = 0;
00981 }
00982 else if(!strcmp(cptr, "reconnect")) {
00983
00984 clnttape_old = NULL;
00985 dptr = getkey_str(params, "HOST");
00986 if(!strcmp(dptr, "xim"))
00987 clnttape = clnt_create(dptr, TAPEPROG, TAPEVERS, "tcp");
00988 else
00989 clnttape = clnt_create(TAPEHOST, TAPEPROG, TAPEVERS, "tcp");
00990 if(!clnttape) {
00991 clnt_pcreateerror("Can't get client handle to tape_svc (from sum_svc)");
00992 write_log("Cannot connect to new tape_svc on d02\n");
00993 rinfo = 1;
00994
00995 }
00996 write_log("sum_svc has reconnected to restarted tape_svc\n");
00997 }
00998 else {
00999 write_log("Illegal action = %s sent to tapereconnectdo_1()\n", cptr);
01000 rinfo = -1;
01001 }
01002 send_ack();
01003 free(user);
01004 return((KEY *)1);
01005 }
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016 KEY *delseriesdo_1(KEY *params)
01017 {
01018 char *filename, *seriesname;
01019
01020 if(findkey(params, "DEBUGFLG")) {
01021 debugflg = getkey_int(params, "DEBUGFLG");
01022 if(debugflg) {
01023 write_log("!!Keylist in delseriesdo_1() is:\n");
01024 keyiterate(logkey, params);
01025 }
01026 }
01027 rinfo = 0;
01028 filename = getkey_str(params, "FILE");
01029 seriesname = getkey_str(params, "SERIESNAME");
01030 write_log("DELSERIESDO for user=%s\n", GETKEY_str(params, "USER"));
01031 send_ack();
01032
01033 SUMLIB_DelSeriesSU(filename, seriesname);
01034 free(filename); free(seriesname);
01035 return((KEY *)1);
01036 }
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093 KEY *sumrespdo_1(KEY *params)
01094 {
01095 FILE *fin;
01096 uint64_t uid;
01097 int pidcall;
01098 int found = 0;
01099 char idstr[128], string[196], pidstr[80];
01100 char *hostcall, *newstr;
01101
01102 if(findkey(params, "DEBUGFLG")) {
01103 debugflg = getkey_int(params, "DEBUGFLG");
01104 if(debugflg) {
01105 write_log("!!Keylist in sumrespdo_1() is:\n");
01106 keyiterate(logkey, params);
01107 }
01108 }
01109 retlist = newkeylist();
01110 add_keys(params, &retlist);
01111 current_client = (CLIENT *)getkey_fileptr(params, "current_client");
01112 rinfo = 0;
01113 send_ack();
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131 if(findkey(params, "pidcaller")) {
01132 pidcall = getkey_int(params, "pidcaller");
01133 hostcall = getkey_str(params, "hostcaller");
01134 sprintf(idstr, "ssh -o \"StrictHostKeyChecking no\" %s ps -p %d -o pid= -o cmd=", hostcall, pidcall);
01135 if(fin = popen(idstr, "r")) {
01136 sprintf(pidstr, "%d ", pidcall);
01137 while(fgets(string, sizeof string, fin)) {
01138
01139 if(strstr(string, pidstr)) { found = 1; }
01140 }
01141 pclose(fin);
01142 }
01143 if(!found) {
01144 write_log("**Error: %s process is gone when tape rd completes\n",
01145 getkey_str(params, "username"));
01146 return((KEY *)1);
01147 }
01148 }
01149
01150 return(retlist);
01151 }
01152
01153
01154 void write_time()
01155 {
01156 struct timeval tvalr;
01157 struct tm *t_ptr;
01158 char datestr[32];
01159
01160 gettimeofday(&tvalr, NULL);
01161 t_ptr = localtime((const time_t *)&tvalr);
01162 sprintf(datestr, "%s", asctime(t_ptr));
01163 write_log("**** %s", datestr);
01164 }
01165
01166
01167 char *trimwhitespace(char *str)
01168 {
01169 char *end;
01170
01171 while(isspace(*str)) str++;
01172 if(*str == 0)
01173 return str;
01174
01175 end = str + strlen(str) - 1;
01176 while(end > str && isspace(*end)) end--;
01177 *(end+1) = 0;
01178 return str;
01179 }