blob: 47ebd9bfd1a1be6c638261c4167d530cd5cb3b2a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Mike Marshall1182fca2015-07-17 10:38:15 -04002/*
3 * (C) 2001 Clemson University and The University of Chicago
4 *
5 * See COPYING in top-level directory.
6 */
7
8#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -05009#include "orangefs-kernel.h"
10#include "orangefs-bufmap.h"
Mike Marshall1182fca2015-07-17 10:38:15 -040011
12#include <linux/parser.h>
13
Yi Liu8bb8aef2015-11-24 15:12:14 -050014/* a cache for orangefs-inode objects (i.e. orangefs inode private data) */
15static struct kmem_cache *orangefs_inode_cache;
Mike Marshall1182fca2015-07-17 10:38:15 -040016
Yi Liu8bb8aef2015-11-24 15:12:14 -050017/* list for storing orangefs specific superblocks in use */
18LIST_HEAD(orangefs_superblocks);
Mike Marshall1182fca2015-07-17 10:38:15 -040019
Yi Liu8bb8aef2015-11-24 15:12:14 -050020DEFINE_SPINLOCK(orangefs_superblocks_lock);
Mike Marshall1182fca2015-07-17 10:38:15 -040021
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
Martin Brandenburg482664d2016-08-12 12:02:31 -040037uint64_t orangefs_features;
Mike Marshall1182fca2015-07-17 10:38:15 -040038
David Howells4dfdb712017-07-05 16:25:45 +010039static 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
Mike Marshall1182fca2015-07-17 10:38:15 -040052static int parse_mount_options(struct super_block *sb, char *options,
53 int silent)
54{
Yi Liu8bb8aef2015-11-24 15:12:14 -050055 struct orangefs_sb_info_s *orangefs_sb = ORANGEFS_SB(sb);
Mike Marshall1182fca2015-07-17 10:38:15 -040056 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;
Yi Liu8bb8aef2015-11-24 15:12:14 -050064 orangefs_sb->flags &= ~ORANGEFS_OPT_INTR;
65 orangefs_sb->flags &= ~ORANGEFS_OPT_LOCAL_LOCK;
Mike Marshall1182fca2015-07-17 10:38:15 -040066
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:
Yi Liu8bb8aef2015-11-24 15:12:14 -050079 orangefs_sb->flags |= ORANGEFS_OPT_INTR;
Mike Marshall1182fca2015-07-17 10:38:15 -040080 break;
81 case Opt_local_lock:
Yi Liu8bb8aef2015-11-24 15:12:14 -050082 orangefs_sb->flags |= ORANGEFS_OPT_LOCAL_LOCK;
Mike Marshall1182fca2015-07-17 10:38:15 -040083 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
Yi Liu8bb8aef2015-11-24 15:12:14 -050096static void orangefs_inode_cache_ctor(void *req)
Mike Marshall1182fca2015-07-17 10:38:15 -040097{
Yi Liu8bb8aef2015-11-24 15:12:14 -050098 struct orangefs_inode_s *orangefs_inode = req;
Mike Marshall1182fca2015-07-17 10:38:15 -040099
Yi Liu8bb8aef2015-11-24 15:12:14 -0500100 inode_init_once(&orangefs_inode->vfs_inode);
101 init_rwsem(&orangefs_inode->xattr_sem);
Mike Marshall1182fca2015-07-17 10:38:15 -0400102
Yi Liu8bb8aef2015-11-24 15:12:14 -0500103 orangefs_inode->vfs_inode.i_version = 1;
Mike Marshall1182fca2015-07-17 10:38:15 -0400104}
105
Yi Liu8bb8aef2015-11-24 15:12:14 -0500106static struct inode *orangefs_alloc_inode(struct super_block *sb)
Mike Marshall1182fca2015-07-17 10:38:15 -0400107{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500108 struct orangefs_inode_s *orangefs_inode;
Mike Marshall1182fca2015-07-17 10:38:15 -0400109
Mike Marshall2d4cae02016-02-04 13:48:16 -0500110 orangefs_inode = kmem_cache_alloc(orangefs_inode_cache, GFP_KERNEL);
Markus Elfring07a25852017-08-17 21:00:07 +0200111 if (!orangefs_inode)
Mike Marshall1182fca2015-07-17 10:38:15 -0400112 return NULL;
Mike Marshall1182fca2015-07-17 10:38:15 -0400113
114 /*
115 * We want to clear everything except for rw_semaphore and the
116 * vfs_inode.
117 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500118 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;
Mike Marshall1182fca2015-07-17 10:38:15 -0400123
124 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500125 "orangefs_alloc_inode: allocated %p\n",
126 &orangefs_inode->vfs_inode);
127 return &orangefs_inode->vfs_inode;
Mike Marshall1182fca2015-07-17 10:38:15 -0400128}
129
Peter Zijlstra0695d7d2017-02-24 16:43:36 +0100130static 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
Yi Liu8bb8aef2015-11-24 15:12:14 -0500137static void orangefs_destroy_inode(struct inode *inode)
Mike Marshall1182fca2015-07-17 10:38:15 -0400138{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500139 struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
Mike Marshall1182fca2015-07-17 10:38:15 -0400140
141 gossip_debug(GOSSIP_SUPER_DEBUG,
142 "%s: deallocated %p destroying inode %pU\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500143 __func__, orangefs_inode, get_khandle_from_ino(inode));
Mike Marshall1182fca2015-07-17 10:38:15 -0400144
Peter Zijlstra0695d7d2017-02-24 16:43:36 +0100145 call_rcu(&inode->i_rcu, orangefs_i_callback);
Mike Marshall1182fca2015-07-17 10:38:15 -0400146}
147
148/*
149 * NOTE: information filled in here is typically reflected in the
150 * output of the system command 'df'
151*/
Yi Liu8bb8aef2015-11-24 15:12:14 -0500152static int orangefs_statfs(struct dentry *dentry, struct kstatfs *buf)
Mike Marshall1182fca2015-07-17 10:38:15 -0400153{
154 int ret = -ENOMEM;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500155 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshall1182fca2015-07-17 10:38:15 -0400156 int flags = 0;
157 struct super_block *sb = NULL;
158
159 sb = dentry->d_sb;
160
161 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500162 "orangefs_statfs: called on sb %p (fs_id is %d)\n",
Mike Marshall1182fca2015-07-17 10:38:15 -0400163 sb,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500164 (int)(ORANGEFS_SB(sb)->fs_id));
Mike Marshall1182fca2015-07-17 10:38:15 -0400165
Yi Liu8bb8aef2015-11-24 15:12:14 -0500166 new_op = op_alloc(ORANGEFS_VFS_OP_STATFS);
Mike Marshall1182fca2015-07-17 10:38:15 -0400167 if (!new_op)
168 return ret;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500169 new_op->upcall.req.statfs.fs_id = ORANGEFS_SB(sb)->fs_id;
Mike Marshall1182fca2015-07-17 10:38:15 -0400170
Yi Liu8bb8aef2015-11-24 15:12:14 -0500171 if (ORANGEFS_SB(sb)->flags & ORANGEFS_OPT_INTR)
172 flags = ORANGEFS_OP_INTERRUPTIBLE;
Mike Marshall1182fca2015-07-17 10:38:15 -0400173
Yi Liu8bb8aef2015-11-24 15:12:14 -0500174 ret = service_operation(new_op, "orangefs_statfs", flags);
Mike Marshall1182fca2015-07-17 10:38:15 -0400175
176 if (new_op->downcall.status < 0)
177 goto out_op_release;
178
179 gossip_debug(GOSSIP_SUPER_DEBUG,
Mike Marshallbe573662016-01-13 11:38:14 -0500180 "%s: got %ld blocks available | "
181 "%ld blocks total | %ld block size | "
182 "%ld files total | %ld files avail\n",
183 __func__,
Mike Marshall1182fca2015-07-17 10:38:15 -0400184 (long)new_op->downcall.resp.statfs.blocks_avail,
185 (long)new_op->downcall.resp.statfs.blocks_total,
Mike Marshallbe573662016-01-13 11:38:14 -0500186 (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);
Mike Marshall1182fca2015-07-17 10:38:15 -0400189
190 buf->f_type = sb->s_magic;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500191 memcpy(&buf->f_fsid, &ORANGEFS_SB(sb)->fs_id, sizeof(buf->f_fsid));
Mike Marshall1182fca2015-07-17 10:38:15 -0400192 buf->f_bsize = new_op->downcall.resp.statfs.block_size;
Martin Brandenburg47b49482016-02-20 14:22:40 -0500193 buf->f_namelen = ORANGEFS_NAME_MAX;
Mike Marshall1182fca2015-07-17 10:38:15 -0400194
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);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500204 gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_statfs: returning %d\n", ret);
Mike Marshall1182fca2015-07-17 10:38:15 -0400205 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 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500212static int orangefs_remount_fs(struct super_block *sb, int *flags, char *data)
Mike Marshall1182fca2015-07-17 10:38:15 -0400213{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500214 gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_remount_fs: called\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400215 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 */
Al Viro45996492016-03-25 19:56:34 -0400233int orangefs_remount(struct orangefs_sb_info_s *orangefs_sb)
Mike Marshall1182fca2015-07-17 10:38:15 -0400234{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500235 struct orangefs_kernel_op_s *new_op;
Mike Marshall1182fca2015-07-17 10:38:15 -0400236 int ret = -EINVAL;
237
Yi Liu8bb8aef2015-11-24 15:12:14 -0500238 gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_remount: called\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400239
Yi Liu8bb8aef2015-11-24 15:12:14 -0500240 new_op = op_alloc(ORANGEFS_VFS_OP_FS_MOUNT);
Mike Marshall1182fca2015-07-17 10:38:15 -0400241 if (!new_op)
242 return -ENOMEM;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500243 strncpy(new_op->upcall.req.fs_mount.orangefs_config_server,
Al Viro45996492016-03-25 19:56:34 -0400244 orangefs_sb->devname,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500245 ORANGEFS_MAX_SERVER_ADDR_LEN);
Mike Marshall1182fca2015-07-17 10:38:15 -0400246
247 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500248 "Attempting ORANGEFS Remount via host %s\n",
249 new_op->upcall.req.fs_mount.orangefs_config_server);
Mike Marshall1182fca2015-07-17 10:38:15 -0400250
251 /*
Mike Marshalladcf34a2016-02-24 16:54:27 -0500252 * we assume that the calling function has already acquired the
Mike Marshall1182fca2015-07-17 10:38:15 -0400253 * request_mutex to prevent other operations from bypassing
254 * this one
255 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500256 ret = service_operation(new_op, "orangefs_remount",
Mike Marshalladcf34a2016-02-24 16:54:27 -0500257 ORANGEFS_OP_PRIORITY | ORANGEFS_OP_NO_MUTEX);
Mike Marshall1182fca2015-07-17 10:38:15 -0400258 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500259 "orangefs_remount: mount got return value of %d\n",
Mike Marshall1182fca2015-07-17 10:38:15 -0400260 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 */
Al Viro45996492016-03-25 19:56:34 -0400267 orangefs_sb->id = new_op->downcall.resp.fs_mount.id;
268 orangefs_sb->mount_pending = 0;
Mike Marshall1182fca2015-07-17 10:38:15 -0400269 }
270
271 op_release(new_op);
Martin Brandenburg482664d2016-08-12 12:02:31 -0400272
Mike Marshallf60fbdb2016-10-03 15:07:36 -0400273 if (orangefs_userspace_version >= 20906) {
Martin Brandenburg482664d2016-08-12 12:02:31 -0400274 new_op = op_alloc(ORANGEFS_VFS_OP_FEATURES);
275 if (!new_op)
276 return -ENOMEM;
277 new_op->upcall.req.features.features = 0;
Martin Brandenburgcefdc262017-04-06 18:11:00 -0400278 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;
Martin Brandenburg482664d2016-08-12 12:02:31 -0400285 op_release(new_op);
286 } else {
287 orangefs_features = 0;
288 }
289
Mike Marshall1182fca2015-07-17 10:38:15 -0400290 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 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500303static void orangefs_dirty_inode(struct inode *inode, int flags)
Mike Marshall1182fca2015-07-17 10:38:15 -0400304{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500305 struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode);
Mike Marshall1182fca2015-07-17 10:38:15 -0400306
307 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500308 "orangefs_dirty_inode: %pU\n",
Mike Marshall1182fca2015-07-17 10:38:15 -0400309 get_khandle_from_ino(inode));
Yi Liu8bb8aef2015-11-24 15:12:14 -0500310 SetAtimeFlag(orangefs_inode);
Mike Marshall1182fca2015-07-17 10:38:15 -0400311}
312
Yi Liu8bb8aef2015-11-24 15:12:14 -0500313static 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,
Mike Marshall1182fca2015-07-17 10:38:15 -0400317 .drop_inode = generic_delete_inode,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500318 .statfs = orangefs_statfs,
319 .remount_fs = orangefs_remount_fs,
David Howells4dfdb712017-07-05 16:25:45 +0100320 .show_options = orangefs_show_options,
Mike Marshall1182fca2015-07-17 10:38:15 -0400321};
322
Yi Liu8bb8aef2015-11-24 15:12:14 -0500323static struct dentry *orangefs_fh_to_dentry(struct super_block *sb,
Mike Marshall1182fca2015-07-17 10:38:15 -0400324 struct fid *fid,
325 int fh_len,
326 int fh_type)
327{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500328 struct orangefs_object_kref refn;
Mike Marshall1182fca2015-07-17 10:38:15 -0400329
330 if (fh_len < 5 || fh_type > 2)
331 return NULL;
332
Yi Liu8bb8aef2015-11-24 15:12:14 -0500333 ORANGEFS_khandle_from(&(refn.khandle), fid->raw, 16);
Mike Marshall1182fca2015-07-17 10:38:15 -0400334 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
Yi Liu8bb8aef2015-11-24 15:12:14 -0500340 return d_obtain_alias(orangefs_iget(sb, &refn));
Mike Marshall1182fca2015-07-17 10:38:15 -0400341}
342
Yi Liu8bb8aef2015-11-24 15:12:14 -0500343static int orangefs_encode_fh(struct inode *inode,
Mike Marshall1182fca2015-07-17 10:38:15 -0400344 __u32 *fh,
345 int *max_len,
346 struct inode *parent)
347{
348 int len = parent ? 10 : 5;
349 int type = 1;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500350 struct orangefs_object_kref refn;
Mike Marshall1182fca2015-07-17 10:38:15 -0400351
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
Yi Liu8bb8aef2015-11-24 15:12:14 -0500359 refn = ORANGEFS_I(inode)->refn;
360 ORANGEFS_khandle_to(&refn.khandle, fh, 16);
Mike Marshall1182fca2015-07-17 10:38:15 -0400361 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) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500370 refn = ORANGEFS_I(parent)->refn;
371 ORANGEFS_khandle_to(&refn.khandle, (char *) fh + 20, 16);
Mike Marshall1182fca2015-07-17 10:38:15 -0400372 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
Julia Lawallacaca362016-01-01 10:01:52 +0100386static const struct export_operations orangefs_export_ops = {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500387 .encode_fh = orangefs_encode_fh,
388 .fh_to_dentry = orangefs_fh_to_dentry,
Mike Marshall1182fca2015-07-17 10:38:15 -0400389};
390
Martin Brandenburg9d286b02017-04-25 15:38:05 -0400391static 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
Yi Liu8bb8aef2015-11-24 15:12:14 -0500410static int orangefs_fill_sb(struct super_block *sb,
411 struct orangefs_fs_mount_response *fs_mount,
Al Viro5c0dbbc2015-10-08 20:22:43 -0400412 void *data, int silent)
Mike Marshall1182fca2015-07-17 10:38:15 -0400413{
414 int ret = -EINVAL;
415 struct inode *root = NULL;
416 struct dentry *root_dentry = NULL;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500417 struct orangefs_object_kref root_object;
Mike Marshall1182fca2015-07-17 10:38:15 -0400418
Yi Liu8bb8aef2015-11-24 15:12:14 -0500419 /* alloc and init our private orangefs sb info */
Martin Brandenburg05d31c52016-03-18 13:36:45 -0400420 sb->s_fs_info = kzalloc(sizeof(struct orangefs_sb_info_s), GFP_KERNEL);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500421 if (!ORANGEFS_SB(sb))
Mike Marshall1182fca2015-07-17 10:38:15 -0400422 return -ENOMEM;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500423 ORANGEFS_SB(sb)->sb = sb;
Mike Marshall1182fca2015-07-17 10:38:15 -0400424
Yi Liu8bb8aef2015-11-24 15:12:14 -0500425 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;
Mike Marshall1182fca2015-07-17 10:38:15 -0400428
Al Viro5c0dbbc2015-10-08 20:22:43 -0400429 if (data) {
430 ret = parse_mount_options(sb, data, silent);
Mike Marshall1182fca2015-07-17 10:38:15 -0400431 if (ret)
432 return ret;
433 }
434
435 /* Hang the xattr handlers off the superblock */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500436 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;
Mike Marshall1182fca2015-07-17 10:38:15 -0400440
Yi Liu8bb8aef2015-11-24 15:12:14 -0500441 sb->s_blocksize = orangefs_bufmap_size_query();
442 sb->s_blocksize_bits = orangefs_bufmap_shift_query();
Mike Marshall1182fca2015-07-17 10:38:15 -0400443 sb->s_maxbytes = MAX_LFS_FILESIZE;
444
Yi Liu8bb8aef2015-11-24 15:12:14 -0500445 root_object.khandle = ORANGEFS_SB(sb)->root_khandle;
446 root_object.fs_id = ORANGEFS_SB(sb)->fs_id;
Mike Marshall1182fca2015-07-17 10:38:15 -0400447 gossip_debug(GOSSIP_SUPER_DEBUG,
448 "get inode %pU, fsid %d\n",
449 &root_object.khandle,
450 root_object.fs_id);
451
Yi Liu8bb8aef2015-11-24 15:12:14 -0500452 root = orangefs_iget(sb, &root_object);
Mike Marshall1182fca2015-07-17 10:38:15 -0400453 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);
Al Virob05a7852015-10-08 20:18:00 -0400463 if (!root_dentry)
Mike Marshall1182fca2015-07-17 10:38:15 -0400464 return -ENOMEM;
Mike Marshall1182fca2015-07-17 10:38:15 -0400465
Yi Liu8bb8aef2015-11-24 15:12:14 -0500466 sb->s_export_op = &orangefs_export_ops;
Mike Marshall1182fca2015-07-17 10:38:15 -0400467 sb->s_root = root_dentry;
468 return 0;
469}
470
Yi Liu8bb8aef2015-11-24 15:12:14 -0500471struct dentry *orangefs_mount(struct file_system_type *fst,
Mike Marshall1182fca2015-07-17 10:38:15 -0400472 int flags,
473 const char *devname,
474 void *data)
475{
476 int ret = -EINVAL;
477 struct super_block *sb = ERR_PTR(-EINVAL);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500478 struct orangefs_kernel_op_s *new_op;
Mike Marshall1be21f82015-09-29 15:26:37 -0400479 struct dentry *d = ERR_PTR(-EINVAL);
Mike Marshall1182fca2015-07-17 10:38:15 -0400480
481 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500482 "orangefs_mount: called with devname %s\n",
Mike Marshall1182fca2015-07-17 10:38:15 -0400483 devname);
484
485 if (!devname) {
486 gossip_err("ERROR: device name not specified.\n");
487 return ERR_PTR(-EINVAL);
488 }
489
Yi Liu8bb8aef2015-11-24 15:12:14 -0500490 new_op = op_alloc(ORANGEFS_VFS_OP_FS_MOUNT);
Mike Marshall1182fca2015-07-17 10:38:15 -0400491 if (!new_op)
492 return ERR_PTR(-ENOMEM);
493
Yi Liu8bb8aef2015-11-24 15:12:14 -0500494 strncpy(new_op->upcall.req.fs_mount.orangefs_config_server,
Mike Marshall1182fca2015-07-17 10:38:15 -0400495 devname,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500496 ORANGEFS_MAX_SERVER_ADDR_LEN);
Mike Marshall1182fca2015-07-17 10:38:15 -0400497
498 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500499 "Attempting ORANGEFS Mount via host %s\n",
500 new_op->upcall.req.fs_mount.orangefs_config_server);
Mike Marshall1182fca2015-07-17 10:38:15 -0400501
Yi Liu8bb8aef2015-11-24 15:12:14 -0500502 ret = service_operation(new_op, "orangefs_mount", 0);
Mike Marshall1182fca2015-07-17 10:38:15 -0400503 gossip_debug(GOSSIP_SUPER_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500504 "orangefs_mount: mount got return value of %d\n", ret);
Mike Marshall1182fca2015-07-17 10:38:15 -0400505 if (ret)
506 goto free_op;
507
Yi Liu8bb8aef2015-11-24 15:12:14 -0500508 if (new_op->downcall.resp.fs_mount.fs_id == ORANGEFS_FS_ID_NULL) {
Mike Marshall1182fca2015-07-17 10:38:15 -0400509 gossip_err("ERROR: Retrieved null fs_id\n");
510 ret = -EINVAL;
511 goto free_op;
512 }
513
Mike Marshall1be21f82015-09-29 15:26:37 -0400514 sb = sget(fst, NULL, set_anon_super, flags, NULL);
515
516 if (IS_ERR(sb)) {
517 d = ERR_CAST(sb);
Martin Brandenburg9d286b02017-04-25 15:38:05 -0400518 orangefs_unmount(new_op->downcall.resp.fs_mount.id,
519 new_op->downcall.resp.fs_mount.fs_id, devname);
Mike Marshall1182fca2015-07-17 10:38:15 -0400520 goto free_op;
521 }
522
Yi Liu8bb8aef2015-11-24 15:12:14 -0500523 ret = orangefs_fill_sb(sb,
Al Viro5c0dbbc2015-10-08 20:22:43 -0400524 &new_op->downcall.resp.fs_mount, data,
Mike Marshall1be21f82015-09-29 15:26:37 -0400525 flags & MS_SILENT ? 1 : 0);
526
527 if (ret) {
528 d = ERR_PTR(ret);
Martin Brandenburg1ec16882017-04-14 14:22:41 -0400529 goto free_sb_and_op;
Mike Marshall1be21f82015-09-29 15:26:37 -0400530 }
Mike Marshall1182fca2015-07-17 10:38:15 -0400531
532 /*
533 * on successful mount, store the devname and data
534 * used
535 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500536 strncpy(ORANGEFS_SB(sb)->devname,
Mike Marshall1182fca2015-07-17 10:38:15 -0400537 devname,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500538 ORANGEFS_MAX_SERVER_ADDR_LEN);
Mike Marshall1182fca2015-07-17 10:38:15 -0400539
540 /* mount_pending must be cleared */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500541 ORANGEFS_SB(sb)->mount_pending = 0;
Mike Marshall1182fca2015-07-17 10:38:15 -0400542
543 /*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500544 * finally, add this sb to our list of known orangefs
Mike Marshall1182fca2015-07-17 10:38:15 -0400545 * sb's
546 */
Al Viro45996492016-03-25 19:56:34 -0400547 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);
Mike Marshall1182fca2015-07-17 10:38:15 -0400553 op_release(new_op);
Martin Brandenburg482664d2016-08-12 12:02:31 -0400554
Martin Brandenburg1ec16882017-04-14 14:22:41 -0400555 /* Must be removed from the list now. */
556 ORANGEFS_SB(sb)->no_list = 0;
557
Mike Marshallf60fbdb2016-10-03 15:07:36 -0400558 if (orangefs_userspace_version >= 20906) {
Martin Brandenburg482664d2016-08-12 12:02:31 -0400559 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
Mike Marshall1be21f82015-09-29 15:26:37 -0400570 return dget(sb->s_root);
Mike Marshall1182fca2015-07-17 10:38:15 -0400571
Martin Brandenburg1ec16882017-04-14 14:22:41 -0400572free_sb_and_op:
573 /* Will call orangefs_kill_sb with sb not in list. */
574 ORANGEFS_SB(sb)->no_list = 1;
Martin Brandenburg9d286b02017-04-25 15:38:05 -0400575 /* ORANGEFS_VFS_OP_FS_UMOUNT is done by orangefs_kill_sb. */
Martin Brandenburg1ec16882017-04-14 14:22:41 -0400576 deactivate_locked_super(sb);
Mike Marshall1182fca2015-07-17 10:38:15 -0400577free_op:
Yi Liu8bb8aef2015-11-24 15:12:14 -0500578 gossip_err("orangefs_mount: mount request failed with %d\n", ret);
Mike Marshall1182fca2015-07-17 10:38:15 -0400579 if (ret == -EINVAL) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500580 gossip_err("Ensure that all orangefs-servers have the same FS configuration files\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400581 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
Mike Marshall1be21f82015-09-29 15:26:37 -0400586 return d;
Mike Marshall1182fca2015-07-17 10:38:15 -0400587}
588
Yi Liu8bb8aef2015-11-24 15:12:14 -0500589void orangefs_kill_sb(struct super_block *sb)
Mike Marshall1182fca2015-07-17 10:38:15 -0400590{
Martin Brandenburg9d286b02017-04-25 15:38:05 -0400591 int r;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500592 gossip_debug(GOSSIP_SUPER_DEBUG, "orangefs_kill_sb: called\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400593
Al Viro524b1d32016-02-16 21:08:29 -0500594 /* provided sb cleanup */
595 kill_anon_super(sb);
596
Mike Marshall1182fca2015-07-17 10:38:15 -0400597 /*
598 * issue the unmount to userspace to tell it to remove the
599 * dynamic mount info it has for this superblock
600 */
Martin Brandenburg9d286b02017-04-25 15:38:05 -0400601 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;
Mike Marshall1182fca2015-07-17 10:38:15 -0400605
Martin Brandenburg1ec16882017-04-14 14:22:41 -0400606 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 }
Al Viro45996492016-03-25 19:56:34 -0400614
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 */
Martin Brandenburg1d503612016-08-16 11:38:14 -0400619 mutex_lock(&orangefs_request_mutex);
620 mutex_unlock(&orangefs_request_mutex);
Mike Marshall1182fca2015-07-17 10:38:15 -0400621
Yi Liu8bb8aef2015-11-24 15:12:14 -0500622 /* free the orangefs superblock private data */
623 kfree(ORANGEFS_SB(sb));
Mike Marshall1182fca2015-07-17 10:38:15 -0400624}
625
Yi Liu8bb8aef2015-11-24 15:12:14 -0500626int orangefs_inode_cache_initialize(void)
Mike Marshall1182fca2015-07-17 10:38:15 -0400627{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500628 orangefs_inode_cache = kmem_cache_create("orangefs_inode_cache",
629 sizeof(struct orangefs_inode_s),
Mike Marshall1182fca2015-07-17 10:38:15 -0400630 0,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500631 ORANGEFS_CACHE_CREATE_FLAGS,
632 orangefs_inode_cache_ctor);
Mike Marshall1182fca2015-07-17 10:38:15 -0400633
Yi Liu8bb8aef2015-11-24 15:12:14 -0500634 if (!orangefs_inode_cache) {
635 gossip_err("Cannot create orangefs_inode_cache\n");
Mike Marshall1182fca2015-07-17 10:38:15 -0400636 return -ENOMEM;
637 }
638 return 0;
639}
640
Yi Liu8bb8aef2015-11-24 15:12:14 -0500641int orangefs_inode_cache_finalize(void)
Mike Marshall1182fca2015-07-17 10:38:15 -0400642{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500643 kmem_cache_destroy(orangefs_inode_cache);
Mike Marshall1182fca2015-07-17 10:38:15 -0400644 return 0;
645}