Class: UBLK::Params
- Inherits:
-
Data
- Object
- Data
- UBLK::Params
- Defined in:
- lib/ublk/params.rb,
sig/ublk.rbs
Instance Attribute Summary collapse
-
#discard ⇒ Object
readonly
Returns the value of attribute discard.
-
#logical_block_size ⇒ Object
readonly
Returns the value of attribute logical_block_size.
-
#max_io_bytes ⇒ Object
readonly
Returns the value of attribute max_io_bytes.
-
#physical_block_size ⇒ Object
readonly
Returns the value of attribute physical_block_size.
-
#read_only ⇒ Object
readonly
Returns the value of attribute read_only.
-
#rotational ⇒ Object
readonly
Returns the value of attribute rotational.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(size:, logical_block_size: 512, physical_block_size: 4096, max_io_bytes: 512 * 1024, read_only: false, rotational: false, discard: true) ⇒ Params
constructor
A new instance of Params.
Constructor Details
#initialize(size:, logical_block_size: 512, physical_block_size: 4096, max_io_bytes: 512 * 1024, read_only: false, rotational: false, discard: true) ⇒ Params
Returns a new instance of Params.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ublk/params.rb', line 8 def initialize(size:, logical_block_size: 512, physical_block_size: 4096, max_io_bytes: 512 * 1024, read_only: false, rotational: false, discard: true) [logical_block_size, physical_block_size].each do |block_size| valid = block_size.is_a?(Integer) && block_size.between?(512, 4096) && (block_size & (block_size - 1)).zero? raise ArgumentError, "block sizes must be powers of two between 512 and 4096" unless valid end raise ArgumentError, "physical block size must not be smaller than logical block size" if physical_block_size < logical_block_size raise ArgumentError, "size must be aligned to the logical block size" unless (size % logical_block_size).zero? raise ArgumentError, "max_io_bytes must be a positive multiple of 512" unless max_io_bytes.is_a?(Integer) && max_io_bytes.positive? && (max_io_bytes % 512).zero? raise ArgumentError, "max_io_bytes must not exceed 32 MiB" if max_io_bytes > 32 * 1024 * 1024 super end |
Instance Attribute Details
#discard ⇒ Object (readonly)
Returns the value of attribute discard
4 5 6 |
# File 'lib/ublk/params.rb', line 4 def discard @discard end |
#logical_block_size ⇒ Object (readonly)
Returns the value of attribute logical_block_size
4 5 6 |
# File 'lib/ublk/params.rb', line 4 def logical_block_size @logical_block_size end |
#max_io_bytes ⇒ Object (readonly)
Returns the value of attribute max_io_bytes
4 5 6 |
# File 'lib/ublk/params.rb', line 4 def max_io_bytes @max_io_bytes end |
#physical_block_size ⇒ Object (readonly)
Returns the value of attribute physical_block_size
4 5 6 |
# File 'lib/ublk/params.rb', line 4 def physical_block_size @physical_block_size end |
#read_only ⇒ Object (readonly)
Returns the value of attribute read_only
4 5 6 |
# File 'lib/ublk/params.rb', line 4 def read_only @read_only end |
#rotational ⇒ Object (readonly)
Returns the value of attribute rotational
4 5 6 |
# File 'lib/ublk/params.rb', line 4 def rotational @rotational end |
#size ⇒ Object (readonly)
Returns the value of attribute size
4 5 6 |
# File 'lib/ublk/params.rb', line 4 def size @size end |
Class Method Details
.from_target(target, max_io_bytes: 512 * 1024) ⇒ Params
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ublk/params.rb', line 23 def self.from_target(target, max_io_bytes: 512 * 1024) new( size: target.size, logical_block_size: target.logical_block_size, physical_block_size: target.physical_block_size, max_io_bytes:, read_only: target.read_only?, rotational: target.rotational?, discard: target.method(:discard).owner != Target || target.method(:write_zeroes).owner != Target ) end |