Masanobu Yasui authored on 2008/12/12 15:37:28
Showing 6 changed files
... ...
@@ -85,7 +85,7 @@ uint8_t rstatenumlist[]={MAKUO_RECVSTATE_NONE,
85 85
                          MAKUO_RECVSTATE_CLOSEERROR,
86 86
                          MAKUO_STATE_MAX};
87 87
 
88
-char *SSTATE(uint8_t n)
88
+char *strsstate(uint8_t n)
89 89
 {
90 90
   int i;
91 91
   for(i=0;sstatenumlist[i] != MAKUO_STATE_MAX;i++){
... ...
@@ -96,7 +96,7 @@ char *SSTATE(uint8_t n)
96 96
   return(sstatestrlist[i]);
97 97
 }
98 98
 
99
-char *RSTATE(uint8_t n)
99
+char *strrstate(uint8_t n)
100 100
 {
101 101
   int i;
102 102
   for(i=0;rstatenumlist[i] != MAKUO_STATE_MAX;i++){
... ...
@@ -107,11 +107,19 @@ char *RSTATE(uint8_t n)
107 107
   return(rstatestrlist[i]);
108 108
 }
109 109
 
110
-char *OPCODE(uint8_t n)
110
+char *strmstate(mdata *data)
111
+{
112
+  if(data->head.flags & MAKUO_FLAG_ACK){
113
+    return(strrstate(data->head.nstate));
114
+  }
115
+  return(strsstate(data->head.nstate));
116
+}
117
+
118
+char *stropcode(mdata *data)
111 119
 {
112 120
   int i;
113 121
   for(i=0;opcodenumlist[i] != MAKUO_STATE_MAX;i++){
114
-    if(opcodenumlist[i] == n){
122
+    if(opcodenumlist[i] == data->head.opcode){
115 123
       break;
116 124
     }
117 125
   }
... ...
@@ -191,6 +199,11 @@ excludeitem *mfnmatch(char *str, excludeitem *exclude)
191 191
   return(NULL);
192 192
 }
193 193
 
194
+int isexclude(char *str, excludeitem *exclude)
195
+{
196
+
197
+}
198
+
194 199
 void fdprintf(int s, char *fmt, ...)
195 200
 {
196 201
   char m[2048];
... ...
@@ -241,15 +254,14 @@ void cprintf(int l, mcomm *c, char *fmt, ...)
241 241
 
242 242
 void mprintf(const char *func, mfile *m)
243 243
 {
244
-  char *st;
245
-  char *op;
246
-  if(m->mdata.head.flags & MAKUO_FLAG_ACK){
247
-    st = RSTATE(m->mdata.head.nstate);
248
-  }else{
249
-    st = SSTATE(m->mdata.head.nstate);
250
-  }
251
-  op = OPCODE(m->mdata.head.opcode);
252
-  lprintf(9, "%s: rid=%d init=%d wait=%d %s %s %s %s\n", func, m->mdata.head.reqid, m->initstate, m->sendwait, inet_ntoa(m->addr.sin_addr), op, st, m->fn);
244
+  lprintf(9, "%s: rid=%d init=%d wait=%d %s %s %s %s\n",
245
+    func, 
246
+    m->mdata.head.reqid, 
247
+    m->initstate, m->sendwait, 
248
+    inet_ntoa(m->addr.sin_addr), 
249
+    stropcode(&(m->mdata)),
250
+    strmstate(&(m->mdata)),
251
+    m->fn);
253 252
 }
254 253
 
255 254
 int getrid()
... ...
@@ -503,7 +515,7 @@ void dump_hoststate(mfile *m, char *func)
503 503
   uint8_t *r;
504 504
   for(t=members;t;t=t->next){
505 505
     if(r=get_hoststate(t,m)){
506
-      lprintf(9,"%s: rstate=%s from %s %s\n", func, RSTATE(*r), t->hostname, m->fn);
506
+      lprintf(9,"%s: %s from %s %s\n", func, strrstate(*r), t->hostname, m->fn);
507 507
     }
508 508
   }
509 509
 }
... ...
@@ -200,6 +200,9 @@ int mfdirchk(mfile *d){
200 200
   if(d->fn[len - 1] == '/'){
201 201
     len--;
202 202
   }
203
+  if(d->mdata.head.flags & MAKUO_FLAG_ACK){
204
+    return(1);
205
+  }
203 206
   for(m=mftop[0];m;m=m->next){
204 207
     if(m == d){
205 208
       continue;
... ...
@@ -8,7 +8,6 @@
8 8
 #define PROTOCOL_VERSION 4
9 9
 #define _GNU_SOURCE
10 10
 #define _FILE_OFFSET_BITS 64
11
-#define MAKUO_DEBUG
12 11
 #include <stdio.h>
13 12
 #include <unistd.h>
14 13
 #include <stdlib.h>
... ...
@@ -276,9 +275,10 @@ extern struct timeval curtime;
276 276
 extern BF_KEY EncKey;
277 277
 
278 278
 /*----- function -----*/
279
-char    *SSTATE(uint8_t n);
280
-char    *RSTATE(uint8_t n);
281
-char    *OPCODE(uint8_t n);
279
+char    *strsstate(uint8_t n);
280
+char    *strrstate(uint8_t n);
281
+char    *strmstate(mdata *data);
282
+char    *stropcode(mdata *data);
282 283
 void     mprintf(const char *func, mfile *m);
283 284
 void     lprintf(int l, char *fmt, ...);
284 285
 void     cprintf(int l, mcomm *c, char *fmt, ...);
... ...
@@ -337,6 +337,15 @@ int mexec_send(mcomm *c, int n, int sync)
337 337
   while(optind < c->argc[n])
338 338
     fn = c->parse[n][optind++];
339 339
 
340
+  if(fn){
341
+    int len;
342
+    if(len = strlen(fn)){
343
+      if(fn[len - 1] == '/'){
344
+        fn[len - 1] = 0;
345
+      }
346
+    }
347
+  }
348
+
340 349
   /*----- directory scan -----*/
341 350
   if(recurs){
342 351
     if(c->cpid){
... ...
@@ -601,6 +610,15 @@ int mexec_dsync(mcomm *c, int n)
601 601
     fn = c->parse[n][optind++];
602 602
   }
603 603
 
604
+  if(fn){
605
+    int len;
606
+    if(len = strlen(fn)){
607
+      if(fn[len - 1] == '/'){
608
+        fn[len - 1] = 0;
609
+      }
610
+    }
611
+  }
612
+
604 613
   /*----- help -----*/
605 614
   if(c->argc[n]<2){
606 615
     cprintf(0, c, "dsync [-r] [-t host] [-n] [path]\r\n");
... ...
@@ -756,19 +774,14 @@ int mexec_status(mcomm *c, int n)
756 756
     if(snow > smax){
757 757
       snow = smax;
758 758
     }
759
-    if(m->mdata.head.flags & MAKUO_FLAG_ACK){
760
-      cprintf(0, c, "  (ack) %s %s %s (%u:%u/%u)\n", 
761
-        OPCODE(m->mdata.head.opcode), 
762
-        RSTATE(m->mdata.head.nstate), 
763
-        m->fn, 
764
-        m->markcount, snow, smax); 
765
-    }else{
766
-      cprintf(0, c, "  (req) %s %s %s (%u:%u/%u)\n", 
767
-        OPCODE(m->mdata.head.opcode), 
768
-        SSTATE(m->mdata.head.nstate), 
769
-        m->fn, 
770
-        m->markcount, snow, smax); 
771
-    }
759
+    cprintf(0, c, "  (ack) %s %s %s (%u:%u/%u) rid=%d\n", 
760
+      stropcode(&(m->mdata)), 
761
+      strmstate(&(m->mdata)), 
762
+      m->fn, 
763
+      m->markcount,
764
+      snow, 
765
+      smax,
766
+      m->mdata.head.reqid); 
772 767
   }
773 768
 
774 769
   count = 0;
... ...
@@ -777,13 +790,15 @@ int mexec_status(mcomm *c, int n)
777 777
   cprintf(0, c, "recv op: %d\n", count);
778 778
   for(m=mftop[1];m;m=m->next){
779 779
     t = localtime(&(m->lastrecv.tv_sec));
780
-    cprintf(0, c, "  %s %s %02d:%02d:%02d %s (%d/%d) mark=%d\n",
781
-      OPCODE(m->mdata.head.opcode), 
782
-      RSTATE(m->mdata.head.nstate), 
780
+    cprintf(0, c, "  %s %s %02d:%02d:%02d %s (%d/%d) mark=%d rid=%d\n",
781
+      stropcode(&(m->mdata)), 
782
+      strrstate(m->mdata.head.nstate), 
783 783
       t->tm_hour, t->tm_min, t->tm_sec, 
784 784
       m->fn, 
785
-      m->recvcount, m->seqnomax, 
786
-      m->markcount); 
785
+      m->recvcount,
786
+      m->seqnomax, 
787
+      m->markcount,
788
+      m->mdata.head.reqid); 
787 789
   }
788 790
   return(0);
789 791
 }
... ...
@@ -139,7 +139,10 @@ void mrecv_gc()
139 139
   while(m){
140 140
     if(mtimeout(&(m->lastrecv), MAKUO_RECV_GCWAIT)){
141 141
       if(MAKUO_RECVSTATE_CLOSE != m->mdata.head.nstate){
142
-        lprintf(0,"%s: mfile object GC state=%s %s\n", __func__, RSTATE(m->mdata.head.nstate), m->fn);
142
+        lprintf(0,"%s: mfile object GC state=%s %s\n",
143
+          __func__, 
144
+          strrstate(m->mdata.head.nstate), 
145
+          m->fn);
143 146
       }
144 147
       m = mrecv_mfdel(m);
145 148
       continue;
... ...
@@ -199,17 +202,17 @@ static void mrecv_ack_report(mfile *m, mhost *h, mdata *data)
199 199
   if(data->head.nstate == MAKUO_RECVSTATE_OPENERROR){
200 200
     cprintf(0, m->comm, "%s: file open error %s\n", h->hostname, m->fn);
201 201
     lprintf(0,          "%s: file open error rid=%06d state=%s %s(%s) %s\n", __func__,
202
-      data->head.reqid, RSTATE(data->head.nstate), inet_ntoa(h->ad), h->hostname, m->fn);
202
+      data->head.reqid, strrstate(data->head.nstate), inet_ntoa(h->ad), h->hostname, m->fn);
203 203
   }
204 204
   if(data->head.nstate == MAKUO_RECVSTATE_WRITEERROR){
205 205
     cprintf(0, m->comm, "%s: file write error %s\n", h->hostname, m->fn);
206 206
     lprintf(0,          "%s: file write error rid=%06d state=%s %s(%s) %s\n", __func__,
207
-     data->head.reqid, RSTATE(data->head.nstate), inet_ntoa(h->ad), h->hostname, m->fn);
207
+     data->head.reqid, strrstate(data->head.nstate), inet_ntoa(h->ad), h->hostname, m->fn);
208 208
   }
209 209
   if(data->head.nstate == MAKUO_RECVSTATE_CLOSEERROR){
210 210
     cprintf(0, m->comm, "%s: file close error %s\n", h->hostname, m->fn);
211 211
     lprintf(0,          "%s: file close error rid=%06d state=%s %s(%s) %s\n", __func__,
212
-      data->head.reqid, RSTATE(data->head.nstate), inet_ntoa(h->ad), h->hostname, m->fn);
212
+      data->head.reqid, strrstate(data->head.nstate), inet_ntoa(h->ad), h->hostname, m->fn);
213 213
   }
214 214
 }
215 215
 
... ...
@@ -289,7 +292,7 @@ static void mrecv_ack_dsync(mdata *data, struct sockaddr_in *addr)
289 289
   mhost *t;
290 290
   mfile *m;
291 291
 
292
-  lprintf(9, "%s: rid=%d %s\n", __func__, data->head.reqid, RSTATE(data->head.nstate));
292
+  lprintf(9, "%s: rid=%d %s\n", __func__, data->head.reqid, strmstate(data));
293 293
   if(data->head.nstate == MAKUO_RECVSTATE_CLOSE){
294 294
     mkreq(data, addr, MAKUO_SENDSTATE_LAST);
295 295
   }
... ...
@@ -322,7 +325,7 @@ static void mrecv_ack_del(mdata *data, struct sockaddr_in *addr)
322 322
   uint32_t err;
323 323
   uint16_t len;
324 324
 
325
-  lprintf(9, "%s: rid=%d %s\n", __func__, data->head.reqid, RSTATE(data->head.nstate));
325
+  lprintf(9, "%s: rid=%d %s\n", __func__, data->head.reqid, strmstate(data));
326 326
   if(mrecv_ack_search(&t, &m, data, addr)){
327 327
     return;
328 328
   }
... ...
@@ -807,12 +810,12 @@ static void mrecv_req_send_next(mfile *m, mdata *r)
807 807
 {
808 808
   switch(r->head.nstate){
809 809
     case MAKUO_SENDSTATE_STAT:
810
-      lprintf(9,"%s: %s/%s %s\n", __func__, SSTATE(r->head.nstate), RSTATE(m->mdata.head.nstate), m->fn);
810
+      lprintf(9,"%s: %s/%s %s\n", __func__, strsstate(r->head.nstate), strrstate(m->mdata.head.nstate), m->fn);
811 811
       mrecv_req_send_stat(m, r);
812 812
       break;
813 813
 
814 814
     case MAKUO_SENDSTATE_OPEN:
815
-      lprintf(9,"%s: %s/%s %s\n", __func__, SSTATE(r->head.nstate), RSTATE(m->mdata.head.nstate), m->fn);
815
+      lprintf(9,"%s: %s/%s %s\n", __func__, strsstate(r->head.nstate), strrstate(m->mdata.head.nstate), m->fn);
816 816
       mrecv_req_send_open(m, r);
817 817
       break;
818 818
 
... ...
@@ -822,22 +825,22 @@ static void mrecv_req_send_next(mfile *m, mdata *r)
822 822
 
823 823
     case MAKUO_SENDSTATE_MARK:
824 824
       lprintf(9,"%s: %s/%s seqno=%d max=%d cnt=%d %s\n", __func__,
825
-        SSTATE(r->head.nstate), RSTATE(m->mdata.head.nstate), m->mdata.head.seqno, m->seqnomax, m->markcount, m->fn);
825
+        strsstate(r->head.nstate), strrstate(m->mdata.head.nstate), m->mdata.head.seqno, m->seqnomax, m->markcount, m->fn);
826 826
       mrecv_req_send_mark(m, r);
827 827
       break;
828 828
 
829 829
     case MAKUO_SENDSTATE_CLOSE:
830
-      lprintf(9,"%s: %s/%s %s\n", __func__, SSTATE(r->head.nstate), RSTATE(m->mdata.head.nstate), m->fn);
830
+      lprintf(9,"%s: %s/%s %s\n", __func__, strsstate(r->head.nstate), strrstate(m->mdata.head.nstate), m->fn);
831 831
       mrecv_req_send_close(m, r);
832 832
       break;
833 833
 
834 834
     case MAKUO_SENDSTATE_LAST:
835
-      lprintf(9,"%s: %s/%s %s\n", __func__, SSTATE(r->head.nstate), RSTATE(m->mdata.head.nstate), m->fn);
835
+      lprintf(9,"%s: %s/%s %s\n", __func__, strsstate(r->head.nstate), strrstate(m->mdata.head.nstate), m->fn);
836 836
       mrecv_req_send_last(m, r);
837 837
       break;
838 838
 
839 839
     case MAKUO_SENDSTATE_BREAK:
840
-      lprintf(9,"%s: %s/%s %s\n", __func__, SSTATE(r->head.nstate), RSTATE(m->mdata.head.nstate), m->fn);
840
+      lprintf(9,"%s: %s/%s %s\n", __func__, strsstate(r->head.nstate), strrstate(m->mdata.head.nstate), m->fn);
841 841
       mrecv_req_send_break(m, r);
842 842
       break;
843 843
   }
... ...
@@ -1205,7 +1208,7 @@ static void mrecv_req_dsync_break(mfile *m, mdata *data, struct sockaddr_in *add
1205 1205
  */
1206 1206
 static void mrecv_req_dsync(mdata *data, struct sockaddr_in *addr)
1207 1207
 {
1208
-  lprintf(9, "%s: rid=%06d %s %s\n", __func__, data->head.reqid, OPCODE(data->head.opcode), SSTATE(data->head.nstate));
1208
+  lprintf(9, "%s: rid=%06d %s %s\n", __func__, data->head.reqid, stropcode(data), strmstate(data));
1209 1209
   mfile *m = mrecv_req_search(data, addr);
1210 1210
   switch(data->head.nstate){
1211 1211
     case MAKUO_SENDSTATE_OPEN:
... ...
@@ -1260,8 +1263,7 @@ static void mrecv_req_del_open(mdata *data, struct sockaddr_in *addr)
1260 1260
   memcpy(a->fn, data->p, len);
1261 1261
   a->fn[len] = 0;
1262 1262
   lprintf(9, "%s: fn=%s\n", __func__, a->fn);
1263
-  
1264
-  strcpy(path, a->fn);
1263
+  sprintf(path, "%s/%s", moption.real_dir, a->fn);
1265 1264
   if(mfnmatch(path, c->exclude)){
1266 1265
     return;
1267 1266
   }
... ...
@@ -58,7 +58,6 @@ static int msend_packet(int s, mdata *data, struct sockaddr_in *addr)
58 58
 {
59 59
   int r;
60 60
   int szdata;
61
-  char *state;
62 61
   mdata senddata;
63 62
 
64 63
   memcpy(&senddata, data, sizeof(senddata));
... ...
@@ -85,16 +84,11 @@ static int msend_packet(int s, mdata *data, struct sockaddr_in *addr)
85 85
       }
86 86
     }
87 87
   }
88
-  if(data->head.flags & MAKUO_FLAG_ACK){
89
-    state = RSTATE(data->head.nstate);
90
-  }else{
91
-    state = SSTATE(data->head.nstate);
92
-  }
93 88
   if(r != -1){
94 89
     lprintf(0, "%s: send size error %s %s rid=%d datasize=%d sendsize=%d seqno=%d\n",
95 90
       __func__,
96
-      OPCODE(data->head.opcode), 
97
-      state,
91
+      stropcode(data), 
92
+      strmstate(data),
98 93
       data->head.reqid,
99 94
       szdata, 
100 95
       r, 
... ...
@@ -104,8 +98,8 @@ static int msend_packet(int s, mdata *data, struct sockaddr_in *addr)
104 104
   lprintf(0,"%s: send error (%s) %s %s rid=%d size=%d seqno=%d\n",
105 105
     __func__,
106 106
     strerror(errno), 
107
-    OPCODE(data->head.opcode), 
108
-    state,
107
+    stropcode(data), 
108
+    strmstate(data),
109 109
     data->head.reqid, 
110 110
     szdata, 
111 111
     data->head.seqno);
... ...
@@ -129,8 +123,8 @@ static int msend_retry(mfile *m)
129 129
     __func__,
130 130
     m->retrycnt, 
131 131
     m->mdata.head.reqid, 
132
-    OPCODE(m->mdata.head.opcode), 
133
-    SSTATE(m->mdata.head.nstate), 
132
+    stropcode(&(m->mdata)),
133
+    strmstate(&(m->mdata)), 
134 134
     m->fn);
135 135
   for(t=members;t;t=t->next){
136 136
     r = get_hoststate(t, m);
... ...
@@ -145,7 +139,7 @@ static int msend_retry(mfile *m)
145 145
         if(*r == MAKUO_RECVSTATE_NONE){
146 146
           lprintf(0, "%s:   %s %s(%s)\n", 
147 147
             __func__, 
148
-           RSTATE(*r), 
148
+           strrstate(*r), 
149 149
            inet_ntoa(t->ad), 
150 150
            t->hostname);
151 151
         }
... ...
@@ -153,7 +147,7 @@ static int msend_retry(mfile *m)
153 153
       default:
154 154
         lprintf(4, "%s:   %s %s(%s)\n", 
155 155
           __func__, 
156
-          RSTATE(*r), 
156
+          strrstate(*r), 
157 157
           inet_ntoa(t->ad), 
158 158
           t->hostname);
159 159
         break;
... ...
@@ -266,11 +260,13 @@ static void msend_req_send_stat_init(int s, mfile *m)
266 266
 {
267 267
   mstat    fs;
268 268
   uint64_t rdev;
269
+
269 270
   if(!m->comm){
270 271
     msend_mfdel(m);
271 272
     m = NULL;
272 273
     return;
273 274
   }
275
+
274 276
   m->mdata.p = m->mdata.data;
275 277
   m->mdata.head.szdata  = sizeof(fs);
276 278
   m->mdata.head.szdata += strlen(m->fn);
... ...
@@ -844,7 +840,7 @@ static void msend_req_dsync_break(int s, mfile *m)
844 844
 /*----- dsync -----*/
845 845
 static void msend_req_dsync(int s, mfile *m)
846 846
 {
847
-  lprintf(9, "%s: rid=%d %s %s\n", __func__, m->mdata.head.reqid, OPCODE(m->mdata.head.opcode), SSTATE(m->mdata.head.nstate));
847
+  lprintf(9, "%s: rid=%d %s %s\n", __func__, m->mdata.head.reqid, stropcode(&(m->mdata)), strmstate(&(m->mdata)));
848 848
   if(m->mdata.head.nstate != MAKUO_SENDSTATE_LAST){
849 849
     if(!m->comm){
850 850
       if(m->mdata.head.nstate != MAKUO_SENDSTATE_BREAK){
... ...
@@ -897,6 +893,7 @@ static void msend_req_del_mark(int s, mfile *m)
897 897
 static void msend_req_del_stat(int s, mfile *m)
898 898
 {
899 899
   int r;
900
+  mfile *a;
900 901
   mfile *d;
901 902
   uint8_t stat;
902 903
   uint16_t len;
... ...
@@ -938,7 +935,12 @@ static void msend_req_del_stat(int s, mfile *m)
938 938
   read(m->pipe, d->fn, len);
939 939
   d->fn[len]    = 0;
940 940
   d->fs.st_mode = mod;
941
-
941
+  for(a=mftop[1];a;a=a->next){
942
+    if(!strcmp(a->tn, d->fn)){
943
+      msend_mfdel(d);
944
+      return;
945
+    }
946
+  }
942 947
   d->mdata.p = d->mdata.data;
943 948
   *(uint32_t *)(d->mdata.p) = htonl(mod);
944 949
   d->mdata.p += sizeof(mod);