Class: FuseFS::StatsHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fuse/fusedir.rb

Overview

Helper for filesystem accounting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_space = nil, max_nodes = nil, strict = false) ⇒ StatsHelper

Returns a new instance of StatsHelper.

Parameters:

  • max_space (Integer) (defaults to: nil)
  • max_nodes (Integer) (defaults to: nil)
  • strict (Booleanr) (defaults to: false)


26
27
28
29
30
31
32
# File 'lib/fuse/fusedir.rb', line 26

def initialize(max_space=nil,max_nodes=nil,strict=false)
    @nodes = 0
    @space = 0
    @max_space = max_space
    @max_nodes = max_nodes
    @strict = strict
end

Instance Attribute Details

#max_nodesInteger

Returns maximum number of (virtual) inodes.

Returns:

  • (Integer)

    maximum number of (virtual) inodes



9
10
11
# File 'lib/fuse/fusedir.rb', line 9

def max_nodes
  @max_nodes
end

#max_spaceInteger

Returns size of filesystem in bytes.

Returns:

  • (Integer)

    size of filesystem in bytes



7
8
9
# File 'lib/fuse/fusedir.rb', line 7

def max_space
  @max_space
end

#nodesInteger (readonly)

Returns used inodes (typically count of files and directories).

Returns:

  • (Integer)

    used inodes (typically count of files and directories)



20
21
22
# File 'lib/fuse/fusedir.rb', line 20

def nodes
  @nodes
end

#spaceInteger (readonly)

Returns used space in bytes.

Returns:

  • (Integer)

    used space in bytes



17
18
19
# File 'lib/fuse/fusedir.rb', line 17

def space
  @space
end

#strictBoolean

If set true, adjustments that cause space/nodes to exceed the maximums will raise ENOSPC (no space left on device)

Returns:

  • (Boolean)


14
15
16
# File 'lib/fuse/fusedir.rb', line 14

def strict
  @strict
end

Instance Method Details

#adjust(delta_space, delta_nodes = 0) ⇒ void

This method returns an undefined value.

Adjust accumlated statistics

Parameters:

  • delta_space (Integer)

    change in #space usage

  • delta_nodes (Integer) (defaults to: 0)

    change in #nodes usage

Raises:



40
41
42
43
44
# File 'lib/fuse/fusedir.rb', line 40

def adjust(delta_space,delta_nodes=0)
    @nodes += delta_nodes
    @space += delta_space
    raise Errno::ENOSPC if @strict && ( @nodes >  @max_nodes ||  @space > @max_space )
end

#to_statisticsArray<Integer> #to_statistics(free_space, free_nodes) ⇒ Array<Integer>

Overloads:

  • #to_statisticsArray<Integer>

    Returns in format expected by FuseDir#statistics.

    Returns:

  • #to_statistics(free_space, free_nodes) ⇒ Array<Integer>

    Calculate total space so that free space remains fixed

    Parameters:

    • free_space (Integer)

      available space in bytes

    • free_nodes (Integer)

      available (virtual) inodes

    Returns:



53
54
55
56
57
# File 'lib/fuse/fusedir.rb', line 53

def to_statistics(free_space=nil,free_nodes=nil)
    total_space = free_space ? space + free_space : max_space
    total_nodes = free_nodes ? nodes + free_nodes : max_nodes
    [ @space, @nodes, total_space, total_nodes ]
end