summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Gerus <arachnist@i.am-a.cat>2013-09-01 15:21:52 +0200
committerRobert Gerus <arachnist@i.am-a.cat>2013-09-01 15:21:52 +0200
commita846c0402c661a47e87213b309fd27c861551d49 (patch)
treeb3e339eff04b3754b76ba1a7da9cc1f5b550d798
downloadzvolcreator-a846c0402c661a47e87213b309fd27c861551d49.tar.gz
zvolcreator-a846c0402c661a47e87213b309fd27c861551d49.tar.bz2
zvolcreator-a846c0402c661a47e87213b309fd27c861551d49.zip
initial commit
-rw-r--r--.gitignore3
-rw-r--r--README1
-rw-r--r--config.rb7
-rw-r--r--zfs_monkeypatch.rb24
-rwxr-xr-xzvolcreator.rb20
5 files changed, 55 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fac8f80
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*~
+.*~
+.*swp
diff --git a/README b/README
new file mode 100644
index 0000000..35b377a
--- /dev/null
+++ b/README
@@ -0,0 +1 @@
+A tiny little ruby daemon for creating ZFS Volumes.
diff --git a/config.rb b/config.rb
new file mode 100644
index 0000000..3c85ef9
--- /dev/null
+++ b/config.rb
@@ -0,0 +1,7 @@
+# encoding: utf-8
+
+Config = {
+ :basefs => "amanojaku/uservols",
+ :default_user_quota => "5G",
+ :socketpath => "/run/zvolcreator/zvolcreator.sock"
+}
diff --git a/zfs_monkeypatch.rb b/zfs_monkeypatch.rb
new file mode 100644
index 0000000..f241798
--- /dev/null
+++ b/zfs_monkeypatch.rb
@@ -0,0 +1,24 @@
+# Monkeypatch the create() method, to add sparse volumes support
+class ZFS
+
+ # Create filesystem
+ def create(opts={})
+ return nil if exist?
+
+ cmd = [ZFS.zfs_path].flatten + ['create']
+ cmd << '-p' if opts[:parents]
+ cmd += ['-V', opts[:volume]] if opts[:volume]
+ cmd << '-s' if opts[:volume] and opts[:sparse]
+ cmd << name
+
+ out, status = Open3.capture2e(*cmd)
+ if status.success? and out.empty?
+ return self
+ elsif out.match(/dataset already exists\n$/)
+ nil
+ else
+ raise Exception, "something went wrong: #{out}, #{status}"
+ end
+ end
+
+end
diff --git a/zvolcreator.rb b/zvolcreator.rb
new file mode 100755
index 0000000..c598519
--- /dev/null
+++ b/zvolcreator.rb
@@ -0,0 +1,20 @@
+require 'zfs'
+require 'socket'
+
+require_relative 'zfs_monkeypatch'
+load File.dirname($0) + "/" + 'config.rb'
+
+sockdir = File.dirname(Config[:socketpath])
+
+# Check if socket directory exists, if not - create if with apropriate options
+Dir.mkdir(sockdir, 0700) if not File.exists?(sockdir)
+
+server = UNIXServer.open(Config[:socketpath])
+loop do
+ Thread.start(server.accept) do |client|
+ client.puts "i'm alive"
+ client.close
+ end
+end
+
+