Coverage for drivers/nfs : 62%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/python # # Copyright (C) Citrix Systems Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation; version 2.1 only. # # 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 Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # nfs.py: NFS related utility functions
# The algorithm for tcp and udp (at least in the linux kernel) for # NFS timeout on softmounts is as follows: # # UDP: # As long as the request wasn't started more than timeo * (2 ^ retrans) # in the past, keep doubling the timeout. # # TCP: # As long as the request wasn't started more than timeo * (1 + retrans) # in the past, keep increaing the timeout by timeo. # # The time when the retrans may retry has been made will be: # For udp: timeo * (2 ^ retrans * 2 - 1) # For tcp: timeo * n! where n is the smallest n for which n! > 1 + retrans # # thus for retrans=1, timeo can be the same for both tcp and udp, # because the first doubling (timeo*2) is the same as the first increment # (timeo+timeo).
'nfsversion', 'for type=nfs, NFS protocol version - 3, 4, 4.1']
"""Make sure that NFS over TCP/IP V3 is supported on the server.
Returns True if everything is OK False otherwise. """ raise NfsException("rpcinfo failed or timed out: return code %d" % inst.code)
"""Ensure NFS service is up and available on the remote server.
Returns False if fails to detect service after NFS_SERVICE_RETRY * NFS_SERVICE_WAIT """
# Services are not present in NFS4 only, this doesn't mean there's no NFS return True # Server failed to give us supported versions
"""Check the validity of 'nfsversion'.
Raise an exception for any invalid version. """ else:
timeout=None, nfsversion=DEFAULT_NFSVERSION, retrans=None): """Mount the remote NFS export at 'mountpoint'.
The 'timeout' param here is in deciseconds (tenths of a second). See nfs(5) for details. """ except util.CommandException, inst: raise NfsException("Failed to make directory: code is %d" % inst.code)
mountcommand = 'mount.nfs4'
transport, nfsversion)
options += ",timeo=%s" % timeout options += ",retrans=%s" % retrans options += ",%s" % useroptions
util.pread([mountcommand, "%s:%s" % (remoteserver, remotepath), mountpoint, "-o", options]), errlist=[errno.EPIPE, errno.EIO], maxretry=2, nofail=True) raise NfsException("mount failed with return code %d" % inst.code)
"""Unmount the mounted mountpoint""" try: util.pread(["umount", mountpoint]) except util.CommandException, inst: raise NfsException("umount failed with return code %d" % inst.code)
if rmmountpoint: try: os.rmdir(mountpoint) except OSError, inst: raise NfsException("rmdir failed with error '%s'" % inst.strerror)
""" Scan target and return an XML DOM with target, path and accesslist. Using NFS3 services. """ continue
# Access is not always provided by showmount return # If none is provided we need to assume "*"
""" Scan target and return an XML DOM with target, path and accesslist. Using NFS4 only pseudo FS. """
mountpoint = "%s/%s" % (NFS4_TMP_MOUNTPOINT, target) soft_mount(mountpoint, target, NFS4_PSEUDOFS, transport, nfsversion="4") paths = os.listdir(mountpoint) unmount(mountpoint, NFS4_PSEUDOFS) for path in paths: entry = dom.createElement("Export") element.appendChild(entry)
subentry = dom.createElement("Target") entry.appendChild(subentry) textnode = dom.createTextNode(target) subentry.appendChild(textnode) subentry = dom.createElement("Path") entry.appendChild(subentry) textnode = dom.createTextNode(path) subentry.appendChild(textnode)
subentry = dom.createElement("Accesslist") entry.appendChild(subentry) # Assume everyone as we do not have any info about it textnode = dom.createTextNode("*") subentry.appendChild(textnode) return dom
"""Scan target and return an XML DOM with target, path and accesslist.""" except Exception: util.SMlog("Unable to scan exports with %s, trying NFSv4" % SHOWMOUNT_BIN)
# NFSv4 only try: return _scan_exports_nfs4_only(target, transport, dom, element) except Exception: util.SMlog("Unable to scan exports with NFSv4 pseudo FS mount")
raise NfsException("Failed to read NFS export paths from server %s" % (target))
"""Scan and report SR, UUID.""" dom = xml.dom.minidom.Document() element = dom.createElement("SRlist") dom.appendChild(element) for val in filter(util.match_uuid, util.ioretry( lambda: util.listdir(path))): fullpath = os.path.join(path, val) if not util.ioretry(lambda: util.isdir(fullpath)): continue
entry = dom.createElement('SR') element.appendChild(entry)
subentry = dom.createElement("UUID") entry.appendChild(subentry) textnode = dom.createTextNode(val) subentry.appendChild(textnode)
from NFSSR import PROBEVERSION if dconf.has_key(PROBEVERSION): util.SMlog("Add supported nfs versions to sr-probe") try: supported_versions = get_supported_nfs_versions(dconf.get('server'), transport) supp_ver = dom.createElement("SupportedVersions") element.appendChild(supp_ver)
for ver in supported_versions: version = dom.createElement('Version') supp_ver.appendChild(version) textnode = dom.createTextNode(ver) version.appendChild(textnode) except NfsException: # Server failed to give us supported versions pass
return dom.toprettyxml()
""" Return list of supported nfs versions. Using NFS3 services. *Might* return "4" in the list of supported NFS versions, but might not: There is no requirement for NFS4 to register with rpcbind, even though it can, so a server which supports NFS4 might still only return ["3"] from here. """
""" Return list of supported nfs versions. Using NFS4 pseudo FS. """
util.pread2([NFS_STAT, "-m"]) unmount(mountpoint, NFS4_PSEUDOFS) return True
""" Return list of supported nfs versions. First check list from rpcinfo and if that does not contain NFS4, probe for it and add it to the list if available. """
# Test for NFS4 if the rpcinfo query did not find it (NFS4 does not *have* to register with rpcbind)
else:
val = int(other_config['nfs-timeout']) if val < 1: util.SMlog("Invalid nfs-timeout value: %d" % val) else: nfs_timeout = val
val = int(other_config['nfs-retrans']) if val < 0: util.SMlog("Invalid nfs-retrans value: %d" % val) else: nfs_retrans = val
|