[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] manual merge of James's stuff.



ChangeSet 1.1339, 2005/03/21 20:07:51+00:00, akw27@xxxxxxxxxxxxxxxxxxxxxx

        manual merge of James's stuff.



 Makefile     |    4 
 blockstore.c |  513 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 blockstore.h |   75 ++++++++
 3 files changed, 575 insertions(+), 17 deletions(-)


diff -Nru a/tools/blktap/Makefile b/tools/blktap/Makefile
--- a/tools/blktap/Makefile     2005-03-22 05:03:18 -05:00
+++ b/tools/blktap/Makefile     2005-03-22 05:03:18 -05:00
@@ -152,6 +152,10 @@
 vdi_validate: $(LIB) vdi_validate.c $(VDI_SRCS)
        $(CC) $(CFLAGS) -g3 -o vdi_validate vdi_validate.c $(VDI_SRCS)
 
+blockstored: blockstored.c
+       $(CC) $(CFLAGS) -g3 -o blockstored blockstored.c
+bstest: bstest.c blockstore.c
+       $(CC) $(CFLAGS) -g3 -o bstest bstest.c blockstore.c
 
 .PHONY: TAGS clean install mk-symlinks rpm
 TAGS:
diff -Nru a/tools/blktap/blockstore.c b/tools/blktap/blockstore.c
--- a/tools/blktap/blockstore.c 2005-03-22 05:03:18 -05:00
+++ b/tools/blktap/blockstore.c 2005-03-22 05:03:18 -05:00
@@ -14,11 +14,409 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include "blockstore.h"
-#include "parallax-threaded.h"
+#define BLOCKSTORE_REMOTE
 
-/*static int block_fp = -1;*/
- 
-static int fd_list[READ_POOL_SIZE+1];
+#ifdef BLOCKSTORE_REMOTE
+
+//#define BSDEBUG
+
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+#define ENTER_QUEUE_CR (void)0
+#define LEAVE_QUEUE_CR (void)0
+
+bsserver_t bsservers[MAX_SERVERS];
+bscluster_t bsclusters[MAX_CLUSTERS];
+
+struct sockaddr_in sin_local;
+int bssock = 0;
+
+typedef struct bsq_t_struct {
+    struct bsq_t_struct *prev;
+    struct bsq_t_struct *next;
+    int server;
+    int length;
+    struct msghdr msghdr;
+    struct iovec iov[2];
+    bshdr_t message;
+    void *block;
+} bsq_t;
+
+bsq_t *bs_head = NULL;
+bsq_t *bs_tail = NULL;
+
+int send_message(bsq_t *qe) {
+    int rc;
+
+    qe->msghdr.msg_name = (void *)&(bsservers[qe->server].sin);
+    qe->msghdr.msg_namelen = sizeof(struct sockaddr_in);
+    qe->msghdr.msg_iov = qe->iov;
+    if (qe->block)
+        qe->msghdr.msg_iovlen = 2;
+    else
+        qe->msghdr.msg_iovlen = 1;
+    qe->msghdr.msg_control = NULL;
+    qe->msghdr.msg_controllen = 0;
+    qe->msghdr.msg_flags = 0;
+
+    qe->iov[0].iov_base = (void *)&(qe->message);
+    qe->iov[0].iov_len = MSGBUFSIZE_ID;
+
+    if (qe->block) {
+        qe->iov[1].iov_base = qe->block;
+        qe->iov[1].iov_len = BLOCK_SIZE;
+    }
+
+    rc = sendmsg(bssock, &(qe->msghdr), 0);
+    //rc = sendto(bssock, (void *)&(qe->message), qe->length, 0,
+    //           (struct sockaddr *)&(bsservers[qe->server].sin),
+    //           sizeof(struct sockaddr_in));
+    if (rc < 0)
+        return rc;
+    
+    ENTER_QUEUE_CR;
+    
+    LEAVE_QUEUE_CR;
+
+    return rc;
+}
+
+int recv_message(bsq_t *qe) {
+    struct sockaddr_in from;
+    //int flen = sizeof(from);
+    int rc;
+
+    qe->msghdr.msg_name = &from;
+    qe->msghdr.msg_namelen = sizeof(struct sockaddr_in);
+    qe->msghdr.msg_iov = qe->iov;
+    if (qe->block)
+        qe->msghdr.msg_iovlen = 2;
+    else
+        qe->msghdr.msg_iovlen = 1;
+    qe->msghdr.msg_control = NULL;
+    qe->msghdr.msg_controllen = 0;
+    qe->msghdr.msg_flags = 0;
+
+    qe->iov[0].iov_base = (void *)&(qe->message);
+    qe->iov[0].iov_len = MSGBUFSIZE_ID;
+    if (qe->block) {
+        qe->iov[1].iov_base = qe->block;
+        qe->iov[1].iov_len = BLOCK_SIZE;
+    }
+
+    rc = recvmsg(bssock, &(qe->msghdr), 0);
+
+    //return recvfrom(bssock, (void *)&(qe->message), sizeof(bsmsg_t), 0,
+    //               (struct sockaddr *)&from, &flen);
+    return rc;
+}
+
+void *readblock_indiv(int server, u64 id) {
+    void *block;
+    bsq_t *qe;
+    int len;
+
+    qe = (bsq_t *)malloc(sizeof(bsq_t));
+    if (!qe) {
+        perror("readblock qe malloc");
+        return NULL;
+    }
+    qe->block = malloc(BLOCK_SIZE);
+    if (!qe->block) {
+        perror("readblock qe malloc");
+        free((void *)qe);
+        return NULL;
+    }
+
+    qe->server = server;
+
+    qe->message.operation = BSOP_READBLOCK;
+    qe->message.flags = 0;
+    qe->message.id = id;
+    qe->length = MSGBUFSIZE_ID;
+
+    if (send_message(qe) < 0) {
+        perror("readblock sendto");
+        goto err;
+    }
+    
+    len = recv_message(qe);
+    if (len < 0) {
+        perror("readblock recv");
+        goto err;
+    }
+    if ((qe->message.flags & BSOP_FLAG_ERROR)) {
+        fprintf(stderr, "readblock server error\n");
+        goto err;
+    }
+    if (len < MSGBUFSIZE_BLOCK) {
+        fprintf(stderr, "readblock recv short (%u)\n", len);
+        goto err;
+    }
+    if ((block = malloc(BLOCK_SIZE)) == NULL) {
+        perror("readblock malloc");
+        goto err;
+    }
+    //memcpy(block, qe->message.block, BLOCK_SIZE);
+    block = qe->block;
+
+    free((void *)qe);
+    return block;
+
+    err:
+    free(qe->block);
+    free((void *)qe);
+    return NULL;
+}
+
+/**
+ * readblock: read a block from disk
+ *   @id: block id to read
+ *
+ *   @return: pointer to block, NULL on error
+ */
+void *readblock(u64 id) {
+    int map = (int)BSID_MAP(id);
+    u64 xid;
+    static int i = CLUSTER_MAX_REPLICAS - 1;
+    void *block = NULL;
+
+    /* special case for the "superblock" just use the first block on the
+     * first replica. (extend to blocks < 6 for vdi bug)
+     */
+    if (id < 6) {
+        block = readblock_indiv(bsclusters[map].servers[0], id);
+        goto out;
+    }
+
+    i++;
+    if (i >= CLUSTER_MAX_REPLICAS)
+        i = 0;
+    switch (i) {
+    case 0:
+        xid = BSID_REPLICA0(id);
+        break;
+    case 1:
+        xid = BSID_REPLICA1(id);
+        break;
+    case 2:
+        xid = BSID_REPLICA2(id);
+        break;
+    }
+    
+    block = readblock_indiv(bsclusters[map].servers[i], xid);
+
+    out:
+#ifdef BSDEBUG
+    if (block)
+        fprintf(stderr, "READ:  %016llx %02x%02x %02x%02x %02x%02x %02x%02x\n",
+                id,
+                (unsigned int)((unsigned char *)block)[0],
+                (unsigned int)((unsigned char *)block)[1],
+                (unsigned int)((unsigned char *)block)[2],
+                (unsigned int)((unsigned char *)block)[3],
+                (unsigned int)((unsigned char *)block)[4],
+                (unsigned int)((unsigned char *)block)[5],
+                (unsigned int)((unsigned char *)block)[6],
+                (unsigned int)((unsigned char *)block)[7]);
+    else
+        fprintf(stderr, "READ:  %016llx NULL\n", id);
+#endif
+    return block;
+}
+
+int writeblock_indiv(int server, u64 id, void *block) {
+    bsq_t *qe;
+    int len;
+
+    qe = (bsq_t *)malloc(sizeof(bsq_t));
+    if (!qe) {
+        perror("writeblock qe malloc");
+        goto err;
+    }
+    qe->server = server;
+


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.