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:
@@ -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?
|
||||
|
Reference in New Issue
Block a user