Skip to content

Commit da5e7c8

Browse files
vvidictorvalds
authored andcommitted
ocfs2: cleanup journal init and shutdown
Allocate and free struct ocfs2_journal in ocfs2_journal_init and ocfs2_journal_shutdown. Init and release of system inodes references the journal so reorder calls to make sure they work correctly. Link: https://lkml.kernel.org/r/20211009145006.3478-1-vvidic@valentin-vidic.from.hr Signed-off-by: Valentin Vidic <vvidic@valentin-vidic.from.hr> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Gang He <ghe@suse.com> Cc: Jun Piao <piaojun@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ae3fab5 commit da5e7c8

File tree

4 files changed

+27
-46
lines changed

4 files changed

+27
-46
lines changed

fs/ocfs2/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
125125
struct inode *inode = NULL;
126126
struct super_block *sb = osb->sb;
127127
struct ocfs2_find_inode_args args;
128-
journal_t *journal = OCFS2_SB(sb)->journal->j_journal;
129128

130129
trace_ocfs2_iget_begin((unsigned long long)blkno, flags,
131130
sysfile_type);
@@ -172,10 +171,11 @@ struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
172171
* part of the transaction - the inode could have been reclaimed and
173172
* now it is reread from disk.
174173
*/
175-
if (journal) {
174+
if (osb->journal) {
176175
transaction_t *transaction;
177176
tid_t tid;
178177
struct ocfs2_inode_info *oi = OCFS2_I(inode);
178+
journal_t *journal = osb->journal->j_journal;
179179

180180
read_lock(&journal->j_state_lock);
181181
if (journal->j_running_transaction)

fs/ocfs2/journal.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -810,19 +810,34 @@ void ocfs2_set_journal_params(struct ocfs2_super *osb)
810810
write_unlock(&journal->j_state_lock);
811811
}
812812

813-
int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty)
813+
int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty)
814814
{
815815
int status = -1;
816816
struct inode *inode = NULL; /* the journal inode */
817817
journal_t *j_journal = NULL;
818+
struct ocfs2_journal *journal = NULL;
818819
struct ocfs2_dinode *di = NULL;
819820
struct buffer_head *bh = NULL;
820-
struct ocfs2_super *osb;
821821
int inode_lock = 0;
822822

823-
BUG_ON(!journal);
823+
/* initialize our journal structure */
824+
journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
825+
if (!journal) {
826+
mlog(ML_ERROR, "unable to alloc journal\n");
827+
status = -ENOMEM;
828+
goto done;
829+
}
830+
osb->journal = journal;
831+
journal->j_osb = osb;
824832

825-
osb = journal->j_osb;
833+
atomic_set(&journal->j_num_trans, 0);
834+
init_rwsem(&journal->j_trans_barrier);
835+
init_waitqueue_head(&journal->j_checkpointed);
836+
spin_lock_init(&journal->j_lock);
837+
journal->j_trans_id = 1UL;
838+
INIT_LIST_HEAD(&journal->j_la_cleanups);
839+
INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
840+
journal->j_state = OCFS2_JOURNAL_FREE;
826841

827842
/* already have the inode for our journal */
828843
inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE,
@@ -1028,9 +1043,10 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb)
10281043

10291044
journal->j_state = OCFS2_JOURNAL_FREE;
10301045

1031-
// up_write(&journal->j_trans_barrier);
10321046
done:
10331047
iput(inode);
1048+
kfree(journal);
1049+
osb->journal = NULL;
10341050
}
10351051

10361052
static void ocfs2_clear_journal_error(struct super_block *sb,

fs/ocfs2/journal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ int ocfs2_compute_replay_slots(struct ocfs2_super *osb);
167167
* ocfs2_start_checkpoint - Kick the commit thread to do a checkpoint.
168168
*/
169169
void ocfs2_set_journal_params(struct ocfs2_super *osb);
170-
int ocfs2_journal_init(struct ocfs2_journal *journal,
171-
int *dirty);
170+
int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty);
172171
void ocfs2_journal_shutdown(struct ocfs2_super *osb);
173172
int ocfs2_journal_wipe(struct ocfs2_journal *journal,
174173
int full);

fs/ocfs2/super.c

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,8 +1894,6 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
18941894
/* This will disable recovery and flush any recovery work. */
18951895
ocfs2_recovery_exit(osb);
18961896

1897-
ocfs2_journal_shutdown(osb);
1898-
18991897
ocfs2_sync_blockdev(sb);
19001898

19011899
ocfs2_purge_refcount_trees(osb);
@@ -1918,6 +1916,8 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
19181916

19191917
ocfs2_release_system_inodes(osb);
19201918

1919+
ocfs2_journal_shutdown(osb);
1920+
19211921
/*
19221922
* If we're dismounting due to mount error, mount.ocfs2 will clean
19231923
* up heartbeat. If we're a local mount, there is no heartbeat.
@@ -2016,7 +2016,6 @@ static int ocfs2_initialize_super(struct super_block *sb,
20162016
int i, cbits, bbits;
20172017
struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
20182018
struct inode *inode = NULL;
2019-
struct ocfs2_journal *journal;
20202019
struct ocfs2_super *osb;
20212020
u64 total_blocks;
20222021

@@ -2197,33 +2196,6 @@ static int ocfs2_initialize_super(struct super_block *sb,
21972196

21982197
get_random_bytes(&osb->s_next_generation, sizeof(u32));
21992198

2200-
/* FIXME
2201-
* This should be done in ocfs2_journal_init(), but unknown
2202-
* ordering issues will cause the filesystem to crash.
2203-
* If anyone wants to figure out what part of the code
2204-
* refers to osb->journal before ocfs2_journal_init() is run,
2205-
* be my guest.
2206-
*/
2207-
/* initialize our journal structure */
2208-
2209-
journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
2210-
if (!journal) {
2211-
mlog(ML_ERROR, "unable to alloc journal\n");
2212-
status = -ENOMEM;
2213-
goto bail;
2214-
}
2215-
osb->journal = journal;
2216-
journal->j_osb = osb;
2217-
2218-
atomic_set(&journal->j_num_trans, 0);
2219-
init_rwsem(&journal->j_trans_barrier);
2220-
init_waitqueue_head(&journal->j_checkpointed);
2221-
spin_lock_init(&journal->j_lock);
2222-
journal->j_trans_id = (unsigned long) 1;
2223-
INIT_LIST_HEAD(&journal->j_la_cleanups);
2224-
INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
2225-
journal->j_state = OCFS2_JOURNAL_FREE;
2226-
22272199
INIT_WORK(&osb->dquot_drop_work, ocfs2_drop_dquot_refs);
22282200
init_llist_head(&osb->dquot_drop_list);
22292201

@@ -2404,7 +2376,7 @@ static int ocfs2_check_volume(struct ocfs2_super *osb)
24042376
* ourselves. */
24052377

24062378
/* Init our journal object. */
2407-
status = ocfs2_journal_init(osb->journal, &dirty);
2379+
status = ocfs2_journal_init(osb, &dirty);
24082380
if (status < 0) {
24092381
mlog(ML_ERROR, "Could not initialize journal!\n");
24102382
goto finally;
@@ -2513,12 +2485,6 @@ static void ocfs2_delete_osb(struct ocfs2_super *osb)
25132485

25142486
kfree(osb->osb_orphan_wipes);
25152487
kfree(osb->slot_recovery_generations);
2516-
/* FIXME
2517-
* This belongs in journal shutdown, but because we have to
2518-
* allocate osb->journal at the start of ocfs2_initialize_osb(),
2519-
* we free it here.
2520-
*/
2521-
kfree(osb->journal);
25222488
kfree(osb->local_alloc_copy);
25232489
kfree(osb->uuid_str);
25242490
kfree(osb->vol_label);

0 commit comments

Comments
 (0)