Commit 33e14b4dfdc477344efbcd9b4218f2b350f0f893

Authored by Miklos Szeredi
1 parent 7a3b2c7547

fuse: req state use flags

Use flags for representing the state in fuse_req.  This is needed since
req->list will be protected by different locks in different states, hence
we'll want the state itself to be split into distinct bits, each protected
with the relevant lock in that state.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>

Showing 3 changed files with 21 additions and 21 deletions Side-by-side Diff

... ... @@ -48,6 +48,7 @@
48 48 req->pages = pages;
49 49 req->page_descs = page_descs;
50 50 req->max_pages = npages;
  51 + __set_bit(FR_PENDING, &req->flags);
51 52 }
52 53  
53 54 static struct fuse_req *__fuse_request_alloc(unsigned npages, gfp_t flags)
54 55  
... ... @@ -380,8 +381,10 @@
380 381 req->end = NULL;
381 382 list_del_init(&req->list);
382 383 list_del_init(&req->intr_entry);
  384 + WARN_ON(test_bit(FR_PENDING, &req->flags));
  385 + WARN_ON(test_bit(FR_SENT, &req->flags));
383 386 smp_wmb();
384   - req->state = FUSE_REQ_FINISHED;
  387 + set_bit(FR_FINISHED, &req->flags);
385 388 if (test_bit(FR_BACKGROUND, &req->flags)) {
386 389 clear_bit(FR_BACKGROUND, &req->flags);
387 390 if (fc->num_background == fc->max_background)
388 391  
... ... @@ -421,13 +424,13 @@
421 424 if (!fc->no_interrupt) {
422 425 /* Any signal may interrupt this */
423 426 err = wait_event_interruptible(req->waitq,
424   - req->state == FUSE_REQ_FINISHED);
  427 + test_bit(FR_FINISHED, &req->flags));
425 428 if (!err)
426 429 return;
427 430  
428 431 spin_lock(&fc->lock);
429 432 set_bit(FR_INTERRUPTED, &req->flags);
430   - if (req->state == FUSE_REQ_SENT)
  433 + if (test_bit(FR_SENT, &req->flags))
431 434 queue_interrupt(fc, req);
432 435 spin_unlock(&fc->lock);
433 436 }
... ... @@ -438,7 +441,7 @@
438 441 /* Only fatal signals may interrupt this */
439 442 block_sigs(&oldset);
440 443 err = wait_event_interruptible(req->waitq,
441   - req->state == FUSE_REQ_FINISHED);
  444 + test_bit(FR_FINISHED, &req->flags));
442 445 restore_sigs(&oldset);
443 446  
444 447 if (!err)
... ... @@ -446,7 +449,7 @@
446 449  
447 450 spin_lock(&fc->lock);
448 451 /* Request is not yet in userspace, bail out */
449   - if (req->state == FUSE_REQ_PENDING) {
  452 + if (test_bit(FR_PENDING, &req->flags)) {
450 453 list_del(&req->list);
451 454 spin_unlock(&fc->lock);
452 455 __fuse_put_request(req);
... ... @@ -460,7 +463,7 @@
460 463 * Either request is already in userspace, or it was forced.
461 464 * Wait it out.
462 465 */
463   - wait_event(req->waitq, req->state == FUSE_REQ_FINISHED);
  466 + wait_event(req->waitq, test_bit(FR_FINISHED, &req->flags));
464 467 }
465 468  
466 469 static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
... ... @@ -1273,7 +1276,7 @@
1273 1276 }
1274 1277  
1275 1278 req = list_entry(fc->pending.next, struct fuse_req, list);
1276   - req->state = FUSE_REQ_IO;
  1279 + clear_bit(FR_PENDING, &req->flags);
1277 1280 list_move(&req->list, &fc->io);
1278 1281  
1279 1282 in = &req->in;
... ... @@ -1308,7 +1311,7 @@
1308 1311 if (!test_bit(FR_ISREPLY, &req->flags)) {
1309 1312 request_end(fc, req);
1310 1313 } else {
1311   - req->state = FUSE_REQ_SENT;
  1314 + set_bit(FR_SENT, &req->flags);
1312 1315 list_move_tail(&req->list, &fc->processing);
1313 1316 if (test_bit(FR_INTERRUPTED, &req->flags))
1314 1317 queue_interrupt(fc, req);
... ... @@ -1904,7 +1907,7 @@
1904 1907 return nbytes;
1905 1908 }
1906 1909  
1907   - req->state = FUSE_REQ_IO;
  1910 + clear_bit(FR_SENT, &req->flags);
1908 1911 list_move(&req->list, &fc->io);
1909 1912 req->out.h = oh;
1910 1913 set_bit(FR_LOCKED, &req->flags);
... ... @@ -2059,6 +2062,8 @@
2059 2062 struct fuse_req *req;
2060 2063 req = list_entry(head->next, struct fuse_req, list);
2061 2064 req->out.h.error = -ECONNABORTED;
  2065 + clear_bit(FR_PENDING, &req->flags);
  2066 + clear_bit(FR_SENT, &req->flags);
2062 2067 request_end(fc, req);
2063 2068 spin_lock(&fc->lock);
2064 2069 }
... ... @@ -1743,7 +1743,7 @@
1743 1743 }
1744 1744 }
1745 1745  
1746   - if (old_req->num_pages == 1 && old_req->state == FUSE_REQ_PENDING) {
  1746 + if (old_req->num_pages == 1 && test_bit(FR_PENDING, &old_req->flags)) {
1747 1747 struct backing_dev_info *bdi = inode_to_bdi(page->mapping->host);
1748 1748  
1749 1749 copy_highpage(old_req->pages[0], page);
... ... @@ -241,14 +241,6 @@
241 241  
242 242 #define FUSE_ARGS(args) struct fuse_args args = {}
243 243  
244   -/** The request state */
245   -enum fuse_req_state {
246   - FUSE_REQ_PENDING = 0,
247   - FUSE_REQ_IO,
248   - FUSE_REQ_SENT,
249   - FUSE_REQ_FINISHED
250   -};
251   -
252 244 /** The request IO state (for asynchronous processing) */
253 245 struct fuse_io_priv {
254 246 int async;
... ... @@ -274,6 +266,9 @@
274 266 * FR_ABORTED: the request was aborted
275 267 * FR_INTERRUPTED: the request has been interrupted
276 268 * FR_LOCKED: data is being copied to/from the request
  269 + * FR_PENDING: request is not yet in userspace
  270 + * FR_SENT: request is in userspace, waiting for an answer
  271 + * FR_FINISHED: request is finished
277 272 */
278 273 enum fuse_req_flag {
279 274 FR_ISREPLY,
... ... @@ -283,6 +278,9 @@
283 278 FR_ABORTED,
284 279 FR_INTERRUPTED,
285 280 FR_LOCKED,
  281 + FR_PENDING,
  282 + FR_SENT,
  283 + FR_FINISHED,
286 284 };
287 285  
288 286 /**
... ... @@ -308,9 +306,6 @@
308 306  
309 307 /* Request flags, updated with test/set/clear_bit() */
310 308 unsigned long flags;
311   -
312   - /** State of the request */
313   - enum fuse_req_state state;
314 309  
315 310 /** The request input */
316 311 struct fuse_in in;