Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2001 Clemson University and The University of Chicago |
| 3 | * |
| 4 | * See COPYING in top-level directory. |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Linux VFS file operations. |
| 9 | */ |
| 10 | |
| 11 | #include "protocol.h" |
Mike Marshall | 575e946 | 2015-12-04 12:56:14 -0500 | [diff] [blame] | 12 | #include "orangefs-kernel.h" |
| 13 | #include "orangefs-bufmap.h" |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 14 | #include <linux/fs.h> |
| 15 | #include <linux/pagemap.h> |
| 16 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 17 | /* |
| 18 | * Copy to client-core's address space from the buffers specified |
| 19 | * by the iovec upto total_size bytes. |
| 20 | * NOTE: the iovector can either contain addresses which |
| 21 | * can futher be kernel-space or user-space addresses. |
| 22 | * or it can pointers to struct page's |
| 23 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 24 | static int precopy_buffers(struct orangefs_bufmap *bufmap, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 25 | int buffer_index, |
Al Viro | a5c126a | 2015-10-08 17:54:31 -0400 | [diff] [blame] | 26 | struct iov_iter *iter, |
Mike Marshall | 4d1c440 | 2015-09-04 10:31:16 -0400 | [diff] [blame] | 27 | size_t total_size) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 28 | { |
| 29 | int ret = 0; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 30 | /* |
| 31 | * copy data from application/kernel by pulling it out |
| 32 | * of the iovec. |
| 33 | */ |
Mike Marshall | 4d1c440 | 2015-09-04 10:31:16 -0400 | [diff] [blame] | 34 | |
| 35 | |
| 36 | if (total_size) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 37 | ret = orangefs_bufmap_copy_from_iovec(bufmap, |
| 38 | iter, |
| 39 | buffer_index, |
| 40 | total_size); |
Mike Marshall | 4d1c440 | 2015-09-04 10:31:16 -0400 | [diff] [blame] | 41 | if (ret < 0) |
| 42 | gossip_err("%s: Failed to copy-in buffers. Please make sure that the pvfs2-client is running. %ld\n", |
| 43 | __func__, |
| 44 | (long)ret); |
Mike Marshall | 4d1c440 | 2015-09-04 10:31:16 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 47 | if (ret < 0) |
| 48 | gossip_err("%s: Failed to copy-in buffers. Please make sure that the pvfs2-client is running. %ld\n", |
| 49 | __func__, |
| 50 | (long)ret); |
| 51 | return ret; |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * Copy from client-core's address space to the buffers specified |
| 56 | * by the iovec upto total_size bytes. |
| 57 | * NOTE: the iovector can either contain addresses which |
| 58 | * can futher be kernel-space or user-space addresses. |
| 59 | * or it can pointers to struct page's |
| 60 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 61 | static int postcopy_buffers(struct orangefs_bufmap *bufmap, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 62 | int buffer_index, |
Al Viro | 5f0e3c9 | 2015-10-08 17:52:44 -0400 | [diff] [blame] | 63 | struct iov_iter *iter, |
Mike Marshall | 4d1c440 | 2015-09-04 10:31:16 -0400 | [diff] [blame] | 64 | size_t total_size) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 65 | { |
| 66 | int ret = 0; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 67 | /* |
| 68 | * copy data to application/kernel by pushing it out to |
| 69 | * the iovec. NOTE; target buffers can be addresses or |
| 70 | * struct page pointers. |
| 71 | */ |
| 72 | if (total_size) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 73 | ret = orangefs_bufmap_copy_to_iovec(bufmap, |
| 74 | iter, |
| 75 | buffer_index, |
| 76 | total_size); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 77 | if (ret < 0) |
Mike Marshall | 4d1c440 | 2015-09-04 10:31:16 -0400 | [diff] [blame] | 78 | gossip_err("%s: Failed to copy-out buffers. Please make sure that the pvfs2-client is running (%ld)\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 79 | __func__, |
| 80 | (long)ret); |
| 81 | } |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | /* |
Al Viro | b0bc3a7 | 2016-01-23 13:50:37 -0500 | [diff] [blame^] | 86 | * handles two possible error cases, depending on context. |
| 87 | * |
| 88 | * by design, our vfs i/o errors need to be handled in one of two ways, |
| 89 | * depending on where the error occured. |
| 90 | * |
| 91 | * if the error happens in the waitqueue code because we either timed |
| 92 | * out or a signal was raised while waiting, we need to cancel the |
| 93 | * userspace i/o operation and free the op manually. this is done to |
| 94 | * avoid having the device start writing application data to our shared |
| 95 | * bufmap pages without us expecting it. |
| 96 | * |
| 97 | * FIXME: POSSIBLE OPTIMIZATION: |
| 98 | * However, if we timed out or if we got a signal AND our upcall was never |
| 99 | * picked off the queue (i.e. we were in OP_VFS_STATE_WAITING), then we don't |
| 100 | * need to send a cancellation upcall. The way we can handle this is |
| 101 | * set error_exit to 2 in such cases and 1 whenever cancellation has to be |
| 102 | * sent and have handle_error |
| 103 | * take care of this situation as well.. |
| 104 | * |
| 105 | * if a orangefs sysint level error occured and i/o has been completed, |
| 106 | * there is no need to cancel the operation, as the user has finished |
| 107 | * using the bufmap page and so there is no danger in this case. in |
| 108 | * this case, we wake up the device normally so that it may free the |
| 109 | * op, as normal. |
| 110 | * |
| 111 | * note the only reason this is a macro is because both read and write |
| 112 | * cases need the exact same handling code. |
| 113 | */ |
| 114 | #define handle_io_error() \ |
| 115 | do { \ |
| 116 | if (!op_state_serviced(new_op)) { \ |
| 117 | orangefs_cancel_op_in_progress(new_op->tag); \ |
| 118 | } else { \ |
| 119 | complete(&new_op->done); \ |
| 120 | } \ |
| 121 | orangefs_bufmap_put(bufmap, buffer_index); \ |
| 122 | buffer_index = -1; \ |
| 123 | } while (0) |
| 124 | |
| 125 | /* |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 126 | * Post and wait for the I/O upcall to finish |
| 127 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 128 | static ssize_t wait_for_direct_io(enum ORANGEFS_io_type type, struct inode *inode, |
Al Viro | 3c2fcfc | 2015-10-08 18:00:26 -0400 | [diff] [blame] | 129 | loff_t *offset, struct iov_iter *iter, |
Mike Marshall | 4d1c440 | 2015-09-04 10:31:16 -0400 | [diff] [blame] | 130 | size_t total_size, loff_t readahead_size) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 131 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 132 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); |
| 133 | struct orangefs_khandle *handle = &orangefs_inode->refn.khandle; |
| 134 | struct orangefs_bufmap *bufmap = NULL; |
| 135 | struct orangefs_kernel_op_s *new_op = NULL; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 136 | int buffer_index = -1; |
| 137 | ssize_t ret; |
| 138 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 139 | new_op = op_alloc(ORANGEFS_VFS_OP_FILE_IO); |
Al Viro | ed42fe0 | 2016-01-22 19:47:47 -0500 | [diff] [blame] | 140 | if (!new_op) |
| 141 | return -ENOMEM; |
| 142 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 143 | /* synchronous I/O */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 144 | new_op->upcall.req.io.async_vfs_io = ORANGEFS_VFS_SYNC_IO; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 145 | new_op->upcall.req.io.readahead_size = readahead_size; |
| 146 | new_op->upcall.req.io.io_type = type; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 147 | new_op->upcall.req.io.refn = orangefs_inode->refn; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 148 | |
| 149 | populate_shared_memory: |
| 150 | /* get a shared buffer index */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 151 | ret = orangefs_bufmap_get(&bufmap, &buffer_index); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 152 | if (ret < 0) { |
| 153 | gossip_debug(GOSSIP_FILE_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 154 | "%s: orangefs_bufmap_get failure (%ld)\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 155 | __func__, (long)ret); |
| 156 | goto out; |
| 157 | } |
| 158 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 159 | "%s(%pU): GET op %p -> buffer_index %d\n", |
| 160 | __func__, |
| 161 | handle, |
| 162 | new_op, |
| 163 | buffer_index); |
| 164 | |
| 165 | new_op->uses_shared_memory = 1; |
| 166 | new_op->upcall.req.io.buf_index = buffer_index; |
| 167 | new_op->upcall.req.io.count = total_size; |
| 168 | new_op->upcall.req.io.offset = *offset; |
| 169 | |
| 170 | gossip_debug(GOSSIP_FILE_DEBUG, |
Al Viro | 3c2fcfc | 2015-10-08 18:00:26 -0400 | [diff] [blame] | 171 | "%s(%pU): offset: %llu total_size: %zd\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 172 | __func__, |
| 173 | handle, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 174 | llu(*offset), |
| 175 | total_size); |
| 176 | /* |
| 177 | * Stage 1: copy the buffers into client-core's address space |
| 178 | * precopy_buffers only pertains to writes. |
| 179 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 180 | if (type == ORANGEFS_IO_WRITE) { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 181 | ret = precopy_buffers(bufmap, |
| 182 | buffer_index, |
Al Viro | 3c2fcfc | 2015-10-08 18:00:26 -0400 | [diff] [blame] | 183 | iter, |
Mike Marshall | 4d1c440 | 2015-09-04 10:31:16 -0400 | [diff] [blame] | 184 | total_size); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 185 | if (ret < 0) |
| 186 | goto out; |
| 187 | } |
| 188 | |
| 189 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 190 | "%s(%pU): Calling post_io_request with tag (%llu)\n", |
| 191 | __func__, |
| 192 | handle, |
| 193 | llu(new_op->tag)); |
| 194 | |
| 195 | /* Stage 2: Service the I/O operation */ |
| 196 | ret = service_operation(new_op, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 197 | type == ORANGEFS_IO_WRITE ? |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 198 | "file_write" : |
| 199 | "file_read", |
| 200 | get_interruptible_flag(inode)); |
| 201 | |
| 202 | /* |
| 203 | * If service_operation() returns -EAGAIN #and# the operation was |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 204 | * purged from orangefs_request_list or htable_ops_in_progress, then |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 205 | * we know that the client was restarted, causing the shared memory |
| 206 | * area to be wiped clean. To restart a write operation in this |
| 207 | * case, we must re-copy the data from the user's iovec to a NEW |
| 208 | * shared memory location. To restart a read operation, we must get |
| 209 | * a new shared memory location. |
| 210 | */ |
| 211 | if (ret == -EAGAIN && op_state_purged(new_op)) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 212 | orangefs_bufmap_put(bufmap, buffer_index); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 213 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 214 | "%s:going to repopulate_shared_memory.\n", |
| 215 | __func__); |
| 216 | goto populate_shared_memory; |
| 217 | } |
| 218 | |
| 219 | if (ret < 0) { |
Mike Marshall | 575e946 | 2015-12-04 12:56:14 -0500 | [diff] [blame] | 220 | handle_io_error(); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 221 | /* |
Mike Marshall | 5480494 | 2015-10-05 13:44:24 -0400 | [diff] [blame] | 222 | * don't write an error to syslog on signaled operation |
| 223 | * termination unless we've got debugging turned on, as |
| 224 | * this can happen regularly (i.e. ctrl-c) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 225 | */ |
| 226 | if (ret == -EINTR) |
| 227 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 228 | "%s: returning error %ld\n", __func__, |
| 229 | (long)ret); |
| 230 | else |
| 231 | gossip_err("%s: error in %s handle %pU, returning %zd\n", |
| 232 | __func__, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 233 | type == ORANGEFS_IO_READ ? |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 234 | "read from" : "write to", |
| 235 | handle, ret); |
| 236 | goto out; |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * Stage 3: Post copy buffers from client-core's address space |
| 241 | * postcopy_buffers only pertains to reads. |
| 242 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 243 | if (type == ORANGEFS_IO_READ) { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 244 | ret = postcopy_buffers(bufmap, |
| 245 | buffer_index, |
Al Viro | 3c2fcfc | 2015-10-08 18:00:26 -0400 | [diff] [blame] | 246 | iter, |
Mike Marshall | 4d1c440 | 2015-09-04 10:31:16 -0400 | [diff] [blame] | 247 | new_op->downcall.resp.io.amt_complete); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 248 | if (ret < 0) { |
| 249 | /* |
| 250 | * put error codes in downcall so that handle_io_error() |
| 251 | * preserves it properly |
| 252 | */ |
| 253 | new_op->downcall.status = ret; |
| 254 | handle_io_error(); |
| 255 | goto out; |
| 256 | } |
| 257 | } |
| 258 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 259 | "%s(%pU): Amount written as returned by the sys-io call:%d\n", |
| 260 | __func__, |
| 261 | handle, |
| 262 | (int)new_op->downcall.resp.io.amt_complete); |
| 263 | |
| 264 | ret = new_op->downcall.resp.io.amt_complete; |
| 265 | |
| 266 | /* |
Mike Marshall | 5480494 | 2015-10-05 13:44:24 -0400 | [diff] [blame] | 267 | * tell the device file owner waiting on I/O that this read has |
Al Viro | ed42fe0 | 2016-01-22 19:47:47 -0500 | [diff] [blame] | 268 | * completed and it can return now. |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 269 | */ |
Al Viro | b0bc3a7 | 2016-01-23 13:50:37 -0500 | [diff] [blame^] | 270 | complete(&new_op->done); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 271 | |
| 272 | out: |
| 273 | if (buffer_index >= 0) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 274 | orangefs_bufmap_put(bufmap, buffer_index); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 275 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 276 | "%s(%pU): PUT buffer_index %d\n", |
| 277 | __func__, handle, buffer_index); |
| 278 | buffer_index = -1; |
| 279 | } |
Al Viro | ed42fe0 | 2016-01-22 19:47:47 -0500 | [diff] [blame] | 280 | op_release(new_op); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 281 | return ret; |
| 282 | } |
| 283 | |
| 284 | /* |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 285 | * Common entry point for read/write/readv/writev |
| 286 | * This function will dispatch it to either the direct I/O |
| 287 | * or buffered I/O path depending on the mount options and/or |
| 288 | * augmented/extended metadata attached to the file. |
| 289 | * Note: File extended attributes override any mount options. |
| 290 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 291 | static ssize_t do_readv_writev(enum ORANGEFS_io_type type, struct file *file, |
Al Viro | 0071ed1 | 2015-10-08 18:22:08 -0400 | [diff] [blame] | 292 | loff_t *offset, struct iov_iter *iter) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 293 | { |
| 294 | struct inode *inode = file->f_mapping->host; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 295 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); |
| 296 | struct orangefs_khandle *handle = &orangefs_inode->refn.khandle; |
Al Viro | 0071ed1 | 2015-10-08 18:22:08 -0400 | [diff] [blame] | 297 | size_t count = iov_iter_count(iter); |
Al Viro | dc4067f | 2015-10-08 18:17:26 -0400 | [diff] [blame] | 298 | ssize_t total_count = 0; |
| 299 | ssize_t ret = -EINVAL; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 300 | |
| 301 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 302 | "%s-BEGIN(%pU): count(%d) after estimate_max_iovecs.\n", |
| 303 | __func__, |
| 304 | handle, |
| 305 | (int)count); |
| 306 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 307 | if (type == ORANGEFS_IO_WRITE) { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 308 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 309 | "%s(%pU): proceeding with offset : %llu, " |
| 310 | "size %d\n", |
| 311 | __func__, |
| 312 | handle, |
| 313 | llu(*offset), |
| 314 | (int)count); |
| 315 | } |
| 316 | |
| 317 | if (count == 0) { |
| 318 | ret = 0; |
| 319 | goto out; |
| 320 | } |
| 321 | |
Al Viro | 0071ed1 | 2015-10-08 18:22:08 -0400 | [diff] [blame] | 322 | while (iov_iter_count(iter)) { |
| 323 | size_t each_count = iov_iter_count(iter); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 324 | size_t amt_complete; |
| 325 | |
| 326 | /* how much to transfer in this loop iteration */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 327 | if (each_count > orangefs_bufmap_size_query()) |
| 328 | each_count = orangefs_bufmap_size_query(); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 329 | |
| 330 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 331 | "%s(%pU): size of each_count(%d)\n", |
| 332 | __func__, |
| 333 | handle, |
| 334 | (int)each_count); |
| 335 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 336 | "%s(%pU): BEFORE wait_for_io: offset is %d\n", |
| 337 | __func__, |
| 338 | handle, |
| 339 | (int)*offset); |
| 340 | |
Al Viro | 0071ed1 | 2015-10-08 18:22:08 -0400 | [diff] [blame] | 341 | ret = wait_for_direct_io(type, inode, offset, iter, |
Al Viro | 3c2fcfc | 2015-10-08 18:00:26 -0400 | [diff] [blame] | 342 | each_count, 0); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 343 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 344 | "%s(%pU): return from wait_for_io:%d\n", |
| 345 | __func__, |
| 346 | handle, |
| 347 | (int)ret); |
| 348 | |
| 349 | if (ret < 0) |
| 350 | goto out; |
| 351 | |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 352 | *offset += ret; |
| 353 | total_count += ret; |
| 354 | amt_complete = ret; |
| 355 | |
| 356 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 357 | "%s(%pU): AFTER wait_for_io: offset is %d\n", |
| 358 | __func__, |
| 359 | handle, |
| 360 | (int)*offset); |
| 361 | |
| 362 | /* |
| 363 | * if we got a short I/O operations, |
| 364 | * fall out and return what we got so far |
| 365 | */ |
| 366 | if (amt_complete < each_count) |
| 367 | break; |
| 368 | } /*end while */ |
| 369 | |
| 370 | if (total_count > 0) |
| 371 | ret = total_count; |
| 372 | out: |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 373 | if (ret > 0) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 374 | if (type == ORANGEFS_IO_READ) { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 375 | file_accessed(file); |
| 376 | } else { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 377 | SetMtimeFlag(orangefs_inode); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 378 | inode->i_mtime = CURRENT_TIME; |
| 379 | mark_inode_dirty_sync(inode); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 384 | "%s(%pU): Value(%d) returned.\n", |
| 385 | __func__, |
| 386 | handle, |
| 387 | (int)ret); |
| 388 | |
| 389 | return ret; |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Read data from a specified offset in a file (referenced by inode). |
| 394 | * Data may be placed either in a user or kernel buffer. |
| 395 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 396 | ssize_t orangefs_inode_read(struct inode *inode, |
| 397 | struct iov_iter *iter, |
| 398 | loff_t *offset, |
| 399 | loff_t readahead_size) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 400 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 401 | struct orangefs_inode_s *orangefs_inode = ORANGEFS_I(inode); |
Al Viro | 74f68fc | 2015-10-08 18:31:05 -0400 | [diff] [blame] | 402 | size_t count = iov_iter_count(iter); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 403 | size_t bufmap_size; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 404 | ssize_t ret = -EINVAL; |
| 405 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 406 | g_orangefs_stats.reads++; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 407 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 408 | bufmap_size = orangefs_bufmap_size_query(); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 409 | if (count > bufmap_size) { |
| 410 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 411 | "%s: count is too large (%zd/%zd)!\n", |
| 412 | __func__, count, bufmap_size); |
| 413 | return -EINVAL; |
| 414 | } |
| 415 | |
| 416 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 417 | "%s(%pU) %zd@%llu\n", |
| 418 | __func__, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 419 | &orangefs_inode->refn.khandle, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 420 | count, |
| 421 | llu(*offset)); |
| 422 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 423 | ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, offset, iter, |
Mike Marshall | 4d1c440 | 2015-09-04 10:31:16 -0400 | [diff] [blame] | 424 | count, readahead_size); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 425 | if (ret > 0) |
| 426 | *offset += ret; |
| 427 | |
| 428 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 429 | "%s(%pU): Value(%zd) returned.\n", |
| 430 | __func__, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 431 | &orangefs_inode->refn.khandle, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 432 | ret); |
| 433 | |
| 434 | return ret; |
| 435 | } |
| 436 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 437 | static ssize_t orangefs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 438 | { |
| 439 | struct file *file = iocb->ki_filp; |
| 440 | loff_t pos = *(&iocb->ki_pos); |
| 441 | ssize_t rc = 0; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 442 | |
| 443 | BUG_ON(iocb->private); |
| 444 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 445 | gossip_debug(GOSSIP_FILE_DEBUG, "orangefs_file_read_iter\n"); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 446 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 447 | g_orangefs_stats.reads++; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 448 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 449 | rc = do_readv_writev(ORANGEFS_IO_READ, file, &pos, iter); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 450 | iocb->ki_pos = pos; |
| 451 | |
| 452 | return rc; |
| 453 | } |
| 454 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 455 | static ssize_t orangefs_file_write_iter(struct kiocb *iocb, struct iov_iter *iter) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 456 | { |
| 457 | struct file *file = iocb->ki_filp; |
Mike Marshall | 3f1b694 | 2015-11-13 13:05:11 -0500 | [diff] [blame] | 458 | loff_t pos; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 459 | ssize_t rc; |
| 460 | |
| 461 | BUG_ON(iocb->private); |
| 462 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 463 | gossip_debug(GOSSIP_FILE_DEBUG, "orangefs_file_write_iter\n"); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 464 | |
| 465 | mutex_lock(&file->f_mapping->host->i_mutex); |
| 466 | |
| 467 | /* Make sure generic_write_checks sees an up to date inode size. */ |
| 468 | if (file->f_flags & O_APPEND) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 469 | rc = orangefs_inode_getattr(file->f_mapping->host, |
| 470 | ORANGEFS_ATTR_SYS_SIZE); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 471 | if (rc) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 472 | gossip_err("%s: orangefs_inode_getattr failed, rc:%zd:.\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 473 | __func__, rc); |
| 474 | goto out; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | if (file->f_pos > i_size_read(file->f_mapping->host)) |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 479 | orangefs_i_size_write(file->f_mapping->host, file->f_pos); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 480 | |
| 481 | rc = generic_write_checks(iocb, iter); |
| 482 | |
| 483 | if (rc <= 0) { |
| 484 | gossip_err("%s: generic_write_checks failed, rc:%zd:.\n", |
| 485 | __func__, rc); |
| 486 | goto out; |
| 487 | } |
| 488 | |
Mike Marshall | 3f1b694 | 2015-11-13 13:05:11 -0500 | [diff] [blame] | 489 | /* |
| 490 | * if we are appending, generic_write_checks would have updated |
| 491 | * pos to the end of the file, so we will wait till now to set |
| 492 | * pos... |
| 493 | */ |
| 494 | pos = *(&iocb->ki_pos); |
| 495 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 496 | rc = do_readv_writev(ORANGEFS_IO_WRITE, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 497 | file, |
| 498 | &pos, |
Al Viro | 0071ed1 | 2015-10-08 18:22:08 -0400 | [diff] [blame] | 499 | iter); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 500 | if (rc < 0) { |
| 501 | gossip_err("%s: do_readv_writev failed, rc:%zd:.\n", |
| 502 | __func__, rc); |
| 503 | goto out; |
| 504 | } |
| 505 | |
| 506 | iocb->ki_pos = pos; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 507 | g_orangefs_stats.writes++; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 508 | |
| 509 | out: |
| 510 | |
| 511 | mutex_unlock(&file->f_mapping->host->i_mutex); |
| 512 | return rc; |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * Perform a miscellaneous operation on a file. |
| 517 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 518 | static long orangefs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 519 | { |
| 520 | int ret = -ENOTTY; |
| 521 | __u64 val = 0; |
| 522 | unsigned long uval; |
| 523 | |
| 524 | gossip_debug(GOSSIP_FILE_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 525 | "orangefs_ioctl: called with cmd %d\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 526 | cmd); |
| 527 | |
| 528 | /* |
| 529 | * we understand some general ioctls on files, such as the immutable |
| 530 | * and append flags |
| 531 | */ |
| 532 | if (cmd == FS_IOC_GETFLAGS) { |
| 533 | val = 0; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 534 | ret = orangefs_inode_getxattr(file_inode(file), |
| 535 | ORANGEFS_XATTR_NAME_DEFAULT_PREFIX, |
| 536 | "user.pvfs2.meta_hint", |
| 537 | &val, sizeof(val)); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 538 | if (ret < 0 && ret != -ENODATA) |
| 539 | return ret; |
| 540 | else if (ret == -ENODATA) |
| 541 | val = 0; |
| 542 | uval = val; |
| 543 | gossip_debug(GOSSIP_FILE_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 544 | "orangefs_ioctl: FS_IOC_GETFLAGS: %llu\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 545 | (unsigned long long)uval); |
| 546 | return put_user(uval, (int __user *)arg); |
| 547 | } else if (cmd == FS_IOC_SETFLAGS) { |
| 548 | ret = 0; |
| 549 | if (get_user(uval, (int __user *)arg)) |
| 550 | return -EFAULT; |
| 551 | /* |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 552 | * ORANGEFS_MIRROR_FL is set internally when the mirroring mode |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 553 | * is turned on for a file. The user is not allowed to turn |
| 554 | * on this bit, but the bit is present if the user first gets |
| 555 | * the flags and then updates the flags with some new |
| 556 | * settings. So, we ignore it in the following edit. bligon. |
| 557 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 558 | if ((uval & ~ORANGEFS_MIRROR_FL) & |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 559 | (~(FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NOATIME_FL))) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 560 | gossip_err("orangefs_ioctl: the FS_IOC_SETFLAGS only supports setting one of FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NOATIME_FL\n"); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 561 | return -EINVAL; |
| 562 | } |
| 563 | val = uval; |
| 564 | gossip_debug(GOSSIP_FILE_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 565 | "orangefs_ioctl: FS_IOC_SETFLAGS: %llu\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 566 | (unsigned long long)val); |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 567 | ret = orangefs_inode_setxattr(file_inode(file), |
| 568 | ORANGEFS_XATTR_NAME_DEFAULT_PREFIX, |
| 569 | "user.pvfs2.meta_hint", |
| 570 | &val, sizeof(val), 0); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | return ret; |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * Memory map a region of a file. |
| 578 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 579 | static int orangefs_file_mmap(struct file *file, struct vm_area_struct *vma) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 580 | { |
| 581 | gossip_debug(GOSSIP_FILE_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 582 | "orangefs_file_mmap: called on %s\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 583 | (file ? |
| 584 | (char *)file->f_path.dentry->d_name.name : |
| 585 | (char *)"Unknown")); |
| 586 | |
| 587 | /* set the sequential readahead hint */ |
| 588 | vma->vm_flags |= VM_SEQ_READ; |
| 589 | vma->vm_flags &= ~VM_RAND_READ; |
Martin Brandenburg | 3539080 | 2015-09-30 13:11:54 -0400 | [diff] [blame] | 590 | |
| 591 | /* Use readonly mmap since we cannot support writable maps. */ |
| 592 | return generic_file_readonly_mmap(file, vma); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | #define mapping_nrpages(idata) ((idata)->nrpages) |
| 596 | |
| 597 | /* |
| 598 | * Called to notify the module that there are no more references to |
| 599 | * this file (i.e. no processes have it open). |
| 600 | * |
| 601 | * \note Not called when each file is closed. |
| 602 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 603 | static int orangefs_file_release(struct inode *inode, struct file *file) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 604 | { |
| 605 | gossip_debug(GOSSIP_FILE_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 606 | "orangefs_file_release: called on %s\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 607 | file->f_path.dentry->d_name.name); |
| 608 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 609 | orangefs_flush_inode(inode); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 610 | |
| 611 | /* |
Mike Marshall | 5480494 | 2015-10-05 13:44:24 -0400 | [diff] [blame] | 612 | * remove all associated inode pages from the page cache and mmap |
| 613 | * readahead cache (if any); this forces an expensive refresh of |
| 614 | * data for the next caller of mmap (or 'get_block' accesses) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 615 | */ |
| 616 | if (file->f_path.dentry->d_inode && |
| 617 | file->f_path.dentry->d_inode->i_mapping && |
| 618 | mapping_nrpages(&file->f_path.dentry->d_inode->i_data)) |
| 619 | truncate_inode_pages(file->f_path.dentry->d_inode->i_mapping, |
| 620 | 0); |
| 621 | return 0; |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * Push all data for a specific file onto permanent storage. |
| 626 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 627 | static int orangefs_fsync(struct file *file, |
Mike Marshall | 84d0215 | 2015-07-28 13:27:51 -0400 | [diff] [blame] | 628 | loff_t start, |
| 629 | loff_t end, |
| 630 | int datasync) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 631 | { |
| 632 | int ret = -EINVAL; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 633 | struct orangefs_inode_s *orangefs_inode = |
| 634 | ORANGEFS_I(file->f_path.dentry->d_inode); |
| 635 | struct orangefs_kernel_op_s *new_op = NULL; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 636 | |
| 637 | /* required call */ |
| 638 | filemap_write_and_wait_range(file->f_mapping, start, end); |
| 639 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 640 | new_op = op_alloc(ORANGEFS_VFS_OP_FSYNC); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 641 | if (!new_op) |
| 642 | return -ENOMEM; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 643 | new_op->upcall.req.fsync.refn = orangefs_inode->refn; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 644 | |
| 645 | ret = service_operation(new_op, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 646 | "orangefs_fsync", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 647 | get_interruptible_flag(file->f_path.dentry->d_inode)); |
| 648 | |
| 649 | gossip_debug(GOSSIP_FILE_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 650 | "orangefs_fsync got return value of %d\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 651 | ret); |
| 652 | |
| 653 | op_release(new_op); |
| 654 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 655 | orangefs_flush_inode(file->f_path.dentry->d_inode); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 656 | return ret; |
| 657 | } |
| 658 | |
| 659 | /* |
| 660 | * Change the file pointer position for an instance of an open file. |
| 661 | * |
| 662 | * \note If .llseek is overriden, we must acquire lock as described in |
| 663 | * Documentation/filesystems/Locking. |
| 664 | * |
| 665 | * Future upgrade could support SEEK_DATA and SEEK_HOLE but would |
| 666 | * require much changes to the FS |
| 667 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 668 | static loff_t orangefs_file_llseek(struct file *file, loff_t offset, int origin) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 669 | { |
| 670 | int ret = -EINVAL; |
| 671 | struct inode *inode = file->f_path.dentry->d_inode; |
| 672 | |
| 673 | if (!inode) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 674 | gossip_err("orangefs_file_llseek: invalid inode (NULL)\n"); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 675 | return ret; |
| 676 | } |
| 677 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 678 | if (origin == ORANGEFS_SEEK_END) { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 679 | /* |
| 680 | * revalidate the inode's file size. |
| 681 | * NOTE: We are only interested in file size here, |
| 682 | * so we set mask accordingly. |
| 683 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 684 | ret = orangefs_inode_getattr(inode, ORANGEFS_ATTR_SYS_SIZE); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 685 | if (ret) { |
| 686 | gossip_debug(GOSSIP_FILE_DEBUG, |
| 687 | "%s:%s:%d calling make bad inode\n", |
| 688 | __FILE__, |
| 689 | __func__, |
| 690 | __LINE__); |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 691 | orangefs_make_bad_inode(inode); |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 692 | return ret; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | gossip_debug(GOSSIP_FILE_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 697 | "orangefs_file_llseek: offset is %ld | origin is %d" |
Mike Marshall | 5480494 | 2015-10-05 13:44:24 -0400 | [diff] [blame] | 698 | " | inode size is %lu\n", |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 699 | (long)offset, |
| 700 | origin, |
| 701 | (unsigned long)file->f_path.dentry->d_inode->i_size); |
| 702 | |
| 703 | return generic_file_llseek(file, offset, origin); |
| 704 | } |
| 705 | |
| 706 | /* |
| 707 | * Support local locks (locks that only this kernel knows about) |
| 708 | * if Orangefs was mounted -o local_lock. |
| 709 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 710 | static int orangefs_lock(struct file *filp, int cmd, struct file_lock *fl) |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 711 | { |
Mike Marshall | f957ae2 | 2015-09-24 12:53:05 -0400 | [diff] [blame] | 712 | int rc = -EINVAL; |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 713 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 714 | if (ORANGEFS_SB(filp->f_inode->i_sb)->flags & ORANGEFS_OPT_LOCAL_LOCK) { |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 715 | if (cmd == F_GETLK) { |
| 716 | rc = 0; |
| 717 | posix_test_lock(filp, fl); |
| 718 | } else { |
| 719 | rc = posix_lock_file(filp, fl, NULL); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | return rc; |
| 724 | } |
| 725 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 726 | /** ORANGEFS implementation of VFS file operations */ |
| 727 | const struct file_operations orangefs_file_operations = { |
| 728 | .llseek = orangefs_file_llseek, |
| 729 | .read_iter = orangefs_file_read_iter, |
| 730 | .write_iter = orangefs_file_write_iter, |
| 731 | .lock = orangefs_lock, |
| 732 | .unlocked_ioctl = orangefs_ioctl, |
| 733 | .mmap = orangefs_file_mmap, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 734 | .open = generic_file_open, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 735 | .release = orangefs_file_release, |
| 736 | .fsync = orangefs_fsync, |
Mike Marshall | 5db11c2 | 2015-07-17 10:38:12 -0400 | [diff] [blame] | 737 | }; |