Skip to content

Commit

Permalink
Stop using vfstype and minorversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Apr 5, 2018
1 parent 4218edc commit fd67817
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 67 deletions.
1 change: 1 addition & 0 deletions package/yast2-nfs-client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ file system access. It allows access to files on remote machines.
%{yast_moduledir}/Nfs.rb
%{yast_moduledir}/NfsOptions.rb
%{yast_dir}/lib/fstab
%{yast_dir}/lib/y2nfs_client
%dir %{yast_desktopdir}
%{yast_desktopdir}/nfs.desktop
%doc %{yast_docdir}
Expand Down
7 changes: 6 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ ylibdir = @ylibdir@/fstab
ylib_DATA = \
lib/fstab/tsort.rb

EXTRA_DIST = $(module_DATA) $(client_DATA) $(ynclude_DATA) $(schemafiles_DATA) $(desktop_DATA) $(ylib_DATA)
y2nfslibdir = @ylibdir@/y2nfs_client
y2nfslib_DATA = \
lib/y2nfs_client/nfs_version.rb

EXTRA_DIST = \
$(module_DATA) $(client_DATA) $(ynclude_DATA) $(schemafiles_DATA) $(desktop_DATA) $(ylib_DATA) $(y2nfslib_DATA)

include $(top_srcdir)/Makefile.am.common
9 changes: 7 additions & 2 deletions src/include/nfs/routines.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# encoding: utf-8

require "y2nfs_client/nfs_version"

# YaST namespace
module Yast
# Miscellaneous
Expand All @@ -12,6 +14,7 @@ def initialize_nfs_routines(_include_target)
Yast.import "IP"
Yast.import "Hostname"
Yast.import "String"
Yast.import "NfsOptions"
end

# @param [String] spec "server:/path/specification"
Expand Down Expand Up @@ -49,13 +52,15 @@ def FstabTableItems(fstab)
count = 0
Builtins.maplist(fstab) do |entry|
sp = SpecToServPath(Ops.get_string(entry, "spec", ""))
mntops = entry.fetch("mntops", "")
version = NfsOptions.nfs_version(mntops)
it = Item(
Id(count),
Ops.add(Ops.get_string(sp, 0, ""), " "),
Ops.add(Ops.get_string(sp, 1, ""), " "),
Ops.add(Ops.get_string(entry, "file", ""), " "),
Ops.get_string(entry, "vfstype", " "),
Ops.add(Ops.get_string(entry, "mntops", ""), " ")
"#{version.label} ",
"#{mntops} "
)
count = Ops.add(count, 1)
deep_copy(it)
Expand Down
48 changes: 29 additions & 19 deletions src/include/nfs/ui.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# encoding: utf-8
require "y2firewall/firewalld"
require "yast2/feedback"
require "y2nfs_client/nfs_version"

# YaST namespace
module Yast
Expand Down Expand Up @@ -48,7 +49,7 @@ def initialize_nfs_ui(include_target)
_(
"<p>Each NFS share is identified by remote NFS server address and\n" \
"exported directory, local directory where the remote directory is mounted, \n" \
"NFS type (either plain nfs or nfsv4) and mount options. For further information \n" \
"version of the NFS protocol and mount options. For further information \n" \
"about mounting NFS and mount options, refer to <tt>man nfs.</tt></p>"
) +
# Help, part 3 of 3
Expand All @@ -61,8 +62,8 @@ def initialize_nfs_ui(include_target)
@help_text2 = Ops.add(
_(
"<p>If you need to access NFSv4 shares (NFSv4 is a newer version of the NFS\n" \
"protocol), check the <b>Enable NFSv4</b> option. In that case, you might need\n" \
"to supply specific a <b>NFSv4 Domain Name</b> required for the correct setting\n" \
"protocol), check the <b>NFS version</b> option. In that case, you might need\n" \
"to supply an specific <b>NFSv4 Domain Name</b> required for the correct setting\n" \
"of file/directory access rights.</p>\n"
),
Ops.get_string(@fw_cwm_widget, "help", "")
Expand Down Expand Up @@ -202,8 +203,6 @@ def GetFstabEntry(fstab_ent, existing)
server = ""
pth = ""
mount = ""
nfs4 = false
nfs41 = false
options = "defaults"
servers = []
old = ""
Expand All @@ -214,15 +213,14 @@ def GetFstabEntry(fstab_ent, existing)
server = Ops.get_string(couple, 0, "")
pth = Ops.get_string(couple, 1, "")
mount = Ops.get_string(fstab_ent, "file", "")
nfs4 = Ops.get_string(fstab_ent, "vfstype", "") == "nfs4"
options = Ops.get_string(fstab_ent, "mntops", "")
nfs41 = nfs4 && NfsOptions.get_nfs41(options)
servers = [server]
old = Ops.get_string(fstab_ent, "spec", "")
else
proposed_server = ProposeHostname()
servers = [proposed_server] if HostnameExists(proposed_server)
end
version = NfsOptions.nfs_version(options)

# append already defined servers - bug #547983
Builtins.foreach(@nfs_entries) do |nfs_entry|
Expand Down Expand Up @@ -273,12 +271,7 @@ def GetFstabEntry(fstab_ent, existing)
)
),
Left(
HBox(
CheckBox(Id(:nfs4), _("NFS&v4 Share"), nfs4),
HSpacing(2),
# parallel NFS, protocol version 4.1
CheckBox(Id(:nfs41), _("pNFS (v4.1)"), nfs41)
)
version_widget(version)
),
Left(
TextAndButton(
Expand Down Expand Up @@ -350,7 +343,7 @@ def GetFstabEntry(fstab_ent, existing)
next
end

v4 = UI.QueryWidget(Id(:nfs4), :Value)
v4 = version_from_widget.browse_with_v4?
scan_exports(server2, v4)
elsif ret == :browse
dir = Convert.to_string(UI.QueryWidget(Id(:mountent), :Value))
Expand All @@ -372,13 +365,11 @@ def GetFstabEntry(fstab_ent, existing)
mount = StripExtraSlash(
Convert.to_string(UI.QueryWidget(Id(:mountent), :Value))
)
nfs4 = Convert.to_boolean(UI.QueryWidget(Id(:nfs4), :Value))
nfs41 = Convert.to_boolean(UI.QueryWidget(Id(:nfs41), :Value))
options = Builtins.deletechars(
Convert.to_string(UI.QueryWidget(Id(:optionsent), :Value)),
" "
)
options = NfsOptions.set_nfs41(options, nfs41)
options = NfsOptions.set_nfs_version(options, version_from_widget)

ret = nil
options_error = NfsOptions.validate(options)
Expand All @@ -395,7 +386,7 @@ def GetFstabEntry(fstab_ent, existing)
fstab_ent = {
"spec" => Ops.add(Ops.add(server, ":"), pth),
"file" => mount,
"vfstype" => nfs4 ? "nfs4" : "nfs",
"vfstype" => "nfs",
"mntops" => options
}
if old != Ops.add(Ops.add(server, ":"), pth)
Expand Down Expand Up @@ -472,7 +463,7 @@ def FstabTab
# table header
_("Mount Point") + " ",
# table header
_("NFS Type"),
_("NFS Version"),
# table header
_("Options") + " "
),
Expand Down Expand Up @@ -723,5 +714,24 @@ def scan_exports(server, v4)
Report.Error(_("The NFS scan failed."))
end
end

private

# Widget to select the version of the NFS protocol to use in a mount that is
# being created or edited.
def version_widget(current_version)
items = Y2NfsClient::NfsVersion.all.map do |vers|
Item(Id(vers.widget_id), vers.widget_text, current_version == vers)
end
ComboBox(Id(:nfs_version), _("NFS &Version"), items)
end

# Version of the NFS protocol selected in the corresponding widget.
#
# @return [Y2NfsClient::NfsVersion]
def version_from_widget
id = UI.QueryWidget(Id(:nfs_version), :Value).to_sym
Y2NfsClient::NfsVersion.all.find { |v| v.widget_id == id }
end
end
end
121 changes: 121 additions & 0 deletions src/lib/y2nfs_client/nfs_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# encoding: utf-8
#
# Copyright (c) [2018] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"

module Y2NfsClient
# Version of the NFS protocol configured for an NFS mount
#
# The main goal of the class if to map how the version is configured in the
# /etc/fstab entry with how that is presented to the user.
#
# Each instance can represent the configuration to enforce a concrete version
# or a more generic configuration (i.e. "use any available version").
class NfsVersion
include Yast::I18n
extend Yast::I18n
textdomain "nfs"

ALL_ATTRIBUTES = [
[nil, N_("Any"), :vers_any, N_("Any (Highest Available)")],
["3", N_("NFSv3"), :vers_3, N_("Force NFSv3")],
["4", N_("NFSv4"), :vers_4, N_("Force NFSv4")],
["4.1", N_("NFSv4.1"), :vers_4_1, N_("Force pNFS (v4.1)")]
].freeze
private_constant :ALL_ATTRIBUTES

# Constructor
def initialize(mntops_value, label, widget_id, widget_text)
textdomain "nfs"

@mntops_value = mntops_value
@label = label
@widget_id = widget_id
@widget_text = widget_text
end

# Sorted list of all possible settings
def self.all
ALL_ATTRIBUTES.map { |attrs| new(*attrs) }
end

# An instance corresponding to a given value in the mount options
#
# @see #mntops_value
#
# @param value [String]
# @return [NfsVersion]
def self.for_mntops_value(value)
all.find { |version| version.mntops_value == value }
end

# Value used in the corresponding mount option (nfsvers or vers)
#
# @return [String]
attr_reader :mntops_value

# Id for a widget representing the instance
#
# @return [Symbol]
attr_reader :widget_id

# Short localized label to represent the instance in listings
#
# @return [String]
def label
_(@label)
end

# Localized text to use in a widget representing the instance
#
# @return [String]
def widget_text
_(@widget_text)
end

def ==(other)
other.class == self.class && other.mntops_value == mntops_value
end

alias_method :eql?, :==

# Whether the system infrastructure associated to NFSv4 (e.g. enabled
# NFS4_SUPPORT in sysconfig/nfs) is needed in order to use this version of
# the protocol.
#
# @return [Boolean]
def requires_v4?
return false if mntops_value.nil?
mntops_value.start_with?("4")
end

# Whether is necessary to use the browsing mechanisms associated to NFSv4 in
# order to find shares of this type in the network or in a given server.
#
# Scanning a network or server to find NFS shares is completely different
# depending on the version of the protocol (version 3 vs version 4+).
#
# @return [Boolean]
def browse_with_v4?
requires_v4?
end
end
end
3 changes: 2 additions & 1 deletion src/modules/Nfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def ImportAny(settings)

# vfstype can override a missing enable_nfs4
@nfs4_enabled = true if Builtins.find(entries) do |entry|
Ops.get_string(entry, "vfstype", "") == "nfs4"
version = NfsOptions.nfs_version(entry["nfs_options"] || "")
version && version.requires_v4?
end

@nfs_entries = Builtins.maplist(entries) do |entry|
Expand Down

0 comments on commit fd67817

Please sign in to comment.