From fcd3d33498dee707486a6c74b0516967e86a3449 Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Tue, 13 Sep 2016 21:41:19 +0100 Subject: [PATCH 01/32] Simplified Makefile gcc and clang can generate dep files as well as compiling in a single pass, no need for two. Signed-off-by: Michel Pollet --- Makefile | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 655325a..2095ced 100644 --- a/Makefile +++ b/Makefile @@ -50,8 +50,7 @@ CC?=gcc LIBS=-lpthread INC=-I/usr/include/libev -Isrc/common -Isrc/server -Isrc/proxy -COMPILE=$(CC) $(INC) -c $(CCFLAGS) -SAVEDEP=$(CC) $(INC) -MM $(CCFLAGS) +COMPILE=$(CC) -MMD $(INC) -c $(CCFLAGS) LINK=$(CC) $(LLDFLAGS) -Isrc $(LIBS) LIB=build/ @@ -71,12 +70,11 @@ SRCS := $(COMMON_SRC) $(SERVER_SRC) $(PROXY_SRC) OBJS := $(COMMON_OBJ) $(SERVER_OBJ) $(PROXY_OBJ) -all: build/flexnbd build/flexnbd-proxy doc +all: build/flexnbd build/flexnbd-proxy #doc build/%.o: %.c mkdir -p $(dir $@) $(COMPILE) $< -o $@ - $(SAVEDEP) $< > build/$*.d objs: $(OBJS) @@ -91,16 +89,13 @@ proxy: build/flexnbd-proxy CHECK_SRC := $(wildcard tests/unit/*.c) -CHECK_OBJ := $(CHECK_SRC:tests/unit/%.c=build/tests/%.o) +CHECK_OBJ := $(CHECK_SRC:tests/unit/%.c=build/%.o) # Why can't we reuse the build/%.o rule above? Not sure. -build/tests/%.o: tests/unit/%.c - mkdir -p $(dir $@) - $(COMPILE) $< -o $@ - $(SAVEDEP) $< > build/tests/$*.d -CHECK_BINS := $(CHECK_OBJ:build/tests/%.o=build/tests/%) -build/tests/%: build/tests/%.o $(OBJS) - $(LINK) $^ -o $@ -lcheck +CHECK_BINS := $(CHECK_SRC:tests/unit/%.c=build/%) + +build/check_%: build/check_%.o + $(LINK) $^ -o $@ $(COMMON_OBJ) -lcheck check_objs: $(CHECK_OBJ) From d9651a038c1444e8e48764d9699d62ea9053bb2f Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Fri, 30 Sep 2016 16:31:47 +0100 Subject: [PATCH 02/32] Makefile: don't include *.d's before 'all' Include any .d file from the build directory, and do that after all the other targets Signed-off-by: Michel Pollet --- Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 2095ced..d41d081 100644 --- a/Makefile +++ b/Makefile @@ -55,9 +55,6 @@ LINK=$(CC) $(LLDFLAGS) -Isrc $(LIBS) LIB=build/ -EXISTING_OBJS := $(wildcard build/*.o) --include $(EXISTING_OBJS:.o=.d) - COMMON_SRC := $(wildcard src/common/*.c) SERVER_SRC := $(wildcard src/server/*.c) PROXY_SRC := $(wildcard src/proxy/*.c) @@ -112,7 +109,6 @@ build/flexnbd-proxy.1: README.proxy.txt %.1.gz: %.1 gzip -c -f $< > $@ - server-man: build/flexnbd.1.gz proxy-man: build/flexnbd-proxy.1.gz @@ -127,3 +123,6 @@ clean: .PHONY: clean objs check_objs all server proxy check_bins check server-man proxy-man doc + +# Include extra dependencies at the end, NOT before 'all' +-include $(wildcard build/*.d) From d3762162dbab51d539812f21e50a7e9415299ab5 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 5 Oct 2016 09:29:07 +0100 Subject: [PATCH 03/32] Fixes "double-definition of constants" warning Looks like `#constants.include?` doesn't work as well as `#const_defined?`. --- tests/acceptance/flexnbd/constants.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/flexnbd/constants.rb b/tests/acceptance/flexnbd/constants.rb index 0d7f207..0e75688 100644 --- a/tests/acceptance/flexnbd/constants.rb +++ b/tests/acceptance/flexnbd/constants.rb @@ -32,7 +32,7 @@ module FlexNBD txt_lines.each do |line| if line =~ /^#\s*define\s+([A-Z0-9_]+)\s+(\d+)\s*$/ # Bodge until I can figure out what to do with #ifdefs - const_set($1, $2.to_i) unless constants.include?( $1 ) + const_set($1, $2.to_i) unless const_defined?( $1 ) end end end From 356e1fd6a10025218cb7671d4fba38e79dd10961 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 5 Oct 2016 10:01:15 +0100 Subject: [PATCH 04/32] Use a BINARY encoded string when doing read/write comparisons. This is a bit of a cheat really, but `#read` returns an ASCII encoded string, where as our ruby generates UTF-8 encoded strings, causing assertion failures. Fixes #20 --- tests/acceptance/proxy_tests.rb | 16 ++++++++++------ tests/acceptance/test_serve_mode.rb | 7 ++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/acceptance/proxy_tests.rb b/tests/acceptance/proxy_tests.rb index 5f3abff..e4030a4 100644 --- a/tests/acceptance/proxy_tests.rb +++ b/tests/acceptance/proxy_tests.rb @@ -3,6 +3,10 @@ require 'flexnbd/fake_source' require 'flexnbd/fake_dest' module ProxyTests + def b + String.new("\xFF", encoding: "BINARY") + end + def with_proxied_client( override_size = nil ) @env.serve1 unless @server_up @env.proxy2 unless @proxy_up @@ -51,7 +55,7 @@ module ProxyTests with_proxied_client do |client| (0..3).each do |n| offset = n * 4096 - client.write(offset, "\xFF" * 4096) + client.write(offset, b * 4096) rsp = client.read_response assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic] @@ -60,7 +64,7 @@ module ProxyTests data = @env.file1.read(offset, 4096) - assert_equal( ( "\xFF" * 4096 ), data, "Data not written correctly (offset is #{n})" ) + assert_equal( ( b * 4096 ), data, "Data not written correctly (offset is #{n})" ) end end end @@ -107,7 +111,7 @@ module ProxyTests # The reply should be proxied back to the client. sc2.write_reply( req2[:handle] ) - sc2.write_data( "\xFF" * 4096 ) + sc2.write_data( b * 4096 ) # Check it to make sure it's correct rsp = timeout(15) { client.read_response } @@ -116,7 +120,7 @@ module ProxyTests assert_equal req1[:handle], rsp[:handle] data = client.read_raw( 4096 ) - assert_equal( ("\xFF" * 4096), data, "Wrong data returned" ) + assert_equal( (b * 4096), data, "Wrong data returned" ) sc2.close server.close @@ -131,7 +135,7 @@ module ProxyTests server, sc1 = maker.value # Send the read request to the proxy - client.write( 0, ( "\xFF" * 4096 ) ) + client.write( 0, ( b * 4096 ) ) # ensure we're given the read request req1 = sc1.read_request @@ -140,7 +144,7 @@ module ProxyTests assert_equal 0, req1[:from] assert_equal 4096, req1[:len] data1 = sc1.read_data( 4096 ) - assert_equal( ( "\xFF" * 4096 ), data1, "Data not proxied successfully" ) + assert_equal( ( b * 4096 ), data1, "Data not proxied successfully" ) # Kill the server again, now we're sure the read request has been sent once sc1.close diff --git a/tests/acceptance/test_serve_mode.rb b/tests/acceptance/test_serve_mode.rb index 2b2fb96..2713fbc 100644 --- a/tests/acceptance/test_serve_mode.rb +++ b/tests/acceptance/test_serve_mode.rb @@ -6,6 +6,7 @@ class TestServeMode < Test::Unit::TestCase def setup super + @b = String.new("\xFF", ecoding: "BINARY") @env = Environment.new @env.writefile1( "0" ) @env.serve1 @@ -53,18 +54,18 @@ class TestServeMode < Test::Unit::TestCase assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic] assert_equal 0, rsp[:error] - client.write( 0, "\xFF" ) + client.write( 0, @b ) rsp = client.read_response assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic] assert_equal 0, rsp[:error] - client.write( 0, "\xFF\xFF" ) + client.write( 0, @b * 2 ) rsp = client.read_response assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic] assert_equal 0, rsp[:error] end - assert_equal "\xFF\xFF", @env.file1.read( 0, 2 ) + assert_equal @b * 2, @env.file1.read( 0, 2 ) end From 99a5f79a5230a8070f5dfed53af23dd90e4769d9 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 10:30:44 +0100 Subject: [PATCH 05/32] fixed typo --- tests/acceptance/test_serve_mode.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/test_serve_mode.rb b/tests/acceptance/test_serve_mode.rb index 2713fbc..bbf6025 100644 --- a/tests/acceptance/test_serve_mode.rb +++ b/tests/acceptance/test_serve_mode.rb @@ -6,7 +6,7 @@ class TestServeMode < Test::Unit::TestCase def setup super - @b = String.new("\xFF", ecoding: "BINARY") + @b = String.new("\xFF", encoding: "BINARY") @env = Environment.new @env.writefile1( "0" ) @env.serve1 From ed3995303f6f78c89a66759259897d2164633b0c Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 5 Oct 2016 10:41:23 +0100 Subject: [PATCH 06/32] Reinstate doc to all --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d41d081..4b2102a 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ SRCS := $(COMMON_SRC) $(SERVER_SRC) $(PROXY_SRC) OBJS := $(COMMON_OBJ) $(SERVER_OBJ) $(PROXY_OBJ) -all: build/flexnbd build/flexnbd-proxy #doc +all: build/flexnbd build/flexnbd-proxy doc build/%.o: %.c mkdir -p $(dir $@) From a6710b6c32933b9c68816c2d259de32c03a711b4 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 10:57:52 +0100 Subject: [PATCH 07/32] update tests to reflect changes in handle storage --- tests/unit/check_nbdtypes.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/unit/check_nbdtypes.c b/tests/unit/check_nbdtypes.c index 58e5b40..90d3f8d 100644 --- a/tests/unit/check_nbdtypes.c +++ b/tests/unit/check_nbdtypes.c @@ -88,14 +88,14 @@ START_TEST(test_request_handle) struct nbd_request_raw request_raw; struct nbd_request request; - memcpy( request_raw.handle, "MYHANDLE", 8 ); + memcpy( request_raw.handle.b, "MYHANDLE", 8 ); nbd_r2h_request( &request_raw, &request ); - memset( request_raw.handle, 0, 8 ); + request_raw.handle.w = 0; nbd_h2r_request( &request, &request_raw ); - fail_unless( memcmp( request.handle, "MYHANDLE", 8 ) == 0, "The handle was not copied." ); - fail_unless( memcmp( request_raw.handle, "MYHANDLE", 8 ) == 0, "The handle was not copied back." ); + fail_unless( memcmp( request.handle.b, "MYHANDLE", 8 ) == 0, "The handle was not copied." ); + fail_unless( memcmp( request_raw.handle.b, "MYHANDLE", 8 ) == 0, "The handle was not copied back." ); } END_TEST @@ -170,14 +170,14 @@ START_TEST(test_reply_handle) struct nbd_reply_raw reply_raw; struct nbd_reply reply; - memcpy( reply_raw.handle, "MYHANDLE", 8 ); + memcpy( reply_raw.handle.b, "MYHANDLE", 8 ); nbd_r2h_reply( &reply_raw, &reply ); - memset( reply_raw.handle, 0, 8 ); + reply_raw.handle.w = 0; nbd_h2r_reply( &reply, &reply_raw ); - fail_unless( memcmp( reply.handle, "MYHANDLE", 8 ) == 0, "The handle was not copied." ); - fail_unless( memcmp( reply_raw.handle, "MYHANDLE", 8 ) == 0, "The handle was not copied back." ); + fail_unless( memcmp( reply.handle.b, "MYHANDLE", 8 ) == 0, "The handle was not copied." ); + fail_unless( memcmp( reply_raw.handle.b, "MYHANDLE", 8 ) == 0, "The handle was not copied back." ); } END_TEST @@ -188,9 +188,8 @@ START_TEST( test_convert_from ) * nbd_request_raw */ struct nbd_request_raw request_raw; struct nbd_request request; - char readbuf[] = {0x80, 0, 0, 0, 0, 0, 0, 0}; - memcpy( &request_raw.from, readbuf, 8 ); + request_raw.from = 0x8000000000000000; nbd_r2h_request( &request_raw, &request ); From a09e14b2d465fea4d0fe593804db56f1804dc75f Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 11:06:39 +0100 Subject: [PATCH 08/32] whitespace fix --- tests/unit/check_nbdtypes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/check_nbdtypes.c b/tests/unit/check_nbdtypes.c index 90d3f8d..262d166 100644 --- a/tests/unit/check_nbdtypes.c +++ b/tests/unit/check_nbdtypes.c @@ -173,7 +173,7 @@ START_TEST(test_reply_handle) memcpy( reply_raw.handle.b, "MYHANDLE", 8 ); nbd_r2h_reply( &reply_raw, &reply ); - reply_raw.handle.w = 0; + reply_raw.handle.w = 0; nbd_h2r_reply( &reply, &reply_raw ); fail_unless( memcmp( reply.handle.b, "MYHANDLE", 8 ) == 0, "The handle was not copied." ); From 0fd16822eaf6b88082d8d9295b5000d64c3491fb Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 11:12:39 +0100 Subject: [PATCH 09/32] run tests in gitlab-ci --- .gitlab-ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..78f85b6 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,8 @@ +image: "ruby:2.1" + +before_script: + - apt-get update; apt-get install -y check + +unit_test: + script: + - rake test:run From 8de07801253d6769c3695c6635cfeee41bad1710 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 11:26:46 +0100 Subject: [PATCH 10/32] install libev-dev in gitlab-ci --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 78f85b6..ea0736b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ image: "ruby:2.1" before_script: - - apt-get update; apt-get install -y check + - apt-get update; apt-get install -y check libev-dev unit_test: script: From e4d398a0789ff18e7b56b570bfdbf8dca9319303 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 11:29:42 +0100 Subject: [PATCH 11/32] install net-tools in gitlab-ci --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ea0736b..67bb073 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ image: "ruby:2.1" before_script: - - apt-get update; apt-get install -y check libev-dev + - apt-get update; apt-get install -y check libev-dev net-tools unit_test: script: From d907025d71eefdda5ec153feef1394b3f70f1721 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 11:39:56 +0100 Subject: [PATCH 12/32] try a newer version of ruby in gitlab-ci --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 67bb073..f92c20b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: "ruby:2.1" +image: "ruby:2.2" before_script: - apt-get update; apt-get install -y check libev-dev net-tools From 50708326ec5358ec480c4c474209ac087fc0752b Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 11:42:32 +0100 Subject: [PATCH 13/32] try ruby2.3 in gitlab-ci --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f92c20b..6f6c894 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: "ruby:2.2" +image: "ruby:2.3" before_script: - apt-get update; apt-get install -y check libev-dev net-tools From 679fa6dbf85caba7540419e1f77381b0b740c407 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 11:54:09 +0100 Subject: [PATCH 14/32] force binary encoding in a ruby2.1-compatible way --- tests/acceptance/proxy_tests.rb | 2 +- tests/acceptance/test_serve_mode.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/proxy_tests.rb b/tests/acceptance/proxy_tests.rb index e4030a4..37b5a9d 100644 --- a/tests/acceptance/proxy_tests.rb +++ b/tests/acceptance/proxy_tests.rb @@ -4,7 +4,7 @@ require 'flexnbd/fake_dest' module ProxyTests def b - String.new("\xFF", encoding: "BINARY") + "\xFF".b end def with_proxied_client( override_size = nil ) diff --git a/tests/acceptance/test_serve_mode.rb b/tests/acceptance/test_serve_mode.rb index bbf6025..6cf383b 100644 --- a/tests/acceptance/test_serve_mode.rb +++ b/tests/acceptance/test_serve_mode.rb @@ -6,7 +6,7 @@ class TestServeMode < Test::Unit::TestCase def setup super - @b = String.new("\xFF", encoding: "BINARY") + @b = "\xFF".b @env = Environment.new @env.writefile1( "0" ) @env.serve1 From edcaef532ca7011c634c1d24201c7d508c483ef3 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 11:58:50 +0100 Subject: [PATCH 15/32] revert gitlab-ci to ruby2.1 --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6f6c894..67bb073 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: "ruby:2.3" +image: "ruby:2.1" before_script: - apt-get update; apt-get install -y check libev-dev net-tools From bf85e329a043fdc6be51d462982211ca42616ebf Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 12:03:23 +0100 Subject: [PATCH 16/32] clean build environment before running tests in gitlab-ci --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 67bb073..0a548a2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,4 +5,5 @@ before_script: unit_test: script: + - rake clean - rake test:run From d6968d8242925ef2777e805041654c11b5e57c3c Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 12:06:11 +0100 Subject: [PATCH 17/32] explicitly compile before running tests in gitlab-ci --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0a548a2..adbc4e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,4 +6,5 @@ before_script: unit_test: script: - rake clean + - rake build - rake test:run From d47a44a204c8aff091feda5198a5d29c556c41d9 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 12:07:24 +0100 Subject: [PATCH 18/32] install asciidoc in gitlab-ci --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index adbc4e7..7cc9902 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ image: "ruby:2.1" before_script: - - apt-get update; apt-get install -y check libev-dev net-tools + - apt-get update; apt-get install -y check libev-dev net-tools asciidoc unit_test: script: From 35d33407085843dfbbfd8d99523b526bfbcef5b0 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 12:10:21 +0100 Subject: [PATCH 19/32] avoid need for slow-to-install asciidoc in gitlab-ci --- .gitlab-ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7cc9902..6ee6917 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,10 +1,11 @@ image: "ruby:2.1" before_script: - - apt-get update; apt-get install -y check libev-dev net-tools asciidoc + - apt-get update; apt-get install -y check libev-dev net-tools unit_test: script: - rake clean - - rake build + - rake flexnbd + - rake flexnbd_proxy - rake test:run From ea7cd64fc21246028ed3e15803753eb149d3f4fb Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 5 Oct 2016 12:36:06 +0100 Subject: [PATCH 20/32] Moved tasks from Rake to Make The rake file was obsolete, apart from one invocation of ruby in a shell! --- Makefile | 21 +++++++++++++------- Rakefile | 60 -------------------------------------------------------- 2 files changed, 14 insertions(+), 67 deletions(-) delete mode 100644 Rakefile diff --git a/Makefile b/Makefile index 4b2102a..84284ef 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,9 @@ SRCS := $(COMMON_SRC) $(SERVER_SRC) $(PROXY_SRC) OBJS := $(COMMON_OBJ) $(SERVER_OBJ) $(PROXY_OBJ) -all: build/flexnbd build/flexnbd-proxy doc +all: build doc + +build: server proxy build/%.o: %.c mkdir -p $(dir $@) @@ -82,8 +84,8 @@ build/flexnbd-proxy: $(COMMON_OBJ) $(PROXY_OBJ) build/proxy-main.o $(LINK) $^ -o $@ server: build/flexnbd -proxy: build/flexnbd-proxy +proxy: build/flexnbd-proxy CHECK_SRC := $(wildcard tests/unit/*.c) CHECK_OBJ := $(CHECK_SRC:tests/unit/%.c=build/%.o) @@ -97,22 +99,27 @@ build/check_%: build/check_%.o check_objs: $(CHECK_OBJ) check_bins: $(CHECK_BINS) + check: $(CHECK_BINS) for bin in $^; do $$bin; done +acceptance: + cd tests/acceptance && RUBYOPT='-I.' ruby nbd_scenarios -v + +test: check acceptance + build/flexnbd.1: README.txt a2x --destination-dir build --format manpage $< + build/flexnbd-proxy.1: README.proxy.txt a2x --destination-dir build --format manpage $< + # If we don't pipe to file, gzip clobbers the original, causing make # to rebuild each time %.1.gz: %.1 gzip -c -f $< > $@ -server-man: build/flexnbd.1.gz -proxy-man: build/flexnbd-proxy.1.gz - -doc: server-man proxy-man +doc: build/flexnbd.1.gz build/flexnbd-proxy.1.gz install: mkdir -p $(INSTALLDIR) @@ -122,7 +129,7 @@ clean: rm -rf build/* -.PHONY: clean objs check_objs all server proxy check_bins check server-man proxy-man doc +.PHONY: clean objs check_objs all server proxy check_bins check doc build test acceptance # Include extra dependencies at the end, NOT before 'all' -include $(wildcard build/*.d) diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 97762ab..0000000 --- a/Rakefile +++ /dev/null @@ -1,60 +0,0 @@ -# encoding: utf-8 - -def make(*targets) - sh "make #{targets.map{|t| t.to_s}.join(" ")}" -end - -def maketask( opts ) - case opts - when Symbol - maketask opts => opts - else - opts.each do |name, targets| - task( name ){make *[*targets]} - end - end -end - - -desc "Build the binary and man page" -maketask :build => [:all, :doc] - -desc "Build just the flexnbd binary" -maketask :flexnbd => [:server] -file "build/flexnbd" => :flexnbd - -desc "Build just the flexnbd-proxy binary" -maketask :flexnbd_proxy => [:proxy] -file "build/flexnbd-proxy" => :flexnbd_proxy - -desc "Build just the man page" -maketask :man => :doc - - -namespace "test" do - desc "Run all tests" - task 'run' => ["unit", "scenarios"] - - desc "Build C tests" - maketask :build => :check_bins - - desc "Run C tests" - maketask :unit => :check - - desc "Run NBD test scenarios" - task 'scenarios' => ["build/flexnbd", "build/flexnbd-proxy"] do - sh "cd tests/acceptance && RUBYOPT='-I.' ruby nbd_scenarios -v" - end -end - - -desc "Remove all build targets, binaries and temporary files" -maketask :clean - -file "debian/changelog" do - FileUtils.mkdir_p "debian" - sh "hg log --style=changelog.template > debian/changelog" -end - -desc "Generate the changelog" -task :changelog => "debian/changelog" From 93c0fa2e927ba614287c2f7f2f6bb661786ab072 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 5 Oct 2016 12:47:24 +0100 Subject: [PATCH 21/32] Merged in gitlab-ci.yml and fixed to use Make The CI should now use Make instead of Rake --- .gitlab-ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6ee6917..88c4223 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,6 @@ before_script: unit_test: script: - - rake clean - - rake flexnbd - - rake flexnbd_proxy - - rake test:run + - make clean + - make build + - make test From 30562ed900548d5714bad73545f2fa025595fd67 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 5 Oct 2016 12:49:25 +0100 Subject: [PATCH 22/32] Added dpkg-dev to requirements Allows dpkg-architecture to run. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6ee6917..0e0ea11 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ image: "ruby:2.1" before_script: - - apt-get update; apt-get install -y check libev-dev net-tools + - apt-get update; apt-get install -y check libev-dev net-tools dpkg-dev unit_test: script: From a744965c6752fe38424d5bfcf55acc1b938f11ca Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 12:51:58 +0100 Subject: [PATCH 23/32] add missing deps on server object files when building check binaries --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4b2102a..eb7cd81 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ CHECK_OBJ := $(CHECK_SRC:tests/unit/%.c=build/%.o) CHECK_BINS := $(CHECK_SRC:tests/unit/%.c=build/%) build/check_%: build/check_%.o - $(LINK) $^ -o $@ $(COMMON_OBJ) -lcheck + $(LINK) $^ -o $@ $(COMMON_OBJ) $(SERVER_OBJ) -lcheck check_objs: $(CHECK_OBJ) From 5da77ea39afcedf7c599d10603e4083277882ab3 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 12:52:32 +0100 Subject: [PATCH 24/32] remove unnecessary step in gitlab-ci --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6ee6917..14cb6af 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,5 +7,4 @@ unit_test: script: - rake clean - rake flexnbd - - rake flexnbd_proxy - rake test:run From 7d2eda6cea523ea8a045308bc6101e99ac8825d5 Mon Sep 17 00:00:00 2001 From: "James F. Carter" Date: Wed, 5 Oct 2016 16:28:27 +0100 Subject: [PATCH 25/32] failures in make check now result in an error --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 80163fc..77c1c20 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ check_objs: $(CHECK_OBJ) check_bins: $(CHECK_BINS) check: $(CHECK_BINS) - for bin in $^; do $$bin; done + r=true ; for bin in $^; do $$bin || r=false; done ; $$r acceptance: cd tests/acceptance && RUBYOPT='-I.' ruby nbd_scenarios -v From 091aacd16dfe5c23c38b47bbd97c98afb5ced446 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 6 Oct 2016 12:55:05 +0100 Subject: [PATCH 26/32] Updated manpages, replaces a2x with txt2man This simplifies the build-deps for Debian packages a little, and brings the docs up to date. --- Makefile | 4 +- README.proxy.txt | 134 ++++++++--------- README.txt | 371 ++++++++++++++++++++++++----------------------- 3 files changed, 255 insertions(+), 254 deletions(-) diff --git a/Makefile b/Makefile index 77c1c20..ecc58ed 100644 --- a/Makefile +++ b/Makefile @@ -109,10 +109,10 @@ acceptance: test: check acceptance build/flexnbd.1: README.txt - a2x --destination-dir build --format manpage $< + txt2man -t flexnbd -s 1 $< > $@ build/flexnbd-proxy.1: README.proxy.txt - a2x --destination-dir build --format manpage $< + txt2man -t flexnbd-proxy -s 1 $< > $@ # If we don't pipe to file, gzip clobbers the original, causing make # to rebuild each time diff --git a/README.proxy.txt b/README.proxy.txt index cc20c9c..c50bb23 100644 --- a/README.proxy.txt +++ b/README.proxy.txt @@ -1,19 +1,14 @@ -FLEXNBD-PROXY(1) -================ -:doctype: manpage - NAME ----- -flexnbd-proxy - A simple NBD proxy + flexnbd-proxy - A simple NBD proxy SYNOPSIS --------- -*flexnbd-proxy* ['OPTIONS'] + flexnbd-proxy --addr ADDR [--port PORT] --conn-addr ADDR + --conn-port PORT [--bind ADDR] [--cache[=CACHE_BYTES]] + [--help] [--verbose] [--quiet] DESCRIPTION ------------ flexnbd-proxy is a simple NBD proxy server that implements resilient connection logic for the client. It connects to an upstream NBD server @@ -25,11 +20,6 @@ of view of the client) reconnects and retransmits the request, before returning the response to the client. USAGE ------ - - $ flexnbd-proxy --addr [ --port ] - --conn-addr --conn-port - [--bind ] [--cache[=]] [option]* Proxy requests from an NBD client to an NBD server, resiliently. Only one client can be connected at a time, and ACLs cannot be applied to the client, as they @@ -58,75 +48,73 @@ Only one request may be in-flight at a time under the current architecture; that doesn't seem to slow things down much relative to alternative options, but may be changed in the future if it becomes an issue. -Options -~~~~~~~ +OPTIONS -*--addr, -l ADDR*: + --addr, -l ADDR The address to listen on. If this begins with a '/', it is assumed to be a UNIX domain socket to create. Otherwise, it should be an IPv4 or IPv6 address. -*--port, -p PORT*: + + --port, -p PORT The port to listen on, if --addr is not a UNIX socket. -*--conn-addr, -C ADDR*: + --conn-addr, -C ADDR The address of the NBD server to connect to. Required. -*--conn-port, -P PORT*: + --conn-port, -P PORT The port of the NBD server to connect to. Required. -*--cache, -c=CACHE_BYTES*: + --cache, -c=CACHE_BYTES If given, the size in bytes of read cache to use. CACHE_BYTES defaults to 4096. -*--help, -h* : + --help, -h Show command or global help. -*--verbose, -v* : + --verbose, -v Output all available log information to STDERR. -*--quiet, -q* : + --quiet, -q Output as little log information as possible to STDERR. - LOGGING -------- -Log output is sent to STDERR. If --quiet is set, no output will be seen -unless the program termintes abnormally. If neither --quiet nor + +Log output is sent to STDERR. If --quiet is set, no output will be +seen unless the program termintes abnormally. If neither --quiet nor --verbose are set, no output will be seen unless something goes wrong -with a specific request. If --verbose is given, every available log -message will be seen (which, for a debug build, is many). It is not an -error to set both --verbose and --quiet. The last one wins. +with a specific request. If --verbose is given, every available log +message will be seen (which, for a debug build, is many). It is not an +error to set both --verbose and --quiet. The last one wins. The log line format is: - :: :: + :: :: -*TIMESTAMP*: + Time the log entry was made. This is expressed in terms of monotonic ms -*LEVEL*: + This will be one of 'D', 'I', 'W', 'E', 'F' in increasing order of -severity. If flexnbd is started with the --quiet flag, only 'F' will be -seen. If it is started with the --verbose flag, any from 'I' upwards -will be seen. Only if you have a debug build and start it with ---verbose will you see 'D' entries. + severity. If flexnbd is started with the --quiet flag, only 'F' will + be seen. If it is started with the --verbose flag, any from 'I' + upwards will be seen. Only if you have a debug build and start it + with --verbose will you see 'D' entries. -*PID*: + This is the process ID. -*THREAD*: - flexnbd-proxy is currently single-threaded, so this should be the same -for all lines. That may not be the case in the future. + + flexnbd-proxy is currently single-threaded, so this should be the + same for all lines. That may not be the case in the future. -*SOURCEFILE:SOURCELINE*: + Identifies where in the source code this log line can be found. -*MSG*: - A short message describing what's happening, how it's being done, or -if you're very lucky *why* it's going on. + + A short message describing what's happening, how it's being done, or + if you're very lucky why it's going on. -Proxying -~~~~~~~~ +EXAMPLES The main point of the proxy mode is to allow clients that would otherwise break when the NBD server goes away (during a migration, for instance) to see a @@ -160,53 +148,59 @@ The data in myfile has been moved between physical servers without the nbd client process having to be disturbed at all. READ CACHE ----------- If the --cache option is given at the command line, either without an argument or with an argument greater than 0, flexnbd-proxy will use a -read-ahead cache. The cache as currently implemented doubles each read +read-ahead cache. The cache as currently implemented doubles each read request size, up to a maximum of 2xCACHE_BYTES, and retains the latter -half in a buffer. If the next read request from the client exactly +half in a buffer. If the next read request from the client exactly matches the region held in the buffer, flexnbd-proxy responds from the cache without making a request to the server. This pattern is designed to match sequential reads, such as those performed by a booting virtual machine. -Note: If specifying a cache size, you *must* use this form: +Note: If specifying a cache size, you must use this form: nbd-client$ flexnbd-proxy --cache=XXXX -That is, the '=' is required. This is a limitation of getopt-long. +That is, the '=' is required. This is a limitation of getopt-long. If no cache size is given, a size of 4096 bytes is assumed. Caching can be explicitly disabled by setting a size of 0. BUGS ----- -Should be reported to nick@bytemark.co.uk. +Should be reported via GitHub. + +* https://github.com/BytemarkHosting/flexnbd-c/issues Current issues include: -* Only old-style NBD negotiation is supported -* Only one request may be in-flight at a time -* All I/O is blocking, and signals terminate the process immediately -* UNIX socket support is limited to the listen address -* FLUSH and TRIM commands, and the FUA flag, are not supported -* DISCONNECT requests do not get passed through to the NBD server -* No active timeout-retry of requests - we trust the kernel's idea of failure +* only old-style NBD negotiation is supported; +* only one request may be in-flight at a time; +* all I/O is blocking, and signals terminate the process immediately; +* UNIX socket support is limited to the listen address; +* FLUSH and TRIM commands, and the FUA flag, are not supported; +* DISCONNECT requests do not get passed through to the NBD server; +* no active timeout-retry of requests - we trust the kernel's idea of + failure. AUTHOR ------- -Written by Alex Young . + +Originally written by Alex Young . Original concept and core code by Matthew Bloch . -Proxy mode written by Nick Thomas +Proxy mode written by Nick Thomas . -COPYING -------- +The full commit history is available on GitHub. -Copyright (c) 2012 Bytemark Hosting Ltd. Free use of this software is -granted under the terms of the GNU General Public License version 3 or -later. +SEE ALSO + +flexnbd(1), nbd-client(8), xnbd-server(8), xnbd-client(8) + +COPYRIGHT + +Copyright (c) 2012-2016 Bytemark Hosting Ltd. Free use of this +software is granted under the terms of the GNU General Public License +version 3 or later. diff --git a/README.txt b/README.txt index ad017f0..8adc836 100644 --- a/README.txt +++ b/README.txt @@ -1,17 +1,36 @@ -FLEXNBD(1) -========== -:doctype: manpage - NAME ----- + flexnbd - A fast NBD server SYNOPSIS --------- -*flexnbd* 'COMMAND' ['OPTIONS'] + + flexnbd MODE [ ARGS ] + + flexnbd serve --addr ADDR --port PORT --file FILE [--sock SOCK] + [--default-deny] [--killswitch] [global_option]* [acl_entry]* + + flexnbd listen --addr ADDR --port PORT --file FILE [--sock SOCK] + [--default-deny] [global_option]* [acl_entry]* + + flexnbd mirror --addr ADDR --port PORT --sock SOCK [--unlink] + [--bind BIND_ADDR] [global_option]* + + flexnbd acl --sock SOCK [acl_entry]+ [global_option]* + + flexnbd break --sock SOCK [global_option]* + + flexnbd status --sock SOCK [global_option]* + + flexnbd read --addr ADDR --port PORT --from OFFSET --size SIZE + [--bind BIND_ADDR] [global_option]* + + flexnbd write --addr ADDR --port PORT --from OFFSET --size SIZE + [--bind BIND_ADDR] [global_option]* + + flexnbd help [mode] [global_option]* DESCRIPTION ------------ + Flexnbd is a fast NBD server which supports live migration. Live migration is performed by writing the data to a new server. A failed migration will be invisible to any connected clients. @@ -19,304 +38,290 @@ migration will be invisible to any connected clients. Flexnbd tries quite hard to preserve sparsity of files it is serving, even across migrations. -COMMANDS --------- +SERVE MODE + +Serve a file. -serve -~~~~~ $ flexnbd serve --addr --port --file - [--sock ] [--default-deny] [-k] [global option]* [acl entry]* + [--sock ] [--default-deny] [-k] [global_option]* + [acl_entry]* -Serve a file. If any ACL entries are given (which should be IP +If any ACL entries are given (which should be IP addresses), only those clients listed will be permitted to connect. flexnbd will continue to serve until a SIGINT, SIGQUIT, or a successful migration. -Options -^^^^^^^ + OPTIONS -*--addr, -l ADDR*: + --addr, -l ADDR The address to listen on. Required. -*--port, -p PORT*: + --port, -p PORT The port to listen on. Required. -*--file, -f FILE*: + --file, -f FILE The file to serve. Must already exist. Required. -*--sock, -s SOCK*: - Path to a control socket to open. You will need this if you want to + --sock, -s SOCK + Path to a control socket to open. You will need this if you want to migrate, get the current status, or manipulate the access control list. -*--default-deny, -d*: - How to interpret an empty ACL. If --default-deny is given, an - empty ACL will let no clients connect. If it is not given, an + --default-deny, -d + How to interpret an empty ACL. If --default-deny is given, an + empty ACL will let no clients connect. If it is not given, an empty ACL will let any client connect. -*--killswitch, -k*: + --killswitch, -k If set, we implement a 2-minute timeout on NBD requests and responses. If a request takes longer than that to complete, the client is disconnected. This is useful to keep broken clients from breaking migrations, among other things. -listen -~~~~~~ - - $ flexnbd listen --addr --port --file - [--sock ] [--default-deny] [global option]* [acl entry]* +LISTEN MODE Listen for an inbound migration, and quit with a status of 0 on completion. + $ flexnbd listen --addr ADDR --port PORT --file FILE + [--sock SOCK] [--default-deny] [global_option]* + [acl_entry]* + flexnbd will wait for a successful migration, and then quit. The file to write the inbound migration data to must already exist before you run 'flexnbd listen'. Only one sender may connect to send data, and if the sender disconnects part-way through the migration, the destination will -expect it to reconnect and retry the whole migration. It isn't safe +expect it to reconnect and retry the whole migration. It isn't safe to assume that a partial migration can be resumed because the destination has no knowledge of whether a client has made a write to the source in the interim. -If the migration fails for a reason which the `flexnbd listen` process +If the migration fails for a reason which the 'flexnbd listen' process can't fix (say, a failed local write), it will exit with an error -status. In this case, the sender will continually retry the migration -until it succeeds, and you will need to restart the `flexnbd listen` +status. In this case, the sender will continually retry the migration +until it succeeds, and you will need to restart the 'flexnbd listen' process to allow that to happen. -Options -^^^^^^^ -As for 'serve'. + OPTIONS -mirror -~~~~~~ +As for serve. - $ flexnbd mirror --addr --port --sock SOCK - [--unlink] [--bind ] [global option]* +MIRROR MODE Start a migration from the server with control socket SOCK to the server listening at ADDR:PORT. + $ flexnbd mirror --addr ADDR --port PORT --sock SOCK [--unlink] + [--bind BIND_ADDR] [global_option]* + Migration can be a slow process. Rather than block the 'flexnbd mirror' process until it completes, it will exit with a message of "Migration started" once it has confirmation that the local server was able to -connect to ADDR:PORT and got an NBD header back. To check on the +connect to ADDR:PORT and got an NBD header back. To check on the progress of a running migration, use 'flexnbd status'. If the destination unexpectedly disconnects part-way through the migration, the source will attempt to reconnect and start the migration -again. It is not safe to resume the migration from where it left off +again. It is not safe to resume the migration from where it left off because the source can't see that the backing store behind the destination is intact, or even on the same machine. -If the `--unlink` option is given, the local file will be deleted -immediately before the mirror connection is terminated. This allows +If the --unlink option is given, the local file will be deleted +immediately before the mirror connection is terminated. This allows an otherwise-ambiguous situation to be resolved: if you don't unlink the file and the flexnbd process at either end is terminated, it's not -possible to tell which copy of the data is canonical. Since the +possible to tell which copy of the data is canonical. Since the unlink happens as soon as the sender knows that it has transmitted all the data, there can be no ambiguity. Note: files smaller than 4096 bytes cannot be mirrored. -Options -^^^^^^^ + OPTIONS -*--addr, -l ADDR*: - The address of the remote server to migrate to. Required. + --addr, -l ADDR + The address of the remote server to migrate to. Required. -*--port, -p PORT*: - The port of the remote server to migrate to. Required. + --port, -p PORT + The port of the remote server to migrate to. Required. -*--sock, -s SOCK*: - The control socket of the local server to migrate from. Required. + --sock, -s SOCK + The control socket of the local server to migrate from. Required. -*--unlink, -u*: - Unlink the served file from the local filesystem after successfully - mirroring. + --unlink, -u + Unlink the served file from the local filesystem after + successfully mirroring. -*--bind, -b BIND-ADDR*: - The local address to bind to. You may need this if the remote server - is using an access control list. + --bind, -b BIND_ADDR + The local address to bind to. You may need this if the remote + server is using an access control list. -break -~~~~~ - - $ flexnbd mirror --sock SOCK [global option]* +BREAK MODE Stop a running migration. -Options -^^^^^^^ + $ flexnbd break --sock SOCK [global_option]* -*--sock, -s SOCK*: - The control socket of the local server whose emigration to stop. - Required. + OPTIONS + --sock, -s SOCK + The control socket of the local server whose migration to stop. + Required. -acl -~~~ - - $ flexnbd acl --sock [acl entry]+ [global option]* +ACL MODE Set the access control list of the server with the control socket SOCK to the given access control list entries. + $ flexnbd acl --sock SOCK [acl_entry]+ [global_option]* + ACL entries are given as IP addresses. -Options -^^^^^^^ + OPTIONS -*--sock, -s SOCK*: - The control socket of the server whose ACL to replace. + --sock, -s SOCK + The control socket of the server whose ACL to replace. Required -status -~~~~~~ - - $ flexnbd status --sock [global option]* +STATUS MODE Get the current status of the server with control socket SOCK. -The status will be printed to STDOUT. It is a space-separated list of -key=value pairs. The space character will never appear in a key or -value. Currently reported values are: + $ flexnbd status --sock SOCK [global_option]* -*pid*: +The status will be printed to STDOUT. It is a space-separated list of +key=value pairs. The space character will never appear in a key or +value. Currently reported values are: + +pid The process id of the server listening on SOCK. -*is_mirroring*: +is_mirroring 'true' if this server is sending migration data, 'false' otherwise. -*has_control*: +has_control 'false' if this server was started in 'listen' mode. 'true' otherwise. -read -~~~~ + OPTIONS - $ flexnbd read --addr --port --from - --size [--bind BIND-ADDR] [global option]* + --sock, -s SOCK + The control socket of the server of interest. Required. + +READ MODE Connect to the server at ADDR:PORT, and read SIZE bytes starting at -OFFSET in a single NBD query. The returned data will be echoed to -STDOUT. In case of a remote ACL, set the local source address to -BIND-ADDR. +OFFSET in a single NBD query. -Options -^^^^^^^ + $ flexnbd read --addr ADDR --port PORT --from OFFSET --size SIZE + [--bind BIND_ADDR] [global_option]* -*--addr, -l ADDR*: - The address of the remote server. Required. +The returned data will be echoed to STDOUT. In case of a remote ACL, +set the local source address to BIND_ADDR. -*--port, -p PORT*: - The port of the remote server. Required. + OPTIONS -*--from, -F OFFSET*: - The byte offset to start reading from. Required. Maximum 2^62. + --addr, -l ADDR + The address of the remote server. Required. -*--size, -S SIZE*: - The number of bytes to read. Required. Maximum 2^30. + --port, -p PORT + The port of the remote server. Required. -*--bind, -b BIND-ADDR*: - The local address to bind to. You may need this if the remote server - is using an access control list. + --from, -F OFFSET + The byte offset to start reading from. Required. Maximum 2^62. -write -~~~~~ + --size, -S SIZE + The number of bytes to read. Required. Maximum 2^30. - $ cat ... | flexnbd write --addr --port --from - --size [--bind BIND-ADDR] [global option]* + --bind, -b BIND_ADDR + The local address to bind to. You may need this if the remote + server is using an access control list. + +WRITE MODE Connect to the server at ADDR:PORT, and write SIZE bytes from STDIN -starting at OFFSET in a single NBD query. In case of a remote ACL, set -the local source address to BIND-ADDR. +starting at OFFSET in a single NBD query. -Options -^^^^^^^ + $ cat ... | flexnbd write --addr ADDR --port PORT --from OFFSET + --size SIZE [--bind BIND_ADDR] [global_option]* -*--addr, -l ADDR*: - The address of the remote server. Required. +In case of a remote ACL, set the local source address to BIND_ADDR. -*--port, -p PORT*: - The port of the remote server. Required. + OPTIONS -*--from, -F OFFSET*: - The byte offset to start writing from. Required. Maximum 2^62. + --addr, -l ADDR + The address of the remote server. Required. -*--size, -S SIZE*: - The number of bytes to write. Required. Maximum 2^30. + --port, -p PORT + The port of the remote server. Required. -*--bind, -b BIND-ADDR*: - The local address to bind to. You may need this if the remote server - is using an access control list. + --from, -F OFFSET + The byte offset to start writing from. Required. Maximum 2^62. -help -~~~~ + --size, -S SIZE + The number of bytes to write. Required. Maximum 2^30. - $ flexnbd help [command] [global option]* + --bind, -b BIND_ADDR + The local address to bind to. You may need this if the remote + server is using an access control list. -Without 'command', show the list of available commands. With 'command', -show help for that command. +HELP MODE + + $ flexnbd help [mode] [global_option]* + +Without mode, show the list of available modes. With mode, show help for that mode. GLOBAL OPTIONS --------------- -*--help, -h* : - Show command or global help. +--help, -h Show mode or global help. -*--verbose, -v* : - Output all available log information to STDERR. - -*--quiet, -q* : - Output as little log information as possible to STDERR. +--verbose, -v Output all available log information to STDERR. +--quiet, -q Output as little log information as possible to STDERR. LOGGING -------- -Log output is sent to STDERR. If --quiet is set, no output will be seen -unless the program termintes abnormally. If neither --quiet nor + +Log output is sent to STDERR. If --quiet is set, no output will be +seen unless the program termintes abnormally. If neither --quiet nor --verbose are set, no output will be seen unless something goes wrong -with a specific request. If --verbose is given, every available log -message will be seen (which, for a debug build, is many). It is not an -error to set both --verbose and --quiet. The last one wins. +with a specific request. If --verbose is given, every available log +message will be seen (which, for a debug build, is many). It is not an +error to set both --verbose and --quiet. The last one wins. The log line format is: - :: :: + :: : -*TIMESTAMP*: - Time the log entry was made. This is expressed in terms of monotonic ms. + + Time the log entry was made. This is expressed in terms of monotonic + ms. -*LEVEL*: + This will be one of 'D', 'I', 'W', 'E', 'F' in increasing order of -severity. If flexnbd is started with the --quiet flag, only 'F' will be -seen. If it is started with the --verbose flag, any from 'I' upwards -will be seen. Only if you have a debug build and start it with ---verbose will you see 'D' entries. + severity. If flexnbd is started with the --quiet flag, only 'F' + will be seen. If it is started with the --verbose flag, any from 'I' + upwards will be seen. Only if you have a debug build and start it + with --verbose will you see 'D' entries. -*PID*: + This is the process ID. -*THREAD*: - There are several pthreads per flexnbd process: a main thread, a serve -thread, a thread per client, and possibly a pair of mirror threads and a -control thread. This field identifies which thread was responsible for -the log line. + + There are several pthreads per flexnbd process: a main thread, a + serve thread, a thread per client, and possibly a pair of mirror + threads and a control thread. This field identifies which thread was + responsible for the log line. -*SOURCEFILE:SOURCELINE*: + Identifies where in the source code this log line can be found. -*MSG*: + A short message describing what's happening, how it's being done, or -if you're very lucky *why* it's going on. + if you're very lucky why it's going on. EXAMPLES --------- -Serving a file -~~~~~~~~~~~~~~ + SERVING A FILE The simplest case is serving a file on the default nbd port: @@ -326,8 +331,7 @@ The simplest case is serving a file on the default nbd port: root:x: $ -Reading server status -~~~~~~~~~~~~~~~~~~~~~ + READING SERVER STATUS In order to read a server's status, we need it to open a control socket. @@ -335,13 +339,12 @@ In order to read a server's status, we need it to open a control socket. --sock /tmp/flexnbd.sock $ flexnbd status --sock /tmp/flexnbd.sock pid=9635 is_mirroring=false has_control=true - + $ Note that the status output is newline-terminated. -Migrating -~~~~~~~~~ + MIGRATING To migrate, we need to provide a destination file of the right size. @@ -367,8 +370,8 @@ With this knowledge in hand, we can start the migration: $ flexnbd mirror --addr 127.0.0.1 --port 4779 \ --sock /tmp/flex-source.sock Migration started - [1] + 9648 done build/flexnbd serve --addr 0.0.0.0 --port 4778 - [2] + 9651 done build/flexnbd listen --addr 0.0.0.0 --port 4779 + [1] + 9648 done flexnbd serve --addr 0.0.0.0 --port 4778 + [2] + 9651 done flexnbd listen --addr 0.0.0.0 --port 4779 $ Note that because the file is so small in this case, we see the source @@ -376,21 +379,25 @@ server quit soon after we start the migration, and the destination exited at roughly the same time. BUGS ----- -Should be reported to alex@bytemark.co.uk. +Should be reported on GitHub at + + * https://github.com/BytemarkHosting/flexnbd-c/issues AUTHOR ------- -Written by Alex Young . +Originally written by Alex Young . Original concept and core code by Matthew Bloch . -Some additions by Nick Thomas +Proxy mode written by Nick Thomas . -COPYING -------- +The full commit history is available on GitHub. -Copyright (c) 2012 Bytemark Hosting Ltd. Free use of this software is -granted under the terms of the GNU General Public License version 3 or -later. +SEE ALSO +flexnbd-proxy(1), nbd-client(8), xnbd-server(8), xnbd-client(8) + +COPYRIGHT + +Copyright (c) 2012-2016 Bytemark Hosting Ltd. Free use of this +software is granted under the terms of the GNU General Public License +version 3 or later. From 0dbea7f8fe79f05b55f2d14f163a818292e6b303 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 6 Oct 2016 13:11:07 +0100 Subject: [PATCH 27/32] Removed extra tabs Oops --- README.proxy.txt | 4 ++-- README.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.proxy.txt b/README.proxy.txt index c50bb23..91ec590 100644 --- a/README.proxy.txt +++ b/README.proxy.txt @@ -111,8 +111,8 @@ The log line format is: Identifies where in the source code this log line can be found. - A short message describing what's happening, how it's being done, or - if you're very lucky why it's going on. + A short message describing what's happening, how it's being done, or + if you're very lucky why it's going on. EXAMPLES diff --git a/README.txt b/README.txt index 8adc836..5d2ec39 100644 --- a/README.txt +++ b/README.txt @@ -85,7 +85,7 @@ Listen for an inbound migration, and quit with a status of 0 on completion. $ flexnbd listen --addr ADDR --port PORT --file FILE - [--sock SOCK] [--default-deny] [global_option]* + [--sock SOCK] [--default-deny] [global_option]* [acl_entry]* flexnbd will wait for a successful migration, and then quit. The file @@ -298,7 +298,7 @@ The log line format is: This will be one of 'D', 'I', 'W', 'E', 'F' in increasing order of - severity. If flexnbd is started with the --quiet flag, only 'F' + severity. If flexnbd is started with the --quiet flag, only 'F' will be seen. If it is started with the --verbose flag, any from 'I' upwards will be seen. Only if you have a debug build and start it with --verbose will you see 'D' entries. From 957707bcfc1b0a3c6052f7c1d42a730310e8b02b Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 6 Oct 2016 13:44:20 +0100 Subject: [PATCH 28/32] Fixed up internal test names (copy/pasta?) The test names output by `make check` now reflect reality. --- tests/unit/check_mbox.c | 6 +++--- tests/unit/check_readwrite.c | 2 +- tests/unit/check_util.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/unit/check_mbox.c b/tests/unit/check_mbox.c index 34ff07c..5399531 100644 --- a/tests/unit/check_mbox.c +++ b/tests/unit/check_mbox.c @@ -66,9 +66,9 @@ START_TEST( test_receive_blocks_until_post ) END_TEST -Suite* acl_suite(void) +Suite* mbox_suite(void) { - Suite *s = suite_create("acl"); + Suite *s = suite_create("mbox"); TCase *tc_create = tcase_create("create"); TCase *tc_post = tcase_create("post"); @@ -93,7 +93,7 @@ int main(void) log_level = 2; #endif int number_failed; - Suite *s = acl_suite(); + Suite *s = mbox_suite(); SRunner *sr = srunner_create(s); srunner_run_all(sr, CK_NORMAL); log_level = 0; diff --git a/tests/unit/check_readwrite.c b/tests/unit/check_readwrite.c index 91c48d1..e7eb719 100644 --- a/tests/unit/check_readwrite.c +++ b/tests/unit/check_readwrite.c @@ -150,7 +150,7 @@ END_TEST Suite* readwrite_suite(void) { - Suite *s = suite_create("acl"); + Suite *s = suite_create("readwrite"); TCase *tc_transfer = tcase_create("entrust"); TCase *tc_disconnect = tcase_create("disconnect"); diff --git a/tests/unit/check_util.c b/tests/unit/check_util.c index b6e3aaa..63e2ade 100644 --- a/tests/unit/check_util.c +++ b/tests/unit/check_util.c @@ -141,9 +141,9 @@ START_TEST( test_fatal_doesnt_call_handler ) END_TEST -Suite* error_suite(void) +Suite* util_suite(void) { - Suite *s = suite_create("error"); + Suite *s = suite_create("util"); TCase *tc_process = tcase_create("process"); TCase *tc_handler = tcase_create("handler"); @@ -163,7 +163,7 @@ Suite* error_suite(void) int main(void) { int number_failed; - Suite *s = error_suite(); + Suite *s = util_suite(); SRunner *sr = srunner_create(s); srunner_run_all(sr, CK_NORMAL); number_failed = srunner_ntests_failed(sr); From 6505588f257e7d7d05b25a931a5951391dd95deb Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 6 Oct 2016 14:01:47 +0100 Subject: [PATCH 29/32] Fixed check_readwrite test to pass correct handle to fd_write_reply The (char*) cast to resp->received.handle.b was causing a segfault --- tests/unit/check_readwrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/check_readwrite.c b/tests/unit/check_readwrite.c index 91c48d1..843c775 100644 --- a/tests/unit/check_readwrite.c +++ b/tests/unit/check_readwrite.c @@ -57,7 +57,7 @@ void * responder( void *respond_uncast ) fd_write_reply( sock_fd, wrong_handle, 0 ); } else { - fd_write_reply( sock_fd, (char*)resp->received.handle.b, 0 ); + fd_write_reply( sock_fd, resp->received.handle.w, 0 ); } write( sock_fd, "12345678", 8 ); } From 1338d9e910e71387f8c836b23f95c5cfc4061b3e Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 6 Oct 2016 14:46:29 +0100 Subject: [PATCH 30/32] Fix up nbdtypes test to correctly use htobe64 Previous change hadn't taken this into account, and hopefully this makes our test a little clearer. --- tests/unit/check_nbdtypes.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/unit/check_nbdtypes.c b/tests/unit/check_nbdtypes.c index 262d166..63ab4e8 100644 --- a/tests/unit/check_nbdtypes.c +++ b/tests/unit/check_nbdtypes.c @@ -189,12 +189,14 @@ START_TEST( test_convert_from ) struct nbd_request_raw request_raw; struct nbd_request request; - request_raw.from = 0x8000000000000000; + uint64_t target = 0x8000000000000000; + /* this is stored big-endian */ + request_raw.from = htobe64(target); + + /* We expect this to convert big-endian to the host format */ nbd_r2h_request( &request_raw, &request ); - uint64_t target = 1; - target <<= 63; fail_unless( target == request.from, "from was wrong" ); } END_TEST From 5a1bc21088394c87dd7b0a272cf29b1fc5ceeac9 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 6 Oct 2016 15:40:15 +0100 Subject: [PATCH 31/32] Update Makefile to specify dependencies properly for tests --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ecc58ed..5626aac 100644 --- a/Makefile +++ b/Makefile @@ -100,10 +100,10 @@ check_objs: $(CHECK_OBJ) check_bins: $(CHECK_BINS) -check: $(CHECK_BINS) - r=true ; for bin in $^; do $$bin || r=false; done ; $$r +check: $(OBJS) $(CHECK_BINS) + r=true ; for bin in $(CHECK_BINS); do $$bin || r=false; done ; $$r -acceptance: +acceptance: build cd tests/acceptance && RUBYOPT='-I.' ruby nbd_scenarios -v test: check acceptance From 898f3f6c7e4fae642e6bc1b50055cfe0ea944150 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 6 Oct 2016 15:43:20 +0100 Subject: [PATCH 32/32] Reinstated char * cast to remove compiler warning --- tests/unit/check_readwrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/check_readwrite.c b/tests/unit/check_readwrite.c index c605d4d..3cb2ba3 100644 --- a/tests/unit/check_readwrite.c +++ b/tests/unit/check_readwrite.c @@ -57,7 +57,7 @@ void * responder( void *respond_uncast ) fd_write_reply( sock_fd, wrong_handle, 0 ); } else { - fd_write_reply( sock_fd, resp->received.handle.w, 0 ); + fd_write_reply( sock_fd, (char *) resp->received.handle.w, 0 ); } write( sock_fd, "12345678", 8 ); }