Coverage for drivers/nfs : 60%

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. """ except util.CommandException, inst: 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 """
"""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)
# Wait for NFS service to be available raise util.CommandException(code=errno.EOPNOTSUPP, reason="No NFS service on host") except util.CommandException, inst: raise NfsException("Failed to detect NFS service on server %s" % remoteserver)
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) except util.CommandException, inst: 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.""" continue
# Access is not always provided by showmount return # If none is provided we need to assume "*"
"""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')) 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.""" if ns[i].find("nfs") > 0: cvi = ns[i].split()[1] cv.add(cvi) except: util.SMlog("Unable to obtain list of valid nfs versions") raise NfsException('Failed to read supported NFS version from server' % (server))
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
|