diff options
author | Steven Whitehouse <swhiteho@redhat.com> | 2011-07-26 04:17:28 -0400 |
---|---|---|
committer | Steven Whitehouse <swhiteho@redhat.com> | 2011-10-21 07:39:17 -0400 |
commit | 4c28d33803d4aeaff32b4ac502af11a9b2aed8f4 (patch) | |
tree | c7119b6755aae3e1ceceedec54e481d9ff893b00 /fs/gfs2 | |
parent | fd11e153b82ad1c84ccc71ba1cfedc222465198c (diff) |
GFS2: Clean up dir hash table reading
Since there is now only a single caller to gfs2_dir_read_data()
and it has a number of constant arguments, we can factor
those out. Also some tests relating to the inode size were
being done twice.
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2')
-rw-r--r-- | fs/gfs2/dir.c | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c index 1cc2f8ec52a2..2045d70753f1 100644 --- a/fs/gfs2/dir.c +++ b/fs/gfs2/dir.c | |||
@@ -240,16 +240,15 @@ fail: | |||
240 | return error; | 240 | return error; |
241 | } | 241 | } |
242 | 242 | ||
243 | static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf, | 243 | static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, __be64 *buf, |
244 | u64 offset, unsigned int size) | 244 | unsigned int size) |
245 | { | 245 | { |
246 | struct buffer_head *dibh; | 246 | struct buffer_head *dibh; |
247 | int error; | 247 | int error; |
248 | 248 | ||
249 | error = gfs2_meta_inode_buffer(ip, &dibh); | 249 | error = gfs2_meta_inode_buffer(ip, &dibh); |
250 | if (!error) { | 250 | if (!error) { |
251 | offset += sizeof(struct gfs2_dinode); | 251 | memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), size); |
252 | memcpy(buf, dibh->b_data + offset, size); | ||
253 | brelse(dibh); | 252 | brelse(dibh); |
254 | } | 253 | } |
255 | 254 | ||
@@ -261,13 +260,12 @@ static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf, | |||
261 | * gfs2_dir_read_data - Read a data from a directory inode | 260 | * gfs2_dir_read_data - Read a data from a directory inode |
262 | * @ip: The GFS2 Inode | 261 | * @ip: The GFS2 Inode |
263 | * @buf: The buffer to place result into | 262 | * @buf: The buffer to place result into |
264 | * @offset: File offset to begin jdata_readng from | ||
265 | * @size: Amount of data to transfer | 263 | * @size: Amount of data to transfer |
266 | * | 264 | * |
267 | * Returns: The amount of data actually copied or the error | 265 | * Returns: The amount of data actually copied or the error |
268 | */ | 266 | */ |
269 | static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, u64 offset, | 267 | static int gfs2_dir_read_data(struct gfs2_inode *ip, __be64 *buf, |
270 | unsigned int size, unsigned ra) | 268 | unsigned int size) |
271 | { | 269 | { |
272 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | 270 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
273 | u64 lblock, dblock; | 271 | u64 lblock, dblock; |
@@ -275,24 +273,14 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, u64 offset, | |||
275 | unsigned int o; | 273 | unsigned int o; |
276 | int copied = 0; | 274 | int copied = 0; |
277 | int error = 0; | 275 | int error = 0; |
278 | u64 disksize = i_size_read(&ip->i_inode); | ||
279 | |||
280 | if (offset >= disksize) | ||
281 | return 0; | ||
282 | |||
283 | if (offset + size > disksize) | ||
284 | size = disksize - offset; | ||
285 | |||
286 | if (!size) | ||
287 | return 0; | ||
288 | 276 | ||
289 | if (gfs2_is_stuffed(ip)) | 277 | if (gfs2_is_stuffed(ip)) |
290 | return gfs2_dir_read_stuffed(ip, buf, offset, size); | 278 | return gfs2_dir_read_stuffed(ip, buf, size); |
291 | 279 | ||
292 | if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) | 280 | if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip))) |
293 | return -EINVAL; | 281 | return -EINVAL; |
294 | 282 | ||
295 | lblock = offset; | 283 | lblock = 0; |
296 | o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header); | 284 | o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header); |
297 | 285 | ||
298 | while (copied < size) { | 286 | while (copied < size) { |
@@ -311,8 +299,6 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, u64 offset, | |||
311 | if (error || !dblock) | 299 | if (error || !dblock) |
312 | goto fail; | 300 | goto fail; |
313 | BUG_ON(extlen < 1); | 301 | BUG_ON(extlen < 1); |
314 | if (!ra) | ||
315 | extlen = 1; | ||
316 | bh = gfs2_meta_ra(ip->i_gl, dblock, extlen); | 302 | bh = gfs2_meta_ra(ip->i_gl, dblock, extlen); |
317 | } else { | 303 | } else { |
318 | error = gfs2_meta_read(ip->i_gl, dblock, DIO_WAIT, &bh); | 304 | error = gfs2_meta_read(ip->i_gl, dblock, DIO_WAIT, &bh); |
@@ -328,7 +314,7 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, u64 offset, | |||
328 | extlen--; | 314 | extlen--; |
329 | memcpy(buf, bh->b_data + o, amount); | 315 | memcpy(buf, bh->b_data + o, amount); |
330 | brelse(bh); | 316 | brelse(bh); |
331 | buf += amount; | 317 | buf += (amount/sizeof(__be64)); |
332 | copied += amount; | 318 | copied += amount; |
333 | lblock++; | 319 | lblock++; |
334 | o = sizeof(struct gfs2_meta_header); | 320 | o = sizeof(struct gfs2_meta_header); |
@@ -371,7 +357,7 @@ static __be64 *gfs2_dir_get_hash_table(struct gfs2_inode *ip) | |||
371 | if (hc == NULL) | 357 | if (hc == NULL) |
372 | return ERR_PTR(-ENOMEM); | 358 | return ERR_PTR(-ENOMEM); |
373 | 359 | ||
374 | ret = gfs2_dir_read_data(ip, (char *)hc, 0, hsize, 1); | 360 | ret = gfs2_dir_read_data(ip, hc, hsize); |
375 | if (ret < 0) { | 361 | if (ret < 0) { |
376 | kfree(hc); | 362 | kfree(hc); |
377 | return ERR_PTR(ret); | 363 | return ERR_PTR(ret); |