Commit 9aeedfc4712ed58d9f7ae41596185c72b8dc97e8

Authored by Ingo Molnar
Committed by Jens Axboe
1 parent 7480a90435

[PATCH] get rid of the PIPE_*() macros

get rid of the PIPE_*() macros. Scripted transformation.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Jens Axboe <axboe@suse.de>

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

... ... @@ -28,14 +28,14 @@
28 28  
29 29 static void wake_up_partner(struct inode* inode)
30 30 {
31   - wake_up_interruptible(PIPE_WAIT(*inode));
  31 + wake_up_interruptible(&inode->i_pipe->wait);
32 32 }
33 33  
34 34 static int fifo_open(struct inode *inode, struct file *filp)
35 35 {
36 36 int ret;
37 37  
38   - mutex_lock(PIPE_MUTEX(*inode));
  38 + mutex_lock(&inode->i_mutex);
39 39 if (!inode->i_pipe) {
40 40 ret = -ENOMEM;
41 41 inode->i_pipe = alloc_pipe_info(inode);
42 42  
43 43  
44 44  
... ... @@ -55,18 +55,18 @@
55 55 * opened, even when there is no process writing the FIFO.
56 56 */
57 57 filp->f_op = &read_fifo_fops;
58   - PIPE_RCOUNTER(*inode)++;
59   - if (PIPE_READERS(*inode)++ == 0)
  58 + inode->i_pipe->r_counter++;
  59 + if (inode->i_pipe->readers++ == 0)
60 60 wake_up_partner(inode);
61 61  
62   - if (!PIPE_WRITERS(*inode)) {
  62 + if (!inode->i_pipe->writers) {
63 63 if ((filp->f_flags & O_NONBLOCK)) {
64 64 /* suppress POLLHUP until we have
65 65 * seen a writer */
66   - filp->f_version = PIPE_WCOUNTER(*inode);
  66 + filp->f_version = inode->i_pipe->w_counter;
67 67 } else
68 68 {
69   - wait_for_partner(inode, &PIPE_WCOUNTER(*inode));
  69 + wait_for_partner(inode, &inode->i_pipe->w_counter);
70 70 if(signal_pending(current))
71 71 goto err_rd;
72 72 }
73 73  
74 74  
... ... @@ -80,16 +80,16 @@
80 80 * errno=ENXIO when there is no process reading the FIFO.
81 81 */
82 82 ret = -ENXIO;
83   - if ((filp->f_flags & O_NONBLOCK) && !PIPE_READERS(*inode))
  83 + if ((filp->f_flags & O_NONBLOCK) && !inode->i_pipe->readers)
84 84 goto err;
85 85  
86 86 filp->f_op = &write_fifo_fops;
87   - PIPE_WCOUNTER(*inode)++;
88   - if (!PIPE_WRITERS(*inode)++)
  87 + inode->i_pipe->w_counter++;
  88 + if (!inode->i_pipe->writers++)
89 89 wake_up_partner(inode);
90 90  
91   - if (!PIPE_READERS(*inode)) {
92   - wait_for_partner(inode, &PIPE_RCOUNTER(*inode));
  91 + if (!inode->i_pipe->readers) {
  92 + wait_for_partner(inode, &inode->i_pipe->r_counter);
93 93 if (signal_pending(current))
94 94 goto err_wr;
95 95 }
... ... @@ -104,11 +104,11 @@
104 104 */
105 105 filp->f_op = &rdwr_fifo_fops;
106 106  
107   - PIPE_READERS(*inode)++;
108   - PIPE_WRITERS(*inode)++;
109   - PIPE_RCOUNTER(*inode)++;
110   - PIPE_WCOUNTER(*inode)++;
111   - if (PIPE_READERS(*inode) == 1 || PIPE_WRITERS(*inode) == 1)
  107 + inode->i_pipe->readers++;
  108 + inode->i_pipe->writers++;
  109 + inode->i_pipe->r_counter++;
  110 + inode->i_pipe->w_counter++;
  111 + if (inode->i_pipe->readers == 1 || inode->i_pipe->writers == 1)
112 112 wake_up_partner(inode);
113 113 break;
114 114  
115 115  
116 116  
117 117  
118 118  
... ... @@ -118,27 +118,27 @@
118 118 }
119 119  
120 120 /* Ok! */
121   - mutex_unlock(PIPE_MUTEX(*inode));
  121 + mutex_unlock(&inode->i_mutex);
122 122 return 0;
123 123  
124 124 err_rd:
125   - if (!--PIPE_READERS(*inode))
126   - wake_up_interruptible(PIPE_WAIT(*inode));
  125 + if (!--inode->i_pipe->readers)
  126 + wake_up_interruptible(&inode->i_pipe->wait);
127 127 ret = -ERESTARTSYS;
128 128 goto err;
129 129  
130 130 err_wr:
131   - if (!--PIPE_WRITERS(*inode))
132   - wake_up_interruptible(PIPE_WAIT(*inode));
  131 + if (!--inode->i_pipe->writers)
  132 + wake_up_interruptible(&inode->i_pipe->wait);
133 133 ret = -ERESTARTSYS;
134 134 goto err;
135 135  
136 136 err:
137   - if (!PIPE_READERS(*inode) && !PIPE_WRITERS(*inode))
  137 + if (!inode->i_pipe->readers && !inode->i_pipe->writers)
138 138 free_pipe_info(inode);
139 139  
140 140 err_nocleanup:
141   - mutex_unlock(PIPE_MUTEX(*inode));
  141 + mutex_unlock(&inode->i_mutex);
142 142 return ret;
143 143 }
144 144  
... ... @@ -158,7 +158,7 @@
158 158  
159 159 do_wakeup = 0;
160 160 ret = 0;
161   - mutex_lock(PIPE_MUTEX(*inode));
  161 + mutex_lock(&inode->i_mutex);
162 162 info = inode->i_pipe;
163 163 for (;;) {
164 164 int bufs = info->nrbufs;
165 165  
... ... @@ -202,9 +202,9 @@
202 202 }
203 203 if (bufs) /* More to do? */
204 204 continue;
205   - if (!PIPE_WRITERS(*inode))
  205 + if (!inode->i_pipe->writers)
206 206 break;
207   - if (!PIPE_WAITING_WRITERS(*inode)) {
  207 + if (!inode->i_pipe->waiting_writers) {
208 208 /* syscall merging: Usually we must not sleep
209 209 * if O_NONBLOCK is set, or if we got some data.
210 210 * But if a writer sleeps in kernel space, then
211 211  
212 212  
... ... @@ -222,16 +222,16 @@
222 222 break;
223 223 }
224 224 if (do_wakeup) {
225   - wake_up_interruptible_sync(PIPE_WAIT(*inode));
226   - kill_fasync(PIPE_FASYNC_WRITERS(*inode), SIGIO, POLL_OUT);
  225 + wake_up_interruptible_sync(&inode->i_pipe->wait);
  226 + kill_fasync(&inode->i_pipe->fasync_writers, SIGIO, POLL_OUT);
227 227 }
228 228 pipe_wait(inode->i_pipe);
229 229 }
230   - mutex_unlock(PIPE_MUTEX(*inode));
  230 + mutex_unlock(&inode->i_mutex);
231 231 /* Signal writers asynchronously that there is more room. */
232 232 if (do_wakeup) {
233   - wake_up_interruptible(PIPE_WAIT(*inode));
234   - kill_fasync(PIPE_FASYNC_WRITERS(*inode), SIGIO, POLL_OUT);
  233 + wake_up_interruptible(&inode->i_pipe->wait);
  234 + kill_fasync(&inode->i_pipe->fasync_writers, SIGIO, POLL_OUT);
235 235 }
236 236 if (ret > 0)
237 237 file_accessed(filp);
238 238  
... ... @@ -264,10 +264,10 @@
264 264  
265 265 do_wakeup = 0;
266 266 ret = 0;
267   - mutex_lock(PIPE_MUTEX(*inode));
  267 + mutex_lock(&inode->i_mutex);
268 268 info = inode->i_pipe;
269 269  
270   - if (!PIPE_READERS(*inode)) {
  270 + if (!inode->i_pipe->readers) {
271 271 send_sig(SIGPIPE, current, 0);
272 272 ret = -EPIPE;
273 273 goto out;
... ... @@ -306,7 +306,7 @@
306 306  
307 307 for (;;) {
308 308 int bufs;
309   - if (!PIPE_READERS(*inode)) {
  309 + if (!inode->i_pipe->readers) {
310 310 send_sig(SIGPIPE, current, 0);
311 311 if (!ret) ret = -EPIPE;
312 312 break;
313 313  
314 314  
315 315  
316 316  
... ... @@ -367,19 +367,19 @@
367 367 break;
368 368 }
369 369 if (do_wakeup) {
370   - wake_up_interruptible_sync(PIPE_WAIT(*inode));
371   - kill_fasync(PIPE_FASYNC_READERS(*inode), SIGIO, POLL_IN);
  370 + wake_up_interruptible_sync(&inode->i_pipe->wait);
  371 + kill_fasync(&inode->i_pipe->fasync_readers, SIGIO, POLL_IN);
372 372 do_wakeup = 0;
373 373 }
374   - PIPE_WAITING_WRITERS(*inode)++;
  374 + inode->i_pipe->waiting_writers++;
375 375 pipe_wait(inode->i_pipe);
376   - PIPE_WAITING_WRITERS(*inode)--;
  376 + inode->i_pipe->waiting_writers--;
377 377 }
378 378 out:
379   - mutex_unlock(PIPE_MUTEX(*inode));
  379 + mutex_unlock(&inode->i_mutex);
380 380 if (do_wakeup) {
381   - wake_up_interruptible(PIPE_WAIT(*inode));
382   - kill_fasync(PIPE_FASYNC_READERS(*inode), SIGIO, POLL_IN);
  381 + wake_up_interruptible(&inode->i_pipe->wait);
  382 + kill_fasync(&inode->i_pipe->fasync_readers, SIGIO, POLL_IN);
383 383 }
384 384 if (ret > 0)
385 385 file_update_time(filp);
... ... @@ -416,7 +416,7 @@
416 416  
417 417 switch (cmd) {
418 418 case FIONREAD:
419   - mutex_lock(PIPE_MUTEX(*inode));
  419 + mutex_lock(&inode->i_mutex);
420 420 info = inode->i_pipe;
421 421 count = 0;
422 422 buf = info->curbuf;
... ... @@ -425,7 +425,7 @@
425 425 count += info->bufs[buf].len;
426 426 buf = (buf+1) & (PIPE_BUFFERS-1);
427 427 }
428   - mutex_unlock(PIPE_MUTEX(*inode));
  428 + mutex_unlock(&inode->i_mutex);
429 429 return put_user(count, (int __user *)arg);
430 430 default:
431 431 return -EINVAL;
432 432  
... ... @@ -441,14 +441,14 @@
441 441 struct pipe_inode_info *info = inode->i_pipe;
442 442 int nrbufs;
443 443  
444   - poll_wait(filp, PIPE_WAIT(*inode), wait);
  444 + poll_wait(filp, &inode->i_pipe->wait, wait);
445 445  
446 446 /* Reading only -- no need for acquiring the semaphore. */
447 447 nrbufs = info->nrbufs;
448 448 mask = 0;
449 449 if (filp->f_mode & FMODE_READ) {
450 450 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
451   - if (!PIPE_WRITERS(*inode) && filp->f_version != PIPE_WCOUNTER(*inode))
  451 + if (!inode->i_pipe->writers && filp->f_version != inode->i_pipe->w_counter)
452 452 mask |= POLLHUP;
453 453 }
454 454  
... ... @@ -458,7 +458,7 @@
458 458 * Most Unices do not set POLLERR for FIFOs but on Linux they
459 459 * behave exactly like pipes for poll().
460 460 */
461   - if (!PIPE_READERS(*inode))
  461 + if (!inode->i_pipe->readers)
462 462 mask |= POLLERR;
463 463 }
464 464  
465 465  
466 466  
... ... @@ -468,17 +468,17 @@
468 468 static int
469 469 pipe_release(struct inode *inode, int decr, int decw)
470 470 {
471   - mutex_lock(PIPE_MUTEX(*inode));
472   - PIPE_READERS(*inode) -= decr;
473   - PIPE_WRITERS(*inode) -= decw;
474   - if (!PIPE_READERS(*inode) && !PIPE_WRITERS(*inode)) {
  471 + mutex_lock(&inode->i_mutex);
  472 + inode->i_pipe->readers -= decr;
  473 + inode->i_pipe->writers -= decw;
  474 + if (!inode->i_pipe->readers && !inode->i_pipe->writers) {
475 475 free_pipe_info(inode);
476 476 } else {
477   - wake_up_interruptible(PIPE_WAIT(*inode));
478   - kill_fasync(PIPE_FASYNC_READERS(*inode), SIGIO, POLL_IN);
479   - kill_fasync(PIPE_FASYNC_WRITERS(*inode), SIGIO, POLL_OUT);
  477 + wake_up_interruptible(&inode->i_pipe->wait);
  478 + kill_fasync(&inode->i_pipe->fasync_readers, SIGIO, POLL_IN);
  479 + kill_fasync(&inode->i_pipe->fasync_writers, SIGIO, POLL_OUT);
480 480 }
481   - mutex_unlock(PIPE_MUTEX(*inode));
  481 + mutex_unlock(&inode->i_mutex);
482 482  
483 483 return 0;
484 484 }
... ... @@ -489,9 +489,9 @@
489 489 struct inode *inode = filp->f_dentry->d_inode;
490 490 int retval;
491 491  
492   - mutex_lock(PIPE_MUTEX(*inode));
493   - retval = fasync_helper(fd, filp, on, PIPE_FASYNC_READERS(*inode));
494   - mutex_unlock(PIPE_MUTEX(*inode));
  492 + mutex_lock(&inode->i_mutex);
  493 + retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_readers);
  494 + mutex_unlock(&inode->i_mutex);
495 495  
496 496 if (retval < 0)
497 497 return retval;
... ... @@ -506,9 +506,9 @@
506 506 struct inode *inode = filp->f_dentry->d_inode;
507 507 int retval;
508 508  
509   - mutex_lock(PIPE_MUTEX(*inode));
510   - retval = fasync_helper(fd, filp, on, PIPE_FASYNC_WRITERS(*inode));
511   - mutex_unlock(PIPE_MUTEX(*inode));
  509 + mutex_lock(&inode->i_mutex);
  510 + retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_writers);
  511 + mutex_unlock(&inode->i_mutex);
512 512  
513 513 if (retval < 0)
514 514 return retval;
515 515  
516 516  
517 517  
... ... @@ -523,14 +523,14 @@
523 523 struct inode *inode = filp->f_dentry->d_inode;
524 524 int retval;
525 525  
526   - mutex_lock(PIPE_MUTEX(*inode));
  526 + mutex_lock(&inode->i_mutex);
527 527  
528   - retval = fasync_helper(fd, filp, on, PIPE_FASYNC_READERS(*inode));
  528 + retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_readers);
529 529  
530 530 if (retval >= 0)
531   - retval = fasync_helper(fd, filp, on, PIPE_FASYNC_WRITERS(*inode));
  531 + retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_writers);
532 532  
533   - mutex_unlock(PIPE_MUTEX(*inode));
  533 + mutex_unlock(&inode->i_mutex);
534 534  
535 535 if (retval < 0)
536 536 return retval;
... ... @@ -569,9 +569,9 @@
569 569 {
570 570 /* We could have perhaps used atomic_t, but this and friends
571 571 below are the only places. So it doesn't seem worthwhile. */
572   - mutex_lock(PIPE_MUTEX(*inode));
573   - PIPE_READERS(*inode)++;
574   - mutex_unlock(PIPE_MUTEX(*inode));
  572 + mutex_lock(&inode->i_mutex);
  573 + inode->i_pipe->readers++;
  574 + mutex_unlock(&inode->i_mutex);
575 575  
576 576 return 0;
577 577 }
... ... @@ -579,9 +579,9 @@
579 579 static int
580 580 pipe_write_open(struct inode *inode, struct file *filp)
581 581 {
582   - mutex_lock(PIPE_MUTEX(*inode));
583   - PIPE_WRITERS(*inode)++;
584   - mutex_unlock(PIPE_MUTEX(*inode));
  582 + mutex_lock(&inode->i_mutex);
  583 + inode->i_pipe->writers++;
  584 + mutex_unlock(&inode->i_mutex);
585 585  
586 586 return 0;
587 587 }
588 588  
589 589  
... ... @@ -589,12 +589,12 @@
589 589 static int
590 590 pipe_rdwr_open(struct inode *inode, struct file *filp)
591 591 {
592   - mutex_lock(PIPE_MUTEX(*inode));
  592 + mutex_lock(&inode->i_mutex);
593 593 if (filp->f_mode & FMODE_READ)
594   - PIPE_READERS(*inode)++;
  594 + inode->i_pipe->readers++;
595 595 if (filp->f_mode & FMODE_WRITE)
596   - PIPE_WRITERS(*inode)++;
597   - mutex_unlock(PIPE_MUTEX(*inode));
  596 + inode->i_pipe->writers++;
  597 + mutex_unlock(&inode->i_mutex);
598 598  
599 599 return 0;
600 600 }
... ... @@ -731,7 +731,7 @@
731 731 if (!inode->i_pipe)
732 732 goto fail_iput;
733 733  
734   - PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 1;
  734 + inode->i_pipe->readers = inode->i_pipe->writers = 1;
735 735 inode->i_fop = &rdwr_pipe_fops;
736 736  
737 737 /*
include/linux/pipe_fs_i.h
... ... @@ -43,16 +43,6 @@
43 43 memory allocation, whereas PIPE_BUF makes atomicity guarantees. */
44 44 #define PIPE_SIZE PAGE_SIZE
45 45  
46   -#define PIPE_MUTEX(inode) (&(inode).i_mutex)
47   -#define PIPE_WAIT(inode) (&(inode).i_pipe->wait)
48   -#define PIPE_READERS(inode) ((inode).i_pipe->readers)
49   -#define PIPE_WRITERS(inode) ((inode).i_pipe->writers)
50   -#define PIPE_WAITING_WRITERS(inode) ((inode).i_pipe->waiting_writers)
51   -#define PIPE_RCOUNTER(inode) ((inode).i_pipe->r_counter)
52   -#define PIPE_WCOUNTER(inode) ((inode).i_pipe->w_counter)
53   -#define PIPE_FASYNC_READERS(inode) (&((inode).i_pipe->fasync_readers))
54   -#define PIPE_FASYNC_WRITERS(inode) (&((inode).i_pipe->fasync_writers))
55   -
56 46 /* Drop the inode semaphore and wait for a pipe event, atomically */
57 47 void pipe_wait(struct pipe_inode_info *pipe);
58 48