summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Gerus <arachnist@i.am-a.cat>2013-09-01 19:31:54 +0200
committerRobert Gerus <arachnist@i.am-a.cat>2013-09-01 19:31:54 +0200
commitc8e3989f62d1feb1ba930ad7f99b9e8ed70215e4 (patch)
treeae10babe93857366b3c14982cdb110c8071fa0af
parentc7a9e769c3d564a577c54dc1ffa3d19890ba3037 (diff)
downloadzvolcreator-c8e3989f62d1feb1ba930ad7f99b9e8ed70215e4.tar.gz
zvolcreator-c8e3989f62d1feb1ba930ad7f99b9e8ed70215e4.tar.bz2
zvolcreator-c8e3989f62d1feb1ba930ad7f99b9e8ed70215e4.zip
Basic protocol code.
-rwxr-xr-xzvolcreator.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/zvolcreator.rb b/zvolcreator.rb
index 7d5dfc3..eb79069 100755
--- a/zvolcreator.rb
+++ b/zvolcreator.rb
@@ -2,11 +2,16 @@
require 'zfs'
require 'socket'
+require 'json'
require_relative 'zfs_monkeypatch'
load File.dirname($0) + "/" + 'config.rb'
+puts "Filesystem base: #{Config[:basefs]}"
+puts "Default user quota: #{Config[:default_user_quota]}"
+puts "Socket path: #{Config[:socketpath]}"
sockdir = File.dirname(Config[:socketpath])
+puts "socket directory: #{sockdir}"
# Check if socket directory exists, if not - create if with apropriate options
Dir.mkdir(sockdir, 0700) if not File.exists?(sockdir)
@@ -15,8 +20,21 @@ File.umask(0077)
server = UNIXServer.open(Config[:socketpath])
loop do
Thread.start(server.accept) do |client|
- client.puts "i'm alive"
- client.close
+ begin
+ client.puts({:status => 0, :content => {:app => "zvolcreator", :apiversion => 0}}.to_json)
+ response = JSON.parse(client.read)
+ raise ArgumentError.new("Bad status") if response["status"] != 0
+
+ client.puts({:status => 0, :content => {:basefs => Config[:basefs], :default_user_quota => Config[:default_user_quota]}}.to_json)
+ response = JSON.parse(client.read)
+ raise ArgumentError.new("Bad status") if response["status"] != 0
+ raise ArgumentError.new("No user specified") if not response["content"]["user"]
+ raise ArgumentError.new("Volume size not specified") if not response["content"]["volsize"]
+ rescue JSON::ParserError, ArgumentError => e
+ client.puts({:status => 1, :content => e.to_s})
+ client.close
+ Thread.kill
+ end
end
end