Class: Yast::NfsOptionsClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/NfsOptions.rb

Overview

Handle NFS mount options

Constant Summary

NEGATABLE_OPTIONS =

these can be negated by “no”

[
  "ac",
  "acl",
  "atime",
  "auto",
  "bg",
  "cto",
  "dev",
  "diratime",
  "exec",
  "fg",
  "fsc",
  "group",
  "hard",
  "intr",
  "iversion",
  "lock",
  "mand",
  "owner",
  "posix",
  "rdirplus",
  "relatime",
  "soft",
  "strictatime",
  "suid",
  "tcp",
  "udp",
  "user",
  "users"
]
NEGATED_OPTIONS =
NEGATABLE_OPTIONS.map { |o| "no#{o}" }
SIMPLE_OPTIONS =

these cannot be negated they are not nfs specific BTW

[
  "_netdev",
  "async",
  "bind",
  "defaults",
  "dirsync",
  "loud",
  "nofail",
  "owner",
  "rbind",
  "remount",
  "ro",
  "rw",
  "silent",
  "sync"
]
OPTIONS_WITH_VALUE =
[
  "acdirmax",
  "acdirmin",
  "acdirmin",
  "acregmax",
  "acregmin",
  "actimeo",
  "bsize",
  "clientaddr",
  "context",
  "defcontext",
  "fscontext",
  "minorversion",
  "mounthost",
  "mountport",
  "mountprog",
  "mountvers",
  "namlen",
  "nfsprog",
  "nfsvers",
  "port",
  "proto",
  "retrans",
  "retry",
  "rootcontext",
  "rsize",
  "sec",
  "timeo",
  "vers",
  "wsize"
]

Instance Method Summary (collapse)

Instance Method Details

- (Array<String>) from_string(options)

Parse to an internal representation: Simply split by commas, but “defaults” is represented by the empty list

Parameters:

  • options (String)

    a fstab option string

Returns:

  • (Array<String>)

    of individual options



115
116
117
118
119
# File '../../src/modules/NfsOptions.rb', line 115

def from_string(options)
  return [] if options == "defaults"

  options.split(",")
end

- (Boolean) get_nfs41(options)

FIXME: factor out get_nfs4(vfstype, options) (depending on n::o)!

Parameters:

  • options (String)

    fstab option string

Returns:

  • (Boolean)

    is version >= 4.1 enabled



175
176
177
178
179
180
# File '../../src/modules/NfsOptions.rb', line 175

def get_nfs41(options)
  option_list = from_string(options)

  enabled = "minorversion=1"
  Builtins.contains(option_list, enabled)
end

- (Object) main



107
108
109
# File '../../src/modules/NfsOptions.rb', line 107

def main
  textdomain "nfs"
end

- (Boolean) non_value_option?(option)

Returns:

  • (Boolean)


130
131
132
# File '../../src/modules/NfsOptions.rb', line 130

def non_value_option?(option)
  NEGATABLE_OPTIONS.include?(option) || NEGATED_OPTIONS.include?(option) || SIMPLE_OPTIONS.include?(option)
end

- (String) set_nfs41(options, nfs41)

Add or remove minorversion=1 according to nfs41. FIXME: vfstype=nfs4 is deprecated in favor of nfsvers=4 (aka vers=4)

Parameters:

  • options (String)

    fstab option string

  • nfs41 (Boolean)

    is version >= 4.1 enabled

Returns:

  • (String)

    new fstab option string



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File '../../src/modules/NfsOptions.rb', line 187

def set_nfs41(options, nfs41)
  # don't mutate the string unnecessarily
  return options if get_nfs41(options) == nfs41

  enabled  = "minorversion=1"
  disabled = "minorversion=0"

  option_list = from_string(options)
  option_list = Builtins.filter(option_list) { |opt| opt != enabled }
  option_list = Builtins.filter(option_list) { |opt| opt != disabled }

  option_list = Builtins.add(option_list, enabled) if nfs41

  to_string(option_list)
end

- (String) to_string(option_list)

Convert list of individual options to a fstab option string

Parameters:

  • option_list (Array<String>)

    list of individual options

Returns:

  • (String)

    a fstab option string



124
125
126
127
128
# File '../../src/modules/NfsOptions.rb', line 124

def to_string(option_list)
  return "defaults" if option_list.empty?

  option_list.join(",")
end

- (String) validate(options)

Checks the nfs options for /etc/fstab: nonempty, comma separated list of foo,nofoo,bar=baz (see nfs(5))

Parameters:

  • options (String)

    options

Returns:

  • (String)

    a translated string with an error message, emtpy if OK



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File '../../src/modules/NfsOptions.rb', line 138

def validate(options)
  # To translators: error popup
  return _("Empty option strings are not allowed.") if options.empty?

  error_message = ""

  from_string(options).each do |opt|
    key, value, *rest = opt.split("=")

    # Known options without any expected value
    if non_value_option?(key)
      next if value.nil?
      # To translators: error popup
      error_message = _("Unexpected value '%{value}' for option '%{key}'") % { :value => value, :key => key }
    # All unknown options
    elsif !OPTIONS_WITH_VALUE.include?(key)
      # To translators: error popup
      error_message = _("Unknown option: '%{key}'") % { :key => key }
    # All known ones with badly specified values
    elsif !rest.empty?
      # To translators: error popup
      error_message = _("Invalid option: '%{opt}'") % { :opt => opt }
    # All options missing a value
    elsif value.nil?
      # To translators: error popup
      error_message = _("Empty value for option: '%{key}'") % { :key => key }
    end

    break unless error_message.empty?
  end

  error_message
end