Commit 53c9c5c0e32c69f9df1822e47671c13e3402c82f
1 parent
a9885444f7
[PATCH] prepare vfs_readdir() callers to returning filldir result
It's not the final state, but it allows moving ->readdir() instances to passing filldir return value to caller of vfs_readdir(). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 6 changed files with 33 additions and 41 deletions Side-by-side Diff
arch/alpha/kernel/osf_sys.c
... | ... | @@ -165,14 +165,11 @@ |
165 | 165 | buf.error = 0; |
166 | 166 | |
167 | 167 | error = vfs_readdir(file, osf_filldir, &buf); |
168 | - if (error < 0) | |
169 | - goto out_putf; | |
170 | - | |
171 | - error = buf.error; | |
168 | + if (error >= 0) | |
169 | + error = buf.error; | |
172 | 170 | if (count != buf.count) |
173 | 171 | error = count - buf.count; |
174 | 172 | |
175 | - out_putf: | |
176 | 173 | fput(file); |
177 | 174 | out: |
178 | 175 | return error; |
arch/parisc/hpux/fs.c
... | ... | @@ -127,9 +127,8 @@ |
127 | 127 | buf.error = 0; |
128 | 128 | |
129 | 129 | error = vfs_readdir(file, filldir, &buf); |
130 | - if (error < 0) | |
131 | - goto out_putf; | |
132 | - error = buf.error; | |
130 | + if (error >= 0) | |
131 | + error = buf.error; | |
133 | 132 | lastdirent = buf.previous; |
134 | 133 | if (lastdirent) { |
135 | 134 | if (put_user(file->f_pos, &lastdirent->d_off)) |
fs/compat.c
... | ... | @@ -869,7 +869,7 @@ |
869 | 869 | buf.dirent = dirent; |
870 | 870 | |
871 | 871 | error = vfs_readdir(file, compat_fillonedir, &buf); |
872 | - if (error >= 0) | |
872 | + if (buf.result) | |
873 | 873 | error = buf.result; |
874 | 874 | |
875 | 875 | fput(file); |
... | ... | @@ -956,9 +956,8 @@ |
956 | 956 | buf.error = 0; |
957 | 957 | |
958 | 958 | error = vfs_readdir(file, compat_filldir, &buf); |
959 | - if (error < 0) | |
960 | - goto out_putf; | |
961 | - error = buf.error; | |
959 | + if (error >= 0) | |
960 | + error = buf.error; | |
962 | 961 | lastdirent = buf.previous; |
963 | 962 | if (lastdirent) { |
964 | 963 | if (put_user(file->f_pos, &lastdirent->d_off)) |
... | ... | @@ -966,8 +965,6 @@ |
966 | 965 | else |
967 | 966 | error = count - buf.count; |
968 | 967 | } |
969 | - | |
970 | -out_putf: | |
971 | 968 | fput(file); |
972 | 969 | out: |
973 | 970 | return error; |
974 | 971 | |
975 | 972 | |
976 | 973 | |
... | ... | @@ -1047,19 +1044,16 @@ |
1047 | 1044 | buf.error = 0; |
1048 | 1045 | |
1049 | 1046 | error = vfs_readdir(file, compat_filldir64, &buf); |
1050 | - if (error < 0) | |
1051 | - goto out_putf; | |
1052 | - error = buf.error; | |
1047 | + if (error >= 0) | |
1048 | + error = buf.error; | |
1053 | 1049 | lastdirent = buf.previous; |
1054 | 1050 | if (lastdirent) { |
1055 | 1051 | typeof(lastdirent->d_off) d_off = file->f_pos; |
1056 | - error = -EFAULT; | |
1057 | 1052 | if (__put_user_unaligned(d_off, &lastdirent->d_off)) |
1058 | - goto out_putf; | |
1059 | - error = count - buf.count; | |
1053 | + error = -EFAULT; | |
1054 | + else | |
1055 | + error = count - buf.count; | |
1060 | 1056 | } |
1061 | - | |
1062 | -out_putf: | |
1063 | 1057 | fput(file); |
1064 | 1058 | out: |
1065 | 1059 | return error; |
fs/exportfs/expfs.c
... | ... | @@ -280,13 +280,14 @@ |
280 | 280 | int old_seq = buffer.sequence; |
281 | 281 | |
282 | 282 | error = vfs_readdir(file, filldir_one, &buffer); |
283 | + if (buffer.found) { | |
284 | + error = 0; | |
285 | + break; | |
286 | + } | |
283 | 287 | |
284 | 288 | if (error < 0) |
285 | 289 | break; |
286 | 290 | |
287 | - error = 0; | |
288 | - if (buffer.found) | |
289 | - break; | |
290 | 291 | error = -ENOENT; |
291 | 292 | if (old_seq == buffer.sequence) |
292 | 293 | break; |
fs/nfsd/vfs.c
... | ... | @@ -1831,6 +1831,7 @@ |
1831 | 1831 | struct readdir_data { |
1832 | 1832 | char *dirent; |
1833 | 1833 | size_t used; |
1834 | + int full; | |
1834 | 1835 | }; |
1835 | 1836 | |
1836 | 1837 | static int nfsd_buffered_filldir(void *__buf, const char *name, int namlen, |
1837 | 1838 | |
... | ... | @@ -1841,8 +1842,10 @@ |
1841 | 1842 | unsigned int reclen; |
1842 | 1843 | |
1843 | 1844 | reclen = ALIGN(sizeof(struct buffered_dirent) + namlen, sizeof(u64)); |
1844 | - if (buf->used + reclen > PAGE_SIZE) | |
1845 | + if (buf->used + reclen > PAGE_SIZE) { | |
1846 | + buf->full = 1; | |
1845 | 1847 | return -EINVAL; |
1848 | + } | |
1846 | 1849 | |
1847 | 1850 | de->namlen = namlen; |
1848 | 1851 | de->offset = offset; |
1849 | 1852 | |
... | ... | @@ -1874,9 +1877,13 @@ |
1874 | 1877 | unsigned int reclen; |
1875 | 1878 | |
1876 | 1879 | buf.used = 0; |
1880 | + buf.full = 0; | |
1877 | 1881 | |
1878 | 1882 | host_err = vfs_readdir(file, nfsd_buffered_filldir, &buf); |
1879 | - if (host_err) | |
1883 | + if (buf.full) | |
1884 | + host_err = 0; | |
1885 | + | |
1886 | + if (host_err < 0) | |
1880 | 1887 | break; |
1881 | 1888 | |
1882 | 1889 | size = buf.used; |
fs/readdir.c
... | ... | @@ -117,7 +117,7 @@ |
117 | 117 | buf.dirent = dirent; |
118 | 118 | |
119 | 119 | error = vfs_readdir(file, fillonedir, &buf); |
120 | - if (error >= 0) | |
120 | + if (buf.result) | |
121 | 121 | error = buf.result; |
122 | 122 | |
123 | 123 | fput(file); |
... | ... | @@ -209,9 +209,8 @@ |
209 | 209 | buf.error = 0; |
210 | 210 | |
211 | 211 | error = vfs_readdir(file, filldir, &buf); |
212 | - if (error < 0) | |
213 | - goto out_putf; | |
214 | - error = buf.error; | |
212 | + if (error >= 0) | |
213 | + error = buf.error; | |
215 | 214 | lastdirent = buf.previous; |
216 | 215 | if (lastdirent) { |
217 | 216 | if (put_user(file->f_pos, &lastdirent->d_off)) |
... | ... | @@ -219,8 +218,6 @@ |
219 | 218 | else |
220 | 219 | error = count - buf.count; |
221 | 220 | } |
222 | - | |
223 | -out_putf: | |
224 | 221 | fput(file); |
225 | 222 | out: |
226 | 223 | return error; |
227 | 224 | |
228 | 225 | |
229 | 226 | |
... | ... | @@ -293,19 +290,16 @@ |
293 | 290 | buf.error = 0; |
294 | 291 | |
295 | 292 | error = vfs_readdir(file, filldir64, &buf); |
296 | - if (error < 0) | |
297 | - goto out_putf; | |
298 | - error = buf.error; | |
293 | + if (error >= 0) | |
294 | + error = buf.error; | |
299 | 295 | lastdirent = buf.previous; |
300 | 296 | if (lastdirent) { |
301 | 297 | typeof(lastdirent->d_off) d_off = file->f_pos; |
302 | - error = -EFAULT; | |
303 | 298 | if (__put_user(d_off, &lastdirent->d_off)) |
304 | - goto out_putf; | |
305 | - error = count - buf.count; | |
299 | + error = -EFAULT; | |
300 | + else | |
301 | + error = count - buf.count; | |
306 | 302 | } |
307 | - | |
308 | -out_putf: | |
309 | 303 | fput(file); |
310 | 304 | out: |
311 | 305 | return error; |