aboutsummaryrefslogtreecommitdiff
path: root/fs/gfs2/mount.c
blob: 3e42697aafc74d2acc6a2f3ac3dc863857a1579f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
 * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU General Public License v.2.
 */

#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/completion.h>
#include <linux/buffer_head.h>
#include <asm/semaphore.h>

#include "gfs2.h"
#include "mount.h"
#include "sys.h"

/**
 * gfs2_mount_args - Parse mount options
 * @sdp:
 * @data:
 *
 * Return: errno
 */

int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
{
	struct gfs2_args *args = &sdp->sd_args;
	char *data = data_arg;
	char *options, *o, *v;
	int error = 0;

	if (!remount) {
		/*  If someone preloaded options, use those instead  */
		spin_lock(&gfs2_sys_margs_lock);
		if (gfs2_sys_margs) {
			data = gfs2_sys_margs;
			gfs2_sys_margs = NULL;
		}
		spin_unlock(&gfs2_sys_margs_lock);

		/*  Set some defaults  */
		args->ar_num_glockd = GFS2_GLOCKD_DEFAULT;
		args->ar_quota = GFS2_QUOTA_DEFAULT;
		args->ar_data = GFS2_DATA_DEFAULT;
	}

	/* Split the options into tokens with the "," character and
	   process them */

	for (options = data; (o = strsep(&options, ",")); ) {
		if (!*o)
			continue;

		v = strchr(o, '=');
		if (v)
			*v++ = 0;

		if (!strcmp(o, "lockproto")) {
			if (!v)
				goto need_value;
			if (remount && strcmp(v, args->ar_lockproto))
				goto cant_remount;
			strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
			args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
		}

		else if (!strcmp(o, "locktable")) {
			if (!v)
				goto need_value;
			if (remount && strcmp(v, args->ar_locktable))
				goto cant_remount;
			strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
			args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
		}

		else if (!strcmp(o, "hostdata")) {
			if (!v)
				goto need_value;
			if (remount && strcmp(v, args->ar_hostdata))
				goto cant_remount;
			strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
			args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
		}

		else if (!strcmp(o, "spectator")) {
			if (remount && !args->ar_spectator)
				goto cant_remount;
			args->ar_spectator = 1;
			sdp->sd_vfs->s_flags |= MS_RDONLY;
		}

		else if (!strcmp(o, "ignore_local_fs")) {
			if (remount && !args->ar_ignore_local_fs)
				goto cant_remount;
			args->ar_ignore_local_fs = 1;
		}

		else if (!strcmp(o, "localflocks")) {
			if (remount && !args->ar_localflocks)
				goto cant_remount;
			args->ar_localflocks = 1;
		}

		else if (!strcmp(o, "localcaching")) {
			if (remount && !args->ar_localcaching)
				goto cant_remount;
			args->ar_localcaching = 1;
		}

		else if (!strcmp(o, "debug"))
			args->ar_debug = 1;

		else if (!strcmp(o, "nodebug"))
			args->ar_debug = 0;

		else if (!strcmp(o, "upgrade")) {
			if (remount && !args->ar_upgrade)
				goto cant_remount;
			args->ar_upgrade = 1;
		}

		else if (!strcmp(o, "num_glockd")) {
			unsigned int x;
			if (!v)
				goto need_value;
			sscanf(v, "%u", &x);
			if (remount && x != args->ar_num_glockd)
				goto cant_remount;
			if (!x || x > GFS2_GLOCKD_MAX) {
				fs_info(sdp, "0 < num_glockd <= %u  (not %u)\n",
				        GFS2_GLOCKD_MAX, x);
				error = -EINVAL;
				break;
			}
			args->ar_num_glockd = x;
		}

		else if (!strcmp(o, "acl")) {
			args->ar_posix_acl = 1;
			sdp->sd_vfs->s_flags |= MS_POSIXACL;
		}

		else if (!strcmp(o, "noacl")) {
			args->ar_posix_acl = 0;
			sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
		}

		else if (!strcmp(o, "quota")) {
			if (!v)
				goto need_value;
			if (!strcmp(v, "off"))
				args->ar_quota = GFS2_QUOTA_OFF;
			else if (!strcmp(v, "account"))
				args->ar_quota = GFS2_QUOTA_ACCOUNT;
			else if (!strcmp(v, "on"))
				args->ar_quota = GFS2_QUOTA_ON;
			else {
				fs_info(sdp, "invalid value for quota\n");
				error = -EINVAL;
				break;
			}
		}

		else if (!strcmp(o, "suiddir"))
			args->ar_suiddir = 1;

		else if (!strcmp(o, "nosuiddir"))
			args->ar_suiddir = 0;

		else if (!strcmp(o, "data")) {
			if (!v)
				goto need_value;
			if (!strcmp(v, "writeback"))
				args->ar_data = GFS2_DATA_WRITEBACK;
			else if (!strcmp(v, "ordered"))
				args->ar_data = GFS2_DATA_ORDERED;
			else {
				fs_info(sdp, "invalid value for data\n");
				error = -EINVAL;
				break;
			}
		}

		else {
			fs_info(sdp, "unknown option: %s\n", o);
			error = -EINVAL;
			break;
		}
	}

	if (error)
		fs_info(sdp, "invalid mount option(s)\n");

	if (data != data_arg)
		kfree(data);

	return error;

 need_value:
	fs_info(sdp, "need value for option %s\n", o);
	return -EINVAL;

 cant_remount:
	fs_info(sdp, "can't remount with option %s\n", o);
	return -EINVAL;
}