Skip to content

Commit 7e32701

Browse files
author
Al Viro
committed
ext4 fast_commit: make use of name_snapshot primitives
... rather than open-coding them. As a bonus, that avoids the pointless work with extra allocations, etc. for long names. Reviewed-by: Jeff Layton <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 95a4ccb commit 7e32701

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

fs/ext4/fast_commit.c

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,7 @@ void ext4_fc_del(struct inode *inode)
322322
WARN_ON(!list_empty(&ei->i_fc_dilist));
323323
spin_unlock(&sbi->s_fc_lock);
324324

325-
if (fc_dentry->fcd_name.name &&
326-
fc_dentry->fcd_name.len > DNAME_INLINE_LEN)
327-
kfree(fc_dentry->fcd_name.name);
325+
release_dentry_name_snapshot(&fc_dentry->fcd_name);
328326
kmem_cache_free(ext4_fc_dentry_cachep, fc_dentry);
329327

330328
return;
@@ -449,22 +447,7 @@ static int __track_dentry_update(handle_t *handle, struct inode *inode,
449447
node->fcd_op = dentry_update->op;
450448
node->fcd_parent = dir->i_ino;
451449
node->fcd_ino = inode->i_ino;
452-
if (dentry->d_name.len > DNAME_INLINE_LEN) {
453-
node->fcd_name.name = kmalloc(dentry->d_name.len, GFP_NOFS);
454-
if (!node->fcd_name.name) {
455-
kmem_cache_free(ext4_fc_dentry_cachep, node);
456-
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle);
457-
mutex_lock(&ei->i_fc_lock);
458-
return -ENOMEM;
459-
}
460-
memcpy((u8 *)node->fcd_name.name, dentry->d_name.name,
461-
dentry->d_name.len);
462-
} else {
463-
memcpy(node->fcd_iname, dentry->d_name.name,
464-
dentry->d_name.len);
465-
node->fcd_name.name = node->fcd_iname;
466-
}
467-
node->fcd_name.len = dentry->d_name.len;
450+
take_dentry_name_snapshot(&node->fcd_name, dentry);
468451
INIT_LIST_HEAD(&node->fcd_dilist);
469452
spin_lock(&sbi->s_fc_lock);
470453
if (sbi->s_journal->j_flags & JBD2_FULL_COMMIT_ONGOING ||
@@ -832,7 +815,7 @@ static bool ext4_fc_add_dentry_tlv(struct super_block *sb, u32 *crc,
832815
{
833816
struct ext4_fc_dentry_info fcd;
834817
struct ext4_fc_tl tl;
835-
int dlen = fc_dentry->fcd_name.len;
818+
int dlen = fc_dentry->fcd_name.name.len;
836819
u8 *dst = ext4_fc_reserve_space(sb,
837820
EXT4_FC_TAG_BASE_LEN + sizeof(fcd) + dlen, crc);
838821

@@ -847,7 +830,7 @@ static bool ext4_fc_add_dentry_tlv(struct super_block *sb, u32 *crc,
847830
dst += EXT4_FC_TAG_BASE_LEN;
848831
memcpy(dst, &fcd, sizeof(fcd));
849832
dst += sizeof(fcd);
850-
memcpy(dst, fc_dentry->fcd_name.name, dlen);
833+
memcpy(dst, fc_dentry->fcd_name.name.name, dlen);
851834

852835
return true;
853836
}
@@ -1328,9 +1311,7 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid)
13281311
list_del_init(&fc_dentry->fcd_dilist);
13291312
spin_unlock(&sbi->s_fc_lock);
13301313

1331-
if (fc_dentry->fcd_name.name &&
1332-
fc_dentry->fcd_name.len > DNAME_INLINE_LEN)
1333-
kfree(fc_dentry->fcd_name.name);
1314+
release_dentry_name_snapshot(&fc_dentry->fcd_name);
13341315
kmem_cache_free(ext4_fc_dentry_cachep, fc_dentry);
13351316
spin_lock(&sbi->s_fc_lock);
13361317
}

fs/ext4/fast_commit.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ struct ext4_fc_dentry_update {
109109
int fcd_op; /* Type of update create / unlink / link */
110110
int fcd_parent; /* Parent inode number */
111111
int fcd_ino; /* Inode number */
112-
struct qstr fcd_name; /* Dirent name */
113-
unsigned char fcd_iname[DNAME_INLINE_LEN]; /* Dirent name string */
112+
struct name_snapshot fcd_name; /* Dirent name */
114113
struct list_head fcd_list;
115114
struct list_head fcd_dilist;
116115
};

0 commit comments

Comments
 (0)