--- /dev/null
+/*
+ * This file is part of the Palacios Virtual Machine Monitor developed
+ * by the V3VEE Project with funding from the United States National
+ * Science Foundation and the Department of Energy.
+ *
+ * The V3VEE Project is a joint project between Northwestern University
+ * and the University of New Mexico. You can find out more at
+ * http://www.v3vee.org
+ *
+ * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software. You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
+#include "v3_nbd.h"
+
+
+
+raw_disk::raw_disk(string &filename) {
+ this->f = fopen(filename.c_str(), "w+");
+}
+
+
+unsigned long long raw_disk::get_capacity() {
+
+
+}
+
+
+
+int raw_disk::read(unsigned char * buf, unsigned long long offset, int length) {
+
+
+}
+
+
+
+int raw_disk::write(unsigned char * buf, unsigned long long offset, int length) {
+
+
+}
--- /dev/null
+/*
+ * This file is part of the Palacios Virtual Machine Monitor developed
+ * by the V3VEE Project with funding from the United States National
+ * Science Foundation and the Department of Energy.
+ *
+ * The V3VEE Project is a joint project between Northwestern University
+ * and the University of New Mexico. You can find out more at
+ * http://www.v3vee.org
+ *
+ * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software. You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
+#ifndef __RAW_H__
+#define __RAW_H__
+
+
+class raw_disk : public v3_disk {
+ private:
+ raw_disk(config_t &config_map, string &disk_tag);
+
+ File * f;
+
+ public:
+ unsigned long long get_capacity();
+ int read(unsigned char * buf, unsigned long long offset, int length);
+ int write(unsigned char * buf, unsigned long long offset, int length);
+
+};
+
+
+
+
+
+
+
+#endif
* redistribute, and modify it as specified in the file "V3VEE_LICENSE".
*/
-#include <string>
+
#include <iostream>
#include <fstream>
#include <stdio.h>
#endif
-#include "vtl.h"
+
+#include "v3_nbd.h"
+
+#define NBD_KEY "V3_NBD_1"
#define DEFAULT_LOG_FILE "./status.log"
//using namespace __gnu_cxx;
-typedef enum {INVALID, ISO, RAW} disk_type_t;
-
-struct disk_info {
- string filename;
- string tag;
- disk_type_t type;
-
- FILE * disk_file;
-};
-
-
-
struct eqsock {
bool operator()(const SOCK sock1, const SOCK sock2) const {
return sock1 == sock2;
// eqstr from vtl (config.h)
map<const string, struct disk_info *, eqstr> disks;
-
// List of open connections
map<SOCK, struct disk_info *, eqsock> conns;
+
// Enable Debugging
static const int enable_debug = 1;
int serv_loop(int serv_sock);
void setup_disk(string disk_tag, config_t &config_map);
+int handle_new_connection(SOCK new_conn);
-int __main (int argc, char ** argv);
-disk_type_t get_disk_type(const string type_str) {
-
- if (type_str == "ISO") {
- return ISO;
- } else if (type_str == "RAW") {
- return RAW;
- }
+int __main (int argc, char ** argv);
- return INVALID;
-}
#ifdef linux
int max_fd = -1;
RawEthernetPacket pkt;
+
+ list<SOCK> pending_cons;
+
FD_ZERO(&all_set);
FD_SET(serv_sock, &all_set);
max_fd = serv_sock;
while (1) {
int nready = 0;
read_set = all_set;
- nready = select(max_fd + 1, &read_set, NULL, NULL, NULL);
+ write_set = all_set;
+ nready = select(max_fd + 1, &read_set, &write_set, NULL, NULL);
if (nready == -1) {
if (errno == EINTR) {
}
}
- // configure socket
+ pending_cons.push_front(conn_socket);
+
+ FD_SET(conn_socket, &all_set);
+
+ if (conn_socket > max_fd) {
+ max_fd = conn_socket;
+ }
+ if (--nready <= 0) continue;
}
+
+ // handle open connections
+
+
+ // check pending connections
+
+ for (list<SOCK>::iterator pending_iter = pending_cons.begin();
+ pending_iter != pending_cons.end();
+ pending_iter++) {
+
+ if (handle_new_connection(pending_iter.value()) == -1) {
+ // error
+ }
+
+ pending_cons.remove(pending_iter);
+
+ if (--nready <= 0) break;
+ }
+
+ if (nready <= 0) continue;
+
+
+
}
return 0;
+
+/* Negotiation:
+ * <NBD_KEY> <Disk Tag>\n
+ */
+
+int handle_new_connection(SOCK new_conn) {
+ string input;
+ string key_str;
+ string tag_str;
+ struct disk_info * disk = NULL;
+
+ GetLine(new_conn, input);
+
+ {
+ istringstream is(input, istringstream::in);
+ is >> key_str >> tag_str;
+ }
+
+ if (key_str != NBD_KEY) {
+ vtl_debug("Error: Invalid NBD key string (%s)\n", key_str.c_str());
+ return -1;
+ }
+
+ if (disks[tag_str].count() == 0) {
+ vtl_debug("Error: Requesting disk that does not exist (%s)\n", tag_str.c_str());
+ return -1;
+ }
+
+ // Check if already assigned...
+ disk = disks[tag_str];
+
+ if (!disk) {
+ return -1;
+ }
+
+ conns[new_conn] = disk;
+
+ return 0;
+}
+
+
int config_nbd(string conf_file_name) {
config_t config_map;
void setup_disk(string disk_tag, config_t &config_map) {
string file_tag = disk_tag + ".file";
string type_tag = disk_tag + ".type";
- struct disk_info * disk = (struct disk_info *)malloc(sizeof(struct disk_info));
+
+ string type;
+
cout << "Setting up " << disk_tag.c_str() << endl;
cerr << "Missing Disk configuration directive for " << disk_tag << endl;
}
- disk->tag = disk_tag;
- disk->filename = config_map[file_tag];
- disk->type = get_disk_type(config_map[type_tag]);
+ type = config_map[type_tag];
- if (disk->type == RAW) {
- disk->disk_file = fopen(disk->filename.c_str(), "w+");
- } else if (disk->type == ISO) {
- disk->disk_file = fopen(disk->filename.c_str(), "r");
+ if (type == "RAW") {
+ disks[disk->tag] = new raw_disk(config_map[file_tag]);;
+ } else if (type == "ISO") {
+
}
- disks[disk->tag] = disk;
+
+
return;
}