From 14f4a50b4b51bc4bdf56cfd43d8ae598579c4e6d Mon Sep 17 00:00:00 2001 From: Chuck Lever Date: Mon, 16 Jul 2007 16:29:01 -0400 Subject: [PATCH] mount.nfs: No need to return nfs_mount_data structs Refactor mount processing slightly to remove an output parameter and an unnecessary type cast. The mount syscall is now made from inside nfs_mount or nfs4mount, rather than in common code after those are called. Code review suggests that EX_BG was never returned by mount.nfs because the logic I just replaced was always returning EX_FAIL. The new logic should properly return EX_BG when appropriate. However, it is unclear whether /bin/mount handles backgrounding the mount request, or whether mount.nfs should. Signed-off-by: Chuck Lever Signed-off-by: Neil Brown --- utils/mount/mount.c | 22 ++-------------------- utils/mount/nfs4_mount.h | 3 +-- utils/mount/nfs4mount.c | 15 +++++++++++---- utils/mount/nfs_mount.h | 3 +-- utils/mount/nfsmount.c | 12 +++++++++--- 5 files changed, 24 insertions(+), 31 deletions(-) diff --git a/utils/mount/mount.c b/utils/mount/mount.c index de94e66..bd7e25c 100644 --- a/utils/mount/mount.c +++ b/utils/mount/mount.c @@ -250,11 +250,6 @@ fail_unlock: return result; } -int do_mount_syscall(char *spec, char *node, char *type, int flags, void *data) -{ - return mount(spec, node, type, flags, data); -} - void mount_usage() { printf("usage: %s remotetarget dir [-rvVwfnh] [-o nfsoptions]\n", @@ -473,26 +468,13 @@ int main(int argc, char *argv[]) exit(EX_FAIL); if (strcmp(fs_type, "nfs4") == 0) - mnt_err = nfs4mount(spec, mount_point, &flags, &extra_opts, &mount_opts, 0); + mnt_err = nfs4mount(spec, mount_point, &flags, &extra_opts, 0, fake); else - mnt_err = nfsmount(spec, mount_point, &flags, - &extra_opts, &mount_opts, - 0, fake); + mnt_err = nfsmount(spec, mount_point, &flags, &extra_opts, 0, fake); if (mnt_err) exit(EX_FAIL); - if (!fake) { - mnt_err = do_mount_syscall(spec, mount_point, fs_type, - flags & ~(MS_USER|MS_USERS) , - mount_opts); - - if (mnt_err) { - mount_error(spec, mount_point, errno); - exit(EX_FAIL); - } - } - if (!nomtab) mnt_err = add_mtab(spec, mount_point, fs_type, flags, extra_opts, 0, 0 /* these are always zero for NFS */ ); diff --git a/utils/mount/nfs4_mount.h b/utils/mount/nfs4_mount.h index 58e311e..921739b 100644 --- a/utils/mount/nfs4_mount.h +++ b/utils/mount/nfs4_mount.h @@ -68,7 +68,6 @@ struct nfs4_mount_data { #define NFS4_MOUNT_UNSHARED 0x8000 /* 5 */ #define NFS4_MOUNT_FLAGMASK 0xFFFF -int nfs4mount(const char *, const char *, int *, char **, - char **, int); +int nfs4mount(const char *, const char *, int *, char **, int, int); #endif diff --git a/utils/mount/nfs4mount.c b/utils/mount/nfs4mount.c index cc6eaf2..a0a1cab 100644 --- a/utils/mount/nfs4mount.c +++ b/utils/mount/nfs4mount.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ #include "conn.h" #include "xcommon.h" +#include "mount_constants.h" #include "nfs4_mount.h" #include "nfs_mount.h" #include "error.h" @@ -166,8 +168,7 @@ static int get_my_ipv4addr(char *ip_addr, int len) } int nfs4mount(const char *spec, const char *node, int *flags, - char **extra_opts, char **mount_opts, - int running_bg) + char **extra_opts, int running_bg, int fake) { static struct nfs4_mount_data data; static char hostdir[1024]; @@ -441,8 +442,14 @@ int nfs4mount(const char *spec, const char *node, int *flags, continue; } - *mount_opts = (char *) &data; - /* clean up */ + if (!fake) { + if (mount(spec, node, "nfs4", + *flags & ~(MS_USER|MS_USERS), &data)) { + mount_error(spec, node, errno); + goto fail; + } + } + return 0; fail: diff --git a/utils/mount/nfs_mount.h b/utils/mount/nfs_mount.h index e566083..169f12e 100644 --- a/utils/mount/nfs_mount.h +++ b/utils/mount/nfs_mount.h @@ -80,7 +80,6 @@ struct nfs_mount_data { #define AUTH_GSS_SPKMP 390011 #endif -int nfsmount(const char *, const char *, int *, char **, char **, - int, int); +int nfsmount(const char *, const char *, int *, char **, int, int); #endif /* _NFS_MOUNT_H */ diff --git a/utils/mount/nfsmount.c b/utils/mount/nfsmount.c index a3cbbbe..b6a0d60 100644 --- a/utils/mount/nfsmount.c +++ b/utils/mount/nfsmount.c @@ -487,8 +487,7 @@ out_bad: int nfsmount(const char *spec, const char *node, int *flags, - char **extra_opts, char **mount_opts, - int running_bg, int fake) + char **extra_opts, int running_bg, int fake) { static char *prev_bg_host; char hostdir[1024]; @@ -618,7 +617,6 @@ nfsmount(const char *spec, const char *node, int *flags, #endif data.version = nfs_mount_data_version; - *mount_opts = (char *) &data; if (*flags & MS_REMOUNT) goto out_ok; @@ -862,6 +860,14 @@ noauth_flavors: } } + if (!fake) { + if (mount(spec, node, "nfs", + *flags & ~(MS_USER|MS_USERS), &data)) { + mount_error(spec, node, errno); + goto fail; + } + } + return 0; /* abort */ -- 2.39.5