ReactOS  0.4.13-dev-464-g6b95727
replay.c File Reference
#include <linux/module.h>
#include <linux/time.h>
#include <linux/fs.h>
#include <linux/jbd.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/freezer.h>
#include <linux/pagemap.h>
#include <linux/kthread.h>
#include <linux/poison.h>
#include <linux/proc_fs.h>
#include <linux/debugfs.h>
Include dependency graph for replay.c:

Go to the source code of this file.

Functions

int __log_start_commit (journal_t *journal, tid_t target)
 
int log_start_commit (journal_t *journal, tid_t tid)
 
static void __journal_abort_hard (journal_t *journal)
 
static void __journal_abort_soft (journal_t *journal, int err)
 
void journal_abort (journal_t *journal, int err)
 
int journal_errno (journal_t *journal)
 
int journal_clear_err (journal_t *journal)
 
void journal_ack_err (journal_t *journal)
 
int journal_blocks_per_page (struct inode *inode)
 
static int journal_init_journal_head_cache (void)
 
static void journal_destroy_journal_head_cache (void)
 
static struct journal_headjournal_alloc_journal_head (void)
 
static void journal_free_journal_head (struct journal_head *jh)
 
struct journal_headjournal_add_journal_head (struct buffer_head *bh)
 
struct journal_headjournal_grab_journal_head (struct buffer_head *bh)
 
static void __journal_remove_journal_head (struct buffer_head *bh)
 
void journal_remove_journal_head (struct buffer_head *bh)
 
void journal_put_journal_head (struct journal_head *jh)
 
int journal_next_log_block (journal_t *journal, unsigned long *retp)
 
int journal_bmap (journal_t *journal, unsigned long blocknr, unsigned long *retp)
 
struct journal_headjournal_get_descriptor_buffer (journal_t *journal)
 
static journal_t * journal_init_common (void)
 
journal_t * journal_init_inode (struct inode *inode)
 
void journal_wipe_recovery (journal_t *journal)
 
void journal_destroy (journal_t *journal)
 
int journal_check_used_features (journal_t *journal, unsigned long compat, unsigned long ro, unsigned long incompat)
 
int journal_check_available_features (journal_t *journal, unsigned long compat, unsigned long ro, unsigned long incompat)
 
int journal_set_features (journal_t *journal, unsigned long compat, unsigned long ro, unsigned long incompat)
 
static int journal_convert_superblock_v1 (journal_t *journal, journal_superblock_t *sb)
 
static void journal_fail_superblock (journal_t *journal)
 
static int journal_get_superblock (journal_t *journal)
 
static int load_superblock (journal_t *journal)
 
int journal_wipe (journal_t *journal, int write)
 
int journal_update_format (journal_t *journal)
 
void journal_update_superblock (journal_t *journal, int wait)
 
static int journal_reset (journal_t *journal)
 
int journal_load (journal_t *journal)
 
static void __blist_add_buffer (struct journal_head **list, struct journal_head *jh)
 
static void __blist_del_buffer (struct journal_head **list, struct journal_head *jh)
 
static void __journal_temp_unlink_buffer (struct journal_head *jh)
 
void __journal_unfile_buffer (struct journal_head *jh)
 
void journal_unfile_buffer (journal_t *journal, struct journal_head *jh)
 
static int __dispose_buffer (struct journal_head *jh, transaction_t *transaction)
 
void __journal_file_buffer (struct journal_head *jh, transaction_t *transaction, int jlist)
 
void journal_file_buffer (struct journal_head *jh, transaction_t *transaction, int jlist)
 
void journal_release_buffer (handle_t *handle, struct buffer_head *bh)
 
int journal_forget (handle_t *handle, struct buffer_head *bh)
 
static void jbd_create_debugfs_entry (void)
 
static void jbd_remove_debugfs_entry (void)
 
static int __init journal_init_handle_cache (void)
 
static void journal_destroy_handle_cache (void)
 
static int __init journal_init_caches (void)
 
static void journal_destroy_caches (void)
 
static int __init journal_init (void)
 
static void __exit journal_exit (void)
 
 MODULE_LICENSE ("GPL")
 
 module_init (journal_init)
 
 module_exit (journal_exit)
 

Variables

static struct kmem_cachejournal_head_cache = NULL
 
struct kmem_cachejbd_handle_cache = NULL
 

Function Documentation

◆ __blist_add_buffer()

static void __blist_add_buffer ( struct journal_head **  list,
struct journal_head jh 
)
inlinestatic

Definition at line 1188 of file replay.c.

1189 {
1190  if (!*list) {
1191  jh->b_tnext = jh->b_tprev = jh;
1192  *list = jh;
1193  } else {
1194  /* Insert at the tail of the list to preserve order */
1195  struct journal_head *first = *list, *last = first->b_tprev;
1196  jh->b_tprev = last;
1197  jh->b_tnext = first;
1198  last->b_tnext = first->b_tprev = jh;
1199  }
1200 }
POINT last
Definition: font.c:46
const GLint * first
Definition: glext.h:5794
struct journal_head * b_tprev
Definition: journal-head.h:75
struct journal_head * b_tnext
Definition: journal-head.h:75
Definition: _list.h:228
#define list
Definition: rosglue.h:35

Referenced by __journal_file_buffer().

◆ __blist_del_buffer()

static void __blist_del_buffer ( struct journal_head **  list,
struct journal_head jh 
)
inlinestatic

Definition at line 1212 of file replay.c.

1213 {
1214  if (*list == jh) {
1215  *list = jh->b_tnext;
1216  if (*list == jh)
1217  *list = NULL;
1218  }
1219  jh->b_tprev->b_tnext = jh->b_tnext;
1220  jh->b_tnext->b_tprev = jh->b_tprev;
1221 }
struct journal_head * b_tprev
Definition: journal-head.h:75
smooth NULL
Definition: ftsmooth.c:416
struct journal_head * b_tnext
Definition: journal-head.h:75
Definition: _list.h:228

Referenced by __journal_temp_unlink_buffer().

◆ __dispose_buffer()

static int __dispose_buffer ( struct journal_head jh,
transaction_t transaction 
)
static

Definition at line 1313 of file replay.c.

1314 {
1315  int may_free = 1;
1316  struct buffer_head *bh = jh2bh(jh);
1317 
1319 
1320  if (jh->b_cp_transaction) {
1321  JBUFFER_TRACE(jh, "on running+cp transaction");
1322  __journal_file_buffer(jh, transaction, BJ_Forget);
1323  clear_buffer_jbddirty(bh);
1324  may_free = 0;
1325  } else {
1326  JBUFFER_TRACE(jh, "on running transaction");
1328  __brelse(bh);
1329  }
1330  return may_free;
1331 }
void journal_remove_journal_head(struct buffer_head *bh)
Definition: replay.c:432
void __journal_unfile_buffer(struct journal_head *jh)
Definition: replay.c:1286
transaction_t * b_cp_transaction
Definition: journal-head.h:82
void __brelse(struct buffer_head *)
Definition: linux.c:800
#define BJ_Forget
Definition: jbd.h:1120
void __journal_file_buffer(struct journal_head *jh, transaction_t *transaction, int jlist)
Definition: replay.c:1337

◆ __journal_abort_hard()

static void __journal_abort_hard ( journal_t *  journal)
static

Definition at line 65 of file replay.c.

66 {
67  transaction_t *transaction;
68 
69  if (journal->j_flags & JFS_ABORT)
70  return;
71 
72  jbd_lock(&journal->j_state_lock);
73  journal->j_flags |= JFS_ABORT;
74  transaction = journal->j_running_transaction;
75  if (transaction)
76  __log_start_commit(journal, transaction->t_tid);
77  jbd_unlock(&journal->j_state_lock);
78 }
int __log_start_commit(journal_t *journal, tid_t target)
Definition: replay.c:21
struct transaction_s transaction_t
Definition: journal-head.h:14

Referenced by __journal_abort_soft().

◆ __journal_abort_soft()

static void __journal_abort_soft ( journal_t *  journal,
int  err 
)
static

Definition at line 82 of file replay.c.

83 {
84  if (journal->j_flags & JFS_ABORT)
85  return;
86 
87  if (!journal->j_errno)
88  journal->j_errno = err;
89 
90  __journal_abort_hard(journal);
91 
92  if (err)
93  journal_update_superblock(journal, 1);
94 }
static void __journal_abort_hard(journal_t *journal)
Definition: replay.c:65
void journal_update_superblock(journal_t *journal, int wait)
Definition: replay.c:1030
#define err(...)

Referenced by journal_abort(), and journal_bmap().

◆ __journal_file_buffer()

void __journal_file_buffer ( struct journal_head jh,
transaction_t transaction,
int  jlist 
)

Definition at line 1337 of file replay.c.

1339 {
1340  struct journal_head **list = NULL;
1341  int was_dirty = 0;
1342  struct buffer_head *bh = jh2bh(jh);
1343 
1344  J_ASSERT_JH(jh, jbd_is_locked_bh_state(bh));
1345  assert_jbd_locked(&transaction->t_journal->j_list_lock);
1346 
1347  J_ASSERT_JH(jh, jh->b_jlist < BJ_Types);
1348  J_ASSERT_JH(jh, jh->b_transaction == transaction ||
1349  jh->b_transaction == NULL);
1350 
1351  if (jh->b_transaction && jh->b_jlist == (unsigned) jlist)
1352  return;
1353 
1354  /* The following list of buffer states needs to be consistent
1355  * with __jbd_unexpected_dirty_buffer()'s handling of dirty
1356  * state. */
1357 
1358  if (jlist == BJ_Metadata || jlist == BJ_Reserved ||
1359  jlist == BJ_Shadow || jlist == BJ_Forget) {
1360  if (test_clear_buffer_dirty(bh) ||
1361  test_clear_buffer_jbddirty(bh))
1362  was_dirty = 1;
1363  }
1364 
1365  if (jh->b_transaction)
1367  jh->b_transaction = transaction;
1368 
1369  switch (jlist) {
1370  case BJ_None:
1371  J_ASSERT_JH(jh, !jh->b_committed_data);
1372  J_ASSERT_JH(jh, !jh->b_frozen_data);
1373  return;
1374  case BJ_SyncData:
1375  list = &transaction->t_sync_datalist;
1376  break;
1377  case BJ_Metadata:
1378  transaction->t_nr_buffers++;
1379  list = &transaction->t_buffers;
1380  break;
1381  case BJ_Forget:
1382  list = &transaction->t_forget;
1383  break;
1384  case BJ_IO:
1385  list = &transaction->t_iobuf_list;
1386  break;
1387  case BJ_Shadow:
1388  list = &transaction->t_shadow_list;
1389  break;
1390  case BJ_LogCtl:
1391  list = &transaction->t_log_list;
1392  break;
1393  case BJ_Reserved:
1394  list = &transaction->t_reserved_list;
1395  break;
1396  case BJ_Locked:
1397  list = &transaction->t_locked_list;
1398  break;
1399  }
1400 
1401  __blist_add_buffer(list, jh);
1402  jh->b_jlist = jlist;
1403 
1404  if (was_dirty)
1405  set_buffer_jbddirty(bh);
1406 }
static void __journal_temp_unlink_buffer(struct journal_head *jh)
Definition: replay.c:1234
#define BJ_Shadow
Definition: jbd.h:1122
transaction_t * b_transaction
Definition: journal-head.h:61
char * b_committed_data
Definition: journal-head.h:52
#define BJ_LogCtl
Definition: jbd.h:1123
#define BJ_Locked
Definition: jbd.h:1125
#define BJ_Reserved
Definition: jbd.h:1124
smooth NULL
Definition: ftsmooth.c:416
#define BJ_None
Definition: jbd.h:1117
Definition: _list.h:228
#define BJ_SyncData
Definition: jbd.h:1118
#define BJ_Metadata
Definition: jbd.h:1119
#define BJ_IO
Definition: jbd.h:1121
#define BJ_Forget
Definition: jbd.h:1120
static void __blist_add_buffer(struct journal_head **list, struct journal_head *jh)
Definition: replay.c:1188
#define BJ_Types
Definition: jbd.h:1126
char * b_frozen_data
Definition: journal-head.h:45
unsigned b_jlist
Definition: journal-head.h:32

Referenced by __dispose_buffer(), journal_file_buffer(), and journal_forget().

◆ __journal_remove_journal_head()

static void __journal_remove_journal_head ( struct buffer_head bh)
static

Definition at line 381 of file replay.c.

382 {
383  struct journal_head *jh = bh2jh(bh);
384 
385  J_ASSERT_JH(jh, jh->b_jcount >= 0);
386 
387  get_bh(bh);
388  if (jh->b_jcount == 0) {
389  if (jh->b_transaction == NULL &&
390  jh->b_next_transaction == NULL &&
391  jh->b_cp_transaction == NULL) {
392  J_ASSERT_JH(jh, jh->b_jlist == BJ_None);
393  J_ASSERT_BH(bh, buffer_jbd(bh));
394  J_ASSERT_BH(bh, jh2bh(jh) == bh);
395  BUFFER_TRACE(bh, "remove journal_head");
396  if (jh->b_frozen_data) {
397  printk(KERN_WARNING "%s: freeing "
398  "b_frozen_data\n",
399  __FUNCTION__);
400  jbd_free(jh->b_frozen_data, bh->b_size);
401  }
402  if (jh->b_committed_data) {
403  printk(KERN_WARNING "%s: freeing "
404  "b_committed_data\n",
405  __FUNCTION__);
406  jbd_free(jh->b_committed_data, bh->b_size);
407  }
408  bh->b_private = NULL;
409  jh->b_bh = NULL; /* debug, really */
410  clear_buffer_jbd(bh);
411  __brelse(bh);
413  } else {
414  BUFFER_TRACE(bh, "journal_head was locked");
415  }
416  }
417 }
static void get_bh(struct buffer_head *bh)
Definition: module.h:934
struct buffer_head * b_bh
Definition: journal-head.h:21
transaction_t * b_next_transaction
Definition: journal-head.h:69
transaction_t * b_transaction
Definition: journal-head.h:61
char * b_committed_data
Definition: journal-head.h:52
size_t b_size
Definition: module.h:724
void * b_private
Definition: module.h:727
smooth NULL
Definition: ftsmooth.c:416
#define KERN_WARNING
Definition: module.h:224
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
transaction_t * b_cp_transaction
Definition: journal-head.h:82
void __brelse(struct buffer_head *)
Definition: linux.c:800
#define BJ_None
Definition: jbd.h:1117
static void journal_free_journal_head(struct journal_head *jh)
Definition: replay.c:273
char * b_frozen_data
Definition: journal-head.h:45
#define __FUNCTION__
Definition: types.h:112
unsigned b_jlist
Definition: journal-head.h:32

Referenced by journal_put_journal_head(), and journal_remove_journal_head().

◆ __journal_temp_unlink_buffer()

static void __journal_temp_unlink_buffer ( struct journal_head jh)
static

Definition at line 1234 of file replay.c.

1235 {
1236  struct journal_head **list = NULL;
1237  transaction_t *transaction;
1238  struct buffer_head *bh = jh2bh(jh);
1239 
1240  J_ASSERT_JH(jh, jbd_is_locked_bh_state(bh));
1241  transaction = jh->b_transaction;
1242  if (transaction)
1243  assert_jbd_locked(&transaction->t_journal->j_list_lock);
1244 
1245  J_ASSERT_JH(jh, jh->b_jlist < BJ_Types);
1246  if (jh->b_jlist != BJ_None)
1247  J_ASSERT_JH(jh, transaction != NULL);
1248 
1249  switch (jh->b_jlist) {
1250  case BJ_None:
1251  return;
1252  case BJ_SyncData:
1253  list = &transaction->t_sync_datalist;
1254  break;
1255  case BJ_Metadata:
1256  transaction->t_nr_buffers--;
1257  J_ASSERT_JH(jh, transaction->t_nr_buffers >= 0);
1258  list = &transaction->t_buffers;
1259  break;
1260  case BJ_Forget:
1261  list = &transaction->t_forget;
1262  break;
1263  case BJ_IO:
1264  list = &transaction->t_iobuf_list;
1265  break;
1266  case BJ_Shadow:
1267  list = &transaction->t_shadow_list;
1268  break;
1269  case BJ_LogCtl:
1270  list = &transaction->t_log_list;
1271  break;
1272  case BJ_Reserved:
1273  list = &transaction->t_reserved_list;
1274  break;
1275  case BJ_Locked:
1276  list = &transaction->t_locked_list;
1277  break;
1278  }
1279 
1280  __blist_del_buffer(list, jh);
1281  jh->b_jlist = BJ_None;
1282  if (test_clear_buffer_jbddirty(bh))
1283  mark_buffer_dirty(bh); /* Expose it to the VM */
1284 }
#define BJ_Shadow
Definition: jbd.h:1122
transaction_t * b_transaction
Definition: journal-head.h:61
#define BJ_LogCtl
Definition: jbd.h:1123
#define BJ_Locked
Definition: jbd.h:1125
#define BJ_Reserved
Definition: jbd.h:1124
smooth NULL
Definition: ftsmooth.c:416
#define BJ_None
Definition: jbd.h:1117
Definition: _list.h:228
#define BJ_SyncData
Definition: jbd.h:1118
void mark_buffer_dirty(struct buffer_head *bh)
Definition: linux.c:906
#define BJ_Metadata
Definition: jbd.h:1119
#define BJ_IO
Definition: jbd.h:1121
#define BJ_Forget
Definition: jbd.h:1120
#define BJ_Types
Definition: jbd.h:1126
struct transaction_s transaction_t
Definition: journal-head.h:14
static void __blist_del_buffer(struct journal_head **list, struct journal_head *jh)
Definition: replay.c:1212
unsigned b_jlist
Definition: journal-head.h:32

Referenced by __journal_file_buffer(), __journal_unfile_buffer(), and journal_forget().

◆ __journal_unfile_buffer()

void __journal_unfile_buffer ( struct journal_head jh)

Definition at line 1286 of file replay.c.

1287 {
1289  jh->b_transaction = NULL;
1290 }
static void __journal_temp_unlink_buffer(struct journal_head *jh)
Definition: replay.c:1234
transaction_t * b_transaction
Definition: journal-head.h:61
smooth NULL
Definition: ftsmooth.c:416

Referenced by __dispose_buffer(), journal_forget(), and journal_unfile_buffer().

◆ __log_start_commit()

int __log_start_commit ( journal_t *  journal,
tid_t  target 
)

Definition at line 21 of file replay.c.

22 {
23  /*
24  * Are we already doing a recent enough commit?
25  */
26  if (!tid_geq(journal->j_commit_request, target)) {
27  /*
28  * We want a new commit: OK, mark the request and wakup the
29  * commit thread. We do _not_ do the commit ourselves.
30  */
31 
32  journal->j_commit_request = target;
33  jbd_debug(1, "JBD: requesting commit %d/%d\n",
34  journal->j_commit_request,
35  journal->j_commit_sequence);
36  wake_up(&journal->j_wait_commit);
37  return 1;
38  }
39  return 0;
40 }
int wake_up(wait_queue_head_t *queue)
Definition: linux.c:279
static int tid_geq(tid_t x, tid_t y)
Definition: jbd.h:1091
GLenum target
Definition: glext.h:7315

Referenced by __journal_abort_hard(), and log_start_commit().

◆ jbd_create_debugfs_entry()

static void jbd_create_debugfs_entry ( void  )
inlinestatic

Definition at line 1573 of file replay.c.

1574 {
1575 }

Referenced by journal_init().

◆ jbd_remove_debugfs_entry()

static void jbd_remove_debugfs_entry ( void  )
inlinestatic

Definition at line 1577 of file replay.c.

1578 {
1579 }

Referenced by journal_exit().

◆ journal_abort()

void journal_abort ( journal_t *  journal,
int  err 
)

void journal_abort () - Shutdown the journal immediately. @journal: the journal to shutdown. @errno: an error number to record in the journal indicating the reason for the shutdown.

Perform a complete, immediate shutdown of the ENTIRE journal (not of a single transaction). This operation cannot be undone without closing and reopening the journal.

The journal_abort function is intended to support higher level error recovery mechanisms such as the ext2/ext3 remount-readonly error mode.

Journal abort has very specific semantics. Any existing dirty, unjournaled buffers in the main filesystem will still be written to disk by bdflush, but the journaling mechanism will be suspended immediately and no further transaction commits will be honoured.

Any dirty, journaled buffers will be written back to disk without hitting the journal. Atomicity cannot be guaranteed on an aborted filesystem, but we do attempt to leave as much data as possible behind for fsck to use for cleanup.

Any attempt to get a new transaction handle on a journal which is in ABORT state will just result in an -EROFS error return. A journal_stop on an existing handle will return -EIO if we have entered abort state during the update.

Recursive transactions are not disturbed by journal abort until the final journal_stop, which will receive the -EIO error.

Finally, the journal_abort call allows the caller to supply an errno which will be recorded (if possible) in the journal superblock. This allows a client to record failure conditions in the middle of a transaction without having to complete the transaction to record the failure to disk. ext3_error, for example, now uses this functionality.

Errors which originate from within the journaling layer will NOT supply an errno; a null errno implies that absolutely no further writes are done to the journal (unless there are any already in progress).

Definition at line 143 of file replay.c.

144 {
145  __journal_abort_soft(journal, err);
146 }
static void __journal_abort_soft(journal_t *journal, int err)
Definition: replay.c:82
#define err(...)

◆ journal_ack_err()

void journal_ack_err ( journal_t *  journal)

void journal_ack_err() - Ack journal err. @journal: journal to act on.

An error must be cleared or Acked to take a FS out of readonly mode.

Definition at line 199 of file replay.c.

200 {
201  jbd_lock(&journal->j_state_lock);
202  if (journal->j_errno)
203  journal->j_flags |= JFS_ACK_ERR;
204  jbd_unlock(&journal->j_state_lock);
205 }

◆ journal_add_journal_head()

struct journal_head* journal_add_journal_head ( struct buffer_head bh)

Definition at line 325 of file replay.c.

326 {
327  struct journal_head *jh;
328  struct journal_head *new_jh = NULL;
329 
330 repeat:
331  if (!buffer_jbd(bh)) {
332  new_jh = journal_alloc_journal_head();
333  memset(new_jh, 0, sizeof(*new_jh));
334  }
335 
336  jbd_lock_bh_journal_head(bh);
337  if (buffer_jbd(bh)) {
338  jh = bh2jh(bh);
339  } else {
340  J_ASSERT_BH(bh,
341  (atomic_read(&bh->b_count) > 0) ||
342  (bh->b_page && bh->b_page->mapping));
343 
344  if (!new_jh) {
345  jbd_unlock_bh_journal_head(bh);
346  goto repeat;
347  }
348 
349  jh = new_jh;
350  new_jh = NULL; /* We consumed it */
351  set_buffer_jbd(bh);
352  bh->b_private = jh;
353  jh->b_bh = bh;
354  get_bh(bh);
355  BUFFER_TRACE(bh, "added journal_head");
356  }
357  jh->b_jcount++;
358  jbd_unlock_bh_journal_head(bh);
359  if (new_jh)
361  return bh->b_private;
362 }
static void get_bh(struct buffer_head *bh)
Definition: module.h:934
struct buffer_head * b_bh
Definition: journal-head.h:21
static struct journal_head * journal_alloc_journal_head(void)
Definition: replay.c:249
atomic_t b_count
Definition: module.h:730
void * b_private
Definition: module.h:727
#define atomic_read(v)
Definition: atomic.h:23
smooth NULL
Definition: ftsmooth.c:416
struct page * b_page
Definition: module.h:716
static int repeat
Definition: xmllint.c:143
static void journal_free_journal_head(struct journal_head *jh)
Definition: replay.c:273
#define memset(x, y, z)
Definition: compat.h:39

Referenced by journal_get_descriptor_buffer().

◆ journal_alloc_journal_head()

static struct journal_head* journal_alloc_journal_head ( void  )
static

Definition at line 249 of file replay.c.

250 {
251  struct journal_head *ret;
252  static unsigned long last_warning;
253 
254 #ifdef CONFIG_JBD_DEBUG
255  atomic_inc(&nr_journal_heads);
256 #endif
258  if (ret == NULL) {
259  jbd_debug(1, "out of memory for journal_head\n");
260  if (time_after(jiffies, last_warning + 5*HZ)) {
261  printk(KERN_NOTICE "ENOMEM in %s, retrying.\n",
262  __FUNCTION__);
263  last_warning = jiffies;
264  }
265  while (ret == NULL) {
266  yield();
268  }
269  }
270  return ret;
271 }
#define KERN_NOTICE
Definition: module.h:225
#define jiffies
Definition: module.h:1075
#define GFP_NOFS
Definition: module.h:659
void * kmem_cache_alloc(kmem_cache_t *kc, int flags)
Definition: linux.c:92
#define HZ
Definition: hardware.c:32
smooth NULL
Definition: ftsmooth.c:416
static void atomic_inc(atomic_t volatile *v)
Definition: atomic.h:95
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
#define time_after(a, b)
Definition: glue.h:18
int ret
#define yield()
Definition: module.h:439
#define __FUNCTION__
Definition: types.h:112
static struct kmem_cache * journal_head_cache
Definition: replay.c:216

Referenced by journal_add_journal_head().

◆ journal_blocks_per_page()

int journal_blocks_per_page ( struct inode inode)

Definition at line 207 of file replay.c.

208 {
209  return 1 << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits);
210 }
Definition: fs.h:78
#define PAGE_CACHE_SHIFT
Definition: module.h:696
struct super_block * i_sb
Definition: fs.h:96

Referenced by ext3_journal_blocks_per_page().

◆ journal_bmap()

int journal_bmap ( journal_t *  journal,
unsigned long  blocknr,
unsigned long retp 
)

Definition at line 484 of file replay.c.

486 {
487  int err = 0;
488  unsigned long ret;
489 
490  if (journal->j_inode) {
491  ret = (unsigned long)bmap(journal->j_inode, (sector_t)blocknr);
492  if (ret)
493  *retp = ret;
494  else {
495  printk(KERN_ALERT "%s: journal block not found "
496  "at offset %lu ...\n",
497  __FUNCTION__,
498  blocknr);
499  err = -EIO;
500  __journal_abort_soft(journal, err);
501  }
502  } else {
503  *retp = blocknr; /* +journal->j_blk_offset */
504  }
505  return err;
506 }
#define KERN_ALERT
Definition: module.h:221
unsigned __int64 sector_t
Definition: types.h:78
static void __journal_abort_soft(journal_t *journal, int err)
Definition: replay.c:82
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
int ret
ULONGLONG bmap(struct inode *i, ULONGLONG b)
Definition: linux.c:934
#define err(...)
#define long
Definition: qsort.c:33
Definition: arc.h:40
#define __FUNCTION__
Definition: types.h:112

Referenced by journal_init_inode(), journal_next_log_block(), and jread().

◆ journal_check_available_features()

int journal_check_available_features ( journal_t *  journal,
unsigned long  compat,
unsigned long  ro,
unsigned long  incompat 
)

int journal_check_available_features() - Check feature set in journalling layer @journal: Journal to check. @compat: bitmask of compatible features @ro: bitmask of features that force read-only mount @incompat: bitmask of incompatible features

Check whether the journaling code supports the use of all of a given set of features on this journal. Return true (non-zero) if it can.

Definition at line 767 of file replay.c.

769 {
771 
772  if (!compat && !ro && !incompat)
773  return 1;
774 
775  sb = journal->j_superblock;
776 
777  /* We can support any known requested features iff the
778  * superblock is in version 2. Otherwise we fail to support any
779  * extended sb features. */
780 
781  if (journal->j_format_version != 2)
782  return 0;
783 
784  if ((compat & JFS_KNOWN_COMPAT_FEATURES) == compat &&
785  (ro & JFS_KNOWN_ROCOMPAT_FEATURES) == ro &&
786  (incompat & JFS_KNOWN_INCOMPAT_FEATURES) == incompat)
787  return 1;
788 
789  return 0;
790 }
#define JFS_KNOWN_COMPAT_FEATURES
Definition: jbd.h:274
superblock * sb
Definition: btrfs.c:3952
#define JFS_KNOWN_ROCOMPAT_FEATURES
Definition: jbd.h:275
#define JFS_KNOWN_INCOMPAT_FEATURES
Definition: jbd.h:276

Referenced by journal_set_features().

◆ journal_check_used_features()

int journal_check_used_features ( journal_t *  journal,
unsigned long  compat,
unsigned long  ro,
unsigned long  incompat 
)

int journal_check_used_features () - Check if features specified are used. @journal: Journal to check. @compat: bitmask of compatible features @ro: bitmask of features that force read-only mount @incompat: bitmask of incompatible features

Check whether the journal uses all of a given set of features. Return true (non-zero) if it does.

Definition at line 736 of file replay.c.

738 {
740 
741  if (!compat && !ro && !incompat)
742  return 1;
743  if (journal->j_format_version == 1)
744  return 0;
745 
746  sb = journal->j_superblock;
747 
748  if (((be32_to_cpu(sb->s_feature_compat) & compat) == compat) &&
749  ((be32_to_cpu(sb->s_feature_ro_compat) & ro) == ro) &&
750  ((be32_to_cpu(sb->s_feature_incompat) & incompat) == incompat))
751  return 1;
752 
753  return 0;
754 }
#define be32_to_cpu
Definition: module.h:155
superblock * sb
Definition: btrfs.c:3952

Referenced by journal_set_features().

◆ journal_clear_err()

int journal_clear_err ( journal_t *  journal)

int journal_clear_err () - clears the journal's error state @journal: journal to act on.

An error must be cleared or Acked to take a FS out of readonly mode.

Definition at line 179 of file replay.c.

180 {
181  int err = 0;
182 
183  jbd_lock(&journal->j_state_lock);
184  if (journal->j_flags & JFS_ABORT)
185  err = -EROFS;
186  else
187  journal->j_errno = 0;
188  jbd_unlock(&journal->j_state_lock);
189  return err;
190 }
Definition: arc.h:53
#define err(...)

◆ journal_convert_superblock_v1()

static int journal_convert_superblock_v1 ( journal_t *  journal,
journal_superblock_t sb 
)
static

Definition at line 827 of file replay.c.

829 {
830  int offset, blocksize;
831  struct buffer_head *bh;
832 
834  "JBD: Converting superblock from version 1 to 2.\n");
835 
836  /* Pre-initialise new fields to zero */
837  offset = (INT)(((INT_PTR) &(sb->s_feature_compat)) - ((INT_PTR) sb));
838  blocksize = be32_to_cpu(sb->s_blocksize);
839  memset(&sb->s_feature_compat, 0, blocksize-offset);
840 
841  sb->s_nr_users = cpu_to_be32(1);
842  sb->s_header.h_blocktype = cpu_to_be32(JFS_SUPERBLOCK_V2);
843  journal->j_format_version = 2;
844 
845  bh = journal->j_sb_buffer;
846  BUFFER_TRACE(bh, "marking dirty");
847  mark_buffer_dirty(bh);
848  sync_dirty_buffer(bh);
849  return 0;
850 }
#define be32_to_cpu
Definition: module.h:155
#define cpu_to_be32
Definition: module.h:154
superblock * sb
Definition: btrfs.c:3952
#define INT
Definition: polytest.cpp:20
GLintptr offset
Definition: glext.h:5920
int32_t INT_PTR
Definition: typedefs.h:62
#define JFS_SUPERBLOCK_V2
Definition: jbd.h:172
int sync_dirty_buffer(struct buffer_head *bh)
Definition: linux.c:890
#define KERN_WARNING
Definition: module.h:224
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
void mark_buffer_dirty(struct buffer_head *bh)
Definition: linux.c:906
#define memset(x, y, z)
Definition: compat.h:39

Referenced by journal_update_format().

◆ journal_destroy()

void journal_destroy ( journal_t *  journal)

void journal_destroy() - Release a journal_t structure. @journal: Journal to act on.

Release a journal_t structure once it is no longer in use by the journaled object.

Definition at line 678 of file replay.c.

679 {
680 #if 0
681  /* Wait for the commit thread to wake up and die. */
682  journal_kill_thread(journal);
683 
684  /* Force a final log commit */
685  if (journal->j_running_transaction)
686  journal_commit_transaction(journal);
687 
688  /* Force any old transactions to disk */
689 
690  /* Totally anal locking here... */
691  jbd_lock(&journal->j_list_lock);
692  while (journal->j_checkpoint_transactions != NULL) {
693  jbd_unlock(&journal->j_list_lock);
694  log_do_checkpoint(journal);
695  jbd_lock(&journal->j_list_lock);
696  }
697 
698  J_ASSERT(journal->j_running_transaction == NULL);
699  J_ASSERT(journal->j_committing_transaction == NULL);
700  J_ASSERT(journal->j_checkpoint_transactions == NULL);
701  jbd_unlock(&journal->j_list_lock);
702 
703  /* We can now mark the journal as empty. */
704  journal->j_tail = 0;
705  journal->j_tail_sequence = ++journal->j_transaction_sequence;
706  if (journal->j_sb_buffer) {
707  journal_update_superblock(journal, 1);
708  brelse(journal->j_sb_buffer);
709  }
710 #endif
711 
712  if (journal->j_sb_buffer) {
713  brelse(journal->j_sb_buffer);
714  }
715  if (journal->j_inode)
716  iput(journal->j_inode);
717  if (journal->j_revoke)
718  journal_destroy_revoke(journal);
719  kfree(journal->j_wbuf);
720  kfree(journal);
721 }
void journal_update_superblock(journal_t *journal, int wait)
Definition: replay.c:1030
static void brelse(struct buffer_head *bh)
Definition: module.h:945
smooth NULL
Definition: ftsmooth.c:416
void iput(struct inode *inode)
Definition: linux.c:984
void journal_destroy_revoke(journal_t *journal)
Definition: revoke.c:271
void kfree(const void *)

Referenced by Ext2RecoverJournal().

◆ journal_destroy_caches()

static void journal_destroy_caches ( void  )
static

Definition at line 1621 of file replay.c.

1622 {
1626 }
void journal_destroy_revoke_caches(void)
Definition: revoke.c:191
static void journal_destroy_handle_cache(void)
Definition: replay.c:1599
static void journal_destroy_journal_head_cache(void)
Definition: replay.c:239

Referenced by journal_exit(), and journal_init().

◆ journal_destroy_handle_cache()

static void journal_destroy_handle_cache ( void  )
static

Definition at line 1599 of file replay.c.

1600 {
1601  if (jbd_handle_cache)
1603 }
int kmem_cache_destroy(kmem_cache_t *kc)
Definition: linux.c:82
struct kmem_cache * jbd_handle_cache
Definition: replay.c:1583

Referenced by journal_destroy_caches().

◆ journal_destroy_journal_head_cache()

static void journal_destroy_journal_head_cache ( void  )
static

Definition at line 239 of file replay.c.

240 {
241  J_ASSERT(journal_head_cache != NULL);
244 }
smooth NULL
Definition: ftsmooth.c:416
int kmem_cache_destroy(kmem_cache_t *kc)
Definition: linux.c:82
static struct kmem_cache * journal_head_cache
Definition: replay.c:216

Referenced by journal_destroy_caches().

◆ journal_errno()

int journal_errno ( journal_t *  journal)

int journal_errno () - returns the journal's error state. @journal: journal to examine.

This is the errno numbet set with journal_abort(), the last time the journal was mounted - if the journal was stopped without calling abort this will be 0.

If the journal has been aborted on this mount time -EROFS will be returned.

Definition at line 159 of file replay.c.

160 {
161  int err;
162 
163  jbd_lock(&journal->j_state_lock);
164  if (journal->j_flags & JFS_ABORT)
165  err = -EROFS;
166  else
167  err = journal->j_errno;
168  jbd_unlock(&journal->j_state_lock);
169  return err;
170 }
Definition: arc.h:53
#define err(...)

◆ journal_exit()

static void __exit journal_exit ( void  )
static

Definition at line 1641 of file replay.c.

1642 {
1643 #ifdef CONFIG_JBD_DEBUG
1644  int n = atomic_read(&nr_journal_heads);
1645  if (n)
1646  printk(KERN_EMERG "JBD: leaked %d journal_heads!\n", n);
1647 #endif
1650 }
static void jbd_remove_debugfs_entry(void)
Definition: replay.c:1577
GLdouble n
Definition: glext.h:7729
#define atomic_read(v)
Definition: atomic.h:23
#define KERN_EMERG
Definition: module.h:220
static void journal_destroy_caches(void)
Definition: replay.c:1621
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76

Referenced by DriverEntry().

◆ journal_fail_superblock()

static void journal_fail_superblock ( journal_t *  journal)
static

Definition at line 858 of file replay.c.

859 {
860  struct buffer_head *bh = journal->j_sb_buffer;
861  brelse(bh);
862  journal->j_sb_buffer = NULL;
863 }
static void brelse(struct buffer_head *bh)
Definition: module.h:945
smooth NULL
Definition: ftsmooth.c:416

Referenced by journal_get_superblock().

◆ journal_file_buffer()

void journal_file_buffer ( struct journal_head jh,
transaction_t transaction,
int  jlist 
)

Definition at line 1408 of file replay.c.

1410 {
1411  jbd_lock_bh_state(jh2bh(jh));
1412  jbd_lock(&transaction->t_journal->j_list_lock);
1413  __journal_file_buffer(jh, transaction, jlist);
1414  jbd_unlock(&transaction->t_journal->j_list_lock);
1415  jbd_unlock_bh_state(jh2bh(jh));
1416 }
void __journal_file_buffer(struct journal_head *jh, transaction_t *transaction, int jlist)
Definition: replay.c:1337

◆ journal_forget()

int journal_forget ( handle_t handle,
struct buffer_head bh 
)

void journal_forget() - bforget() for potentially-journaled buffers. @handle: transaction handle @bh: bh to 'forget'

We can only do the bforget if there are no commits pending against the buffer. If the buffer is dirty in the current running transaction we can safely unlink it.

bh may not be a journalled buffer at all - it may be a non-JBD buffer which came off the hashtable. Check for this.

Decrements bh->b_count by one.

Allow this call even if the handle has aborted — it may be part of the caller's cleanup after an abort.

Definition at line 1447 of file replay.c.

1448 {
1449  transaction_t *transaction = handle->h_transaction;
1450  journal_t *journal = transaction->t_journal;
1451  struct journal_head *jh;
1452  int drop_reserve = 0;
1453  int err = 0;
1454 
1455  BUFFER_TRACE(bh, "entry");
1456 
1457  jbd_lock_bh_state(bh);
1458  jbd_lock(&journal->j_list_lock);
1459 
1460  if (!buffer_jbd(bh))
1461  goto not_jbd;
1462  jh = bh2jh(bh);
1463 
1464  /* Critical error: attempting to delete a bitmap buffer, maybe?
1465  * Don't do any jbd operations, and return an error. */
1466  if (!J_EXPECT_JH(jh, !jh->b_committed_data,
1467  "inconsistent data on disk")) {
1468  err = -EIO;
1469  goto not_jbd;
1470  }
1471 
1472  /*
1473  * The buffer's going from the transaction, we must drop
1474  * all references -bzzz
1475  */
1476  jh->b_modified = 0;
1477 
1478  if (jh->b_transaction == handle->h_transaction) {
1479  J_ASSERT_JH(jh, !jh->b_frozen_data);
1480 
1481  /* If we are forgetting a buffer which is already part
1482  * of this transaction, then we can just drop it from
1483  * the transaction immediately. */
1484  clear_buffer_dirty(bh);
1485  clear_buffer_jbddirty(bh);
1486 
1487  JBUFFER_TRACE(jh, "belongs to current transaction: unfile");
1488 
1489  drop_reserve = 1;
1490 
1491  /*
1492  * We are no longer going to journal this buffer.
1493  * However, the commit of this transaction is still
1494  * important to the buffer: the delete that we are now
1495  * processing might obsolete an old log entry, so by
1496  * committing, we can satisfy the buffer's checkpoint.
1497  *
1498  * So, if we have a checkpoint on the buffer, we should
1499  * now refile the buffer on our BJ_Forget list so that
1500  * we know to remove the checkpoint after we commit.
1501  */
1502 
1503  if (jh->b_cp_transaction) {
1505  __journal_file_buffer(jh, transaction, BJ_Forget);
1506  } else {
1509  __brelse(bh);
1510  if (!buffer_jbd(bh)) {
1511  jbd_unlock(&journal->j_list_lock);
1512  jbd_unlock_bh_state(bh);
1513  __bforget(bh);
1514  goto drop;
1515  }
1516  }
1517  } else if (jh->b_transaction) {
1518  J_ASSERT_JH(jh, (jh->b_transaction ==
1519  journal->j_committing_transaction));
1520  /* However, if the buffer is still owned by a prior
1521  * (committing) transaction, we can't drop it yet... */
1522  JBUFFER_TRACE(jh, "belongs to older transaction");
1523  /* ... but we CAN drop it from the new transaction if we
1524  * have also modified it since the original commit. */
1525 
1526  if (jh->b_next_transaction) {
1527  J_ASSERT(jh->b_next_transaction == transaction);
1528  jh->b_next_transaction = NULL;
1529  drop_reserve = 1;
1530  }
1531  }
1532 
1533 not_jbd:
1534  jbd_unlock(&journal->j_list_lock);
1535  jbd_unlock_bh_state(bh);
1536  __brelse(bh);
1537 drop:
1538  if (drop_reserve) {
1539  /* no need to reserve log space for this block -bzzz */
1540  handle->h_buffer_credits++;
1541  }
1542  return err;
1543 }
void __bforget(struct buffer_head *)
Definition: linux.c:835
static void __journal_temp_unlink_buffer(struct journal_head *jh)
Definition: replay.c:1234
void journal_remove_journal_head(struct buffer_head *bh)
Definition: replay.c:432
transaction_t * b_next_transaction
Definition: journal-head.h:69
transaction_t * b_transaction
Definition: journal-head.h:61
char * b_committed_data
Definition: journal-head.h:52
void __journal_unfile_buffer(struct journal_head *jh)
Definition: replay.c:1286
smooth NULL
Definition: ftsmooth.c:416
transaction_t * b_cp_transaction
Definition: journal-head.h:82
unsigned b_modified
Definition: journal-head.h:39
void __brelse(struct buffer_head *)
Definition: linux.c:800
#define err(...)
#define BJ_Forget
Definition: jbd.h:1120
Definition: arc.h:40
char * b_frozen_data
Definition: journal-head.h:45
struct transaction_s transaction_t
Definition: journal-head.h:14
void __journal_file_buffer(struct journal_head *jh, transaction_t *transaction, int jlist)
Definition: replay.c:1337

◆ journal_free_journal_head()

static void journal_free_journal_head ( struct journal_head jh)
static

Definition at line 273 of file replay.c.

274 {
275 #ifdef CONFIG_JBD_DEBUG
276  atomic_dec(&nr_journal_heads);
277  memset(jh, JBD_POISON_FREE, sizeof(*jh));
278 #endif
280 }
void kmem_cache_free(kmem_cache_t *kc, void *p)
Definition: linux.c:103
static void atomic_dec(atomic_t volatile *v)
Definition: atomic.h:107
#define memset(x, y, z)
Definition: compat.h:39
static struct kmem_cache * journal_head_cache
Definition: replay.c:216

Referenced by __journal_remove_journal_head(), and journal_add_journal_head().

◆ journal_get_descriptor_buffer()

struct journal_head* journal_get_descriptor_buffer ( journal_t *  journal)

Definition at line 518 of file replay.c.

519 {
520  struct buffer_head *bh;
521  unsigned long blocknr;
522  int err;
523 
524  err = journal_next_log_block(journal, &blocknr);
525 
526  if (err)
527  return NULL;
528 
529  bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
530  lock_buffer(bh);
531  memset(bh->b_data, 0, journal->j_blocksize);
532  set_buffer_uptodate(bh);
533  unlock_buffer(bh);
534  BUFFER_TRACE(bh, "return this buffer");
535  return journal_add_journal_head(bh);
536 }
void unlock_buffer(struct buffer_head *bh)
Definition: linux.c:845
struct buffer_head * __getblk(struct block_device *bdev, sector_t block, unsigned long size)
Definition: linux.c:791
smooth NULL
Definition: ftsmooth.c:416
int journal_next_log_block(journal_t *journal, unsigned long *retp)
Definition: replay.c:461
struct journal_head * journal_add_journal_head(struct buffer_head *bh)
Definition: replay.c:325
#define err(...)
char * b_data
Definition: module.h:725
static void lock_buffer(struct buffer_head *bh)
Definition: module.h:1018
#define memset(x, y, z)
Definition: compat.h:39

◆ journal_get_superblock()

static int journal_get_superblock ( journal_t *  journal)
static

Definition at line 871 of file replay.c.

872 {
873  struct buffer_head *bh;
875  int err = -EIO;
876 
877  bh = journal->j_sb_buffer;
878 
879  J_ASSERT(bh != NULL);
880  if (!buffer_uptodate(bh)) {
881  ll_rw_block(READ, 1, &bh);
882  wait_on_buffer(bh);
883  if (!buffer_uptodate(bh)) {
885  "JBD: IO error reading journal superblock\n");
886  goto out;
887  }
888  }
889 
890  sb = journal->j_superblock;
891 
892  err = -EINVAL;
893 
894  if (sb->s_header.h_magic != cpu_to_be32(JFS_MAGIC_NUMBER) ||
895  sb->s_blocksize != cpu_to_be32(journal->j_blocksize)) {
896  printk(KERN_WARNING "JBD: no valid journal superblock found\n");
897  goto out;
898  }
899 
900  switch (be32_to_cpu(sb->s_header.h_blocktype)) {
901  case JFS_SUPERBLOCK_V1:
902  journal->j_format_version = 1;
903  break;
904  case JFS_SUPERBLOCK_V2:
905  journal->j_format_version = 2;
906  break;
907  default:
908  printk(KERN_WARNING "JBD: unrecognised superblock format ID\n");
909  goto out;
910  }
911 
912  if (be32_to_cpu(sb->s_maxlen) < journal->j_maxlen)
913  journal->j_maxlen = be32_to_cpu(sb->s_maxlen);
914  else if (be32_to_cpu(sb->s_maxlen) > journal->j_maxlen) {
915  printk (KERN_WARNING "JBD: journal file too short\n");
916  goto out;
917  }
918 
919  return 0;
920 
921 out:
922  journal_fail_superblock(journal);
923  return err;
924 }
#define be32_to_cpu
Definition: module.h:155
#define cpu_to_be32
Definition: module.h:154
superblock * sb
Definition: btrfs.c:3952
Definition: arc.h:39
void ll_rw_block(int, int, struct buffer_head *bh[])
Definition: linux.c:854
#define JFS_SUPERBLOCK_V2
Definition: jbd.h:172
#define READ(_gif, _buf, _len)
Definition: ungif.c:107
static void wait_on_buffer(struct buffer_head *bh)
Definition: module.h:1011
#define JFS_MAGIC_NUMBER
Definition: jbd.h:159
smooth NULL
Definition: ftsmooth.c:416
#define KERN_WARNING
Definition: module.h:224
#define JFS_SUPERBLOCK_V1
Definition: jbd.h:171
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
static void journal_fail_superblock(journal_t *journal)
Definition: replay.c:858
#define KERN_ERR
Definition: module.h:223
static FILE * out
Definition: regtests2xml.c:44
#define err(...)
Definition: arc.h:40

Referenced by journal_update_format(), and load_superblock().

◆ journal_grab_journal_head()

struct journal_head* journal_grab_journal_head ( struct buffer_head bh)

Definition at line 368 of file replay.c.

369 {
370  struct journal_head *jh = NULL;
371 
372  jbd_lock_bh_journal_head(bh);
373  if (buffer_jbd(bh)) {
374  jh = bh2jh(bh);
375  jh->b_jcount++;
376  }
377  jbd_unlock_bh_journal_head(bh);
378  return jh;
379 }
smooth NULL
Definition: ftsmooth.c:416

◆ journal_init()

static int __init journal_init ( void  )
static

Definition at line 1628 of file replay.c.

1629 {
1630  int ret;
1631 
1632  J_ASSERT(sizeof(struct journal_superblock_s) == 1024);
1633 
1635  if (ret != 0)
1638  return ret;
1639 }
static void journal_destroy_caches(void)
Definition: replay.c:1621
int ret
static void jbd_create_debugfs_entry(void)
Definition: replay.c:1573
static int __init journal_init_caches(void)
Definition: replay.c:1609

◆ journal_init_caches()

static int __init journal_init_caches ( void  )
static

Definition at line 1609 of file replay.c.

1610 {
1611  int ret;
1612 
1614  if (ret == 0)
1616  if (ret == 0)
1618  return ret;
1619 }
int __init journal_init_revoke_caches(void)
Definition: revoke.c:170
static int journal_init_journal_head_cache(void)
Definition: replay.c:221
int ret
static int __init journal_init_handle_cache(void)
Definition: replay.c:1585

Referenced by journal_init().

◆ journal_init_common()

static journal_t* journal_init_common ( void  )
static

Definition at line 547 of file replay.c.

548 {
549  journal_t *journal;
550  int err;
551 
552  journal = kzalloc(sizeof(*journal), GFP_KERNEL);
553  if (!journal)
554  goto fail;
555 
556  init_waitqueue_head(&journal->j_wait_transaction_locked);
557  init_waitqueue_head(&journal->j_wait_logspace);
558  init_waitqueue_head(&journal->j_wait_done_commit);
559  init_waitqueue_head(&journal->j_wait_checkpoint);
560  init_waitqueue_head(&journal->j_wait_commit);
561  init_waitqueue_head(&journal->j_wait_updates);
562  mutex_init(&journal->j_barrier);
563  mutex_init(&journal->j_checkpoint_mutex);
564  jbd_lock_init(&journal->j_revoke_lock);
565  jbd_lock_init(&journal->j_list_lock);
566  jbd_lock_init(&journal->j_state_lock);
567 
568  journal->j_commit_interval = (HZ * JBD_DEFAULT_MAX_COMMIT_AGE);
569 
570  /* The journal is marked for error until we succeed with recovery! */
571  journal->j_flags = JFS_ABORT;
572 
573  /* Set up a default-sized revoke table for the new mount. */
574  err = journal_init_revoke(journal, JOURNAL_REVOKE_DEFAULT_HASH);
575  if (err) {
576  kfree(journal);
577  goto fail;
578  }
579  return journal;
580 fail:
581  return NULL;
582 }
int journal_init_revoke(journal_t *journal, int hash_size)
Definition: revoke.c:201
#define GFP_KERNEL
Definition: module.h:658
#define HZ
Definition: hardware.c:32
#define mutex_init(m, a)
Definition: reentrant.h:127
smooth NULL
Definition: ftsmooth.c:416
#define err(...)
void * kzalloc(int size, int flags)
Definition: linux.c:34
void init_waitqueue_head(wait_queue_head_t *q)
Definition: linux.c:115
void kfree(const void *)

Referenced by journal_init_inode().

◆ journal_init_handle_cache()

static int __init journal_init_handle_cache ( void  )
static

Definition at line 1585 of file replay.c.

1586 {
1587  jbd_handle_cache = kmem_cache_create("journal_handle",
1588  sizeof(handle_t),
1589  0, /* offset */
1590  SLAB_TEMPORARY, /* flags */
1591  NULL); /* ctor */
1592  if (jbd_handle_cache == NULL) {
1593  printk(KERN_EMERG "JBD: failed to create handle cache\n");
1594  return -ENOMEM;
1595  }
1596  return 0;
1597 }
kmem_cache_t * kmem_cache_create(const char *name, size_t size, size_t offset, unsigned long flags, kmem_cache_cb_t ctor)
Definition: linux.c:48
Definition: arc.h:48
smooth NULL
Definition: ftsmooth.c:416
#define KERN_EMERG
Definition: module.h:220
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
struct kmem_cache * jbd_handle_cache
Definition: replay.c:1583
#define SLAB_TEMPORARY
Definition: module.h:1123

Referenced by journal_init_caches().

◆ journal_init_inode()

journal_t* journal_init_inode ( struct inode inode)

journal_t * journal_init_inode () - creates a journal which maps to a inode. @inode: An inode to create the journal in

journal_init_inode creates a journal which maps an on-disk inode as the journal. The inode must exist already, must support bmap() and must have all data blocks preallocated.

Definition at line 592 of file replay.c.

593 {
594  struct buffer_head *bh;
595  journal_t *journal = journal_init_common();
596  int err;
597  int n;
598  unsigned long blocknr;
599 
600  if (!journal)
601  return NULL;
602 
603  journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev;
604  journal->j_inode = inode;
605  jbd_debug(1,
606  "journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n",
607  journal, inode->i_sb->s_id, inode->i_ino,
608  (s64) inode->i_size,
609  inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize);
610 
611  journal->j_maxlen = (unsigned int)(inode->i_size >> inode->i_sb->s_blocksize_bits);
612  journal->j_blocksize = inode->i_sb->s_blocksize;
613 
614  /* journal descriptor can store up to n blocks -bzzz */
615  n = journal->j_blocksize / sizeof(journal_block_tag_t);
616  journal->j_wbufsize = n;
617  journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
618  if (!journal->j_wbuf) {
619  printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
620  __FUNCTION__);
621 
622  J_ASSERT(journal->j_revoke != NULL);
623  if (journal->j_revoke)
624  journal_destroy_revoke(journal);
625 
626  kfree(journal);
627  return NULL;
628  }
629 
630  err = journal_bmap(journal, 0, &blocknr);
631  /* If that failed, give up */
632  if (err) {
633  printk(KERN_ERR "%s: Cannnot locate journal superblock\n",
634  __FUNCTION__);
635 
636  J_ASSERT(journal->j_revoke != NULL);
637  if (journal->j_revoke)
638  journal_destroy_revoke(journal);
639  J_ASSERT(journal->j_wbuf != NULL);
640  kfree(journal->j_wbuf);
641  kfree(journal);
642  return NULL;
643  }
644 
645  bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
646  J_ASSERT(bh != NULL);
647  journal->j_sb_buffer = bh;
648  journal->j_superblock = (journal_superblock_t *)bh->b_data;
649 
650  return journal;
651 }
__s64 s64
Definition: types.h:36
GLdouble n
Definition: glext.h:7729
#define GFP_KERNEL
Definition: module.h:658
static journal_t * journal_init_common(void)
Definition: replay.c:547
struct buffer_head * __getblk(struct block_device *bdev, sector_t block, unsigned long size)
Definition: linux.c:791
Definition: fs.h:78
smooth NULL
Definition: ftsmooth.c:416
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
loff_t i_size
Definition: fs.h:80
#define KERN_ERR
Definition: module.h:223
int journal_bmap(journal_t *journal, unsigned long blocknr, unsigned long *retp)
Definition: replay.c:484
#define err(...)
__u32 i_ino
Definition: fs.h:79
char * b_data
Definition: module.h:725
void * kmalloc(size_t, int)
struct journal_block_tag_s journal_block_tag_t
struct super_block * i_sb
Definition: fs.h:96
#define __FUNCTION__
Definition: types.h:112
void journal_destroy_revoke(journal_t *journal)
Definition: revoke.c:271
void kfree(const void *)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by Ext2RecoverJournal().

◆ journal_init_journal_head_cache()

static int journal_init_journal_head_cache ( void  )
static

Definition at line 221 of file replay.c.

222 {
223  int retval;
224 
225  J_ASSERT(journal_head_cache == 0);
226  journal_head_cache = kmem_cache_create("journal_head",
227  sizeof(struct journal_head),
228  0, /* offset */
229  SLAB_TEMPORARY, /* flags */
230  NULL); /* ctor */
231  retval = 0;
232  if (journal_head_cache == 0) {
233  retval = -ENOMEM;
234  printk(KERN_EMERG "JBD: no memory for journal_head cache\n");
235  }
236  return retval;
237 }
kmem_cache_t * kmem_cache_create(const char *name, size_t size, size_t offset, unsigned long flags, kmem_cache_cb_t ctor)
Definition: linux.c:48
Definition: arc.h:48
smooth NULL
Definition: ftsmooth.c:416
#define KERN_EMERG
Definition: module.h:220
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
#define SLAB_TEMPORARY
Definition: module.h:1123
static struct kmem_cache * journal_head_cache
Definition: replay.c:216

Referenced by journal_init_caches().

◆ journal_load()

int journal_load ( journal_t *  journal)

int journal_load() - Read journal from disk. @journal: Journal to act on.

Given a journal_t structure which tells us which disk blocks contain a journal, read the journal from disk to initialise the in-memory structures.

Definition at line 1121 of file replay.c.

1122 {
1123  int err;
1125 
1126  err = load_superblock(journal);
1127  if (err)
1128  return err;
1129 
1130  sb = journal->j_superblock;
1131  /* If this is a V2 superblock, then we have to check the
1132  * features flags on it. */
1133 
1134  if (journal->j_format_version >= 2) {
1135  if ((sb->s_feature_ro_compat &
1137  (sb->s_feature_incompat &
1140  "JBD: Unrecognised features on journal\n");
1141  return -EINVAL;
1142  }
1143  }
1144 
1145  /* Let the recovery code check whether it needs to recover any
1146  * data from the journal. */
1147  if (journal_recover(journal))
1148  goto recovery_error;
1149 
1150  /* OK, we've finished with the dynamic journal bits:
1151  * reinitialise the dynamic contents of the superblock in memory
1152  * and reset them on disk. */
1153  if (journal_reset(journal))
1154  goto recovery_error;
1155 
1156  journal->j_flags &= ~JFS_ABORT;
1157  journal->j_flags |= JFS_LOADED;
1158  return 0;
1159 
1160 recovery_error:
1161  printk (KERN_WARNING "JBD: recovery failed\n");
1162  return -EIO;
1163 }
#define cpu_to_be32
Definition: module.h:154
superblock * sb
Definition: btrfs.c:3952
Definition: arc.h:39
#define KERN_WARNING
Definition: module.h:224
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
#define JFS_KNOWN_ROCOMPAT_FEATURES
Definition: jbd.h:275
int journal_recover(journal_t *journal)
Definition: recovery.c:225
static int load_superblock(journal_t *journal)
Definition: replay.c:931
#define err(...)
Definition: arc.h:40
static int journal_reset(journal_t *journal)
Definition: replay.c:1087
#define JFS_KNOWN_INCOMPAT_FEATURES
Definition: jbd.h:276

Referenced by Ext2RecoverJournal().

◆ journal_next_log_block()

int journal_next_log_block ( journal_t *  journal,
unsigned long retp 
)

Definition at line 461 of file replay.c.

462 {
463  unsigned long blocknr;
464 
465  jbd_lock(&journal->j_state_lock);
466  J_ASSERT(journal->j_free > 1);
467 
468  blocknr = journal->j_head;
469  journal->j_head++;
470  journal->j_free--;
471  if (journal->j_head == journal->j_last)
472  journal->j_head = journal->j_first;
473  jbd_unlock(&journal->j_state_lock);
474  return journal_bmap(journal, blocknr, retp);
475 }
int journal_bmap(journal_t *journal, unsigned long blocknr, unsigned long *retp)
Definition: replay.c:484

Referenced by journal_get_descriptor_buffer().

◆ journal_put_journal_head()

void journal_put_journal_head ( struct journal_head jh)

Definition at line 443 of file replay.c.

444 {
445  struct buffer_head *bh = jh2bh(jh);
446 
447  jbd_lock_bh_journal_head(bh);
448  J_ASSERT_JH(jh, jh->b_jcount > 0);
449  --jh->b_jcount;
450  if (!jh->b_jcount && !jh->b_transaction) {
452  __brelse(bh);
453  }
454  jbd_unlock_bh_journal_head(bh);
455 }
transaction_t * b_transaction
Definition: journal-head.h:61
void __brelse(struct buffer_head *)
Definition: linux.c:800
static void __journal_remove_journal_head(struct buffer_head *bh)
Definition: replay.c:381

◆ journal_release_buffer()

void journal_release_buffer ( handle_t handle,
struct buffer_head bh 
)

Definition at line 1425 of file replay.c.

1426 {
1427  BUFFER_TRACE(bh, "entry");
1428 }

Referenced by ext3_journal_release_buffer().

◆ journal_remove_journal_head()

void journal_remove_journal_head ( struct buffer_head bh)

Definition at line 432 of file replay.c.

433 {
434  jbd_lock_bh_journal_head(bh);
436  jbd_unlock_bh_journal_head(bh);
437 }
static void __journal_remove_journal_head(struct buffer_head *bh)
Definition: replay.c:381

Referenced by __dispose_buffer(), and journal_forget().

◆ journal_reset()

static int journal_reset ( journal_t *  journal)
static

Definition at line 1087 of file replay.c.

1088 {
1089  journal_superblock_t *sb = journal->j_superblock;
1090  unsigned long first, last;
1091 
1092  first = be32_to_cpu(sb->s_first);
1093  last = be32_to_cpu(sb->s_maxlen);
1094 
1095  journal->j_first = first;
1096  journal->j_last = last;
1097 
1098  journal->j_head = first;
1099  journal->j_tail = first;
1100  journal->j_free = last - first;
1101 
1102  journal->j_tail_sequence = journal->j_transaction_sequence;
1103  journal->j_commit_sequence = journal->j_transaction_sequence - 1;
1104  journal->j_commit_request = journal->j_commit_sequence;
1105 
1106  journal->j_max_transaction_buffers = journal->j_maxlen / 4;
1107 
1108  /* Add the dynamic fields and write it to disk. */
1109  journal_update_superblock(journal, 1);
1110  return 0;
1111 }
#define be32_to_cpu
Definition: module.h:155
POINT last
Definition: font.c:46
superblock * sb
Definition: btrfs.c:3952
void journal_update_superblock(journal_t *journal, int wait)
Definition: replay.c:1030
const GLint * first
Definition: glext.h:5794

Referenced by journal_load().

◆ journal_set_features()

int journal_set_features ( journal_t *  journal,
unsigned long  compat,
unsigned long  ro,
unsigned long  incompat 
)

int journal_set_features () - Mark a given journal feature in the superblock @journal: Journal to act on. @compat: bitmask of compatible features @ro: bitmask of features that force read-only mount @incompat: bitmask of incompatible features

Mark a given journal feature as present on the superblock. Returns true if the requested features could be set.

Definition at line 804 of file replay.c.

806 {
808 
809  if (journal_check_used_features(journal, compat, ro, incompat))
810  return 1;
811 
812  if (!journal_check_available_features(journal, compat, ro, incompat))
813  return 0;
814 
815  jbd_debug(1, "Setting new features 0x%lx/0x%lx/0x%lx\n",
816  compat, ro, incompat);
817 
818  sb = journal->j_superblock;
819 
820  sb->s_feature_compat |= cpu_to_be32(compat);
821  sb->s_feature_ro_compat |= cpu_to_be32(ro);
822  sb->s_feature_incompat |= cpu_to_be32(incompat);
823 
824  return 1;
825 }
#define cpu_to_be32
Definition: module.h:154
superblock * sb
Definition: btrfs.c:3952
int journal_check_available_features(journal_t *journal, unsigned long compat, unsigned long ro, unsigned long incompat)
Definition: replay.c:767
int journal_check_used_features(journal_t *journal, unsigned long compat, unsigned long ro, unsigned long incompat)
Definition: replay.c:736

◆ journal_unfile_buffer()

void journal_unfile_buffer ( journal_t *  journal,
struct journal_head jh 
)

Definition at line 1292 of file replay.c.

1293 {
1294  jbd_lock_bh_state(jh2bh(jh));
1295  jbd_lock(&journal->j_list_lock);
1297  jbd_unlock(&journal->j_list_lock);
1298  jbd_unlock_bh_state(jh2bh(jh));
1299 }
void __journal_unfile_buffer(struct journal_head *jh)
Definition: replay.c:1286

◆ journal_update_format()

int journal_update_format ( journal_t *  journal)

int journal_update_format () - Update on-disk journal structure. @journal: Journal to act on.

Given an initialised but unloaded journal struct, poke about in the on-disk structure to update it to the most recent supported version.

Definition at line 999 of file replay.c.

1000 {
1002  int err;
1003 
1004  err = journal_get_superblock(journal);
1005  if (err)
1006  return err;
1007 
1008  sb = journal->j_superblock;
1009 
1010  switch (be32_to_cpu(sb->s_header.h_blocktype)) {
1011  case JFS_SUPERBLOCK_V2:
1012  return 0;
1013  case JFS_SUPERBLOCK_V1:
1014  return journal_convert_superblock_v1(journal, sb);
1015  default:
1016  break;
1017  }
1018  return -EINVAL;
1019 }
#define be32_to_cpu
Definition: module.h:155
superblock * sb
Definition: btrfs.c:3952
Definition: arc.h:39
static int journal_convert_superblock_v1(journal_t *journal, journal_superblock_t *sb)
Definition: replay.c:827
static int journal_get_superblock(journal_t *journal)
Definition: replay.c:871
#define JFS_SUPERBLOCK_V2
Definition: jbd.h:172
#define JFS_SUPERBLOCK_V1
Definition: jbd.h:171
#define err(...)

◆ journal_update_superblock()

void journal_update_superblock ( journal_t *  journal,
int  wait 
)

void journal_update_superblock() - Update journal sb on disk. @journal: The journal to update. @wait: Set to '0' if you don't want to wait for IO completion.

Update a journal's dynamic superblock fields and write it to disk, optionally waiting for the IO to complete.

Definition at line 1030 of file replay.c.

1031 {
1032  journal_superblock_t *sb = journal->j_superblock;
1033  struct buffer_head *bh = journal->j_sb_buffer;
1034 
1035  /*
1036  * As a special case, if the on-disk copy is already marked as needing
1037  * no recovery (s_start == 0) and there are no outstanding transactions
1038  * in the filesystem, then we can safely defer the superblock update
1039  * until the next commit by setting JFS_FLUSHED. This avoids
1040  * attempting a write to a potential-readonly device.
1041  */
1042  if (sb->s_start == 0 && journal->j_tail_sequence ==
1043  journal->j_transaction_sequence) {
1044  jbd_debug(1,"JBD: Skipping superblock update on recovered sb "
1045  "(start %ld, seq %d, errno %d)\n",
1046  journal->j_tail, journal->j_tail_sequence,
1047  journal->j_errno);
1048  goto out;
1049  }
1050 
1051  jbd_lock(&journal->j_state_lock);
1052  jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n",
1053  journal->j_tail, journal->j_tail_sequence, journal->j_errno);
1054 
1055  sb->s_sequence = cpu_to_be32(journal->j_tail_sequence);
1056  sb->s_start = cpu_to_be32(journal->j_tail);
1057  sb->s_errno = cpu_to_be32(journal->j_errno);
1058  jbd_unlock(&journal->j_state_lock);
1059 
1060  BUFFER_TRACE(bh, "marking dirty");
1061  mark_buffer_dirty(bh);
1062  if (wait)
1063  sync_dirty_buffer(bh);
1064  else
1065  ll_rw_block(SWRITE, 1, &bh);
1066 
1067 out:
1068  /* If we have just flushed the log (by marking s_start==0), then
1069  * any future commit will have to be careful to update the
1070  * superblock again to re-record the true start of the log. */
1071 
1072  jbd_lock(&journal->j_state_lock);
1073  if (sb->s_start)
1074  journal->j_flags &= ~JFS_FLUSHED;
1075  else
1076  journal->j_flags |= JFS_FLUSHED;
1077  jbd_unlock(&journal->j_state_lock);
1078 }
#define cpu_to_be32
Definition: module.h:154
superblock * sb
Definition: btrfs.c:3952
void ll_rw_block(int, int, struct buffer_head *bh[])
Definition: linux.c:854
int sync_dirty_buffer(struct buffer_head *bh)
Definition: linux.c:890
static FILE * out
Definition: regtests2xml.c:44
void mark_buffer_dirty(struct buffer_head *bh)
Definition: linux.c:906
#define SWRITE
Definition: module.h:1168

Referenced by __journal_abort_soft(), journal_destroy(), journal_reset(), journal_wipe(), and journal_wipe_recovery().

◆ journal_wipe()

int journal_wipe ( journal_t *  journal,
int  write 
)

int journal_wipe() - Wipe journal contents @journal: Journal to act on. @write: flag (see below)

Wipe out all of the contents of a journal, safely. This will produce a warning if the journal contains any valid recovery information. Must be called between journal_init_*() and journal_load().

If 'write' is non-zero, then we wipe out the journal on disk; otherwise we merely suppress recovery.

Definition at line 964 of file replay.c.

965 {
967  int err = 0;
968 
969  J_ASSERT (!(journal->j_flags & JFS_LOADED));
970 
971  err = load_superblock(journal);
972  if (err)
973  return err;
974 
975  sb = journal->j_superblock;
976 
977  if (!journal->j_tail)
978  goto no_recovery;
979 
980  printk (KERN_WARNING "JBD: %s recovery information on journal\n",
981  write ? "Clearing" : "Ignoring");
982 
983  err = journal_skip_recovery(journal);
984  if (write)
985  journal_update_superblock(journal, 1);
986 
987 no_recovery:
988  return err;
989 }
superblock * sb
Definition: btrfs.c:3952
void journal_update_superblock(journal_t *journal, int wait)
Definition: replay.c:1030
#define write
Definition: acwin.h:73
#define KERN_WARNING
Definition: module.h:224
asmlinkage int printk(const char *fmt,...)
Definition: output.c:76
static int load_superblock(journal_t *journal)
Definition: replay.c:931
#define err(...)
int journal_skip_recovery(journal_t *journal)
Definition: recovery.c:282

◆ journal_wipe_recovery()

void journal_wipe_recovery ( journal_t *  journal)

wipe all journal data ...

Definition at line 659 of file replay.c.

660 {
661  /* We can now mark the journal as empty. */
662 
663  journal->j_tail = 0;
664  if (journal->j_sb_buffer) {
665  journal_update_superblock(journal, 0);
666  brelse(journal->j_sb_buffer);
667  journal->j_sb_buffer = NULL;
668  }
669 }
void journal_update_superblock(journal_t *journal, int wait)
Definition: replay.c:1030
static void brelse(struct buffer_head *bh)
Definition: module.h:945
smooth NULL
Definition: ftsmooth.c:416

Referenced by Ext2RecoverJournal().

◆ load_superblock()

static int load_superblock ( journal_t *  journal)
static

Definition at line 931 of file replay.c.

932 {
933  int err;
935 
936  err = journal_get_superblock(journal);
937  if (err)
938  return err;
939 
940  sb = journal->j_superblock;
941 
942  journal->j_tail_sequence = be32_to_cpu(sb->s_sequence);
943  journal->j_tail = be32_to_cpu(sb->s_start);
944  journal->j_first = be32_to_cpu(sb->s_first);
945  journal->j_last = be32_to_cpu(sb->s_maxlen);
946  journal->j_errno = be32_to_cpu(sb->s_errno);
947 
948  return 0;
949 }
#define be32_to_cpu
Definition: module.h:155
superblock * sb
Definition: btrfs.c:3952
static int journal_get_superblock(journal_t *journal)
Definition: replay.c:871
#define err(...)

Referenced by journal_load(), and journal_wipe().

◆ log_start_commit()

int log_start_commit ( journal_t *  journal,
tid_t  tid 
)

Definition at line 42 of file replay.c.

43 {
44  int ret;
45 
46  jbd_lock(&journal->j_state_lock);
47  ret = __log_start_commit(journal, tid);
48  jbd_unlock(&journal->j_state_lock);
49  return ret;
50 }
int __log_start_commit(journal_t *journal, tid_t target)
Definition: replay.c:21
int ret
static TfClientId tid

◆ module_exit()

module_exit ( journal_exit  )

◆ module_init()

module_init ( journal_init  )

◆ MODULE_LICENSE()

MODULE_LICENSE ( "GPL"  )

Variable Documentation

◆ jbd_handle_cache

struct kmem_cache* jbd_handle_cache = NULL

Definition at line 1583 of file replay.c.

Referenced by journal_destroy_handle_cache(), and journal_init_handle_cache().

◆ journal_head_cache