Skip to content
Permalink
Browse files

nbd support

  • Loading branch information...
Jacob Gorm Hansen
Jacob Gorm Hansen committed Sep 3, 2017
0 parents commit ce4ceea4c2653139b523b7b1e6c6924c0a68b95f
Showing with 7,702 additions and 0 deletions.
  1. +3 −0 .vimrc
  2. +23 −0 CMakeLists.txt
  3. +15 −0 Makefile
  4. +58 −0 aio.c
  5. +4 −0 aio.h
  6. +2,629 −0 block-swap.c
  7. +25 −0 block-swap.h
  8. +1,581 −0 block-swap/dubtree.c
  9. +66 −0 block-swap/dubtree.h
  10. +8 −0 block-swap/dubtree_constants.h
  11. +189 −0 block-swap/dubtree_io.h
  12. +22 −0 block-swap/dubtree_sys.h
  13. +210 −0 block-swap/hashtable.c
  14. +40 −0 block-swap/hashtable.h
  15. +779 −0 block-swap/hashtable_noise.h
  16. +87 −0 block-swap/lrucache.h
  17. +320 −0 block-swap/simpletree.c
  18. +153 −0 block-swap/simpletree.h
  19. +242 −0 block.h
  20. +106 −0 config.h
  21. +59 −0 ioh.c
  22. +27 −0 ioh.h
  23. +236 −0 nbd.c
  24. +749 −0 queue.h
  25. +71 −0 thread-event.h
3 .vimrc
@@ -0,0 +1,3 @@
set ts=4
set expandtab
set makeprg=ninja\ -C\ build
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.4)

set(CMAKE_C_FLAGS "-Wall -Werror -Ofast -Wfatal-errors -g")
#add_definitions(-DPTHREAD_BARRIER_SERIAL_THREAD)

#set (SANITIZE 1)
if (SANITIZE)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer -g")
endif()

include_directories("${CMAKE_SOURCE_DIR}")

add_executable(oneroot
block-swap.c
nbd.c
aio.c
ioh.c
block-swap/dubtree.c
block-swap/hashtable.c
block-swap/simpletree.c
)

target_link_libraries(oneroot -lpthread -llz4 -luuid)
@@ -0,0 +1,15 @@
all: build/build.ninja
ninja -C build &&\
ln -f -s build/oneroot oneroot

build/build.ninja:
(mkdir -p build && cd build && cmake -G Ninja ..)

clean:
ninja -C build clean

distclean:
rm -rf build tags oneroot

tags:
ctags -R *
58 aio.c
@@ -0,0 +1,58 @@
#include <assert.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "ioh.h"

typedef struct AioEntry {
ioh_event *event;
void (*cb) (void *opaque);
void *opaque;
} AioEntry;

static AioEntry aios[1024];

void aio_add_wait_object(ioh_event *event, void (*cb) (void *opaque), void *opaque) {
for (int i = 0; i < sizeof(aios) / sizeof(aios[0]); ++i) {
AioEntry *e = &aios[i];
if (!e->event && __sync_bool_compare_and_swap(&e->event, NULL, event)) {
e->cb = cb;
e->opaque = opaque;
return;
}
}
}

void aio_wait(void)
{
fd_set fds;
FD_ZERO(&fds);
int max = -1;
for (int i = 0; i < sizeof(aios) / sizeof(aios[0]); ++i) {
AioEntry *e = &aios[i];
if (e->event) {
int fd = ioh_handle(e->event);
max = fd > max ? fd : max;
FD_SET(fd, &fds);
}
}

if (max != -1) {

int r = select(max + 1, &fds, NULL, NULL, NULL);
assert(r >= 0);

for (int i = 0; i < sizeof(aios) / sizeof(aios[0]); ++i) {
AioEntry *e = &aios[i];
if (e->event) {
if (FD_ISSET(ioh_handle(e->event), &fds)) {
ioh_event *event = e->event;
ioh_event_reset(event);
e->cb(e->opaque);
__sync_bool_compare_and_swap(&e->event, event, NULL);
}
}
}
}
}
4 aio.h
@@ -0,0 +1,4 @@
struct ioh_event;

void aio_add_wait_object(struct ioh_event *event, void (*cb) (void *opaque), void *opaque);
void aio_wait(void);

0 comments on commit ce4ceea

Please sign in to comment.
You can’t perform that action at this time.