Added getopt_long command-line handling.

All parameters now have switches.  The one gotcha is the parameter which
was overloaded - s_length_or_filename to params_readwrite - is only
pretending to be a length at the moment. If you pass a filename it'll
still work, but the help messages don't mention that.  I'll split the
parameter into two in a later commit.
This commit is contained in:
Alex Young
2012-05-30 15:19:40 +01:00
parent a01621dc1e
commit 0c62e66a70
3 changed files with 512 additions and 83 deletions

View File

@@ -15,7 +15,13 @@ class FlexNBD
def serve(ip, port, file, *acl)
@pid = fork do
exec("#{@bin} serve #{ip} #{port} #{file} #{ctrl} #{acl.join(' ')}")
cmd ="#{@bin} serve "\
"--addr #{ip} "\
"--port #{port} "\
"--file #{file} "\
"--sock #{ctrl} "\
"#{acl.join(' ')}"
exec(cmd)
end
end
@@ -25,14 +31,22 @@ class FlexNBD
end
def read(offset, length)
IO.popen("#{@bin} read #{ip} #{port} #{offset} #{length}","r") do |fh|
IO.popen("#{@bin} read "\
"--addr #{ip} "\
"--port #{port} "\
"--from #{offset} "\
"--size #{length}","r") do |fh|
return fh.read
end
raise "read failed" unless $?.success?
end
def write(offset, data)
IO.popen("#{@bin} write #{ip} #{port} #{offset} #{data.length}","w") do |fh|
IO.popen("#{@bin} write "\
"--addr #{ip} "\
"--port #{port} "\
"--from #{offset} "\
"--size #{data.length}","w") do |fh|
fh.write(data)
end
raise "write failed" unless $?.success?