Skip to content

Commit faab35a

Browse files
Luis Henriques (SUSE)tytso
Luis Henriques (SUSE)
authored andcommitted
ext4: use handle to mark fc as ineligible in __track_dentry_update()
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]
1 parent 9852d85 commit faab35a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

fs/ext4/fast_commit.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handl
379379
*/
380380
static int ext4_fc_track_template(
381381
handle_t *handle, struct inode *inode,
382-
int (*__fc_track_fn)(struct inode *, void *, bool),
382+
int (*__fc_track_fn)(handle_t *handle, struct inode *, void *, bool),
383383
void *args, int enqueue)
384384
{
385385
bool update = false;
@@ -396,7 +396,7 @@ static int ext4_fc_track_template(
396396
ext4_fc_reset_inode(inode);
397397
ei->i_sync_tid = tid;
398398
}
399-
ret = __fc_track_fn(inode, args, update);
399+
ret = __fc_track_fn(handle, inode, args, update);
400400
mutex_unlock(&ei->i_fc_lock);
401401

402402
if (!enqueue)
@@ -420,7 +420,8 @@ struct __track_dentry_update_args {
420420
};
421421

422422
/* __track_fn for directory entry updates. Called with ei->i_fc_lock. */
423-
static int __track_dentry_update(struct inode *inode, void *arg, bool update)
423+
static int __track_dentry_update(handle_t *handle, struct inode *inode,
424+
void *arg, bool update)
424425
{
425426
struct ext4_fc_dentry_update *node;
426427
struct ext4_inode_info *ei = EXT4_I(inode);
@@ -435,14 +436,14 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
435436

436437
if (IS_ENCRYPTED(dir)) {
437438
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_ENCRYPTED_FILENAME,
438-
NULL);
439+
handle);
439440
mutex_lock(&ei->i_fc_lock);
440441
return -EOPNOTSUPP;
441442
}
442443

443444
node = kmem_cache_alloc(ext4_fc_dentry_cachep, GFP_NOFS);
444445
if (!node) {
445-
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL);
446+
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle);
446447
mutex_lock(&ei->i_fc_lock);
447448
return -ENOMEM;
448449
}
@@ -454,7 +455,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
454455
node->fcd_name.name = kmalloc(dentry->d_name.len, GFP_NOFS);
455456
if (!node->fcd_name.name) {
456457
kmem_cache_free(ext4_fc_dentry_cachep, node);
457-
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, NULL);
458+
ext4_fc_mark_ineligible(sb, EXT4_FC_REASON_NOMEM, handle);
458459
mutex_lock(&ei->i_fc_lock);
459460
return -ENOMEM;
460461
}
@@ -576,7 +577,8 @@ void ext4_fc_track_create(handle_t *handle, struct dentry *dentry)
576577
}
577578

578579
/* __track_fn for inode tracking */
579-
static int __track_inode(struct inode *inode, void *arg, bool update)
580+
static int __track_inode(handle_t *handle, struct inode *inode, void *arg,
581+
bool update)
580582
{
581583
if (update)
582584
return -EEXIST;
@@ -614,7 +616,8 @@ struct __track_range_args {
614616
};
615617

616618
/* __track_fn for tracking data updates */
617-
static int __track_range(struct inode *inode, void *arg, bool update)
619+
static int __track_range(handle_t *handle, struct inode *inode, void *arg,
620+
bool update)
618621
{
619622
struct ext4_inode_info *ei = EXT4_I(inode);
620623
ext4_lblk_t oldstart;

0 commit comments

Comments
 (0)