Skip to content

Commit a80f7fc

Browse files
harshadjstytso
authored andcommitted
ext4: fixup ext4_fc_track_* functions' signature
Firstly, pass handle to all ext4_fc_track_* functions and use transaction id found in handle->h_transaction->h_tid for tracking fast commit updates. Secondly, don't pass inode to ext4_fc_track_link/create/unlink functions. inode can be found inside these functions as d_inode(dentry). However, rename path is an exeception. That's because in that case, we need inode that's not same as d_inode(dentry). To handle that, add a couple of low-level wrapper functions that take inode and dentry as arguments. Suggested-by: Jan Kara <[email protected]> Signed-off-by: Harshad Shirwadkar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 5b552ad commit a80f7fc

File tree

5 files changed

+74
-63
lines changed

5 files changed

+74
-63
lines changed

fs/ext4/ext4.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -2738,12 +2738,16 @@ extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate);
27382738
int ext4_fc_info_show(struct seq_file *seq, void *v);
27392739
void ext4_fc_init(struct super_block *sb, journal_t *journal);
27402740
void ext4_fc_init_inode(struct inode *inode);
2741-
void ext4_fc_track_range(struct inode *inode, ext4_lblk_t start,
2741+
void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t start,
27422742
ext4_lblk_t end);
2743-
void ext4_fc_track_unlink(struct inode *inode, struct dentry *dentry);
2744-
void ext4_fc_track_link(struct inode *inode, struct dentry *dentry);
2745-
void ext4_fc_track_create(struct inode *inode, struct dentry *dentry);
2746-
void ext4_fc_track_inode(struct inode *inode);
2743+
void __ext4_fc_track_unlink(handle_t *handle, struct inode *inode,
2744+
struct dentry *dentry);
2745+
void __ext4_fc_track_link(handle_t *handle, struct inode *inode,
2746+
struct dentry *dentry);
2747+
void ext4_fc_track_unlink(handle_t *handle, struct dentry *dentry);
2748+
void ext4_fc_track_link(handle_t *handle, struct dentry *dentry);
2749+
void ext4_fc_track_create(handle_t *handle, struct dentry *dentry);
2750+
void ext4_fc_track_inode(handle_t *handle, struct inode *inode);
27472751
void ext4_fc_mark_ineligible(struct super_block *sb, int reason);
27482752
void ext4_fc_start_ineligible(struct super_block *sb, int reason);
27492753
void ext4_fc_stop_ineligible(struct super_block *sb);
@@ -3459,7 +3463,7 @@ extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode,
34593463
extern int ext4_ci_compare(const struct inode *parent,
34603464
const struct qstr *fname,
34613465
const struct qstr *entry, bool quick);
3462-
extern int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
3466+
extern int __ext4_unlink(handle_t *handle, struct inode *dir, const struct qstr *d_name,
34633467
struct inode *inode);
34643468
extern int __ext4_link(struct inode *dir, struct inode *inode,
34653469
struct dentry *dentry);

fs/ext4/extents.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4599,7 +4599,7 @@ static long ext4_zero_range(struct file *file, loff_t offset,
45994599
ret = ext4_mark_inode_dirty(handle, inode);
46004600
if (unlikely(ret))
46014601
goto out_handle;
4602-
ext4_fc_track_range(inode, offset >> inode->i_sb->s_blocksize_bits,
4602+
ext4_fc_track_range(handle, inode, offset >> inode->i_sb->s_blocksize_bits,
46034603
(offset + len - 1) >> inode->i_sb->s_blocksize_bits);
46044604
/* Zero out partial block at the edges of the range */
46054605
ret = ext4_zero_partial_blocks(handle, inode, offset, len);

fs/ext4/fast_commit.c

+30-18
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,14 @@ static inline int ext4_fc_is_ineligible(struct super_block *sb)
323323
* If enqueue is set, this function enqueues the inode in fast commit list.
324324
*/
325325
static int ext4_fc_track_template(
326-
struct inode *inode, int (*__fc_track_fn)(struct inode *, void *, bool),
326+
handle_t *handle, struct inode *inode,
327+
int (*__fc_track_fn)(struct inode *, void *, bool),
327328
void *args, int enqueue)
328329
{
329-
tid_t running_txn_tid;
330330
bool update = false;
331331
struct ext4_inode_info *ei = EXT4_I(inode);
332332
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
333+
tid_t tid = 0;
333334
int ret;
334335

335336
if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) ||
@@ -339,15 +340,13 @@ static int ext4_fc_track_template(
339340
if (ext4_fc_is_ineligible(inode->i_sb))
340341
return -EINVAL;
341342

342-
running_txn_tid = sbi->s_journal ?
343-
sbi->s_journal->j_commit_sequence + 1 : 0;
344-
343+
tid = handle->h_transaction->t_tid;
345344
mutex_lock(&ei->i_fc_lock);
346-
if (running_txn_tid == ei->i_sync_tid) {
345+
if (tid == ei->i_sync_tid) {
347346
update = true;
348347
} else {
349348
ext4_fc_reset_inode(inode);
350-
ei->i_sync_tid = running_txn_tid;
349+
ei->i_sync_tid = tid;
351350
}
352351
ret = __fc_track_fn(inode, args, update);
353352
mutex_unlock(&ei->i_fc_lock);
@@ -422,41 +421,54 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)
422421
return 0;
423422
}
424423

425-
void ext4_fc_track_unlink(struct inode *inode, struct dentry *dentry)
424+
void __ext4_fc_track_unlink(handle_t *handle,
425+
struct inode *inode, struct dentry *dentry)
426426
{
427427
struct __track_dentry_update_args args;
428428
int ret;
429429

430430
args.dentry = dentry;
431431
args.op = EXT4_FC_TAG_UNLINK;
432432

433-
ret = ext4_fc_track_template(inode, __track_dentry_update,
433+
ret = ext4_fc_track_template(handle, inode, __track_dentry_update,
434434
(void *)&args, 0);
435435
trace_ext4_fc_track_unlink(inode, dentry, ret);
436436
}
437437

438-
void ext4_fc_track_link(struct inode *inode, struct dentry *dentry)
438+
void ext4_fc_track_unlink(handle_t *handle, struct dentry *dentry)
439+
{
440+
__ext4_fc_track_unlink(handle, d_inode(dentry), dentry);
441+
}
442+
443+
void __ext4_fc_track_link(handle_t *handle,
444+
struct inode *inode, struct dentry *dentry)
439445
{
440446
struct __track_dentry_update_args args;
441447
int ret;
442448

443449
args.dentry = dentry;
444450
args.op = EXT4_FC_TAG_LINK;
445451

446-
ret = ext4_fc_track_template(inode, __track_dentry_update,
452+
ret = ext4_fc_track_template(handle, inode, __track_dentry_update,
447453
(void *)&args, 0);
448454
trace_ext4_fc_track_link(inode, dentry, ret);
449455
}
450456

451-
void ext4_fc_track_create(struct inode *inode, struct dentry *dentry)
457+
void ext4_fc_track_link(handle_t *handle, struct dentry *dentry)
458+
{
459+
__ext4_fc_track_link(handle, d_inode(dentry), dentry);
460+
}
461+
462+
void ext4_fc_track_create(handle_t *handle, struct dentry *dentry)
452463
{
453464
struct __track_dentry_update_args args;
465+
struct inode *inode = d_inode(dentry);
454466
int ret;
455467

456468
args.dentry = dentry;
457469
args.op = EXT4_FC_TAG_CREAT;
458470

459-
ret = ext4_fc_track_template(inode, __track_dentry_update,
471+
ret = ext4_fc_track_template(handle, inode, __track_dentry_update,
460472
(void *)&args, 0);
461473
trace_ext4_fc_track_create(inode, dentry, ret);
462474
}
@@ -472,14 +484,14 @@ static int __track_inode(struct inode *inode, void *arg, bool update)
472484
return 0;
473485
}
474486

475-
void ext4_fc_track_inode(struct inode *inode)
487+
void ext4_fc_track_inode(handle_t *handle, struct inode *inode)
476488
{
477489
int ret;
478490

479491
if (S_ISDIR(inode->i_mode))
480492
return;
481493

482-
ret = ext4_fc_track_template(inode, __track_inode, NULL, 1);
494+
ret = ext4_fc_track_template(handle, inode, __track_inode, NULL, 1);
483495
trace_ext4_fc_track_inode(inode, ret);
484496
}
485497

@@ -515,7 +527,7 @@ static int __track_range(struct inode *inode, void *arg, bool update)
515527
return 0;
516528
}
517529

518-
void ext4_fc_track_range(struct inode *inode, ext4_lblk_t start,
530+
void ext4_fc_track_range(handle_t *handle, struct inode *inode, ext4_lblk_t start,
519531
ext4_lblk_t end)
520532
{
521533
struct __track_range_args args;
@@ -527,7 +539,7 @@ void ext4_fc_track_range(struct inode *inode, ext4_lblk_t start,
527539
args.start = start;
528540
args.end = end;
529541

530-
ret = ext4_fc_track_template(inode, __track_range, &args, 1);
542+
ret = ext4_fc_track_template(handle, inode, __track_range, &args, 1);
531543

532544
trace_ext4_fc_track_range(inode, start, end, ret);
533545
}
@@ -1263,7 +1275,7 @@ static int ext4_fc_replay_unlink(struct super_block *sb, struct ext4_fc_tl *tl)
12631275
return 0;
12641276
}
12651277

1266-
ret = __ext4_unlink(old_parent, &entry, inode);
1278+
ret = __ext4_unlink(NULL, old_parent, &entry, inode);
12671279
/* -ENOENT ok coz it might not exist anymore. */
12681280
if (ret == -ENOENT)
12691281
ret = 0;

fs/ext4/inode.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
732732
if (ret)
733733
return ret;
734734
}
735-
ext4_fc_track_range(inode, map->m_lblk,
735+
ext4_fc_track_range(handle, inode, map->m_lblk,
736736
map->m_lblk + map->m_len - 1);
737737
}
738738

@@ -4111,7 +4111,7 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
41114111

41124112
up_write(&EXT4_I(inode)->i_data_sem);
41134113
}
4114-
ext4_fc_track_range(inode, first_block, stop_block);
4114+
ext4_fc_track_range(handle, inode, first_block, stop_block);
41154115
if (IS_SYNC(inode))
41164116
ext4_handle_sync(handle);
41174117

@@ -5444,14 +5444,14 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
54445444
}
54455445

54465446
if (shrink)
5447-
ext4_fc_track_range(inode,
5447+
ext4_fc_track_range(handle, inode,
54485448
(attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
54495449
inode->i_sb->s_blocksize_bits,
54505450
(oldsize > 0 ? oldsize - 1 : 0) >>
54515451
inode->i_sb->s_blocksize_bits);
54525452
else
54535453
ext4_fc_track_range(
5454-
inode,
5454+
handle, inode,
54555455
(oldsize > 0 ? oldsize - 1 : oldsize) >>
54565456
inode->i_sb->s_blocksize_bits,
54575457
(attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
@@ -5701,7 +5701,7 @@ int ext4_mark_iloc_dirty(handle_t *handle,
57015701
put_bh(iloc->bh);
57025702
return -EIO;
57035703
}
5704-
ext4_fc_track_inode(inode);
5704+
ext4_fc_track_inode(handle, inode);
57055705

57065706
if (IS_I_VERSION(inode))
57075707
inode_inc_iversion(inode);

0 commit comments

Comments
 (0)