xref: /linux/fs/orangefs/super.c (revision 7ed37e9d5c05bf3dc74146572d89e7391091e1a4)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * (C) 2001 Clemson University and The University of Chicago
4  *
5  * See COPYING in top-level directory.
6  */
7 
8 #include "protocol.h"
9 #include "orangefs-kernel.h"
10 #include "orangefs-bufmap.h"
11 
12 #include <linux/hashtable.h>
13 #include <linux/seq_file.h>
14 
15 /* a cache for orangefs-inode objects (i.e. orangefs inode private data) */
16 static struct kmem_cache *orangefs_inode_cache;
17 
18 /* list for storing orangefs specific superblocks in use */
19 LIST_HEAD(orangefs_superblocks);
20 
21 DEFINE_SPINLOCK(orangefs_superblocks_lock);
22 
23 enum {
24 	Opt_acl,
25 	Opt_intr,
26 	Opt_local_lock,
27 };
28 
29 const struct fs_parameter_spec orangefs_fs_param_spec[] = {
30 	fsparam_flag	("acl",			Opt_acl),
31 	fsparam_flag	("intr",		Opt_intr),
32 	fsparam_flag	("local_lock",		Opt_local_lock),
33 	{}
34 };
35 
36 uint64_t orangefs_features;
37 
orangefs_show_options(struct seq_file * m,struct dentry * root)38 static int orangefs_show_options(struct seq_file *m, struct dentry *root)
39 {
40 	struct orangefs_sb_info_s *orangefs_sb = ORANGEFS_SB(root->d_sb);
41 
42 	if (root->d_sb->s_flags & SB_POSIXACL)
43 		seq_puts(m, ",acl");
44 	if (orangefs_sb->flags & ORANGEFS_OPT_INTR)
45 		seq_puts(m, ",intr");
46 	if (orangefs_sb->flags & ORANGEFS_OPT_LOCAL_LOCK)
47 		seq_puts(m, ",local_lock");
48 	return 0;
49 }
50 
orangefs_parse_param(struct fs_context * fc,struct fs_parameter * param)51 static int orangefs_parse_param(struct fs_context *fc,
52 		struct fs_parameter *param)
53 {
54 	struct orangefs_sb_info_s *orangefs_sb = fc->s_fs_info;
55 	struct fs_parse_result result;
56 	int opt;
57 
58 	opt = fs_parse(fc, orangefs_fs_param_spec, param, &result);
59 	if (opt < 0)
60 		return opt;
61 
62 	switch (opt) {
63 	case Opt_acl:
64 		fc->sb_flags |= SB_POSIXACL;
65 		break;
66 	case Opt_intr:
67 		orangefs_sb->flags |= ORANGEFS_OPT_INTR;
68 		break;
69 	case Opt_local_lock:
70 		orangefs_sb->flags |= ORANGEFS_OPT_LOCAL_LOCK;
71 		break;
72 	}
73 
74 	return 0;
75 }
76 
orangefs_inode_cache_ctor(void * req)77 static void orangefs_inode_cache_ctor(void *req)
78 {
79 	struct orangefs_inode_s *orangefs_inode = req;
80 
81 	inode_init_once(&orangefs_inode->vfs_inode);
82 	init_rwsem(&orangefs_inode->xattr_sem);
83 }
84 
orangefs_alloc_inode(struct super_block * sb)85 static struct inode *orangefs_alloc_inode(struct super_block *sb)
86 {
87 	struct orangefs_inode_s *orangefs_inode;
88 
89 	orangefs_inode = alloc_inode_sb(sb, orangefs_inode_cache, GFP_KERNEL);
90 	if (!orangefs_inode)
91 		return NULL;
92 
93 	/*
94 	 * We want to clear everything except for rw_semaphore and the
95 	 * vfs_inode.
96 	 */
97 	memset(&orangefs_inode->refn.khandle, 0, 16);
98 	orangefs_inode->refn.fs_id = ORANGEFS_FS_ID_NULL;
99 	orangefs_inode->last_failed_block_index_read = 0;
100 	memset(orangefs_inode->link_target, 0, sizeof(orangefs_inode->link_target));
101 
102 	gossip_debug(GOSSIP_SUPER_DEBUG,
103 		     "orangefs_alloc_inode: allocated %p\n",
104 		     &orangefs_inode->vfs_inode);
105 	return &orangefs_inode->vfs_inode;
106 }
107 
orangefs_free_inode(struct inode * inode)108 static void orangefs_free_inode(struct inode *inode)
109 {
110 	struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
111 	struct orangefs_cached_xattr *cx;
112 	struct hlist_node *tmp;
113 	int i;
114 
115 	hash_for_each_safe(orangefs_inode->xattr_cache, i, tmp, cx, node) {
116 		hlist_del(&cx->node);
117 		kfree(cx);
118 	}
119 
120 	kmem_cache_free(orangefs_inode_cache, orangefs_inode);
121 }
122 
orangefs_destroy_inode(struct inode * inode)123 static void orangefs_destroy_inode(struct inode *inode)
124 {
125 	struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
126 
127 	gossip_debug(GOSSIP_SUPER_DEBUG,
128 			"%s: deallocated %p destroying inode %pU\n",
129 			__func__, orangefs_inode, get_khandle_from_ino(inode));
130 }
131 
orangefs_write_inode(struct inode * inode,struct writeback_control * wbc)132 static int orangefs_write_inode(struct inode *inode,
133 				struct writeback_control *wbc)
134 {
135 	gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_write_inode\n");
136 	return orangefs_inode_setattr(inode);
137 }
138 
139 /*
140  * NOTE: information filled in here is typically reflected in the
141  * output of the system command 'df'
142 */
orangefs_statfs(struct dentry * dentry,struct kstatfs * buf)143 static int orangefs_statfs(struct dentry *dentry, struct kstatfs *buf)
144 {
145 	int ret = -ENOMEM;
146 	struct orangefs_kernel_op_s *new_op = NULL;
147 	int flags = 0;
148 	struct super_block *sb = NULL;
149 
150 	sb = dentry->d_sb;
151 
152 	gossip_debug(GOSSIP_SUPER_DEBUG,
153 			"%s: called on sb %p (fs_id is %d)\n",
154 			__func__,
155 			sb,
156 			(int)(ORANGEFS_SB(sb)->fs_id));
157 
158 	new_op = op_alloc(ORANGEFS_VFS_OP_STATFS);
159 	if (!new_op)
160 		return ret;
161 	new_op->upcall.req.statfs.fs_id = ORANGEFS_SB(sb)->fs_id;
162 
163 	if (ORANGEFS_SB(sb)->flags & ORANGEFS_OPT_INTR)
164 		flags = ORANGEFS_OP_INTERRUPTIBLE;
165 
166 	ret = service_operation(new_op, "orangefs_statfs", flags);
167 
168 	if (new_op->downcall.status < 0)
169 		goto out_op_release;
170 
171 	gossip_debug(GOSSIP_SUPER_DEBUG,
172 		     "%s: got %ld blocks available | "
173 		     "%ld blocks total | %ld block size | "
174 		     "%ld files total | %ld files avail\n",
175 		     __func__,
176 		     (long)new_op->downcall.resp.statfs.blocks_avail,
177 		     (long)new_op->downcall.resp.statfs.blocks_total,
178 		     (long)new_op->downcall.resp.statfs.block_size,
179 		     (long)new_op->downcall.resp.statfs.files_total,
180 		     (long)new_op->downcall.resp.statfs.files_avail);
181 
182 	buf->f_type = sb->s_magic;
183 	buf->f_fsid.val[0] = ORANGEFS_SB(sb)->fs_id;
184 	buf->f_fsid.val[1] = ORANGEFS_SB(sb)->id;
185 	buf->f_bsize = new_op->downcall.resp.statfs.block_size;
186 	buf->f_namelen = ORANGEFS_NAME_MAX;
187 
188 	buf->f_blocks = (sector_t) new_op->downcall.resp.statfs.blocks_total;
189 	buf->f_bfree = (sector_t) new_op->downcall.resp.statfs.blocks_avail;
190 	buf->f_bavail = (sector_t) new_op->downcall.resp.statfs.blocks_avail;
191 	buf->f_files = (sector_t) new_op->downcall.resp.statfs.files_total;
192 	buf->f_ffree = (sector_t) new_op->downcall.resp.statfs.files_avail;
193 	buf->f_frsize = 0;
194 
195 out_op_release:
196 	op_release(new_op);
197 	gossip_debug(GOSSIP_SUPER_DEBUG, "%s: returning %d\n", __func__, ret);
198 	return ret;
199 }
200 
201 /*
202  * Remount as initiated by VFS layer.  We just need to reparse the mount
203  * options, no need to signal pvfs2-client-core about it.
204  */
orangefs_reconfigure(struct fs_context * fc)205 static int orangefs_reconfigure(struct fs_context *fc)
206 {
207 	struct super_block *sb = fc->root->d_sb;
208 	struct orangefs_sb_info_s *orangefs_sb = ORANGEFS_SB(sb);
209 	struct orangefs_sb_info_s *revised = fc->s_fs_info;
210 	unsigned int flags;
211 
212 	flags = orangefs_sb->flags;
213 	flags &= ~(ORANGEFS_OPT_INTR | ORANGEFS_OPT_LOCAL_LOCK);
214 	flags |= revised->flags;
215 	WRITE_ONCE(orangefs_sb->flags, flags);
216 
217 	gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_reconfigure: called\n");
218 	return 0;
219 }
220 
221 /*
222  * Remount as initiated by pvfs2-client-core on restart.  This is used to
223  * repopulate mount information left from previous pvfs2-client-core.
224  *
225  * the idea here is that given a valid superblock, we're
226  * re-initializing the user space client with the initial mount
227  * information specified when the super block was first initialized.
228  * this is very different than the first initialization/creation of a
229  * superblock.  we use the special service_priority_operation to make
230  * sure that the mount gets ahead of any other pending operation that
231  * is waiting for servicing.  this means that the pvfs2-client won't
232  * fail to start several times for all other pending operations before
233  * the client regains all of the mount information from us.
234  * NOTE: this function assumes that the request_mutex is already acquired!
235  */
orangefs_remount(struct orangefs_sb_info_s * orangefs_sb)236 int orangefs_remount(struct orangefs_sb_info_s *orangefs_sb)
237 {
238 	struct orangefs_kernel_op_s *new_op;
239 	int ret = -EINVAL;
240 
241 	gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_remount: called\n");
242 
243 	new_op = op_alloc(ORANGEFS_VFS_OP_FS_MOUNT);
244 	if (!new_op)
245 		return -ENOMEM;
246 	strscpy(new_op->upcall.req.fs_mount.orangefs_config_server,
247 		orangefs_sb->devname);
248 
249 	gossip_debug(GOSSIP_SUPER_DEBUG,
250 		     "Attempting ORANGEFS Remount via host %s\n",
251 		     new_op->upcall.req.fs_mount.orangefs_config_server);
252 
253 	/*
254 	 * we assume that the calling function has already acquired the
255 	 * request_mutex to prevent other operations from bypassing
256 	 * this one
257 	 */
258 	ret = service_operation(new_op, "orangefs_remount",
259 		ORANGEFS_OP_PRIORITY | ORANGEFS_OP_NO_MUTEX);
260 	gossip_debug(GOSSIP_SUPER_DEBUG,
261 		     "orangefs_remount: mount got return value of %d\n",
262 		     ret);
263 	if (ret == 0) {
264 		/*
265 		 * store the id assigned to this sb -- it's just a
266 		 * short-lived mapping that the system interface uses
267 		 * to map this superblock to a particular mount entry
268 		 */
269 		orangefs_sb->id = new_op->downcall.resp.fs_mount.id;
270 		orangefs_sb->mount_pending = 0;
271 	}
272 
273 	op_release(new_op);
274 
275 	if (orangefs_userspace_version >= 20906) {
276 		new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES);
277 		if (!new_op)
278 			return -ENOMEM;
279 		new_op->upcall.req.features.features = 0;
280 		ret = service_operation(new_op, "orangefs_features",
281 		    ORANGEFS_OP_PRIORITY | ORANGEFS_OP_NO_MUTEX);
282 		if (!ret)
283 			orangefs_features =
284 			    new_op->downcall.resp.features.features;
285 		else
286 			orangefs_features = 0;
287 		op_release(new_op);
288 	} else {
289 		orangefs_features = 0;
290 	}
291 
292 	return ret;
293 }
294 
fsid_key_table_initialize(void)295 int fsid_key_table_initialize(void)
296 {
297 	return 0;
298 }
299 
fsid_key_table_finalize(void)300 void fsid_key_table_finalize(void)
301 {
302 }
303 
304 static const struct super_operations orangefs_s_ops = {
305 	.alloc_inode = orangefs_alloc_inode,
306 	.free_inode = orangefs_free_inode,
307 	.destroy_inode = orangefs_destroy_inode,
308 	.write_inode = orangefs_write_inode,
309 	.drop_inode = inode_just_drop,
310 	.statfs = orangefs_statfs,
311 	.show_options = orangefs_show_options,
312 };
313 
orangefs_fh_to_dentry(struct super_block * sb,struct fid * fid,int fh_len,int fh_type)314 static struct dentry *orangefs_fh_to_dentry(struct super_block *sb,
315 				  struct fid *fid,
316 				  int fh_len,
317 				  int fh_type)
318 {
319 	struct orangefs_object_kref refn;
320 
321 	if (fh_len < 5 || fh_type > 2)
322 		return NULL;
323 
324 	ORANGEFS_khandle_from(&(refn.khandle), fid->raw, 16);
325 	refn.fs_id = (u32) fid->raw[4];
326 	gossip_debug(GOSSIP_SUPER_DEBUG,
327 		     "fh_to_dentry: handle %pU, fs_id %d\n",
328 		     &refn.khandle,
329 		     refn.fs_id);
330 
331 	return d_obtain_alias(orangefs_iget(sb, &refn));
332 }
333 
orangefs_encode_fh(struct inode * inode,__u32 * fh,int * max_len,struct inode * parent)334 static int orangefs_encode_fh(struct inode *inode,
335 		    __u32 *fh,
336 		    int *max_len,
337 		    struct inode *parent)
338 {
339 	int len = parent ? 10 : 5;
340 	int type = 1;
341 	struct orangefs_object_kref refn;
342 
343 	if (*max_len < len) {
344 		gossip_err("fh buffer is too small for encoding\n");
345 		*max_len = len;
346 		type = 255;
347 		goto out;
348 	}
349 
350 	refn = ORANGEFS_I(inode)->refn;
351 	ORANGEFS_khandle_to(&refn.khandle, fh, 16);
352 	fh[4] = refn.fs_id;
353 
354 	gossip_debug(GOSSIP_SUPER_DEBUG,
355 		     "Encoding fh: handle %pU, fsid %u\n",
356 		     &refn.khandle,
357 		     refn.fs_id);
358 
359 
360 	if (parent) {
361 		refn = ORANGEFS_I(parent)->refn;
362 		ORANGEFS_khandle_to(&refn.khandle, (char *) fh + 20, 16);
363 		fh[9] = refn.fs_id;
364 
365 		type = 2;
366 		gossip_debug(GOSSIP_SUPER_DEBUG,
367 			     "Encoding parent: handle %pU, fsid %u\n",
368 			     &refn.khandle,
369 			     refn.fs_id);
370 	}
371 	*max_len = len;
372 
373 out:
374 	return type;
375 }
376 
377 static const struct export_operations orangefs_export_ops = {
378 	.encode_fh = orangefs_encode_fh,
379 	.fh_to_dentry = orangefs_fh_to_dentry,
380 };
381 
orangefs_unmount(int id,__s32 fs_id,const char * devname)382 static int orangefs_unmount(int id, __s32 fs_id, const char *devname)
383 {
384 	struct orangefs_kernel_op_s *op;
385 	int r;
386 
387 	/*
388 	 * If someone reboots linux without unmounting orangefs first,
389 	 * don't bother firing off an unmount service operation that
390 	 * will never complete, or the whole system shutdown
391 	 * stalls for ORANGEFS_DEFAULT_OP_TIMEOUT_SECS.
392 	 */
393 
394 	if (!__is_daemon_in_service() ||
395 		system_state == SYSTEM_HALT ||
396 		system_state == SYSTEM_POWER_OFF ||
397 		system_state == SYSTEM_RESTART) {
398 			gossip_debug(GOSSIP_SUPER_DEBUG,
399 				"%s: dirty unmount.\n",
400 				__func__);
401 			return 0;
402 	}
403 
404 	op = op_alloc(ORANGEFS_VFS_OP_FS_UMOUNT);
405 	if (!op)
406 		return -ENOMEM;
407 	op->upcall.req.fs_umount.id = id;
408 	op->upcall.req.fs_umount.fs_id = fs_id;
409 	strscpy(op->upcall.req.fs_umount.orangefs_config_server, devname);
410 	r = service_operation(op, "orangefs_fs_umount", 0);
411 	/* Not much to do about an error here. */
412 	if (r)
413 		gossip_err("orangefs_unmount: service_operation %d\n", r);
414 	op_release(op);
415 	return r;
416 }
417 
orangefs_fill_sb(struct super_block * sb,struct fs_context * fc,struct orangefs_fs_mount_response * fs_mount)418 static int orangefs_fill_sb(struct super_block *sb,
419 			    struct fs_context *fc,
420 			    struct orangefs_fs_mount_response *fs_mount)
421 {
422 	int ret;
423 	struct inode *root;
424 	struct dentry *root_dentry;
425 	struct orangefs_object_kref root_object;
426 
427 	ORANGEFS_SB(sb)->sb = sb;
428 
429 	ORANGEFS_SB(sb)->root_khandle = fs_mount->root_khandle;
430 	ORANGEFS_SB(sb)->fs_id = fs_mount->fs_id;
431 	ORANGEFS_SB(sb)->id = fs_mount->id;
432 
433 	/* Hang the xattr handlers off the superblock */
434 	sb->s_xattr = orangefs_xattr_handlers;
435 	sb->s_magic = ORANGEFS_SUPER_MAGIC;
436 	sb->s_op = &orangefs_s_ops;
437 	set_default_d_op(sb, &orangefs_dentry_operations);
438 
439 	sb->s_blocksize = PAGE_SIZE;
440 	sb->s_blocksize_bits = PAGE_SHIFT;
441 	sb->s_maxbytes = MAX_LFS_FILESIZE;
442 
443 	ret = super_setup_bdi(sb);
444 	if (ret)
445 		return ret;
446 
447 	root_object.khandle = ORANGEFS_SB(sb)->root_khandle;
448 	root_object.fs_id = ORANGEFS_SB(sb)->fs_id;
449 	gossip_debug(GOSSIP_SUPER_DEBUG,
450 		     "get inode %pU, fsid %d\n",
451 		     &root_object.khandle,
452 		     root_object.fs_id);
453 
454 	root = orangefs_iget(sb, &root_object);
455 	if (IS_ERR(root))
456 		return PTR_ERR(root);
457 
458 	gossip_debug(GOSSIP_SUPER_DEBUG,
459 		     "Allocated root inode [%p] with mode %x\n",
460 		     root,
461 		     root->i_mode);
462 
463 	/* allocates and places root dentry in dcache */
464 	root_dentry = d_make_root(root);
465 	if (!root_dentry)
466 		return -ENOMEM;
467 
468 	sb->s_export_op = &orangefs_export_ops;
469 	sb->s_root = root_dentry;
470 	return 0;
471 }
472 
orangefs_get_tree(struct fs_context * fc)473 static int orangefs_get_tree(struct fs_context *fc)
474 {
475 	int ret;
476 	struct super_block *sb = ERR_PTR(-EINVAL);
477 	struct orangefs_kernel_op_s *new_op;
478 
479 	if (!fc->source)
480 		return invalf(fc, "Device name not specified.\n");
481 
482 	gossip_debug(GOSSIP_SUPER_DEBUG,
483 		     "orangefs_mount: called with devname %s\n",
484 		     fc->source);
485 
486 	new_op = op_alloc(ORANGEFS_VFS_OP_FS_MOUNT);
487 	if (!new_op)
488 		return -ENOMEM;
489 
490 	strscpy(new_op->upcall.req.fs_mount.orangefs_config_server, fc->source);
491 
492 	gossip_debug(GOSSIP_SUPER_DEBUG,
493 		     "Attempting ORANGEFS Mount via host %s\n",
494 		     new_op->upcall.req.fs_mount.orangefs_config_server);
495 
496 	ret = service_operation(new_op, "orangefs_mount", 0);
497 	gossip_debug(GOSSIP_SUPER_DEBUG,
498 		     "orangefs_mount: mount got return value of %d\n", ret);
499 	if (ret)
500 		goto free_op;
501 
502 	if (new_op->downcall.resp.fs_mount.fs_id == ORANGEFS_FS_ID_NULL) {
503 		gossip_err("ERROR: Retrieved null fs_id\n");
504 		ret = -EINVAL;
505 		goto free_op;
506 	}
507 
508 	sb = sget_fc(fc, NULL, set_anon_super_fc);
509 
510 	if (IS_ERR(sb)) {
511 		ret = PTR_ERR(sb);
512 		orangefs_unmount(new_op->downcall.resp.fs_mount.id,
513 				 new_op->downcall.resp.fs_mount.fs_id,
514 				 fc->source);
515 		goto free_op;
516 	}
517 
518 	/* init our private orangefs sb info */
519 	ret = orangefs_fill_sb(sb, fc, &new_op->downcall.resp.fs_mount);
520 
521 	if (ret)
522 		goto free_sb_and_op;
523 
524 	/*
525 	 * on successful mount, store the devname and data
526 	 * used
527 	 */
528 	strscpy(ORANGEFS_SB(sb)->devname, fc->source);
529 
530 	/* mount_pending must be cleared */
531 	ORANGEFS_SB(sb)->mount_pending = 0;
532 
533 	/*
534 	 * finally, add this sb to our list of known orangefs
535 	 * sb's
536 	 */
537 	gossip_debug(GOSSIP_SUPER_DEBUG,
538 		     "Adding SB %p to orangefs superblocks\n",
539 		     ORANGEFS_SB(sb));
540 	spin_lock(&orangefs_superblocks_lock);
541 	list_add_tail(&ORANGEFS_SB(sb)->list, &orangefs_superblocks);
542 	spin_unlock(&orangefs_superblocks_lock);
543 	op_release(new_op);
544 
545 	/* Must be removed from the list now. */
546 	ORANGEFS_SB(sb)->no_list = 0;
547 
548 	if (orangefs_userspace_version >= 20906) {
549 		new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES);
550 		if (!new_op)
551 			return -ENOMEM;
552 		new_op->upcall.req.features.features = 0;
553 		ret = service_operation(new_op, "orangefs_features", 0);
554 		orangefs_features = new_op->downcall.resp.features.features;
555 		op_release(new_op);
556 	} else {
557 		orangefs_features = 0;
558 	}
559 
560 	fc->root = dget(sb->s_root);
561 	return 0;
562 
563 free_sb_and_op:
564 	/* Will call orangefs_kill_sb with sb not in list. */
565 	ORANGEFS_SB(sb)->no_list = 1;
566 	/* ORANGEFS_VFS_OP_FS_UMOUNT is done by orangefs_kill_sb. */
567 	deactivate_locked_super(sb);
568 free_op:
569 	gossip_err("orangefs_mount: mount request failed with %d\n", ret);
570 	if (ret == -EINVAL) {
571 		gossip_err("Ensure that all orangefs-servers have the same FS configuration files\n");
572 		gossip_err("Look at pvfs2-client-core log file (typically /tmp/pvfs2-client.log) for more details\n");
573 	}
574 
575 	op_release(new_op);
576 
577 	return ret;
578 }
579 
orangefs_free_fc(struct fs_context * fc)580 static void orangefs_free_fc(struct fs_context *fc)
581 {
582 	kfree(fc->s_fs_info);
583 }
584 
585 static const struct fs_context_operations orangefs_context_ops = {
586 	.free		= orangefs_free_fc,
587 	.parse_param	= orangefs_parse_param,
588 	.get_tree	= orangefs_get_tree,
589 	.reconfigure	= orangefs_reconfigure,
590 };
591 
592 /*
593  * Set up the filesystem mount context.
594  */
orangefs_init_fs_context(struct fs_context * fc)595 int orangefs_init_fs_context(struct fs_context *fc)
596 {
597 	struct orangefs_sb_info_s *osi;
598 
599 	osi = kzalloc_obj(struct orangefs_sb_info_s);
600 	if (!osi)
601 		return -ENOMEM;
602 
603 	/*
604 	 * Force any potential flags that might be set from the mount
605 	 * to zero, ie, initialize to unset.
606 	 */
607 	fc->sb_flags_mask &= ~SB_POSIXACL;
608 	osi->flags &= ~ORANGEFS_OPT_INTR;
609 	osi->flags &= ~ORANGEFS_OPT_LOCAL_LOCK;
610 
611 	fc->s_fs_info = osi;
612 	fc->ops = &orangefs_context_ops;
613 	return 0;
614 }
615 
orangefs_kill_sb(struct super_block * sb)616 void orangefs_kill_sb(struct super_block *sb)
617 {
618 	int r;
619 	gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_kill_sb: called\n");
620 
621 	/* provided sb cleanup */
622 	kill_anon_super(sb);
623 
624 	if (!ORANGEFS_SB(sb)) {
625 		mutex_lock(&orangefs_request_mutex);
626 		mutex_unlock(&orangefs_request_mutex);
627 		return;
628 	}
629 	/*
630 	 * issue the unmount to userspace to tell it to remove the
631 	 * dynamic mount info it has for this superblock
632 	 */
633 	r = orangefs_unmount(ORANGEFS_SB(sb)->id, ORANGEFS_SB(sb)->fs_id,
634 	    ORANGEFS_SB(sb)->devname);
635 	if (!r)
636 		ORANGEFS_SB(sb)->mount_pending = 1;
637 
638 	if (!ORANGEFS_SB(sb)->no_list) {
639 		/* remove the sb from our list of orangefs specific sb's */
640 		spin_lock(&orangefs_superblocks_lock);
641 		/* not list_del_init */
642 		__list_del_entry(&ORANGEFS_SB(sb)->list);
643 		ORANGEFS_SB(sb)->list.prev = NULL;
644 		spin_unlock(&orangefs_superblocks_lock);
645 	}
646 
647 	/*
648 	 * make sure that ORANGEFS_DEV_REMOUNT_ALL loop that might've seen us
649 	 * gets completed before we free the dang thing.
650 	 */
651 	mutex_lock(&orangefs_request_mutex);
652 	mutex_unlock(&orangefs_request_mutex);
653 
654 	/* free the orangefs superblock private data */
655 	kfree(ORANGEFS_SB(sb));
656 }
657 
orangefs_inode_cache_initialize(void)658 int orangefs_inode_cache_initialize(void)
659 {
660 	orangefs_inode_cache = kmem_cache_create_usercopy(
661 					"orangefs_inode_cache",
662 					sizeof(struct orangefs_inode_s),
663 					0,
664 					0,
665 					offsetof(struct orangefs_inode_s,
666 						link_target),
667 					sizeof_field(struct orangefs_inode_s,
668 						link_target),
669 					orangefs_inode_cache_ctor);
670 
671 	if (!orangefs_inode_cache) {
672 		gossip_err("Cannot create orangefs_inode_cache\n");
673 		return -ENOMEM;
674 	}
675 	return 0;
676 }
677 
orangefs_inode_cache_finalize(void)678 int orangefs_inode_cache_finalize(void)
679 {
680 	kmem_cache_destroy(orangefs_inode_cache);
681 	return 0;
682 }
683