diff options
author | Harshavardhana Ranganath <harsha@gluster.com> | 2009-11-25 14:40:55 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-11-26 03:04:22 -0800 |
commit | 057c071403eb808b065e760d91101d519f86b65c (patch) | |
tree | ca62848faacda616a0b1d8770bf8ed1e0b30d884 /extras | |
parent | 3429e8755756191d010896083ca9a7141682ead9 (diff) |
Volgen supporting multidisks and booster configuration for nfs and cifs
Signed-off-by: Harshavardhana <harsha@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 396 (Volgen multiple export directory support)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=396
Diffstat (limited to 'extras')
-rw-r--r-- | extras/Makefile.am | 8 | ||||
-rw-r--r-- | extras/glusterfs-volgen | 433 | ||||
-rw-r--r-- | extras/volgen/CreateBooster.py | 56 | ||||
-rw-r--r-- | extras/volgen/CreateVolfile.py | 238 | ||||
-rw-r--r-- | extras/volgen/Makefile.am | 8 | ||||
-rwxr-xr-x | extras/volgen/glusterfs-volgen | 184 |
6 files changed, 487 insertions, 440 deletions
diff --git a/extras/Makefile.am b/extras/Makefile.am index 9ad0442951a..8ec2edf05cc 100644 --- a/extras/Makefile.am +++ b/extras/Makefile.am @@ -3,13 +3,7 @@ docdir = $(datadir)/doc/glusterfs/ EditorModedir = $(docdir)/ EditorMode_DATA = glusterfs-mode.el glusterfs.vim -SUBDIRS = init.d benchmarking +SUBDIRS = init.d benchmarking volgen EXTRA_DIST = specgen.scm MacOSX/Portfile glusterfs-mode.el glusterfs.vim migrate-unify-to-distribute.sh backend-xattr-sanitize.sh -dist_bin_SCRIPTS = glusterfs-volgen - -install-exec-hook: - chmod 755 $(DESTDIR)$(bindir)/glusterfs-volgen - -CLEANFILES = diff --git a/extras/glusterfs-volgen b/extras/glusterfs-volgen deleted file mode 100644 index 5dcb9e3cea5..00000000000 --- a/extras/glusterfs-volgen +++ /dev/null @@ -1,433 +0,0 @@ -#!/usr/bin/python - -import getopt, sys, os, string - -transport_type = "tcp" -gfs_port = 6996 -raid_type = None -num_replica = 2 -num_stripe = 4 -cache_size = "1GB" - -def print_usage (name): - spaces = ' ' * (len(name) + 1) - print name, " --name <volume-name>" - print "%s[--raid 0|1|10]" % spaces - print "%s[--transport tcp|ib-verbs]" % spaces - print "%s[--cache-size <cache-size>]" % spaces - print "%s[--port <port>]" % spaces - print "%s[--export-directory <export-dir>]" % spaces - print "%s[--num-stripe n]" % spaces - print "%s[--num-replica m]" % spaces - print "%s[--usage, --help]" % spaces - print "%s[--upgrade]" % spaces - print "%s[--version]" % spaces - print "%sserver1 server2 ... serverN" % spaces - return - -def print_version (version): - print "glusterfs-volgen %s: A tool to generate volume files for GlusterFS." % version - print "Copyright (C) 2009 Gluster, Inc. <http://www.gluster.com>" - print """License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> -This is free software: you are free to change and redistribute it. -There is NO WARRANTY, to the extent permitted by law.""" - -def print_error (msg): - print "%s: %s" % (sys.argv[0], msg) - -def setup_env (): -# os.system ("mkdir -p "confdir"/glusterfs") -# os.system ("touch "confdir"/glusterfs/19993") - return - -def print_mount_volume (mount_fd, servers): - - global raid_type - global gfs_port - global transport_type - global num_replica - global num_stripe - global cache_size - - # Make sure 'server list is uniq' - tmp_servers = [] - for server in servers: - if server in tmp_servers: - print "duplicate entry in server list (%s).. exiting" % server - sys.exit (1) - tmp_servers.append (server); - - num_servers = len (servers) - - if num_servers is 0: - print "no servers given, exiting" - sys.exit (1) - - # Make sure proper RAID type is given - if raid_type == 1: - if (num_servers % num_replica) != 0: - print_error ("raid type (%d) and number of of hosts (%d) not appropriate" % (raid_type, num_servers)) - sys.exit (1) - num_stripe = 1 - - if raid_type == 0: - if (num_servers % num_stripe) != 0: - print_error ("raid type (%d) and number of of hosts (%d) not appropriate" % (raid_type, num_servers)) - sys.exit (1) - num_replica = 1 - - if raid_type == 10: - if (num_servers % (num_replica * num_stripe)) != 0: - print_error ("raid type (%d) and number of of hosts (%d) not appropriate" % (raid_type, num_servers)) - sys.exit (1) - - cmdline = string.join (sys.argv, ' ') - mount_fd.write ("## file auto generated by %s (mount.vol)\n" % sys.argv[0]) - mount_fd.write ("# Cmd line:\n") - mount_fd.write ("# $ %s\n\n" % cmdline) - - if raid_type is not None: - # Used for later usage - mount_fd.write ("# RAID %d\n" % raid_type) - - mount_fd.write ("# TRANSPORT-TYPE %s\n" % transport_type) - mount_fd.write ("# PORT %d\n\n" % gfs_port) - - for host in servers: - mount_fd.write ("volume %s\n" % host) - mount_fd.write (" type protocol/client\n") - mount_fd.write (" option transport-type %s\n" % transport_type) - mount_fd.write (" option remote-host %s\n" % host) - mount_fd.write (" option remote-port %d\n" % gfs_port) - mount_fd.write (" option remote-subvolume brick\n") - mount_fd.write ("end-volume\n\n") - - subvolumes = [] - subvolumes.append (host) - - # Stripe section.. if given - if raid_type is 0 or raid_type is 10: - subvolumes = [] - temp = [] - flag = 0 - for host in servers: - temp.append (host) - flag += 1 - if (flag % num_stripe) is 0: - subvolumes.append (string.join (temp, ' ')) - temp = [] - - max_stripe_idx = len (servers) / num_stripe - stripe_idx = 0 - while stripe_idx < max_stripe_idx: - mount_fd.write ("volume stripe-%d\n" % stripe_idx) - mount_fd.write (" type cluster/stripe\n") - mount_fd.write (" subvolumes %s\n" % subvolumes[stripe_idx]) - mount_fd.write ("end-volume\n\n") - stripe_idx += 1 - - # Replicate section - if raid_type is 1 or raid_type is 10: - if raid_type is 1: - subvolumes = [] - temp = [] - flag = 0 - for host in servers: - temp.append (host) - flag += 1 - if (flag % num_replica) is 0: - subvolumes.append (string.join (temp, ' ')) - temp = [] - else: - subvolumes = [] - temp = [] - flag = 0 - while flag < stripe_idx: - temp.append ("stripe-%d" % flag) - flag += 1 - if (flag % num_replica) is 0: - subvolumes.append (string.join (temp, ' ')) - temp = [] - - max_mirror_idx = len (servers) / (num_replica * num_stripe) - mirror_idx = 0 - while mirror_idx < max_mirror_idx: - mount_fd.write ("volume mirror-%d\n" % mirror_idx) - mount_fd.write (" type cluster/replicate\n") - mount_fd.write (" subvolumes %s\n" % subvolumes[mirror_idx]) - mount_fd.write ("end-volume\n\n") - mirror_idx += 1 - - # Distribute section - if raid_type is None: - subvolumes = [] - for host in servers: - subvolumes.append (host) - - elif raid_type is 0: - subvolumes = [] - flag = 0 - while flag < stripe_idx: - subvolumes.append ("stripe-%d" % flag) - flag += 1 - else: - subvolumes = [] - flag = 0 - while flag < mirror_idx: - subvolumes.append ("mirror-%d" % flag) - flag += 1 - - if len (subvolumes) > 1: - mount_fd.write ("volume distribute\n") - mount_fd.write (" type cluster/distribute\n") - mount_fd.write (" subvolumes %s\n" % string.join (subvolumes, ' ')) - mount_fd.write ("end-volume\n\n") - subvolumes[0] = "distribute" - - mount_fd.write ("volume writebehind\n") - mount_fd.write (" type performance/write-behind\n") - mount_fd.write (" option cache-size 4MB\n") - mount_fd.write (" subvolumes %s\n" % subvolumes[0]) - mount_fd.write ("end-volume\n\n") - - mount_fd.write ("volume io-cache\n") - mount_fd.write (" type performance/io-cache\n") - mount_fd.write (" option cache-size %s\n" % cache_size) - mount_fd.write (" subvolumes writebehind\n") - mount_fd.write ("end-volume\n\n") - - return - -def print_export_volume (exp_fd, export_dir): - - global transport_type - global gfs_port - - cmdline = string.join (sys.argv, ' ') - exp_fd.write ("## file auto generated by %s (export.vol)\n" % sys.argv[0]) - exp_fd.write ("# Cmd line:\n") - exp_fd.write ("# $ %s\n\n" % cmdline) - - exp_fd.write ("# TRANSPORT-TYPE %s\n" % transport_type) - exp_fd.write ("# PORT %d\n\n" % gfs_port) - - exp_fd.write ("volume posix\n") - exp_fd.write (" type storage/posix\n") - exp_fd.write (" option directory %s\n" % export_dir) - exp_fd.write ("end-volume\n\n") - - exp_fd.write ("volume locks\n") - exp_fd.write (" type features/locks\n") - exp_fd.write (" subvolumes posix\n") - exp_fd.write ("end-volume\n\n") - - exp_fd.write ("volume brick\n") - exp_fd.write (" type performance/io-threads\n") - exp_fd.write (" option thread-count 8\n") - exp_fd.write (" subvolumes locks\n") - exp_fd.write ("end-volume\n\n") - - exp_fd.write ("volume server\n") - exp_fd.write (" type protocol/server\n") - exp_fd.write (" option transport-type %s\n" % transport_type) - exp_fd.write (" option auth.addr.brick.allow *\n") - exp_fd.write (" option listen-port %d\n" % gfs_port) - exp_fd.write (" subvolumes brick\n") - exp_fd.write ("end-volume\n\n") - - return - -def upgrade_mount_volume (volume_path, new_servers): - - global transport_type - global gfs_port - global raid_type - - try: - tmp_read_fd = file (volume_path, "r") - except IOError, (errno, strerror): - print_error ("open of %s failed: %s" % (volume_path, strerror)) - sys.exit (1) - - volume_file_buf = tmp_read_fd.readlines () - volume_file_buf = map (string.strip, volume_file_buf) - - old_servers = [] - for line in volume_file_buf: - if line[0:6] == "# RAID": - raid_type = int (line[7:]) - - volume_name = "" - if line[0:6] == "volume": - volume_name = line[7:] - if (volume_name == "stripe-0" or volume_name == "mirror-0" or volume_name == "distribute"): - break - old_servers.append (volume_name) - - if (len (line) > 22 and line[7:21] == "transport-type"): - transport_type = line[22:] - - if (len (line) > 20 and line[7:18] == "remote-port"): - gfs_port = int (line[19:]) - - - servers = old_servers + new_servers - - # Make sure 'server list is uniq' - tmp_servers = [] - for server in servers: - if server in tmp_servers: - print_error ("duplicate entry in server list (%s)." % server) - sys.exit (1) - tmp_servers.append (server); - - try: - tmp_fd = file (volume_path, "w") - except IOError, (errno, strerror): - print_error ("open of %s failed: %s" % (volume_path, strerror)) - sys.exit (1) - - print_mount_volume (tmp_fd, servers) - print "Wrote new mount file %s" % volume_path - return - - -def main (): - - global transport_type - global gfs_port - global raid_type - global num_replica - global num_stripe - - main_name = None - - needs_upgrade = None - version_num ="0.1.3" - volume_name = None - export_dir = None - - if len(sys.argv) == 1: - print_usage (sys.argv[0]) - sys.exit (1) - - # TODO: take this variable from --prefix option. - confdir = "/usr/local/etc/glusterfs" - - #rport = $(($(ls ${confdir}/glusterfs/ | sort | head -n 1 | cut -f 1 -d -) - 10)); - #cache_size = "$(free | grep 'Mem:' | awk '{print $2 * .40}')KB"; # 40% of available memory - - export_volume_path="/dev/stdout" - mount_volume_path="/dev/stdout" - - try: - (opt, args) = getopt.getopt (sys.argv[1:], "r:t:c:p:d:n:o:v:uh", - ["raid=", - "transport=", - "cache-size=", - "port=", - "export-directory=", - "num-stripe=", - "num-replica=", - "name=", - "conf-dir=", - "upgrade", - "usage", - "version", - "help"]) - - except getopt.GetoptError, (msg, opt): - print msg - sys.exit (1) - - for (o, val) in opt: - if o == '--usage' or o == '--help': - print_usage (sys.argv[0]) - sys.exit (0) - - if o == '--upgrade': - needs_upgrade = 1 - - if o == '--num-stripe': - num_stripe = int (val) - - if o == '--num-replica': - num_replica = int (val) - - if o == '-n' or o == '--name': - main_name = val - - if o == '-o' or o == '--conf-dir': - print val - confdir = val - - if o == '-d' or o == '--export-directory': - export_dir = val - - if o == '-p' or o == '--port': - gfs_port = int (val) - - if o == '-c' or o == '--cache-size': - cache_size = val - - if o == '-r' or o == '--raid': - if (val != "1" and val != "0" and val != "10"): - print_error ("--raid: '" + val + "' is not a valid RAID type.") - print_usage (sys.argv[0]) - sys.exit (1) - raid_type = int (val) - - if o == '-t' or o == '--transport': - if (val != "tcp" and val != "ib-verbs"): - print_error ("--transport: '" + val + "' is not a valid transport type.") - print_usage (sys.argv[0]) - sys.exit (1) - transport_type = val - - if o == '-v' or o == '--version': - print_version (version_num) - sys.exit (0) - - if main_name is None: - print_error ("'--name' not specified.") - print_usage (sys.argv[0]) - sys.exit (1) - - setup_env() - export_volume_path = "%s/%s-export.vol" % (confdir, main_name) - mount_volume_path = "%s/%s-mount.vol" % (confdir, main_name) - - num_servers = len (args) - - if num_servers is 0: - print_error ("no servers specified.") - print_usage (sys.argv[0]) - sys.exit (1) - - if needs_upgrade is 1: - upgrade_mount_volume (mount_volume_path, args) - sys.exit (0) - - if export_dir is None: - print_error ("'--export-directory' not specified.") - sys.exit (1) - - try: - exp_fd = file (export_volume_path, "w") - except IOError, (errno, strerror): - print_error ("open of %s failed: %s" % (export_volume_path, strerror)) - sys.exit (1) - - try: - mount_fd = file (mount_volume_path, "w") - except IOError, (errno, strerror): - print_error ("open of %s failed: %s" % (mount_volume_path, strerror)) - sys.exit (1) - - print_export_volume (exp_fd, export_dir) - print "Wrote export file %s" % export_volume_path - print_mount_volume (mount_fd, args) - print "Wrote mount file %s" % mount_volume_path - return - -main () diff --git a/extras/volgen/CreateBooster.py b/extras/volgen/CreateBooster.py new file mode 100644 index 00000000000..9051f44017f --- /dev/null +++ b/extras/volgen/CreateBooster.py @@ -0,0 +1,56 @@ +GLUSTERFS_BOOSTER_FSTAB = "/etc/gluster/booster.fstab" +GLUSTERFS_UNFS3_EXPORTS = "/etc/gluster/boosterexports" +GLUSTERFS_CIFS_CONFIG = "/etc/gluster/boostersmb.conf" +LOGDIR = "/var/log/glusterfs" +CONFDIR = "/etc/gluster" +fstype = "glusterfs" + +class CreateBooster: + + def __init__ (self, main_name, export_dir): + + self.volume_name = main_name + self.export = export_dir + + def configure_booster_fstab (self): + if self.volume_name is None or self.export is None: + sys.exit(1) + + booster_fstab_fd = file (GLUSTERFS_BOOSTER_FSTAB, "a") + _fstab = "%s/%s.vol %s" % (CONFDIR, self.volume_name, self.export) + _options = "%s subvolume=io-cache" % fstype + _options_log = "logfile=%s/%s.log" % (LOGDIR, self.volume_name) + _options_ext = "loglevel=ERROR,attr_timeout=0" + booster_fstab_fd.write ("%s %s,%s,%s\n" % + (_fstab, + _options, + _options_log, + _options_ext)) + + return + + def configure_nfs_booster (self): + if self.volume_name is None or self.export is None: + sys.exit(1) + + nfs_exports_fd = file (GLUSTERFS_UNFS3_EXPORTS, "a") + nfs_exports_fd.write ("%s 0.0.0.0/0(rw,no_root_squash)\n" % + self.export) + return + + def configure_cifs_booster (self): + + if self.volume_name is None or self.export is None: + sys.exit(1) + + cifs_config_fd = file (GLUSTERFS_CIFS_CONFIG, "a") + cifs_config_fd.write ("[%s]\n" % self.volume_name) + cifs_config_fd.write ("comment = %s volume served by Gluster\n" % + self.volume_name) + cifs_config_fd.write ("path = %s\n" % self.export) + cifs_config_fd.write ("guest ok = yes\n") + cifs_config_fd.write ("public = yes\n") + cifs_config_fd.write ("writable = yes\n") + cifs_config_fd.write ("admin users = gluster\n") + cifs_config_fd.close() + return diff --git a/extras/volgen/CreateVolfile.py b/extras/volgen/CreateVolfile.py new file mode 100644 index 00000000000..1d22e8fb164 --- /dev/null +++ b/extras/volgen/CreateVolfile.py @@ -0,0 +1,238 @@ +import os, sys, string +import subprocess + +num_replica = 2 +num_stripe = 4 +cache_size = "1GB" + +class CreateVolfile: + + def __init__ (self, servers, server, volume_name, + transport, transports, port, auth_param, + ib_port, confdir, args): + self.hosts = servers + self.host = server + self.volume_name = volume_name + self.transport = transport + self.transports = transports + self.gfs_port = port + self.gfs_ib_port = port + 1 + self.auth_parameters = auth_param + self.ib_devport = ib_port + self.num_servers = len (self.hosts.keys()) + self.conf_dir = confdir + self.arguments = args + + def create_mount_volfile (self, raid_type): + + + if self.conf_dir: + mount_fd = file ("%s/%s-%s.vol" % (self.conf_dir, + str(self.volume_name), + str(self.transport)), "w") + else: + mount_fd = file ("%s-%s.vol" % (str(self.volume_name), + str(self.transport)), "w") + + print "Generating client volfiles.. for transport '%s'" % (self.transport) + + num_stripe = 4 + num_replica = 2 + + + cmdline = string.join (sys.argv, ' ') + mount_fd.write ("## file auto generated by %s (mount.vol)\n" % + sys.argv[0]) + mount_fd.write ("# Cmd line:\n") + mount_fd.write ("# $ %s\n\n" % cmdline) + + if raid_type is not None: + # Used for later usage + mount_fd.write ("# RAID %d\n" % raid_type) + + mount_fd.write ("# TRANSPORT-TYPE %s\n" % self.transport) + subvolumes = [] + for host in self.hosts.keys(): + i = 1 + for exports in self.hosts[host]: + mount_fd.write ("volume %s-%s\n" % (host,i)) + mount_fd.write (" type protocol/client\n") + mount_fd.write (" option transport-type %s\n" % + self.transport) + command = "dig %s | grep '^%s'" % (host, host) + ps = subprocess.Popen(command, + shell=True, + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=True) + ipaddress = host + if ps.wait() == 0: + output = ps.communicate() + ipaddress = output[0].split()[-1] + + mount_fd.write (" option remote-host %s\n" % ipaddress) + if self.transport == 'ib-verbs': + mount_fd.write (" option transport.ib-verbs.port %d\n" % + self.ib_devport) + mount_fd.write (" option transport.remote-port %d\n" % + self.gfs_ib_port) + if self.transport == 'tcp': + mount_fd.write (" option transport.socket.nodelay on\n") + mount_fd.write (" option transport.remote-port %d\n" % + self.gfs_port) + + mount_fd.write (" option remote-subvolume brick%s\n" % + i) + mount_fd.write ("end-volume\n\n") + i += 1 + + exportlist = {} + for entry in self.arguments: + node = entry.split(':')[0] + if not exportlist.has_key(node): + exportlist[node] = 1 + else: + exportlist[node] += 1 + subvolumes.append(str(node) + '-' + str(exportlist[node])) + + + if raid_type == 1: + if (len(subvolumes) % num_replica) != 0: + print "raid type (%d) and number of volumes (%d) invalid" % (raid_type, len(subvolumes)) + sys.exit (1) + + if raid_type == 0: + if (len(subvolumes) % num_stripe) != 0: + print "raid type (%d) and number of volumes (%d) invalid" % (raid_type, len(subvolumes)) + sys.exit (1) + + # Stripe section.. if given + if raid_type is 0: + max_stripe_idx = len (subvolumes) / num_stripe + stripe_idx = 0 + index = 0 + while index < max_stripe_idx: + mount_fd.write ("volume stripe-%d\n" % index) + mount_fd.write (" type cluster/stripe\n") + mount_fd.write (" subvolumes %s %s %s %s\n" % + (subvolumes[stripe_idx], + subvolumes[stripe_idx+1], + subvolumes[stripe_idx+2], + subvolumes[stripe_idx+3])) + mount_fd.write ("end-volume\n\n") + stripe_idx += 4 + index +=1 + + # Replicate section + if raid_type is 1: + max_mirror_idx = len (subvolumes) / num_replica + mirror_idx = 0 + index = 0 + while index < max_mirror_idx: + mount_fd.write ("volume mirror-%d\n" % index) + mount_fd.write (" type cluster/replicate\n") + mount_fd.write (" subvolumes %s %s\n" % + (subvolumes[mirror_idx], + subvolumes[mirror_idx+1])) + mount_fd.write ("end-volume\n\n") + mirror_idx += 2 + index += 1 + + # Distribute section + if raid_type is 0: + subvolumes = [] + flag = 0 + while flag < index: + subvolumes.append ("stripe-%d" % flag) + flag += 1 + if raid_type is 1: + subvolumes = [] + flag = 0 + while flag < index: + subvolumes.append ("mirror-%d" % flag) + flag += 1 + + if len (subvolumes) > 1: + mount_fd.write ("volume distribute\n") + mount_fd.write (" type cluster/distribute\n") + mount_fd.write (" subvolumes %s\n" % + string.join (subvolumes,' ')) + mount_fd.write ("end-volume\n\n") + subvolumes[0] = "distribute" + + mount_fd.write ("volume writebehind\n") + mount_fd.write (" type performance/write-behind\n") + mount_fd.write (" option cache-size 4MB\n") + mount_fd.write (" subvolumes %s\n" % subvolumes[0]) + mount_fd.write ("end-volume\n\n") + + mount_fd.write ("volume io-cache\n") + mount_fd.write (" type performance/io-cache\n") + mount_fd.write (" option cache-size %s\n" % cache_size) + mount_fd.write (" subvolumes writebehind\n") + mount_fd.write ("end-volume\n\n") + + return + + def create_export_volfile (self): + + cmdline = string.join (sys.argv, ' ') + + if self.conf_dir: + exp_fd = file ("%s/%s-export.vol" % + (self.conf_dir, + str(self.host + '-' + self.volume_name)),"w") + else: + exp_fd = file ("%s-export.vol" % + (str(self.host + '-' + self.volume_name)),"w") + + print "Generating server volfiles.. for server '%s'" % (self.host) + + exp_fd.write ("## file auto generated by %s (export.vol)\n" % + sys.argv[0]) + exp_fd.write ("# Cmd line:\n") + exp_fd.write ("# $ %s\n\n" % cmdline) + total_bricks = [] + i=1 + for export in self.hosts[self.host]: + exp_fd.write ("volume posix%d\n" % i) + exp_fd.write (" type storage/posix\n") + exp_fd.write (" option directory %s\n" % export) + exp_fd.write ("end-volume\n\n") + + exp_fd.write ("volume locks%d\n" % i) + exp_fd.write (" type features/locks\n") + exp_fd.write (" subvolumes posix%d\n" % i) + exp_fd.write ("end-volume\n\n") + + exp_fd.write ("volume brick%d\n" % i) + exp_fd.write (" type performance/io-threads\n") + exp_fd.write (" option thread-count 8\n") + exp_fd.write (" subvolumes locks%d\n" % i) + exp_fd.write ("end-volume\n\n") + + total_bricks.append("brick%s" % i) + i += 1 + + for transport in self.transports: + exp_fd.write ("volume server-%s\n" % transport) + exp_fd.write (" type protocol/server\n") + exp_fd.write (" option transport-type %s\n" % transport) + for brick in total_bricks: + exp_fd.write (" option auth.addr.%s.allow %s\n" % + (brick, self.auth_parameters)) + + if transport == 'ib-verbs': + exp_fd.write (" option transport.ib-verbs.listen-port %d\n" % self.gfs_ib_port) + exp_fd.write (" option transport.ib-verbs.port %d\n" % + self.ib_devport) + if transport == 'tcp': + exp_fd.write (" option transport.socket.listen-port %d\n" % self.gfs_port) + exp_fd.write (" option transport.socket.nodelay on\n") + + exp_fd.write (" subvolumes %s\n" % + string.join(total_bricks, ' ')) + exp_fd.write ("end-volume\n\n") + + return diff --git a/extras/volgen/Makefile.am b/extras/volgen/Makefile.am new file mode 100644 index 00000000000..73b62356ed3 --- /dev/null +++ b/extras/volgen/Makefile.am @@ -0,0 +1,8 @@ + +volgendir = $(datadir)/glusterfs +dist_volgen_DATA = CreateVolfile.py CreateBooster.py + +dist_bin_SCRIPTS = glusterfs-volgen + +CLEANFILES = + diff --git a/extras/volgen/glusterfs-volgen b/extras/volgen/glusterfs-volgen new file mode 100755 index 00000000000..1151053acf6 --- /dev/null +++ b/extras/volgen/glusterfs-volgen @@ -0,0 +1,184 @@ +#!/usr/bin/python + +import getopt, sys, os, string +import subprocess + +if not "/usr/share/glusterfs" in sys.path: + sys.path.append("/usr/share/glusterfs") + +from CreateVolfile import * +from CreateBooster import * + +def print_usage (name): + spaces = ' ' * (len(name) + 1) + print name, "--name <volume-name>" + print "%s[--raid 0|1]" % spaces + print "%s[--transport tcp,ib-verbs]" % spaces + print "%s[--port <port>]" % spaces + print "%s[--ibdev <lid>]" % spaces + print "%s[--auth <ip-range>]" % spaces + print "%s[--conf-dir <confdir>]" % spaces + print "%s[--usage]" % spaces + print "%s[--nfs]" % spaces + print "%s[--cifs]" % spaces + print "%s[--version]" % spaces + print "%shost1:<export> host2:<export> ... hostN:<exportNN>" % spaces + return + +def print_version (version): + print "glusterfs-volgen %s: A tool to generate volume files for GlusterFS." % version + print "Copyright (C) 2009 Gluster, Inc. <http://www.gluster.com>" + print """License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law.""" + + +def main (): + + needs_upgrade = None + needs_nfs = None + needs_cifs = None + version_num ="3.0" + _volume_name = None + _server_chain = {} + _server = None + _transports = ['tcp'] + _transport = None + _port = 6996 + _auth_param = "*" + _ib_dev = 1 + _raid_type = None + node = None + _conf_dir = None + + try: + (opt, args) = getopt.getopt (sys.argv[1:], "r:t:p:n:a:i:ch", + ["raid=", + "transport=", + "port=", + "name=", + "auth=", + "ibdev=", + "conf-dir=", + "nfs", + "cifs", + "usage", + "version", + "help"]) + + except getopt.GetoptError, (msg, opt): + print msg + sys.exit (1) + + for (o, val) in opt: + if o == '--usage' or o == '--help': + print_usage (sys.argv[0]) + sys.exit (0) + + if o == '-n' or o == '--name': + _volume_name = val + + if o == '--nfs': + needs_nfs = 1 + + if o == '--cifs': + needs_cifs = 1 + + if o == '-t' or o == '--transport': + if not val: + print "--transport: option " + val + \ + " is not valid transport type" + sys.exit (1) + _transports = val.split(',') + + if o == '-a' or o == '--auth': + _auth_param = val + + if o == '-p' or o == '--port': + _port = int(val) + + if o == '-r' or o == '--raid': + if (val != "1" and val != "0"): + print "--raid: option " + val + " is not valid raid type" + sys.exit (1) + _raid_type = int (val) + + if o == '-i' or o == '--ibdev': + _ib_dev = int(val) + + if o == '-v' or o == '--version': + print_version (version_num) + sys.exit (0) + + if o == '-c' or o == '--conf-dir': + _conf_dir = val + + if _volume_name is None: + print "Volume name is mandatory, please provide volume name.. exiting" + print_usage(sys.argv[0]) + sys.exit(1) + + _tmp = [] + for server in args: + if server not in _tmp: + _tmp.append (server) + else: + print "Duplicate arguments detected (%s)" % server + sys.exit(1) + + node = server.split(':')[0] + _server_chain[node] = [] + + for server in args: + node = server.split(':')[0] + if server.split(':')[1] not in _server_chain [node]: + if server.split(':')[1][0] != '/': + print "Absolute export path required for %s" % server + sys.exit(1) + _server_chain [node].append (server.split(':')[1]) + + num_servers = len (_server_chain.keys()) + + if num_servers is 0: + print "no servers provided, exiting" + print_usage(sys.argv[0]) + sys.exit (1) + + print num_servers + + + for _server in _server_chain.keys(): + create_exp = CreateVolfile (_server_chain, _server, + _volume_name, None, + _transports, _port, + _auth_param, _ib_dev, + _conf_dir, None) + try: + create_exp.create_export_volfile () + except IOError, (errno, strerror): + print "Got %s creating server volfiles for %s" % (strerror, _server) + + for _transport in _transports: + create_mnt = CreateVolfile (_server_chain, None, + _volume_name, _transport, + _transports, _port, + _auth_param, _ib_dev, + _conf_dir, args) + try: + create_mnt.create_mount_volfile (_raid_type) + except IOError, (errno, strerror): + print "Got %s creating client volfiles for transport '%s'" % (strerror, _transport) + + + for _server in _server_chain.keys(): + for export_dir in _server_chain[_server]: + commonobj = CreateBooster (_volume_name, export_dir) + if needs_nfs is 1 or needs_cifs is 1: + commonobj.configure_booster_fstab () + if needs_nfs is 1: + commonobj.configure_nfs_booster () + if needs_cifs is 1: + commonobj.configure_cifs_booster () + return + +main () |