blob: 5a1bed6c8c6ae5b19eea666343347422b3f0dbbb [file] [log] [blame]
Mike Marshall1182fca2015-07-17 10:38:15 -04001/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -05008#include "orangefs-kernel.h"
9#include "orangefs-bufmap.h"
Mike Marshall1182fca2015-07-17 10:38:15 -040010
11#include <linux/parser.h>
12
Yi Liu8bb8aef2015-11-24 15:12:14 -050013/* a cache for orangefs-inode objects (i.e. orangefs inode private data) */
14static struct kmem_cache *orangefs_inode_cache;
Mike Marshall1182fca2015-07-17 10:38:15 -040015
Yi Liu8bb8aef2015-11-24 15:12:14 -050016/* list for storing orangefs specific superblocks in use */
17LIST_HEAD(orangefs_superblocks);
Mike Marshall1182fca2015-07-17 10:38:15 -040018
Yi Liu8bb8aef2015-11-24 15:12:14 -050019DEFINE_SPINLOCK(orangefs_superblocks_lock);
Mike Marshall1182fca2015-07-17 10:38:15 -040020
21enum {
22 Opt_intr,
23 Opt_acl,
24 Opt_local_lock,
25
26 Opt_err
27};
28
29static const match_table_t tokens = {
30 { Opt_acl, "acl" },
31 { Opt_intr, "intr" },
32 { Opt_local_lock, "local_lock" },
33 { Opt_err, NULL }
34};
35
Martin Brandenburg482664d2016-08-12 12:02:31 -040036uint64_t orangefs_features;
Mike Marshall1182fca2015-07-17 10:38:15 -040037
David Howells4dfdb712017-07-05 16:25:45 +010038static 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 & MS_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
Mike Marshall1182fca2015-07-17 10:38:15 -040051static int parse_mount_options(struct super_block *sb, char *options,
52 int silent)
53{
Yi Liu8bb8aef2015-11-24 15:12:14 -050054 struct orangefs_sb_info_s *orangefs_sb = ORANGEFS_SB(sb);
Mike Marshall1182fca2015-07-17 10:38:15 -040055 substring_t args[MAX_OPT_ARGS];
56 char *p;
57
58 /*
59 * Force any potential flags that might be set from the mount
60 * to zero, ie, initialize to unset.
61 */
62 sb->s_flags &= ~MS_POSIXACL;
Yi Liu8bb8aef2015-11-24 15:12:14 -050063 orangefs_sb->flags &= ~ORANGEFS_OPT_INTR;
64 orangefs_sb->flags &= ~ORANGEFS_OPT_LOCAL_LOCK;
Mike Marshall1182fca2015-07-17 10:38:15 -040065
66 while ((p = strsep(&options, ",")) != NULL) {
67 int token;
68
69 if (!*p)
70 continue;
71
72 token = match_token(p, tokens, args);
73 switch (token) {
74 case Opt_acl:
75 sb->s_flags |= MS_POSIXACL;
76 break;
77 case Opt_intr:
Yi Liu8bb8aef2015-11-24 15:12:14 -050078 orangefs_sb->flags |= ORANGEFS_OPT_INTR;
Mike Marshall1182fca2015-07-17 10:38:15 -040079 break;
80 case Opt_local_lock:
Yi Liu8bb8aef2015-11-24 15:12:14 -050081 orangefs_sb->flags |= ORANGEFS_OPT_LOCAL_LOCK;
Mike Marshall1182fca2015-07-17 10:38:15 -040082 break;
83 default:
84 goto fail;
85 }
86 }
87
88 return 0;
89fail:
90 if (!silent)
91 gossip_err("Error: mount option [%s] is not supported.\n", p);
92 return -EINVAL;
93}
94
Yi Liu8bb8aef2015-11-24 15:12:14 -050095static void orangefs_inode_cache_ctor(void *req)
Mike Marshall1182fca2015-07-17 10:38:15 -040096{
Yi Liu8bb8aef2015-11-24 15:12:14 -050097 struct orangefs_inode_s *orangefs_inode = req;
Mike Marshall1182fca2015-07-17 10:38:15 -040098
Yi Liu8bb8aef2015-11-24 15:12:14 -050099 inode_init_once(&orangefs_inode->vfs_inode);
100 init_rwsem(&orangefs_inode->xattr_sem);
Mike Marshall1182fca2015-07-17 10:38:15 -0400101
Yi Liu8bb8aef2015-11-24 15:12:14 -0500102 orangefs_inode->vfs_inode.i_version = 1;
Mike Marshall1182fca2015-07-17 10:38:15 -0400103}
104
Yi Liu8bb8aef2015-11-24 15:12:14 -0500105static struct inode *orangefs_alloc_inode(struct super_block *sb)
Mike Marshall1182fca2015-07-17 10:38:15 -0400106{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500107 struct orangefs_inode_s *orangefs_inode;
Mike Marshall1182fca2015-07-17 10:38:15 -0400108
Mike Marshall2d4cae02016-02-04 13:48:16 -0500109 orangefs_inode = kmem_cache_alloc(orangefs_inode_cache, GFP_KERNEL);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500110 if (orangefs_inode == NULL) {
111 gossip_err("Failed to allocate orangefs_inode\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400112 return NULL;
113 }
114
115 /*
116 * We want to clear everything except for rw_semaphore and the
117 * vfs_inode.
118 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500119 memset(&orangefs_inode->refn.khandle, 0, 16);
120 orangefs_inode->refn.fs_id = ORANGEFS_FS_ID_NULL;
121 orangefs_inode->last_failed_block_index_read = 0;
122 memset(orangefs_inode->link_target, 0, sizeof(orangefs_inode->link_target));
123 orangefs_inode->pinode_flags = 0;
Mike Marshall1182fca2015-07-17 10:38:15 -0400124
125 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500126 "orangefs_alloc_inode: allocated %p\n",
127 &orangefs_inode->vfs_inode);
128 return &orangefs_inode->vfs_inode;
Mike Marshall1182fca2015-07-17 10:38:15 -0400129}
130
Peter Zijlstra0695d7d2017-02-24 16:43:36 +0100131static void orangefs_i_callback(struct rcu_head *head)
132{
133 struct inode *inode = container_of(head, struct inode, i_rcu);
134 struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
135 kmem_cache_free(orangefs_inode_cache, orangefs_inode);
136}
137
Yi Liu8bb8aef2015-11-24 15:12:14 -0500138static void orangefs_destroy_inode(struct inode *inode)
Mike Marshall1182fca2015-07-17 10:38:15 -0400139{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500140 struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
Mike Marshall1182fca2015-07-17 10:38:15 -0400141
142 gossip_debug(GOSSIP_SUPER_DEBUG,
143 "%s: deallocated %p destroying inode %pU\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500144 __func__, orangefs_inode, get_khandle_from_ino(inode));
Mike Marshall1182fca2015-07-17 10:38:15 -0400145
Peter Zijlstra0695d7d2017-02-24 16:43:36 +0100146 call_rcu(&inode->i_rcu, orangefs_i_callback);
Mike Marshall1182fca2015-07-17 10:38:15 -0400147}
148
149/*
150 * NOTE: information filled in here is typically reflected in the
151 * output of the system command 'df'
152*/
Yi Liu8bb8aef2015-11-24 15:12:14 -0500153static int orangefs_statfs(struct dentry *dentry, struct kstatfs *buf)
Mike Marshall1182fca2015-07-17 10:38:15 -0400154{
155 int ret = -ENOMEM;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500156 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshall1182fca2015-07-17 10:38:15 -0400157 int flags = 0;
158 struct super_block *sb = NULL;
159
160 sb = dentry->d_sb;
161
162 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500163 "orangefs_statfs: called on sb %p (fs_id is %d)\n",
Mike Marshall1182fca2015-07-17 10:38:15 -0400164 sb,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500165 (int)(ORANGEFS_SB(sb)->fs_id));
Mike Marshall1182fca2015-07-17 10:38:15 -0400166
Yi Liu8bb8aef2015-11-24 15:12:14 -0500167 new_op = op_alloc(ORANGEFS_VFS_OP_STATFS);
Mike Marshall1182fca2015-07-17 10:38:15 -0400168 if (!new_op)
169 return ret;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500170 new_op->upcall.req.statfs.fs_id = ORANGEFS_SB(sb)->fs_id;
Mike Marshall1182fca2015-07-17 10:38:15 -0400171
Yi Liu8bb8aef2015-11-24 15:12:14 -0500172 if (ORANGEFS_SB(sb)->flags & ORANGEFS_OPT_INTR)
173 flags = ORANGEFS_OP_INTERRUPTIBLE;
Mike Marshall1182fca2015-07-17 10:38:15 -0400174
Yi Liu8bb8aef2015-11-24 15:12:14 -0500175 ret = service_operation(new_op, "orangefs_statfs", flags);
Mike Marshall1182fca2015-07-17 10:38:15 -0400176
177 if (new_op->downcall.status < 0)
178 goto out_op_release;
179
180 gossip_debug(GOSSIP_SUPER_DEBUG,
Mike Marshallbe573662016-01-13 11:38:14 -0500181 "%s: got %ld blocks available | "
182 "%ld blocks total | %ld block size | "
183 "%ld files total | %ld files avail\n",
184 __func__,
Mike Marshall1182fca2015-07-17 10:38:15 -0400185 (long)new_op->downcall.resp.statfs.blocks_avail,
186 (long)new_op->downcall.resp.statfs.blocks_total,
Mike Marshallbe573662016-01-13 11:38:14 -0500187 (long)new_op->downcall.resp.statfs.block_size,
188 (long)new_op->downcall.resp.statfs.files_total,
189 (long)new_op->downcall.resp.statfs.files_avail);
Mike Marshall1182fca2015-07-17 10:38:15 -0400190
191 buf->f_type = sb->s_magic;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500192 memcpy(&buf->f_fsid, &ORANGEFS_SB(sb)->fs_id, sizeof(buf->f_fsid));
Mike Marshall1182fca2015-07-17 10:38:15 -0400193 buf->f_bsize = new_op->downcall.resp.statfs.block_size;
Martin Brandenburg47b49482016-02-20 14:22:40 -0500194 buf->f_namelen = ORANGEFS_NAME_MAX;
Mike Marshall1182fca2015-07-17 10:38:15 -0400195
196 buf->f_blocks = (sector_t) new_op->downcall.resp.statfs.blocks_total;
197 buf->f_bfree = (sector_t) new_op->downcall.resp.statfs.blocks_avail;
198 buf->f_bavail = (sector_t) new_op->downcall.resp.statfs.blocks_avail;
199 buf->f_files = (sector_t) new_op->downcall.resp.statfs.files_total;
200 buf->f_ffree = (sector_t) new_op->downcall.resp.statfs.files_avail;
201 buf->f_frsize = sb->s_blocksize;
202
203out_op_release:
204 op_release(new_op);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500205 gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_statfs: returning %d\n", ret);
Mike Marshall1182fca2015-07-17 10:38:15 -0400206 return ret;
207}
208
209/*
210 * Remount as initiated by VFS layer. We just need to reparse the mount
211 * options, no need to signal pvfs2-client-core about it.
212 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500213static int orangefs_remount_fs(struct super_block *sb, int *flags, char *data)
Mike Marshall1182fca2015-07-17 10:38:15 -0400214{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500215 gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_remount_fs: called\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400216 return parse_mount_options(sb, data, 1);
217}
218
219/*
220 * Remount as initiated by pvfs2-client-core on restart. This is used to
221 * repopulate mount information left from previous pvfs2-client-core.
222 *
223 * the idea here is that given a valid superblock, we're
224 * re-initializing the user space client with the initial mount
225 * information specified when the super block was first initialized.
226 * this is very different than the first initialization/creation of a
227 * superblock. we use the special service_priority_operation to make
228 * sure that the mount gets ahead of any other pending operation that
229 * is waiting for servicing. this means that the pvfs2-client won't
230 * fail to start several times for all other pending operations before
231 * the client regains all of the mount information from us.
232 * NOTE: this function assumes that the request_mutex is already acquired!
233 */
Al Viro45996492016-03-25 19:56:34 -0400234int orangefs_remount(struct orangefs_sb_info_s *orangefs_sb)
Mike Marshall1182fca2015-07-17 10:38:15 -0400235{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500236 struct orangefs_kernel_op_s *new_op;
Mike Marshall1182fca2015-07-17 10:38:15 -0400237 int ret = -EINVAL;
238
Yi Liu8bb8aef2015-11-24 15:12:14 -0500239 gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_remount: called\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400240
Yi Liu8bb8aef2015-11-24 15:12:14 -0500241 new_op = op_alloc(ORANGEFS_VFS_OP_FS_MOUNT);
Mike Marshall1182fca2015-07-17 10:38:15 -0400242 if (!new_op)
243 return -ENOMEM;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500244 strncpy(new_op->upcall.req.fs_mount.orangefs_config_server,
Al Viro45996492016-03-25 19:56:34 -0400245 orangefs_sb->devname,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500246 ORANGEFS_MAX_SERVER_ADDR_LEN);
Mike Marshall1182fca2015-07-17 10:38:15 -0400247
248 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500249 "Attempting ORANGEFS Remount via host %s\n",
250 new_op->upcall.req.fs_mount.orangefs_config_server);
Mike Marshall1182fca2015-07-17 10:38:15 -0400251
252 /*
Mike Marshalladcf34a2016-02-24 16:54:27 -0500253 * we assume that the calling function has already acquired the
Mike Marshall1182fca2015-07-17 10:38:15 -0400254 * request_mutex to prevent other operations from bypassing
255 * this one
256 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500257 ret = service_operation(new_op, "orangefs_remount",
Mike Marshalladcf34a2016-02-24 16:54:27 -0500258 ORANGEFS_OP_PRIORITY | ORANGEFS_OP_NO_MUTEX);
Mike Marshall1182fca2015-07-17 10:38:15 -0400259 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500260 "orangefs_remount: mount got return value of %d\n",
Mike Marshall1182fca2015-07-17 10:38:15 -0400261 ret);
262 if (ret == 0) {
263 /*
264 * store the id assigned to this sb -- it's just a
265 * short-lived mapping that the system interface uses
266 * to map this superblock to a particular mount entry
267 */
Al Viro45996492016-03-25 19:56:34 -0400268 orangefs_sb->id = new_op->downcall.resp.fs_mount.id;
269 orangefs_sb->mount_pending = 0;
Mike Marshall1182fca2015-07-17 10:38:15 -0400270 }
271
272 op_release(new_op);
Martin Brandenburg482664d2016-08-12 12:02:31 -0400273
Mike Marshallf60fbdb2016-10-03 15:07:36 -0400274 if (orangefs_userspace_version >= 20906) {
Martin Brandenburg482664d2016-08-12 12:02:31 -0400275 new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES);
276 if (!new_op)
277 return -ENOMEM;
278 new_op->upcall.req.features.features = 0;
Martin Brandenburgcefdc262017-04-06 18:11:00 -0400279 ret = service_operation(new_op, "orangefs_features",
280 ORANGEFS_OP_PRIORITY | ORANGEFS_OP_NO_MUTEX);
281 if (!ret)
282 orangefs_features =
283 new_op->downcall.resp.features.features;
284 else
285 orangefs_features = 0;
Martin Brandenburg482664d2016-08-12 12:02:31 -0400286 op_release(new_op);
287 } else {
288 orangefs_features = 0;
289 }
290
Mike Marshall1182fca2015-07-17 10:38:15 -0400291 return ret;
292}
293
294int fsid_key_table_initialize(void)
295{
296 return 0;
297}
298
299void fsid_key_table_finalize(void)
300{
301}
302
303/* Called whenever the VFS dirties the inode in response to atime updates */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500304static void orangefs_dirty_inode(struct inode *inode, int flags)
Mike Marshall1182fca2015-07-17 10:38:15 -0400305{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500306 struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
Mike Marshall1182fca2015-07-17 10:38:15 -0400307
308 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500309 "orangefs_dirty_inode: %pU\n",
Mike Marshall1182fca2015-07-17 10:38:15 -0400310 get_khandle_from_ino(inode));
Yi Liu8bb8aef2015-11-24 15:12:14 -0500311 SetAtimeFlag(orangefs_inode);
Mike Marshall1182fca2015-07-17 10:38:15 -0400312}
313
Yi Liu8bb8aef2015-11-24 15:12:14 -0500314static const struct super_operations orangefs_s_ops = {
315 .alloc_inode = orangefs_alloc_inode,
316 .destroy_inode = orangefs_destroy_inode,
317 .dirty_inode = orangefs_dirty_inode,
Mike Marshall1182fca2015-07-17 10:38:15 -0400318 .drop_inode = generic_delete_inode,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500319 .statfs = orangefs_statfs,
320 .remount_fs = orangefs_remount_fs,
David Howells4dfdb712017-07-05 16:25:45 +0100321 .show_options = orangefs_show_options,
Mike Marshall1182fca2015-07-17 10:38:15 -0400322};
323
Yi Liu8bb8aef2015-11-24 15:12:14 -0500324static struct dentry *orangefs_fh_to_dentry(struct super_block *sb,
Mike Marshall1182fca2015-07-17 10:38:15 -0400325 struct fid *fid,
326 int fh_len,
327 int fh_type)
328{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500329 struct orangefs_object_kref refn;
Mike Marshall1182fca2015-07-17 10:38:15 -0400330
331 if (fh_len < 5 || fh_type > 2)
332 return NULL;
333
Yi Liu8bb8aef2015-11-24 15:12:14 -0500334 ORANGEFS_khandle_from(&(refn.khandle), fid->raw, 16);
Mike Marshall1182fca2015-07-17 10:38:15 -0400335 refn.fs_id = (u32) fid->raw[4];
336 gossip_debug(GOSSIP_SUPER_DEBUG,
337 "fh_to_dentry: handle %pU, fs_id %d\n",
338 &refn.khandle,
339 refn.fs_id);
340
Yi Liu8bb8aef2015-11-24 15:12:14 -0500341 return d_obtain_alias(orangefs_iget(sb, &refn));
Mike Marshall1182fca2015-07-17 10:38:15 -0400342}
343
Yi Liu8bb8aef2015-11-24 15:12:14 -0500344static int orangefs_encode_fh(struct inode *inode,
Mike Marshall1182fca2015-07-17 10:38:15 -0400345 __u32 *fh,
346 int *max_len,
347 struct inode *parent)
348{
349 int len = parent ? 10 : 5;
350 int type = 1;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500351 struct orangefs_object_kref refn;
Mike Marshall1182fca2015-07-17 10:38:15 -0400352
353 if (*max_len < len) {
354 gossip_lerr("fh buffer is too small for encoding\n");
355 *max_len = len;
356 type = 255;
357 goto out;
358 }
359
Yi Liu8bb8aef2015-11-24 15:12:14 -0500360 refn = ORANGEFS_I(inode)->refn;
361 ORANGEFS_khandle_to(&refn.khandle, fh, 16);
Mike Marshall1182fca2015-07-17 10:38:15 -0400362 fh[4] = refn.fs_id;
363
364 gossip_debug(GOSSIP_SUPER_DEBUG,
365 "Encoding fh: handle %pU, fsid %u\n",
366 &refn.khandle,
367 refn.fs_id);
368
369
370 if (parent) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500371 refn = ORANGEFS_I(parent)->refn;
372 ORANGEFS_khandle_to(&refn.khandle, (char *) fh + 20, 16);
Mike Marshall1182fca2015-07-17 10:38:15 -0400373 fh[9] = refn.fs_id;
374
375 type = 2;
376 gossip_debug(GOSSIP_SUPER_DEBUG,
377 "Encoding parent: handle %pU, fsid %u\n",
378 &refn.khandle,
379 refn.fs_id);
380 }
381 *max_len = len;
382
383out:
384 return type;
385}
386
Julia Lawallacaca362016-01-01 10:01:52 +0100387static const struct export_operations orangefs_export_ops = {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500388 .encode_fh = orangefs_encode_fh,
389 .fh_to_dentry = orangefs_fh_to_dentry,
Mike Marshall1182fca2015-07-17 10:38:15 -0400390};
391
Martin Brandenburg9d286b02017-04-25 15:38:05 -0400392static int orangefs_unmount(int id, __s32 fs_id, const char *devname)
393{
394 struct orangefs_kernel_op_s *op;
395 int r;
396 op = op_alloc(ORANGEFS_VFS_OP_FS_UMOUNT);
397 if (!op)
398 return -ENOMEM;
399 op->upcall.req.fs_umount.id = id;
400 op->upcall.req.fs_umount.fs_id = fs_id;
401 strncpy(op->upcall.req.fs_umount.orangefs_config_server,
402 devname, ORANGEFS_MAX_SERVER_ADDR_LEN);
403 r = service_operation(op, "orangefs_fs_umount", 0);
404 /* Not much to do about an error here. */
405 if (r)
406 gossip_err("orangefs_unmount: service_operation %d\n", r);
407 op_release(op);
408 return r;
409}
410
Yi Liu8bb8aef2015-11-24 15:12:14 -0500411static int orangefs_fill_sb(struct super_block *sb,
412 struct orangefs_fs_mount_response *fs_mount,
Al Viro5c0dbbc2015-10-08 20:22:43 -0400413 void *data, int silent)
Mike Marshall1182fca2015-07-17 10:38:15 -0400414{
415 int ret = -EINVAL;
416 struct inode *root = NULL;
417 struct dentry *root_dentry = NULL;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500418 struct orangefs_object_kref root_object;
Mike Marshall1182fca2015-07-17 10:38:15 -0400419
Yi Liu8bb8aef2015-11-24 15:12:14 -0500420 /* alloc and init our private orangefs sb info */
Martin Brandenburg05d31c52016-03-18 13:36:45 -0400421 sb->s_fs_info = kzalloc(sizeof(struct orangefs_sb_info_s), GFP_KERNEL);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500422 if (!ORANGEFS_SB(sb))
Mike Marshall1182fca2015-07-17 10:38:15 -0400423 return -ENOMEM;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500424 ORANGEFS_SB(sb)->sb = sb;
Mike Marshall1182fca2015-07-17 10:38:15 -0400425
Yi Liu8bb8aef2015-11-24 15:12:14 -0500426 ORANGEFS_SB(sb)->root_khandle = fs_mount->root_khandle;
427 ORANGEFS_SB(sb)->fs_id = fs_mount->fs_id;
428 ORANGEFS_SB(sb)->id = fs_mount->id;
Mike Marshall1182fca2015-07-17 10:38:15 -0400429
Al Viro5c0dbbc2015-10-08 20:22:43 -0400430 if (data) {
431 ret = parse_mount_options(sb, data, silent);
Mike Marshall1182fca2015-07-17 10:38:15 -0400432 if (ret)
433 return ret;
434 }
435
436 /* Hang the xattr handlers off the superblock */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500437 sb->s_xattr = orangefs_xattr_handlers;
438 sb->s_magic = ORANGEFS_SUPER_MAGIC;
439 sb->s_op = &orangefs_s_ops;
440 sb->s_d_op = &orangefs_dentry_operations;
Mike Marshall1182fca2015-07-17 10:38:15 -0400441
Yi Liu8bb8aef2015-11-24 15:12:14 -0500442 sb->s_blocksize = orangefs_bufmap_size_query();
443 sb->s_blocksize_bits = orangefs_bufmap_shift_query();
Mike Marshall1182fca2015-07-17 10:38:15 -0400444 sb->s_maxbytes = MAX_LFS_FILESIZE;
445
Yi Liu8bb8aef2015-11-24 15:12:14 -0500446 root_object.khandle = ORANGEFS_SB(sb)->root_khandle;
447 root_object.fs_id = ORANGEFS_SB(sb)->fs_id;
Mike Marshall1182fca2015-07-17 10:38:15 -0400448 gossip_debug(GOSSIP_SUPER_DEBUG,
449 "get inode %pU, fsid %d\n",
450 &root_object.khandle,
451 root_object.fs_id);
452
Yi Liu8bb8aef2015-11-24 15:12:14 -0500453 root = orangefs_iget(sb, &root_object);
Mike Marshall1182fca2015-07-17 10:38:15 -0400454 if (IS_ERR(root))
455 return PTR_ERR(root);
456
457 gossip_debug(GOSSIP_SUPER_DEBUG,
458 "Allocated root inode [%p] with mode %x\n",
459 root,
460 root->i_mode);
461
462 /* allocates and places root dentry in dcache */
463 root_dentry = d_make_root(root);
Al Virob05a7852015-10-08 20:18:00 -0400464 if (!root_dentry)
Mike Marshall1182fca2015-07-17 10:38:15 -0400465 return -ENOMEM;
Mike Marshall1182fca2015-07-17 10:38:15 -0400466
Yi Liu8bb8aef2015-11-24 15:12:14 -0500467 sb->s_export_op = &orangefs_export_ops;
Mike Marshall1182fca2015-07-17 10:38:15 -0400468 sb->s_root = root_dentry;
469 return 0;
470}
471
Yi Liu8bb8aef2015-11-24 15:12:14 -0500472struct dentry *orangefs_mount(struct file_system_type *fst,
Mike Marshall1182fca2015-07-17 10:38:15 -0400473 int flags,
474 const char *devname,
475 void *data)
476{
477 int ret = -EINVAL;
478 struct super_block *sb = ERR_PTR(-EINVAL);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500479 struct orangefs_kernel_op_s *new_op;
Mike Marshall1be21f82015-09-29 15:26:37 -0400480 struct dentry *d = ERR_PTR(-EINVAL);
Mike Marshall1182fca2015-07-17 10:38:15 -0400481
482 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500483 "orangefs_mount: called with devname %s\n",
Mike Marshall1182fca2015-07-17 10:38:15 -0400484 devname);
485
486 if (!devname) {
487 gossip_err("ERROR: device name not specified.\n");
488 return ERR_PTR(-EINVAL);
489 }
490
Yi Liu8bb8aef2015-11-24 15:12:14 -0500491 new_op = op_alloc(ORANGEFS_VFS_OP_FS_MOUNT);
Mike Marshall1182fca2015-07-17 10:38:15 -0400492 if (!new_op)
493 return ERR_PTR(-ENOMEM);
494
Yi Liu8bb8aef2015-11-24 15:12:14 -0500495 strncpy(new_op->upcall.req.fs_mount.orangefs_config_server,
Mike Marshall1182fca2015-07-17 10:38:15 -0400496 devname,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500497 ORANGEFS_MAX_SERVER_ADDR_LEN);
Mike Marshall1182fca2015-07-17 10:38:15 -0400498
499 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500500 "Attempting ORANGEFS Mount via host %s\n",
501 new_op->upcall.req.fs_mount.orangefs_config_server);
Mike Marshall1182fca2015-07-17 10:38:15 -0400502
Yi Liu8bb8aef2015-11-24 15:12:14 -0500503 ret = service_operation(new_op, "orangefs_mount", 0);
Mike Marshall1182fca2015-07-17 10:38:15 -0400504 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500505 "orangefs_mount: mount got return value of %d\n", ret);
Mike Marshall1182fca2015-07-17 10:38:15 -0400506 if (ret)
507 goto free_op;
508
Yi Liu8bb8aef2015-11-24 15:12:14 -0500509 if (new_op->downcall.resp.fs_mount.fs_id == ORANGEFS_FS_ID_NULL) {
Mike Marshall1182fca2015-07-17 10:38:15 -0400510 gossip_err("ERROR: Retrieved null fs_id\n");
511 ret = -EINVAL;
512 goto free_op;
513 }
514
Mike Marshall1be21f82015-09-29 15:26:37 -0400515 sb = sget(fst, NULL, set_anon_super, flags, NULL);
516
517 if (IS_ERR(sb)) {
518 d = ERR_CAST(sb);
Martin Brandenburg9d286b02017-04-25 15:38:05 -0400519 orangefs_unmount(new_op->downcall.resp.fs_mount.id,
520 new_op->downcall.resp.fs_mount.fs_id, devname);
Mike Marshall1182fca2015-07-17 10:38:15 -0400521 goto free_op;
522 }
523
Yi Liu8bb8aef2015-11-24 15:12:14 -0500524 ret = orangefs_fill_sb(sb,
Al Viro5c0dbbc2015-10-08 20:22:43 -0400525 &new_op->downcall.resp.fs_mount, data,
Mike Marshall1be21f82015-09-29 15:26:37 -0400526 flags & MS_SILENT ? 1 : 0);
527
528 if (ret) {
529 d = ERR_PTR(ret);
Martin Brandenburg1ec16882017-04-14 14:22:41 -0400530 goto free_sb_and_op;
Mike Marshall1be21f82015-09-29 15:26:37 -0400531 }
Mike Marshall1182fca2015-07-17 10:38:15 -0400532
533 /*
534 * on successful mount, store the devname and data
535 * used
536 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500537 strncpy(ORANGEFS_SB(sb)->devname,
Mike Marshall1182fca2015-07-17 10:38:15 -0400538 devname,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500539 ORANGEFS_MAX_SERVER_ADDR_LEN);
Mike Marshall1182fca2015-07-17 10:38:15 -0400540
541 /* mount_pending must be cleared */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500542 ORANGEFS_SB(sb)->mount_pending = 0;
Mike Marshall1182fca2015-07-17 10:38:15 -0400543
544 /*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500545 * finally, add this sb to our list of known orangefs
Mike Marshall1182fca2015-07-17 10:38:15 -0400546 * sb's
547 */
Al Viro45996492016-03-25 19:56:34 -0400548 gossip_debug(GOSSIP_SUPER_DEBUG,
549 "Adding SB %p to orangefs superblocks\n",
550 ORANGEFS_SB(sb));
551 spin_lock(&orangefs_superblocks_lock);
552 list_add_tail(&ORANGEFS_SB(sb)->list, &orangefs_superblocks);
553 spin_unlock(&orangefs_superblocks_lock);
Mike Marshall1182fca2015-07-17 10:38:15 -0400554 op_release(new_op);
Martin Brandenburg482664d2016-08-12 12:02:31 -0400555
Martin Brandenburg1ec16882017-04-14 14:22:41 -0400556 /* Must be removed from the list now. */
557 ORANGEFS_SB(sb)->no_list = 0;
558
Mike Marshallf60fbdb2016-10-03 15:07:36 -0400559 if (orangefs_userspace_version >= 20906) {
Martin Brandenburg482664d2016-08-12 12:02:31 -0400560 new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES);
561 if (!new_op)
562 return ERR_PTR(-ENOMEM);
563 new_op->upcall.req.features.features = 0;
564 ret = service_operation(new_op, "orangefs_features", 0);
565 orangefs_features = new_op->downcall.resp.features.features;
566 op_release(new_op);
567 } else {
568 orangefs_features = 0;
569 }
570
Mike Marshall1be21f82015-09-29 15:26:37 -0400571 return dget(sb->s_root);
Mike Marshall1182fca2015-07-17 10:38:15 -0400572
Martin Brandenburg1ec16882017-04-14 14:22:41 -0400573free_sb_and_op:
574 /* Will call orangefs_kill_sb with sb not in list. */
575 ORANGEFS_SB(sb)->no_list = 1;
Martin Brandenburg9d286b02017-04-25 15:38:05 -0400576 /* ORANGEFS_VFS_OP_FS_UMOUNT is done by orangefs_kill_sb. */
Martin Brandenburg1ec16882017-04-14 14:22:41 -0400577 deactivate_locked_super(sb);
Mike Marshall1182fca2015-07-17 10:38:15 -0400578free_op:
Yi Liu8bb8aef2015-11-24 15:12:14 -0500579 gossip_err("orangefs_mount: mount request failed with %d\n", ret);
Mike Marshall1182fca2015-07-17 10:38:15 -0400580 if (ret == -EINVAL) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500581 gossip_err("Ensure that all orangefs-servers have the same FS configuration files\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400582 gossip_err("Look at pvfs2-client-core log file (typically /tmp/pvfs2-client.log) for more details\n");
583 }
584
585 op_release(new_op);
586
Mike Marshall1be21f82015-09-29 15:26:37 -0400587 return d;
Mike Marshall1182fca2015-07-17 10:38:15 -0400588}
589
Yi Liu8bb8aef2015-11-24 15:12:14 -0500590void orangefs_kill_sb(struct super_block *sb)
Mike Marshall1182fca2015-07-17 10:38:15 -0400591{
Martin Brandenburg9d286b02017-04-25 15:38:05 -0400592 int r;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500593 gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_kill_sb: called\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400594
Al Viro524b1d32016-02-16 21:08:29 -0500595 /* provided sb cleanup */
596 kill_anon_super(sb);
597
Mike Marshall1182fca2015-07-17 10:38:15 -0400598 /*
599 * issue the unmount to userspace to tell it to remove the
600 * dynamic mount info it has for this superblock
601 */
Martin Brandenburg9d286b02017-04-25 15:38:05 -0400602 r = orangefs_unmount(ORANGEFS_SB(sb)->id, ORANGEFS_SB(sb)->fs_id,
603 ORANGEFS_SB(sb)->devname);
604 if (!r)
605 ORANGEFS_SB(sb)->mount_pending = 1;
Mike Marshall1182fca2015-07-17 10:38:15 -0400606
Martin Brandenburg1ec16882017-04-14 14:22:41 -0400607 if (!ORANGEFS_SB(sb)->no_list) {
608 /* remove the sb from our list of orangefs specific sb's */
609 spin_lock(&orangefs_superblocks_lock);
610 /* not list_del_init */
611 __list_del_entry(&ORANGEFS_SB(sb)->list);
612 ORANGEFS_SB(sb)->list.prev = NULL;
613 spin_unlock(&orangefs_superblocks_lock);
614 }
Al Viro45996492016-03-25 19:56:34 -0400615
616 /*
617 * make sure that ORANGEFS_DEV_REMOUNT_ALL loop that might've seen us
618 * gets completed before we free the dang thing.
619 */
Martin Brandenburg1d503612016-08-16 11:38:14 -0400620 mutex_lock(&orangefs_request_mutex);
621 mutex_unlock(&orangefs_request_mutex);
Mike Marshall1182fca2015-07-17 10:38:15 -0400622
Yi Liu8bb8aef2015-11-24 15:12:14 -0500623 /* free the orangefs superblock private data */
624 kfree(ORANGEFS_SB(sb));
Mike Marshall1182fca2015-07-17 10:38:15 -0400625}
626
Yi Liu8bb8aef2015-11-24 15:12:14 -0500627int orangefs_inode_cache_initialize(void)
Mike Marshall1182fca2015-07-17 10:38:15 -0400628{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500629 orangefs_inode_cache = kmem_cache_create("orangefs_inode_cache",
630 sizeof(struct orangefs_inode_s),
Mike Marshall1182fca2015-07-17 10:38:15 -0400631 0,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500632 ORANGEFS_CACHE_CREATE_FLAGS,
633 orangefs_inode_cache_ctor);
Mike Marshall1182fca2015-07-17 10:38:15 -0400634
Yi Liu8bb8aef2015-11-24 15:12:14 -0500635 if (!orangefs_inode_cache) {
636 gossip_err("Cannot create orangefs_inode_cache\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400637 return -ENOMEM;
638 }
639 return 0;
640}
641
Yi Liu8bb8aef2015-11-24 15:12:14 -0500642int orangefs_inode_cache_finalize(void)
Mike Marshall1182fca2015-07-17 10:38:15 -0400643{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500644 kmem_cache_destroy(orangefs_inode_cache);
Mike Marshall1182fca2015-07-17 10:38:15 -0400645 return 0;
646}