Re: [PATCH 08/13] NFS: Add functions to parse nfs mount options to fs/nfs/super.c
On Mon, May 21, 2007 at 12:09:54PM -0400, Chuck Lever wrote: For NFSv2 and NFSv3 mount options. Signed-off-by: Chuck Lever [EMAIL PROTECTED] +static int nfs_parse_options(char *raw, struct nfs_mount_args *mnt) +{ + char *p, *string; + + if (!raw) { + dprintk(NFS: mount options string was NULL.\n); + return 1; + } + + while ((p = strsep (raw, ,)) != NULL) { + substring_t args[MAX_OPT_ARGS]; + int option, token; + + if (!*p) + continue; + token = match_token(p, nfs_tokens, args); + + case Opt_context: + match_strcpy(mnt-nmd.context, args); + break; The userspace version (nfs-utils) of this code supports a quoted context strings. For example: context=aaa,bbb,ccc,hard It seems your code blindly parses a raw option string by ,. Karel -- Karel Zak [EMAIL PROTECTED] - To unsubscribe from this list: send the line unsubscribe linux-fsdevel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 08/13] NFS: Add functions to parse nfs mount options to fs/nfs/super.c
Karel Zak wrote: On Mon, May 21, 2007 at 12:09:54PM -0400, Chuck Lever wrote: For NFSv2 and NFSv3 mount options. Signed-off-by: Chuck Lever [EMAIL PROTECTED] +static int nfs_parse_options(char *raw, struct nfs_mount_args *mnt) +{ + char *p, *string; + + if (!raw) { + dprintk(NFS: mount options string was NULL.\n); + return 1; + } + + while ((p = strsep (raw, ,)) != NULL) { + substring_t args[MAX_OPT_ARGS]; + int option, token; + + if (!*p) + continue; + token = match_token(p, nfs_tokens, args); + + case Opt_context: + match_strcpy(mnt-nmd.context, args); + break; The userspace version (nfs-utils) of this code supports a quoted context strings. For example: context=aaa,bbb,ccc,hard It seems your code blindly parses a raw option string by ,. Karel- I've never used the context= option, and didn't find any documentation describing how it was used. Is there a clean example of how to use the in-kernel parser to handle quoted strings containing commas? begin:vcard fn:Chuck Lever n:Lever;Chuck org:Oracle Corporation;Corporate Architecture: Linux Projects Group adr:;;1015 Granger Avenue;Ann Arbor;MI;48104;USA title:Principal Member of Staff tel;work:+1 248 614 5091 x-mozilla-html:FALSE url:http://oss.oracle.com/~cel/ version:2.1 end:vcard
Re: [PATCH 08/13] NFS: Add functions to parse nfs mount options to fs/nfs/super.c
On Tue, May 29, 2007 at 05:08:01PM -0400, Chuck Lever wrote: Karel Zak wrote: On Mon, May 21, 2007 at 12:09:54PM -0400, Chuck Lever wrote: For NFSv2 and NFSv3 mount options. Signed-off-by: Chuck Lever [EMAIL PROTECTED] +static int nfs_parse_options(char *raw, struct nfs_mount_args *mnt) +{ + char *p, *string; + + if (!raw) { + dprintk(NFS: mount options string was NULL.\n); + return 1; + } + + while ((p = strsep (raw, ,)) != NULL) { + substring_t args[MAX_OPT_ARGS]; + int option, token; + + if (!*p) + continue; + token = match_token(p, nfs_tokens, args); + + case Opt_context: + match_strcpy(mnt-nmd.context, args); + break; The userspace version (nfs-utils) of this code supports a quoted context strings. For example: context=aaa,bbb,ccc,hard It seems your code blindly parses a raw option string by ,. Karel- I've never used the context= option, and didn't find any documentation describing how it was used. That's SELinux stuff. See original discussion: http://thread.gmane.org/gmane.linux.redhat.security.lspp/1002/focus=1004 There are also fscontext, defcontext and context for normal (non-NFS) mounts. See the mount.8 patch (where is basic docs): http://git.kernel.org/?p=utils/util-linux-ng/util-linux-ng.git;a=blobdiff;f=mount/mount.8;h=8ed5a11b77985c8da2dcac4602a67f8785a95070;hp=4692a42b3487b8e0db6dc0b7d17cfd214e8aefc8;hb=3a620ba4bffade41d81c429560c40bb65c9b81a7;hpb=6573c985a4077fa7d50ccb993bae177526fde8ec Is there a clean example of how to use the in-kernel parser to handle quoted strings containing commas? Not sure. It was introduced by [PATCH] SELinux: support mls categories for context mounts: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=3528a95322b5c1ce882ab723f175a1845430cd89 The SELinux specific options are extracted from mount options by the sb_copy_data hook (fs/super.c, vfs_kern_mount()) -- that's probably transparent for all filesystems, maybe for your NFS options too. (I didn't study it in detail.) Karel -- Karel Zak [EMAIL PROTECTED] - To unsubscribe from this list: send the line unsubscribe linux-fsdevel in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 08/13] NFS: Add functions to parse nfs mount options to fs/nfs/super.c
For NFSv2 and NFSv3 mount options. Signed-off-by: Chuck Lever [EMAIL PROTECTED] --- fs/nfs/super.c | 449 1 files changed, 449 insertions(+), 0 deletions(-) diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 1974648..a9f698b 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c @@ -514,6 +514,455 @@ static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags) shrink_submounts(vfsmnt, nfs_automount_list); } + +static match_table_t nfs_tokens = { + {Opt_userspace, bg}, + {Opt_userspace, fg}, + {Opt_soft, soft}, + {Opt_hard, hard}, + {Opt_intr, intr}, + {Opt_nointr, nointr}, + {Opt_posix, posix}, + {Opt_noposix, noposix}, + {Opt_cto, cto}, + {Opt_nocto, nocto}, + {Opt_ac, ac}, + {Opt_noac, noac}, + {Opt_lock, lock}, + {Opt_nolock, nolock}, + {Opt_v2, v2}, + {Opt_v3, v3}, + {Opt_udp, udp}, + {Opt_tcp, tcp}, + {Opt_acl, acl}, + {Opt_noacl, noacl}, + + {Opt_port, port=%u}, + {Opt_rsize, rsize=%u}, + {Opt_wsize, wsize=%u}, + {Opt_timeo, timeo=%u}, + {Opt_retrans, retrans=%u}, + {Opt_acregmin, acregmin=%u}, + {Opt_acregmax, acregmax=%u}, + {Opt_acdirmin, acdirmin=%u}, + {Opt_acdirmax, acdirmax=%u}, + {Opt_actimeo, actimeo=%u}, + {Opt_userspace, retry=%u}, + {Opt_namelen, namlen=%u}, + {Opt_mountport, mountport=%u}, + {Opt_mountprog, mountprog=%u}, + {Opt_mountvers, mountvers=%u}, + {Opt_nfsprog, nfsprog=%u}, + {Opt_nfsvers, nfsvers=%u}, + {Opt_nfsvers, vers=%u}, + + {Opt_sec, sec=%s}, + {Opt_proto, proto=%s}, + {Opt_addr, addr=%s}, + {Opt_mounthost, mounthost=%s}, + {Opt_context, context=%s}, + + {Opt_err, NULL}, +}; + +static int nfs_parse_options(char *raw, struct nfs_mount_args *mnt) +{ + char *p, *string; + + if (!raw) { + dprintk(NFS: mount options string was NULL.\n); + return 1; + } + + while ((p = strsep (raw, ,)) != NULL) { + substring_t args[MAX_OPT_ARGS]; + int option, token; + + if (!*p) + continue; + token = match_token(p, nfs_tokens, args); + + dprintk(NFS: nfs mount option '%s': parsing token %d\n, + p, token); + + switch (token) { + case Opt_soft: + mnt-nmd.flags |= NFS_MOUNT_SOFT; + break; + case Opt_hard: + mnt-nmd.flags = ~NFS_MOUNT_SOFT; + break; + case Opt_intr: + mnt-nmd.flags |= NFS_MOUNT_INTR; + break; + case Opt_nointr: + mnt-nmd.flags = ~NFS_MOUNT_INTR; + break; + case Opt_posix: + mnt-nmd.flags |= NFS_MOUNT_POSIX; + break; + case Opt_noposix: + mnt-nmd.flags = ~NFS_MOUNT_POSIX; + break; + case Opt_cto: + mnt-nmd.flags = ~NFS_MOUNT_NOCTO; + break; + case Opt_nocto: + mnt-nmd.flags |= NFS_MOUNT_NOCTO; + break; + case Opt_ac: + mnt-nmd.flags = ~NFS_MOUNT_NOAC; + break; + case Opt_noac: + mnt-nmd.flags |= NFS_MOUNT_NOAC; + break; + case Opt_lock: + mnt-nmd.flags = ~NFS_MOUNT_NONLM; + break; + case Opt_nolock: + mnt-nmd.flags |= NFS_MOUNT_NONLM; + break; + case Opt_v2: + mnt-nmd.flags = ~NFS_MOUNT_VER3; + break; + case Opt_v3: + mnt-nmd.flags |= NFS_MOUNT_VER3; + break; + case Opt_udp: + mnt-nmd.flags = ~NFS_MOUNT_TCP; + break; + case Opt_tcp: + mnt-nmd.flags |= NFS_MOUNT_TCP; + break; + case Opt_acl: + mnt-nmd.flags = ~NFS_MOUNT_NOACL; + break; + case Opt_noacl: + mnt-nmd.flags |= NFS_MOUNT_NOACL; + break; + + case Opt_port: + if (match_int(args, option)) + return 0; + if (option 0 || option 65535) + return 0; + mnt-nmd.addr.sin_port = htonl(option); + break; + case Opt_rsize: +