diff options
Diffstat (limited to 'fs/fifo.c')
-rw-r--r-- | fs/fifo.c | 49 |
1 files changed, 26 insertions, 23 deletions
@@ -33,14 +33,17 @@ static void wake_up_partner(struct inode* inode) | |||
33 | 33 | ||
34 | static int fifo_open(struct inode *inode, struct file *filp) | 34 | static int fifo_open(struct inode *inode, struct file *filp) |
35 | { | 35 | { |
36 | struct pipe_inode_info *pipe; | ||
36 | int ret; | 37 | int ret; |
37 | 38 | ||
38 | mutex_lock(&inode->i_mutex); | 39 | mutex_lock(&inode->i_mutex); |
39 | if (!inode->i_pipe) { | 40 | pipe = inode->i_pipe; |
41 | if (!pipe) { | ||
40 | ret = -ENOMEM; | 42 | ret = -ENOMEM; |
41 | inode->i_pipe = alloc_pipe_info(inode); | 43 | pipe = alloc_pipe_info(inode); |
42 | if (!inode->i_pipe) | 44 | if (!pipe) |
43 | goto err_nocleanup; | 45 | goto err_nocleanup; |
46 | inode->i_pipe = pipe; | ||
44 | } | 47 | } |
45 | filp->f_version = 0; | 48 | filp->f_version = 0; |
46 | 49 | ||
@@ -55,18 +58,18 @@ static int fifo_open(struct inode *inode, struct file *filp) | |||
55 | * opened, even when there is no process writing the FIFO. | 58 | * opened, even when there is no process writing the FIFO. |
56 | */ | 59 | */ |
57 | filp->f_op = &read_fifo_fops; | 60 | filp->f_op = &read_fifo_fops; |
58 | inode->i_pipe->r_counter++; | 61 | pipe->r_counter++; |
59 | if (inode->i_pipe->readers++ == 0) | 62 | if (pipe->readers++ == 0) |
60 | wake_up_partner(inode); | 63 | wake_up_partner(inode); |
61 | 64 | ||
62 | if (!inode->i_pipe->writers) { | 65 | if (!pipe->writers) { |
63 | if ((filp->f_flags & O_NONBLOCK)) { | 66 | if ((filp->f_flags & O_NONBLOCK)) { |
64 | /* suppress POLLHUP until we have | 67 | /* suppress POLLHUP until we have |
65 | * seen a writer */ | 68 | * seen a writer */ |
66 | filp->f_version = inode->i_pipe->w_counter; | 69 | filp->f_version = pipe->w_counter; |
67 | } else | 70 | } else |
68 | { | 71 | { |
69 | wait_for_partner(inode, &inode->i_pipe->w_counter); | 72 | wait_for_partner(inode, &pipe->w_counter); |
70 | if(signal_pending(current)) | 73 | if(signal_pending(current)) |
71 | goto err_rd; | 74 | goto err_rd; |
72 | } | 75 | } |
@@ -80,16 +83,16 @@ static int fifo_open(struct inode *inode, struct file *filp) | |||
80 | * errno=ENXIO when there is no process reading the FIFO. | 83 | * errno=ENXIO when there is no process reading the FIFO. |
81 | */ | 84 | */ |
82 | ret = -ENXIO; | 85 | ret = -ENXIO; |
83 | if ((filp->f_flags & O_NONBLOCK) && !inode->i_pipe->readers) | 86 | if ((filp->f_flags & O_NONBLOCK) && !pipe->readers) |
84 | goto err; | 87 | goto err; |
85 | 88 | ||
86 | filp->f_op = &write_fifo_fops; | 89 | filp->f_op = &write_fifo_fops; |
87 | inode->i_pipe->w_counter++; | 90 | pipe->w_counter++; |
88 | if (!inode->i_pipe->writers++) | 91 | if (!pipe->writers++) |
89 | wake_up_partner(inode); | 92 | wake_up_partner(inode); |
90 | 93 | ||
91 | if (!inode->i_pipe->readers) { | 94 | if (!pipe->readers) { |
92 | wait_for_partner(inode, &inode->i_pipe->r_counter); | 95 | wait_for_partner(inode, &pipe->r_counter); |
93 | if (signal_pending(current)) | 96 | if (signal_pending(current)) |
94 | goto err_wr; | 97 | goto err_wr; |
95 | } | 98 | } |
@@ -104,11 +107,11 @@ static int fifo_open(struct inode *inode, struct file *filp) | |||
104 | */ | 107 | */ |
105 | filp->f_op = &rdwr_fifo_fops; | 108 | filp->f_op = &rdwr_fifo_fops; |
106 | 109 | ||
107 | inode->i_pipe->readers++; | 110 | pipe->readers++; |
108 | inode->i_pipe->writers++; | 111 | pipe->writers++; |
109 | inode->i_pipe->r_counter++; | 112 | pipe->r_counter++; |
110 | inode->i_pipe->w_counter++; | 113 | pipe->w_counter++; |
111 | if (inode->i_pipe->readers == 1 || inode->i_pipe->writers == 1) | 114 | if (pipe->readers == 1 || pipe->writers == 1) |
112 | wake_up_partner(inode); | 115 | wake_up_partner(inode); |
113 | break; | 116 | break; |
114 | 117 | ||
@@ -122,19 +125,19 @@ static int fifo_open(struct inode *inode, struct file *filp) | |||
122 | return 0; | 125 | return 0; |
123 | 126 | ||
124 | err_rd: | 127 | err_rd: |
125 | if (!--inode->i_pipe->readers) | 128 | if (!--pipe->readers) |
126 | wake_up_interruptible(&inode->i_pipe->wait); | 129 | wake_up_interruptible(&pipe->wait); |
127 | ret = -ERESTARTSYS; | 130 | ret = -ERESTARTSYS; |
128 | goto err; | 131 | goto err; |
129 | 132 | ||
130 | err_wr: | 133 | err_wr: |
131 | if (!--inode->i_pipe->writers) | 134 | if (!--pipe->writers) |
132 | wake_up_interruptible(&inode->i_pipe->wait); | 135 | wake_up_interruptible(&pipe->wait); |
133 | ret = -ERESTARTSYS; | 136 | ret = -ERESTARTSYS; |
134 | goto err; | 137 | goto err; |
135 | 138 | ||
136 | err: | 139 | err: |
137 | if (!inode->i_pipe->readers && !inode->i_pipe->writers) | 140 | if (!pipe->readers && !pipe->writers) |
138 | free_pipe_info(inode); | 141 | free_pipe_info(inode); |
139 | 142 | ||
140 | err_nocleanup: | 143 | err_nocleanup: |