summaryrefslogtreecommitdiff
path: root/source3/modules/onefs_config.c
blob: 8b34d7cd4548d877afb9b2a16266f5165cfbb715 (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
 * Unix SMB/CIFS implementation.
 * Support for OneFS
 *
 * Copyright (C) Todd Stecher, 2009
 * Copyright (C) Tim Prouty, 2009
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "includes.h"
#include "smbd/smbd.h"
#include "onefs_config.h"

#include <ifs/ifs_syscalls.h>

#define ONEFS_DATA_FASTBUF	10

struct onefs_vfs_share_config vfs_share_config[ONEFS_DATA_FASTBUF];
struct onefs_vfs_share_config *pvfs_share_config;

static void onefs_load_faketimestamp_config(struct connection_struct *conn,
					    struct onefs_vfs_share_config *cfg)
{
	const char **parm;
	int snum = SNUM(conn);

	parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_ATIME_NOW,
				   PARM_ATIME_NOW_DEFAULT);

	if (parm) {
		cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
		set_namearray(&cfg->atime_now_list,*parm);
	}

	parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_CTIME_NOW,
				   PARM_CTIME_NOW_DEFAULT);

	if (parm) {
		cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
		set_namearray(&cfg->ctime_now_list,*parm);
	}

	parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_MTIME_NOW,
				   PARM_MTIME_NOW_DEFAULT);

	if (parm) {
		cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
		set_namearray(&cfg->mtime_now_list,*parm);
	}

	parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_ATIME_STATIC,
				   PARM_ATIME_STATIC_DEFAULT);

	if (parm) {
		cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
		set_namearray(&cfg->atime_static_list,*parm);
	}

	parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_MTIME_STATIC,
				   PARM_MTIME_STATIC_DEFAULT);

	if (parm) {
		cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
		set_namearray(&cfg->mtime_static_list,*parm);
	}

	cfg->atime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_ATIME_SLOP,
				      PARM_ATIME_SLOP_DEFAULT);
	cfg->ctime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_CTIME_SLOP,
				      PARM_CTIME_SLOP_DEFAULT);
	cfg->mtime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_MTIME_SLOP,
				      PARM_MTIME_SLOP_DEFAULT);
}

/**
 * Set onefs-specific vfs global config parameters.
 *
 * Since changes in these parameters require calling syscalls, we only want to
 * call them when the configuration actually changes.
 */
static void onefs_load_global_config(connection_struct *conn)
{
	static struct onefs_vfs_global_config global_config;
	bool dot_snap_child_accessible;
	bool dot_snap_child_visible;
	bool dot_snap_root_accessible;
	bool dot_snap_root_visible;
	bool dot_snap_tilde;
	bool reconfig_dso = false;
	bool reconfig_tilde = false;

	/* Check if this is the first time setting the config options. */
	if (!(global_config.init_flags & ONEFS_VFS_CONFIG_INITIALIZED)) {
		global_config.init_flags |= ONEFS_VFS_CONFIG_INITIALIZED;

		/* Set process encoding */
		onefs_sys_config_enc();

		reconfig_dso = true;
		reconfig_tilde = true;
	}

	/* Get the dot snap options from the conf. */
	dot_snap_child_accessible =
	    lp_parm_bool(SNUM(conn), PARM_ONEFS_TYPE,
			 PARM_DOT_SNAP_CHILD_ACCESSIBLE,
			 PARM_DOT_SNAP_CHILD_ACCESSIBLE_DEFAULT);
	dot_snap_child_visible =
	    lp_parm_bool(SNUM(conn), PARM_ONEFS_TYPE,
			 PARM_DOT_SNAP_CHILD_VISIBLE,
			 PARM_DOT_SNAP_CHILD_VISIBLE_DEFAULT);
	dot_snap_root_accessible =
	    lp_parm_bool(SNUM(conn), PARM_ONEFS_TYPE,
			 PARM_DOT_SNAP_ROOT_ACCESSIBLE,
			 PARM_DOT_SNAP_ROOT_ACCESSIBLE_DEFAULT);
	dot_snap_root_visible =
	    lp_parm_bool(SNUM(conn), PARM_ONEFS_TYPE,
			 PARM_DOT_SNAP_ROOT_VISIBLE,
			 PARM_DOT_SNAP_ROOT_VISIBLE_DEFAULT);
	dot_snap_tilde =
	    lp_parm_bool(SNUM(conn), PARM_ONEFS_TYPE,
			 PARM_DOT_SNAP_TILDE,
			 PARM_DOT_SNAP_TILDE_DEFAULT);

	/* Check if any of the dot snap options need updating. */
	if (dot_snap_child_accessible !=
	    global_config.dot_snap_child_accessible) {
		global_config.dot_snap_child_accessible =
		    dot_snap_child_accessible;
		reconfig_dso = true;
	}
	if (dot_snap_child_visible !=
	    global_config.dot_snap_child_visible) {
		global_config.dot_snap_child_visible =
		    dot_snap_child_visible;
		reconfig_dso = true;
	}
	if (dot_snap_root_accessible !=
	    global_config.dot_snap_root_accessible) {
		global_config.dot_snap_root_accessible =
		    dot_snap_root_accessible;
		reconfig_dso = true;
	}
	if (dot_snap_root_visible !=
	    global_config.dot_snap_root_visible) {
		global_config.dot_snap_root_visible =
		    dot_snap_root_visible;
		reconfig_dso = true;
	}
	if (dot_snap_tilde != global_config.dot_snap_tilde) {
		global_config.dot_snap_tilde = dot_snap_tilde;
		reconfig_tilde = true;
	}

	/* If a dot snap option has changed update the process.  */
	if (reconfig_dso) {
		onefs_sys_config_snap_opt(&global_config);
	}

	/* If the dot snap tilde option has changed update the process.  */
	if (reconfig_tilde) {
		onefs_sys_config_tilde(&global_config);
	}
}

int onefs_load_config(connection_struct *conn)
{
	int snum = SNUM(conn);
	int share_count = lp_numservices();

	/* Share config */
	if (!pvfs_share_config) {

		if (share_count <= ONEFS_DATA_FASTBUF)
			pvfs_share_config = vfs_share_config;
		else {
			pvfs_share_config =
			    SMB_MALLOC_ARRAY(struct onefs_vfs_share_config,
					     share_count);
			if (!pvfs_share_config) {
				errno = ENOMEM;
				return -1;
			}

			memset(pvfs_share_config, 0,
			    (sizeof(struct onefs_vfs_share_config) *
				    share_count));
		}
	}

	if ((pvfs_share_config[snum].init_flags &
		ONEFS_VFS_CONFIG_INITIALIZED) == 0) {
			pvfs_share_config[snum].init_flags =
			    ONEFS_VFS_CONFIG_INITIALIZED;
			onefs_load_faketimestamp_config(conn,
						        &pvfs_share_config[snum]);
	}

	/* Global config */
	onefs_load_global_config(conn);

	return 0;
}

bool onefs_get_config(int snum, int config_type,
		      struct onefs_vfs_share_config *cfg)
{
	if ((pvfs_share_config != NULL) &&
	    (pvfs_share_config[snum].init_flags & config_type))
		*cfg = pvfs_share_config[snum];
	else
		return false;

	return true;
}


/**
 * Set the per-process encoding, ignoring errors.
 */
void onefs_sys_config_enc(void)
{
	int ret;

	ret = enc_set_proc(ENC_UTF8);
	if (ret) {
		DEBUG(0, ("Setting process encoding failed: %s\n",
			strerror(errno)));
	}
}

/**
 * Set the per-process .snpashot directory options, ignoring errors.
 */
void onefs_sys_config_snap_opt(struct onefs_vfs_global_config *global_config)
{
	struct ifs_dotsnap_options dso;
	int ret;

	dso.per_proc = 1;
	dso.sub_accessible = global_config->dot_snap_child_accessible;
	dso.sub_visible = global_config->dot_snap_child_visible;
	dso.root_accessible = global_config->dot_snap_root_accessible;
	dso.root_visible = global_config->dot_snap_root_visible;

	ret = ifs_set_dotsnap_options(&dso);
	if (ret) {
		DEBUG(0, ("Setting snapshot visibility/accessibility "
			"failed: %s\n", strerror(errno)));
	}
}

/**
 * Set the per-process flag saying whether or not to accept ~snapshot
 * as an alternative name for .snapshot directories.
 */
void onefs_sys_config_tilde(struct onefs_vfs_global_config *global_config)
{
	int ret;

	ret = ifs_tilde_snapshot(global_config->dot_snap_tilde);
	if (ret) {
		DEBUG(0, ("Setting snapshot tilde failed: %s\n",
			strerror(errno)));
	}
}