super.c 16.6 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
M
Mike Marshall 已提交
2 3 4 5 6 7 8
/*
 * (C) 2001 Clemson University and The University of Chicago
 *
 * See COPYING in top-level directory.
 */

#include "protocol.h"
9 10
#include "orangefs-kernel.h"
#include "orangefs-bufmap.h"
M
Mike Marshall 已提交
11 12 13

#include <linux/parser.h>

14 15
/* a cache for orangefs-inode objects (i.e. orangefs inode private data) */
static struct kmem_cache *orangefs_inode_cache;
M
Mike Marshall 已提交
16

17 18
/* list for storing orangefs specific superblocks in use */
LIST_HEAD(orangefs_superblocks);
M
Mike Marshall 已提交
19

20
DEFINE_SPINLOCK(orangefs_superblocks_lock);
M
Mike Marshall 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

enum {
	Opt_intr,
	Opt_acl,
	Opt_local_lock,

	Opt_err
};

static const match_table_t tokens = {
	{ Opt_acl,		"acl" },
	{ Opt_intr,		"intr" },
	{ Opt_local_lock,	"local_lock" },
	{ Opt_err,	NULL }
};

M
Martin Brandenburg 已提交
37
uint64_t orangefs_features;
M
Mike Marshall 已提交
38

D
David Howells 已提交
39 40 41 42
static int orangefs_show_options(struct seq_file *m, struct dentry *root)
{
	struct orangefs_sb_info_s *orangefs_sb = ORANGEFS_SB(root->d_sb);

43
	if (root->d_sb->s_flags & SB_POSIXACL)
D
David Howells 已提交
44 45 46 47 48 49 50 51
		seq_puts(m, ",acl");
	if (orangefs_sb->flags & ORANGEFS_OPT_INTR)
		seq_puts(m, ",intr");
	if (orangefs_sb->flags & ORANGEFS_OPT_LOCAL_LOCK)
		seq_puts(m, ",local_lock");
	return 0;
}

M
Mike Marshall 已提交
52 53 54
static int parse_mount_options(struct super_block *sb, char *options,
		int silent)
{
55
	struct orangefs_sb_info_s *orangefs_sb = ORANGEFS_SB(sb);
M
Mike Marshall 已提交
56 57 58 59 60 61 62
	substring_t args[MAX_OPT_ARGS];
	char *p;

	/*
	 * Force any potential flags that might be set from the mount
	 * to zero, ie, initialize to unset.
	 */
63
	sb->s_flags &= ~SB_POSIXACL;
64 65
	orangefs_sb->flags &= ~ORANGEFS_OPT_INTR;
	orangefs_sb->flags &= ~ORANGEFS_OPT_LOCAL_LOCK;
M
Mike Marshall 已提交
66 67 68 69 70 71 72 73 74 75

	while ((p = strsep(&options, ",")) != NULL) {
		int token;

		if (!*p)
			continue;

		token = match_token(p, tokens, args);
		switch (token) {
		case Opt_acl:
76
			sb->s_flags |= SB_POSIXACL;
M
Mike Marshall 已提交
77 78
			break;
		case Opt_intr:
79
			orangefs_sb->flags |= ORANGEFS_OPT_INTR;
M
Mike Marshall 已提交
80 81
			break;
		case Opt_local_lock:
82
			orangefs_sb->flags |= ORANGEFS_OPT_LOCAL_LOCK;
M
Mike Marshall 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95
			break;
		default:
			goto fail;
		}
	}

	return 0;
fail:
	if (!silent)
		gossip_err("Error: mount option [%s] is not supported.\n", p);
	return -EINVAL;
}

96
static void orangefs_inode_cache_ctor(void *req)
M
Mike Marshall 已提交
97
{
98
	struct orangefs_inode_s *orangefs_inode = req;
M
Mike Marshall 已提交
99

100 101
	inode_init_once(&orangefs_inode->vfs_inode);
	init_rwsem(&orangefs_inode->xattr_sem);
M
Mike Marshall 已提交
102 103
}

104
static struct inode *orangefs_alloc_inode(struct super_block *sb)
M
Mike Marshall 已提交
105
{
106
	struct orangefs_inode_s *orangefs_inode;
M
Mike Marshall 已提交
107

108
	orangefs_inode = kmem_cache_alloc(orangefs_inode_cache, GFP_KERNEL);
109
	if (!orangefs_inode)
M
Mike Marshall 已提交
110 111 112 113 114 115
		return NULL;

	/*
	 * We want to clear everything except for rw_semaphore and the
	 * vfs_inode.
	 */
116 117 118 119
	memset(&orangefs_inode->refn.khandle, 0, 16);
	orangefs_inode->refn.fs_id = ORANGEFS_FS_ID_NULL;
	orangefs_inode->last_failed_block_index_read = 0;
	memset(orangefs_inode->link_target, 0, sizeof(orangefs_inode->link_target));
M
Mike Marshall 已提交
120 121

	gossip_debug(GOSSIP_SUPER_DEBUG,
122 123 124
		     "orangefs_alloc_inode: allocated %p\n",
		     &orangefs_inode->vfs_inode);
	return &orangefs_inode->vfs_inode;
M
Mike Marshall 已提交
125 126
}

127 128 129 130 131 132 133
static void orangefs_i_callback(struct rcu_head *head)
{
	struct inode *inode = container_of(head, struct inode, i_rcu);
	struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
	kmem_cache_free(orangefs_inode_cache, orangefs_inode);
}

134
static void orangefs_destroy_inode(struct inode *inode)
M
Mike Marshall 已提交
135
{
136
	struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
M
Mike Marshall 已提交
137 138 139

	gossip_debug(GOSSIP_SUPER_DEBUG,
			"%s: deallocated %p destroying inode %pU\n",
140
			__func__, orangefs_inode, get_khandle_from_ino(inode));
M
Mike Marshall 已提交
141

142
	call_rcu(&inode->i_rcu, orangefs_i_callback);
M
Mike Marshall 已提交
143 144 145 146 147 148
}

/*
 * NOTE: information filled in here is typically reflected in the
 * output of the system command 'df'
*/
149
static int orangefs_statfs(struct dentry *dentry, struct kstatfs *buf)
M
Mike Marshall 已提交
150 151
{
	int ret = -ENOMEM;
152
	struct orangefs_kernel_op_s *new_op = NULL;
M
Mike Marshall 已提交
153 154 155 156 157 158
	int flags = 0;
	struct super_block *sb = NULL;

	sb = dentry->d_sb;

	gossip_debug(GOSSIP_SUPER_DEBUG,
159
		     "orangefs_statfs: called on sb %p (fs_id is %d)\n",
M
Mike Marshall 已提交
160
		     sb,
161
		     (int)(ORANGEFS_SB(sb)->fs_id));
M
Mike Marshall 已提交
162

163
	new_op = op_alloc(ORANGEFS_VFS_OP_STATFS);
M
Mike Marshall 已提交
164 165
	if (!new_op)
		return ret;
166
	new_op->upcall.req.statfs.fs_id = ORANGEFS_SB(sb)->fs_id;
M
Mike Marshall 已提交
167

168 169
	if (ORANGEFS_SB(sb)->flags & ORANGEFS_OPT_INTR)
		flags = ORANGEFS_OP_INTERRUPTIBLE;
M
Mike Marshall 已提交
170

171
	ret = service_operation(new_op, "orangefs_statfs", flags);
M
Mike Marshall 已提交
172 173 174 175 176

	if (new_op->downcall.status < 0)
		goto out_op_release;

	gossip_debug(GOSSIP_SUPER_DEBUG,
177 178 179 180
		     "%s: got %ld blocks available | "
		     "%ld blocks total | %ld block size | "
		     "%ld files total | %ld files avail\n",
		     __func__,
M
Mike Marshall 已提交
181 182
		     (long)new_op->downcall.resp.statfs.blocks_avail,
		     (long)new_op->downcall.resp.statfs.blocks_total,
183 184 185
		     (long)new_op->downcall.resp.statfs.block_size,
		     (long)new_op->downcall.resp.statfs.files_total,
		     (long)new_op->downcall.resp.statfs.files_avail);
M
Mike Marshall 已提交
186 187

	buf->f_type = sb->s_magic;
188
	memcpy(&buf->f_fsid, &ORANGEFS_SB(sb)->fs_id, sizeof(buf->f_fsid));
M
Mike Marshall 已提交
189
	buf->f_bsize = new_op->downcall.resp.statfs.block_size;
190
	buf->f_namelen = ORANGEFS_NAME_MAX;
M
Mike Marshall 已提交
191 192 193 194 195 196 197 198 199 200

	buf->f_blocks = (sector_t) new_op->downcall.resp.statfs.blocks_total;
	buf->f_bfree = (sector_t) new_op->downcall.resp.statfs.blocks_avail;
	buf->f_bavail = (sector_t) new_op->downcall.resp.statfs.blocks_avail;
	buf->f_files = (sector_t) new_op->downcall.resp.statfs.files_total;
	buf->f_ffree = (sector_t) new_op->downcall.resp.statfs.files_avail;
	buf->f_frsize = sb->s_blocksize;

out_op_release:
	op_release(new_op);
201
	gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_statfs: returning %d\n", ret);
M
Mike Marshall 已提交
202 203 204 205 206 207 208
	return ret;
}

/*
 * Remount as initiated by VFS layer.  We just need to reparse the mount
 * options, no need to signal pvfs2-client-core about it.
 */
209
static int orangefs_remount_fs(struct super_block *sb, int *flags, char *data)
M
Mike Marshall 已提交
210
{
211
	gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_remount_fs: called\n");
M
Mike Marshall 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
	return parse_mount_options(sb, data, 1);
}

/*
 * Remount as initiated by pvfs2-client-core on restart.  This is used to
 * repopulate mount information left from previous pvfs2-client-core.
 *
 * the idea here is that given a valid superblock, we're
 * re-initializing the user space client with the initial mount
 * information specified when the super block was first initialized.
 * this is very different than the first initialization/creation of a
 * superblock.  we use the special service_priority_operation to make
 * sure that the mount gets ahead of any other pending operation that
 * is waiting for servicing.  this means that the pvfs2-client won't
 * fail to start several times for all other pending operations before
 * the client regains all of the mount information from us.
 * NOTE: this function assumes that the request_mutex is already acquired!
 */
230
int orangefs_remount(struct orangefs_sb_info_s *orangefs_sb)
M
Mike Marshall 已提交
231
{
232
	struct orangefs_kernel_op_s *new_op;
M
Mike Marshall 已提交
233 234
	int ret = -EINVAL;

235
	gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_remount: called\n");
M
Mike Marshall 已提交
236

237
	new_op = op_alloc(ORANGEFS_VFS_OP_FS_MOUNT);
M
Mike Marshall 已提交
238 239
	if (!new_op)
		return -ENOMEM;
240
	strncpy(new_op->upcall.req.fs_mount.orangefs_config_server,
241
		orangefs_sb->devname,
242
		ORANGEFS_MAX_SERVER_ADDR_LEN);
M
Mike Marshall 已提交
243 244

	gossip_debug(GOSSIP_SUPER_DEBUG,
245 246
		     "Attempting ORANGEFS Remount via host %s\n",
		     new_op->upcall.req.fs_mount.orangefs_config_server);
M
Mike Marshall 已提交
247 248

	/*
M
Mike Marshall 已提交
249
	 * we assume that the calling function has already acquired the
M
Mike Marshall 已提交
250 251 252
	 * request_mutex to prevent other operations from bypassing
	 * this one
	 */
253
	ret = service_operation(new_op, "orangefs_remount",
M
Mike Marshall 已提交
254
		ORANGEFS_OP_PRIORITY | ORANGEFS_OP_NO_MUTEX);
M
Mike Marshall 已提交
255
	gossip_debug(GOSSIP_SUPER_DEBUG,
256
		     "orangefs_remount: mount got return value of %d\n",
M
Mike Marshall 已提交
257 258 259 260 261 262 263
		     ret);
	if (ret == 0) {
		/*
		 * store the id assigned to this sb -- it's just a
		 * short-lived mapping that the system interface uses
		 * to map this superblock to a particular mount entry
		 */
264 265
		orangefs_sb->id = new_op->downcall.resp.fs_mount.id;
		orangefs_sb->mount_pending = 0;
M
Mike Marshall 已提交
266 267 268
	}

	op_release(new_op);
M
Martin Brandenburg 已提交
269

270
	if (orangefs_userspace_version >= 20906) {
M
Martin Brandenburg 已提交
271 272 273 274
		new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES);
		if (!new_op)
			return -ENOMEM;
		new_op->upcall.req.features.features = 0;
275 276 277 278 279 280 281
		ret = service_operation(new_op, "orangefs_features",
		    ORANGEFS_OP_PRIORITY | ORANGEFS_OP_NO_MUTEX);
		if (!ret)
			orangefs_features =
			    new_op->downcall.resp.features.features;
		else
			orangefs_features = 0;
M
Martin Brandenburg 已提交
282 283 284 285 286
		op_release(new_op);
	} else {
		orangefs_features = 0;
	}

M
Mike Marshall 已提交
287 288 289 290 291 292 293 294 295 296 297 298
	return ret;
}

int fsid_key_table_initialize(void)
{
	return 0;
}

void fsid_key_table_finalize(void)
{
}

299 300 301
static const struct super_operations orangefs_s_ops = {
	.alloc_inode = orangefs_alloc_inode,
	.destroy_inode = orangefs_destroy_inode,
M
Mike Marshall 已提交
302
	.drop_inode = generic_delete_inode,
303 304
	.statfs = orangefs_statfs,
	.remount_fs = orangefs_remount_fs,
D
David Howells 已提交
305
	.show_options = orangefs_show_options,
M
Mike Marshall 已提交
306 307
};

308
static struct dentry *orangefs_fh_to_dentry(struct super_block *sb,
M
Mike Marshall 已提交
309 310 311 312
				  struct fid *fid,
				  int fh_len,
				  int fh_type)
{
313
	struct orangefs_object_kref refn;
M
Mike Marshall 已提交
314 315 316 317

	if (fh_len < 5 || fh_type > 2)
		return NULL;

318
	ORANGEFS_khandle_from(&(refn.khandle), fid->raw, 16);
M
Mike Marshall 已提交
319 320 321 322 323 324
	refn.fs_id = (u32) fid->raw[4];
	gossip_debug(GOSSIP_SUPER_DEBUG,
		     "fh_to_dentry: handle %pU, fs_id %d\n",
		     &refn.khandle,
		     refn.fs_id);

325
	return d_obtain_alias(orangefs_iget(sb, &refn));
M
Mike Marshall 已提交
326 327
}

328
static int orangefs_encode_fh(struct inode *inode,
M
Mike Marshall 已提交
329 330 331 332 333 334
		    __u32 *fh,
		    int *max_len,
		    struct inode *parent)
{
	int len = parent ? 10 : 5;
	int type = 1;
335
	struct orangefs_object_kref refn;
M
Mike Marshall 已提交
336 337 338 339 340 341 342 343

	if (*max_len < len) {
		gossip_lerr("fh buffer is too small for encoding\n");
		*max_len = len;
		type = 255;
		goto out;
	}

344 345
	refn = ORANGEFS_I(inode)->refn;
	ORANGEFS_khandle_to(&refn.khandle, fh, 16);
M
Mike Marshall 已提交
346 347 348 349 350 351 352 353 354
	fh[4] = refn.fs_id;

	gossip_debug(GOSSIP_SUPER_DEBUG,
		     "Encoding fh: handle %pU, fsid %u\n",
		     &refn.khandle,
		     refn.fs_id);


	if (parent) {
355 356
		refn = ORANGEFS_I(parent)->refn;
		ORANGEFS_khandle_to(&refn.khandle, (char *) fh + 20, 16);
M
Mike Marshall 已提交
357 358 359 360 361 362 363 364 365 366 367 368 369 370
		fh[9] = refn.fs_id;

		type = 2;
		gossip_debug(GOSSIP_SUPER_DEBUG,
			     "Encoding parent: handle %pU, fsid %u\n",
			     &refn.khandle,
			     refn.fs_id);
	}
	*max_len = len;

out:
	return type;
}

371
static const struct export_operations orangefs_export_ops = {
372 373
	.encode_fh = orangefs_encode_fh,
	.fh_to_dentry = orangefs_fh_to_dentry,
M
Mike Marshall 已提交
374 375
};

376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
static int orangefs_unmount(int id, __s32 fs_id, const char *devname)
{
	struct orangefs_kernel_op_s *op;
	int r;
	op = op_alloc(ORANGEFS_VFS_OP_FS_UMOUNT);
	if (!op)
		return -ENOMEM;
	op->upcall.req.fs_umount.id = id;
	op->upcall.req.fs_umount.fs_id = fs_id;
	strncpy(op->upcall.req.fs_umount.orangefs_config_server,
	    devname, ORANGEFS_MAX_SERVER_ADDR_LEN);
	r = service_operation(op, "orangefs_fs_umount", 0);
	/* Not much to do about an error here. */
	if (r)
		gossip_err("orangefs_unmount: service_operation %d\n", r);
	op_release(op);
	return r;
}

395 396
static int orangefs_fill_sb(struct super_block *sb,
		struct orangefs_fs_mount_response *fs_mount,
397
		void *data, int silent)
M
Mike Marshall 已提交
398 399 400 401
{
	int ret = -EINVAL;
	struct inode *root = NULL;
	struct dentry *root_dentry = NULL;
402
	struct orangefs_object_kref root_object;
M
Mike Marshall 已提交
403

404
	/* alloc and init our private orangefs sb info */
405
	sb->s_fs_info = kzalloc(sizeof(struct orangefs_sb_info_s), GFP_KERNEL);
406
	if (!ORANGEFS_SB(sb))
M
Mike Marshall 已提交
407
		return -ENOMEM;
408
	ORANGEFS_SB(sb)->sb = sb;
M
Mike Marshall 已提交
409

410 411 412
	ORANGEFS_SB(sb)->root_khandle = fs_mount->root_khandle;
	ORANGEFS_SB(sb)->fs_id = fs_mount->fs_id;
	ORANGEFS_SB(sb)->id = fs_mount->id;
M
Mike Marshall 已提交
413

414 415
	if (data) {
		ret = parse_mount_options(sb, data, silent);
M
Mike Marshall 已提交
416 417 418 419 420
		if (ret)
			return ret;
	}

	/* Hang the xattr handlers off the superblock */
421 422 423 424
	sb->s_xattr = orangefs_xattr_handlers;
	sb->s_magic = ORANGEFS_SUPER_MAGIC;
	sb->s_op = &orangefs_s_ops;
	sb->s_d_op = &orangefs_dentry_operations;
M
Mike Marshall 已提交
425

426 427
	sb->s_blocksize = orangefs_bufmap_size_query();
	sb->s_blocksize_bits = orangefs_bufmap_shift_query();
M
Mike Marshall 已提交
428 429
	sb->s_maxbytes = MAX_LFS_FILESIZE;

430 431
	root_object.khandle = ORANGEFS_SB(sb)->root_khandle;
	root_object.fs_id = ORANGEFS_SB(sb)->fs_id;
M
Mike Marshall 已提交
432 433 434 435 436
	gossip_debug(GOSSIP_SUPER_DEBUG,
		     "get inode %pU, fsid %d\n",
		     &root_object.khandle,
		     root_object.fs_id);

437
	root = orangefs_iget(sb, &root_object);
M
Mike Marshall 已提交
438 439 440 441 442 443 444 445 446 447
	if (IS_ERR(root))
		return PTR_ERR(root);

	gossip_debug(GOSSIP_SUPER_DEBUG,
		     "Allocated root inode [%p] with mode %x\n",
		     root,
		     root->i_mode);

	/* allocates and places root dentry in dcache */
	root_dentry = d_make_root(root);
448
	if (!root_dentry)
M
Mike Marshall 已提交
449 450
		return -ENOMEM;

451
	sb->s_export_op = &orangefs_export_ops;
M
Mike Marshall 已提交
452 453 454 455
	sb->s_root = root_dentry;
	return 0;
}

456
struct dentry *orangefs_mount(struct file_system_type *fst,
M
Mike Marshall 已提交
457 458 459 460 461 462
			   int flags,
			   const char *devname,
			   void *data)
{
	int ret = -EINVAL;
	struct super_block *sb = ERR_PTR(-EINVAL);
463
	struct orangefs_kernel_op_s *new_op;
464
	struct dentry *d = ERR_PTR(-EINVAL);
M
Mike Marshall 已提交
465 466

	gossip_debug(GOSSIP_SUPER_DEBUG,
467
		     "orangefs_mount: called with devname %s\n",
M
Mike Marshall 已提交
468 469 470 471 472 473 474
		     devname);

	if (!devname) {
		gossip_err("ERROR: device name not specified.\n");
		return ERR_PTR(-EINVAL);
	}

475
	new_op = op_alloc(ORANGEFS_VFS_OP_FS_MOUNT);
M
Mike Marshall 已提交
476 477 478
	if (!new_op)
		return ERR_PTR(-ENOMEM);

479
	strncpy(new_op->upcall.req.fs_mount.orangefs_config_server,
M
Mike Marshall 已提交
480
		devname,
481
		ORANGEFS_MAX_SERVER_ADDR_LEN);
M
Mike Marshall 已提交
482 483

	gossip_debug(GOSSIP_SUPER_DEBUG,
484 485
		     "Attempting ORANGEFS Mount via host %s\n",
		     new_op->upcall.req.fs_mount.orangefs_config_server);
M
Mike Marshall 已提交
486

487
	ret = service_operation(new_op, "orangefs_mount", 0);
M
Mike Marshall 已提交
488
	gossip_debug(GOSSIP_SUPER_DEBUG,
489
		     "orangefs_mount: mount got return value of %d\n", ret);
M
Mike Marshall 已提交
490 491 492
	if (ret)
		goto free_op;

493
	if (new_op->downcall.resp.fs_mount.fs_id == ORANGEFS_FS_ID_NULL) {
M
Mike Marshall 已提交
494 495 496 497 498
		gossip_err("ERROR: Retrieved null fs_id\n");
		ret = -EINVAL;
		goto free_op;
	}

499 500 501 502
	sb = sget(fst, NULL, set_anon_super, flags, NULL);

	if (IS_ERR(sb)) {
		d = ERR_CAST(sb);
503 504
		orangefs_unmount(new_op->downcall.resp.fs_mount.id,
		    new_op->downcall.resp.fs_mount.fs_id, devname);
M
Mike Marshall 已提交
505 506 507
		goto free_op;
	}

508
	ret = orangefs_fill_sb(sb,
509
	      &new_op->downcall.resp.fs_mount, data,
510
	      flags & SB_SILENT ? 1 : 0);
511 512 513

	if (ret) {
		d = ERR_PTR(ret);
514
		goto free_sb_and_op;
515
	}
M
Mike Marshall 已提交
516 517 518 519 520

	/*
	 * on successful mount, store the devname and data
	 * used
	 */
521
	strncpy(ORANGEFS_SB(sb)->devname,
M
Mike Marshall 已提交
522
		devname,
523
		ORANGEFS_MAX_SERVER_ADDR_LEN);
M
Mike Marshall 已提交
524 525

	/* mount_pending must be cleared */
526
	ORANGEFS_SB(sb)->mount_pending = 0;
M
Mike Marshall 已提交
527 528

	/*
529
	 * finally, add this sb to our list of known orangefs
M
Mike Marshall 已提交
530 531
	 * sb's
	 */
532 533 534 535 536 537
	gossip_debug(GOSSIP_SUPER_DEBUG,
		     "Adding SB %p to orangefs superblocks\n",
		     ORANGEFS_SB(sb));
	spin_lock(&orangefs_superblocks_lock);
	list_add_tail(&ORANGEFS_SB(sb)->list, &orangefs_superblocks);
	spin_unlock(&orangefs_superblocks_lock);
M
Mike Marshall 已提交
538
	op_release(new_op);
M
Martin Brandenburg 已提交
539

540 541 542
	/* Must be removed from the list now. */
	ORANGEFS_SB(sb)->no_list = 0;

543
	if (orangefs_userspace_version >= 20906) {
M
Martin Brandenburg 已提交
544 545 546 547 548 549 550 551 552 553 554
		new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES);
		if (!new_op)
			return ERR_PTR(-ENOMEM);
		new_op->upcall.req.features.features = 0;
		ret = service_operation(new_op, "orangefs_features", 0);
		orangefs_features = new_op->downcall.resp.features.features;
		op_release(new_op);
	} else {
		orangefs_features = 0;
	}

555
	return dget(sb->s_root);
M
Mike Marshall 已提交
556

557 558 559
free_sb_and_op:
	/* Will call orangefs_kill_sb with sb not in list. */
	ORANGEFS_SB(sb)->no_list = 1;
560
	/* ORANGEFS_VFS_OP_FS_UMOUNT is done by orangefs_kill_sb. */
561
	deactivate_locked_super(sb);
M
Mike Marshall 已提交
562
free_op:
563
	gossip_err("orangefs_mount: mount request failed with %d\n", ret);
M
Mike Marshall 已提交
564
	if (ret == -EINVAL) {
565
		gossip_err("Ensure that all orangefs-servers have the same FS configuration files\n");
M
Mike Marshall 已提交
566 567 568 569 570
		gossip_err("Look at pvfs2-client-core log file (typically /tmp/pvfs2-client.log) for more details\n");
	}

	op_release(new_op);

571
	return d;
M
Mike Marshall 已提交
572 573
}

574
void orangefs_kill_sb(struct super_block *sb)
M
Mike Marshall 已提交
575
{
576
	int r;
577
	gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_kill_sb: called\n");
M
Mike Marshall 已提交
578

579 580 581
	/* provided sb cleanup */
	kill_anon_super(sb);

M
Mike Marshall 已提交
582 583 584 585
	/*
	 * issue the unmount to userspace to tell it to remove the
	 * dynamic mount info it has for this superblock
	 */
586 587 588 589
	r = orangefs_unmount(ORANGEFS_SB(sb)->id, ORANGEFS_SB(sb)->fs_id,
	    ORANGEFS_SB(sb)->devname);
	if (!r)
		ORANGEFS_SB(sb)->mount_pending = 1;
M
Mike Marshall 已提交
590

591 592 593 594 595 596 597 598
	if (!ORANGEFS_SB(sb)->no_list) {
		/* remove the sb from our list of orangefs specific sb's */
		spin_lock(&orangefs_superblocks_lock);
		/* not list_del_init */
		__list_del_entry(&ORANGEFS_SB(sb)->list);
		ORANGEFS_SB(sb)->list.prev = NULL;
		spin_unlock(&orangefs_superblocks_lock);
	}
599 600 601 602 603

	/*
	 * make sure that ORANGEFS_DEV_REMOUNT_ALL loop that might've seen us
	 * gets completed before we free the dang thing.
	 */
604 605
	mutex_lock(&orangefs_request_mutex);
	mutex_unlock(&orangefs_request_mutex);
M
Mike Marshall 已提交
606

607 608
	/* free the orangefs superblock private data */
	kfree(ORANGEFS_SB(sb));
M
Mike Marshall 已提交
609 610
}

611
int orangefs_inode_cache_initialize(void)
M
Mike Marshall 已提交
612
{
613 614 615 616 617 618 619 620 621 622
	orangefs_inode_cache = kmem_cache_create_usercopy(
					"orangefs_inode_cache",
					sizeof(struct orangefs_inode_s),
					0,
					ORANGEFS_CACHE_CREATE_FLAGS,
					offsetof(struct orangefs_inode_s,
						link_target),
					sizeof_field(struct orangefs_inode_s,
						link_target),
					orangefs_inode_cache_ctor);
M
Mike Marshall 已提交
623

624 625
	if (!orangefs_inode_cache) {
		gossip_err("Cannot create orangefs_inode_cache\n");
M
Mike Marshall 已提交
626 627 628 629 630
		return -ENOMEM;
	}
	return 0;
}

631
int orangefs_inode_cache_finalize(void)
M
Mike Marshall 已提交
632
{
633
	kmem_cache_destroy(orangefs_inode_cache);
M
Mike Marshall 已提交
634 635
	return 0;
}