00001 /* call_drms_inq.c 00002 * Gets the wd of the ARG_DATA_IN datasets 00003 */ 00004 #include <stdio.h> 00005 #include <drms.h> 00006 #include <drms_names.h> 00007 #include <soi_key.h> 00008 #include <printk.h> 00009 00010 extern DRMS_Env_t *drms_env; 00011 extern void printkey (KEY *key); 00012 extern void abortit(); 00013 extern int ampexflg; // 1 = retrieve from tape 00014 extern int wdonly; // 1 = only get the wd info 00015 extern SUM_t *sumhandle; 00016 00017 static KEY *alist; 00018 00019 #define out_namespace "dsds" 00020 //#define out_namespace "su_production" 00021 00022 /************************OLD************************************************* 00023 //Take the su dir and convert to the corresponding ds_index (i.e. sunum) 00024 int path2index(char *path, ulong *dsindex) { 00025 char pathx[DRMS_MAXPATHLEN]; 00026 char *cptr, *cptr2; 00027 00028 strcpy(pathx, path); 00029 cptr = strstr(pathx, "/D"); //find first /D 00030 if(!cptr) { 00031 printk("**Error: no /D in path %s\n", pathx); 00032 printk("**Use the -A flag if need to bring data on-line\n"); 00033 return(1); 00034 } 00035 //if there's a second /D then that is the orig one that we want 00036 cptr2 = strstr(cptr+1, "/D"); 00037 if(cptr2) cptr = cptr2; 00038 cptr2 = index(cptr+1, '/'); //elim an other '/' after sunum 00039 if(cptr2) *cptr = NULL; 00040 cptr2 = cptr+2; //skip the /D 00041 *dsindex = strtoul(cptr2, NULL, 0); 00042 return(0); 00043 } 00044 ************************OLD*************************************************/ 00045 00046 00047 /* 00048 * Uses extern ampexflg, wdonly, and sumhandle; 00049 * 00050 * Here an example of a keylist received here: 00051 * (the args are given by arg_data_in_0, arg_data_in_1, etc) 00052 * 00053 *lago_tid: KEYTYP_INT 0 00054 *pds_host: KEYTYP_STRING d00 00055 *dsds_uid: KEYTYP_UINT 0 00056 *alsoin_2_basename: KEYTYP_STRING fd_V_01h.029795 00057 *alsoin_2_wd: KEYTYP_STRING /tmp40/jim/tmp/lev1.5/fd_V_01h/29795 00058 *alsoin_2_rule: KEYTYP_STRING wd:{dbase}/{level}/{series}/{#%04d#series};bn:{series}.{#%06d#series} 00059 *alsoin_1_basename: KEYTYP_STRING fd_V_01h.029794 00060 *alsoin_1_wd: KEYTYP_STRING /tmp40/jim/tmp/lev1.5/fd_V_01h/29794 00061 *alsoin_1_rule: KEYTYP_STRING wd:{dbase}/{level}/{series}/{#%04d#series};bn:{series}.{#%06d#series} 00062 *alsoin_0_basename: KEYTYP_STRING fd_V_01h.029793 00063 *alsoin_0_wd: KEYTYP_STRING /tmp40/jim/tmp/lev1.5/fd_V_01h/29793 00064 *alsoin_0_rule: KEYTYP_STRING wd:{dbase}/{level}/{series}/{#%04d#series};bn:{series}.{#%06d#series} 00065 *alsoin_2_dbase: KEYTYP_STRING /tmp40/jim/tmp 00066 *alsoin_1_dbase: KEYTYP_STRING /tmp40/jim/tmp 00067 *alsoin_0_dbase: KEYTYP_STRING /tmp40/jim/tmp 00068 *alsoin_0_series_sn: KEYTYP_INT 29793 00069 *alsoin_0_fmt: KEYTYP_STRING %04d 00070 *alsoin_0_incr: KEYTYP_INT 1 00071 *alsoin_0_lsn: KEYTYP_INT -1 00072 *alsoin_0_fsn: KEYTYP_INT 0 00073 *alsoin_0_data: KEYTYP_STRING prog:mdi,level:lev1.5,series:fd_V_01h[29793-29795] 00074 *alsoin_0_prog: KEYTYP_STRING mdi 00075 *alsoin_0_level: KEYTYP_STRING lev1.5 00076 *alsoin_0_series: KEYTYP_STRING fd_V_01h 00077 *alsoin_0_series_range: KEYTYP_STRING 29793,29794,29795 00078 *alsoin_1_series_sn: KEYTYP_INT 29794 00079 *alsoin_1_fmt: KEYTYP_STRING %04d 00080 *alsoin_1_incr: KEYTYP_INT 1 00081 *alsoin_1_lsn: KEYTYP_INT -1 00082 *alsoin_1_fsn: KEYTYP_INT 0 00083 *alsoin_1_data: KEYTYP_STRING prog:mdi,level:lev1.5,series:fd_V_01h[29793-29795] 00084 *alsoin_1_prog: KEYTYP_STRING mdi 00085 *alsoin_1_level: KEYTYP_STRING lev1.5 00086 *alsoin_1_series: KEYTYP_STRING fd_V_01h 00087 *alsoin_1_series_range: KEYTYP_STRING 29793,29794,29795 00088 *alsoin_2_series_sn: KEYTYP_INT 29795 00089 *alsoin_2_fmt: KEYTYP_STRING %04d 00090 *alsoin_2_incr: KEYTYP_INT 1 00091 *alsoin_2_lsn: KEYTYP_INT -1 00092 *alsoin_2_fsn: KEYTYP_INT 0 00093 *alsoin_2_data: KEYTYP_STRING prog:mdi,level:lev1.5,series:fd_V_01h[29793-29795] 00094 *alsoin_2_prog: KEYTYP_STRING mdi 00095 *alsoin_2_level: KEYTYP_STRING lev1.5 00096 *alsoin_2_series: KEYTYP_STRING fd_V_01h 00097 *alsoin_2_series_range: KEYTYP_STRING 29793,29794,29795 00098 *alsoin_nsets: KEYTYP_INT 3 00099 *alsoin_dbase: KEYTYP_STRING /tmp40/jim/tmp 00100 *arg_data_in_1: KEYTYP_STRING alsoin 00101 *in_0_basename: KEYTYP_STRING 00102 *in_0_wd: KEYTYP_STRING . 00103 *in_basename: KEYTYP_STRING 00104 *in_wd: KEYTYP_STRING . 00105 *in_0_dbase: KEYTYP_STRING /tmp40/jim/tmp 00106 *in_0_series_sn: KEYTYP_INT -1 00107 *in_0_fmt: KEYTYP_STRING %04d 00108 *in_0_incr: KEYTYP_INT 1 00109 *in_0_lsn: KEYTYP_INT -1 00110 *in_0_fsn: KEYTYP_INT 0 00111 *in_0_data: KEYTYP_STRING prog:mdi_klist,level:copy,series:vw_V[-1] 00112 *in_0_prog: KEYTYP_STRING mdi_klist 00113 *in_0_level: KEYTYP_STRING copy 00114 *in_0_series: KEYTYP_STRING vw_V 00115 *in_0_series_range: KEYTYP_STRING -1 00116 *in_fmt: KEYTYP_STRING %04d 00117 *in_incr: KEYTYP_INT 1 00118 *in_lsn: KEYTYP_INT -1 00119 *in_fsn: KEYTYP_INT 0 00120 *in_data: KEYTYP_STRING prog:mdi_klist,level:copy,series:vw_V[-1] 00121 *in_prog: KEYTYP_STRING mdi_klist 00122 *in_level: KEYTYP_STRING copy 00123 *in_series: KEYTYP_STRING vw_V 00124 *in_series_sn: KEYTYP_INT -1 00125 *in_series_range: KEYTYP_STRING -1 00126 *in_nsets: KEYTYP_INT 1 00127 *in_dbase: KEYTYP_STRING /tmp40/jim/tmp 00128 *arg_data_in_0: KEYTYP_STRING in 00129 *dlocalflg: KEYTYP_INT 0 00130 *db: KEYTYP_STRING mdi_2 00131 *anotherout: KEYTYP_STRING prog:mdi,level:tmp,series:test[666] 00132 *out: KEYTYP_STRING prog:mdi_raw,level:tlm,series:nxt2ser[3006,3007] 00133 *alsoin: KEYTYP_STRING prog:mdi,level:lev1.5,series:fd_V_01h[29793-29795] 00134 *in: KEYTYP_STRING prog:mdi_klist,level:copy,series:vw_V[-1] 00135 *T_FIRST: KEYTYP_STRING '1999.11.06_00:01:00_TAI' 00136 */ 00137 00138 KEY *call_drms_inq(KEY *list, int dbflg) 00139 { 00140 char drmsname[MAX_STR]; 00141 char cmd[128], buf[128]; 00142 char path[DRMS_MAXPATHLEN] = {0}; 00143 char *stmp, *cptr; 00144 DRMS_RecordSet_t *rset; 00145 DRMS_Record_t *rec; 00146 SUM_info_t *sinfo; 00147 uint64_t sunum; 00148 FILE *fin; 00149 char argname[MAX_STR], inname[MAX_STR], ext[MAX_STR]; 00150 double dbytes; 00151 ulong dsindex; 00152 int i, loop, innsets, rstatus, touch; 00153 int restoreenv = 0; 00154 int num_ds = 0; /* total # of ds queried */ 00155 int ntmp; 00156 00157 alist = newkeylist(); 00158 for(loop = 0; ; loop++) { 00159 sprintf(ext, "arg_data_in_%d", loop); 00160 if(!findkey(list, ext)) break; /* all done, exit for(loop)*/ 00161 strcpy(argname, GETKEY_str(list, ext)); /* e.g. "in" */ 00162 strcpy(inname, argname); strcat(inname, "_nsets"); 00163 innsets = getkey_int(list, inname); 00164 for(i=0; i < innsets; i++) { /* do for each dataset */ 00165 sprintf(ext, "_%d", i); 00166 strcpy(inname, argname); strcat(inname, ext); /* e.g. "in_0" */ 00167 setkey_str(&alist, "inname", inname); 00168 sprintf(ext, "inname_%d", num_ds); 00169 setkey_str(&alist, ext, inname); /* also make unique inname*/ 00170 sprintf(ext, "%s_prog", inname); //e.g. in_0_prog 00171 stmp = GETKEY_str(list, ext); 00172 if(!strcmp(stmp, "")) { 00173 printk("ERROR: you didn't give me a DSDS style name, i.e. prog:\n"); 00174 continue; //not a ds name 00175 } 00176 sprintf(drmsname, "%s__", stmp); 00177 00178 // setkey_str(&alist, ext, GETKEY_str(list, ext)); 00179 // sprintf(ext, "%s_prog_sn", inname); 00180 // if(findkey(list, ext)) 00181 // setkey_int(&alist, ext, getkey_int(list, ext)); 00182 sprintf(ext, "%s_level", inname); 00183 stmp = GETKEY_str(list, ext); 00184 sprintf(drmsname, "%s%s__", drmsname, stmp); 00185 sprintf(ext, "%s_series", inname); 00186 stmp = GETKEY_str(list, ext); 00187 sprintf(drmsname, "%s%s", drmsname, stmp); 00188 sprintf(cmd, "echo \"%s\" | sed 's/\\\./_/g' | sed 's/-/__/g'", drmsname); 00189 //printf("cmd = %s\n", cmd); 00190 fin = popen(cmd, "r"); 00191 fgets(buf, sizeof buf, fin); 00192 cptr = rindex(buf, '\n'); 00193 if(cptr) *cptr = NULL; 00194 sprintf(ext, "%s_series_sn", inname); 00195 if(findkey(list, ext)) { 00196 ntmp = getkey_int(list, ext); 00197 } 00198 else ntmp = -1; 00199 sprintf(buf, "%s[%d]", buf, ntmp); 00200 sprintf(drmsname, "%s.%s", out_namespace, buf); 00201 00202 if(findkey(list, ext)) 00203 setkey_int(&alist, ext, getkey_int(list, ext)); 00204 if(findkey(list, "touch")) { 00205 touch = getkey_int(list, "touch"); 00206 setkey_int(&alist, "touch", touch); 00207 restoreenv = drms_env->retention; 00208 drms_env->retention = touch; 00209 } 00210 if(findkey(list, "ampex_tid")) 00211 setkey_int(&alist, "ampex_tid", getkey_int(list, "ampex_tid")); 00212 00213 //printf("drmsname=%s\nThe keylist for call_drms_inq():\n",drmsname); 00214 //keyiterate(printkey, list); 00215 00216 rset = drms_open_records(drms_env, drmsname, &rstatus); 00217 if(rstatus) { 00218 printk("Can't do drms_open_records(%s)\n", drmsname); 00219 return(NULL); 00220 } 00221 sprintf(ext, "%s_wd", inname); 00222 if(!rset || rset->n == 0) { 00223 printk("No prev ds for %s\n", drmsname); 00224 setkey_str(&alist, ext, ""); //send back empty wd 00225 } 00226 else { 00227 if(rstatus = drms_stage_records(rset, 0, 1)) { 00228 printk("Can't do drms_stage_records() for %s\n", drmsname); 00229 return(NULL); 00230 } 00231 rec = rset->records[0]; /* !!TBD fix 0 when more than one */ 00232 if(!ampexflg) { 00233 rstatus = drms_record_directory (rec, path, 0); 00234 } else { 00235 printk("Possible wait for drms retrieve from tape...\n"); 00236 rstatus = drms_record_directory (rec, path, 1); 00237 } 00238 setkey_str(&alist, ext, path); 00239 sprintf(ext, "status_%d", num_ds); 00240 setkey_int(&alist, ext, rstatus); 00241 dbytes = du_dir(path); 00242 sprintf(ext, "%s_bytes", inname); 00243 setkey_double(&alist, ext, dbytes); 00244 dsindex = rec->sunum; 00245 sprintf(ext, "%s_ds_index", inname); 00246 setkey_ulong(&alist, ext, dsindex); 00247 if(!wdonly) { //need to get info from SUM_info() 00248 sunum = (uint64_t)(rec->sunum); 00249 00250 /* SUM_info() is not supported by the new MT SUMS. Convert to SUM_infoArray(), 00251 * providing an array of size one. A better solution would be to re-write the 00252 * enclosing loop to batch the records. This way, many records could be 00253 * opened at once, and then a chunk of SUNUMs could be provided to 00254 * SUM_infoArray(). However, this program isn't likely to be used again, 00255 * so we'll leave the loop inefficient. 00256 */ 00257 if(SUM_infoArray(sumhandle, &sunum, 1, printk)) { 00258 printk("Fail on SUM_info() for sunum=%u\n", dsindex); 00259 } 00260 else { 00261 /* sumhandle->sinfo is the first node in a linked list of size one. */ 00262 sinfo = sumhandle->sinfo; 00263 sprintf(ext, "%s_creat_date", inname); 00264 setkey_str(&alist, ext, sinfo->creat_date); 00265 sprintf(ext, "%s_archive_status", inname); 00266 setkey_str(&alist, ext, sinfo->archive_status); 00267 sprintf(ext, "%s_bytes", inname); 00268 setkey_double(&alist, ext, sinfo->bytes); 00269 } 00270 } 00271 //printk("In call_drms_inq() ext=%s dsindex=%u\n", ext, dsindex); 00272 //keyiterate(printkey, alist); //!!TEMP 00273 } 00274 num_ds++; 00275 } 00276 if(restoreenv != 0) drms_env->retention = restoreenv; 00277 } 00278 return(alist); 00279 }