libgfapi-ruby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c76e0c238e01dd72054a79ac78b55b71922d048
4
+ data.tar.gz: 418e0caf8e1a634b1485fce01a1770965a0922c6
5
+ SHA512:
6
+ metadata.gz: b4ff79d6248fcc8eed086d14490da110e73c626b9e14134803c65416e6ce341bc13cdc2f5167d11e7077b34da3e2a1c755086832e80d9179ab86cadfcc227455
7
+ data.tar.gz: 9854d3d99c7e8af888f354f2b44097c6d78ba39004439dd709f4539d960a7be468cfe04d1e48e06017bdd8fa3667d4706a05fbd72b58cc16bd6ef4b7911b8895
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in libgfapi-ruby.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Tomas Varaneckas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # libgfapi-ruby
2
+
3
+ Ruby bindings for [libgfapi](https://github.com/gluster/glusterfs/blob/master/api/src/glfs.h)
4
+ (GlusterFS API).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'libgfapi-ruby'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install libgfapi-ruby
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ require 'glusterfs'
24
+
25
+ fs = GlusterFS.new 'my_volume'
26
+ GlusterFS.set_volfile_server fs, 'tcp', '1.2.3.4', 24007
27
+ GlusterFS.init fs
28
+ fd = GlusterFS.creat fs, 'my_file', 2, 0755
29
+ str = "test data\n"
30
+ GlusterFS.write fd, str, str.size + 1, 0
31
+ GlusterFS.close fd
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( http://github.com/spajus/libgfapi-ruby/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module GlusterFS
2
+ VERSION = "0.0.1"
3
+ end
data/lib/glusterfs.rb ADDED
@@ -0,0 +1,339 @@
1
+ require "glusterfs/version"
2
+ require "ffi"
3
+
4
+ module GlusterFS
5
+ extend FFI::Library
6
+
7
+ # https://github.com/gluster/glusterfs/blob/master/api/src/glfs.h
8
+ ffi_lib 'gfapi'
9
+
10
+ =begin
11
+ SYNOPSIS
12
+
13
+ glfs_new: Create a new 'virtual mount' object.
14
+
15
+ DESCRIPTION
16
+
17
+ This is most likely the very first function you will use. This function
18
+ will create a new glfs_t (virtual mount) object in memory.
19
+
20
+ On this newly created glfs_t, you need to be either set a volfile path
21
+ (glfs_set_volfile) or a volfile server (glfs_set_volfile_server).
22
+
23
+ The glfs_t object needs to be initialized with glfs_init() before you
24
+ can start issuing file operations on it.
25
+
26
+ PARAMETERS
27
+
28
+ @volname: Name of the volume. This identifies the server-side volume and
29
+ the fetched volfile (equivalent of --volfile-id command line
30
+ parameter to glusterfsd). When used with glfs_set_volfile() the
31
+ @volname has no effect (except for appearing in log messages).
32
+
33
+ RETURN VALUES
34
+
35
+ NULL : Out of memory condition.
36
+ Others : Pointer to the newly created glfs_t virtual mount object.
37
+
38
+ glfs_t *glfs_new (const char *volname) __THROW;
39
+ =end
40
+ attach_function :new, :glfs_new, [:string], :pointer
41
+
42
+ =begin
43
+ SYNOPSIS
44
+
45
+ glfs_set_volfile: Specify the path to the volume specification file.
46
+
47
+ DESCRIPTION
48
+
49
+ If you are using a static volume specification file (without dynamic
50
+ volume management abilities from the CLI), then specify the path to
51
+ the volume specification file.
52
+
53
+ This is incompatible with glfs_set_volfile_server().
54
+
55
+ PARAMETERS
56
+
57
+ @fs: The 'virtual mount' object to be configured with the volume
58
+ specification file.
59
+
60
+ @volfile: Path to the locally available volume specification file.
61
+
62
+ RETURN VALUES
63
+
64
+ 0 : Success.
65
+ -1 : Failure. @errno will be set with the type of failure.
66
+
67
+ int glfs_set_volfile (glfs_t *fs, const char *volfile);
68
+ =end
69
+ attach_function :set_volfile, :gfs_set_volfile, [:pointer, :string], :int
70
+
71
+ =begin
72
+ SYNOPSIS
73
+
74
+ glfs_set_volfile_server: Specify the address of management server.
75
+
76
+ DESCRIPTION
77
+
78
+ This function specifies the address of the management server (glusterd)
79
+ to connect, and establish the volume configuration. The @volname
80
+ parameter passed to glfs_new() is the volume which will be virtually
81
+ mounted as the glfs_t object. All operations performed by the CLI at
82
+ the management server will automatically be reflected in the 'virtual
83
+ mount' object as it maintains a connection to glusterd and polls on
84
+ configuration change notifications.
85
+
86
+ This is incompatible with glfs_set_volfile().
87
+
88
+ PARAMETERS
89
+
90
+ @fs: The 'virtual mount' object to be configured with the volume
91
+ specification file.
92
+
93
+ @transport: String specifying the transport used to connect to the
94
+ management daemon. Specifying NULL will result in the usage
95
+ of the default (tcp) transport type. Permitted values
96
+ are those what you specify as transport-type in a volume
97
+ specification file (e.g "tcp", "rdma", "unix".)
98
+
99
+ @host: String specifying the address of where to find the management
100
+ daemon. Depending on the transport type this would either be
101
+ an FQDN (e.g: "storage01.company.com"), ASCII encoded IP
102
+ address "192.168.22.1", or a UNIX domain socket path (e.g
103
+ "/tmp/glusterd.socket".)
104
+
105
+ @port: The TCP port number where gluster management daemon is listening.
106
+ Specifying 0 uses the default port number GF_DEFAULT_BASE_PORT.
107
+ This parameter is unused if you are using a UNIX domain socket.
108
+
109
+ RETURN VALUES
110
+
111
+ 0 : Success.
112
+ -1 : Failure. @errno will be set with the type of failure.
113
+
114
+ int glfs_set_volfile_server (glfs_t *fs, const char *transport,
115
+ const char *host, int port) __THROW;
116
+ =end
117
+ attach_function :set_volfile_server, :glfs_set_volfile_server,
118
+ [:pointer, :string, :string, :int], :int
119
+
120
+ =begin
121
+ SYNOPSIS
122
+
123
+ glfs_set_logging: Specify logging parameters.
124
+
125
+ DESCRIPTION
126
+
127
+ This function specifies logging parameters for the virtual mount.
128
+ Default log file is /dev/null.
129
+
130
+ PARAMETERS
131
+
132
+ @fs: The 'virtual mount' object to be configured with the logging parameters.
133
+
134
+ @logfile: The logfile to be used for logging. Will be created if it does not
135
+ already exist (provided system permissions allow). If NULL, a new
136
+ logfile will be created in default log directory associated with
137
+ the glusterfs installation.
138
+
139
+ @loglevel: Numerical value specifying the degree of verbosity. Higher the
140
+ value, more verbose the logging.
141
+
142
+ RETURN VALUES
143
+
144
+ 0 : Success.
145
+ -1 : Failure. @errno will be set with the type of failure.
146
+
147
+ int glfs_set_logging (glfs_t *fs, const char *logfile, int loglevel) __THROW;
148
+ =end
149
+ attach_function :set_logging, :glfs_set_logging, [:pointer, :string, :int], :int
150
+
151
+ =begin
152
+ SYNOPSIS
153
+
154
+ glfs_init: Initialize the 'virtual mount'
155
+
156
+ DESCRIPTION
157
+
158
+ This function initializes the glfs_t object. This consists of many steps:
159
+ - Spawn a poll-loop thread.
160
+ - Establish connection to management daemon and receive volume specification.
161
+ - Construct translator graph and initialize graph.
162
+ - Wait for initialization (connecting to all bricks) to complete.
163
+
164
+ PARAMETERS
165
+
166
+ @fs: The 'virtual mount' object to be initialized.
167
+
168
+ RETURN VALUES
169
+
170
+ 0 : Success.
171
+ -1 : Failure. @errno will be set with the type of failure.
172
+
173
+ int glfs_init (glfs_t *fs) __THROW;
174
+ =end
175
+ attach_function :init, :glfs_init, [:pointer], :int
176
+
177
+ =begin
178
+ SYNOPSIS
179
+
180
+ glfs_fini: Cleanup and destroy the 'virtual mount'
181
+
182
+ DESCRIPTION
183
+
184
+ This function attempts to gracefully destroy glfs_t object. An attempt is
185
+ made to wait for all background processing to complete before returning.
186
+
187
+ glfs_fini() must be called after all operations on glfs_t is finished.
188
+
189
+ IMPORTANT
190
+
191
+ IT IS NECESSARY TO CALL glfs_fini() ON ALL THE INITIALIZED glfs_t
192
+ OBJECTS BEFORE TERMINATING THE PROGRAM. THERE MAY BE CACHED AND
193
+ UNWRITTEN / INCOMPLETE OPERATIONS STILL IN PROGRESS EVEN THOUGH THE
194
+ API CALLS HAVE RETURNED. glfs_fini() WILL WAIT FOR BACKGROUND OPERATIONS
195
+ TO COMPLETE BEFORE RETURNING, THEREBY MAKING IT SAFE FOR THE PROGRAM TO
196
+ EXIT.
197
+
198
+ PARAMETERS
199
+
200
+ @fs: The 'virtual mount' object to be destroyed.
201
+
202
+ RETURN VALUES
203
+
204
+ 0 : Success.
205
+
206
+ int glfs_fini (glfs_t *fs) __THROW;
207
+ =end
208
+ attach_function :fini, :glfs_fini, [:pointer], :int
209
+
210
+ =begin
211
+ PER THREAD IDENTITY MODIFIERS
212
+
213
+ The following operations enable to set a per thread identity context
214
+ for the glfs APIs to perform operations as. The calls here are kept as close
215
+ to POSIX equivalents as possible.
216
+
217
+ NOTES:
218
+
219
+ - setgroups is a per thread setting, hence this is named as fsgroups to be
220
+ close in naming to the fs(u/g)id APIs
221
+ - Typical mode of operation is to set the IDs as required, with the
222
+ supplementary groups being optionally set, make the glfs call and post the
223
+ glfs operation set them back to eu/gid or uid/gid as appropriate to the
224
+ caller
225
+ - The groups once set, need to be unset by setting the size to 0 (in which
226
+ case the list argument is a do not care)
227
+ - Once a process for a thread of operation choses to set the IDs, all glfs
228
+ calls made from that thread would default to the IDs set for the thread.
229
+ As a result use these APIs with care and ensure that the set IDs are
230
+ reverted to global process defaults as required.
231
+
232
+ int glfs_setfsuid (uid_t fsuid) __THROW;
233
+ int glfs_setfsgid (gid_t fsgid) __THROW;
234
+ int glfs_setfsgroups (size_t size, const gid_t *list) __THROW;
235
+ =end
236
+ attach_function :setfsuid, :glfs_setfsuid, [:int], :int
237
+ attach_function :setfsgid, :glfs_setfsgid, [:int], :int
238
+ attach_function :setfsgroups, :glfs_setfsgroups, [:uint, :pointer], :int
239
+
240
+ =begin
241
+ SYNOPSIS
242
+
243
+ glfs_open: Open a file.
244
+
245
+ DESCRIPTION
246
+
247
+ This function opens a file on a virtual mount.
248
+
249
+ PARAMETERS
250
+
251
+ @fs: The 'virtual mount' object to be initialized.
252
+
253
+ @path: Path of the file within the virtual mount.
254
+
255
+ @flags: Open flags. See open(2). O_CREAT is not supported.
256
+ Use glfs_creat() for creating files.
257
+
258
+ RETURN VALUES
259
+
260
+ NULL : Failure. @errno will be set with the type of failure.
261
+ Others : Pointer to the opened glfs_fd_t.
262
+
263
+ glfs_fd_t *glfs_open (glfs_t *fs, const char *path, int flags) __THROW;
264
+ =end
265
+ attach_function :open, :glfs_open, [:pointer, :string, :int], :pointer
266
+
267
+ =begin
268
+ SYNOPSIS
269
+
270
+ glfs_creat: Create a file.
271
+
272
+ DESCRIPTION
273
+
274
+ This function opens a file on a virtual mount.
275
+
276
+ PARAMETERS
277
+
278
+ @fs: The 'virtual mount' object to be initialized.
279
+
280
+ @path: Path of the file within the virtual mount.
281
+
282
+ @mode: Permission of the file to be created.
283
+
284
+ @flags: Create flags. See open(2). O_EXCL is supported.
285
+
286
+ RETURN VALUES
287
+
288
+ NULL : Failure. @errno will be set with the type of failure.
289
+ Others : Pointer to the opened glfs_fd_t.
290
+
291
+ glfs_fd_t *glfs_creat (glfs_t *fs, const char *path, int flags,
292
+ mode_t mode) __THROW;
293
+ =end
294
+ attach_function :creat, :glfs_creat, [:pointer, :string, :int, :int], :pointer
295
+
296
+ =begin
297
+ int glfs_close (glfs_fd_t *fd) __THROW;
298
+ =end
299
+ attach_function :close, :glfs_close, [:pointer], :int
300
+
301
+ =begin
302
+ // glfs_{read,write}[_async]
303
+
304
+ ssize_t glfs_read (glfs_fd_t *fd, void *buf,
305
+ size_t count, int flags) __THROW;
306
+ ssize_t glfs_write (glfs_fd_t *fd, const void *buf,
307
+ size_t count, int flags) __THROW;
308
+ int glfs_read_async (glfs_fd_t *fd, void *buf, size_t count, int flags,
309
+ glfs_io_cbk fn, void *data) __THROW;
310
+ int glfs_write_async (glfs_fd_t *fd, const void *buf, size_t count, int flags,
311
+ glfs_io_cbk fn, void *data) __THROW;
312
+ =end
313
+ attach_function :read, :glfs_read, [:pointer, :string, :uint, :int], :uint
314
+ attach_function :write, :glfs_write, [:pointer, :string, :uint, :int], :uint
315
+ # TODO async
316
+
317
+ =begin
318
+ int glfs_mkdir (glfs_t *fs, const char *path, mode_t mode) __THROW;
319
+ =end
320
+ attach_function :mkdir, :glfs_mkdir, [:pointer, :string, :int], :int
321
+
322
+ =begin
323
+ int glfs_unlink (glfs_t *fs, const char *path) __THROW;
324
+ =end
325
+ attach_function :unlink, :glfs_unlink, [:pointer, :string], :int
326
+
327
+ =begin
328
+ int glfs_rmdir (glfs_t *fs, const char *path) __THROW;
329
+ =end
330
+ attach_function :rmdir, :glfs_rmdir, [:pointer, :string], :int
331
+
332
+ =begin
333
+ int glfs_rename (glfs_t *fs, const char *oldpath, const char *newpath) __THROW;
334
+ =end
335
+ attach_function :rename, :glfs_rename, [:pointer, :string, :string], :int
336
+
337
+ # TODO the rest
338
+
339
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'glusterfs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "libgfapi-ruby"
8
+ spec.version = GlusterFS::VERSION
9
+ spec.authors = ["Tomas Varaneckas"]
10
+ spec.email = ["tomas.varaneckas@gmail.com"]
11
+ spec.summary = %q{Ruby bindings for libgfapi (GlusterFS API)}
12
+ spec.description = %q{Ruby bindings for libgfapi (GlusterFS API)}
13
+ spec.homepage = "https://github.com/spajus/libgfapi-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "ffi", "~> 1.9"
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libgfapi-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Varaneckas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Ruby bindings for libgfapi (GlusterFS API)
56
+ email:
57
+ - tomas.varaneckas@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - lib/glusterfs.rb
68
+ - lib/glusterfs/version.rb
69
+ - libgfapi-ruby.gemspec
70
+ homepage: https://github.com/spajus/libgfapi-ruby
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.0.6
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Ruby bindings for libgfapi (GlusterFS API)
94
+ test_files: []
95
+ has_rdoc: