From: Glauber Costa Subject: [RFC 1/5] Accept per-mntpoint named options Date: Mon, 25 Jul 2011 19:16:40 +0400 Message-ID: <1311607004-15434-2-git-send-email-glommer@parallels.com> References: <1311607004-15434-1-git-send-email-glommer@parallels.com> Cc: Pavel Emelyanov , Al Viro , Hugh Dickins , Nick Piggin , Andrea Arcangeli , Rik van Riel , Dave Hansen , David Chinner , Glauber Costa To: linux-fsdevel@vger.kernel.org Return-path: Received: from mailhub.sw.ru ([195.214.232.25]:9996 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751351Ab1GYPSZ (ORCPT ); Mon, 25 Jul 2011 11:18:25 -0400 In-Reply-To: <1311607004-15434-1-git-send-email-glommer@parallels.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: This is the core patch of the proposed interface. It basically consists of an option parser much like the one some filesystems, like for instance the ext family, ships. It does, however, have two fundamental differences: * Since it is generic, it does not operate on a super block. Rather, a mountpoint, which is a file-system independent entity, is its argument. Per-mntpoint options are expected to be tweaked here. * It modifies the option string to remove whatever option it handled. This allow us to chain this parser with whatever parser the underlying filesystem may have. Its first option is vfs_dcache_size. It specifies how many dentries are allowed to exist at any given time in the dentry group that lives in this mount point. --- fs/namespace.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mount.h | 2 + 2 files changed, 67 insertions(+), 0 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index dffe6f4..3ccd264 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "pnode.h" #include "internal.h" @@ -2190,6 +2191,70 @@ int copy_mount_string(const void __user *data, char **where) return 0; } +static const match_table_t tokens = { + {1, "vfs_dcache_size=%u"}, +}; + +int vfs_parse_options(char *options, struct vfsmount *mnt) +{ + substring_t args[MAX_OPT_ARGS]; + unsigned int option; + char *p; + char *opt; + char *start = NULL; + + /* FIXME: remove options from original string */ + if (!options) + return 1; + + opt = kstrdup(options, GFP_KERNEL); + if (!opt) + return 0; + + start = opt; + + while ((p = strsep(&opt, ",")) != NULL) { + int token; + if (!*p) + continue; + + /* + * Initialize args struct so we know whether arg was + * found; some options take optional arguments. + */ + args[0].to = args[0].from = 0; + token = match_token(p, tokens, args); + switch (token) { + case 1: + if (args[0].from) { + if (match_int(&args[0], &option)) { + break; + } + else { + mnt->dcache_size = option; + } + } + else { + printk("did not give an option\n"); + break; + } + + if (!opt) /* it is the last option listed */ + *(options + (p - start)) = '\0'; + else + strcpy(options + (p - start), opt); + break; + default: + break; + } + } + kfree(start); + + return 0; +} + + + /* * Flags is a 32-bit value that allows up to 31 non-fs dependent flags to * be given to the mount() call (ie: read-only, no-dev, no-suid etc). diff --git a/include/linux/mount.h b/include/linux/mount.h index 604f122..cf50da2 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -86,6 +86,8 @@ struct vfsmount { int mnt_expiry_mark; /* true if marked for expiry */ int mnt_pinned; int mnt_ghosts; + + unsigned int dcache_size; }; struct file; /* forward dec */ -- 1.7.5.1