Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -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" |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 10 | |
| 11 | /* tags assigned to kernel upcall operations */ |
| 12 | static __u64 next_tag_value; |
| 13 | static DEFINE_SPINLOCK(next_tag_value_lock); |
| 14 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 15 | /* the orangefs memory caches */ |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 16 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 17 | /* a cache for orangefs upcall/downcall operations */ |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 18 | static struct kmem_cache *op_cache; |
| 19 | |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 20 | int op_cache_initialize(void) |
| 21 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 22 | op_cache = kmem_cache_create("orangefs_op_cache", |
| 23 | sizeof(struct orangefs_kernel_op_s), |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 24 | 0, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 25 | ORANGEFS_CACHE_CREATE_FLAGS, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 26 | NULL); |
| 27 | |
| 28 | if (!op_cache) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 29 | gossip_err("Cannot create orangefs_op_cache\n"); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 30 | return -ENOMEM; |
| 31 | } |
| 32 | |
| 33 | /* initialize our atomic tag counter */ |
| 34 | spin_lock(&next_tag_value_lock); |
| 35 | next_tag_value = 100; |
| 36 | spin_unlock(&next_tag_value_lock); |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | int op_cache_finalize(void) |
| 41 | { |
| 42 | kmem_cache_destroy(op_cache); |
| 43 | return 0; |
| 44 | } |
| 45 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 46 | char *get_opname_string(struct orangefs_kernel_op_s *new_op) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 47 | { |
| 48 | if (new_op) { |
| 49 | __s32 type = new_op->upcall.type; |
| 50 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 51 | if (type == ORANGEFS_VFS_OP_FILE_IO) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 52 | return "OP_FILE_IO"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 53 | else if (type == ORANGEFS_VFS_OP_LOOKUP) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 54 | return "OP_LOOKUP"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 55 | else if (type == ORANGEFS_VFS_OP_CREATE) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 56 | return "OP_CREATE"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 57 | else if (type == ORANGEFS_VFS_OP_GETATTR) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 58 | return "OP_GETATTR"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 59 | else if (type == ORANGEFS_VFS_OP_REMOVE) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 60 | return "OP_REMOVE"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 61 | else if (type == ORANGEFS_VFS_OP_MKDIR) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 62 | return "OP_MKDIR"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 63 | else if (type == ORANGEFS_VFS_OP_READDIR) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 64 | return "OP_READDIR"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 65 | else if (type == ORANGEFS_VFS_OP_READDIRPLUS) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 66 | return "OP_READDIRPLUS"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 67 | else if (type == ORANGEFS_VFS_OP_SETATTR) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 68 | return "OP_SETATTR"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 69 | else if (type == ORANGEFS_VFS_OP_SYMLINK) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 70 | return "OP_SYMLINK"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 71 | else if (type == ORANGEFS_VFS_OP_RENAME) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 72 | return "OP_RENAME"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 73 | else if (type == ORANGEFS_VFS_OP_STATFS) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 74 | return "OP_STATFS"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 75 | else if (type == ORANGEFS_VFS_OP_TRUNCATE) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 76 | return "OP_TRUNCATE"; |
Martin Brandenburg | 6eaff8c | 2016-08-02 14:31:05 -0400 | [diff] [blame] | 77 | else if (type == ORANGEFS_VFS_OP_RA_FLUSH) |
| 78 | return "OP_RA_FLUSH"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 79 | else if (type == ORANGEFS_VFS_OP_FS_MOUNT) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 80 | return "OP_FS_MOUNT"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 81 | else if (type == ORANGEFS_VFS_OP_FS_UMOUNT) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 82 | return "OP_FS_UMOUNT"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 83 | else if (type == ORANGEFS_VFS_OP_GETXATTR) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 84 | return "OP_GETXATTR"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 85 | else if (type == ORANGEFS_VFS_OP_SETXATTR) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 86 | return "OP_SETXATTR"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 87 | else if (type == ORANGEFS_VFS_OP_LISTXATTR) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 88 | return "OP_LISTXATTR"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 89 | else if (type == ORANGEFS_VFS_OP_REMOVEXATTR) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 90 | return "OP_REMOVEXATTR"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 91 | else if (type == ORANGEFS_VFS_OP_PARAM) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 92 | return "OP_PARAM"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 93 | else if (type == ORANGEFS_VFS_OP_PERF_COUNT) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 94 | return "OP_PERF_COUNT"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 95 | else if (type == ORANGEFS_VFS_OP_CANCEL) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 96 | return "OP_CANCEL"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 97 | else if (type == ORANGEFS_VFS_OP_FSYNC) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 98 | return "OP_FSYNC"; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 99 | else if (type == ORANGEFS_VFS_OP_FSKEY) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 100 | return "OP_FSKEY"; |
Martin Brandenburg | 482664d | 2016-08-12 12:02:31 -0400 | [diff] [blame] | 101 | else if (type == ORANGEFS_VFS_OP_FEATURES) |
| 102 | return "OP_FEATURES"; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 103 | } |
| 104 | return "OP_UNKNOWN?"; |
| 105 | } |
| 106 | |
Al Viro | 78699e2 | 2016-02-11 23:07:19 -0500 | [diff] [blame] | 107 | void orangefs_new_tag(struct orangefs_kernel_op_s *op) |
| 108 | { |
| 109 | spin_lock(&next_tag_value_lock); |
| 110 | op->tag = next_tag_value++; |
| 111 | if (next_tag_value == 0) |
| 112 | next_tag_value = 100; |
| 113 | spin_unlock(&next_tag_value_lock); |
| 114 | } |
| 115 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 116 | struct orangefs_kernel_op_s *op_alloc(__s32 type) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 117 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 118 | struct orangefs_kernel_op_s *new_op = NULL; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 119 | |
Mike Marshall | 2d4cae0 | 2016-02-04 13:48:16 -0500 | [diff] [blame] | 120 | new_op = kmem_cache_zalloc(op_cache, GFP_KERNEL); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 121 | if (new_op) { |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 122 | INIT_LIST_HEAD(&new_op->list); |
| 123 | spin_lock_init(&new_op->lock); |
Al Viro | d2d87a3 | 2016-02-13 10:15:22 -0500 | [diff] [blame] | 124 | init_completion(&new_op->waitq); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 125 | |
Al Viro | 115b93a | 2016-01-23 14:04:31 -0500 | [diff] [blame] | 126 | new_op->upcall.type = ORANGEFS_VFS_OP_INVALID; |
| 127 | new_op->downcall.type = ORANGEFS_VFS_OP_INVALID; |
| 128 | new_op->downcall.status = -1; |
| 129 | |
| 130 | new_op->op_state = OP_VFS_STATE_UNKNOWN; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 131 | |
| 132 | /* initialize the op specific tag and upcall credentials */ |
Al Viro | 78699e2 | 2016-02-11 23:07:19 -0500 | [diff] [blame] | 133 | orangefs_new_tag(new_op); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 134 | new_op->upcall.type = type; |
| 135 | new_op->attempts = 0; |
| 136 | gossip_debug(GOSSIP_CACHE_DEBUG, |
| 137 | "Alloced OP (%p: %llu %s)\n", |
| 138 | new_op, |
| 139 | llu(new_op->tag), |
| 140 | get_opname_string(new_op)); |
| 141 | |
Jann Horn | 78fee0b | 2016-06-25 01:51:52 +0200 | [diff] [blame] | 142 | new_op->upcall.uid = from_kuid(&init_user_ns, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 143 | current_fsuid()); |
| 144 | |
Jann Horn | 78fee0b | 2016-06-25 01:51:52 +0200 | [diff] [blame] | 145 | new_op->upcall.gid = from_kgid(&init_user_ns, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 146 | current_fsgid()); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 147 | } else { |
Mike Marshall | 2d4cae0 | 2016-02-04 13:48:16 -0500 | [diff] [blame] | 148 | gossip_err("op_alloc: kmem_cache_zalloc failed!\n"); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 149 | } |
| 150 | return new_op; |
| 151 | } |
| 152 | |
Al Viro | c1223ca | 2016-02-18 19:17:51 -0500 | [diff] [blame] | 153 | void op_release(struct orangefs_kernel_op_s *orangefs_op) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 154 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 155 | if (orangefs_op) { |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 156 | gossip_debug(GOSSIP_CACHE_DEBUG, |
| 157 | "Releasing OP (%p: %llu)\n", |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 158 | orangefs_op, |
| 159 | llu(orangefs_op->tag)); |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 160 | kmem_cache_free(op_cache, orangefs_op); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 161 | } else { |
| 162 | gossip_err("NULL pointer in op_release\n"); |
| 163 | } |
| 164 | } |