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