From 1d25f99f401c65ce63e68d03815fb69b3a852de6 Mon Sep 17 00:00:00 2001 From: Rafi Khardalian Date: Sat, 2 Feb 2013 23:01:54 +0000 Subject: [PATCH] Allow for specifying nfs mount options Fixes bug 1113042 Adds a new config option: nfs_mount_options=None (Default) When not None, anything set here will be passed as -o to the mount command. The default behavior is to do exactly as we are doing today and relying on the OS/kernel defaults. Change-Id: I6bd27f9d0e8848a9ba98318ba7288e43ee6b4cb9 Flags: DocImpact --- cinder/volume/drivers/nfs.py | 16 +++++++++++++--- etc/cinder/cinder.conf.sample | 5 +++++ 2 files changed, 18 insertions(+), 3 deletions(-) mode change 100644 => 100755 cinder/volume/drivers/nfs.py diff --git a/cinder/volume/drivers/nfs.py b/cinder/volume/drivers/nfs.py old mode 100644 new mode 100755 index 4ebf377e7..ebf157582 --- a/cinder/volume/drivers/nfs.py +++ b/cinder/volume/drivers/nfs.py @@ -41,7 +41,12 @@ volume_opts = [ default=True, help=('Create volumes as sparsed files which take no space.' 'If set to False volume is created as regular file.' - 'In such case volume creation takes a lot of time.'))] + 'In such case volume creation takes a lot of time.')), + cfg.StrOpt('nfs_mount_options', + default=None, + help='Mount options passed to the nfs client. See section ' + 'of the nfs man page for details'), +] FLAGS = flags.FLAGS FLAGS.register_opts(volume_opts) @@ -270,9 +275,14 @@ class NfsDriver(driver.VolumeDriver): if not self._path_exists(mount_path): self._execute('mkdir', '-p', mount_path) + # Construct the NFS mount command. + nfs_cmd = ['mount', '-t', 'nfs'] + if FLAGS.nfs_mount_options is not None: + nfs_cmd.extend(['-o', FLAGS.nfs_mount_options]) + nfs_cmd.extend([nfs_share, mount_path]) + try: - self._execute('mount', '-t', 'nfs', nfs_share, mount_path, - run_as_root=True) + self._execute(*nfs_cmd, run_as_root=True) except exception.ProcessExecutionError as exc: if ensure and 'already mounted' in exc.stderr: LOG.warn(_("%s is already mounted"), nfs_share) diff --git a/etc/cinder/cinder.conf.sample b/etc/cinder/cinder.conf.sample index 5553f0a96..e7b2c9463 100644 --- a/etc/cinder/cinder.conf.sample +++ b/etc/cinder/cinder.conf.sample @@ -882,6 +882,11 @@ # volume creation takes a lot of time. (boolean value) #nfs_sparsed_volumes=true +# Mount options passed to the nfs client (string value) +# The value set here is passed directly to the -o flag +# of the mount command. See the nfs man page for details. +#nfs_mount_options=None + # # Options defined in cinder.volume.drivers.rbd -- 2.45.2