add support for configurable max allocated requests and local req cache
[archipelago] / xseg / peers / user / filed.c
index 4e805ac..b9666d4 100644 (file)
@@ -432,22 +432,33 @@ static void handle_copy(struct store *store, struct io *io)
         struct xseg_request_copy *xcopy = (struct xseg_request_copy *) xseg_get_data(store->xseg, req);
         struct stat st;
         int n, src, dst;
+       char buf[XSEG_MAX_TARGETLEN+1];
        char *target = xseg_get_target(store->xseg, req);
 
         dst = dir_open(store, io, target, req->targetlen, 1);
         if (dst < 0) {
                 fprintf(stderr, "fail in dst\n");
                 fail(store, io);
-               free(buf);
                 return;
         }
 
-       src = openat(store->dirfd, xcopy->target, O_RDWR);      
+       strncpy(buf, xcopy->target, xcopy->targetlen);
+       buf[xcopy->targetlen] = 0;
+       src = openat(store->dirfd, buf, O_RDWR);        
         if (src < 0) {
-                fprintf(stderr, "fail in src\n");
-                fail(store, io);
-               free(buf);
-                return;
+               if (errno == ENOENT){
+                       src = openat(store->dirfd, buf, 
+                                       O_RDWR | O_CREAT, 0600);
+                       if (src < 0 ) {
+                               fprintf(stderr, "fail in src\n");
+                               fail(store, io);
+                               return;
+                       }       
+               } else {
+                       fprintf(stderr, "fail in src\n");
+                       fail(store, io);
+                       return;
+               }
         }
 
         fstat(src, &st);
@@ -467,7 +478,6 @@ static void handle_copy(struct store *store, struct io *io)
         complete(store, io);
 
 out:
-       free(buf);
         close(src);
 }
 
@@ -495,7 +505,7 @@ static void handle_delete(struct store *store, struct io *io)
        buf[req->targetlen] = 0;
        unlinkat(store->dirfd, buf, 0);
 
-       complete(pfiled, io);
+       complete(store, io);
 
        return;
 }
@@ -552,7 +562,7 @@ void *io_loop(void *arg)
 
        for (;;) {
                accepted = NULL;
-               accepted = xseg_accept(xseg, portno);
+               accepted = xseg_accept(xseg, portno, 0);
                if (accepted) {
                        io->req = accepted;
                        wake_up_next_iothread(store);
@@ -696,7 +706,7 @@ malloc_fail:
        if (!store->xseg)
                return -1;
 
-       store->xport = xseg_bind_port(store->xseg, portno);
+       store->xport = xseg_bind_port(store->xseg, portno, NULL);
        if (!store->xport) {
                printf("cannot bind to port %ld\n", portno);
                return -1;