00001
00002
00003
00004
00005 #include <SUM.h>
00006 #include <soi_key.h>
00007 #include <sys/time.h>
00008 #include <sys/errno.h>
00009 #include <rpc/rpc.h>
00010 #include <sum_rpc.h>
00011 #include <soi_error.h>
00012
00013
00014 #include <sys/mtio.h>
00015
00016 #include <scsi/sg.h>
00017 #include <stdio.h>
00018 #include <sys/types.h>
00019 #include <sys/stat.h>
00020 #include <dirent.h>
00021
00022
00023 int SUM_drop_series(char *tablename);
00024
00025 extern int errno;
00026
00027
00028
00029
00030
00031 KEY *rlist;
00032 FILE *logfp;
00033 SUM_t *sum;
00034 SUMID_t uid;
00035
00036 int soi_errno = NO_ERROR;
00037 int bytes, msgtag, petid, req_num, status, cnt, i, j, k, inum;
00038 char **cptr;
00039 float ftmp;
00040 uint64_t *dsixpt;
00041 uint64_t alloc_index, alloc_indexA, alloc_indexB;
00042 char alloc_wd[64], alloc_wdA[64], alloc_wdB[64];
00043 char cmd[128];
00044 char mod_name[] = "sum_rpc";
00045
00046 char dsname[] = "main5";
00047 char hcomment[] = "this is a dummy history comment that is greater than 80 chars long to check out the code";
00048
00049 static struct timeval first[8], second[8];
00050
00051 void StartTimer(int n)
00052 {
00053 gettimeofday (&first[n], NULL);
00054 }
00055
00056 float StopTimer(int n)
00057 {
00058 gettimeofday (&second[n], NULL);
00059 if (first[n].tv_usec > second[n].tv_usec) {
00060 second[n].tv_usec += 1000000;
00061 second[n].tv_sec--;
00062 }
00063 return (float) (second[n].tv_sec-first[n].tv_sec) +
00064 (float) (second[n].tv_usec-first[n].tv_usec)/1000000.0;
00065 }
00066
00067
00068
00069
00070
00071 int main(int argc, char *argv[])
00072 {
00073
00074
00075
00076 if((sum = SUM_open("n02", NULL, printf)) == 0) {
00077 printf("Failed on SUM_open()\n");
00078 exit(1);
00079 }
00080 uid = sum->uid;
00081
00082
00083 sum->username = "production";
00084
00085 printf("Opened with sumid = %d\n", uid);
00086
00087
00088 sum->bytes = (double)120000000;
00089 sum->reqcnt = 1;
00090 sum->group = 0;
00091
00092 StartTimer(0);
00093 if(status = SUM_alloc(sum, printf)) {
00094 printf("SUM_alloc() failed to alloc %g bytes. Error code = %d\n",
00095 sum->bytes, status);
00096 SUM_close(sum, printf);
00097 exit(1);
00098 }
00099 ftmp = StopTimer(0);
00100 printf("Time for SUM_alloc() = %f sec\n", ftmp);
00101 cptr = sum->wd;
00102 dsixpt = sum->dsix_ptr;
00103 alloc_index = *dsixpt;
00104 strcpy(alloc_wd, *cptr);
00105 printf("Allocated %g bytes at %s with dsindex=%lu\n",
00106 sum->bytes, *cptr, alloc_index);
00107
00108 sprintf(cmd, "cp -rp /home/jim/junk %s", *cptr);
00109
00110
00111 sprintf(cmd, "touch %s/%s%d", *cptr, "touch", uid);
00112
00113
00114
00115 if(status = SUM_alloc(sum, printf)) {
00116 printf("SUM_alloc() failed to alloc %g bytes. Error code = %d\n",
00117 sum->bytes, status);
00118 SUM_close(sum, printf);
00119 exit(1);
00120 }
00121 cptr = sum->wd;
00122 dsixpt = sum->dsix_ptr;
00123 alloc_indexA = *dsixpt;
00124 strcpy(alloc_wdA, *cptr);
00125 printf("Allocated %g bytes at %s with dsindex=%lu\n",
00126 sum->bytes, *cptr, alloc_indexA);
00127
00128 sprintf(cmd, "cp -rp /home/jim/junk %s", *cptr);
00129
00130
00131 sprintf(cmd, "touch %s/%s%d", *cptr, "touch", uid);
00132
00133
00134
00135 if(status = SUM_alloc(sum, printf)) {
00136 printf("SUM_alloc() failed to alloc %g bytes. Error code = %d\n",
00137 sum->bytes, status);
00138 SUM_close(sum, printf);
00139 exit(1);
00140 }
00141 cptr = sum->wd;
00142 dsixpt = sum->dsix_ptr;
00143 alloc_indexB = *dsixpt;
00144 strcpy(alloc_wdB, *cptr);
00145 printf("Allocated %g bytes at %s with dsindex=%lu\n",
00146 sum->bytes, *cptr, alloc_indexB);
00147
00148 sprintf(cmd, "cp -rp /home/jim/junk %s", *cptr);
00149
00150
00151 sprintf(cmd, "touch %s/%s%d", *cptr, "touch", uid);
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 sum->mode = TEMP;
00211
00212
00213
00214
00215 sum->group = k;
00216
00217 sum->group = 666;
00218
00219 sum->reqcnt = 1;
00220 dsixpt = sum->dsix_ptr;
00221 *dsixpt++ = alloc_index;
00222 *dsixpt++ = alloc_indexA;
00223 *dsixpt++ = alloc_indexB;
00224
00225 cptr = sum->wd;
00226 *cptr = (char *)malloc(64);
00227 strcpy(*cptr, alloc_wd);
00228 *cptr++;
00229 *cptr = (char *)malloc(64);
00230 strcpy(*cptr, alloc_wdA);
00231 *cptr++;
00232 *cptr = (char *)malloc(64);
00233 strcpy(*cptr, alloc_wdB);
00234 sum->dsname = dsname;
00235 sum->history_comment = hcomment;
00236
00237 sum->storeset = 0;
00238
00239
00240
00241 for(i=0; i < 3; i++) {
00242 dsixpt = sum->dsix_ptr;
00243 if(i==0) *dsixpt = alloc_index;
00244 if(i==1) *dsixpt = alloc_indexA;
00245 if(i==2) *dsixpt = alloc_indexB;
00246 if(SUM_put(sum, printf)) {
00247 printf("Error: on SUM_put()\n");
00248 }
00249 else {
00250 cptr = sum->wd;
00251 printf("The put wd = %s\n", *cptr);
00252 }
00253 }
00254
00255
00256
00257
00258 SUM_close(sum, printf);
00259
00260 }