Bump version to 0.3.5next
[archipelago] / xseg / peers / user / mapperd.c
index 3072d7c..2d14101 100644 (file)
@@ -1,4 +1,38 @@
 /*
+ * Copyright 2012 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+/*
  * The Mapper
  */
 
@@ -148,6 +182,8 @@ static int mapperd_loop(struct mapperd *mapperd)
        struct xseg_request *xreq;
        struct xseg *xseg = mapperd->xseg;
        uint32_t mportno = mapperd->mportno;
+       char *target, buf[MAX_FILENAME_SIZE];
+       xport p;
 
        always_assert(xseg);
 
@@ -155,7 +191,7 @@ static int mapperd_loop(struct mapperd *mapperd)
                ret = xseg_prepare_wait(xseg, mportno);
                always_assert(ret == 0);
 
-               xreq = xseg_accept(xseg, mportno);
+               xreq = xseg_accept(xseg, mportno, 0);
                if (xreq) {
                        xseg_cancel_wait(xseg, mportno);
                        /*
@@ -164,24 +200,36 @@ static int mapperd_loop(struct mapperd *mapperd)
                         * the reply and the target name fits in the map reply.
                         */
                        size_t s = sizeof(struct xseg_reply_map) +
-                               sizeof(struct xseg_reply_map_scatterlist);
-                       always_assert(xreq->datalen >= s);
-                       always_assert(xreq->targetlen <= XSEG_MAX_TARGETLEN);
-
-                       struct xseg_reply_map *mreply = (void *)xreq->data;
-                       mreply->cnt = 1;
+                               2 * sizeof(struct xseg_reply_map_scatterlist);
+                       target = xseg_get_target(xseg, xreq);
+                       strncpy(buf, target, xreq->targetlen);
+                       xseg_resize_request(xseg, xreq, xreq->targetlen, s);
+                       target = xseg_get_target(xseg, xreq);
+                       strncpy(target, buf, xreq->targetlen);
+
+                       struct xseg_reply_map *mreply = (void *)xseg_get_data(xseg, xreq);
+                       mreply->cnt = 2;
                        mreply->segs[0].offset = xreq->offset;
-                       mreply->segs[0].size = xreq->size;
+                       mreply->segs[0].size = xreq->size/2;
+                       /* FIXME: strlcpy() would work nicely here */
+                       strncpy(mreply->segs[0].target, target, xreq->targetlen);
+                       mreply->segs[0].target[xreq->targetlen] = '_';
+                       mreply->segs[0].target[xreq->targetlen + 1] = '1';
+                       mreply->segs[0].target[xreq->targetlen + 2] = '\0';
+                       
+                       mreply->segs[1].offset = xreq->offset;
+                       mreply->segs[1].size = xreq->size/2;
                        /* FIXME: strlcpy() would work nicely here */
-                       strncpy(mreply->segs[0].target, xreq->target, xreq->targetlen);
-                       mreply->segs[0].target[xreq->targetlen] = '\0';
+                       strncpy(mreply->segs[1].target, target, xreq->targetlen);
+                       mreply->segs[1].target[xreq->targetlen] = '_';
+                       mreply->segs[1].target[xreq->targetlen + 1] = '2';
+                       mreply->segs[1].target[xreq->targetlen + 2] = '\0';
 
                        /* Respond to the initiator, signal the source port */
 //                     perr(PI, 0, "completed io");
                        xreq->state |= XS_SERVED;
-                       ret = xseg_respond(xseg, xreq->portno, xreq);
-                       always_assert(ret != NoSerial);
-                       ret = xseg_signal(xseg, xreq->portno);
+                       p = xseg_respond(xseg, xreq, mportno, X_ALLOC);
+                       ret = xseg_signal(xseg, p);
 //                     always_assert(ret == 1);
                } else {
                        /*
@@ -221,14 +269,14 @@ static int mapperd_init(struct mapperd *mapperd)
                goto out_with_xseginit;
        }
 
-       if (! (mapperd->mport = xseg_bind_port(mapperd->xseg, mapperd->mportno))) {
+       if (! (mapperd->mport = xseg_bind_port(mapperd->xseg, mapperd->mportno, NULL))) {
                perr(PE, 0, "cannot bind to xseg port %ld", (long)mapperd->mportno);
                ret = -EIO;
                goto out_with_xsegjoin;
        }
 
        mapperd->mportno = xseg_portno(mapperd->xseg, mapperd->mport);
-       
+       xseg_init_local_signal(mapperd->xseg, mapperd->mportno);
        perr(PI, 0, "mapperd on port %u of %u",
                mapperd->mportno, mapperd->xseg->config.nr_ports);