Skip to content

Commit cb85e6b

Browse files
Luis Henriques (SUSE)mehmetb0
authored andcommitted
ext4: use handle to mark fc as ineligible in __track_dentry_update()
BugLink: https://bugs.launchpad.net/bugs/2086242 commit faab35a upstream. Calling ext4_fc_mark_ineligible() with a NULL handle is racy and may result in a fast-commit being done before the filesystem is effectively marked as ineligible. This patch fixes the calls to this function in __track_dentry_update() by adding an extra parameter to the callback used in ext4_fc_track_template(). Suggested-by: Jan Kara <[email protected]> Signed-off-by: Luis Henriques (SUSE) <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Koichiro Den <[email protected]> Signed-off-by: Roxana Nicolescu <[email protected]>
1 parent 4f34c18 commit cb85e6b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

fs/ext4/fast_commit.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handl
344344
*/
345345
static int ext4_fc_track_template(
346346
handle_t *handle, struct inode *inode,
347-
int (*__fc_track_fn)(struct inode *, void *, bool),
347+
int (*__fc_track_fn)(handle_t *handle, struct inode *, void *, bool),
348348
void *args, int enqueue)
349349
{
350350
bool update = false;
@@ -361,7 +361,7 @@ static int ext4_fc_track_template(
361361
ext4_fc_reset_inode(inode);
362362
ei->i_sync_tid = tid;
363363
}
364-
ret = __fc_track_fn(inode, args, update);
364+
ret = __fc_track_fn(handle, inode, args, update);
365365
mutex_unlock(&ei->i_fc_lock);
366366

367367
if (!enqueue)
@@ -385,7 +385,8 @@ struct __track_dentry_update_args {
385385
};
386386

387387
/* __track_fn for directory entry updates. Called with ei->i_fc_lock. */
388-
static int __track_dentry_update(struct inode *inode, void *arg, bool update)
388+
static int __track_dentry_update(handle_t *handle, struct inode *inode,
389+
void *arg, bool update)
389390
{
390391
struct ext4_fc_dentry_update *node;
391392
struct ext4_inode_info *ei = EXT4_I(inode);
@@ -400,14 +401,14 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
400401

401402
if (IS_ENCRYPTED(dir)) {
402403
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_ENCRYPTED_FILENAME,
403-
NULL);
404+
handle);
404405
mutex_lock(&ei->i_fc_lock);
405406
return -EOPNOTSUPP;
406407
}
407408

408409
node = kmem_cache_alloc(ext4_fc_dentry_cachep, GFP_NOFS);
409410
if (!node) {
410-
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL);
411+
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle);
411412
mutex_lock(&ei->i_fc_lock);
412413
return -ENOMEM;
413414
}
@@ -419,7 +420,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
419420
node->fcd_name.name = kmalloc(dentry->d_name.len, GFP_NOFS);
420421
if (!node->fcd_name.name) {
421422
kmem_cache_free(ext4_fc_dentry_cachep, node);
422-
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL);
423+
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle);
423424
mutex_lock(&ei->i_fc_lock);
424425
return -ENOMEM;
425426
}
@@ -533,7 +534,8 @@ void ext4_fc_track_create(handle_t *handle, struct dentry *dentry)
533534
}
534535

535536
/* __track_fn for inode tracking */
536-
static int __track_inode(struct inode *inode, void *arg, bool update)
537+
static int __track_inode(handle_t *handle, struct inode *inode, void *arg,
538+
bool update)
537539
{
538540
if (update)
539541
return -EEXIST;
@@ -573,7 +575,8 @@ struct __track_range_args {
573575
};
574576

575577
/* __track_fn for tracking data updates */
576-
static int __track_range(struct inode *inode, void *arg, bool update)
578+
static int __track_range(handle_t *handle, struct inode *inode, void *arg,
579+
bool update)
577580
{
578581
struct ext4_inode_info *ei = EXT4_I(inode);
579582
ext4_lblk_t oldstart;

0 commit comments

Comments
 (0)