aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/super.c
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2007-07-01 12:13:44 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2007-07-10 23:40:47 -0400
commitbf0fd7680f1cf31b9cbabcc037a204548e2c866d (patch)
tree928e908559377a0489f8b4004d821d8f61c761bf /fs/nfs/super.c
parent013a8c1ab5a214c608e12b602770449fb6b15a81 (diff)
NFS: Add enums and match tables for mount option parsing
This generic infrastructure works for both NFS and NFSv4 mounts. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/super.c')
-rw-r--r--fs/nfs/super.c528
1 files changed, 528 insertions, 0 deletions
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index ed3ec4477a0f..7e56411e55fc 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -45,6 +45,7 @@
45#include <linux/inet.h> 45#include <linux/inet.h>
46#include <linux/nfs_xdr.h> 46#include <linux/nfs_xdr.h>
47#include <linux/magic.h> 47#include <linux/magic.h>
48#include <linux/parser.h>
48 49
49#include <asm/system.h> 50#include <asm/system.h>
50#include <asm/uaccess.h> 51#include <asm/uaccess.h>
@@ -57,6 +58,164 @@
57 58
58#define NFSDBG_FACILITY NFSDBG_VFS 59#define NFSDBG_FACILITY NFSDBG_VFS
59 60
61
62struct nfs_parsed_mount_data {
63 int flags;
64 int rsize, wsize;
65 int timeo, retrans;
66 int acregmin, acregmax,
67 acdirmin, acdirmax;
68 int namlen;
69 unsigned int bsize;
70 unsigned int auth_flavor_len;
71 rpc_authflavor_t auth_flavors[1];
72 char *client_address;
73
74 struct {
75 struct sockaddr_in address;
76 unsigned int program;
77 unsigned int version;
78 unsigned short port;
79 int protocol;
80 } mount_server;
81
82 struct {
83 struct sockaddr_in address;
84 char *hostname;
85 char *export_path;
86 unsigned int program;
87 int protocol;
88 } nfs_server;
89};
90
91enum {
92 /* Mount options that take no arguments */
93 Opt_soft, Opt_hard,
94 Opt_intr, Opt_nointr,
95 Opt_posix, Opt_noposix,
96 Opt_cto, Opt_nocto,
97 Opt_ac, Opt_noac,
98 Opt_lock, Opt_nolock,
99 Opt_v2, Opt_v3,
100 Opt_udp, Opt_tcp,
101 Opt_acl, Opt_noacl,
102 Opt_rdirplus, Opt_nordirplus,
103
104 /* Mount options that take integer arguments */
105 Opt_port,
106 Opt_rsize, Opt_wsize, Opt_bsize,
107 Opt_timeo, Opt_retrans,
108 Opt_acregmin, Opt_acregmax,
109 Opt_acdirmin, Opt_acdirmax,
110 Opt_actimeo,
111 Opt_namelen,
112 Opt_mountport,
113 Opt_mountprog, Opt_mountvers,
114 Opt_nfsprog, Opt_nfsvers,
115
116 /* Mount options that take string arguments */
117 Opt_sec, Opt_proto, Opt_mountproto,
118 Opt_addr, Opt_mounthost, Opt_clientaddr,
119
120 /* Mount options that are ignored */
121 Opt_userspace, Opt_deprecated,
122
123 Opt_err
124};
125
126static match_table_t nfs_mount_option_tokens = {
127 { Opt_userspace, "bg" },
128 { Opt_userspace, "fg" },
129 { Opt_soft, "soft" },
130 { Opt_hard, "hard" },
131 { Opt_intr, "intr" },
132 { Opt_nointr, "nointr" },
133 { Opt_posix, "posix" },
134 { Opt_noposix, "noposix" },
135 { Opt_cto, "cto" },
136 { Opt_nocto, "nocto" },
137 { Opt_ac, "ac" },
138 { Opt_noac, "noac" },
139 { Opt_lock, "lock" },
140 { Opt_nolock, "nolock" },
141 { Opt_v2, "v2" },
142 { Opt_v3, "v3" },
143 { Opt_udp, "udp" },
144 { Opt_tcp, "tcp" },
145 { Opt_acl, "acl" },
146 { Opt_noacl, "noacl" },
147 { Opt_rdirplus, "rdirplus" },
148 { Opt_nordirplus, "nordirplus" },
149
150 { Opt_port, "port=%u" },
151 { Opt_rsize, "rsize=%u" },
152 { Opt_wsize, "wsize=%u" },
153 { Opt_bsize, "bsize=%u" },
154 { Opt_timeo, "timeo=%u" },
155 { Opt_retrans, "retrans=%u" },
156 { Opt_acregmin, "acregmin=%u" },
157 { Opt_acregmax, "acregmax=%u" },
158 { Opt_acdirmin, "acdirmin=%u" },
159 { Opt_acdirmax, "acdirmax=%u" },
160 { Opt_actimeo, "actimeo=%u" },
161 { Opt_userspace, "retry=%u" },
162 { Opt_namelen, "namlen=%u" },
163 { Opt_mountport, "mountport=%u" },
164 { Opt_mountprog, "mountprog=%u" },
165 { Opt_mountvers, "mountvers=%u" },
166 { Opt_nfsprog, "nfsprog=%u" },
167 { Opt_nfsvers, "nfsvers=%u" },
168 { Opt_nfsvers, "vers=%u" },
169
170 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" },
172 { Opt_mountproto, "mountproto=%s" },
173 { Opt_addr, "addr=%s" },
174 { Opt_clientaddr, "clientaddr=%s" },
175 { Opt_mounthost, "mounthost=%s" },
176
177 { Opt_err, NULL }
178};
179
180enum {
181 Opt_xprt_udp, Opt_xprt_tcp,
182
183 Opt_xprt_err
184};
185
186static match_table_t nfs_xprt_protocol_tokens = {
187 { Opt_xprt_udp, "udp" },
188 { Opt_xprt_tcp, "tcp" },
189
190 { Opt_xprt_err, NULL }
191};
192
193enum {
194 Opt_sec_none, Opt_sec_sys,
195 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
196 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
197 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
198
199 Opt_sec_err
200};
201
202static match_table_t nfs_secflavor_tokens = {
203 { Opt_sec_none, "none" },
204 { Opt_sec_none, "null" },
205 { Opt_sec_sys, "sys" },
206
207 { Opt_sec_krb5, "krb5" },
208 { Opt_sec_krb5i, "krb5i" },
209 { Opt_sec_krb5p, "krb5p" },
210
211 { Opt_sec_lkey, "lkey" },
212 { Opt_sec_lkeyi, "lkeyi" },
213 { Opt_sec_lkeyp, "lkeyp" },
214
215 { Opt_sec_err, NULL }
216};
217
218
60static void nfs_umount_begin(struct vfsmount *, int); 219static void nfs_umount_begin(struct vfsmount *, int);
61static int nfs_statfs(struct dentry *, struct kstatfs *); 220static int nfs_statfs(struct dentry *, struct kstatfs *);
62static int nfs_show_options(struct seq_file *, struct vfsmount *); 221static int nfs_show_options(struct seq_file *, struct vfsmount *);
@@ -464,6 +623,375 @@ static int nfs_verify_server_address(struct sockaddr *addr)
464} 623}
465 624
466/* 625/*
626 * Error-check and convert a string of mount options from user space into
627 * a data structure
628 */
629static int nfs_parse_mount_options(char *raw,
630 struct nfs_parsed_mount_data *mnt)
631{
632 char *p, *string;
633
634 if (!raw) {
635 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
636 return 1;
637 }
638 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
639
640 while ((p = strsep(&raw, ",")) != NULL) {
641 substring_t args[MAX_OPT_ARGS];
642 int option, token;
643
644 if (!*p)
645 continue;
646
647 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
648
649 token = match_token(p, nfs_mount_option_tokens, args);
650 switch (token) {
651 case Opt_soft:
652 mnt->flags |= NFS_MOUNT_SOFT;
653 break;
654 case Opt_hard:
655 mnt->flags &= ~NFS_MOUNT_SOFT;
656 break;
657 case Opt_intr:
658 mnt->flags |= NFS_MOUNT_INTR;
659 break;
660 case Opt_nointr:
661 mnt->flags &= ~NFS_MOUNT_INTR;
662 break;
663 case Opt_posix:
664 mnt->flags |= NFS_MOUNT_POSIX;
665 break;
666 case Opt_noposix:
667 mnt->flags &= ~NFS_MOUNT_POSIX;
668 break;
669 case Opt_cto:
670 mnt->flags &= ~NFS_MOUNT_NOCTO;
671 break;
672 case Opt_nocto:
673 mnt->flags |= NFS_MOUNT_NOCTO;
674 break;
675 case Opt_ac:
676 mnt->flags &= ~NFS_MOUNT_NOAC;
677 break;
678 case Opt_noac:
679 mnt->flags |= NFS_MOUNT_NOAC;
680 break;
681 case Opt_lock:
682 mnt->flags &= ~NFS_MOUNT_NONLM;
683 break;
684 case Opt_nolock:
685 mnt->flags |= NFS_MOUNT_NONLM;
686 break;
687 case Opt_v2:
688 mnt->flags &= ~NFS_MOUNT_VER3;
689 break;
690 case Opt_v3:
691 mnt->flags |= NFS_MOUNT_VER3;
692 break;
693 case Opt_udp:
694 mnt->flags &= ~NFS_MOUNT_TCP;
695 mnt->nfs_server.protocol = IPPROTO_UDP;
696 mnt->timeo = 7;
697 mnt->retrans = 5;
698 break;
699 case Opt_tcp:
700 mnt->flags |= NFS_MOUNT_TCP;
701 mnt->nfs_server.protocol = IPPROTO_TCP;
702 mnt->timeo = 600;
703 mnt->retrans = 2;
704 break;
705 case Opt_acl:
706 mnt->flags &= ~NFS_MOUNT_NOACL;
707 break;
708 case Opt_noacl:
709 mnt->flags |= NFS_MOUNT_NOACL;
710 break;
711 case Opt_rdirplus:
712 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
713 break;
714 case Opt_nordirplus:
715 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
716 break;
717
718 case Opt_port:
719 if (match_int(args, &option))
720 return 0;
721 if (option < 0 || option > 65535)
722 return 0;
723 mnt->nfs_server.address.sin_port = htonl(option);
724 break;
725 case Opt_rsize:
726 if (match_int(args, &mnt->rsize))
727 return 0;
728 break;
729 case Opt_wsize:
730 if (match_int(args, &mnt->wsize))
731 return 0;
732 break;
733 case Opt_bsize:
734 if (match_int(args, &option))
735 return 0;
736 if (option < 0)
737 return 0;
738 mnt->bsize = option;
739 break;
740 case Opt_timeo:
741 if (match_int(args, &mnt->timeo))
742 return 0;
743 break;
744 case Opt_retrans:
745 if (match_int(args, &mnt->retrans))
746 return 0;
747 break;
748 case Opt_acregmin:
749 if (match_int(args, &mnt->acregmin))
750 return 0;
751 break;
752 case Opt_acregmax:
753 if (match_int(args, &mnt->acregmax))
754 return 0;
755 break;
756 case Opt_acdirmin:
757 if (match_int(args, &mnt->acdirmin))
758 return 0;
759 break;
760 case Opt_acdirmax:
761 if (match_int(args, &mnt->acdirmax))
762 return 0;
763 break;
764 case Opt_actimeo:
765 if (match_int(args, &option))
766 return 0;
767 if (option < 0)
768 return 0;
769 mnt->acregmin =
770 mnt->acregmax =
771 mnt->acdirmin =
772 mnt->acdirmax = option;
773 break;
774 case Opt_namelen:
775 if (match_int(args, &mnt->namlen))
776 return 0;
777 break;
778 case Opt_mountport:
779 if (match_int(args, &option))
780 return 0;
781 if (option < 0 || option > 65535)
782 return 0;
783 mnt->mount_server.port = option;
784 break;
785 case Opt_mountprog:
786 if (match_int(args, &option))
787 return 0;
788 if (option < 0)
789 return 0;
790 mnt->mount_server.program = option;
791 break;
792 case Opt_mountvers:
793 if (match_int(args, &option))
794 return 0;
795 if (option < 0)
796 return 0;
797 mnt->mount_server.version = option;
798 break;
799 case Opt_nfsprog:
800 if (match_int(args, &option))
801 return 0;
802 if (option < 0)
803 return 0;
804 mnt->nfs_server.program = option;
805 break;
806 case Opt_nfsvers:
807 if (match_int(args, &option))
808 return 0;
809 switch (option) {
810 case 2:
811 mnt->flags &= ~NFS_MOUNT_VER3;
812 break;
813 case 3:
814 mnt->flags |= NFS_MOUNT_VER3;
815 break;
816 default:
817 goto out_unrec_vers;
818 }
819 break;
820
821 case Opt_sec:
822 string = match_strdup(args);
823 if (string == NULL)
824 goto out_nomem;
825 token = match_token(string, nfs_secflavor_tokens, args);
826 kfree(string);
827
828 /*
829 * The flags setting is for v2/v3. The flavor_len
830 * setting is for v4. v2/v3 also need to know the
831 * difference between NULL and UNIX.
832 */
833 switch (token) {
834 case Opt_sec_none:
835 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
836 mnt->auth_flavor_len = 0;
837 mnt->auth_flavors[0] = RPC_AUTH_NULL;
838 break;
839 case Opt_sec_sys:
840 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
841 mnt->auth_flavor_len = 0;
842 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
843 break;
844 case Opt_sec_krb5:
845 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
846 mnt->auth_flavor_len = 1;
847 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
848 break;
849 case Opt_sec_krb5i:
850 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
851 mnt->auth_flavor_len = 1;
852 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
853 break;
854 case Opt_sec_krb5p:
855 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
856 mnt->auth_flavor_len = 1;
857 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
858 break;
859 case Opt_sec_lkey:
860 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
861 mnt->auth_flavor_len = 1;
862 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
863 break;
864 case Opt_sec_lkeyi:
865 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
866 mnt->auth_flavor_len = 1;
867 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
868 break;
869 case Opt_sec_lkeyp:
870 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
871 mnt->auth_flavor_len = 1;
872 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
873 break;
874 case Opt_sec_spkm:
875 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
876 mnt->auth_flavor_len = 1;
877 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
878 break;
879 case Opt_sec_spkmi:
880 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
881 mnt->auth_flavor_len = 1;
882 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
883 break;
884 case Opt_sec_spkmp:
885 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
886 mnt->auth_flavor_len = 1;
887 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
888 break;
889 default:
890 goto out_unrec_sec;
891 }
892 break;
893 case Opt_proto:
894 string = match_strdup(args);
895 if (string == NULL)
896 goto out_nomem;
897 token = match_token(string,
898 nfs_xprt_protocol_tokens, args);
899 kfree(string);
900
901 switch (token) {
902 case Opt_udp:
903 mnt->flags &= ~NFS_MOUNT_TCP;
904 mnt->nfs_server.protocol = IPPROTO_UDP;
905 mnt->timeo = 7;
906 mnt->retrans = 5;
907 break;
908 case Opt_tcp:
909 mnt->flags |= NFS_MOUNT_TCP;
910 mnt->nfs_server.protocol = IPPROTO_TCP;
911 mnt->timeo = 600;
912 mnt->retrans = 2;
913 break;
914 default:
915 goto out_unrec_xprt;
916 }
917 break;
918 case Opt_mountproto:
919 string = match_strdup(args);
920 if (string == NULL)
921 goto out_nomem;
922 token = match_token(string,
923 nfs_xprt_protocol_tokens, args);
924 kfree(string);
925
926 switch (token) {
927 case Opt_udp:
928 mnt->mount_server.protocol = IPPROTO_UDP;
929 break;
930 case Opt_tcp:
931 mnt->mount_server.protocol = IPPROTO_TCP;
932 break;
933 default:
934 goto out_unrec_xprt;
935 }
936 break;
937 case Opt_addr:
938 string = match_strdup(args);
939 if (string == NULL)
940 goto out_nomem;
941 mnt->nfs_server.address.sin_family = AF_INET;
942 mnt->nfs_server.address.sin_addr.s_addr =
943 in_aton(string);
944 kfree(string);
945 break;
946 case Opt_clientaddr:
947 string = match_strdup(args);
948 if (string == NULL)
949 goto out_nomem;
950 mnt->client_address = string;
951 break;
952 case Opt_mounthost:
953 string = match_strdup(args);
954 if (string == NULL)
955 goto out_nomem;
956 mnt->mount_server.address.sin_family = AF_INET;
957 mnt->mount_server.address.sin_addr.s_addr =
958 in_aton(string);
959 kfree(string);
960 break;
961
962 case Opt_userspace:
963 case Opt_deprecated:
964 break;
965
966 default:
967 goto out_unknown;
968 }
969 }
970
971 return 1;
972
973out_nomem:
974 printk(KERN_INFO "NFS: not enough memory to parse option\n");
975 return 0;
976
977out_unrec_vers:
978 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
979 return 0;
980
981out_unrec_xprt:
982 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
983 return 0;
984
985out_unrec_sec:
986 printk(KERN_INFO "NFS: unrecognized security flavor\n");
987 return 0;
988
989out_unknown:
990 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
991 return 0;
992}
993
994/*
467 * Validate the NFS2/NFS3 mount data 995 * Validate the NFS2/NFS3 mount data
468 * - fills in the mount root filehandle 996 * - fills in the mount root filehandle
469 */ 997 */