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