liblvm 1.0.0

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.
Files changed (5) hide show
  1. data/README.md +97 -0
  2. data/ext/extconf.rb +9 -0
  3. data/ext/liblvm.c +224 -0
  4. data/lib/liblvm.rb +3 -0
  5. metadata +50 -0
data/README.md ADDED
@@ -0,0 +1,97 @@
1
+ ## Liblvm
2
+
3
+ liblvm is a rubygem provide functions to manipulate the linux LVM objects.
4
+ * Create Lvm
5
+ * Remove LVM
6
+ * Get LVM list
7
+ * Verify if a LVM exist
8
+ * Get vg extent size
9
+ * Get vg free size
10
+ * Get vg extent count
11
+
12
+ ### Requirement
13
+
14
+ * libllvm2.7 a linux library
15
+
16
+ ### Getting started
17
+
18
+ * Install the liblvm rubygem
19
+
20
+ ```ruby
21
+ gem install liblvm
22
+ ```
23
+ * Initialize the lvm Object
24
+ Before you should create your VG. The constructor take the VG name as argument
25
+
26
+ ```ruby
27
+ lvm = Linuxlvm.new('G5K_VG')
28
+ ```
29
+ puts lvm.get_lvm_version
30
+ puts lvm.vg_get_free_size
31
+ puts lvm.vg_get_extent_count
32
+ puts lvm.vg_get_extent_size
33
+ puts lvm.vg_get_free_extent_count
34
+ lvm.lv_create("test", lvm.vg_get_extent_size * 10)
35
+ puts lvm.lv_exist("test")
36
+ puts lvm.get_lv_list
37
+ puts lvm.lv_remove("test")
38
+ puts lvm.lv_exist("test")
39
+
40
+ * Get the lvm version
41
+ ```ruby
42
+ lvm.get_lvm_version
43
+ ```
44
+ * Get the VG free size (KB)
45
+
46
+ ```ruby
47
+ lvm.vg_get_free_size
48
+ ```
49
+
50
+ * Get VG extent count
51
+
52
+ ```ruby
53
+ lvm.vg_get_extent_count
54
+ ```
55
+
56
+ * Get VG extent size
57
+
58
+ ```ruby
59
+ lvm.vg_get_extent_size
60
+ ```
61
+
62
+ * Get vg free extent count
63
+
64
+ ```ruby
65
+ lvm.vg_get_free_extent_count
66
+ ```
67
+
68
+ * Create a LV object
69
+ the lv_create function take two argument the "lv name" and "lv size"
70
+
71
+ ```ruby
72
+ lvm.lv_create("test", lvm.vg_get_extent_size * 10)
73
+ ```
74
+
75
+ * Verify if a lv exist
76
+
77
+ ```ruby
78
+ lvm.lv_exist("test")
79
+ ```
80
+
81
+ * Get the lvs list
82
+
83
+ ```ruby
84
+ lvm.get_lv_list
85
+ ```
86
+ * Remove a Lv object
87
+
88
+ ```ruby
89
+ lvm.lv_remove("test")
90
+ ```
91
+
92
+
93
+
94
+
95
+
96
+
97
+
data/ext/extconf.rb ADDED
@@ -0,0 +1,9 @@
1
+
2
+ require 'mkmf'
3
+
4
+ have_header("lvm2app.h")
5
+ have_header("sys/types.h")
6
+ have_header("libdevmapper.h")
7
+ #have_header("sys/mount.h");
8
+ $LOCAL_LIBS = "/lib/libdevmapper.so.1.02.1 /lib/liblvm2app.so.2.2"
9
+ create_makefile("liblvm")
data/ext/liblvm.c ADDED
@@ -0,0 +1,224 @@
1
+ #include "ruby.h"
2
+ #include <lvm2app.h>
3
+ #include <string.h>
4
+ static VALUE
5
+ c_init(VALUE self, VALUE vg)
6
+ {
7
+ Check_Type(vg, T_STRING);
8
+ rb_iv_set(self, "@vg", vg);
9
+
10
+ return self;
11
+ }
12
+
13
+ static VALUE
14
+ c_get_vg(VALUE self)
15
+ {
16
+ VALUE vg = rb_iv_get(self, "@vg");
17
+ return vg;
18
+ }
19
+
20
+ static VALUE
21
+ c_set_vg(VALUE self, VALUE vg)
22
+ {
23
+ rb_iv_set(self, "@vg", vg);
24
+ }
25
+
26
+ static VALUE
27
+ c_get_lvm_version(VALUE self)
28
+ {
29
+ char *version;
30
+ version = lvm_library_get_version();
31
+ printf("\n Lvm version : %s \n", version);
32
+ }
33
+
34
+ static VALUE
35
+ c_vg_get_free_size(VALUE self)
36
+ {
37
+ lvm_t handle;
38
+ vg_t vg_handle;
39
+ VALUE vg = rb_iv_get(self, "@vg");
40
+ char *c_vg = STR2CSTR(vg);
41
+ handle = lvm_init(NULL);
42
+ vg_handle = lvm_vg_open(handle, c_vg, "r", NULL);
43
+ uint64_t free_size = lvm_vg_get_free_size(vg_handle);
44
+ lvm_vg_close(vg_handle);
45
+ lvm_quit(handle);
46
+ return INT2NUM(free_size);
47
+ }
48
+
49
+ static VALUE
50
+ c_vg_get_extent_size(VALUE self)
51
+ {
52
+ lvm_t handle;
53
+ vg_t vg_handle;
54
+ VALUE vg = rb_iv_get(self, "@vg");
55
+ char *c_vg = STR2CSTR(vg);
56
+ handle = lvm_init(NULL);
57
+ vg_handle = lvm_vg_open(handle, c_vg, "r", NULL);
58
+ uint64_t extent_size = lvm_vg_get_extent_size(vg_handle);
59
+ lvm_vg_close(vg_handle);
60
+ lvm_quit(handle);
61
+ return INT2NUM(extent_size);
62
+ }
63
+
64
+ static VALUE
65
+ c_vg_get_extent_count(VALUE self)
66
+ {
67
+ lvm_t handle;
68
+ vg_t vg_handle;
69
+ VALUE vg = rb_iv_get(self, "@vg");
70
+ char *c_vg = STR2CSTR(vg);
71
+ handle = lvm_init(NULL);
72
+ vg_handle = lvm_vg_open(handle, c_vg, "r", NULL);
73
+ uint64_t extent_count = lvm_vg_get_extent_count(vg_handle);
74
+ lvm_vg_close(vg_handle);
75
+ lvm_quit(handle);
76
+ return INT2NUM(extent_count);
77
+ }
78
+
79
+ static VALUE
80
+ c_vg_get_free_extent_count(VALUE self)
81
+ {
82
+ lvm_t handle;
83
+ vg_t vg_handle;
84
+ VALUE vg = rb_iv_get(self, "@vg");
85
+ char *c_vg = STR2CSTR(vg);
86
+ handle = lvm_init(NULL);
87
+ vg_handle = lvm_vg_open(handle, c_vg, "r", NULL);
88
+ uint64_t free_extent_count = lvm_vg_get_free_extent_count(vg_handle);
89
+ lvm_vg_close(vg_handle);
90
+ lvm_quit(handle);
91
+ return INT2NUM(free_extent_count);
92
+ }
93
+
94
+ static VALUE
95
+ c_vg_get_max_lv(VALUE self)
96
+ {
97
+ lvm_t handle;
98
+ vg_t vg_handle;
99
+ VALUE vg = rb_iv_get(self, "@vg");
100
+ char *c_vg = STR2CSTR(vg);
101
+ handle = lvm_init(NULL);
102
+ vg_handle = lvm_vg_open(handle, c_vg, "r", NULL);
103
+ uint64_t max_lv = lvm_vg_get_max_lv(vg_handle);
104
+ lvm_vg_close(vg_handle);
105
+ lvm_quit(handle);
106
+ return INT2NUM(max_lv);
107
+ }
108
+
109
+ lv_t lvm_lv_from_name(vg_t vg_handle, char *lv_name)
110
+ {
111
+ struct dm_list * lv_list = NULL;
112
+ lv_t lv_handle = NULL;
113
+ lv_list_t * lv_list_entry = NULL;
114
+ lv_list = lvm_vg_list_lvs(vg_handle);
115
+ if (lv_list != NULL) {
116
+ dm_list_iterate_items(lv_list_entry, lv_list) {
117
+ const char * lv_name_from_list = lvm_lv_get_name(lv_list_entry->lv);
118
+ if (strcmp(lv_name_from_list, lv_name) == 0) {
119
+ lv_handle = lv_list_entry->lv;
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ return lv_handle;
125
+ }
126
+
127
+ static VALUE
128
+ c_lv_exist(VALUE self, VALUE lv_name)
129
+ {
130
+ lvm_t handle;
131
+ lv_t lv_handle;
132
+ vg_t vg_handle;
133
+ VALUE vg = rb_iv_get(self,"@vg");
134
+ char *c_vg = STR2CSTR(vg);
135
+ char *c_lv_name = STR2CSTR(lv_name);
136
+ handle = lvm_init(NULL);
137
+ vg_handle = lvm_vg_open(handle, c_vg, "r" , NULL);
138
+ lv_handle = lvm_lv_from_name(vg_handle, c_lv_name);
139
+ lvm_vg_close(vg_handle);
140
+ lvm_quit(handle);
141
+ if (lv_handle == NULL)
142
+ return Qfalse;
143
+ else
144
+ return Qtrue;
145
+ }
146
+
147
+ static VALUE
148
+ c_lv_create(VALUE self, VALUE name, VALUE size)
149
+ {
150
+ lvm_t handle;
151
+ vg_t vg_handle;
152
+ VALUE vg = rb_iv_get(self, "@vg");
153
+ char *c_vg = STR2CSTR(vg);
154
+ char *c_name = STR2CSTR(name);
155
+ uint64_t c_size = NUM2LONG(size);
156
+ handle = lvm_init(NULL);
157
+ vg_handle = lvm_vg_open(handle, c_vg, "w", NULL);
158
+ lvm_vg_create_lv_linear(vg_handle, c_name, c_size);
159
+ lvm_vg_close(vg_handle);
160
+ lvm_quit(handle);
161
+ }
162
+
163
+ static VALUE
164
+ c_lv_remove(VALUE self, VALUE name)
165
+ {
166
+ lvm_t handle;
167
+ vg_t vg_handle;
168
+ lv_t lv_handle;
169
+ VALUE vg = rb_iv_get(self, "@vg");
170
+ char *c_vg = STR2CSTR(vg);
171
+ char *c_name = STR2CSTR(name);
172
+ handle = lvm_init(NULL);
173
+ vg_handle = lvm_vg_open(handle, c_vg, "w", NULL);
174
+ lv_handle = lvm_lv_from_name(vg_handle, c_name);
175
+ int rm = lvm_vg_remove_lv(lv_handle);
176
+ lvm_vg_close(vg_handle);
177
+ lvm_quit(handle);
178
+ if (rm == 0 )
179
+ return Qtrue;
180
+ else
181
+ return Qfalse;
182
+
183
+ }
184
+
185
+ void
186
+ c_get_lv_list(VALUE self)
187
+ {
188
+ lvm_t handle;
189
+ vg_t vg_handle;
190
+ VALUE vg = rb_iv_get(self, "@vg");
191
+ char *c_vg = STR2CSTR(vg);
192
+ handle = lvm_init(NULL);
193
+ vg_handle = lvm_vg_open(handle, c_vg, "r", NULL);
194
+ struct dm_list *lvnames;
195
+ struct lvm_lv_list *strl;
196
+ lvnames = lvm_vg_list_lvs(vg_handle);
197
+ printf("\n %s:", c_vg);
198
+ dm_list_iterate_items(strl, lvnames) {
199
+ lv_t lv_handle = strl->lv;
200
+ char *lv_name = lvm_lv_get_name(lv_handle);
201
+ printf ("\n- %s", lv_name);
202
+ }
203
+ lvm_vg_close(vg_handle);
204
+ lvm_quit(handle);
205
+ }
206
+
207
+ VALUE cLinuxlvm;
208
+ void Init_liblvm() {
209
+ cLinuxlvm = rb_define_class("Linuxlvm", rb_cObject);
210
+ rb_define_method(cLinuxlvm, "initialize", c_init, 1);
211
+ rb_define_method(cLinuxlvm, "get_lvm_version", c_get_lvm_version,0);
212
+ rb_define_method(cLinuxlvm, "get_vg", c_get_vg, 0);
213
+ rb_define_method(cLinuxlvm, "set_vg", c_set_vg, 1);
214
+ rb_define_method(cLinuxlvm, "lv_exist", c_lv_exist, 1);
215
+ rb_define_method(cLinuxlvm, "vg_get_free_size", c_vg_get_free_size, 0);
216
+ rb_define_method(cLinuxlvm, "vg_get_extent_size", c_vg_get_extent_size, 0);
217
+ rb_define_method(cLinuxlvm, "vg_get_extent_count", c_vg_get_extent_count, 0);
218
+ rb_define_method(cLinuxlvm, "vg_get_free_extent_count", c_vg_get_free_extent_count, 0);
219
+ rb_define_method(cLinuxlvm, "vg_get_max_lv", c_vg_get_max_lv, 0);
220
+ rb_define_method(cLinuxlvm, "lv_create", c_lv_create, 2);
221
+ rb_define_method(cLinuxlvm, "lv_remove", c_lv_remove, 1);
222
+ rb_define_method(cLinuxlvm, "get_lv_list", c_get_lv_list, 0);
223
+
224
+ }
data/lib/liblvm.rb ADDED
@@ -0,0 +1,3 @@
1
+ module LibLvm
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: liblvm
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mehrez Alachheb
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: liblvm is a ruby gem to use the linux library liblvm2 in ruby
15
+ email: lachheb.mehrez@gmail.com
16
+ executables: []
17
+ extensions:
18
+ - ext/extconf.rb
19
+ extra_rdoc_files:
20
+ - README.md
21
+ files:
22
+ - README.md
23
+ - ext/extconf.rb
24
+ - ext/liblvm.c
25
+ - lib/liblvm.rb
26
+ homepage: ''
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.22
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: liblvm is a ruby gem to use the linux library liblvm2 in ruby
50
+ test_files: []