mount.nfs: Create a common source module for reporting mount errors
Subsystems (2)
PATCH 6/17 mount.nfs: Create a common source module for reporting mount errors
Clean up, and pre-requisite for subsequent fixes.
Signed-off-by Chuck Lever <[email protected]>
---
utils/mount/Makefile.am | 7 + utils/mount/mount.c | 33 +----- utils/mount/nfs4mount.c | 1 utils/mount/nfs_mount.h | 1 utils/mount/nfsmount.c | 128 ------------------------ utils/mount/nfsmount_err.c | 235 ++++++++++++++++++++++++++++++++++++++++++++ utils/mount/nfsmount_err.h | 28 +++++ utils/mount/nfsumount.c | 27 ----- 8 files changed, 277 insertions(+), 183 deletions(-)
utils/mount/Makefile.am +5 -2
@@ -9,8 +9,11 @@ man5_MANS = nfs.man sbin_PROGRAMS = mount.nfs EXTRA_DIST = nfsmount.x $(man8_MANS) $(man5_MANS) -mount_nfs_SOURCES = mount.c nfsmount.c nfs4mount.c nfsumount.c \ - mount_constants.h nfs4_mount.h nfs_mount4.h +mount_nfs_SOURCES = mount.c nfsmount_err.c \ + nfsmount.c nfs4mount.c \ + nfsumount.c \ + mount_constants.h nfsmount_err.h \ + nfs4_mount.h nfs_mount4.h mount_nfs_LDADD = ../../support/nfs/libnfs.a \ ../../support/export/libexport.a
utils/mount/mount.c +5 -28
@@ -40,6 +40,7 @@#include "nfs4_mount.h" #include "nfsumount.h" #include "mount.h" +#include "nfsmount_err.h" char *progname;int nomtab;
@@ -276,44 +277,20 @@ static void parse_opts (const char *options, int *flags, char **extra_opts) } } -static void mount_error (char *mntpnt,char *node) -{ -switch (errno) { -case ENOTDIR : -fprintf (stderr,"%s: mount point %s is not a directory\n" , - progname, mntpnt); -break ; -case EBUSY : -fprintf (stderr,"%s: %s is already mounted or busy\n" , - progname, mntpnt); -break ; -case ENOENT : -if (node) { -fprintf (stderr,"%s: %s failed, reason given by server: %s\n" , - progname, node,strerror (errno)); - }else -fprintf (stderr,"%s: mount point %s does not exist\n" , - progname, mntpnt); -break ; -default : -fprintf (stderr,"%s: %s\n" , progname,strerror (errno)); - } -}static int chk_mountpoint (char *mount_point) {struct stat sb;if (stat (mount_point, &sb) <0 ){ -mount_error (mount_point,NULL ); +mount_error (NULL , mount_point, errno);return 1 ; }if (S_ISDIR (sb.st_mode) ==0 ){ - errno =ENOTDIR ; -mount_error (mount_point,NULL ); +mount_error (NULL , mount_point,ENOTDIR );return 1 ; }if (access (mount_point,X_OK ) <0 ) { -mount_error (mount_point,NULL ); +mount_error (NULL , mount_point, errno);return 1 ; }
@@ -523,7 +500,7 @@ int main(int argc, char *argv[]) mount_opts);if (mnt_err) { -mount_error (mount_point, spec); +mount_error (spec, mount_point, errno);exit (EX_FAIL ); } }
utils/mount/nfs4mount.c +1 -0
@@ -43,6 +43,7 @@#include "nfs4_mount.h" #include "nfs_mount.h" +#include "nfsmount_err.h" #if defined(VAR_LOCK_DIR )#define DEFAULT_DIR VAR_LOCK_DIR
utils/mount/nfs_mount.h +0 -1
@@ -82,6 +82,5 @@ struct nfs_mount_data {int nfsmount (const char *,const char *,int *,char **,char **,int ,int *); -void mount_errors (char *,int ,int );#endif /* _NFS_MOUNT_H */
utils/mount/nfsmount.c +1 -127
152 lines not on this page · raw message
utils/mount/nfsmount_err.c new file +235 -0
235 lines not on this page · raw message
utils/mount/nfsmount_err.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* nfsmount_err.h: Common error handling functions +* +* Copyright (C) 2007 Oracle. All rights reserved. +* Copyright (C) 2007 Chuck Lever <[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. +* +*/ + +char *nfs_strerror (int ); + +void mount_error (const char *,const char *,int ); +void mount_errors (char *,int ,int ); +void umount_error (int ,const char *);
utils/mount/nfsumount.c +2 -25
@@ -34,6 +34,7 @@#include "mount_constants.h" #include "mount.h" #include "nfsumount.h" +#include "nfsmount_err.h" #if !defined(MNT_FORCE )/* dare not try to include <linux/mount.h> -- lots of errors */
@@ -93,30 +94,6 @@ int nfs_call_umount(clnt_addr_t *mnt_server, dirpath *argp)return res; } -/* complain about a failed umount */ -static void complain (int err,const char *dev) { -switch (err) { -case ENXIO : -nfs_error (_ ("umount: %s: invalid block device" ), dev);break ; -case EINVAL : -nfs_error (_ ("umount: %s: not mounted" ), dev);break ; -case EIO : -nfs_error (_ ("umount: %s: can't write superblock" ), dev);break ; -case EBUSY : -/* Let us hope fstab has a line "proc /proc ..." -and not "none /proc ..."*/ -nfs_error (_ ("umount: %s: device is busy" ), dev);break ; -case ENOENT : -nfs_error (_ ("umount: %s: not found" ), dev);break ; -case EPERM : -nfs_error (_ ("umount: %s: must be superuser to umount" ), dev);break ; -case EACCES : -nfs_error (_ ("umount: %s: block devices not permitted on fs" ), dev);break ; -default : -nfs_error (_ ("umount: %s: %s" ), dev,strerror (err));break ; - } -} -int del_mtab (const char *spec,const char *node) {int umnt_err, res;
@@ -183,7 +160,7 @@ int del_mtab(const char *spec, const char *node)return 0 ;if (umnt_err) -complain (umnt_err, node); +umount_error (umnt_err, node);return 1 ; }
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs