blob: 790855a72e3209b8ab570e1faa311e07b78c25e2 [file] [log] [blame]
Mike Marshall5db11c22015-07-17 10:38:12 -04001/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * Changes by Acxiom Corporation to add protocol version to kernel
5 * communication, Copyright Acxiom Corporation, 2005.
6 *
7 * See COPYING in top-level directory.
8 */
9
10#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -050011#include "orangefs-kernel.h"
12#include "orangefs-dev-proto.h"
13#include "orangefs-bufmap.h"
Mike Marshall5db11c22015-07-17 10:38:12 -040014
15#include <linux/debugfs.h>
16#include <linux/slab.h>
17
18/* this file implements the /dev/pvfs2-req device node */
19
20static int open_access_count;
21
22#define DUMP_DEVICE_ERROR() \
23do { \
24 gossip_err("*****************************************************\n");\
Yi Liu8bb8aef2015-11-24 15:12:14 -050025 gossip_err("ORANGEFS Device Error: You cannot open the device file "); \
Mike Marshall5db11c22015-07-17 10:38:12 -040026 gossip_err("\n/dev/%s more than once. Please make sure that\nthere " \
Yi Liu8bb8aef2015-11-24 15:12:14 -050027 "are no ", ORANGEFS_REQDEVICE_NAME); \
Mike Marshall5db11c22015-07-17 10:38:12 -040028 gossip_err("instances of a program using this device\ncurrently " \
29 "running. (You must verify this!)\n"); \
30 gossip_err("For example, you can use the lsof program as follows:\n");\
31 gossip_err("'lsof | grep %s' (run this as root)\n", \
Yi Liu8bb8aef2015-11-24 15:12:14 -050032 ORANGEFS_REQDEVICE_NAME); \
Mike Marshall5db11c22015-07-17 10:38:12 -040033 gossip_err(" open_access_count = %d\n", open_access_count); \
34 gossip_err("*****************************************************\n");\
35} while (0)
36
37static int hash_func(__u64 tag, int table_size)
38{
Mike Marshall2c590d52015-07-24 10:37:15 -040039 return do_div(tag, (unsigned int)table_size);
Mike Marshall5db11c22015-07-17 10:38:12 -040040}
41
Yi Liu8bb8aef2015-11-24 15:12:14 -050042static void orangefs_devreq_add_op(struct orangefs_kernel_op_s *op)
Mike Marshall5db11c22015-07-17 10:38:12 -040043{
44 int index = hash_func(op->tag, hash_table_size);
45
Mike Marshall5db11c22015-07-17 10:38:12 -040046 list_add_tail(&op->list, &htable_ops_in_progress[index]);
Mike Marshall5db11c22015-07-17 10:38:12 -040047}
48
Yi Liu8bb8aef2015-11-24 15:12:14 -050049static struct orangefs_kernel_op_s *orangefs_devreq_remove_op(__u64 tag)
Mike Marshall5db11c22015-07-17 10:38:12 -040050{
Yi Liu8bb8aef2015-11-24 15:12:14 -050051 struct orangefs_kernel_op_s *op, *next;
Mike Marshall5db11c22015-07-17 10:38:12 -040052 int index;
53
54 index = hash_func(tag, hash_table_size);
55
56 spin_lock(&htable_ops_in_progress_lock);
57 list_for_each_entry_safe(op,
58 next,
59 &htable_ops_in_progress[index],
60 list) {
Al Viroed42fe02016-01-22 19:47:47 -050061 if (op->tag == tag && !op_state_purged(op)) {
62 list_del_init(&op->list);
63 get_op(op); /* increase ref count. */
Mike Marshall5db11c22015-07-17 10:38:12 -040064 spin_unlock(&htable_ops_in_progress_lock);
65 return op;
66 }
67 }
68
69 spin_unlock(&htable_ops_in_progress_lock);
70 return NULL;
71}
72
Yi Liu8bb8aef2015-11-24 15:12:14 -050073static int orangefs_devreq_open(struct inode *inode, struct file *file)
Mike Marshall5db11c22015-07-17 10:38:12 -040074{
75 int ret = -EINVAL;
76
77 if (!(file->f_flags & O_NONBLOCK)) {
Mike Marshall97f10022015-12-11 16:45:03 -050078 gossip_err("%s: device cannot be opened in blocking mode\n",
79 __func__);
Mike Marshall5db11c22015-07-17 10:38:12 -040080 goto out;
81 }
82 ret = -EACCES;
Mike Marshall97f10022015-12-11 16:45:03 -050083 gossip_debug(GOSSIP_DEV_DEBUG, "client-core: opening device\n");
Mike Marshall5db11c22015-07-17 10:38:12 -040084 mutex_lock(&devreq_mutex);
85
86 if (open_access_count == 0) {
Al Virofee25ce2016-01-22 19:46:08 -050087 open_access_count = 1;
Al Virofb6d2522016-01-19 12:00:26 -050088 ret = 0;
Mike Marshall5db11c22015-07-17 10:38:12 -040089 } else {
90 DUMP_DEVICE_ERROR();
91 }
92 mutex_unlock(&devreq_mutex);
93
94out:
95
96 gossip_debug(GOSSIP_DEV_DEBUG,
97 "pvfs2-client-core: open device complete (ret = %d)\n",
98 ret);
99 return ret;
100}
101
Mike Marshall97f10022015-12-11 16:45:03 -0500102/* Function for read() callers into the device */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500103static ssize_t orangefs_devreq_read(struct file *file,
Mike Marshall5db11c22015-07-17 10:38:12 -0400104 char __user *buf,
105 size_t count, loff_t *offset)
106{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500107 struct orangefs_kernel_op_s *op, *temp;
108 __s32 proto_ver = ORANGEFS_KERNEL_PROTO_VERSION;
109 static __s32 magic = ORANGEFS_DEVREQ_MAGIC;
110 struct orangefs_kernel_op_s *cur_op = NULL;
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500111 unsigned long ret;
Mike Marshall5db11c22015-07-17 10:38:12 -0400112
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500113 /* We do not support blocking IO. */
Mike Marshall5db11c22015-07-17 10:38:12 -0400114 if (!(file->f_flags & O_NONBLOCK)) {
Mike Marshall97f10022015-12-11 16:45:03 -0500115 gossip_err("%s: blocking read from client-core.\n",
116 __func__);
Mike Marshall5db11c22015-07-17 10:38:12 -0400117 return -EINVAL;
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500118 }
119
120 /*
Martin Brandenburga762ae62015-12-15 14:22:06 -0500121 * The client will do an ioctl to find MAX_DEV_REQ_UPSIZE, then
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500122 * always read with that size buffer.
123 */
Martin Brandenburga762ae62015-12-15 14:22:06 -0500124 if (count != MAX_DEV_REQ_UPSIZE) {
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500125 gossip_err("orangefs: client-core tried to read wrong size\n");
126 return -EINVAL;
127 }
128
Al Viroed42fe02016-01-22 19:47:47 -0500129restart:
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500130 /* Get next op (if any) from top of list. */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500131 spin_lock(&orangefs_request_list_lock);
132 list_for_each_entry_safe(op, temp, &orangefs_request_list, list) {
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500133 __s32 fsid;
134 /* This lock is held past the end of the loop when we break. */
135 spin_lock(&op->lock);
Al Viroed42fe02016-01-22 19:47:47 -0500136 if (unlikely(op_state_purged(op))) {
137 spin_unlock(&op->lock);
138 continue;
139 }
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500140
141 fsid = fsid_of_op(op);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500142 if (fsid != ORANGEFS_FS_ID_NULL) {
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500143 int ret;
144 /* Skip ops whose filesystem needs to be mounted. */
145 ret = fs_mount_pending(fsid);
146 if (ret == 1) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400147 gossip_debug(GOSSIP_DEV_DEBUG,
Mike Marshall5090c962016-02-04 13:29:27 -0500148 "%s: mount pending, skipping op tag "
149 "%llu %s\n",
150 __func__,
151 llu(op->tag),
152 get_opname_string(op));
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500153 spin_unlock(&op->lock);
Mike Marshall5db11c22015-07-17 10:38:12 -0400154 continue;
Mike Marshall97f10022015-12-11 16:45:03 -0500155 /*
156 * Skip ops whose filesystem we don't know about unless
157 * it is being mounted.
158 */
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500159 /* XXX: is there a better way to detect this? */
160 } else if (ret == -1 &&
Mike Marshall97f10022015-12-11 16:45:03 -0500161 !(op->upcall.type ==
162 ORANGEFS_VFS_OP_FS_MOUNT ||
163 op->upcall.type ==
164 ORANGEFS_VFS_OP_GETATTR)) {
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500165 gossip_debug(GOSSIP_DEV_DEBUG,
166 "orangefs: skipping op tag %llu %s\n",
167 llu(op->tag), get_opname_string(op));
168 gossip_err(
169 "orangefs: ERROR: fs_mount_pending %d\n",
170 fsid);
171 spin_unlock(&op->lock);
172 continue;
Mike Marshall5db11c22015-07-17 10:38:12 -0400173 }
174 }
Mike Marshall5db11c22015-07-17 10:38:12 -0400175 /*
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500176 * Either this op does not pertain to a filesystem, is mounting
177 * a filesystem, or pertains to a mounted filesystem. Let it
178 * through.
Mike Marshall5db11c22015-07-17 10:38:12 -0400179 */
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500180 cur_op = op;
181 break;
Mike Marshall5db11c22015-07-17 10:38:12 -0400182 }
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500183
184 /*
185 * At this point we either have a valid op and can continue or have not
186 * found an op and must ask the client to try again later.
187 */
188 if (!cur_op) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500189 spin_unlock(&orangefs_request_list_lock);
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500190 return -EAGAIN;
191 }
192
193 gossip_debug(GOSSIP_DEV_DEBUG, "orangefs: reading op tag %llu %s\n",
194 llu(cur_op->tag), get_opname_string(cur_op));
195
196 /*
197 * Such an op should never be on the list in the first place. If so, we
198 * will abort.
199 */
200 if (op_state_in_progress(cur_op) || op_state_serviced(cur_op)) {
201 gossip_err("orangefs: ERROR: Current op already queued.\n");
202 list_del(&cur_op->list);
203 spin_unlock(&cur_op->lock);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500204 spin_unlock(&orangefs_request_list_lock);
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500205 return -EAGAIN;
206 }
Al Viroed42fe02016-01-22 19:47:47 -0500207 list_del_init(&cur_op->list);
208 get_op(op);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500209 spin_unlock(&orangefs_request_list_lock);
Al Viroed42fe02016-01-22 19:47:47 -0500210
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500211 spin_unlock(&cur_op->lock);
212
213 /* Push the upcall out. */
214 ret = copy_to_user(buf, &proto_ver, sizeof(__s32));
215 if (ret != 0)
216 goto error;
217 ret = copy_to_user(buf+sizeof(__s32), &magic, sizeof(__s32));
218 if (ret != 0)
219 goto error;
220 ret = copy_to_user(buf+2 * sizeof(__s32), &cur_op->tag, sizeof(__u64));
221 if (ret != 0)
222 goto error;
223 ret = copy_to_user(buf+2*sizeof(__s32)+sizeof(__u64), &cur_op->upcall,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500224 sizeof(struct orangefs_upcall_s));
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500225 if (ret != 0)
226 goto error;
227
Al Viroed42fe02016-01-22 19:47:47 -0500228 spin_lock(&htable_ops_in_progress_lock);
229 spin_lock(&cur_op->lock);
230 if (unlikely(op_state_given_up(cur_op))) {
231 spin_unlock(&cur_op->lock);
232 spin_unlock(&htable_ops_in_progress_lock);
233 op_release(cur_op);
234 goto restart;
235 }
236
237 /*
238 * Set the operation to be in progress and move it between lists since
239 * it has been sent to the client.
240 */
241 set_op_state_inprogress(cur_op);
242 orangefs_devreq_add_op(cur_op);
243 spin_unlock(&cur_op->lock);
244 spin_unlock(&htable_ops_in_progress_lock);
245 op_release(cur_op);
246
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500247 /* The client only asks to read one size buffer. */
Martin Brandenburga762ae62015-12-15 14:22:06 -0500248 return MAX_DEV_REQ_UPSIZE;
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500249error:
250 /*
251 * We were unable to copy the op data to the client. Put the op back in
252 * list. If client has crashed, the op will be purged later when the
253 * device is released.
254 */
255 gossip_err("orangefs: Failed to copy data to user space\n");
Yi Liu8bb8aef2015-11-24 15:12:14 -0500256 spin_lock(&orangefs_request_list_lock);
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500257 spin_lock(&cur_op->lock);
Al Viroed42fe02016-01-22 19:47:47 -0500258 if (likely(!op_state_given_up(cur_op))) {
259 set_op_state_waiting(cur_op);
260 list_add(&cur_op->list, &orangefs_request_list);
261 }
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500262 spin_unlock(&cur_op->lock);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500263 spin_unlock(&orangefs_request_list_lock);
Al Viroed42fe02016-01-22 19:47:47 -0500264 op_release(cur_op);
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500265 return -EFAULT;
Mike Marshall5db11c22015-07-17 10:38:12 -0400266}
267
Mike Marshall97f10022015-12-11 16:45:03 -0500268/*
Mike Marshallb3ae4752016-01-13 11:18:12 -0500269 * Function for writev() callers into the device.
270 *
271 * Userspace should have written:
272 * - __u32 version
273 * - __u32 magic
274 * - __u64 tag
275 * - struct orangefs_downcall_s
276 * - trailer buffer (in the case of READDIR operations)
Mike Marshall97f10022015-12-11 16:45:03 -0500277 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500278static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
Mike Marshall5db11c22015-07-17 10:38:12 -0400279 struct iov_iter *iter)
280{
Mike Marshallb3ae4752016-01-13 11:18:12 -0500281 ssize_t ret;
282 struct orangefs_kernel_op_s *op = NULL;
283 struct {
284 __u32 version;
285 __u32 magic;
286 __u64 tag;
287 } head;
288 int total = ret = iov_iter_count(iter);
289 int n;
290 int downcall_size = sizeof(struct orangefs_downcall_s);
291 int head_size = sizeof(head);
292
293 gossip_debug(GOSSIP_DEV_DEBUG, "%s: total:%d: ret:%zd:\n",
294 __func__,
295 total,
296 ret);
297
298 if (total < MAX_DEV_REQ_DOWNSIZE) {
Mike Marshallcf0c2772016-01-19 12:04:40 -0500299 gossip_err("%s: total:%d: must be at least:%u:\n",
Mike Marshallb3ae4752016-01-13 11:18:12 -0500300 __func__,
301 total,
Mike Marshallcf0c2772016-01-19 12:04:40 -0500302 (unsigned int) MAX_DEV_REQ_DOWNSIZE);
Al Viroed42fe02016-01-22 19:47:47 -0500303 return -EFAULT;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500304 }
305
306 n = copy_from_iter(&head, head_size, iter);
307 if (n < head_size) {
308 gossip_err("%s: failed to copy head.\n", __func__);
Al Viroed42fe02016-01-22 19:47:47 -0500309 return -EFAULT;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500310 }
311
312 if (head.version < ORANGEFS_MINIMUM_USERSPACE_VERSION) {
313 gossip_err("%s: userspace claims version"
314 "%d, minimum version required: %d.\n",
315 __func__,
316 head.version,
317 ORANGEFS_MINIMUM_USERSPACE_VERSION);
Al Viroed42fe02016-01-22 19:47:47 -0500318 return -EPROTO;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500319 }
320
321 if (head.magic != ORANGEFS_DEVREQ_MAGIC) {
322 gossip_err("Error: Device magic number does not match.\n");
Al Viroed42fe02016-01-22 19:47:47 -0500323 return -EPROTO;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500324 }
325
326 op = orangefs_devreq_remove_op(head.tag);
327 if (!op) {
328 gossip_err("WARNING: No one's waiting for tag %llu\n",
329 llu(head.tag));
Al Viroed42fe02016-01-22 19:47:47 -0500330 return ret;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500331 }
332
Mike Marshallb3ae4752016-01-13 11:18:12 -0500333 n = copy_from_iter(&op->downcall, downcall_size, iter);
334 if (n != downcall_size) {
335 gossip_err("%s: failed to copy downcall.\n", __func__);
Mike Marshallb3ae4752016-01-13 11:18:12 -0500336 ret = -EFAULT;
Al Viroed42fe02016-01-22 19:47:47 -0500337 goto Broken;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500338 }
339
340 if (op->downcall.status)
341 goto wakeup;
342
343 /*
344 * We've successfully peeled off the head and the downcall.
345 * Something has gone awry if total doesn't equal the
346 * sum of head_size, downcall_size and trailer_size.
347 */
348 if ((head_size + downcall_size + op->downcall.trailer_size) != total) {
349 gossip_err("%s: funky write, head_size:%d"
350 ": downcall_size:%d: trailer_size:%lld"
351 ": total size:%d:\n",
352 __func__,
353 head_size,
354 downcall_size,
355 op->downcall.trailer_size,
356 total);
Mike Marshallb3ae4752016-01-13 11:18:12 -0500357 ret = -EFAULT;
Al Viroed42fe02016-01-22 19:47:47 -0500358 goto Broken;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500359 }
360
361 /* Only READDIR operations should have trailers. */
362 if ((op->downcall.type != ORANGEFS_VFS_OP_READDIR) &&
363 (op->downcall.trailer_size != 0)) {
364 gossip_err("%s: %x operation with trailer.",
365 __func__,
366 op->downcall.type);
Mike Marshallb3ae4752016-01-13 11:18:12 -0500367 ret = -EFAULT;
Al Viroed42fe02016-01-22 19:47:47 -0500368 goto Broken;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500369 }
370
371 /* READDIR operations should always have trailers. */
372 if ((op->downcall.type == ORANGEFS_VFS_OP_READDIR) &&
373 (op->downcall.trailer_size == 0)) {
374 gossip_err("%s: %x operation with no trailer.",
375 __func__,
376 op->downcall.type);
Mike Marshallb3ae4752016-01-13 11:18:12 -0500377 ret = -EFAULT;
Al Viroed42fe02016-01-22 19:47:47 -0500378 goto Broken;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500379 }
380
381 if (op->downcall.type != ORANGEFS_VFS_OP_READDIR)
382 goto wakeup;
383
384 op->downcall.trailer_buf =
385 vmalloc(op->downcall.trailer_size);
386 if (op->downcall.trailer_buf == NULL) {
387 gossip_err("%s: failed trailer vmalloc.\n",
388 __func__);
Mike Marshallb3ae4752016-01-13 11:18:12 -0500389 ret = -ENOMEM;
Al Viroed42fe02016-01-22 19:47:47 -0500390 goto Broken;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500391 }
392 memset(op->downcall.trailer_buf, 0, op->downcall.trailer_size);
393 n = copy_from_iter(op->downcall.trailer_buf,
394 op->downcall.trailer_size,
395 iter);
396 if (n != op->downcall.trailer_size) {
397 gossip_err("%s: failed to copy trailer.\n", __func__);
398 vfree(op->downcall.trailer_buf);
Mike Marshallb3ae4752016-01-13 11:18:12 -0500399 ret = -EFAULT;
Al Viroed42fe02016-01-22 19:47:47 -0500400 goto Broken;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500401 }
402
403wakeup:
Al Viro2a9e5c22016-01-23 13:45:46 -0500404 /*
405 * tell the vfs op waiting on a waitqueue
406 * that this op is done
407 */
408 spin_lock(&op->lock);
409 if (unlikely(op_state_given_up(op))) {
410 spin_unlock(&op->lock);
411 goto out;
412 }
413 set_op_state_serviced(op);
414 spin_unlock(&op->lock);
Mike Marshallb3ae4752016-01-13 11:18:12 -0500415
416 /*
417 * If this operation is an I/O operation we need to wait
418 * for all data to be copied before we can return to avoid
419 * buffer corruption and races that can pull the buffers
420 * out from under us.
421 *
422 * Essentially we're synchronizing with other parts of the
423 * vfs implicitly by not allowing the user space
424 * application reading/writing this device to return until
425 * the buffers are done being used.
426 */
427 if (op->downcall.type == ORANGEFS_VFS_OP_FILE_IO) {
Al Viro2a9e5c22016-01-23 13:45:46 -0500428 long n = wait_for_completion_interruptible_timeout(&op->done,
429 op_timeout_secs * HZ);
430 if (unlikely(n < 0)) {
431 gossip_debug(GOSSIP_DEV_DEBUG,
432 "%s: signal on I/O wait, aborting\n",
433 __func__);
434 } else if (unlikely(n == 0)) {
435 gossip_debug(GOSSIP_DEV_DEBUG,
436 "%s: timed out.\n",
437 __func__);
Al Viro4f55e392016-01-23 13:27:50 -0500438 }
Mike Marshallb3ae4752016-01-13 11:18:12 -0500439 }
440out:
Al Viro78699e22016-02-11 23:07:19 -0500441 if (unlikely(op_is_cancel(op)))
442 put_cancel(op);
Al Viroed42fe02016-01-22 19:47:47 -0500443 op_release(op);
Mike Marshallb3ae4752016-01-13 11:18:12 -0500444 return ret;
Al Viroed42fe02016-01-22 19:47:47 -0500445
446Broken:
447 spin_lock(&op->lock);
448 if (!op_state_given_up(op)) {
449 op->downcall.status = ret;
450 set_op_state_serviced(op);
451 }
452 spin_unlock(&op->lock);
453 goto out;
Mike Marshall5db11c22015-07-17 10:38:12 -0400454}
455
456/* Returns whether any FS are still pending remounted */
457static int mark_all_pending_mounts(void)
458{
459 int unmounted = 1;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500460 struct orangefs_sb_info_s *orangefs_sb = NULL;
Mike Marshall5db11c22015-07-17 10:38:12 -0400461
Yi Liu8bb8aef2015-11-24 15:12:14 -0500462 spin_lock(&orangefs_superblocks_lock);
463 list_for_each_entry(orangefs_sb, &orangefs_superblocks, list) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400464 /* All of these file system require a remount */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500465 orangefs_sb->mount_pending = 1;
Mike Marshall5db11c22015-07-17 10:38:12 -0400466 unmounted = 0;
467 }
Yi Liu8bb8aef2015-11-24 15:12:14 -0500468 spin_unlock(&orangefs_superblocks_lock);
Mike Marshall5db11c22015-07-17 10:38:12 -0400469 return unmounted;
470}
471
472/*
473 * Determine if a given file system needs to be remounted or not
474 * Returns -1 on error
475 * 0 if already mounted
476 * 1 if needs remount
477 */
478int fs_mount_pending(__s32 fsid)
479{
480 int mount_pending = -1;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500481 struct orangefs_sb_info_s *orangefs_sb = NULL;
Mike Marshall5db11c22015-07-17 10:38:12 -0400482
Yi Liu8bb8aef2015-11-24 15:12:14 -0500483 spin_lock(&orangefs_superblocks_lock);
484 list_for_each_entry(orangefs_sb, &orangefs_superblocks, list) {
485 if (orangefs_sb->fs_id == fsid) {
486 mount_pending = orangefs_sb->mount_pending;
Mike Marshall5db11c22015-07-17 10:38:12 -0400487 break;
488 }
489 }
Yi Liu8bb8aef2015-11-24 15:12:14 -0500490 spin_unlock(&orangefs_superblocks_lock);
Mike Marshall5db11c22015-07-17 10:38:12 -0400491 return mount_pending;
492}
493
494/*
495 * NOTE: gets called when the last reference to this device is dropped.
496 * Using the open_access_count variable, we enforce a reference count
497 * on this file so that it can be opened by only one process at a time.
498 * the devreq_mutex is used to make sure all i/o has completed
Yi Liu8bb8aef2015-11-24 15:12:14 -0500499 * before we call orangefs_bufmap_finalize, and similar such tricky
Mike Marshall5db11c22015-07-17 10:38:12 -0400500 * situations
501 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500502static int orangefs_devreq_release(struct inode *inode, struct file *file)
Mike Marshall5db11c22015-07-17 10:38:12 -0400503{
504 int unmounted = 0;
505
506 gossip_debug(GOSSIP_DEV_DEBUG,
507 "%s:pvfs2-client-core: exiting, closing device\n",
508 __func__);
509
510 mutex_lock(&devreq_mutex);
Al Viroea2c9c92016-02-13 21:01:21 -0500511 orangefs_bufmap_finalize();
Mike Marshall5db11c22015-07-17 10:38:12 -0400512
Al Virofee25ce2016-01-22 19:46:08 -0500513 open_access_count = -1;
Mike Marshall5db11c22015-07-17 10:38:12 -0400514
515 unmounted = mark_all_pending_mounts();
Yi Liu8bb8aef2015-11-24 15:12:14 -0500516 gossip_debug(GOSSIP_DEV_DEBUG, "ORANGEFS Device Close: Filesystem(s) %s\n",
Mike Marshall5db11c22015-07-17 10:38:12 -0400517 (unmounted ? "UNMOUNTED" : "MOUNTED"));
Mike Marshall5db11c22015-07-17 10:38:12 -0400518
519 /*
520 * Walk through the list of ops in the request list, mark them
521 * as purged and wake them up.
522 */
523 purge_waiting_ops();
524 /*
525 * Walk through the hash table of in progress operations; mark
526 * them as purged and wake them up
527 */
528 purge_inprogress_ops();
Al Viroea2c9c92016-02-13 21:01:21 -0500529
530 orangefs_bufmap_run_down();
531
Mike Marshall5db11c22015-07-17 10:38:12 -0400532 gossip_debug(GOSSIP_DEV_DEBUG,
533 "pvfs2-client-core: device close complete\n");
Al Virofee25ce2016-01-22 19:46:08 -0500534 open_access_count = 0;
535 mutex_unlock(&devreq_mutex);
Mike Marshall5db11c22015-07-17 10:38:12 -0400536 return 0;
537}
538
539int is_daemon_in_service(void)
540{
541 int in_service;
542
543 /*
544 * What this function does is checks if client-core is alive
545 * based on the access count we maintain on the device.
546 */
547 mutex_lock(&devreq_mutex);
548 in_service = open_access_count == 1 ? 0 : -EIO;
549 mutex_unlock(&devreq_mutex);
550 return in_service;
551}
552
Al Viro78699e22016-02-11 23:07:19 -0500553bool __is_daemon_in_service(void)
554{
555 return open_access_count == 1;
556}
557
Mike Marshall5db11c22015-07-17 10:38:12 -0400558static inline long check_ioctl_command(unsigned int command)
559{
560 /* Check for valid ioctl codes */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500561 if (_IOC_TYPE(command) != ORANGEFS_DEV_MAGIC) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400562 gossip_err("device ioctl magic numbers don't match! Did you rebuild pvfs2-client-core/libpvfs2? [cmd %x, magic %x != %x]\n",
563 command,
564 _IOC_TYPE(command),
Yi Liu8bb8aef2015-11-24 15:12:14 -0500565 ORANGEFS_DEV_MAGIC);
Mike Marshall5db11c22015-07-17 10:38:12 -0400566 return -EINVAL;
567 }
568 /* and valid ioctl commands */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500569 if (_IOC_NR(command) >= ORANGEFS_DEV_MAXNR || _IOC_NR(command) <= 0) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400570 gossip_err("Invalid ioctl command number [%d >= %d]\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500571 _IOC_NR(command), ORANGEFS_DEV_MAXNR);
Mike Marshall5db11c22015-07-17 10:38:12 -0400572 return -ENOIOCTLCMD;
573 }
574 return 0;
575}
576
577static long dispatch_ioctl_command(unsigned int command, unsigned long arg)
578{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500579 static __s32 magic = ORANGEFS_DEVREQ_MAGIC;
Martin Brandenburga762ae62015-12-15 14:22:06 -0500580 static __s32 max_up_size = MAX_DEV_REQ_UPSIZE;
581 static __s32 max_down_size = MAX_DEV_REQ_DOWNSIZE;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500582 struct ORANGEFS_dev_map_desc user_desc;
Mike Marshall5db11c22015-07-17 10:38:12 -0400583 int ret = 0;
584 struct dev_mask_info_s mask_info = { 0 };
585 struct dev_mask2_info_s mask2_info = { 0, 0 };
586 int upstream_kmod = 1;
587 struct list_head *tmp = NULL;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500588 struct orangefs_sb_info_s *orangefs_sb = NULL;
Mike Marshall5db11c22015-07-17 10:38:12 -0400589
590 /* mtmoore: add locking here */
591
592 switch (command) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500593 case ORANGEFS_DEV_GET_MAGIC:
Mike Marshall5db11c22015-07-17 10:38:12 -0400594 return ((put_user(magic, (__s32 __user *) arg) == -EFAULT) ?
595 -EIO :
596 0);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500597 case ORANGEFS_DEV_GET_MAX_UPSIZE:
Mike Marshall5db11c22015-07-17 10:38:12 -0400598 return ((put_user(max_up_size,
599 (__s32 __user *) arg) == -EFAULT) ?
600 -EIO :
601 0);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500602 case ORANGEFS_DEV_GET_MAX_DOWNSIZE:
Mike Marshall5db11c22015-07-17 10:38:12 -0400603 return ((put_user(max_down_size,
604 (__s32 __user *) arg) == -EFAULT) ?
605 -EIO :
606 0);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500607 case ORANGEFS_DEV_MAP:
Mike Marshall5db11c22015-07-17 10:38:12 -0400608 ret = copy_from_user(&user_desc,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500609 (struct ORANGEFS_dev_map_desc __user *)
Mike Marshall5db11c22015-07-17 10:38:12 -0400610 arg,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500611 sizeof(struct ORANGEFS_dev_map_desc));
Al Viroea2c9c92016-02-13 21:01:21 -0500612 /* WTF -EIO and not -EFAULT? */
613 return ret ? -EIO : orangefs_bufmap_initialize(&user_desc);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500614 case ORANGEFS_DEV_REMOUNT_ALL:
Mike Marshall5db11c22015-07-17 10:38:12 -0400615 gossip_debug(GOSSIP_DEV_DEBUG,
Mike Marshall97f10022015-12-11 16:45:03 -0500616 "%s: got ORANGEFS_DEV_REMOUNT_ALL\n",
617 __func__);
Mike Marshall5db11c22015-07-17 10:38:12 -0400618
619 /*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500620 * remount all mounted orangefs volumes to regain the lost
Mike Marshall5db11c22015-07-17 10:38:12 -0400621 * dynamic mount tables (if any) -- NOTE: this is done
622 * without keeping the superblock list locked due to the
623 * upcall/downcall waiting. also, the request semaphore is
624 * used to ensure that no operations will be serviced until
625 * all of the remounts are serviced (to avoid ops between
626 * mounts to fail)
627 */
628 ret = mutex_lock_interruptible(&request_mutex);
629 if (ret < 0)
630 return ret;
631 gossip_debug(GOSSIP_DEV_DEBUG,
Mike Marshall97f10022015-12-11 16:45:03 -0500632 "%s: priority remount in progress\n",
633 __func__);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500634 list_for_each(tmp, &orangefs_superblocks) {
635 orangefs_sb =
Mike Marshall97f10022015-12-11 16:45:03 -0500636 list_entry(tmp,
637 struct orangefs_sb_info_s,
638 list);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500639 if (orangefs_sb && (orangefs_sb->sb)) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400640 gossip_debug(GOSSIP_DEV_DEBUG,
Mike Marshall97f10022015-12-11 16:45:03 -0500641 "%s: Remounting SB %p\n",
642 __func__,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500643 orangefs_sb);
Mike Marshall5db11c22015-07-17 10:38:12 -0400644
Yi Liu8bb8aef2015-11-24 15:12:14 -0500645 ret = orangefs_remount(orangefs_sb->sb);
Mike Marshall5db11c22015-07-17 10:38:12 -0400646 if (ret) {
647 gossip_debug(GOSSIP_DEV_DEBUG,
648 "SB %p remount failed\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500649 orangefs_sb);
Mike Marshall97f10022015-12-11 16:45:03 -0500650 break;
Mike Marshall5db11c22015-07-17 10:38:12 -0400651 }
652 }
653 }
654 gossip_debug(GOSSIP_DEV_DEBUG,
Mike Marshall97f10022015-12-11 16:45:03 -0500655 "%s: priority remount complete\n",
656 __func__);
Mike Marshall5db11c22015-07-17 10:38:12 -0400657 mutex_unlock(&request_mutex);
658 return ret;
659
Yi Liu8bb8aef2015-11-24 15:12:14 -0500660 case ORANGEFS_DEV_UPSTREAM:
Mike Marshall5db11c22015-07-17 10:38:12 -0400661 ret = copy_to_user((void __user *)arg,
662 &upstream_kmod,
663 sizeof(upstream_kmod));
664
665 if (ret != 0)
666 return -EIO;
667 else
668 return ret;
669
Yi Liu8bb8aef2015-11-24 15:12:14 -0500670 case ORANGEFS_DEV_CLIENT_MASK:
Mike Marshall5db11c22015-07-17 10:38:12 -0400671 ret = copy_from_user(&mask2_info,
672 (void __user *)arg,
673 sizeof(struct dev_mask2_info_s));
674
675 if (ret != 0)
676 return -EIO;
677
678 client_debug_mask.mask1 = mask2_info.mask1_value;
679 client_debug_mask.mask2 = mask2_info.mask2_value;
680
681 pr_info("%s: client debug mask has been been received "
682 ":%llx: :%llx:\n",
683 __func__,
684 (unsigned long long)client_debug_mask.mask1,
685 (unsigned long long)client_debug_mask.mask2);
686
687 return ret;
688
Yi Liu8bb8aef2015-11-24 15:12:14 -0500689 case ORANGEFS_DEV_CLIENT_STRING:
Mike Marshall5db11c22015-07-17 10:38:12 -0400690 ret = copy_from_user(&client_debug_array_string,
691 (void __user *)arg,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500692 ORANGEFS_MAX_DEBUG_STRING_LEN);
Mike Marshall5db11c22015-07-17 10:38:12 -0400693 if (ret != 0) {
Mike Marshall97f10022015-12-11 16:45:03 -0500694 pr_info("%s: CLIENT_STRING: copy_from_user failed\n",
Mike Marshall5db11c22015-07-17 10:38:12 -0400695 __func__);
696 return -EIO;
697 }
698
Mike Marshall97f10022015-12-11 16:45:03 -0500699 pr_info("%s: client debug array string has been received.\n",
Mike Marshall5db11c22015-07-17 10:38:12 -0400700 __func__);
701
702 if (!help_string_initialized) {
703
704 /* Free the "we don't know yet" default string... */
705 kfree(debug_help_string);
706
707 /* build a proper debug help string */
708 if (orangefs_prepare_debugfs_help_string(0)) {
Mike Marshall97f10022015-12-11 16:45:03 -0500709 gossip_err("%s: no debug help string \n",
Mike Marshall5db11c22015-07-17 10:38:12 -0400710 __func__);
711 return -EIO;
712 }
713
714 /* Replace the boilerplate boot-time debug-help file. */
715 debugfs_remove(help_file_dentry);
716
717 help_file_dentry =
718 debugfs_create_file(
719 ORANGEFS_KMOD_DEBUG_HELP_FILE,
720 0444,
721 debug_dir,
722 debug_help_string,
723 &debug_help_fops);
724
725 if (!help_file_dentry) {
726 gossip_err("%s: debugfs_create_file failed for"
727 " :%s:!\n",
728 __func__,
729 ORANGEFS_KMOD_DEBUG_HELP_FILE);
730 return -EIO;
731 }
732 }
733
734 debug_mask_to_string(&client_debug_mask, 1);
735
736 debugfs_remove(client_debug_dentry);
737
Yi Liu8bb8aef2015-11-24 15:12:14 -0500738 orangefs_client_debug_init();
Mike Marshall5db11c22015-07-17 10:38:12 -0400739
740 help_string_initialized++;
741
742 return ret;
743
Yi Liu8bb8aef2015-11-24 15:12:14 -0500744 case ORANGEFS_DEV_DEBUG:
Mike Marshall5db11c22015-07-17 10:38:12 -0400745 ret = copy_from_user(&mask_info,
746 (void __user *)arg,
747 sizeof(mask_info));
748
749 if (ret != 0)
750 return -EIO;
751
752 if (mask_info.mask_type == KERNEL_MASK) {
753 if ((mask_info.mask_value == 0)
754 && (kernel_mask_set_mod_init)) {
755 /*
756 * the kernel debug mask was set when the
757 * kernel module was loaded; don't override
758 * it if the client-core was started without
Yi Liu8bb8aef2015-11-24 15:12:14 -0500759 * a value for ORANGEFS_KMODMASK.
Mike Marshall5db11c22015-07-17 10:38:12 -0400760 */
761 return 0;
762 }
763 debug_mask_to_string(&mask_info.mask_value,
764 mask_info.mask_type);
765 gossip_debug_mask = mask_info.mask_value;
Mike Marshall97f10022015-12-11 16:45:03 -0500766 pr_info("%s: kernel debug mask has been modified to "
Mike Marshall5db11c22015-07-17 10:38:12 -0400767 ":%s: :%llx:\n",
Mike Marshall97f10022015-12-11 16:45:03 -0500768 __func__,
Mike Marshall5db11c22015-07-17 10:38:12 -0400769 kernel_debug_string,
770 (unsigned long long)gossip_debug_mask);
771 } else if (mask_info.mask_type == CLIENT_MASK) {
772 debug_mask_to_string(&mask_info.mask_value,
773 mask_info.mask_type);
Mike Marshall97f10022015-12-11 16:45:03 -0500774 pr_info("%s: client debug mask has been modified to"
Mike Marshall5db11c22015-07-17 10:38:12 -0400775 ":%s: :%llx:\n",
Mike Marshall97f10022015-12-11 16:45:03 -0500776 __func__,
Mike Marshall5db11c22015-07-17 10:38:12 -0400777 client_debug_string,
778 llu(mask_info.mask_value));
779 } else {
780 gossip_lerr("Invalid mask type....\n");
781 return -EINVAL;
782 }
783
784 return ret;
785
786 default:
787 return -ENOIOCTLCMD;
788 }
789 return -ENOIOCTLCMD;
790}
791
Yi Liu8bb8aef2015-11-24 15:12:14 -0500792static long orangefs_devreq_ioctl(struct file *file,
Mike Marshall5db11c22015-07-17 10:38:12 -0400793 unsigned int command, unsigned long arg)
794{
795 long ret;
796
797 /* Check for properly constructed commands */
798 ret = check_ioctl_command(command);
799 if (ret < 0)
800 return (int)ret;
801
802 return (int)dispatch_ioctl_command(command, arg);
803}
804
805#ifdef CONFIG_COMPAT /* CONFIG_COMPAT is in .config */
806
Yi Liu8bb8aef2015-11-24 15:12:14 -0500807/* Compat structure for the ORANGEFS_DEV_MAP ioctl */
808struct ORANGEFS_dev_map_desc32 {
Mike Marshall5db11c22015-07-17 10:38:12 -0400809 compat_uptr_t ptr;
810 __s32 total_size;
811 __s32 size;
812 __s32 count;
813};
814
815static unsigned long translate_dev_map26(unsigned long args, long *error)
816{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500817 struct ORANGEFS_dev_map_desc32 __user *p32 = (void __user *)args;
Mike Marshall5db11c22015-07-17 10:38:12 -0400818 /*
819 * Depending on the architecture, allocate some space on the
820 * user-call-stack based on our expected layout.
821 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500822 struct ORANGEFS_dev_map_desc __user *p =
Mike Marshall5db11c22015-07-17 10:38:12 -0400823 compat_alloc_user_space(sizeof(*p));
Mike Marshall84d02152015-07-28 13:27:51 -0400824 compat_uptr_t addr;
Mike Marshall5db11c22015-07-17 10:38:12 -0400825
826 *error = 0;
827 /* get the ptr from the 32 bit user-space */
828 if (get_user(addr, &p32->ptr))
829 goto err;
830 /* try to put that into a 64-bit layout */
831 if (put_user(compat_ptr(addr), &p->ptr))
832 goto err;
833 /* copy the remaining fields */
834 if (copy_in_user(&p->total_size, &p32->total_size, sizeof(__s32)))
835 goto err;
836 if (copy_in_user(&p->size, &p32->size, sizeof(__s32)))
837 goto err;
838 if (copy_in_user(&p->count, &p32->count, sizeof(__s32)))
839 goto err;
840 return (unsigned long)p;
841err:
842 *error = -EFAULT;
843 return 0;
844}
845
846/*
847 * 32 bit user-space apps' ioctl handlers when kernel modules
848 * is compiled as a 64 bit one
849 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500850static long orangefs_devreq_compat_ioctl(struct file *filp, unsigned int cmd,
Mike Marshall5db11c22015-07-17 10:38:12 -0400851 unsigned long args)
852{
853 long ret;
854 unsigned long arg = args;
855
856 /* Check for properly constructed commands */
857 ret = check_ioctl_command(cmd);
858 if (ret < 0)
859 return ret;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500860 if (cmd == ORANGEFS_DEV_MAP) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400861 /*
862 * convert the arguments to what we expect internally
863 * in kernel space
864 */
865 arg = translate_dev_map26(args, &ret);
866 if (ret < 0) {
867 gossip_err("Could not translate dev map\n");
868 return ret;
869 }
870 }
871 /* no other ioctl requires translation */
872 return dispatch_ioctl_command(cmd, arg);
873}
874
Mike Marshall2c590d52015-07-24 10:37:15 -0400875#endif /* CONFIG_COMPAT is in .config */
876
Mike Marshall5db11c22015-07-17 10:38:12 -0400877/* the assigned character device major number */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500878static int orangefs_dev_major;
Mike Marshall5db11c22015-07-17 10:38:12 -0400879
880/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500881 * Initialize orangefs device specific state:
Mike Marshall5db11c22015-07-17 10:38:12 -0400882 * Must be called at module load time only
883 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500884int orangefs_dev_init(void)
Mike Marshall5db11c22015-07-17 10:38:12 -0400885{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500886 /* register orangefs-req device */
887 orangefs_dev_major = register_chrdev(0,
888 ORANGEFS_REQDEVICE_NAME,
889 &orangefs_devreq_file_operations);
890 if (orangefs_dev_major < 0) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400891 gossip_debug(GOSSIP_DEV_DEBUG,
892 "Failed to register /dev/%s (error %d)\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500893 ORANGEFS_REQDEVICE_NAME, orangefs_dev_major);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500894 return orangefs_dev_major;
Mike Marshall5db11c22015-07-17 10:38:12 -0400895 }
896
897 gossip_debug(GOSSIP_DEV_DEBUG,
898 "*** /dev/%s character device registered ***\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500899 ORANGEFS_REQDEVICE_NAME);
Mike Marshall5db11c22015-07-17 10:38:12 -0400900 gossip_debug(GOSSIP_DEV_DEBUG, "'mknod /dev/%s c %d 0'.\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500901 ORANGEFS_REQDEVICE_NAME, orangefs_dev_major);
Mike Marshall5db11c22015-07-17 10:38:12 -0400902 return 0;
903}
904
Yi Liu8bb8aef2015-11-24 15:12:14 -0500905void orangefs_dev_cleanup(void)
Mike Marshall5db11c22015-07-17 10:38:12 -0400906{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500907 unregister_chrdev(orangefs_dev_major, ORANGEFS_REQDEVICE_NAME);
Mike Marshall5db11c22015-07-17 10:38:12 -0400908 gossip_debug(GOSSIP_DEV_DEBUG,
909 "*** /dev/%s character device unregistered ***\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500910 ORANGEFS_REQDEVICE_NAME);
Mike Marshall5db11c22015-07-17 10:38:12 -0400911}
912
Yi Liu8bb8aef2015-11-24 15:12:14 -0500913static unsigned int orangefs_devreq_poll(struct file *file,
Mike Marshall5db11c22015-07-17 10:38:12 -0400914 struct poll_table_struct *poll_table)
915{
916 int poll_revent_mask = 0;
917
Al Viro83595db2016-01-19 12:03:05 -0500918 poll_wait(file, &orangefs_request_list_waitq, poll_table);
Mike Marshall5db11c22015-07-17 10:38:12 -0400919
Al Viro83595db2016-01-19 12:03:05 -0500920 if (!list_empty(&orangefs_request_list))
921 poll_revent_mask |= POLL_IN;
Mike Marshall5db11c22015-07-17 10:38:12 -0400922 return poll_revent_mask;
923}
924
Yi Liu8bb8aef2015-11-24 15:12:14 -0500925const struct file_operations orangefs_devreq_file_operations = {
Mike Marshall5db11c22015-07-17 10:38:12 -0400926 .owner = THIS_MODULE,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500927 .read = orangefs_devreq_read,
928 .write_iter = orangefs_devreq_write_iter,
929 .open = orangefs_devreq_open,
930 .release = orangefs_devreq_release,
931 .unlocked_ioctl = orangefs_devreq_ioctl,
Mike Marshall5db11c22015-07-17 10:38:12 -0400932
933#ifdef CONFIG_COMPAT /* CONFIG_COMPAT is in .config */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500934 .compat_ioctl = orangefs_devreq_compat_ioctl,
Mike Marshall5db11c22015-07-17 10:38:12 -0400935#endif
Yi Liu8bb8aef2015-11-24 15:12:14 -0500936 .poll = orangefs_devreq_poll
Mike Marshall5db11c22015-07-17 10:38:12 -0400937};