blob: e3934c06b96a896fdcdb080b2980888f53fd0f27 [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
Mike Marshallca9f5182016-02-26 10:21:12 -050049/*
50 * find the op with this tag and remove it from the in progress
51 * hash table.
52 */
Yi Liu8bb8aef2015-11-24 15:12:14 -050053static struct orangefs_kernel_op_s *orangefs_devreq_remove_op(__u64 tag)
Mike Marshall5db11c22015-07-17 10:38:12 -040054{
Yi Liu8bb8aef2015-11-24 15:12:14 -050055 struct orangefs_kernel_op_s *op, *next;
Mike Marshall5db11c22015-07-17 10:38:12 -040056 int index;
57
58 index = hash_func(tag, hash_table_size);
59
60 spin_lock(&htable_ops_in_progress_lock);
61 list_for_each_entry_safe(op,
62 next,
63 &htable_ops_in_progress[index],
64 list) {
Al Viro05a50a52016-02-18 18:59:44 -050065 if (op->tag == tag && !op_state_purged(op) &&
66 !op_state_given_up(op)) {
Al Viroed42fe02016-01-22 19:47:47 -050067 list_del_init(&op->list);
Mike Marshall5db11c22015-07-17 10:38:12 -040068 spin_unlock(&htable_ops_in_progress_lock);
69 return op;
70 }
71 }
72
73 spin_unlock(&htable_ops_in_progress_lock);
74 return NULL;
75}
76
Yi Liu8bb8aef2015-11-24 15:12:14 -050077static int orangefs_devreq_open(struct inode *inode, struct file *file)
Mike Marshall5db11c22015-07-17 10:38:12 -040078{
79 int ret = -EINVAL;
80
81 if (!(file->f_flags & O_NONBLOCK)) {
Mike Marshall97f10022015-12-11 16:45:03 -050082 gossip_err("%s: device cannot be opened in blocking mode\n",
83 __func__);
Mike Marshall5db11c22015-07-17 10:38:12 -040084 goto out;
85 }
86 ret = -EACCES;
Mike Marshall97f10022015-12-11 16:45:03 -050087 gossip_debug(GOSSIP_DEV_DEBUG, "client-core: opening device\n");
Mike Marshall5db11c22015-07-17 10:38:12 -040088 mutex_lock(&devreq_mutex);
89
90 if (open_access_count == 0) {
Al Virofee25ce2016-01-22 19:46:08 -050091 open_access_count = 1;
Al Virofb6d2522016-01-19 12:00:26 -050092 ret = 0;
Mike Marshall5db11c22015-07-17 10:38:12 -040093 } else {
94 DUMP_DEVICE_ERROR();
95 }
96 mutex_unlock(&devreq_mutex);
97
98out:
99
100 gossip_debug(GOSSIP_DEV_DEBUG,
101 "pvfs2-client-core: open device complete (ret = %d)\n",
102 ret);
103 return ret;
104}
105
Mike Marshall97f10022015-12-11 16:45:03 -0500106/* Function for read() callers into the device */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500107static ssize_t orangefs_devreq_read(struct file *file,
Mike Marshall5db11c22015-07-17 10:38:12 -0400108 char __user *buf,
109 size_t count, loff_t *offset)
110{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500111 struct orangefs_kernel_op_s *op, *temp;
112 __s32 proto_ver = ORANGEFS_KERNEL_PROTO_VERSION;
113 static __s32 magic = ORANGEFS_DEVREQ_MAGIC;
114 struct orangefs_kernel_op_s *cur_op = NULL;
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500115 unsigned long ret;
Mike Marshall5db11c22015-07-17 10:38:12 -0400116
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500117 /* We do not support blocking IO. */
Mike Marshall5db11c22015-07-17 10:38:12 -0400118 if (!(file->f_flags & O_NONBLOCK)) {
Mike Marshall97f10022015-12-11 16:45:03 -0500119 gossip_err("%s: blocking read from client-core.\n",
120 __func__);
Mike Marshall5db11c22015-07-17 10:38:12 -0400121 return -EINVAL;
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500122 }
123
124 /*
Martin Brandenburga762ae62015-12-15 14:22:06 -0500125 * The client will do an ioctl to find MAX_DEV_REQ_UPSIZE, then
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500126 * always read with that size buffer.
127 */
Martin Brandenburga762ae62015-12-15 14:22:06 -0500128 if (count != MAX_DEV_REQ_UPSIZE) {
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500129 gossip_err("orangefs: client-core tried to read wrong size\n");
130 return -EINVAL;
131 }
132
Al Viroed42fe02016-01-22 19:47:47 -0500133restart:
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500134 /* Get next op (if any) from top of list. */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500135 spin_lock(&orangefs_request_list_lock);
136 list_for_each_entry_safe(op, temp, &orangefs_request_list, list) {
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500137 __s32 fsid;
138 /* This lock is held past the end of the loop when we break. */
139 spin_lock(&op->lock);
Al Viro05a50a52016-02-18 18:59:44 -0500140 if (unlikely(op_state_purged(op) || op_state_given_up(op))) {
Al Viroed42fe02016-01-22 19:47:47 -0500141 spin_unlock(&op->lock);
142 continue;
143 }
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500144
145 fsid = fsid_of_op(op);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500146 if (fsid != ORANGEFS_FS_ID_NULL) {
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500147 int ret;
148 /* Skip ops whose filesystem needs to be mounted. */
149 ret = fs_mount_pending(fsid);
150 if (ret == 1) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400151 gossip_debug(GOSSIP_DEV_DEBUG,
Mike Marshall5090c962016-02-04 13:29:27 -0500152 "%s: mount pending, skipping op tag "
153 "%llu %s\n",
154 __func__,
155 llu(op->tag),
156 get_opname_string(op));
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500157 spin_unlock(&op->lock);
Mike Marshall5db11c22015-07-17 10:38:12 -0400158 continue;
Mike Marshall97f10022015-12-11 16:45:03 -0500159 /*
160 * Skip ops whose filesystem we don't know about unless
161 * it is being mounted.
162 */
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500163 /* XXX: is there a better way to detect this? */
164 } else if (ret == -1 &&
Mike Marshall97f10022015-12-11 16:45:03 -0500165 !(op->upcall.type ==
166 ORANGEFS_VFS_OP_FS_MOUNT ||
167 op->upcall.type ==
168 ORANGEFS_VFS_OP_GETATTR)) {
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500169 gossip_debug(GOSSIP_DEV_DEBUG,
170 "orangefs: skipping op tag %llu %s\n",
171 llu(op->tag), get_opname_string(op));
172 gossip_err(
173 "orangefs: ERROR: fs_mount_pending %d\n",
174 fsid);
175 spin_unlock(&op->lock);
176 continue;
Mike Marshall5db11c22015-07-17 10:38:12 -0400177 }
178 }
Mike Marshall5db11c22015-07-17 10:38:12 -0400179 /*
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500180 * Either this op does not pertain to a filesystem, is mounting
181 * a filesystem, or pertains to a mounted filesystem. Let it
182 * through.
Mike Marshall5db11c22015-07-17 10:38:12 -0400183 */
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500184 cur_op = op;
185 break;
Mike Marshall5db11c22015-07-17 10:38:12 -0400186 }
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500187
188 /*
189 * At this point we either have a valid op and can continue or have not
190 * found an op and must ask the client to try again later.
191 */
192 if (!cur_op) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500193 spin_unlock(&orangefs_request_list_lock);
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500194 return -EAGAIN;
195 }
196
Mike Marshallca9f5182016-02-26 10:21:12 -0500197 gossip_debug(GOSSIP_DEV_DEBUG, "%s: reading op tag %llu %s\n",
198 __func__,
199 llu(cur_op->tag),
200 get_opname_string(cur_op));
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500201
202 /*
203 * Such an op should never be on the list in the first place. If so, we
204 * will abort.
205 */
206 if (op_state_in_progress(cur_op) || op_state_serviced(cur_op)) {
207 gossip_err("orangefs: ERROR: Current op already queued.\n");
Al Viro05a50a52016-02-18 18:59:44 -0500208 list_del_init(&cur_op->list);
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500209 spin_unlock(&cur_op->lock);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500210 spin_unlock(&orangefs_request_list_lock);
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500211 return -EAGAIN;
212 }
Mike Marshallca9f5182016-02-26 10:21:12 -0500213
Al Viroed42fe02016-01-22 19:47:47 -0500214 list_del_init(&cur_op->list);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500215 spin_unlock(&orangefs_request_list_lock);
Al Viroed42fe02016-01-22 19:47:47 -0500216
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500217 spin_unlock(&cur_op->lock);
218
219 /* Push the upcall out. */
220 ret = copy_to_user(buf, &proto_ver, sizeof(__s32));
221 if (ret != 0)
222 goto error;
223 ret = copy_to_user(buf+sizeof(__s32), &magic, sizeof(__s32));
224 if (ret != 0)
225 goto error;
226 ret = copy_to_user(buf+2 * sizeof(__s32), &cur_op->tag, sizeof(__u64));
227 if (ret != 0)
228 goto error;
229 ret = copy_to_user(buf+2*sizeof(__s32)+sizeof(__u64), &cur_op->upcall,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500230 sizeof(struct orangefs_upcall_s));
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500231 if (ret != 0)
232 goto error;
233
Al Viroed42fe02016-01-22 19:47:47 -0500234 spin_lock(&htable_ops_in_progress_lock);
235 spin_lock(&cur_op->lock);
236 if (unlikely(op_state_given_up(cur_op))) {
237 spin_unlock(&cur_op->lock);
238 spin_unlock(&htable_ops_in_progress_lock);
Al Viro05a50a52016-02-18 18:59:44 -0500239 complete(&cur_op->waitq);
Al Viroed42fe02016-01-22 19:47:47 -0500240 goto restart;
241 }
242
243 /*
244 * Set the operation to be in progress and move it between lists since
245 * it has been sent to the client.
246 */
247 set_op_state_inprogress(cur_op);
248 orangefs_devreq_add_op(cur_op);
249 spin_unlock(&cur_op->lock);
250 spin_unlock(&htable_ops_in_progress_lock);
Al Viroed42fe02016-01-22 19:47:47 -0500251
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500252 /* The client only asks to read one size buffer. */
Martin Brandenburga762ae62015-12-15 14:22:06 -0500253 return MAX_DEV_REQ_UPSIZE;
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500254error:
255 /*
256 * We were unable to copy the op data to the client. Put the op back in
257 * list. If client has crashed, the op will be purged later when the
258 * device is released.
259 */
260 gossip_err("orangefs: Failed to copy data to user space\n");
Yi Liu8bb8aef2015-11-24 15:12:14 -0500261 spin_lock(&orangefs_request_list_lock);
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500262 spin_lock(&cur_op->lock);
Al Viroed42fe02016-01-22 19:47:47 -0500263 if (likely(!op_state_given_up(cur_op))) {
264 set_op_state_waiting(cur_op);
265 list_add(&cur_op->list, &orangefs_request_list);
Al Viro05a50a52016-02-18 18:59:44 -0500266 spin_unlock(&cur_op->lock);
267 } else {
268 spin_unlock(&cur_op->lock);
269 complete(&cur_op->waitq);
Al Viroed42fe02016-01-22 19:47:47 -0500270 }
Yi Liu8bb8aef2015-11-24 15:12:14 -0500271 spin_unlock(&orangefs_request_list_lock);
Martin Brandenburg24c8d082015-11-13 14:26:10 -0500272 return -EFAULT;
Mike Marshall5db11c22015-07-17 10:38:12 -0400273}
274
Mike Marshall97f10022015-12-11 16:45:03 -0500275/*
Mike Marshallb3ae4752016-01-13 11:18:12 -0500276 * Function for writev() callers into the device.
277 *
278 * Userspace should have written:
279 * - __u32 version
280 * - __u32 magic
281 * - __u64 tag
282 * - struct orangefs_downcall_s
283 * - trailer buffer (in the case of READDIR operations)
Mike Marshall97f10022015-12-11 16:45:03 -0500284 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500285static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
Mike Marshall5db11c22015-07-17 10:38:12 -0400286 struct iov_iter *iter)
287{
Mike Marshallb3ae4752016-01-13 11:18:12 -0500288 ssize_t ret;
289 struct orangefs_kernel_op_s *op = NULL;
290 struct {
291 __u32 version;
292 __u32 magic;
293 __u64 tag;
294 } head;
295 int total = ret = iov_iter_count(iter);
296 int n;
297 int downcall_size = sizeof(struct orangefs_downcall_s);
298 int head_size = sizeof(head);
299
300 gossip_debug(GOSSIP_DEV_DEBUG, "%s: total:%d: ret:%zd:\n",
301 __func__,
302 total,
303 ret);
304
305 if (total < MAX_DEV_REQ_DOWNSIZE) {
Mike Marshallcf0c2772016-01-19 12:04:40 -0500306 gossip_err("%s: total:%d: must be at least:%u:\n",
Mike Marshallb3ae4752016-01-13 11:18:12 -0500307 __func__,
308 total,
Mike Marshallcf0c2772016-01-19 12:04:40 -0500309 (unsigned int) MAX_DEV_REQ_DOWNSIZE);
Al Viroed42fe02016-01-22 19:47:47 -0500310 return -EFAULT;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500311 }
312
313 n = copy_from_iter(&head, head_size, iter);
314 if (n < head_size) {
315 gossip_err("%s: failed to copy head.\n", __func__);
Al Viroed42fe02016-01-22 19:47:47 -0500316 return -EFAULT;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500317 }
318
319 if (head.version < ORANGEFS_MINIMUM_USERSPACE_VERSION) {
320 gossip_err("%s: userspace claims version"
321 "%d, minimum version required: %d.\n",
322 __func__,
323 head.version,
324 ORANGEFS_MINIMUM_USERSPACE_VERSION);
Al Viroed42fe02016-01-22 19:47:47 -0500325 return -EPROTO;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500326 }
327
328 if (head.magic != ORANGEFS_DEVREQ_MAGIC) {
329 gossip_err("Error: Device magic number does not match.\n");
Al Viroed42fe02016-01-22 19:47:47 -0500330 return -EPROTO;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500331 }
332
Mike Marshallca9f5182016-02-26 10:21:12 -0500333 /* remove the op from the in progress hash table */
Mike Marshallb3ae4752016-01-13 11:18:12 -0500334 op = orangefs_devreq_remove_op(head.tag);
335 if (!op) {
336 gossip_err("WARNING: No one's waiting for tag %llu\n",
337 llu(head.tag));
Al Viroed42fe02016-01-22 19:47:47 -0500338 return ret;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500339 }
340
Mike Marshallb3ae4752016-01-13 11:18:12 -0500341 n = copy_from_iter(&op->downcall, downcall_size, iter);
342 if (n != downcall_size) {
343 gossip_err("%s: failed to copy downcall.\n", __func__);
Al Viro5964c1b2016-02-18 18:53:41 -0500344 goto Efault;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500345 }
346
347 if (op->downcall.status)
348 goto wakeup;
349
350 /*
351 * We've successfully peeled off the head and the downcall.
352 * Something has gone awry if total doesn't equal the
353 * sum of head_size, downcall_size and trailer_size.
354 */
355 if ((head_size + downcall_size + op->downcall.trailer_size) != total) {
356 gossip_err("%s: funky write, head_size:%d"
357 ": downcall_size:%d: trailer_size:%lld"
358 ": total size:%d:\n",
359 __func__,
360 head_size,
361 downcall_size,
362 op->downcall.trailer_size,
363 total);
Al Viro5964c1b2016-02-18 18:53:41 -0500364 goto Efault;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500365 }
366
367 /* Only READDIR operations should have trailers. */
368 if ((op->downcall.type != ORANGEFS_VFS_OP_READDIR) &&
369 (op->downcall.trailer_size != 0)) {
370 gossip_err("%s: %x operation with trailer.",
371 __func__,
372 op->downcall.type);
Al Viro5964c1b2016-02-18 18:53:41 -0500373 goto Efault;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500374 }
375
376 /* READDIR operations should always have trailers. */
377 if ((op->downcall.type == ORANGEFS_VFS_OP_READDIR) &&
378 (op->downcall.trailer_size == 0)) {
379 gossip_err("%s: %x operation with no trailer.",
380 __func__,
381 op->downcall.type);
Al Viro5964c1b2016-02-18 18:53:41 -0500382 goto Efault;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500383 }
384
385 if (op->downcall.type != ORANGEFS_VFS_OP_READDIR)
386 goto wakeup;
387
388 op->downcall.trailer_buf =
389 vmalloc(op->downcall.trailer_size);
390 if (op->downcall.trailer_buf == NULL) {
391 gossip_err("%s: failed trailer vmalloc.\n",
392 __func__);
Al Viro5964c1b2016-02-18 18:53:41 -0500393 goto Enomem;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500394 }
395 memset(op->downcall.trailer_buf, 0, op->downcall.trailer_size);
396 n = copy_from_iter(op->downcall.trailer_buf,
397 op->downcall.trailer_size,
398 iter);
399 if (n != op->downcall.trailer_size) {
400 gossip_err("%s: failed to copy trailer.\n", __func__);
401 vfree(op->downcall.trailer_buf);
Al Viro5964c1b2016-02-18 18:53:41 -0500402 goto Efault;
Mike Marshallb3ae4752016-01-13 11:18:12 -0500403 }
404
405wakeup:
Al Viro2a9e5c22016-01-23 13:45:46 -0500406 /*
407 * tell the vfs op waiting on a waitqueue
408 * that this op is done
409 */
410 spin_lock(&op->lock);
Al Viro5964c1b2016-02-18 18:53:41 -0500411 if (unlikely(op_is_cancel(op))) {
Al Viro2a9e5c22016-01-23 13:45:46 -0500412 spin_unlock(&op->lock);
Al Viro78699e22016-02-11 23:07:19 -0500413 put_cancel(op);
Al Viro5964c1b2016-02-18 18:53:41 -0500414 } else if (unlikely(op_state_given_up(op))) {
415 spin_unlock(&op->lock);
Al Viro05a50a52016-02-18 18:59:44 -0500416 complete(&op->waitq);
Al Viro5964c1b2016-02-18 18:53:41 -0500417 } else {
418 set_op_state_serviced(op);
419 spin_unlock(&op->lock);
420 }
Mike Marshallb3ae4752016-01-13 11:18:12 -0500421 return ret;
Al Viroed42fe02016-01-22 19:47:47 -0500422
Al Viro5964c1b2016-02-18 18:53:41 -0500423Efault:
424 op->downcall.status = -(ORANGEFS_ERROR_BIT | 9);
425 ret = -EFAULT;
426 goto wakeup;
427
428Enomem:
429 op->downcall.status = -(ORANGEFS_ERROR_BIT | 8);
430 ret = -ENOMEM;
431 goto wakeup;
Mike Marshall5db11c22015-07-17 10:38:12 -0400432}
433
434/* Returns whether any FS are still pending remounted */
435static int mark_all_pending_mounts(void)
436{
437 int unmounted = 1;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500438 struct orangefs_sb_info_s *orangefs_sb = NULL;
Mike Marshall5db11c22015-07-17 10:38:12 -0400439
Yi Liu8bb8aef2015-11-24 15:12:14 -0500440 spin_lock(&orangefs_superblocks_lock);
441 list_for_each_entry(orangefs_sb, &orangefs_superblocks, list) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400442 /* All of these file system require a remount */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500443 orangefs_sb->mount_pending = 1;
Mike Marshall5db11c22015-07-17 10:38:12 -0400444 unmounted = 0;
445 }
Yi Liu8bb8aef2015-11-24 15:12:14 -0500446 spin_unlock(&orangefs_superblocks_lock);
Mike Marshall5db11c22015-07-17 10:38:12 -0400447 return unmounted;
448}
449
450/*
451 * Determine if a given file system needs to be remounted or not
452 * Returns -1 on error
453 * 0 if already mounted
454 * 1 if needs remount
455 */
456int fs_mount_pending(__s32 fsid)
457{
458 int mount_pending = -1;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500459 struct orangefs_sb_info_s *orangefs_sb = NULL;
Mike Marshall5db11c22015-07-17 10:38:12 -0400460
Yi Liu8bb8aef2015-11-24 15:12:14 -0500461 spin_lock(&orangefs_superblocks_lock);
462 list_for_each_entry(orangefs_sb, &orangefs_superblocks, list) {
463 if (orangefs_sb->fs_id == fsid) {
464 mount_pending = orangefs_sb->mount_pending;
Mike Marshall5db11c22015-07-17 10:38:12 -0400465 break;
466 }
467 }
Yi Liu8bb8aef2015-11-24 15:12:14 -0500468 spin_unlock(&orangefs_superblocks_lock);
Mike Marshall5db11c22015-07-17 10:38:12 -0400469 return mount_pending;
470}
471
472/*
473 * NOTE: gets called when the last reference to this device is dropped.
474 * Using the open_access_count variable, we enforce a reference count
475 * on this file so that it can be opened by only one process at a time.
476 * the devreq_mutex is used to make sure all i/o has completed
Yi Liu8bb8aef2015-11-24 15:12:14 -0500477 * before we call orangefs_bufmap_finalize, and similar such tricky
Mike Marshall5db11c22015-07-17 10:38:12 -0400478 * situations
479 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500480static int orangefs_devreq_release(struct inode *inode, struct file *file)
Mike Marshall5db11c22015-07-17 10:38:12 -0400481{
482 int unmounted = 0;
483
484 gossip_debug(GOSSIP_DEV_DEBUG,
485 "%s:pvfs2-client-core: exiting, closing device\n",
486 __func__);
487
488 mutex_lock(&devreq_mutex);
Al Viroea2c9c92016-02-13 21:01:21 -0500489 orangefs_bufmap_finalize();
Mike Marshall5db11c22015-07-17 10:38:12 -0400490
Al Virofee25ce2016-01-22 19:46:08 -0500491 open_access_count = -1;
Mike Marshall5db11c22015-07-17 10:38:12 -0400492
493 unmounted = mark_all_pending_mounts();
Yi Liu8bb8aef2015-11-24 15:12:14 -0500494 gossip_debug(GOSSIP_DEV_DEBUG, "ORANGEFS Device Close: Filesystem(s) %s\n",
Mike Marshall5db11c22015-07-17 10:38:12 -0400495 (unmounted ? "UNMOUNTED" : "MOUNTED"));
Mike Marshall5db11c22015-07-17 10:38:12 -0400496
Mike Marshall5db11c22015-07-17 10:38:12 -0400497 purge_waiting_ops();
Mike Marshall5db11c22015-07-17 10:38:12 -0400498 purge_inprogress_ops();
Al Viroea2c9c92016-02-13 21:01:21 -0500499
500 orangefs_bufmap_run_down();
501
Mike Marshall5db11c22015-07-17 10:38:12 -0400502 gossip_debug(GOSSIP_DEV_DEBUG,
503 "pvfs2-client-core: device close complete\n");
Al Virofee25ce2016-01-22 19:46:08 -0500504 open_access_count = 0;
505 mutex_unlock(&devreq_mutex);
Mike Marshall5db11c22015-07-17 10:38:12 -0400506 return 0;
507}
508
509int is_daemon_in_service(void)
510{
511 int in_service;
512
513 /*
514 * What this function does is checks if client-core is alive
515 * based on the access count we maintain on the device.
516 */
517 mutex_lock(&devreq_mutex);
518 in_service = open_access_count == 1 ? 0 : -EIO;
519 mutex_unlock(&devreq_mutex);
520 return in_service;
521}
522
Al Viro78699e22016-02-11 23:07:19 -0500523bool __is_daemon_in_service(void)
524{
525 return open_access_count == 1;
526}
527
Mike Marshall5db11c22015-07-17 10:38:12 -0400528static inline long check_ioctl_command(unsigned int command)
529{
530 /* Check for valid ioctl codes */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500531 if (_IOC_TYPE(command) != ORANGEFS_DEV_MAGIC) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400532 gossip_err("device ioctl magic numbers don't match! Did you rebuild pvfs2-client-core/libpvfs2? [cmd %x, magic %x != %x]\n",
533 command,
534 _IOC_TYPE(command),
Yi Liu8bb8aef2015-11-24 15:12:14 -0500535 ORANGEFS_DEV_MAGIC);
Mike Marshall5db11c22015-07-17 10:38:12 -0400536 return -EINVAL;
537 }
538 /* and valid ioctl commands */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500539 if (_IOC_NR(command) >= ORANGEFS_DEV_MAXNR || _IOC_NR(command) <= 0) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400540 gossip_err("Invalid ioctl command number [%d >= %d]\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500541 _IOC_NR(command), ORANGEFS_DEV_MAXNR);
Mike Marshall5db11c22015-07-17 10:38:12 -0400542 return -ENOIOCTLCMD;
543 }
544 return 0;
545}
546
547static long dispatch_ioctl_command(unsigned int command, unsigned long arg)
548{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500549 static __s32 magic = ORANGEFS_DEVREQ_MAGIC;
Martin Brandenburga762ae62015-12-15 14:22:06 -0500550 static __s32 max_up_size = MAX_DEV_REQ_UPSIZE;
551 static __s32 max_down_size = MAX_DEV_REQ_DOWNSIZE;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500552 struct ORANGEFS_dev_map_desc user_desc;
Mike Marshall5db11c22015-07-17 10:38:12 -0400553 int ret = 0;
554 struct dev_mask_info_s mask_info = { 0 };
555 struct dev_mask2_info_s mask2_info = { 0, 0 };
556 int upstream_kmod = 1;
557 struct list_head *tmp = NULL;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500558 struct orangefs_sb_info_s *orangefs_sb = NULL;
Mike Marshall5db11c22015-07-17 10:38:12 -0400559
560 /* mtmoore: add locking here */
561
562 switch (command) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500563 case ORANGEFS_DEV_GET_MAGIC:
Mike Marshall5db11c22015-07-17 10:38:12 -0400564 return ((put_user(magic, (__s32 __user *) arg) == -EFAULT) ?
565 -EIO :
566 0);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500567 case ORANGEFS_DEV_GET_MAX_UPSIZE:
Mike Marshall5db11c22015-07-17 10:38:12 -0400568 return ((put_user(max_up_size,
569 (__s32 __user *) arg) == -EFAULT) ?
570 -EIO :
571 0);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500572 case ORANGEFS_DEV_GET_MAX_DOWNSIZE:
Mike Marshall5db11c22015-07-17 10:38:12 -0400573 return ((put_user(max_down_size,
574 (__s32 __user *) arg) == -EFAULT) ?
575 -EIO :
576 0);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500577 case ORANGEFS_DEV_MAP:
Mike Marshall5db11c22015-07-17 10:38:12 -0400578 ret = copy_from_user(&user_desc,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500579 (struct ORANGEFS_dev_map_desc __user *)
Mike Marshall5db11c22015-07-17 10:38:12 -0400580 arg,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500581 sizeof(struct ORANGEFS_dev_map_desc));
Al Viroea2c9c92016-02-13 21:01:21 -0500582 /* WTF -EIO and not -EFAULT? */
583 return ret ? -EIO : orangefs_bufmap_initialize(&user_desc);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500584 case ORANGEFS_DEV_REMOUNT_ALL:
Mike Marshall5db11c22015-07-17 10:38:12 -0400585 gossip_debug(GOSSIP_DEV_DEBUG,
Mike Marshall97f10022015-12-11 16:45:03 -0500586 "%s: got ORANGEFS_DEV_REMOUNT_ALL\n",
587 __func__);
Mike Marshall5db11c22015-07-17 10:38:12 -0400588
589 /*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500590 * remount all mounted orangefs volumes to regain the lost
Mike Marshall5db11c22015-07-17 10:38:12 -0400591 * dynamic mount tables (if any) -- NOTE: this is done
592 * without keeping the superblock list locked due to the
Mike Marshalladcf34a2016-02-24 16:54:27 -0500593 * upcall/downcall waiting. also, the request mutex is
Mike Marshall5db11c22015-07-17 10:38:12 -0400594 * used to ensure that no operations will be serviced until
595 * all of the remounts are serviced (to avoid ops between
596 * mounts to fail)
597 */
598 ret = mutex_lock_interruptible(&request_mutex);
599 if (ret < 0)
600 return ret;
601 gossip_debug(GOSSIP_DEV_DEBUG,
Mike Marshall97f10022015-12-11 16:45:03 -0500602 "%s: priority remount in progress\n",
603 __func__);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500604 list_for_each(tmp, &orangefs_superblocks) {
605 orangefs_sb =
Mike Marshall97f10022015-12-11 16:45:03 -0500606 list_entry(tmp,
607 struct orangefs_sb_info_s,
608 list);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500609 if (orangefs_sb && (orangefs_sb->sb)) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400610 gossip_debug(GOSSIP_DEV_DEBUG,
Mike Marshall97f10022015-12-11 16:45:03 -0500611 "%s: Remounting SB %p\n",
612 __func__,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500613 orangefs_sb);
Mike Marshall5db11c22015-07-17 10:38:12 -0400614
Yi Liu8bb8aef2015-11-24 15:12:14 -0500615 ret = orangefs_remount(orangefs_sb->sb);
Mike Marshall5db11c22015-07-17 10:38:12 -0400616 if (ret) {
617 gossip_debug(GOSSIP_DEV_DEBUG,
618 "SB %p remount failed\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500619 orangefs_sb);
Mike Marshall97f10022015-12-11 16:45:03 -0500620 break;
Mike Marshall5db11c22015-07-17 10:38:12 -0400621 }
622 }
623 }
624 gossip_debug(GOSSIP_DEV_DEBUG,
Mike Marshall97f10022015-12-11 16:45:03 -0500625 "%s: priority remount complete\n",
626 __func__);
Mike Marshall5db11c22015-07-17 10:38:12 -0400627 mutex_unlock(&request_mutex);
628 return ret;
629
Yi Liu8bb8aef2015-11-24 15:12:14 -0500630 case ORANGEFS_DEV_UPSTREAM:
Mike Marshall5db11c22015-07-17 10:38:12 -0400631 ret = copy_to_user((void __user *)arg,
632 &upstream_kmod,
633 sizeof(upstream_kmod));
634
635 if (ret != 0)
636 return -EIO;
637 else
638 return ret;
639
Yi Liu8bb8aef2015-11-24 15:12:14 -0500640 case ORANGEFS_DEV_CLIENT_MASK:
Mike Marshall5db11c22015-07-17 10:38:12 -0400641 ret = copy_from_user(&mask2_info,
642 (void __user *)arg,
643 sizeof(struct dev_mask2_info_s));
644
645 if (ret != 0)
646 return -EIO;
647
648 client_debug_mask.mask1 = mask2_info.mask1_value;
649 client_debug_mask.mask2 = mask2_info.mask2_value;
650
651 pr_info("%s: client debug mask has been been received "
652 ":%llx: :%llx:\n",
653 __func__,
654 (unsigned long long)client_debug_mask.mask1,
655 (unsigned long long)client_debug_mask.mask2);
656
657 return ret;
658
Yi Liu8bb8aef2015-11-24 15:12:14 -0500659 case ORANGEFS_DEV_CLIENT_STRING:
Mike Marshall5db11c22015-07-17 10:38:12 -0400660 ret = copy_from_user(&client_debug_array_string,
661 (void __user *)arg,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500662 ORANGEFS_MAX_DEBUG_STRING_LEN);
Mike Marshall5db11c22015-07-17 10:38:12 -0400663 if (ret != 0) {
Mike Marshall97f10022015-12-11 16:45:03 -0500664 pr_info("%s: CLIENT_STRING: copy_from_user failed\n",
Mike Marshall5db11c22015-07-17 10:38:12 -0400665 __func__);
666 return -EIO;
667 }
668
Mike Marshall97f10022015-12-11 16:45:03 -0500669 pr_info("%s: client debug array string has been received.\n",
Mike Marshall5db11c22015-07-17 10:38:12 -0400670 __func__);
671
672 if (!help_string_initialized) {
673
674 /* Free the "we don't know yet" default string... */
675 kfree(debug_help_string);
676
677 /* build a proper debug help string */
678 if (orangefs_prepare_debugfs_help_string(0)) {
Mike Marshall97f10022015-12-11 16:45:03 -0500679 gossip_err("%s: no debug help string \n",
Mike Marshall5db11c22015-07-17 10:38:12 -0400680 __func__);
681 return -EIO;
682 }
683
684 /* Replace the boilerplate boot-time debug-help file. */
685 debugfs_remove(help_file_dentry);
686
687 help_file_dentry =
688 debugfs_create_file(
689 ORANGEFS_KMOD_DEBUG_HELP_FILE,
690 0444,
691 debug_dir,
692 debug_help_string,
693 &debug_help_fops);
694
695 if (!help_file_dentry) {
696 gossip_err("%s: debugfs_create_file failed for"
697 " :%s:!\n",
698 __func__,
699 ORANGEFS_KMOD_DEBUG_HELP_FILE);
700 return -EIO;
701 }
702 }
703
704 debug_mask_to_string(&client_debug_mask, 1);
705
706 debugfs_remove(client_debug_dentry);
707
Yi Liu8bb8aef2015-11-24 15:12:14 -0500708 orangefs_client_debug_init();
Mike Marshall5db11c22015-07-17 10:38:12 -0400709
710 help_string_initialized++;
711
712 return ret;
713
Yi Liu8bb8aef2015-11-24 15:12:14 -0500714 case ORANGEFS_DEV_DEBUG:
Mike Marshall5db11c22015-07-17 10:38:12 -0400715 ret = copy_from_user(&mask_info,
716 (void __user *)arg,
717 sizeof(mask_info));
718
719 if (ret != 0)
720 return -EIO;
721
722 if (mask_info.mask_type == KERNEL_MASK) {
723 if ((mask_info.mask_value == 0)
724 && (kernel_mask_set_mod_init)) {
725 /*
726 * the kernel debug mask was set when the
727 * kernel module was loaded; don't override
728 * it if the client-core was started without
Yi Liu8bb8aef2015-11-24 15:12:14 -0500729 * a value for ORANGEFS_KMODMASK.
Mike Marshall5db11c22015-07-17 10:38:12 -0400730 */
731 return 0;
732 }
733 debug_mask_to_string(&mask_info.mask_value,
734 mask_info.mask_type);
735 gossip_debug_mask = mask_info.mask_value;
Mike Marshall97f10022015-12-11 16:45:03 -0500736 pr_info("%s: kernel debug mask has been modified to "
Mike Marshall5db11c22015-07-17 10:38:12 -0400737 ":%s: :%llx:\n",
Mike Marshall97f10022015-12-11 16:45:03 -0500738 __func__,
Mike Marshall5db11c22015-07-17 10:38:12 -0400739 kernel_debug_string,
740 (unsigned long long)gossip_debug_mask);
741 } else if (mask_info.mask_type == CLIENT_MASK) {
742 debug_mask_to_string(&mask_info.mask_value,
743 mask_info.mask_type);
Mike Marshall97f10022015-12-11 16:45:03 -0500744 pr_info("%s: client debug mask has been modified to"
Mike Marshall5db11c22015-07-17 10:38:12 -0400745 ":%s: :%llx:\n",
Mike Marshall97f10022015-12-11 16:45:03 -0500746 __func__,
Mike Marshall5db11c22015-07-17 10:38:12 -0400747 client_debug_string,
748 llu(mask_info.mask_value));
749 } else {
750 gossip_lerr("Invalid mask type....\n");
751 return -EINVAL;
752 }
753
754 return ret;
755
756 default:
757 return -ENOIOCTLCMD;
758 }
759 return -ENOIOCTLCMD;
760}
761
Yi Liu8bb8aef2015-11-24 15:12:14 -0500762static long orangefs_devreq_ioctl(struct file *file,
Mike Marshall5db11c22015-07-17 10:38:12 -0400763 unsigned int command, unsigned long arg)
764{
765 long ret;
766
767 /* Check for properly constructed commands */
768 ret = check_ioctl_command(command);
769 if (ret < 0)
770 return (int)ret;
771
772 return (int)dispatch_ioctl_command(command, arg);
773}
774
775#ifdef CONFIG_COMPAT /* CONFIG_COMPAT is in .config */
776
Yi Liu8bb8aef2015-11-24 15:12:14 -0500777/* Compat structure for the ORANGEFS_DEV_MAP ioctl */
778struct ORANGEFS_dev_map_desc32 {
Mike Marshall5db11c22015-07-17 10:38:12 -0400779 compat_uptr_t ptr;
780 __s32 total_size;
781 __s32 size;
782 __s32 count;
783};
784
785static unsigned long translate_dev_map26(unsigned long args, long *error)
786{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500787 struct ORANGEFS_dev_map_desc32 __user *p32 = (void __user *)args;
Mike Marshall5db11c22015-07-17 10:38:12 -0400788 /*
789 * Depending on the architecture, allocate some space on the
790 * user-call-stack based on our expected layout.
791 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500792 struct ORANGEFS_dev_map_desc __user *p =
Mike Marshall5db11c22015-07-17 10:38:12 -0400793 compat_alloc_user_space(sizeof(*p));
Mike Marshall84d02152015-07-28 13:27:51 -0400794 compat_uptr_t addr;
Mike Marshall5db11c22015-07-17 10:38:12 -0400795
796 *error = 0;
797 /* get the ptr from the 32 bit user-space */
798 if (get_user(addr, &p32->ptr))
799 goto err;
800 /* try to put that into a 64-bit layout */
801 if (put_user(compat_ptr(addr), &p->ptr))
802 goto err;
803 /* copy the remaining fields */
804 if (copy_in_user(&p->total_size, &p32->total_size, sizeof(__s32)))
805 goto err;
806 if (copy_in_user(&p->size, &p32->size, sizeof(__s32)))
807 goto err;
808 if (copy_in_user(&p->count, &p32->count, sizeof(__s32)))
809 goto err;
810 return (unsigned long)p;
811err:
812 *error = -EFAULT;
813 return 0;
814}
815
816/*
817 * 32 bit user-space apps' ioctl handlers when kernel modules
818 * is compiled as a 64 bit one
819 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500820static long orangefs_devreq_compat_ioctl(struct file *filp, unsigned int cmd,
Mike Marshall5db11c22015-07-17 10:38:12 -0400821 unsigned long args)
822{
823 long ret;
824 unsigned long arg = args;
825
826 /* Check for properly constructed commands */
827 ret = check_ioctl_command(cmd);
828 if (ret < 0)
829 return ret;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500830 if (cmd == ORANGEFS_DEV_MAP) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400831 /*
832 * convert the arguments to what we expect internally
833 * in kernel space
834 */
835 arg = translate_dev_map26(args, &ret);
836 if (ret < 0) {
837 gossip_err("Could not translate dev map\n");
838 return ret;
839 }
840 }
841 /* no other ioctl requires translation */
842 return dispatch_ioctl_command(cmd, arg);
843}
844
Mike Marshall2c590d52015-07-24 10:37:15 -0400845#endif /* CONFIG_COMPAT is in .config */
846
Mike Marshall5db11c22015-07-17 10:38:12 -0400847/* the assigned character device major number */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500848static int orangefs_dev_major;
Mike Marshall5db11c22015-07-17 10:38:12 -0400849
850/*
Yi Liu8bb8aef2015-11-24 15:12:14 -0500851 * Initialize orangefs device specific state:
Mike Marshall5db11c22015-07-17 10:38:12 -0400852 * Must be called at module load time only
853 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500854int orangefs_dev_init(void)
Mike Marshall5db11c22015-07-17 10:38:12 -0400855{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500856 /* register orangefs-req device */
857 orangefs_dev_major = register_chrdev(0,
858 ORANGEFS_REQDEVICE_NAME,
859 &orangefs_devreq_file_operations);
860 if (orangefs_dev_major < 0) {
Mike Marshall5db11c22015-07-17 10:38:12 -0400861 gossip_debug(GOSSIP_DEV_DEBUG,
862 "Failed to register /dev/%s (error %d)\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500863 ORANGEFS_REQDEVICE_NAME, orangefs_dev_major);
Yi Liu8bb8aef2015-11-24 15:12:14 -0500864 return orangefs_dev_major;
Mike Marshall5db11c22015-07-17 10:38:12 -0400865 }
866
867 gossip_debug(GOSSIP_DEV_DEBUG,
868 "*** /dev/%s character device registered ***\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500869 ORANGEFS_REQDEVICE_NAME);
Mike Marshall5db11c22015-07-17 10:38:12 -0400870 gossip_debug(GOSSIP_DEV_DEBUG, "'mknod /dev/%s c %d 0'.\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500871 ORANGEFS_REQDEVICE_NAME, orangefs_dev_major);
Mike Marshall5db11c22015-07-17 10:38:12 -0400872 return 0;
873}
874
Yi Liu8bb8aef2015-11-24 15:12:14 -0500875void orangefs_dev_cleanup(void)
Mike Marshall5db11c22015-07-17 10:38:12 -0400876{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500877 unregister_chrdev(orangefs_dev_major, ORANGEFS_REQDEVICE_NAME);
Mike Marshall5db11c22015-07-17 10:38:12 -0400878 gossip_debug(GOSSIP_DEV_DEBUG,
879 "*** /dev/%s character device unregistered ***\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500880 ORANGEFS_REQDEVICE_NAME);
Mike Marshall5db11c22015-07-17 10:38:12 -0400881}
882
Yi Liu8bb8aef2015-11-24 15:12:14 -0500883static unsigned int orangefs_devreq_poll(struct file *file,
Mike Marshall5db11c22015-07-17 10:38:12 -0400884 struct poll_table_struct *poll_table)
885{
886 int poll_revent_mask = 0;
887
Al Viro83595db2016-01-19 12:03:05 -0500888 poll_wait(file, &orangefs_request_list_waitq, poll_table);
Mike Marshall5db11c22015-07-17 10:38:12 -0400889
Al Viro83595db2016-01-19 12:03:05 -0500890 if (!list_empty(&orangefs_request_list))
891 poll_revent_mask |= POLL_IN;
Mike Marshall5db11c22015-07-17 10:38:12 -0400892 return poll_revent_mask;
893}
894
Yi Liu8bb8aef2015-11-24 15:12:14 -0500895const struct file_operations orangefs_devreq_file_operations = {
Mike Marshall5db11c22015-07-17 10:38:12 -0400896 .owner = THIS_MODULE,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500897 .read = orangefs_devreq_read,
898 .write_iter = orangefs_devreq_write_iter,
899 .open = orangefs_devreq_open,
900 .release = orangefs_devreq_release,
901 .unlocked_ioctl = orangefs_devreq_ioctl,
Mike Marshall5db11c22015-07-17 10:38:12 -0400902
903#ifdef CONFIG_COMPAT /* CONFIG_COMPAT is in .config */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500904 .compat_ioctl = orangefs_devreq_compat_ioctl,
Mike Marshall5db11c22015-07-17 10:38:12 -0400905#endif
Yi Liu8bb8aef2015-11-24 15:12:14 -0500906 .poll = orangefs_devreq_poll
Mike Marshall5db11c22015-07-17 10:38:12 -0400907};