xref: /haiku/src/add-ons/kernel/file_systems/btrfs/Journal.h (revision aa08671d9cd445a6ff181c83e9b077c51521f857)
199768086Shyche /*
299768086Shyche  * Copyright 2017, Chế Vũ Gia Hy, cvghy116@gmail.com.
399768086Shyche  * Copyright 2001-2012, Axel Dörfler, axeld@pinc-software.de.
499768086Shyche  * This file may be used under the terms of the MIT License.
599768086Shyche  */
6c1320b3aShyche #ifndef JOURNAL_H
7c1320b3aShyche #define JOURNAL_H
8c1320b3aShyche 
9c1320b3aShyche 
10c1320b3aShyche #include "Volume.h"
11c1320b3aShyche 
12c1320b3aShyche class Transaction;
13c1320b3aShyche 
14c1320b3aShyche 
15c1320b3aShyche class Journal {
16c1320b3aShyche public:
17c1320b3aShyche 							Journal(Volume* volume);
18c1320b3aShyche 							~Journal();
19c1320b3aShyche 
GetVolume()20c1320b3aShyche 			Volume*			GetVolume() const { return fVolume; }
CurrentTransaction()21c1320b3aShyche 			Transaction*	CurrentTransaction() const { return fOwner; }
SystemTransactionID()22c1320b3aShyche 			uint64			SystemTransactionID() const
23c1320b3aShyche 								{ return fCurrentGeneration; }
TransactionID()24c1320b3aShyche 			int32			TransactionID() const { return fTransactionID; }
25c1320b3aShyche 			status_t		Lock(Transaction* owner);
26c1320b3aShyche 			status_t		UnLock(Transaction* owner, bool success);
27c1320b3aShyche 
28c1320b3aShyche private:
29c1320b3aShyche 	static	void			_TransactionWritten(int32 transactionID, int32 event,
30c1320b3aShyche 								void* _journal);
31c1320b3aShyche 			status_t		_TransactionDone(bool success);
32c1320b3aShyche 
33c1320b3aShyche private:
34c1320b3aShyche 			Volume*			fVolume;
35c1320b3aShyche 			recursive_lock	fLock;
36c1320b3aShyche 			Transaction*	fOwner;
37c1320b3aShyche 			int32			fTransactionID;
38c1320b3aShyche 			uint64			fCurrentGeneration;
39c1320b3aShyche };
40c1320b3aShyche 
41c1320b3aShyche 
42c1320b3aShyche class Transaction {
43c1320b3aShyche public:
44c1320b3aShyche 							Transaction(Volume* volume);
45c1320b3aShyche 							Transaction();
46c1320b3aShyche 							~Transaction();
47c1320b3aShyche 
GetJournal()48*aa08671dSLes De Ridder 			Journal*		GetJournal() const { return fJournal; }
ID()49c1320b3aShyche 			int32			ID() const { return fJournal->TransactionID(); }
SystemID()50c1320b3aShyche 			uint64			SystemID() const
51c1320b3aShyche 								{ return fJournal->SystemTransactionID(); }
52c1320b3aShyche 			bool			HasBlock(fsblock_t blockNumber) const;
Parent()53c1320b3aShyche 			Transaction*	Parent() const { return fParent; }
SetParent(Transaction * parent)54c1320b3aShyche 			void			SetParent(Transaction* parent) { fParent = parent; }
55c1320b3aShyche 			status_t		Start(Volume* volume);
56c1320b3aShyche 			status_t		Done();
57c1320b3aShyche private:
58c1320b3aShyche 			Journal*		fJournal;
59c1320b3aShyche 			Transaction*	fParent;
60c1320b3aShyche };
61c1320b3aShyche 
62c1320b3aShyche 
63c1320b3aShyche #endif	// JOURNAL_H
64