aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorMark Fasheh <mark.fasheh@oracle.com>2007-09-13 19:29:01 -0400
committerMark Fasheh <mark.fasheh@oracle.com>2007-10-12 14:54:39 -0400
commit8553cf4f360d6fc4913a0bdd3b22dd7b5bb9a3be (patch)
tree705bedbd5dcaf12e1ed8bb3c3f6fc8f9bd828477 /fs
parent38760e243249f03b4c6d78ca624dd846a2681b67 (diff)
ocfs2: Cleanup dirent size check
The check to see if a new dirent would fit in an old one is pretty ugly, and it's done at least twice. Clean things up by putting this in it's own easier-to-read function. Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com> Reviewed-by: Joel Becker <joel.becker@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/ocfs2/dir.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
index 31db7e3881b1..f2e2ffbf6c95 100644
--- a/fs/ocfs2/dir.c
+++ b/fs/ocfs2/dir.c
@@ -343,6 +343,31 @@ bail:
343 return status; 343 return status;
344} 344}
345 345
346/*
347 * Check whether 'de' has enough room to hold an entry of
348 * 'new_rec_len' bytes.
349 */
350static inline int ocfs2_dirent_would_fit(struct ocfs2_dir_entry *de,
351 unsigned int new_rec_len)
352{
353 unsigned int de_really_used;
354
355 /* Check whether this is an empty record with enough space */
356 if (le64_to_cpu(de->inode) == 0 &&
357 le16_to_cpu(de->rec_len) >= new_rec_len)
358 return 1;
359
360 /*
361 * Record might have free space at the end which we can
362 * use.
363 */
364 de_really_used = OCFS2_DIR_REC_LEN(de->name_len);
365 if (le16_to_cpu(de->rec_len) >= (de_really_used + new_rec_len))
366 return 1;
367
368 return 0;
369}
370
346/* we don't always have a dentry for what we want to add, so people 371/* we don't always have a dentry for what we want to add, so people
347 * like orphan dir can call this instead. 372 * like orphan dir can call this instead.
348 * 373 *
@@ -385,10 +410,8 @@ int __ocfs2_add_entry(handle_t *handle,
385 retval = -EEXIST; 410 retval = -EEXIST;
386 goto bail; 411 goto bail;
387 } 412 }
388 if (((le64_to_cpu(de->inode) == 0) && 413
389 (le16_to_cpu(de->rec_len) >= rec_len)) || 414 if (ocfs2_dirent_would_fit(de, rec_len)) {
390 (le16_to_cpu(de->rec_len) >=
391 (OCFS2_DIR_REC_LEN(de->name_len) + rec_len))) {
392 dir->i_mtime = dir->i_ctime = CURRENT_TIME; 415 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
393 retval = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh); 416 retval = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh);
394 if (retval < 0) { 417 if (retval < 0) {
@@ -1078,10 +1101,7 @@ int ocfs2_prepare_dir_for_insert(struct ocfs2_super *osb,
1078 status = -EEXIST; 1101 status = -EEXIST;
1079 goto bail; 1102 goto bail;
1080 } 1103 }
1081 if (((le64_to_cpu(de->inode) == 0) && 1104 if (ocfs2_dirent_would_fit(de, rec_len)) {
1082 (le16_to_cpu(de->rec_len) >= rec_len)) ||
1083 (le16_to_cpu(de->rec_len) >=
1084 (OCFS2_DIR_REC_LEN(de->name_len) + rec_len))) {
1085 /* Ok, we found a spot. Return this bh and let 1105 /* Ok, we found a spot. Return this bh and let
1086 * the caller actually fill it in. */ 1106 * the caller actually fill it in. */
1087 *ret_de_bh = bh; 1107 *ret_de_bh = bh;