pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for mount_sshnfs/sshnfs update, 2024-01-29
Posted by Anonymous on Mon 29th Jan 2024 16:48
raw | new post

  1. From a1c69127e8a4279a6d98583031e9157ec74291e1 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Mon, 29 Jan 2024 15:18:29 +0100
  4. Subject: [PATCH] Update mount_sshnfs and sshnfs utilities
  5.  
  6. Sync mount_sshnfs and sshnfs utilities with upstream
  7. (http://svn.nrubsig.org/svn/people/gisburn/scripts/mount_sshnfs/ and
  8. http://svn.nrubsig.org/svn/people/gisburn/scripts/sshnfs/).
  9.  
  10. Changes include:
  11. - Fix relative vs absolute URLs, nfs:// and ssh+nfs:// should always
  12.   have absolute paths for now.
  13. - Only use NFSv4.2 for mounting if supported by (Linux) kernel
  14. - Add MIT license plate
  15.  
  16. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  17. ---
  18. cygwin/utils/mount_sshnfs/mount_sshnfs.ksh | 81 +++++++++++++++++++---
  19.  cygwin/utils/sshnfs/sshnfs.ksh             | 46 +++++++++---
  20.  2 files changed, 107 insertions(+), 20 deletions(-)
  21.  mode change 100755 => 100644 cygwin/utils/mount_sshnfs/mount_sshnfs.ksh
  22.  
  23. diff --git a/cygwin/utils/mount_sshnfs/mount_sshnfs.ksh b/cygwin/utils/mount_sshnfs/mount_sshnfs.ksh
  24. old mode 100755
  25. new mode 100644
  26. index 4193d56..52c3db0
  27. --- a/cygwin/utils/mount_sshnfs/mount_sshnfs.ksh
  28. +++ b/cygwin/utils/mount_sshnfs/mount_sshnfs.ksh
  29. @@ -1,5 +1,29 @@
  30.  #!/bin/ksh93
  31.  
  32. +#
  33. +# MIT License
  34. +#
  35. +# Copyright (c) 2023-2024 Roland Mainz <roland.mainz@nrubsig.org>
  36. +#
  37. +# Permission is hereby granted, free of charge, to any person obtaining a copy
  38. +# of this software and associated documentation files (the "Software"), to deal
  39. +# in the Software without restriction, including without limitation the rights
  40. +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  41. +# copies of the Software, and to permit persons to whom the Software is
  42. +# furnished to do so, subject to the following conditions:
  43. +#
  44. +# The above copyright notice and this permission notice shall be included in all
  45. +# copies or substantial portions of the Software.
  46. +#
  47. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  48. +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  49. +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  50. +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  51. +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  52. +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  53. +# SOFTWARE.
  54. +#
  55. +
  56.  #
  57.  # mount_sshnfs - mount NFSv4 filesystem through ssh tunnel
  58.  #
  59. @@ -9,13 +33,13 @@
  60.  #
  61.  # 1. UNIX/Linux: Mount&&unmount /export/home/rmainz on NFS server "/export/home/rmainz":
  62.  # $ mkdir -p /foobarmnt
  63. -# $ ksh mount_sshnfs.ksh mount ssh+nfs://rmainz@derfwpc5131/export/home/rmainz /foobarmnt
  64. +# $ ksh mount_sshnfs.ksh mount ssh+nfs://rmainz@derfwpc5131//export/home/rmainz /foobarmnt
  65.  # $ mount_sshnfs.ksh umount /foobarmnt
  66.  #
  67.  #
  68.  # 2. UNIX/Linux: Mount&&unmount /export/home/rmainz on NFS server "/export/home/rmainz" via SSH jumphost rmainz@10.49.20.131:
  69.  # $ mkdir -p /foobarmnt
  70. -# $ ksh mount_sshnfs.ksh mount -o ro,mount_sshnfs_jumphost=rmainz@10.49.20.131 ssh+nfs://rmainz@derfwpc5131/export/home/rmainz /foobarmnt
  71. +# $ ksh mount_sshnfs.ksh mount -o ro,mount_sshnfs_jumphost=rmainz@10.49.20.131 ssh+nfs://rmainz@derfwpc5131//export/home/rmainz /foobarmnt
  72.  # $ mount_sshnfs.ksh umount /foobarmnt
  73.  #
  74.  
  75. @@ -282,6 +306,8 @@ function parse_sshnfs_url
  76.                 { print -u2 -f $"%s: Not a nfs:// or ssh+nfs:// url\n" "$0" ; return 1 ; }
  77.         [[ "${data.host}" != '' ]] || { print -u2 -f $"%s: NFS hostname missing\n" "$0" ; return 1 ; }
  78.         [[ "${data.uripath}" != '' ]] || { print -u2 -f $"%s: NFS path missing\n" "$0" ; return 1 ; }
  79. +       [[ "${data.uripath}" == /* ]] || { print -u2 -f $"%s: NFS path (%q) must be absolute\n" "$0" "${data.uripath}" ; return 1 ; }
  80. +       [[ "${data.uripath}" != //* ]] || { print -u2 -f $"%s: NFS path (%q) should not start with '//' \n" "$0" "${data.uripath}" ; return 1 ; }
  81.  
  82.         return 0
  83.  }
  84. @@ -305,6 +331,31 @@ function mountpoint2configfilename
  85.  }
  86.  
  87.  
  88. +function kernel_supports_nfs42_client
  89. +{
  90. +       typeset s=''
  91. +
  92. +       if [[ "$(uname -s)" == 'Linux' ]] ; then
  93. +               if [[ -r '/proc/config.gz' ]] ; then
  94. +                       s="$(gunzip -c <'/proc/config.gz' | egrep -v '^[[:space:]]*#')"
  95. +               elif [[ -r "/boot/config-$(uname -r)" ]] ; then
  96. +                       s="$( egrep -v '^[[:space:]]*#' "/boot/config-$(uname -r)")"
  97. +               fi
  98. +
  99. +               if [[ "$s" == *CONFIG_NFS_V4_2=y* ]] ; then
  100. +                       return 0
  101. +               fi
  102. +
  103. +               return 1
  104. +       else
  105. +               # FIXME: Add more OS support
  106. +               true
  107. +       fi
  108. +
  109. +       return 2
  110. +}
  111. +
  112. +
  113.  function cmd_mount
  114.  {
  115.         set -o nounset
  116. @@ -312,7 +363,7 @@ function cmd_mount
  117.  
  118.         # fixme: Need better text layout for $ mount_sshnfs mount --man #
  119.         typeset -r mount_sshnfs_cmdmount_usage=$'+
  120. -       [-?\n@(#)\$Id: mount_sshnfs mount (Roland Mainz) 2023-12-08 \$\n]
  121. +       [-?\n@(#)\$Id: mount_sshnfs mount (Roland Mainz) 2024-01-29 \$\n]
  122.         [-author?Roland Mainz <roland.mainz@nrubsig.org>]
  123.         [+NAME?mount_sshnfs mount - mount NFSv4 filesystem through ssh
  124.                 tunnel]
  125. @@ -569,7 +620,7 @@ function cmd_mount
  126.                                 mount_args+=( '-o' 'sec=sys' )
  127.                                 # '*' == Let nfs_mount.exe should pick drive letter itself
  128.                                 mount_args+=( '*' )
  129. -                               mount_args+=( "localhost:/${c.nfs_server.uripath}" )
  130. +                               mount_args+=( "localhost:${c.nfs_server.uripath}" )
  131.  
  132.                                 #
  133.                                 # ... and do the mount
  134. @@ -604,9 +655,19 @@ function cmd_mount
  135.                                 for s in "${c.mount_nfs_options[@]}" ; do
  136.                                         mount_args+=( '-o' "$s" )
  137.                                 done
  138. -                               mount_args+=( '-o' 'vers=4.2' )
  139. +
  140. +                               if kernel_supports_nfs42_client ; then
  141. +                                       mount_args+=( '-o' 'vers=4.2' )
  142. +                               else
  143. +                                       #
  144. +                                       # some kernels (like WSL) have a
  145. +                                       # Linux 5.15.x kernel with NFSv4.2
  146. +                                       # client support turned off
  147. +                                       #
  148. +                                       mount_args+=( '-o' 'vers=4.1' )
  149. +                               fi
  150.                                 mount_args+=( '-o' "port=${c.local_forward_port}" )
  151. -                               mount_args+=( "localhost:/${c.nfs_server.uripath}" )
  152. +                               mount_args+=( "localhost:${c.nfs_server.uripath}" )
  153.                                 mount_args+=( "${c.mountpoint}" )
  154.  
  155.                                 #
  156. @@ -668,7 +729,7 @@ function cmd_umount
  157.         typeset mydebug=false # fixme: should be "bool" for ksh93v
  158.         # fixme: Need better text layout for $ mount_sshnfs mount --man #
  159.         typeset -r mount_sshnfs_cmdumount_usage=$'+
  160. -       [-?\n@(#)\$Id: mount_sshnfs umount (Roland Mainz) 2023-12-08 \$\n]
  161. +       [-?\n@(#)\$Id: mount_sshnfs umount (Roland Mainz) 2024-01-29 \$\n]
  162.         [-author?Roland Mainz <roland.mainz@nrubsig.org>]
  163.         [+NAME?mount_sshnfs umount - unmount NFSv4 filesystem mounted
  164.                 via mount_sshnfs mount]
  165. @@ -772,7 +833,7 @@ function main
  166.  
  167.         # fixme: Need better text layout for $ mount_sshnfs --man #
  168.         typeset -r mount_sshnfs_usage=$'+
  169. -       [-?\n@(#)\$Id: mount_sshnfs (Roland Mainz) 2023-12-08 \$\n]
  170. +       [-?\n@(#)\$Id: mount_sshnfs (Roland Mainz) 2024-01-29 \$\n]
  171.         [-author?Roland Mainz <roland.mainz@nrubsig.org>]
  172.         [+NAME?mount_sshnfs - mount/umount NFSv4 filesystem via ssh
  173.                 tunnel]
  174. @@ -788,13 +849,13 @@ function main
  175.         [+EXAMPLES]{
  176.                 [+?Example 1:][+?Mount&&unmount /export/home/rmainz on NFS server "/export/home/rmainz"]{
  177.  [+\n# mkdir -p /foobarmnt
  178. -# ksh mount_sshnfs.ksh mount ssh+nfs:://rmainz@derfwpc5131/export/home/rmainz /foobarmnt
  179. +# ksh mount_sshnfs.ksh mount ssh+nfs:://rmainz@derfwpc5131//export/home/rmainz /foobarmnt
  180.  # mount_sshnfs.ksh umount /foobarmnt
  181.  ]
  182.  }
  183.                 [+?Example 2:][+?Mount&&unmount /export/home/rmainz on NFS server "/export/home/rmainz" via SSH jumphost rmainz@10.49.20.131]{
  184.  [+\n# mkdir -p /foobarmnt
  185. -# ksh mount_sshnfs.ksh mount -o ro,mount_sshnfs_jumphost=rmainz@10.49.20.131 ssh+nfs:://rmainz@derfwpc5131/export/home/rmainz /foobarmnt
  186. +# ksh mount_sshnfs.ksh mount -o ro,mount_sshnfs_jumphost=rmainz@10.49.20.131 ssh+nfs:://rmainz@derfwpc5131//export/home/rmainz /foobarmnt
  187.  # mount_sshnfs.ksh umount /foobarmnt
  188.  ]
  189.                 }
  190. diff --git a/cygwin/utils/sshnfs/sshnfs.ksh b/cygwin/utils/sshnfs/sshnfs.ksh
  191. index 1e39241..2f2f64e 100644
  192. --- a/cygwin/utils/sshnfs/sshnfs.ksh
  193. +++ b/cygwin/utils/sshnfs/sshnfs.ksh
  194. @@ -1,19 +1,43 @@
  195.  #!/bin/ksh93
  196.  
  197. +#
  198. +# MIT License
  199. +#
  200. +# Copyright (c) 2023-2024 Roland Mainz <roland.mainz@nrubsig.org>
  201. +#
  202. +# Permission is hereby granted, free of charge, to any person obtaining a copy
  203. +# of this software and associated documentation files (the "Software"), to deal
  204. +# in the Software without restriction, including without limitation the rights
  205. +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  206. +# copies of the Software, and to permit persons to whom the Software is
  207. +# furnished to do so, subject to the following conditions:
  208. +#
  209. +# The above copyright notice and this permission notice shall be included in all
  210. +# copies or substantial portions of the Software.
  211. +#
  212. +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  213. +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  214. +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  215. +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  216. +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  217. +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  218. +# SOFTWARE.
  219. +#
  220. +
  221.  #
  222.  # sshnfs - remote login client with NFSv4 forwarding
  223.  #
  224.  
  225.  #
  226.  # Example usage:
  227. -# $ ksh sshnfs.ksh -o NFSURL=ssh+nfs://localhost/export/home/rmainz root@10.49.28.10 #
  228. -# $ ksh sshnfs.ksh -o NFSURL=nfs://localhost/export/home/rmainz root@10.49.20.207 #
  229. -# $ ksh sshnfs.ksh -o NFSURL=nfs://derfwpc5131/export/home/rmainz root@10.49.28.10 #
  230. -# $ ksh sshnfs.ksh -o NFSURL=ssh+nfs://derfwpc5131/export/home/rmainz -o SSHNFSJumphost=rmainz@derfwpc5131,roland.mainz@derfwnb8353 -J rmainz@derfwpc5131,roland.mainz@derfwnb8353 root@10.49.20.207
  231. -# $ ksh sshnfs.ksh -o NFSURL=ssh+nfs://derfwpc5131/export/home/rmainz target@fe80::d6f5:27ff:fe2b:8588%enp2s0
  232. -# $ ksh sshnfs.ksh -o NFSURL=ssh+nfs://root@derfwpc5131/export/home/rmainz root@10.49.28.56
  233. -# $ ksh sshnfs.ksh -o NFSServerSSHLoginName=root -o NFSURL=ssh+nfs://derfwpc5131/export/home/rmainz root@10.49.28.56
  234. -# $ SSHNFS_OPTIONS='-o NFSServerSSHLoginName=root -o NFSURL=ssh+nfs://derfwpc5131/export/home/rmainz' sshnfs.ksh root@10.49.28.56
  235. +# $ ksh sshnfs.ksh -o NFSURL=ssh+nfs://localhost//export/home/rmainz root@10.49.28.10 #
  236. +# $ ksh sshnfs.ksh -o NFSURL=nfs://localhost//export/home/rmainz root@10.49.20.207 #
  237. +# $ ksh sshnfs.ksh -o NFSURL=nfs://derfwpc5131//export/home/rmainz root@10.49.28.10 #
  238. +# $ ksh sshnfs.ksh -o NFSURL=ssh+nfs://derfwpc5131//export/home/rmainz -o SSHNFSJumphost=rmainz@derfwpc5131,roland.mainz@derfwnb8353 -J rmainz@derfwpc5131,roland.mainz@derfwnb8353 root@10.49.20.207
  239. +# $ ksh sshnfs.ksh -o NFSURL=ssh+nfs://derfwpc5131//export/home/rmainz target@fe80::d6f5:27ff:fe2b:8588%enp2s0
  240. +# $ ksh sshnfs.ksh -o NFSURL=ssh+nfs://root@derfwpc5131//export/home/rmainz root@10.49.28.56
  241. +# $ ksh sshnfs.ksh -o NFSServerSSHLoginName=root -o NFSURL=ssh+nfs://derfwpc5131//export/home/rmainz root@10.49.28.56
  242. +# $ SSHNFS_OPTIONS='-o NFSServerSSHLoginName=root -o NFSURL=ssh+nfs://derfwpc5131//export/home/rmainz' sshnfs.ksh root@10.49.28.56
  243.  #
  244.  
  245.  #
  246. @@ -263,6 +287,8 @@ function parse_sshnfs_url
  247.                 { print -u2 -f $"%s: Not a nfs:// or ssh+nfs:// url\n" "$0" ; return 1 ; }
  248.         [[ "${data.host}" != '' ]] || { print -u2 -f $"%s: NFS hostname missing\n" "$0" ; return 1 ; }
  249.         [[ "${data.uripath}" != '' ]] || { print -u2 -f $"%s: NFS path missing\n" "$0" ; return 1 ; }
  250. +       [[ "${data.uripath}" == /* ]] || { print -u2 -f $"%s: NFS path (%q) must be absolute\n" "$0" "${data.uripath}" ; return 1 ; }
  251. +       [[ "${data.uripath}" != //* ]] || { print -u2 -f $"%s: NFS path (%q) should not start with '//' \n" "$0" "${data.uripath}" ; return 1 ; }
  252.  
  253.         return 0
  254.  }
  255. @@ -424,7 +450,7 @@ function main
  256.  
  257.                                 print -u2 -f $"# Use this to mount the directory:\n"
  258.                                 print -u2 -f $"# $ mkdir /mnt_nfs\n"
  259. -                               print -u2 -f $"# $ mount -vvv -t nfs -o vers=4.2,port=%d localhost:/%s /mnt_nfs\n" \
  260. +                               print -u2 -f $"# $ mount -vvv -t nfs -o vers=4.2,port=%d localhost:%s /mnt_nfs\n" \
  261.                                         c.destination_nfs_port \
  262.                                         "${c.nfs_server.uripath}"
  263.  
  264. @@ -481,7 +507,7 @@ function main
  265.  
  266.                                 print -u2 -f $"# Use this to mount the directory:\n"
  267.                                 print -u2 -f $"# $ mkdir /mnt_nfs\n"
  268. -                               print -u2 -f $"# $ mount -vvv -t nfs -o vers=4.2,port=%d localhost:/%s /mnt_nfs\n" \
  269. +                               print -u2 -f $"# $ mount -vvv -t nfs -o vers=4.2,port=%d localhost:%s /mnt_nfs\n" \
  270.                                         c.destination_nfs_port \
  271.                                         "${c.nfs_server.uripath}"
  272.  
  273. --
  274. 2.43.0

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at