Add a no-op debug() define for non-debug builds and make valgrind optional in nbd_scenarios
This commit is contained in:
@@ -15,6 +15,9 @@ void* xmalloc(size_t size);
|
|||||||
void set_debug(int value);
|
void set_debug(int value);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
void debug(const char*msg, ...);
|
void debug(const char*msg, ...);
|
||||||
|
#else
|
||||||
|
/* no-op */
|
||||||
|
# define debug( msg, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CLIENT_ERROR(msg, ...) \
|
#define CLIENT_ERROR(msg, ...) \
|
||||||
|
@@ -7,6 +7,9 @@ class FlexNBD
|
|||||||
|
|
||||||
def initialize(bin, ip, port)
|
def initialize(bin, ip, port)
|
||||||
@bin = bin
|
@bin = bin
|
||||||
|
@debug = `#{@bin} serve --help` =~ /--debug/ ? "--debug" : ""
|
||||||
|
@valgrind = ENV['VALGRIND'] ? "valgrind " : ""
|
||||||
|
@bin = "#{@valgrind}#{@bin}"
|
||||||
raise "#{bin} not executable" unless File.executable?(bin)
|
raise "#{bin} not executable" unless File.executable?(bin)
|
||||||
@ctrl = "/tmp/.flexnbd.ctrl.#{Time.now.to_i}.#{rand}"
|
@ctrl = "/tmp/.flexnbd.ctrl.#{Time.now.to_i}.#{rand}"
|
||||||
@ip = ip
|
@ip = ip
|
||||||
@@ -16,12 +19,12 @@ class FlexNBD
|
|||||||
def serve(ip, port, file, *acl)
|
def serve(ip, port, file, *acl)
|
||||||
File.unlink(ctrl) if File.exists?(ctrl)
|
File.unlink(ctrl) if File.exists?(ctrl)
|
||||||
@pid = fork do
|
@pid = fork do
|
||||||
cmd ="valgrind #{@bin} serve "\
|
cmd ="#{@bin} serve "\
|
||||||
"--addr #{ip} "\
|
"--addr #{ip} "\
|
||||||
"--port #{port} "\
|
"--port #{port} "\
|
||||||
"--file #{file} "\
|
"--file #{file} "\
|
||||||
"--sock #{ctrl} "\
|
"--sock #{ctrl} "\
|
||||||
"--debug "\
|
"#{@debug} "\
|
||||||
"#{acl.join(' ')}"
|
"#{acl.join(' ')}"
|
||||||
exec(cmd)
|
exec(cmd)
|
||||||
end
|
end
|
||||||
@@ -34,11 +37,11 @@ class FlexNBD
|
|||||||
end
|
end
|
||||||
|
|
||||||
def read(offset, length)
|
def read(offset, length)
|
||||||
IO.popen("valgrind #{@bin} read "\
|
IO.popen("#{@bin} read "\
|
||||||
"--addr #{ip} "\
|
"--addr #{ip} "\
|
||||||
"--port #{port} "\
|
"--port #{port} "\
|
||||||
"--from #{offset} "\
|
"--from #{offset} "\
|
||||||
"--debug "\
|
"#{@debug} "\
|
||||||
"--size #{length}","r") do |fh|
|
"--size #{length}","r") do |fh|
|
||||||
return fh.read
|
return fh.read
|
||||||
end
|
end
|
||||||
@@ -46,11 +49,11 @@ class FlexNBD
|
|||||||
end
|
end
|
||||||
|
|
||||||
def write(offset, data)
|
def write(offset, data)
|
||||||
IO.popen("valgrind #{@bin} write "\
|
IO.popen("#{@bin} write "\
|
||||||
"--addr #{ip} "\
|
"--addr #{ip} "\
|
||||||
"--port #{port} "\
|
"--port #{port} "\
|
||||||
"--from #{offset} "\
|
"--from #{offset} "\
|
||||||
"--debug "\
|
"#{@debug} "\
|
||||||
"--size #{data.length}","w") do |fh|
|
"--size #{data.length}","w") do |fh|
|
||||||
fh.write(data)
|
fh.write(data)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user