From: Petr Tesarik <ptesarik@suse.cz>
Subject: do not call showmount prior to mounting an NFS share
References: bnc#572002

The description given by Bernhard seems to be incorrect, or the mount
command has been fixed meanwhile. If you try to mount a non-existent
directory, mount complains like this:

mount.nfs: mounting slave:/space/dumps/nonexistent failed, reason given by server:
  No such file or directory

So, calling showmount is no longer necessary, and it only makes the
initrd bigger, and progress slower.

Remove it.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>

---
 init/boot-kdump.sh    |    2 +-
 kdumptool/fileutil.cc |   43 ++-----------------------------------------
 kdumptool/fileutil.h  |   13 ++-----------
 kdumptool/transfer.cc |    6 +++---
 4 files changed, 8 insertions(+), 56 deletions(-)

--- a/kdumptool/fileutil.cc
+++ b/kdumptool/fileutil.cc
@@ -233,53 +233,14 @@ string FileUtil::pathconcat(const string
 void FileUtil::nfsmount(const string &host,
                         const string &dir,
                         const string &mountpoint,
-                        const StringVector &options,
-                        string &mountdir)
+                        const StringVector &options)
     throw (KError)
 {
     Debug::debug()->trace("FileUtil::nfsmount(%s, %s, %s, %s)",
         host.c_str(), dir.c_str(), mountpoint.c_str(),
         Stringutil::vector2string(options).c_str());
 
-    // get the exported file systems
-    Process p;
-    StringVector args;
-    args.push_back("-e");
-    args.push_back("--no-headers");
-    args.push_back(host);
-    ByteVector stdoutBytes, stderrBytes;
-    p.setStdoutBuffer(&stdoutBytes);
-    p.setStderrBuffer(&stderrBytes);
-    int ret = p.execute("showmount", args);
-    if (ret != 0)
-        throw KError("Cannot execute showmount -e --no-headers " + host + ":" +
-            Stringutil::trim(Stringutil::bytes2str(stderrBytes)));
-
-    StringVector dirs = Stringutil::splitlines(
-        Stringutil::bytes2str(stdoutBytes));
-
-    mountdir = "";
-    for (StringVector::const_iterator it = dirs.begin();
-            it != dirs.end(); ++it) {
-
-        // XXX: export cannot contain white spaces
-        StringVector vec = Stringutil::split(*it, ' ');
-        if (vec.size() < 1)
-            throw KError("Invalid line in showmount output: " + *it);
-
-        string exportdir = vec[0];
-
-        Debug::debug()->trace("Checking %s", exportdir.c_str());
-        if (Stringutil::startsWith(dir, exportdir)) {
-            mountdir = exportdir;
-            break;
-        }
-    }
-
-    if (mountdir.size() == 0)
-        throw KError(host + " does not export " + dir + ".");
-
-    mount(host + ":" + mountdir, mountpoint, "nfs", options);
+    mount(host + ":" + dir, mountpoint, "nfs", options);
 
 }
 
--- a/kdumptool/fileutil.h
+++ b/kdumptool/fileutil.h
@@ -191,15 +191,7 @@ class FileUtil {
          throw (KError);
 
          /**
-          * Mounts a NFS directory. That function checks with "showmount"
-          * before which directories are actually exported and mounts the
-          * correct directory.
-          *
-          * That function was implemented because mount does not terminate
-          * if you mount a directory that does not exist. So for example,
-          * if /a/b/c is exported and you mount /a/b/c/d, then the mount
-          * succeeds if /a/b/c/d exists, but it does not even terminate if
-          * /a/b/c/d does not exist.
+          * Mounts a NFS directory.
           *
           * @param[in] host remote host
           * @param[in] dir directory to mount
@@ -214,8 +206,7 @@ class FileUtil {
          static void nfsmount(const std::string &host,
                                const std::string &dir,
                                const std::string &mountpoint,
-                               const StringVector &options,
-                               std::string &mountdir)
+                               const StringVector &options)
          throw (KError);
 
          /**
--- a/kdumptool/transfer.cc
+++ b/kdumptool/transfer.cc
@@ -675,9 +675,9 @@ NFSTransfer::NFSTransfer(const char *tar
 
     URLParser &parser = getURLParser();
 
-    string mountedDir;
-    FileUtil::nfsmount(parser.getHostname(), parser.getPath(),
-        DEFAULT_MOUNTPOINT, options, mountedDir);
+    string mountedDir = FileUtil::dirname(parser.getPath());
+    FileUtil::nfsmount(parser.getHostname(), mountedDir,
+        DEFAULT_MOUNTPOINT, options);
 
 
     m_mountpoint = DEFAULT_MOUNTPOINT;
--- a/init/boot-kdump.sh
+++ b/init/boot-kdump.sh
@@ -17,7 +17,7 @@
 #
 #%stage: setup
 #%depends: mount network
-#%programs: /bin/makedumpfile /bin/awk /bin/gawk /bin/grep /sbin/kdumptool /sbin/showmount /sbin/mount.cifs mount.nfs
+#%programs: /bin/makedumpfile /bin/awk /bin/gawk /bin/grep /sbin/kdumptool /sbin/mount.cifs mount.nfs
 #%if: "$use_kdump"
 #%udevmodules: cifs nls_utf8 reiserfs xfs ext2 ext3
 
