Commit e04dc423 authored by Al Viro's avatar Al Viro

shmem_parse_options(): take handling a single option into a helper

mechanical move.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent f6490b7f
...@@ -3363,40 +3363,13 @@ static const struct export_operations shmem_export_ops = { ...@@ -3363,40 +3363,13 @@ static const struct export_operations shmem_export_ops = {
.fh_to_dentry = shmem_fh_to_dentry, .fh_to_dentry = shmem_fh_to_dentry,
}; };
static int shmem_parse_options(char *options, struct shmem_options *ctx) static int shmem_parse_one(struct shmem_options *ctx, char *opt, char *value)
{ {
char *this_char, *value, *rest; char *rest;
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
while (options != NULL) { if (!strcmp(opt, "size")) {
this_char = options;
for (;;) {
/*
* NUL-terminate this option: unfortunately,
* mount options form a comma-separated list,
* but mpol's nodelist may also contain commas.
*/
options = strchr(options, ',');
if (options == NULL)
break;
options++;
if (!isdigit(*options)) {
options[-1] = '\0';
break;
}
}
if (!*this_char)
continue;
if ((value = strchr(this_char,'=')) != NULL) {
*value++ = 0;
} else {
pr_err("tmpfs: No value for mount option '%s'\n",
this_char);
goto error;
}
if (!strcmp(this_char,"size")) {
unsigned long long size; unsigned long long size;
size = memparse(value,&rest); size = memparse(value,&rest);
if (*rest == '%') { if (*rest == '%') {
...@@ -3409,28 +3382,28 @@ static int shmem_parse_options(char *options, struct shmem_options *ctx) ...@@ -3409,28 +3382,28 @@ static int shmem_parse_options(char *options, struct shmem_options *ctx)
goto bad_val; goto bad_val;
ctx->blocks = DIV_ROUND_UP(size, PAGE_SIZE); ctx->blocks = DIV_ROUND_UP(size, PAGE_SIZE);
ctx->seen |= SHMEM_SEEN_BLOCKS; ctx->seen |= SHMEM_SEEN_BLOCKS;
} else if (!strcmp(this_char,"nr_blocks")) { } else if (!strcmp(opt, "nr_blocks")) {
ctx->blocks = memparse(value, &rest); ctx->blocks = memparse(value, &rest);
if (*rest) if (*rest)
goto bad_val; goto bad_val;
ctx->seen |= SHMEM_SEEN_BLOCKS; ctx->seen |= SHMEM_SEEN_BLOCKS;
} else if (!strcmp(this_char,"nr_inodes")) { } else if (!strcmp(opt, "nr_inodes")) {
ctx->inodes = memparse(value, &rest); ctx->inodes = memparse(value, &rest);
if (*rest) if (*rest)
goto bad_val; goto bad_val;
ctx->seen |= SHMEM_SEEN_INODES; ctx->seen |= SHMEM_SEEN_INODES;
} else if (!strcmp(this_char,"mode")) { } else if (!strcmp(opt, "mode")) {
ctx->mode = simple_strtoul(value, &rest, 8) & 07777; ctx->mode = simple_strtoul(value, &rest, 8) & 07777;
if (*rest) if (*rest)
goto bad_val; goto bad_val;
} else if (!strcmp(this_char,"uid")) { } else if (!strcmp(opt, "uid")) {
uid = simple_strtoul(value, &rest, 0); uid = simple_strtoul(value, &rest, 0);
if (*rest) if (*rest)
goto bad_val; goto bad_val;
ctx->uid = make_kuid(current_user_ns(), uid); ctx->uid = make_kuid(current_user_ns(), uid);
if (!uid_valid(ctx->uid)) if (!uid_valid(ctx->uid))
goto bad_val; goto bad_val;
} else if (!strcmp(this_char,"gid")) { } else if (!strcmp(opt, "gid")) {
gid = simple_strtoul(value, &rest, 0); gid = simple_strtoul(value, &rest, 0);
if (*rest) if (*rest)
goto bad_val; goto bad_val;
...@@ -3438,7 +3411,7 @@ static int shmem_parse_options(char *options, struct shmem_options *ctx) ...@@ -3438,7 +3411,7 @@ static int shmem_parse_options(char *options, struct shmem_options *ctx)
if (!gid_valid(ctx->gid)) if (!gid_valid(ctx->gid))
goto bad_val; goto bad_val;
#ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE #ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE
} else if (!strcmp(this_char, "huge")) { } else if (!strcmp(opt, "huge")) {
int huge; int huge;
huge = shmem_parse_huge(value); huge = shmem_parse_huge(value);
if (huge < 0) if (huge < 0)
...@@ -3450,22 +3423,59 @@ static int shmem_parse_options(char *options, struct shmem_options *ctx) ...@@ -3450,22 +3423,59 @@ static int shmem_parse_options(char *options, struct shmem_options *ctx)
ctx->seen |= SHMEM_SEEN_HUGE; ctx->seen |= SHMEM_SEEN_HUGE;
#endif #endif
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
} else if (!strcmp(this_char,"mpol")) { } else if (!strcmp(opt, "mpol")) {
mpol_put(ctx->mpol); mpol_put(ctx->mpol);
ctx->mpol = NULL; ctx->mpol = NULL;
if (mpol_parse_str(value, &ctx->mpol)) if (mpol_parse_str(value, &ctx->mpol))
goto bad_val; goto bad_val;
#endif #endif
} else { } else {
pr_err("tmpfs: Bad mount option %s\n", this_char); pr_err("tmpfs: Bad mount option %s\n", opt);
goto error; return -EINVAL;
}
} }
return 0; return 0;
bad_val: bad_val:
pr_err("tmpfs: Bad value '%s' for mount option '%s'\n", pr_err("tmpfs: Bad value '%s' for mount option '%s'\n",
value, this_char); value, opt);
return -EINVAL;
}
static int shmem_parse_options(char *options, struct shmem_options *ctx)
{
char *this_char, *value;
while (options != NULL) {
this_char = options;
for (;;) {
/*
* NUL-terminate this option: unfortunately,
* mount options form a comma-separated list,
* but mpol's nodelist may also contain commas.
*/
options = strchr(options, ',');
if (options == NULL)
break;
options++;
if (!isdigit(*options)) {
options[-1] = '\0';
break;
}
}
if (!*this_char)
continue;
if ((value = strchr(this_char,'=')) != NULL) {
*value++ = 0;
} else {
pr_err("tmpfs: No value for mount option '%s'\n",
this_char);
goto error;
}
if (shmem_parse_one(ctx, this_char, value) < 0)
goto error;
}
return 0;
error: error:
mpol_put(ctx->mpol); mpol_put(ctx->mpol);
ctx->mpol = NULL; ctx->mpol = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment