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