Sha256: 318fd41e29ee8c9a7d4f338189a126ce22a12304a69d32efe04d31bf20060062

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

require 'ffi'

# see https://github.com/ceph/ceph/blob/v0.48.2argonaut/src/pybind/rbd.py

module CephRuby
  module Lib
    # Ruby librbd bindings
    module Rbd
      extend FFI::Library

      ffi_lib ['rbd', 'librbd.so.1']

      attach_function 'rbd_version', [:pointer, :pointer, :pointer], :void

      attach_function 'rbd_create2', [:pointer, :string, :size_t, :uint64,
                                      :pointer], :int

      attach_function 'rbd_remove', [:pointer, :string], :int

      attach_function 'rbd_open', [:pointer, :string, :pointer, :string], :int

      attach_function 'rbd_close', [:pointer], :void

      attach_function 'rbd_write', [:pointer, :off_t, :size_t, :buffer_in], :int

      attach_function 'rbd_read', [:pointer, :off_t, :size_t, :buffer_out], :int

      attach_function 'rbd_stat', [:pointer, :pointer, :size_t], :int

      attach_function 'rbd_resize', [:pointer, :size_t], :int

      attach_function 'rbd_copy', [:pointer, :pointer, :string], :int

      attach_function 'rbd_copy_with_progress', [:pointer, :pointer, :string,
                                                 :pointer, :pointer], :int

      # Datatype to store rbd status information
      class StatStruct < FFI::Struct #:nodoc:
        layout :size, :uint64,
               :obj_size, :uint64,
               :num_objs, :uint64,
               :order, :int,
               :block_name_prefix, [:char, 24],
               :parent_pool, :int, # deprecated
               :parent_name, [:char, 96] # deprecated
      end

      def self.version
        major = FFI::MemoryPointer.new(:int)
        minor = FFI::MemoryPointer.new(:int)
        extra = FFI::MemoryPointer.new(:int)
        rbd_version(major, minor, extra)
        {
          major: major.get_int(0),
          minor: minor.get_int(0),
          extra: extra.get_int(0)
        }
      end

      def self.version_string
        "#{version[:major]}.#{version[:minor]}.#{version[:extra]}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ceph-ruby-livelink-1.5.1 lib/ceph-ruby/lib/rbd.rb