mount.nfs libmount support (v2)
Subsystems (2)
This is the second version of the mount.nfs with libmount support. The code depends on util-linux >= v2.19 (e.g. Fedora 15).
Chnages:
- move nfs_umount_do_umnt() to network.c
- use union nfs_sockaddr
- add missing GPL address paragraph
- use abstract function the storing and retrieval mount options
- use "static const" for struct option
- use "strncmp() == 0" everywhere
The locale issue is not fixed. It seems that _() macro from nls.h is used on many places in the package, but ENABLE_NLS macro is nowhere defined and setlocale() is not called at all.
I believe that this issue should be fixed independently on the libmount patches.
PATCH 1/2 mount: move generic functions to utils.c and network.c
Move generic code that could be shared between standard mount.nfs and libmount version to utils.c and network.c.
--- utils/mount/Makefile.am | 2 +- utils/mount/mount.c | 83 +---------------------- utils/mount/network.c | 68 ++++++++++++++++++ utils/mount/network.h | 3 + utils/mount/nfsumount.c | 119 +------------------------------- utils/mount/utils.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++ utils/mount/utils.h | 36 ++++++++++ 7 files changed, 286 insertions(+), 200 deletions(-) create mode 100644 utils/mount/utils.c create mode 100644 utils/mount/utils.h
utils/mount/Makefile.am +1 -1
@@ -16,7 +16,7 @@ mount_nfs_SOURCES = mount.c error.c network.c fstab.c token.c \ mount_constants.h error.h network.h fstab.h token.h \ parse_opt.h parse_dev.h \ nfs4_mount.h nfs_mount4.h stropts.h version.h \ - mount_config.h + mount_config.h utils.c utils.h if MOUNT_CONFIG mount_nfs_SOURCES += configfile.c
utils/mount/mount.c +2 -81
113 lines not on this page · raw message
utils/mount/network.c +68 -0
71 lines not on this page · raw message
utils/mount/network.h +3 -0
@@ -75,4 +75,7 @@ int nfs_advise_umount(const struct sockaddr *, const socklen_t,CLIENT *mnt_openclnt (clnt_addr_t *,int *);void mnt_closeclnt (CLIENT *,int ); +int nfs_umount_do_umnt (struct mount_options *options, +char **hostname,char **dirname); +#endif /* _NFS_UTILS_MOUNT_NETWORK_H */
utils/mount/nfsumount.c +1 -118
137 lines not on this page · raw message
utils/mount/utils.c new file +175 -0
175 lines not on this page · raw message
utils/mount/utils.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* utils.h -- misc utils for mount and umount +* +* Copyright (C) 2010 Karel Zak <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* 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 +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 021110-1307, USA. +* +*/ + +#ifndef _NFS_UTILS_MOUNT_UTILS_H +#define _NFS_UTILS_MOUNT_UTILS_H + +#include "parse_opt.h" + +int discover_nfs_mount_data_version (int *string_ver); +void print_one (char *spec,char *node,char *type,char *opts); +void mount_usage (void ); +void umount_usage (void ); +int chk_mountpoint (const char *mount_point); + +int nfs_umount23 (const char *devname,char *string); + +#endif /* !_NFS_UTILS_MOUNT_UTILS_H */
Signature · 1 line
1.7.3.4
PATCH 1/1 mount: Remove MOUNT_CONFIG warning
The following changes are needed to remove compile warnings when MOUNT_CONFIG is not define
utils/mount/mount_config.h +3 -3
@@ -39,10 +39,10 @@ static inline char *mount_config_opts(char *spec,#else /* MOUNT_CONFIG */ -static inline void mount_config_init (char *program) { } +static inline void mount_config_init (__attribute__ ((unused))char *program) { } -static inline char *mount_config_opts (char *spec, -char *mount_point,char *mount_opts) +static inline char *mount_config_opts (__attribute__ ((unused))char *spec, + __attribute__ ((unused))char *mount_point,char *mount_opts) {return mount_opts; }
utils/mount/stropts.c +1 -1
@@ -110,7 +110,7 @@ static void nfs_default_version(struct nfsmount_info *mi) } }#else -inline void nfs_default_version (struct nfsmount_info *mi) {} +inline void nfs_default_version (__attribute__ ((unused))struct nfsmount_info *mi) {}#endif /* MOUNT_CONFIG */
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 1.5/2] mount: Remove MOUNT_CONFIG warning
Hey Karel,
Quoted 2 lines · Steve Dickson
The following changes are needed to remove compile warnings when
MOUNT_CONFIGis not define
Don't worry about this one... I just committed it..
steved.
Quoted 36 lines
Signed-off-by Steve Dickson <[email protected]>utils/mount/mount_config.h +3
-3@@ -39,10 +39,10 @@ static inline char *mount_config_opts(char *spec,#else /* MOUNT_CONFIG */ -static inline void mount_config_init (char *program) { } +static inline void mount_config_init (__attribute__ ((unused))char *program) { } -static inline char *mount_config_opts (char *spec, -char *mount_point,char *mount_opts) +static inline char *mount_config_opts (__attribute__ ((unused))char *spec, + __attribute__ ((unused))char *mount_point,char *mount_opts) {return mount_opts; }utils/mount/stropts.c +1
-2@@ -110,7 +110,7 @@ static void nfs_default_version(struct nfsmount_info *mi) } }#else -inline void nfs_default_version (struct nfsmount_info *mi) {} +inline void nfs_default_version (__attribute__ ((unused))struct nfsmount_info *mi) {}#endif /* MOUNT_CONFIG */ --To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/2 mount: add --enable-libmount-mount
In reply to Karel ZakThis patch allows to link mount.nfs with libmount from util-linux >= v2.19. The new libmount based code is enabled by CONFIG_LIBMOUNT and is stored in mount_libmount.c. The old code is not affected by this change.
The libmount does not have officially stable API yet, so the --enable-libmount-mount is marked as experimental in the configure help output.
The ./configure option is the same as we use in util-linux to enable support for libmount in mount(8).
The addr= (and some other options necessary for remount/umount) are stored to /etc/mtab or to /dev/.mount/utab. The utab file is *private* libmount file. It's possible that some mount options (for example user=) will be moved to kernel, so the utab will not be necessary.
About libmount:
* supports systems without and with regular /etc/mtab
* does not store VFS and FS mount options in userspace
* manages user= option and evaluate permissions
* parses VFS mount options and generate MS_* flags
* parses /etc/{fstab,mtab}, /proc/mounts or /proc/self/mountinfo
* long-term goal is to use the same code in all mount.<type> helpers
Note, use
LIBMOUNT_DEBUG=0xffff mount.nfs foo:/path /path
to debug the library.
On systems with util-linux v2.19 the findmnt(8) command uses libmount to list all/selected mount points:
$ findmnt /path $ findmnt --mtab /path
the --mtab appends userspace mount options (e.g. user=) to the output.
--- configure.ac | 16 ++ utils/mount/Makefile.am | 13 ++- utils/mount/mount_libmount.c | 411 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 438 insertions(+), 2 deletions(-) create mode 100644 utils/mount/mount_libmount.c
configure.ac +16 -0
@@ -132,6 +132,15 @@ AC_ARG_ENABLE(mount, enable_mount=$enableval, enable_mount=yes) AM_CONDITIONAL(CONFIG_MOUNT, [test "$enable_mount" = "yes"]) + +if test "$enable_mount" = yes; then + AC_ARG_ENABLE(libmount-mount, + [AC_HELP_STRING([--enable-libmount-mount], + [Link mount.nfs with libmount (EXPERIMENTAL)])], + enable_libmount=yes, + enable_libmount=no) +fi + AC_ARG_ENABLE(tirpc, [AC_HELP_STRING([--enable-tirpc], [enable use of TI-RPC @<:@default=yes@:>@])],
@@ -285,6 +294,13 @@ AC_SUBST(LIBCRYPT) AC_SUBST(LIBBSD) AC_SUBST(LIBBLKID) +if test "$enable_libmount" != no; then + AC_CHECK_LIB(mount, mnt_context_do_mount, [LIBMOUNT="-lmount"], AC_MSG_ERROR([libmount needed])) + AC_CHECK_HEADER(libmount/libmount.h, , AC_MSG_ERROR([Cannot find libmount header file libmount/libmount.h])) +fi +AM_CONDITIONAL(CONFIG_LIBMOUNT, [test "$enable_libmount" = "yes"]) +AC_SUBST(LIBMOUNT) + if test "$enable_gss" = yes; then dnl 'gss' requires getnameinfo - at least for gssd_proc.c AC_CHECK_FUNC([getnameinfo], , [AC_MSG_ERROR([GSSAPI support requires 'getnameinfo' function])])
utils/mount/Makefile.am +11 -2
@@ -9,7 +9,7 @@ man5_MANS = nfs.man sbin_PROGRAMS = mount.nfs EXTRA_DIST = nfsmount.x $(man8_MANS) $(man5_MANS) -mount_nfs_SOURCES = mount.c error.c network.c fstab.c token.c \ +mount_common = error.c network.c fstab.c token.c \ parse_opt.c parse_dev.c \ nfsmount.c nfs4mount.c stropts.c\ nfsumount.c \
@@ -19,7 +19,7 @@ mount_nfs_SOURCES = mount.c error.c network.c fstab.c token.c \ mount_config.h utils.c utils.h if MOUNT_CONFIG -mount_nfs_SOURCES += configfile.c +mount_common += configfile.c man5_MANS += nfsmount.conf.man EXTRA_DIST += nfsmount.conf endif
@@ -27,6 +27,15 @@ endif mount_nfs_LDADD = ../../support/nfs/libnfs.a \ ../../support/export/libexport.a +mount_nfs_SOURCES = $(mount_common) + +if CONFIG_LIBMOUNT +mount_nfs_SOURCES += mount_libmount.c +mount_nfs_LDADD += $(LIBMOUNT) +else +mount_nfs_SOURCES += mount.c +endif + MAINTAINERCLEANFILES = Makefile.in install-exec-hook:
utils/mount/mount_libmount.c new file +411 -0
411 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Re: [PATCH 2/2] mount: add --enable-libmount-mount
Quoted 63 lines · Karel Zak
utils/mount/mount_libmount.c new file +63
-0+static int umount_main (struct libmnt_context *cxt,int argc,char **argv) +{ +int rc, c; +char *spec =NULL , *opts =NULL ; + +static const struct option longopts[] = { + {"force" ,0 ,0 ,'f' }, + {"help" ,0 ,0 ,'h' }, + {"no-mtab" ,0 ,0 ,'n' }, + {"verbose" ,0 ,0 ,'v' }, + {"read-only" ,0 ,0 ,'r' }, + {"lazy" ,0 ,0 ,'l' }, + {"types" ,1 ,0 ,'t' }, + {NULL ,0 ,0 ,0 } + }; + +mnt_context_init_helper (cxt,MNT_ACT_UMOUNT ,0 ); + +while ((c =getopt_long (argc, argv,"fvnrlh" , longopts,NULL )) !=-1 ) { + + rc =mnt_context_helper_setopt (cxt, c, optarg); +if (rc ==0 )/* valid option */ +continue ; +if (rc <0 )/* error (probably ENOMEM) */ + goto err; +/* rc==1 means unknow option */ +umount_usage (); +return EX_USAGE ; + } + +if (optind < argc) + spec = argv[optind++]; + +if (!spec || (*spec !='/' &&strchr (spec,':' ) ==NULL )) { +nfs_error (_ ("%s: no mount point provided" ), progname); +return EX_USAGE ; + } + +if (mnt_context_set_target (cxt, spec)) + goto err; +if (mnt_context_set_fstype_pattern (cxt,"nfs,nfs4" ))/* restrict filesystems */ + goto err; + +/* read mtab/fstab, evaluate permissions, etc. */ + rc =mnt_context_prepare_umount (cxt); +if (rc) { +nfs_error (_ ("%s: failed to prepare umount: %s\n" ), + progname,strerror (-rc)); + goto err; + } + + opts =retrieve_mount_options (mnt_context_get_fs (cxt)); + +if (!mnt_context_is_lazy (cxt)) { +if (opts) { +/* we have full FS description (e.g. from mtab or /proc) */ +switch (is_vers4 (cxt)) { +case 0 : +/* We ignore the error from nfs_umount23. +* If the actual umount succeeds (in del_mtab), +* we don't want to signal an error, as that +* could cause /sbin/mount to retry! +*/
utils/mount/mount_libmount.c line 235
Quoted 10 lines
utils/mount/mount_libmount.c new file +10
-0+nfs_umount23 (mnt_context_get_source (cxt), opts); +break ; +case 1 :/* unknown */ +break ; +default :/* error */ + goto err; + } + }else +/* strange, no entry in mtab or /proc not mounted */ +nfs_umount23 (spec,"tcp,v3" );
Question: since retrieve_mount_options() returns NULL why do you assume the mount exists? What's happing is I'm doing an umount.nfs on an not existing mount point and the error is
umount.nfs: remote share not in 'host:dir' format
Instead of
umount.nfs: /mnt/home: not mounted
steved.
Re: [PATCH 2/2] mount: add --enable-libmount-mount
Quoted 16 lines · Steve Dickson
Quoted 16 lines
utils/mount/mount_libmount.c new file +16
-0+ opts =retrieve_mount_options (mnt_context_get_fs (cxt)); + +if (!mnt_context_is_lazy (cxt)) { +if (opts) { +/* we have full FS description (e.g. from mtab or /proc) */ +switch (is_vers4 (cxt)) { +case 0 : +/* We ignore the error from nfs_umount23. +* If the actual umount succeeds (in del_mtab), +* we don't want to signal an error, as that +* could cause /sbin/mount to retry! +*/ +nfs_umount23 (mnt_context_get_source (cxt), opts); +break ; +case 1 :/* unknown */ +break ;
Quoted 8 lines
utils/mount/mount_libmount.c line 235
Quoted 6 lines
utils/mount/mount_libmount.c new file +6
-0+default :/* error */ + goto err; + } + }else +/* strange, no entry in mtab or /proc not mounted */ +nfs_umount23 (spec,"tcp,v3" );Question: since
retrieve_mount_options()returns NULL why do you assume the mount exists?
because on systems with /etc/mtab is possible that the file is empty, so we have no clue about the mount point.
This is normal umount(8) behavior, for root user it always tries to call umount(2) syscall. We should not assume that there is usable /proc or /etc/mtab. It's important be able to umount any device independently on /proc or /etc.
See nfsumount.c, the current code uses the same logic.
Quoted 6 lines
What's happing is I'm doing an umount.nfs on an not existing mount point and the error is
umount.nfs: remote share not in 'host:dir' formatInstead of
umount.nfs:/mnt/home: not mounted
Good catch, this is bug. There is missing umount_error();
I'll update the patch and add your change to mount_config_init() too.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH 2/2] mount: add --enable-libmount-mount
Quoted 26 lines · Karel Zak
Quoted 16 lines · Steve Dickson
Quoted 16 lines
utils/mount/mount_libmount.c new file +16
-0+ opts =retrieve_mount_options (mnt_context_get_fs (cxt)); + +if (!mnt_context_is_lazy (cxt)) { +if (opts) { +/* we have full FS description (e.g. from mtab or /proc) */ +switch (is_vers4 (cxt)) { +case 0 : +/* We ignore the error from nfs_umount23. +* If the actual umount succeeds (in del_mtab), +* we don't want to signal an error, as that +* could cause /sbin/mount to retry! +*/ +nfs_umount23 (mnt_context_get_source (cxt), opts); +break ; +case 1 :/* unknown */ +break ;Quoted 8 lines
utils/mount/mount_libmount.c line 235
Quoted 6 lines
utils/mount/mount_libmount.c new file +6
-0+default :/* error */ + goto err; + } + }else +/* strange, no entry in mtab or /proc not mounted */ +nfs_umount23 (spec,"tcp,v3" );Question: since
retrieve_mount_options()returns NULL why do you assume the mount exists?
Quoted 2 lines
because on systems with
/etc/mtabis possible that the file is empty, so we have no clue about the mount point.
Ah... I am so glad mtab is going away!
Quoted 7 lines
This is normal umount(8) behavior, for root user it always tries to call umount(2) syscall. We should not assume that there is usable /proc or
/etc/mtab. It's important be able to umount any device independently on /proc or /etc.See
nfsumount.c, the current code uses the same logic.
Got it..
Quoted 11 lines
Quoted 7 lines
What's happing is I'm doing an umount.nfs on an not existing mount point and the error is
umount.nfs: remote share not in 'host:dir' formatInstead of
umount.nfs:/mnt/home: not mountedGood catch, this is bug. There is missing
umount_error();I'll update the patch and add your change to
mount_config_init()too.
Thank you...
steved.
Quoted 12 lines · Karel Zak
This is the second version of the mount.nfs with libmount support. The code depends on util-linux >= v2.19 (e.g. Fedora 15).
Chnages:
- movenfs_umount_do_umnt()tonetwork.c
- use unionnfs_sockaddr
- add missing GPL address paragraph
- use abstract function the storing and retrieval mount options
- use "static const" for struct option
- use "strncmp()== 0" everywhere
Quoted 6 lines
The locale issue is not fixed. It seems that
_()macro fromnls.his used on many places in the package, butENABLE_NLSmacro is nowhere defined andsetlocale()is not called at all.I believe that this issue should be fixed independently on the libmount patches.
Thanks for the update.
The overall architecture looks sane to me. I think we would accelerate adoption by having nfs-utils take this now as an experimental "technology preview" thing, so the new code is widely available in a shared repo. That would make it easier for people to play with it as libmount becomes available in more distributions. We can then quickly make any minor adjustments needed. Steve, thoughts?
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
[PATCH 3/2] mount: Allow 'port=0' to be a valid port value.
In reply to Karel ZakWith the new util-linux, /etc/mtab is now is symbolically linked to /proc/mounts. In /proc/mounts, the 'port=0' exits which causes the umount.nfs to error out with the following error:
umount.nfs: invalid value for 'port=' option
Setting port=0 is a valid value. It just means go out and query remote rpcbind to get the correct port.
--- utils/mount/network.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
utils/mount/network.c +1 -1
@@ -1346,7 +1346,7 @@ nfs_nfs_port(struct mount_options *options, unsigned long *port)case PO_NOT_FOUND :break ;case PO_FOUND : -if (tmp >=1 && tmp <=65535 ) { +if (tmp >=0 && tmp <=65535 ) { *port = tmp;return 1 ; }
Re: [PATCH 3/2] mount: Allow 'port=0' to be a valid port value.
Hi Steve-
Quoted 9 lines · Steve Dickson
With the new util-linux,
/etc/mtabis now is symbolically linked to/proc/mounts. In/proc/mounts, the 'port=0' exits which causes the umount.nfs to error out with the following error:
umount.nfs: invalid value for 'port=' optionSetting port=0 is a valid value. It just means go out and query remote rpcbind to get the correct port.
Signed-off-by Steve Dickson <[email protected]>
Why are you signing off on this? I sent you this patch weeks ago. (In fact my version of the patch also fixes this problem in nfs_mount_port() as well).
Quoted 21 lines
---
utils/mount/network.c| 2 +-1 files changed, 1 insertions(+), 1 deletions(-)utils/mount/network.c +1
-2@@ -1346,7 +1346,7 @@ nfs_nfs_port(struct mount_options *options, unsigned long *port)case PO_NOT_FOUND :break ;case PO_FOUND : -if (tmp >=1 && tmp <=65535 ) { +if (tmp >=0 && tmp <=65535 ) { *port = tmp;return 1 ; } --To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 3/2] mount: Allow 'port=0' to be a valid port value.
Quoted 9 lines · Chuck Lever
Hi Steve-
Quoted 5 lines · Steve Dickson
With the new util-linux,
/etc/mtabis now is symbolically linked to/proc/mounts. In/proc/mounts, the 'port=0' exits which causes the umount.nfs to error out with the following error:
umount.nfs: invalid value for 'port=' option
Quoted 6 lines
Quoted 4 lines
Setting port=0 is a valid value. It just means go out and query remote rpcbind to get the correct port.
Signed-off-by Steve Dickson <[email protected]>Why are you signing off on this? I sent you this patch weeks ago. (In fact my version of the patch also fixes this problem in
nfs_mount_port()as well).
Could have been lost in the shuffle... we were all traveling. Anyway, you need to fix this in nfs_mount_port() too.
Quoted 34 lines
Quoted 22 lines
---
utils/mount/network.c| 2 +-1 files changed, 1 insertions(+), 1 deletions(-)utils/mount/network.c +1
-2@@ -1346,7 +1346,7 @@ nfs_nfs_port(struct mount_options *options, unsigned long *port)case PO_NOT_FOUND :break ;case PO_FOUND : -if (tmp >=1 && tmp <=65535 ) { +if (tmp >=0 && tmp <=65535 ) { *port = tmp;return 1 ; } --To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 10 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Re: [PATCH 3/2] mount: Allow 'port=0' to be a valid port value.
Quoted 12 lines · Chuck Lever
Quoted 9 lines · Chuck Lever
Hi Steve-
Quoted 5 lines · Steve Dickson
With the new util-linux,
/etc/mtabis now is symbolically linked to/proc/mounts. In/proc/mounts, the 'port=0' exits which causes the umount.nfs to error out with the following error:
umount.nfs: invalid value for 'port=' option
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Setting port=0 is a valid value. It just means go out and query remote rpcbind to get the correct port.
Signed-off-by Steve Dickson <[email protected]>Why are you signing off on this? I sent you this patch weeks ago. (In fact my version of the patch also fixes this problem in
nfs_mount_port()as well).Could have been lost in the shuffle... we were all traveling. Anyway, you need to fix this in () too.
Yeah... I don't see it... but see your point WRT nfs_mount_port()
steved.
Quoted 37 lines
Quoted 36 lines
Quoted 24 lines
---
utils/mount/network.c| 2 +-1 files changed, 1 insertions(+), 1 deletions(-)utils/mount/network.c +1
-2@@ -1346,7 +1346,7 @@ nfs_nfs_port(struct mount_options *options, unsigned long *port)case PO_NOT_FOUND :break ;case PO_FOUND : -if (tmp >=1 && tmp <=65535 ) { +if (tmp >=0 && tmp <=65535 ) { *port = tmp;return 1 ; } --To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 10 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html