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