~ubuntu-branches/ubuntu/wily/glusterfs/wily

« back to all changes in this revision

Viewing changes to extras/volgen/CreateVolfile.py

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2011-03-15 21:14:50 UTC
  • mfrom: (1.3.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20110315211450-5iekpirgkdntccne
Tags: 3.1.3-1
* New upstream release.
  - glusterfs-volgen and glusterfs-defrag have been removed.
* Suggest nfs-common with the glusterfs-server for native NFS support.
  Closes: #614988
* Migrate to dh_python2.
  Closes: #616826

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#    Copyright (c) 2009-2010 Gluster, Inc. <http://www.gluster.com>
2
 
#    This file is part of GlusterFS.
3
 
 
4
 
#    GlusterFS is free software; you can redistribute it and/or modify
5
 
#    it under the terms of the GNU General Public License as published
6
 
#    by the Free Software Foundation; either version 3 of the License,
7
 
#    or (at your option) any later version.
8
 
 
9
 
#    GlusterFS is distributed in the hope that it will be useful, but
10
 
#    WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
#    General Public License for more details.
13
 
 
14
 
#    You should have received a copy of the GNU General Public License
15
 
#    along with this program.  If not, see
16
 
#    <http://www.gnu.org/licenses/>.
17
 
 
18
 
import os, sys, string
19
 
 
20
 
#Cachesize calculator
21
 
cache_size = "`echo $(( $(grep 'MemTotal' /proc/meminfo | sed 's/[^0-9]//g') / 5120 ))`"
22
 
 
23
 
class CreateVolfile:
24
 
 
25
 
    def __init__ (self, server_dict, server, transport,
26
 
                  transports, options, server_array):
27
 
 
28
 
        self.host_dict = server_dict
29
 
        self.host = server
30
 
        self.volume_name = options.volume_name
31
 
        self.transport = transport
32
 
        self.transports = transports
33
 
        self.auth_parameters = options.auth_param
34
 
        self.raid_type = options.raid_type
35
 
        self.ib_devport = options.ib_dev
36
 
        self.conf_dir = options.conf_dir
37
 
        self.host_array = server_array
38
 
        self.enable_safe_mode = options.enable_safe_mode
39
 
        self.volume_size_server = options.size_server
40
 
        self.volume_size_client = options.size_client
41
 
        self.nfs = options.need_nfs
42
 
        self.num_replica = options.num_replica
43
 
        self.num_stripe = options.num_stripe
44
 
        if options.port:
45
 
            self.gfs_port    = options.port
46
 
            self.gfs_ib_port = options.port + 1
47
 
        else:
48
 
            self.gfs_port    = 24007
49
 
            self.gfs_ib_port = 24008
50
 
 
51
 
    def create_pmap_mount_volfile (self):
52
 
 
53
 
        raid_type = self.raid_type
54
 
 
55
 
        mount_volfile = "%s/%s-%s.vol" % (self.conf_dir, str(self.volume_name), str(self.transport))
56
 
        mount_fd = file ("%s" % (mount_volfile), "w")
57
 
 
58
 
        print "Generating client volfiles.. '%s'" % mount_volfile
59
 
 
60
 
        cmdline = string.join (sys.argv, ' ')
61
 
 
62
 
        mount_fd.write ("## file auto generated by %s\n" % sys.argv[0])
63
 
        mount_fd.write ("# Cmd line:\n")
64
 
        mount_fd.write ("# $ %s\n\n" % cmdline)
65
 
 
66
 
        if raid_type is not None:
67
 
            # Used for later usage
68
 
            mount_fd.write ("# RAID %d\n" % raid_type)
69
 
 
70
 
        mount_fd.write ("# TRANSPORT-TYPE %s\n" % self.transport)
71
 
        subvolumes = []
72
 
        for host in self.host_dict.keys():
73
 
            i = 1
74
 
            for export in self.host_dict[host]:
75
 
                mount_fd.write ("volume %s-%s\n" % (host,export))
76
 
                mount_fd.write ("    type protocol/client\n")
77
 
                mount_fd.write ("    option transport-type %s\n" %
78
 
                                self.transport)
79
 
                mount_fd.write ("    option remote-host %s\n" % host)
80
 
                if self.transport == 'ib-verbs':
81
 
                    mount_fd.write ("    option transport.ib-verbs.port %d\n" %
82
 
                                    self.ib_devport)
83
 
                if self.transport == 'tcp':
84
 
                    mount_fd.write ("    option transport.socket.nodelay on\n")
85
 
 
86
 
                mount_fd.write ("    option remote-subvolume %s\n" % export)
87
 
                mount_fd.write ("end-volume\n\n")
88
 
                i += 1
89
 
                subvolumes.append(str(host) + '-' + str(export))
90
 
 
91
 
        # Stripe section.. if given
92
 
        if raid_type is 0:
93
 
            max_stripe_idx = len (subvolumes) / self.num_stripe
94
 
            stripe_idx = 0
95
 
            index = 0
96
 
            while index < max_stripe_idx:
97
 
                mount_fd.write ("volume stripe-%d\n" % index)
98
 
                mount_fd.write ("    type cluster/stripe\n")
99
 
                mount_fd.write ("#    option block-size 128k\n")
100
 
                mount_fd.write ("#    option use-xattr no\n")
101
 
                mount_fd.write ("    subvolumes %s" % subvolumes[stripe_idx])
102
 
                sub_idx = 1
103
 
                while sub_idx < self.num_stripe:
104
 
                    mount_fd.write (" %s" % subvolumes[stripe_idx+sub_idx])
105
 
                    sub_idx += 1
106
 
                mount_fd.write ("\nend-volume\n\n")
107
 
                stripe_idx += self.num_stripe
108
 
                index +=1
109
 
 
110
 
        # Replicate section
111
 
        if raid_type is 1:
112
 
            max_mirror_idx = len (subvolumes) / self.num_replica
113
 
            mirror_idx = 0
114
 
            index = 0
115
 
            while index < max_mirror_idx:
116
 
                mount_fd.write ("volume mirror-%d\n" % index)
117
 
                mount_fd.write ("    type cluster/replicate\n")
118
 
                mount_fd.write ("    subvolumes %s" % subvolumes[mirror_idx])
119
 
                sub_idx = 1
120
 
                while sub_idx < self.num_replica:
121
 
                    mount_fd.write (" %s" % subvolumes[mirror_idx + sub_idx])
122
 
                    sub_idx += 1
123
 
                mount_fd.write ("\nend-volume\n\n")
124
 
                mirror_idx += self.num_replica
125
 
                index += 1
126
 
 
127
 
        # Distribute section
128
 
        if raid_type is 0:
129
 
            subvolumes = []
130
 
            flag = 0
131
 
            while flag < index:
132
 
                subvolumes.append ("stripe-%d" % flag)
133
 
                flag += 1
134
 
 
135
 
        if raid_type is 1:
136
 
            subvolumes = []
137
 
            flag = 0
138
 
            while flag < index:
139
 
                subvolumes.append ("mirror-%d" % flag)
140
 
                flag += 1
141
 
 
142
 
        if len (subvolumes) > 1:
143
 
            mount_fd.write ("volume distribute\n")
144
 
            mount_fd.write ("    type cluster/distribute\n")
145
 
            mount_fd.write ("#   option unhashed-sticky-bit yes"
146
 
                           "  # Used for migrating data while adding new nodes\n")
147
 
            mount_fd.write ("#   option min-free-disk 5%"
148
 
                           "  # Minimum free disk available on the volume\n")
149
 
            mount_fd.write ("    subvolumes %s\n" %
150
 
                                 string.join (subvolumes,' '))
151
 
            mount_fd.write ("end-volume\n\n")
152
 
            subvolumes[0] = "distribute"
153
 
 
154
 
        if self.volume_size_client:
155
 
            mount_fd.write ("volume quota\n")
156
 
            mount_fd.write ("    type features/quota\n")
157
 
            mount_fd.write ("    option disk-usage-limit %s\n" % self.volume_size_client)
158
 
            mount_fd.write ("#   option minimum-free-disk-limit 10GB\n"
159
 
                            "#   minimum free disk value (default) 0\n")
160
 
            mount_fd.write ("#   option refresh-interval 10\n")
161
 
            mount_fd.write ("    subvolumes %s\n" % subvolumes[0])
162
 
            mount_fd.write ("end-volume\n\n")
163
 
            subvolumes[0] = "quota"
164
 
 
165
 
        if self.enable_safe_mode:
166
 
            return
167
 
 
168
 
        self.performance_mode (subvolumes[0], mount_fd)
169
 
 
170
 
        return
171
 
 
172
 
 
173
 
    def performance_mode (self, cluster_subvolume, volfile_fd):
174
 
 
175
 
        volfile_fd.write ("volume writebehind\n")
176
 
        volfile_fd.write ("    type performance/write-behind\n")
177
 
        volfile_fd.write ("    option cache-size 4MB\n")
178
 
        volfile_fd.write ("#   option enable-trickling-writes yes # Flush final write calls when network is free\n")
179
 
        volfile_fd.write ("#   option enable-O_SYNC yes # Enable O_SYNC for write-behind\n")
180
 
        volfile_fd.write ("#   option disable-for-first-nbytes 1 # Disable first nbytes with very small initial writes\n")
181
 
        if self.volume_size_client:
182
 
            volfile_fd.write ("    subvolumes quota\n")
183
 
        else:
184
 
            volfile_fd.write ("    subvolumes %s\n" % cluster_subvolume)
185
 
            volfile_fd.write ("end-volume\n\n")
186
 
 
187
 
        volfile_fd.write ("volume readahead\n")
188
 
        volfile_fd.write ("    type performance/read-ahead\n")
189
 
        volfile_fd.write ("    option page-count 4\n")
190
 
        volfile_fd.write ("#   option force-atime-update yes # force updating atimes, default off\n")
191
 
        volfile_fd.write ("    subvolumes writebehind\n")
192
 
        volfile_fd.write ("end-volume\n\n")
193
 
 
194
 
        volfile_fd.write ("volume iocache\n")
195
 
        volfile_fd.write ("    type performance/io-cache\n")
196
 
        volfile_fd.write ("    option cache-size %sMB\n" % cache_size)
197
 
        volfile_fd.write ("    option cache-timeout 1\n")
198
 
        volfile_fd.write ("#   option priority *.html:1,abc*:2 # Priority list for iocaching files\n")
199
 
        volfile_fd.write ("    subvolumes readahead\n")
200
 
        volfile_fd.write ("end-volume\n\n")
201
 
 
202
 
        volfile_fd.write ("volume quickread\n")
203
 
        volfile_fd.write ("    type performance/quick-read\n")
204
 
        volfile_fd.write ("    option cache-timeout 1\n")
205
 
        volfile_fd.write ("    option max-file-size 64kB\n")
206
 
        volfile_fd.write ("    subvolumes iocache\n")
207
 
        volfile_fd.write ("end-volume\n\n")
208
 
 
209
 
        volfile_fd.write ("volume statprefetch\n")
210
 
        volfile_fd.write ("    type performance/stat-prefetch\n")
211
 
        volfile_fd.write ("    subvolumes quickread\n")
212
 
        volfile_fd.write ("end-volume\n\n")
213
 
 
214
 
        return
215
 
 
216
 
    def create_pmap_nfs_volfile (self):
217
 
 
218
 
        raid_type = self.raid_type
219
 
 
220
 
        mount_volfile = "%s/%s-%s-nfs.vol" % (self.conf_dir, str(self.volume_name), str(self.transport))
221
 
        mount_fd = file ("%s" % (mount_volfile), "w")
222
 
 
223
 
        print "Generating client volfiles.. '%s'" % mount_volfile
224
 
 
225
 
        cmdline = string.join (sys.argv, ' ')
226
 
 
227
 
        mount_fd.write ("## file auto generated by %s\n" % sys.argv[0])
228
 
        mount_fd.write ("# Cmd line:\n")
229
 
        mount_fd.write ("# $ %s\n\n" % cmdline)
230
 
 
231
 
        if raid_type is not None:
232
 
            # Used for later usage
233
 
            mount_fd.write ("# RAID %d\n" % raid_type)
234
 
 
235
 
        mount_fd.write ("# TRANSPORT-TYPE %s\n" % self.transport)
236
 
        subvolumes = []
237
 
        for host in self.host_dict.keys():
238
 
            i = 1
239
 
            for export in self.host_dict[host]:
240
 
                mount_fd.write ("volume %s-%d\n" % (host,i))
241
 
                mount_fd.write ("    type protocol/client\n")
242
 
                mount_fd.write ("    option transport-type %s\n" %
243
 
                                self.transport)
244
 
                mount_fd.write ("    option remote-host %s\n" % host)
245
 
                if self.transport == 'ib-verbs':
246
 
                    mount_fd.write ("    option transport.ib-verbs.port %d\n" %
247
 
                                    self.ib_devport)
248
 
                if self.transport == 'tcp':
249
 
                    mount_fd.write ("    option transport.socket.nodelay on\n")
250
 
 
251
 
                mount_fd.write ("    option remote-subvolume %s\n" % export)
252
 
                mount_fd.write ("end-volume\n\n")
253
 
                subvolumes.append(str(host) + '-' + str(i))
254
 
                i += 1
255
 
 
256
 
        # Stripe section.. if given
257
 
        if raid_type is 0:
258
 
            max_stripe_idx = len (subvolumes) / self.num_stripe
259
 
            stripe_idx = 0
260
 
            index = 0
261
 
            while index < max_stripe_idx:
262
 
                mount_fd.write ("volume stripe-%d\n" % index)
263
 
                mount_fd.write ("    type cluster/stripe\n")
264
 
                mount_fd.write ("#    option block-size 128k\n")
265
 
                mount_fd.write ("#    option use-xattr no\n")
266
 
                mount_fd.write ("    subvolumes %s" % subvolumes[stripe_idx])
267
 
                sub_idx = 1
268
 
                while sub_idx < self.num_stripe:
269
 
                    mount_fd.write (" %s" % subvolumes[stripe_idx+sub_idx])
270
 
                    sub_idx += 1
271
 
                mount_fd.write ("\nend-volume\n\n")
272
 
                stripe_idx += self.num_stripe
273
 
                index +=1
274
 
 
275
 
        # Replicate section
276
 
        if raid_type is 1:
277
 
            max_mirror_idx = len (subvolumes) / self.num_replica
278
 
            mirror_idx = 0
279
 
            index = 0
280
 
            while index < max_mirror_idx:
281
 
                mount_fd.write ("volume mirror-%d\n" % index)
282
 
                mount_fd.write ("    type cluster/replicate\n")
283
 
                mount_fd.write ("    subvolumes %s" % subvolumes[mirror_idx])
284
 
                sub_idx = 1
285
 
                while sub_idx < self.num_replica:
286
 
                    mount_fd.write (" %s" % subvolumes[mirror_idx + sub_idx])
287
 
                    sub_idx += 1
288
 
                mount_fd.write ("\nend-volume\n\n")
289
 
                mirror_idx += self.num_replica
290
 
                index += 1
291
 
 
292
 
        # Distribute section
293
 
        if raid_type is 0:
294
 
            subvolumes = []
295
 
            flag = 0
296
 
            while flag < index:
297
 
                subvolumes.append ("stripe-%d" % flag)
298
 
                flag += 1
299
 
 
300
 
        if raid_type is 1:
301
 
            subvolumes = []
302
 
            flag = 0
303
 
            while flag < index:
304
 
                subvolumes.append ("mirror-%d" % flag)
305
 
                flag += 1
306
 
 
307
 
        if len (subvolumes) > 1:
308
 
            mount_fd.write ("volume distribute\n")
309
 
            mount_fd.write ("    type cluster/distribute\n")
310
 
            mount_fd.write ("#   option unhashed-sticky-bit yes"
311
 
                           "  # Used for migrating data while adding new nodes\n")
312
 
            mount_fd.write ("#   option min-free-disk 5%"
313
 
                           "  # Minimum free disk available on the volume\n")
314
 
            mount_fd.write ("    subvolumes %s\n" %
315
 
                                 string.join (subvolumes,' '))
316
 
            mount_fd.write ("end-volume\n\n")
317
 
            subvolumes[0] = "distribute"
318
 
 
319
 
 
320
 
        mount_fd.write ("volume nfsxlator\n")
321
 
        mount_fd.write ("    type nfs/server\n")
322
 
        mount_fd.write ("    subvolumes %s\n" % subvolumes[0])
323
 
        mount_fd.write ("#   option rpc-auth.auth-unix         off  #Enabled by default\n")
324
 
        mount_fd.write ("#   option rpc-auth.auth-null         off  #Enabled by default\n")
325
 
        mount_fd.write ("#   By default all addresses are rejected until allowed.\n")
326
 
        mount_fd.write ("#   option rpc-auth.addr.reject       127.*\n")
327
 
        mount_fd.write ("#   option rpc-auth.addr.allow        localhost\n")
328
 
        mount_fd.write ("    option rpc-auth.addr.%s.allow %s\n" % (subvolumes[0], self.auth_parameters))
329
 
        mount_fd.write ("#   By default insecure ports are not allowed.\n")
330
 
        mount_fd.write ("#   option rpc-auth.ports.insecure    on\n")
331
 
        mount_fd.write ("#   option rpc-auth.ports.<volume>.insecure  on\n")
332
 
        mount_fd.write ("#   By default all access is read-write.\n")
333
 
        mount_fd.write ("#   option nfs3.<volume>.volume-access       read-only\n")
334
 
        mount_fd.write ("#   option nfs3.<volume>.volume-access       read-only\n")
335
 
        mount_fd.write ("#   option nfs3.read-size             128Kb\n")
336
 
        mount_fd.write ("#   option nfs3.write-size            32Kb\n")
337
 
        mount_fd.write ("#   option nfs3.readdir-size          64Kb\n")
338
 
        mount_fd.write ("#   option nfs3.<volume>.read-size    64Kb\n")
339
 
        mount_fd.write ("#   option nfs3.<volume>.write-size   64Kb\n")
340
 
        mount_fd.write ("#   option nfs3.posix1.readdir-size   128Kb\n")
341
 
        mount_fd.write ("end-volume\n\n")
342
 
 
343
 
        return
344
 
 
345
 
    def create_pmap_export_volfile (self):
346
 
 
347
 
        cmdline = string.join (sys.argv, ' ')
348
 
        i = 0
349
 
        for export in self.host_dict[self.host]:
350
 
            export_volfile = "%s/%s-%d.vol" % (self.conf_dir,
351
 
                                               str(self.volume_name + '.' + self.host),
352
 
                                               i)
353
 
            i += 1
354
 
            exp_fd = file ("%s" % (export_volfile),"w")
355
 
 
356
 
            print "Generating server volfiles.. for server %s as '%s'" % (self.host,
357
 
                                                                          export_volfile)
358
 
 
359
 
            exp_fd.write ("## file auto generated by %s\n" % sys.argv[0])
360
 
            exp_fd.write ("# Cmd line:\n")
361
 
            exp_fd.write ("# $ %s\n\n" % cmdline)
362
 
            exp_fd.write ("volume posix\n")
363
 
            exp_fd.write ("    type storage/posix\n")
364
 
            exp_fd.write ("#   option o-direct enable # (default: disable) boolean type only\n")
365
 
            exp_fd.write ("#   option export-statfs-size no # (default: yes) boolean type only\n")
366
 
            exp_fd.write ("#   option mandate-attribute off # (default: on) boolean type only\n")
367
 
            exp_fd.write ("#   option span-devices 8 # (default: 0) integer value\n")
368
 
            exp_fd.write ("#   option background-unlink yes # (default: no) boolean type\n")
369
 
 
370
 
            exp_fd.write ("    option directory %s\n" % export)
371
 
            exp_fd.write ("end-volume\n\n")
372
 
 
373
 
            if self.nfs:
374
 
                exp_fd.write ("volume posix-ac\n")
375
 
                exp_fd.write ("    type features/access-control\n")
376
 
                exp_fd.write ("    subvolumes posix\n")
377
 
                exp_fd.write ("end-volume\n\n")
378
 
 
379
 
            if self.volume_size_server:
380
 
                exp_fd.write ("volume quota\n")
381
 
                exp_fd.write ("    type features/quota\n")
382
 
                exp_fd.write ("    option disk-usage-limit %s\n" % self.volume_size_server)
383
 
                exp_fd.write ("#   option minimum-free-disk-limit 10GB"
384
 
                              "  # minimum free disk value (default) 0\n")
385
 
                exp_fd.write ("#   option refresh-interval 10\n")
386
 
                if self.nfs:
387
 
                    exp_fd.write ("    subvolumes posix-ac\n")
388
 
                else:
389
 
                    exp_fd.write ("    subvolumes posix\n")
390
 
                exp_fd.write ("end-volume\n\n")
391
 
 
392
 
            exp_fd.write ("volume locks\n")
393
 
            exp_fd.write ("    type features/locks\n")
394
 
            exp_fd.write ("#   option mandatory on # Default off, used in specific applications\n")
395
 
            if self.volume_size_server:
396
 
                exp_fd.write ("    subvolumes quota\n")
397
 
            elif self.nfs:
398
 
                exp_fd.write ("    subvolumes posix-ac\n")
399
 
            else:
400
 
                exp_fd.write ("    subvolumes posix\n")
401
 
            exp_fd.write ("end-volume\n\n")
402
 
 
403
 
            exp_fd.write ("volume replace-brick\n")
404
 
            exp_fd.write ("    type protocol/client\n")
405
 
            if self.transport:
406
 
                exp_fd.write ("    option transport-type %s\n" % self.transport)
407
 
            if self.gfs_port:
408
 
                exp_fd.write ("    option transport.remote-port 34034\n")
409
 
            exp_fd.write ("    option ping-timeout 42\n")
410
 
            exp_fd.write ("end-volume\n\n")
411
 
 
412
 
            exp_fd.write ("volume pump\n")
413
 
            exp_fd.write ("    type cluster/pump\n")
414
 
            exp_fd.write ("    subvolumes locks replace-brick\n")
415
 
            exp_fd.write ("end-volume\n\n")
416
 
 
417
 
            exp_fd.write ("volume %s\n" % export)
418
 
            exp_fd.write ("    type performance/io-threads\n")
419
 
            exp_fd.write ("    option thread-count 8\n")
420
 
            exp_fd.write ("#   option autoscaling yes # Heuristic for autoscaling threads on demand\n")
421
 
            exp_fd.write ("#   option min-threads 2 # min count for thread pool\n")
422
 
            exp_fd.write ("#   option max-threads 64 # max count for thread pool\n")
423
 
            exp_fd.write ("    subvolumes pump\n")
424
 
            exp_fd.write ("end-volume\n\n")
425
 
 
426
 
            for transport in self.transports:
427
 
                exp_fd.write ("volume server-%s\n" % export)
428
 
                exp_fd.write ("    type protocol/server\n")
429
 
                exp_fd.write ("    option transport-type %s\n" % transport)
430
 
                exp_fd.write ("    option auth.addr.%s.allow %s\n" %
431
 
                                  (export, self.auth_parameters))
432
 
                if transport == 'ib-verbs':
433
 
                    exp_fd.write ("    option transport.ib-verbs.port %d\n" %
434
 
                                  self.ib_devport)
435
 
                if transport == 'tcp':
436
 
                    exp_fd.write ("    option transport.socket.nodelay on\n")
437
 
                    exp_fd.write ("    option transport.socket.listen-port %d\n" % self.gfs_port)
438
 
                exp_fd.write ("    subvolumes %s\n" % export)
439
 
                exp_fd.write ("end-volume\n\n")
440
 
 
441
 
        return
442
 
 
443
 
 
444
 
    def create_mount_volfile (self):
445
 
 
446
 
        raid_type = self.raid_type
447
 
 
448
 
        mount_volfile = "%s/%s-%s.vol" % (self.conf_dir, str(self.volume_name), str(self.transport))
449
 
        mount_fd = file ("%s" % (mount_volfile), "w")
450
 
 
451
 
        print "Generating client volfiles.. '%s'" % mount_volfile
452
 
 
453
 
        cmdline = string.join (sys.argv, ' ')
454
 
 
455
 
        mount_fd.write ("## file auto generated by %s\n" % sys.argv[0])
456
 
        mount_fd.write ("# Cmd line:\n")
457
 
        mount_fd.write ("# $ %s\n\n" % cmdline)
458
 
 
459
 
        if raid_type is not None:
460
 
            # Used for later usage
461
 
            mount_fd.write ("# RAID %d\n" % raid_type)
462
 
 
463
 
        mount_fd.write ("# TRANSPORT-TYPE %s\n" % self.transport)
464
 
        subvolumes = []
465
 
        for host in self.host_dict.keys():
466
 
            i = 1
467
 
            for exports in self.host_dict[host]:
468
 
                mount_fd.write ("volume %s-%s\n" % (host,exports))
469
 
                mount_fd.write ("    type protocol/client\n")
470
 
                mount_fd.write ("    option transport-type %s\n" %
471
 
                                self.transport)
472
 
                mount_fd.write ("    option remote-host %s\n" % host)
473
 
                if self.transport == 'ib-verbs':
474
 
                    mount_fd.write ("    option transport.ib-verbs.port %d\n" %
475
 
                                    self.ib_devport)
476
 
                    mount_fd.write ("    option remote-port %d\n" %
477
 
                                    self.gfs_ib_port)
478
 
                if self.transport == 'tcp':
479
 
                    mount_fd.write ("    option transport.socket.nodelay on\n")
480
 
                    mount_fd.write ("    option remote-port %d\n" %
481
 
                                    self.gfs_port)
482
 
 
483
 
                mount_fd.write ("    option remote-subvolume %s\n" % exports)
484
 
                mount_fd.write ("end-volume\n\n")
485
 
                subvolumes.append(str(host) + '-' + str(exports))
486
 
 
487
 
        # Stripe section.. if given
488
 
        if raid_type is 0:
489
 
            max_stripe_idx = len (subvolumes) / self.num_stripe
490
 
            stripe_idx = 0
491
 
            index = 0
492
 
            while index < max_stripe_idx:
493
 
                mount_fd.write ("volume stripe-%d\n" % index)
494
 
                mount_fd.write ("    type cluster/stripe\n")
495
 
                mount_fd.write ("#    option block-size 128k\n")
496
 
                mount_fd.write ("#    option use-xattr no\n")
497
 
                mount_fd.write ("    subvolumes %s" % subvolumes[stripe_idx])
498
 
                sub_idx = 1
499
 
                while sub_idx < self.num_stripe:
500
 
                    mount_fd.write (" %s" % subvolumes[stripe_idx+sub_idx])
501
 
                    sub_idx += 1
502
 
                mount_fd.write ("\nend-volume\n\n")
503
 
                stripe_idx += self.num_stripe
504
 
                index +=1
505
 
 
506
 
        # Replicate section
507
 
        if raid_type is 1:
508
 
            max_mirror_idx = len (subvolumes) / self.num_replica
509
 
            mirror_idx = 0
510
 
            index = 0
511
 
            while index < max_mirror_idx:
512
 
                mount_fd.write ("volume mirror-%d\n" % index)
513
 
                mount_fd.write ("    type cluster/replicate\n")
514
 
                mount_fd.write ("    subvolumes %s" % subvolumes[mirror_idx])
515
 
                sub_idx = 1
516
 
                while sub_idx < self.num_replica:
517
 
                    mount_fd.write (" %s" % subvolumes[mirror_idx + sub_idx])
518
 
                    sub_idx += 1
519
 
                mount_fd.write ("\nend-volume\n\n")
520
 
                mirror_idx += self.num_replica
521
 
                index += 1
522
 
 
523
 
        # Distribute section
524
 
        if raid_type is 0:
525
 
            subvolumes = []
526
 
            flag = 0
527
 
            while flag < index:
528
 
                subvolumes.append ("stripe-%d" % flag)
529
 
                flag += 1
530
 
 
531
 
        if raid_type is 1:
532
 
            subvolumes = []
533
 
            flag = 0
534
 
            while flag < index:
535
 
                subvolumes.append ("mirror-%d" % flag)
536
 
                flag += 1
537
 
 
538
 
        if len (subvolumes) > 1:
539
 
            mount_fd.write ("volume distribute\n")
540
 
            mount_fd.write ("    type cluster/distribute\n")
541
 
            mount_fd.write ("#   option unhashed-sticky-bit yes"
542
 
                           "  # Used for migrating data while adding new nodes\n")
543
 
            mount_fd.write ("#   option min-free-disk 5%"
544
 
                           "  # Minimum free disk available on the volume\n")
545
 
            mount_fd.write ("    subvolumes %s\n" %
546
 
                                 string.join (subvolumes,' '))
547
 
            mount_fd.write ("end-volume\n\n")
548
 
            subvolumes[0] = "distribute"
549
 
 
550
 
 
551
 
        if self.nfs:
552
 
            mount_fd.write ("volume nfsxlator\n")
553
 
            mount_fd.write ("    type nfs/server\n")
554
 
            mount_fd.write ("    subvolumes %s\n" % subvolumes[0])
555
 
            mount_fd.write ("#   option rpc-auth.auth-unix         off  #Enabled by default\n")
556
 
            mount_fd.write ("#   option rpc-auth.auth-null         off  #Enabled by default\n")
557
 
            mount_fd.write ("#   By default all addresses are rejected until allowed.\n")
558
 
            mount_fd.write ("#   option rpc-auth.addr.reject       127.*\n")
559
 
            mount_fd.write ("#   option rpc-auth.addr.allow        localhost\n")
560
 
            mount_fd.write ("    option rpc-auth.addr.%s.allow %s\n" % (subvolumes[0], self.auth_parameters))
561
 
            mount_fd.write ("#   By default insecure ports are not allowed.\n")
562
 
            mount_fd.write ("#   option rpc-auth.ports.insecure    on\n")
563
 
            mount_fd.write ("#   option rpc-auth.ports.<volume>.insecure  on\n")
564
 
            mount_fd.write ("#   By default all access is read-write.\n")
565
 
            mount_fd.write ("#   option nfs3.<volume>.volume-access       read-only\n")
566
 
            mount_fd.write ("#   option nfs3.<volume>.volume-access       read-only\n")
567
 
            mount_fd.write ("#   option nfs3.read-size             128Kb\n")
568
 
            mount_fd.write ("#   option nfs3.write-size            32Kb\n")
569
 
            mount_fd.write ("#   option nfs3.readdir-size          64Kb\n")
570
 
            mount_fd.write ("#   option nfs3.<volume>.read-size    64Kb\n")
571
 
            mount_fd.write ("#   option nfs3.<volume>.write-size   64Kb\n")
572
 
            mount_fd.write ("#   option nfs3.posix1.readdir-size   128Kb\n")
573
 
            mount_fd.write ("end-volume\n\n")
574
 
            return
575
 
 
576
 
        if self.volume_size_client:
577
 
            mount_fd.write ("volume quota\n")
578
 
            mount_fd.write ("    type features/quota\n")
579
 
            mount_fd.write ("    option disk-usage-limit %s\n" % self.volume_size_client)
580
 
            mount_fd.write ("#   option minimum-free-disk-limit 10GB\n"
581
 
                            "#   minimum free disk value (default) 0\n")
582
 
            mount_fd.write ("#   option refresh-interval 10\n")
583
 
            mount_fd.write ("    subvolumes %s\n" % subvolumes[0])
584
 
            mount_fd.write ("end-volume\n\n")
585
 
            subvolumes[0] = "quota"
586
 
 
587
 
        if self.enable_safe_mode:
588
 
            return
589
 
 
590
 
        self.performance_mode (subvolumes[0], mount_fd)
591
 
 
592
 
        return
593
 
 
594
 
    def create_export_volfile (self):
595
 
 
596
 
        cmdline = string.join (sys.argv, ' ')
597
 
        export_volfile = "%s/%s-export.vol" % (self.conf_dir, str(self.host + '-' + self.volume_name))
598
 
        exp_fd = file ("%s" % (export_volfile),"w")
599
 
 
600
 
        print "Generating server volfiles.. for server %s as '%s'" % (self.host,
601
 
                                                                      export_volfile)
602
 
 
603
 
        exp_fd.write ("## file auto generated by %s\n" %
604
 
                      sys.argv[0])
605
 
        exp_fd.write ("# Cmd line:\n")
606
 
        exp_fd.write ("# $ %s\n\n" % cmdline)
607
 
        total_bricks = []
608
 
        i=1
609
 
        for export in self.host_dict[self.host]:
610
 
            exp_fd.write ("volume posix%d\n" % i)
611
 
            exp_fd.write ("    type storage/posix\n")
612
 
            exp_fd.write ("#   option o-direct enable # (default: disable) boolean type only\n")
613
 
            exp_fd.write ("#   option export-statfs-size no # (default: yes) boolean type only\n")
614
 
            exp_fd.write ("#   option mandate-attribute off # (default: on) boolean type only\n")
615
 
            exp_fd.write ("#   option span-devices 8 # (default: 0) integer value\n")
616
 
            exp_fd.write ("#   option background-unlink yes # (default: no) boolean type\n")
617
 
 
618
 
            exp_fd.write ("    option directory %s\n" % export)
619
 
            exp_fd.write ("end-volume\n\n")
620
 
 
621
 
            if self.nfs:
622
 
                exp_fd.write ("volume posix-ac%d\n" % i)
623
 
                exp_fd.write ("    type features/access-control\n")
624
 
                exp_fd.write ("    subvolumes posix%d\n" % i)
625
 
                exp_fd.write ("end-volume\n\n")
626
 
 
627
 
            if self.volume_size_server:
628
 
                exp_fd.write ("volume quota%d\n" % i)
629
 
                exp_fd.write ("    type features/quota\n")
630
 
                exp_fd.write ("    option disk-usage-limit %s\n" % self.volume_size_server)
631
 
                exp_fd.write ("#   option minimum-free-disk-limit 10GB"
632
 
                              "  # minimum free disk value (default) 0\n")
633
 
                exp_fd.write ("#   option refresh-interval 10\n")
634
 
                if self.nfs:
635
 
                    exp_fd.write ("    subvolumes posix-ac%d\n" % i)
636
 
                else:
637
 
                    exp_fd.write ("    subvolumes posix%d\n" % i)
638
 
                exp_fd.write ("end-volume\n\n")
639
 
 
640
 
 
641
 
            exp_fd.write ("volume locks%d\n" % i)
642
 
            exp_fd.write ("    type features/locks\n")
643
 
            exp_fd.write ("#   option mandatory on # Default off, used in specific applications\n")
644
 
            if self.volume_size_server:
645
 
                exp_fd.write ("    subvolumes quota%d\n" % i)
646
 
            else:
647
 
                exp_fd.write ("    subvolumes posix%d\n" % i)
648
 
            exp_fd.write ("end-volume\n\n")
649
 
 
650
 
            exp_fd.write ("volume %s\n" % export)
651
 
            exp_fd.write ("    type performance/io-threads\n")
652
 
            exp_fd.write ("    option thread-count 8\n")
653
 
            exp_fd.write ("#   option autoscaling yes # Heuristic for autoscaling threads on demand\n")
654
 
            exp_fd.write ("#   option min-threads 2 # min count for thread pool\n")
655
 
            exp_fd.write ("#   option max-threads 64 # max count for thread pool\n")
656
 
 
657
 
            exp_fd.write ("    subvolumes locks%d\n" % i)
658
 
            exp_fd.write ("end-volume\n\n")
659
 
 
660
 
            total_bricks.append("%s" % export)
661
 
            i += 1
662
 
 
663
 
        for transport in self.transports:
664
 
            exp_fd.write ("volume server-%s\n" % transport)
665
 
            exp_fd.write ("    type protocol/server\n")
666
 
            exp_fd.write ("    option transport-type %s\n" % transport)
667
 
            for brick in total_bricks:
668
 
                exp_fd.write ("    option auth.addr.%s.allow %s\n" %
669
 
                              (brick, self.auth_parameters))
670
 
 
671
 
            if transport == 'ib-verbs':
672
 
                exp_fd.write ("    option transport.ib-verbs.listen-port %d\n" % self.gfs_ib_port)
673
 
                exp_fd.write ("    option transport.ib-verbs.port %d\n" %
674
 
                              self.ib_devport)
675
 
            if transport == 'tcp':
676
 
                exp_fd.write ("    option transport.socket.listen-port %d\n" % self.gfs_port)
677
 
                exp_fd.write ("    option transport.socket.nodelay on\n")
678
 
 
679
 
            exp_fd.write ("    subvolumes %s\n" %
680
 
                          string.join(total_bricks, ' '))
681
 
            exp_fd.write ("end-volume\n\n")
682
 
 
683
 
        return
684