Class: CephRuby::RadosObject
- Inherits:
-
Object
- Object
- CephRuby::RadosObject
- Defined in:
- lib/ceph-ruby/rados_object.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#pool ⇒ Object
Returns the value of attribute pool.
Instance Method Summary collapse
- #destroy ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(pool, name) ⇒ RadosObject
constructor
A new instance of RadosObject.
-
#log(message) ⇒ Object
helper methods below.
- #read(offset, size) ⇒ Object
- #resize(size) ⇒ Object
- #size ⇒ Object
- #stat ⇒ Object
- #write(offset, data) ⇒ Object
Constructor Details
#initialize(pool, name) ⇒ RadosObject
Returns a new instance of RadosObject.
5 6 7 8 9 10 11 |
# File 'lib/ceph-ruby/rados_object.rb', line 5 def initialize(pool, name) self.pool = pool self.name = name if block_given? yield(self) end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/ceph-ruby/rados_object.rb', line 3 def name @name end |
#pool ⇒ Object
Returns the value of attribute pool.
3 4 5 |
# File 'lib/ceph-ruby/rados_object.rb', line 3 def pool @pool end |
Instance Method Details
#destroy ⇒ Object
36 37 38 39 40 |
# File 'lib/ceph-ruby/rados_object.rb', line 36 def destroy log("destroy") ret = Lib::Rados.rados_remove(pool.handle, name) raise SystemCallError.new("destroy of '#{name}' failed", -ret) if ret < 0 end |
#exists? ⇒ Boolean
13 14 15 16 17 18 19 |
# File 'lib/ceph-ruby/rados_object.rb', line 13 def exists? log("exists?") !!stat rescue SystemCallError => e return false if e.errno == Errno::ENOENT::Errno raise e end |
#log(message) ⇒ Object
helper methods below
66 67 68 |
# File 'lib/ceph-ruby/rados_object.rb', line 66 def log() CephRuby.log("rados object #{pool.name}/#{name} #{}") end |
#read(offset, size) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ceph-ruby/rados_object.rb', line 28 def read(offset, size) log("read offset #{offset}, size #{size}") data_p = FFI::MemoryPointer.new(:char, size) ret = Lib::Rados.rados_read(pool.handle, name, data_p, size, offset) raise SystemCallError.new("read of #{size} bytes from '#{name}' at #{offset} failed", -ret) if ret < 0 data_p.get_bytes(0, ret) end |
#resize(size) ⇒ Object
42 43 44 45 46 |
# File 'lib/ceph-ruby/rados_object.rb', line 42 def resize(size) log("resize size #{size}") ret = Lib::Rados.rados_trunc(pool.handle, name, size) raise SystemCallError.new("resize of '#{name}' to #{size} failed", -ret) if ret < 0 end |
#size ⇒ Object
60 61 62 |
# File 'lib/ceph-ruby/rados_object.rb', line 60 def size stat[:size] end |
#stat ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ceph-ruby/rados_object.rb', line 48 def stat log("stat") size_p = FFI::MemoryPointer.new(:uint64) mtime_p = FFI::MemoryPointer.new(:uint64) ret = Lib::Rados.rados_stat(pool.handle, name, size_p, mtime_p) raise SystemCallError.new("stat of '#{name}' failed", -ret) if ret < 0 { :size => size_p.get_uint64(0), :mtime => Time.at(mtime_p.get_uint64(0)), } end |
#write(offset, data) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/ceph-ruby/rados_object.rb', line 21 def write(offset, data) size = data.bytesize log("write offset #{offset}, size #{size}") ret = Lib::Rados.rados_write(pool.handle, name, data, size, offset) raise SystemCallError.new("write of #{size} bytes to '#{name}' at #{offset} failed", -ret) if ret < 0 end |