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 extern int errno;
00014
00015
00016
00017
00018
00019 KEY *rlist;
00020 FILE *logfp;
00021 SUM_t *sum;
00022 SUMID_t uid;
00023
00024 int soi_errno = NO_ERROR;
00025 int bytes, msgtag, petid, req_num, status, cnt, i, j, k, inum;
00026 char **cptr;
00027 float ftmp;
00028 uint64_t *dsixpt;
00029 uint64_t alloc_index, alloc_indexA, alloc_indexB;
00030 char alloc_wd[64], alloc_wdA[64], alloc_wdB[64];
00031 char cmd[128];
00032 char mod_name[] = "sum_rpc";
00033
00034 char dsname[] = "main4";
00035 char hcomment[] = "this is a dummy history comment that is greater than 80 chars long to check out the code";
00036
00037 static struct timeval first[8], second[8];
00038
00039 void StartTimer(int n)
00040 {
00041 gettimeofday (&first[n], NULL);
00042 }
00043
00044 float StopTimer(int n)
00045 {
00046 gettimeofday (&second[n], NULL);
00047 if (first[n].tv_usec > second[n].tv_usec) {
00048 second[n].tv_usec += 1000000;
00049 second[n].tv_sec--;
00050 }
00051 return (float) (second[n].tv_sec-first[n].tv_sec) +
00052 (float) (second[n].tv_usec-first[n].tv_usec)/1000000.0;
00053 }
00054
00055
00056
00057
00058
00059 int main(int argc, char *argv[])
00060 {
00061
00062
00063 if((sum = SUM_open(NULL, NULL, printf)) == 0) {
00064 printf("Failed on SUM_open()\n");
00065 exit(1);
00066 }
00067 uid = sum->uid;
00068
00069
00070 sum->username = "production";
00071
00072 printf("Opened with sumid = %d\n", uid);
00073
00074
00075 sum->bytes = (double)120000000;
00076 sum->reqcnt = 1;
00077
00078 StartTimer(0);
00079 if(status = SUM_alloc(sum, printf)) {
00080 printf("SUM_alloc() failed to alloc %g bytes. Error code = %d\n",
00081 sum->bytes, status);
00082 SUM_close(sum, printf);
00083 exit(1);
00084 }
00085 ftmp = StopTimer(0);
00086 printf("Time for SUM_alloc() = %f sec\n", ftmp);
00087 cptr = sum->wd;
00088 dsixpt = sum->dsix_ptr;
00089 alloc_index = *dsixpt;
00090 strcpy(alloc_wd, *cptr);
00091 printf("Allocated %g bytes at %s with dsindex=%lu\n",
00092 sum->bytes, *cptr, alloc_index);
00093
00094 sprintf(cmd, "cp -rp /home/jim/junk %s", *cptr);
00095 printf("cmd is: %s\n", cmd);
00096 system(cmd);
00097 sprintf(cmd, "touch %s/%s%d", *cptr, "touch", uid);
00098 printf("cmd is: %s\n", cmd);
00099 system(cmd);
00100
00101 if(status = SUM_alloc(sum, printf)) {
00102 printf("SUM_alloc() failed to alloc %g bytes. Error code = %d\n",
00103 sum->bytes, status);
00104 SUM_close(sum, printf);
00105 exit(1);
00106 }
00107 cptr = sum->wd;
00108 dsixpt = sum->dsix_ptr;
00109 alloc_indexA = *dsixpt;
00110 strcpy(alloc_wdA, *cptr);
00111 printf("Allocated %g bytes at %s with dsindex=%lu\n",
00112 sum->bytes, *cptr, alloc_indexA);
00113
00114 sprintf(cmd, "cp -rp /home/jim/junk %s", *cptr);
00115 printf("cmd is: %s\n", cmd);
00116 system(cmd);
00117 sprintf(cmd, "touch %s/%s%d", *cptr, "touch", uid);
00118 printf("cmd is: %s\n", cmd);
00119 system(cmd);
00120
00121 if(status = SUM_alloc(sum, printf)) {
00122 printf("SUM_alloc() failed to alloc %g bytes. Error code = %d\n",
00123 sum->bytes, status);
00124 SUM_close(sum, printf);
00125 exit(1);
00126 }
00127 cptr = sum->wd;
00128 dsixpt = sum->dsix_ptr;
00129 alloc_indexB = *dsixpt;
00130 strcpy(alloc_wdB, *cptr);
00131 printf("Allocated %g bytes at %s with dsindex=%lu\n",
00132 sum->bytes, *cptr, alloc_indexB);
00133
00134 sprintf(cmd, "cp -rp /home/jim/junk %s", *cptr);
00135 printf("cmd is: %s\n", cmd);
00136 system(cmd);
00137 sprintf(cmd, "touch %s/%s%d", *cptr, "touch", uid);
00138 printf("cmd is: %s\n", cmd);
00139 system(cmd);
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
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 sum->mode = TEMP;
00197
00198
00199
00200
00201 sum->group = k;
00202
00203 sum->group = 666;
00204 sum->reqcnt = 3;
00205 dsixpt = sum->dsix_ptr;
00206 *dsixpt++ = alloc_index;
00207 *dsixpt++ = alloc_indexA;
00208 *dsixpt++ = alloc_indexB;
00209
00210 cptr = sum->wd;
00211 *cptr = (char *)malloc(64);
00212 strcpy(*cptr, alloc_wd);
00213 *cptr++;
00214 *cptr = (char *)malloc(64);
00215 strcpy(*cptr, alloc_wdA);
00216 *cptr++;
00217 *cptr = (char *)malloc(64);
00218 strcpy(*cptr, alloc_wdB);
00219 sum->dsname = dsname;
00220 sum->history_comment = hcomment;
00221
00222 sum->storeset = 0;
00223
00224
00225 if(SUM_put(sum, printf)) {
00226 printf("Error: on SUM_put()\n");
00227 }
00228 else {
00229 cptr = sum->wd;
00230 for(i=0; i < sum->reqcnt; i++) {
00231 printf("The put wd = %s\n", *cptr++);
00232 }
00233 }
00234
00235
00236
00237
00238 SUM_close(sum, printf);
00239
00240 }