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