Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/revoke.c |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 3 | * |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 4 | * Written by Stephen C. Tweedie <sct@redhat.com>, 2000 |
| 5 | * |
| 6 | * Copyright 2000 Red Hat corp --- All Rights Reserved |
| 7 | * |
| 8 | * This file is part of the Linux kernel and is made available under |
| 9 | * the terms of the GNU General Public License, version 2, or at your |
| 10 | * option, any later version, incorporated herein by reference. |
| 11 | * |
| 12 | * Journal revoke routines for the generic filesystem journaling code; |
| 13 | * part of the ext2fs journaling system. |
| 14 | * |
| 15 | * Revoke is the mechanism used to prevent old log records for deleted |
| 16 | * metadata from being replayed on top of newer data using the same |
| 17 | * blocks. The revoke mechanism is used in two separate places: |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 18 | * |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 19 | * + Commit: during commit we write the entire list of the current |
| 20 | * transaction's revoked blocks to the journal |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 21 | * |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 22 | * + Recovery: during recovery we record the transaction ID of all |
| 23 | * revoked blocks. If there are multiple revoke records in the log |
| 24 | * for a single block, only the last one counts, and if there is a log |
| 25 | * entry for a block beyond the last revoke, then that log entry still |
| 26 | * gets replayed. |
| 27 | * |
| 28 | * We can get interactions between revokes and new log data within a |
| 29 | * single transaction: |
| 30 | * |
| 31 | * Block is revoked and then journaled: |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 32 | * The desired end result is the journaling of the new block, so we |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 33 | * cancel the revoke before the transaction commits. |
| 34 | * |
| 35 | * Block is journaled and then revoked: |
Theodore Ts'o | 725c474 | 2001-06-08 11:55:44 +0000 | [diff] [blame] | 36 | * The revoke must take precedence over the write of the block, so we |
| 37 | * need either to cancel the journal entry or to write the revoke |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 38 | * later in the log than the log block. In this case, we choose the |
Theodore Ts'o | 725c474 | 2001-06-08 11:55:44 +0000 | [diff] [blame] | 39 | * latter: journaling a block cancels any revoke record for that block |
| 40 | * in the current transaction, so any revoke for that block in the |
| 41 | * transaction must have happened after the block was journaled and so |
| 42 | * the revoke must take precedence. |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 43 | * |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 44 | * Block is revoked and then written as data: |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 45 | * The data write is allowed to succeed, but the revoke is _not_ |
| 46 | * cancelled. We still need to prevent old log records from |
| 47 | * overwriting the new data. We don't even need to clear the revoke |
| 48 | * bit here. |
| 49 | * |
| 50 | * Revoke information on buffers is a tri-state value: |
| 51 | * |
| 52 | * RevokeValid clear: no cached revoke status, need to look it up |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 53 | * RevokeValid set, Revoked clear: |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 54 | * buffer has not been revoked, and cancel_revoke |
| 55 | * need do nothing. |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 56 | * RevokeValid set, Revoked set: |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 57 | * buffer has been revoked. |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 58 | */ |
| 59 | |
| 60 | #ifndef __KERNEL__ |
Theodore Ts'o | d1154eb | 2011-09-18 17:34:37 -0400 | [diff] [blame] | 61 | #include "config.h" |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 62 | #include "jfs_user.h" |
| 63 | #else |
| 64 | #include <linux/sched.h> |
| 65 | #include <linux/fs.h> |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 66 | #include <linux/jbd.h> |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 67 | #include <linux/errno.h> |
| 68 | #include <linux/slab.h> |
| 69 | #include <linux/locks.h> |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 70 | #include <linux/list.h> |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 71 | #include <linux/smp_lock.h> |
| 72 | #include <linux/init.h> |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 73 | #endif |
| 74 | |
Theodore Ts'o | 1911bf1 | 2008-07-13 08:04:36 -0400 | [diff] [blame] | 75 | static lkmem_cache_t *revoke_record_cache; |
| 76 | static lkmem_cache_t *revoke_table_cache; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 77 | |
| 78 | /* Each revoke record represents one single revoked block. During |
| 79 | journal replay, this involves recording the transaction ID of the |
| 80 | last transaction to revoke this block. */ |
| 81 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 82 | struct jbd_revoke_record_s |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 83 | { |
| 84 | struct list_head hash; |
| 85 | tid_t sequence; /* Used for recovery only */ |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 86 | unsigned long blocknr; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | |
| 90 | /* The revoke table is just a simple hash table of revoke records. */ |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 91 | struct jbd_revoke_table_s |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 92 | { |
| 93 | /* It is conceivable that we might want a larger hash table |
| 94 | * for recovery. Must be a power of two. */ |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 95 | int hash_size; |
| 96 | int hash_shift; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 97 | struct list_head *hash_table; |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | #ifdef __KERNEL__ |
| 102 | static void write_one_revoke_record(journal_t *, transaction_t *, |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 103 | struct journal_head **, int *, |
| 104 | struct jbd_revoke_record_s *); |
| 105 | static void flush_descriptor(journal_t *, struct journal_head *, int); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 106 | #endif |
| 107 | |
| 108 | /* Utility functions to maintain the revoke table */ |
| 109 | |
| 110 | /* Borrowed from buffer.c: this is a tried and tested block hash function */ |
| 111 | static inline int hash(journal_t *journal, unsigned long block) |
| 112 | { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 113 | struct jbd_revoke_table_s *table = journal->j_revoke; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 114 | int hash_shift = table->hash_shift; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 115 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 116 | return ((block << (hash_shift - 6)) ^ |
| 117 | (block >> 13) ^ |
| 118 | (block << (hash_shift - 12))) & (table->hash_size - 1); |
| 119 | } |
| 120 | |
Theodore Ts'o | 3e69906 | 2002-10-13 23:56:28 -0400 | [diff] [blame] | 121 | static int insert_revoke_hash(journal_t *journal, unsigned long blocknr, |
| 122 | tid_t seq) |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 123 | { |
| 124 | struct list_head *hash_list; |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 125 | struct jbd_revoke_record_s *record; |
| 126 | |
Theodore Ts'o | 546a1ff | 2002-03-07 23:52:56 -0500 | [diff] [blame] | 127 | #ifdef __KERNEL__ |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 128 | repeat: |
Theodore Ts'o | 546a1ff | 2002-03-07 23:52:56 -0500 | [diff] [blame] | 129 | #endif |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 130 | record = kmem_cache_alloc(revoke_record_cache, GFP_NOFS); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 131 | if (!record) |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 132 | goto oom; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 133 | |
| 134 | record->sequence = seq; |
| 135 | record->blocknr = blocknr; |
| 136 | hash_list = &journal->j_revoke->hash_table[hash(journal, blocknr)]; |
| 137 | list_add(&record->hash, hash_list); |
| 138 | return 0; |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 139 | |
| 140 | oom: |
| 141 | #ifdef __KERNEL__ |
| 142 | if (!journal_oom_retry) |
| 143 | return -ENOMEM; |
| 144 | jbd_debug(1, "ENOMEM in " __FUNCTION__ ", retrying.\n"); |
| 145 | current->policy |= SCHED_YIELD; |
| 146 | schedule(); |
| 147 | goto repeat; |
| 148 | #else |
| 149 | return -ENOMEM; |
| 150 | #endif |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* Find a revoke record in the journal's hash table. */ |
| 154 | |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 155 | static struct jbd_revoke_record_s *find_revoke_record(journal_t *journal, |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 156 | unsigned long blocknr) |
| 157 | { |
| 158 | struct list_head *hash_list; |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 159 | struct jbd_revoke_record_s *record; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 160 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 161 | hash_list = &journal->j_revoke->hash_table[hash(journal, blocknr)]; |
| 162 | |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 163 | record = (struct jbd_revoke_record_s *) hash_list->next; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 164 | while (&(record->hash) != hash_list) { |
| 165 | if (record->blocknr == blocknr) |
| 166 | return record; |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 167 | record = (struct jbd_revoke_record_s *) record->hash.next; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 168 | } |
| 169 | return NULL; |
| 170 | } |
| 171 | |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 172 | int __init journal_init_revoke_caches(void) |
| 173 | { |
| 174 | revoke_record_cache = kmem_cache_create("revoke_record", |
| 175 | sizeof(struct jbd_revoke_record_s), |
| 176 | 0, SLAB_HWCACHE_ALIGN, NULL, NULL); |
| 177 | if (revoke_record_cache == 0) |
| 178 | return -ENOMEM; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 179 | |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 180 | revoke_table_cache = kmem_cache_create("revoke_table", |
| 181 | sizeof(struct jbd_revoke_table_s), |
| 182 | 0, 0, NULL, NULL); |
| 183 | if (revoke_table_cache == 0) { |
| 184 | kmem_cache_destroy(revoke_record_cache); |
| 185 | revoke_record_cache = NULL; |
| 186 | return -ENOMEM; |
| 187 | } |
| 188 | return 0; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 189 | } |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 190 | |
| 191 | void journal_destroy_revoke_caches(void) |
| 192 | { |
| 193 | kmem_cache_destroy(revoke_record_cache); |
| 194 | revoke_record_cache = 0; |
| 195 | kmem_cache_destroy(revoke_table_cache); |
| 196 | revoke_table_cache = 0; |
| 197 | } |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 198 | |
| 199 | /* Initialise the revoke table for a given journal to a given size. */ |
| 200 | |
| 201 | int journal_init_revoke(journal_t *journal, int hash_size) |
| 202 | { |
| 203 | int shift, tmp; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 204 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 205 | J_ASSERT (journal->j_revoke == NULL); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 206 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 207 | journal->j_revoke = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL); |
| 208 | if (!journal->j_revoke) |
| 209 | return -ENOMEM; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 210 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 211 | /* Check that the hash_size is a power of two */ |
| 212 | J_ASSERT ((hash_size & (hash_size-1)) == 0); |
| 213 | |
| 214 | journal->j_revoke->hash_size = hash_size; |
| 215 | |
| 216 | shift = 0; |
| 217 | tmp = hash_size; |
| 218 | while((tmp >>= 1UL) != 0UL) |
| 219 | shift++; |
| 220 | journal->j_revoke->hash_shift = shift; |
| 221 | |
| 222 | journal->j_revoke->hash_table = |
| 223 | kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL); |
| 224 | if (!journal->j_revoke->hash_table) { |
| 225 | kmem_cache_free(revoke_table_cache, journal->j_revoke); |
| 226 | journal->j_revoke = NULL; |
| 227 | return -ENOMEM; |
| 228 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 229 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 230 | for (tmp = 0; tmp < hash_size; tmp++) |
| 231 | INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 232 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | /* Destoy a journal's revoke table. The table must already be empty! */ |
| 237 | |
| 238 | void journal_destroy_revoke(journal_t *journal) |
| 239 | { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 240 | struct jbd_revoke_table_s *table; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 241 | struct list_head *hash_list; |
| 242 | int i; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 243 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 244 | table = journal->j_revoke; |
| 245 | if (!table) |
| 246 | return; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 247 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 248 | for (i=0; i<table->hash_size; i++) { |
| 249 | hash_list = &table->hash_table[i]; |
| 250 | J_ASSERT (list_empty(hash_list)); |
| 251 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 252 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 253 | kfree(table->hash_table); |
| 254 | kmem_cache_free(revoke_table_cache, table); |
| 255 | journal->j_revoke = NULL; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | #ifdef __KERNEL__ |
| 260 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 261 | /* |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 262 | * journal_revoke: revoke a given buffer_head from the journal. This |
| 263 | * prevents the block from being replayed during recovery if we take a |
| 264 | * crash after this current transaction commits. Any subsequent |
| 265 | * metadata writes of the buffer in this transaction cancel the |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 266 | * revoke. |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 267 | * |
| 268 | * Note that this call may block --- it is up to the caller to make |
| 269 | * sure that there are no further calls to journal_write_metadata |
| 270 | * before the revoke is complete. In ext3, this implies calling the |
| 271 | * revoke before clearing the block bitmap when we are deleting |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 272 | * metadata. |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 273 | * |
| 274 | * Revoke performs a journal_forget on any buffer_head passed in as a |
| 275 | * parameter, but does _not_ forget the buffer_head if the bh was only |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 276 | * found implicitly. |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 277 | * |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 278 | * bh_in may not be a journalled buffer - it may have come off |
| 279 | * the hash tables without an attached journal_head. |
| 280 | * |
| 281 | * If bh_in is non-zero, journal_revoke() will decrement its b_count |
| 282 | * by one. |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 283 | */ |
| 284 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 285 | int journal_revoke(handle_t *handle, unsigned long blocknr, |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 286 | struct buffer_head *bh_in) |
| 287 | { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 288 | struct buffer_head *bh = NULL; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 289 | journal_t *journal; |
| 290 | kdev_t dev; |
| 291 | int err; |
| 292 | |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 293 | if (bh_in) |
| 294 | BUFFER_TRACE(bh_in, "enter"); |
| 295 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 296 | journal = handle->h_transaction->t_journal; |
Theodore Ts'o | 1f73503 | 2001-03-29 19:00:50 +0000 | [diff] [blame] | 297 | if (!journal_set_features(journal, 0, 0, JFS_FEATURE_INCOMPAT_REVOKE)){ |
| 298 | J_ASSERT (!"Cannot set revoke feature!"); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 299 | return -EINVAL; |
Theodore Ts'o | 1f73503 | 2001-03-29 19:00:50 +0000 | [diff] [blame] | 300 | } |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 301 | |
| 302 | dev = journal->j_fs_dev; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 303 | bh = bh_in; |
| 304 | |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 305 | if (!bh) { |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 306 | bh = get_hash_table(dev, blocknr, journal->j_blocksize); |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 307 | if (bh) |
| 308 | BUFFER_TRACE(bh, "found on hash"); |
| 309 | } |
| 310 | #ifdef JBD_EXPENSIVE_CHECKING |
| 311 | else { |
| 312 | struct buffer_head *bh2; |
| 313 | |
| 314 | /* If there is a different buffer_head lying around in |
| 315 | * memory anywhere... */ |
| 316 | bh2 = get_hash_table(dev, blocknr, journal->j_blocksize); |
| 317 | if (bh2) { |
| 318 | /* ... and it has RevokeValid status... */ |
| 319 | if ((bh2 != bh) && |
| 320 | test_bit(BH_RevokeValid, &bh2->b_state)) |
| 321 | /* ...then it better be revoked too, |
| 322 | * since it's illegal to create a revoke |
| 323 | * record against a buffer_head which is |
| 324 | * not marked revoked --- that would |
| 325 | * risk missing a subsequent revoke |
| 326 | * cancel. */ |
| 327 | J_ASSERT_BH(bh2, test_bit(BH_Revoked, & |
| 328 | bh2->b_state)); |
| 329 | __brelse(bh2); |
| 330 | } |
| 331 | } |
| 332 | #endif |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 333 | |
| 334 | /* We really ought not ever to revoke twice in a row without |
| 335 | first having the revoke cancelled: it's illegal to free a |
| 336 | block twice without allocating it in between! */ |
| 337 | if (bh) { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 338 | J_ASSERT_BH(bh, !test_bit(BH_Revoked, &bh->b_state)); |
| 339 | set_bit(BH_Revoked, &bh->b_state); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 340 | set_bit(BH_RevokeValid, &bh->b_state); |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 341 | if (bh_in) { |
| 342 | BUFFER_TRACE(bh_in, "call journal_forget"); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 343 | journal_forget(handle, bh_in); |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 344 | } else { |
| 345 | BUFFER_TRACE(bh, "call brelse"); |
| 346 | __brelse(bh); |
| 347 | } |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | lock_journal(journal); |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 351 | jbd_debug(2, "insert revoke for block %lu, bh_in=%p\n", blocknr, bh_in); |
| 352 | err = insert_revoke_hash(journal, blocknr, |
| 353 | handle->h_transaction->t_tid); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 354 | unlock_journal(journal); |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 355 | BUFFER_TRACE(bh_in, "exit"); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 356 | return err; |
| 357 | } |
| 358 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 359 | /* |
| 360 | * Cancel an outstanding revoke. For use only internally by the |
| 361 | * journaling code (called from journal_get_write_access). |
| 362 | * |
| 363 | * We trust the BH_Revoked bit on the buffer if the buffer is already |
| 364 | * being journaled: if there is no revoke pending on the buffer, then we |
| 365 | * don't do anything here. |
| 366 | * |
| 367 | * This would break if it were possible for a buffer to be revoked and |
| 368 | * discarded, and then reallocated within the same transaction. In such |
| 369 | * a case we would have lost the revoked bit, but when we arrived here |
| 370 | * the second time we would still have a pending revoke to cancel. So, |
| 371 | * do not trust the Revoked bit on buffers unless RevokeValid is also |
| 372 | * set. |
| 373 | * |
| 374 | * The caller must have the journal locked. |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 375 | */ |
| 376 | int journal_cancel_revoke(handle_t *handle, struct journal_head *jh) |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 377 | { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 378 | struct jbd_revoke_record_s *record; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 379 | journal_t *journal = handle->h_transaction->t_journal; |
| 380 | int need_cancel; |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 381 | int did_revoke = 0; /* akpm: debug */ |
| 382 | struct buffer_head *bh = jh2bh(jh); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 383 | |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 384 | jbd_debug(4, "journal_head %p, cancelling revoke\n", jh); |
| 385 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 386 | /* Is the existing Revoke bit valid? If so, we trust it, and |
| 387 | * only perform the full cancel if the revoke bit is set. If |
| 388 | * not, we can't trust the revoke bit, and we need to do the |
| 389 | * full search for a revoke record. */ |
| 390 | if (test_and_set_bit(BH_RevokeValid, &bh->b_state)) |
| 391 | need_cancel = (test_and_clear_bit(BH_Revoked, &bh->b_state)); |
| 392 | else { |
| 393 | need_cancel = 1; |
| 394 | clear_bit(BH_Revoked, &bh->b_state); |
| 395 | } |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 396 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 397 | if (need_cancel) { |
| 398 | record = find_revoke_record(journal, bh->b_blocknr); |
| 399 | if (record) { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 400 | jbd_debug(4, "cancelled existing revoke on " |
| 401 | "blocknr %lu\n", bh->b_blocknr); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 402 | list_del(&record->hash); |
| 403 | kmem_cache_free(revoke_record_cache, record); |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 404 | did_revoke = 1; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 405 | } |
| 406 | } |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 407 | |
| 408 | #ifdef JBD_EXPENSIVE_CHECKING |
| 409 | /* There better not be one left behind by now! */ |
| 410 | record = find_revoke_record(journal, bh->b_blocknr); |
| 411 | J_ASSERT_JH(jh, record == NULL); |
| 412 | #endif |
| 413 | |
| 414 | /* Finally, have we just cleared revoke on an unhashed |
| 415 | * buffer_head? If so, we'd better make sure we clear the |
| 416 | * revoked status on any hashed alias too, otherwise the revoke |
| 417 | * state machine will get very upset later on. */ |
| 418 | if (need_cancel && !bh->b_pprev) { |
| 419 | struct buffer_head *bh2; |
| 420 | bh2 = get_hash_table(bh->b_dev, bh->b_blocknr, bh->b_size); |
| 421 | if (bh2) { |
| 422 | clear_bit(BH_Revoked, &bh2->b_state); |
| 423 | __brelse(bh2); |
| 424 | } |
| 425 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 426 | |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 427 | return did_revoke; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | |
| 431 | /* |
| 432 | * Write revoke records to the journal for all entries in the current |
| 433 | * revoke hash, deleting the entries as we go. |
| 434 | * |
| 435 | * Called with the journal lock held. |
| 436 | */ |
| 437 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 438 | void journal_write_revoke_records(journal_t *journal, |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 439 | transaction_t *transaction) |
| 440 | { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 441 | struct journal_head *descriptor; |
| 442 | struct jbd_revoke_record_s *record; |
| 443 | struct jbd_revoke_table_s *revoke; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 444 | struct list_head *hash_list; |
Theodore Ts'o | 1f73503 | 2001-03-29 19:00:50 +0000 | [diff] [blame] | 445 | int i, offset, count; |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 446 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 447 | descriptor = NULL; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 448 | offset = 0; |
Theodore Ts'o | 1f73503 | 2001-03-29 19:00:50 +0000 | [diff] [blame] | 449 | count = 0; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 450 | revoke = journal->j_revoke; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 451 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 452 | for (i = 0; i < revoke->hash_size; i++) { |
| 453 | hash_list = &revoke->hash_table[i]; |
| 454 | |
| 455 | while (!list_empty(hash_list)) { |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 456 | record = (struct jbd_revoke_record_s *) |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 457 | hash_list->next; |
| 458 | write_one_revoke_record(journal, transaction, |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 459 | &descriptor, &offset, |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 460 | record); |
Theodore Ts'o | 1f73503 | 2001-03-29 19:00:50 +0000 | [diff] [blame] | 461 | count++; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 462 | list_del(&record->hash); |
| 463 | kmem_cache_free(revoke_record_cache, record); |
| 464 | } |
| 465 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 466 | if (descriptor) |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 467 | flush_descriptor(journal, descriptor, offset); |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 468 | jbd_debug(1, "Wrote %d revoke records\n", count); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 471 | /* |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 472 | * Write out one revoke record. We need to create a new descriptor |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 473 | * block if the old one is full or if we have not already created one. |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 474 | */ |
| 475 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 476 | static void write_one_revoke_record(journal_t *journal, |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 477 | transaction_t *transaction, |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 478 | struct journal_head **descriptorp, |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 479 | int *offsetp, |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 480 | struct jbd_revoke_record_s *record) |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 481 | { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 482 | struct journal_head *descriptor; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 483 | int offset; |
| 484 | journal_header_t *header; |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 485 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 486 | /* If we are already aborting, this all becomes a noop. We |
| 487 | still need to go round the loop in |
| 488 | journal_write_revoke_records in order to free all of the |
| 489 | revoke records: only the IO to the journal is omitted. */ |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 490 | if (is_journal_aborted(journal)) |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 491 | return; |
| 492 | |
| 493 | descriptor = *descriptorp; |
| 494 | offset = *offsetp; |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 495 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 496 | /* Make sure we have a descriptor with space left for the record */ |
| 497 | if (descriptor) { |
| 498 | if (offset == journal->j_blocksize) { |
| 499 | flush_descriptor(journal, descriptor, offset); |
| 500 | descriptor = NULL; |
| 501 | } |
| 502 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 503 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 504 | if (!descriptor) { |
| 505 | descriptor = journal_get_descriptor_buffer(journal); |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 506 | if (!descriptor) |
| 507 | return; |
| 508 | header = (journal_header_t *) &jh2bh(descriptor)->b_data[0]; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 509 | header->h_magic = htonl(JFS_MAGIC_NUMBER); |
| 510 | header->h_blocktype = htonl(JFS_REVOKE_BLOCK); |
| 511 | header->h_sequence = htonl(transaction->t_tid); |
| 512 | |
| 513 | /* Record it so that we can wait for IO completion later */ |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 514 | JBUFFER_TRACE(descriptor, "file as BJ_LogCtl"); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 515 | journal_file_buffer(descriptor, transaction, BJ_LogCtl); |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 516 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 517 | offset = sizeof(journal_revoke_header_t); |
| 518 | *descriptorp = descriptor; |
| 519 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 520 | |
| 521 | * ((unsigned int *)(&jh2bh(descriptor)->b_data[offset])) = |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 522 | htonl(record->blocknr); |
| 523 | offset += 4; |
| 524 | *offsetp = offset; |
| 525 | } |
| 526 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 527 | /* |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 528 | * Flush a revoke descriptor out to the journal. If we are aborting, |
| 529 | * this is a noop; otherwise we are generating a buffer which needs to |
| 530 | * be waited for during commit, so it has to go onto the appropriate |
| 531 | * journal buffer list. |
| 532 | */ |
| 533 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 534 | static void flush_descriptor(journal_t *journal, |
| 535 | struct journal_head *descriptor, |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 536 | int offset) |
| 537 | { |
| 538 | journal_revoke_header_t *header; |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 539 | |
| 540 | if (is_journal_aborted(journal)) { |
| 541 | JBUFFER_TRACE(descriptor, "brelse"); |
| 542 | __brelse(jh2bh(descriptor)); |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 543 | return; |
| 544 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 545 | |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 546 | header = (journal_revoke_header_t *) jh2bh(descriptor)->b_data; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 547 | header->r_count = htonl(offset); |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 548 | set_bit(BH_JWrite, &jh2bh(descriptor)->b_state); |
| 549 | { |
| 550 | struct buffer_head *bh = jh2bh(descriptor); |
| 551 | BUFFER_TRACE(bh, "write"); |
| 552 | ll_rw_block (WRITE, 1, &bh); |
| 553 | } |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | #endif |
| 557 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 558 | /* |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 559 | * Revoke support for recovery. |
| 560 | * |
| 561 | * Recovery needs to be able to: |
| 562 | * |
| 563 | * record all revoke records, including the tid of the latest instance |
| 564 | * of each revoke in the journal |
| 565 | * |
| 566 | * check whether a given block in a given transaction should be replayed |
| 567 | * (ie. has not been revoked by a revoke record in that or a subsequent |
| 568 | * transaction) |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 569 | * |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 570 | * empty the revoke table after recovery. |
| 571 | */ |
| 572 | |
| 573 | /* |
| 574 | * First, setting revoke records. We create a new revoke record for |
| 575 | * every block ever revoked in the log as we scan it for recovery, and |
| 576 | * we update the existing records if we find multiple revokes for a |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 577 | * single block. |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 578 | */ |
| 579 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 580 | int journal_set_revoke(journal_t *journal, |
| 581 | unsigned long blocknr, |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 582 | tid_t sequence) |
| 583 | { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 584 | struct jbd_revoke_record_s *record; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 585 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 586 | record = find_revoke_record(journal, blocknr); |
| 587 | if (record) { |
| 588 | /* If we have multiple occurences, only record the |
| 589 | * latest sequence number in the hashed record */ |
Theodore Ts'o | 725c474 | 2001-06-08 11:55:44 +0000 | [diff] [blame] | 590 | if (tid_gt(sequence, record->sequence)) |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 591 | record->sequence = sequence; |
| 592 | return 0; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 593 | } |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 594 | return insert_revoke_hash(journal, blocknr, sequence); |
| 595 | } |
| 596 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 597 | /* |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 598 | * Test revoke records. For a given block referenced in the log, has |
| 599 | * that block been revoked? A revoke record with a given transaction |
| 600 | * sequence number revokes all blocks in that transaction and earlier |
| 601 | * ones, but later transactions still need replayed. |
| 602 | */ |
| 603 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 604 | int journal_test_revoke(journal_t *journal, |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 605 | unsigned long blocknr, |
| 606 | tid_t sequence) |
| 607 | { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 608 | struct jbd_revoke_record_s *record; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 609 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 610 | record = find_revoke_record(journal, blocknr); |
| 611 | if (!record) |
| 612 | return 0; |
Theodore Ts'o | 725c474 | 2001-06-08 11:55:44 +0000 | [diff] [blame] | 613 | if (tid_gt(sequence, record->sequence)) |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 614 | return 0; |
| 615 | return 1; |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * Finally, once recovery is over, we need to clear the revoke table so |
| 620 | * that it can be reused by the running filesystem. |
| 621 | */ |
| 622 | |
| 623 | void journal_clear_revoke(journal_t *journal) |
| 624 | { |
| 625 | int i; |
| 626 | struct list_head *hash_list; |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 627 | struct jbd_revoke_record_s *record; |
| 628 | struct jbd_revoke_table_s *revoke; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 629 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 630 | revoke = journal->j_revoke; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 631 | |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 632 | for (i = 0; i < revoke->hash_size; i++) { |
| 633 | hash_list = &revoke->hash_table[i]; |
| 634 | while (!list_empty(hash_list)) { |
Theodore Ts'o | 8cf9333 | 2001-12-16 02:23:36 -0500 | [diff] [blame] | 635 | record = (struct jbd_revoke_record_s*) hash_list->next; |
Theodore Ts'o | 0e8a956 | 2000-12-09 06:41:25 +0000 | [diff] [blame] | 636 | list_del(&record->hash); |
| 637 | kmem_cache_free(revoke_record_cache, record); |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |