ReactOS 0.4.16-dev-297-gc569aee
revoke.c File Reference
#include "jfs_user.h"
#include <linux/log2.h>
Include dependency graph for revoke.c:

Go to the source code of this file.

Classes

struct  jbd_revoke_record_s
 
struct  jbd_revoke_table_s
 

Functions

static int hash (journal_t *journal, unsigned long block)
 
static int insert_revoke_hash (journal_t *journal, unsigned long blocknr, tid_t seq)
 
static struct jbd_revoke_record_sfind_revoke_record (journal_t *journal, unsigned long blocknr)
 
int __init journal_init_revoke_caches (void)
 
void journal_destroy_revoke_caches (void)
 
int journal_init_revoke (journal_t *journal, int hash_size)
 
void journal_destroy_revoke (journal_t *journal)
 
int journal_set_revoke (journal_t *journal, unsigned long blocknr, tid_t sequence)
 
int journal_test_revoke (journal_t *journal, unsigned long blocknr, tid_t sequence)
 
void journal_clear_revoke (journal_t *journal)
 

Variables

static struct kmem_cacherevoke_record_cache = NULL
 
static struct kmem_cacherevoke_table_cache = NULL
 

Function Documentation

◆ find_revoke_record()

static struct jbd_revoke_record_s * find_revoke_record ( journal_t *  journal,
unsigned long  blocknr 
)
static

Definition at line 149 of file revoke.c.

151{
152 struct list_head *hash_list;
154
155 hash_list = &journal->j_revoke->hash_table[hash(journal, blocknr)];
156
157 jbd_lock(&journal->j_revoke_lock);
158 record = (struct jbd_revoke_record_s *) hash_list->next;
159 while (&(record->hash) != hash_list) {
160 if (record->blocknr == blocknr) {
161 jbd_unlock(&journal->j_revoke_lock);
162 return record;
163 }
164 record = (struct jbd_revoke_record_s *) record->hash.next;
165 }
166 jbd_unlock(&journal->j_revoke_lock);
167 return NULL;
168}
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
#define NULL
Definition: types.h:112
unsigned long blocknr
Definition: revoke.c:84
struct list_head hash
Definition: revoke.c:82
Definition: list.h:15
struct list_head * next
Definition: list.h:16

Referenced by journal_set_revoke(), and journal_test_revoke().

◆ hash()

static int hash ( journal_t *  journal,
unsigned long  block 
)
inlinestatic

Definition at line 109 of file revoke.c.

110{
111 struct jbd_revoke_table_s *table = journal->j_revoke;
112 int hash_shift = table->hash_shift;
113
114 return ((block << (hash_shift - 6)) ^
115 (block >> 13) ^
116 (block << (hash_shift - 12))) & (table->hash_size - 1);
117}
static unsigned int block
Definition: xmlmemory.c:101

◆ insert_revoke_hash()

static int insert_revoke_hash ( journal_t *  journal,
unsigned long  blocknr,
tid_t  seq 
)
static

Definition at line 119 of file revoke.c.

121{
122 struct list_head *hash_list;
124
125repeat:
126 record = (struct jbd_revoke_record_s *)
128 if (!record)
129 goto oom;
130
131 record->sequence = seq;
132 record->blocknr = blocknr;
133 hash_list = &journal->j_revoke->hash_table[hash(journal, blocknr)];
134 jbd_lock(&journal->j_revoke_lock);
135 list_add(&record->hash, hash_list);
136 jbd_unlock(&journal->j_revoke_lock);
137 return 0;
138
139oom:
140 if (!journal_oom_retry)
141 return -ENOMEM;
142 jbd_debug(1, "ENOMEM in %s, retrying\n", __FUNCTION__);
143 yield();
144 goto repeat;
145}
#define ENOMEM
Definition: acclib.h:84
static void list_add(struct list_entry *entry, struct list_entry *prev, struct list_entry *next)
Definition: list.h:64
#define __FUNCTION__
Definition: types.h:116
#define GFP_NOFS
Definition: module.h:669
void * kmem_cache_alloc(kmem_cache_t *kc, int flags)
Definition: linux.c:92
#define yield()
Definition: module.h:449
static struct kmem_cache * revoke_record_cache
Definition: revoke.c:73
static int repeat
Definition: xmllint.c:137

Referenced by journal_set_revoke().

◆ journal_clear_revoke()

void journal_clear_revoke ( journal_t *  journal)

Definition at line 689 of file revoke.c.

690{
691 int i;
692 struct list_head *hash_list;
694 struct jbd_revoke_table_s *revoke;
695
696 revoke = journal->j_revoke;
697
698 for (i = 0; i < revoke->hash_size; i++) {
699 hash_list = &revoke->hash_table[i];
700 while (!list_empty(hash_list)) {
701 record = (struct jbd_revoke_record_s*) hash_list->next;
702 list_del(&record->hash);
704 }
705 }
706}
static int list_empty(struct list_entry *head)
Definition: list.h:58
static void list_del(struct list_head *entry)
Definition: list.h:89
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void kmem_cache_free(kmem_cache_t *kc, void *p)
Definition: linux.c:103
struct list_head * hash_table
Definition: revoke.c:95

Referenced by journal_recover().

◆ journal_destroy_revoke()

void journal_destroy_revoke ( journal_t *  journal)

Definition at line 271 of file revoke.c.

272{
274 struct list_head *hash_list;
275 int i;
276
277 table = journal->j_revoke_table[0];
278 if (!table)
279 return;
280
281 for (i=0; i<table->hash_size; i++) {
282 hash_list = &table->hash_table[i];
283 J_ASSERT (list_empty(hash_list));
284 }
285
286 kfree(table->hash_table);
288 journal->j_revoke = NULL;
289
290 table = journal->j_revoke_table[1];
291 if (!table)
292 return;
293
294 for (i=0; i<table->hash_size; i++) {
295 hash_list = &table->hash_table[i];
296 J_ASSERT (list_empty(hash_list));
297 }
298
299 kfree(table->hash_table);
301 journal->j_revoke = NULL;
302}
#define kfree(p)
Definition: module.h:1126
static struct kmem_cache * revoke_table_cache
Definition: revoke.c:74

Referenced by journal_destroy(), and journal_init_inode().

◆ journal_destroy_revoke_caches()

void journal_destroy_revoke_caches ( void  )

Definition at line 191 of file revoke.c.

192{
197}
int kmem_cache_destroy(kmem_cache_t *kc)
Definition: linux.c:82

Referenced by journal_destroy_caches().

◆ journal_init_revoke()

int journal_init_revoke ( journal_t *  journal,
int  hash_size 
)

Definition at line 201 of file revoke.c.

202{
203 int shift, tmp;
204
205 J_ASSERT (journal->j_revoke_table[0] == NULL);
206
207 shift = 0;
208 tmp = hash_size;
209 while ((tmp >>= 1UL) != 0UL)
210 shift++;
211
212 journal->j_revoke_table[0] = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL);
213 if (!journal->j_revoke_table[0])
214 return -ENOMEM;
215 journal->j_revoke = journal->j_revoke_table[0];
216
217 /* Check that the hash_size is a power of two */
218 J_ASSERT(is_power_of_2(hash_size));
219
220 journal->j_revoke->hash_size = hash_size;
221
222 journal->j_revoke->hash_shift = shift;
223
224 journal->j_revoke->hash_table =
225 kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL);
226 if (!journal->j_revoke->hash_table) {
227 kmem_cache_free(revoke_table_cache, journal->j_revoke_table[0]);
228 journal->j_revoke = NULL;
229 return -ENOMEM;
230 }
231
232 for (tmp = 0; tmp < hash_size; tmp++)
233 INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]);
234
235 journal->j_revoke_table[1] = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL);
236 if (!journal->j_revoke_table[1]) {
237 kfree(journal->j_revoke_table[0]->hash_table);
238 kmem_cache_free(revoke_table_cache, journal->j_revoke_table[0]);
239 return -ENOMEM;
240 }
241
242 journal->j_revoke = journal->j_revoke_table[1];
243
244 /* Check that the hash_size is a power of two */
245 J_ASSERT(is_power_of_2(hash_size));
246
247 journal->j_revoke->hash_size = hash_size;
248
249 journal->j_revoke->hash_shift = shift;
250
251 journal->j_revoke->hash_table =
252 kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL);
253 if (!journal->j_revoke->hash_table) {
254 kfree(journal->j_revoke_table[0]->hash_table);
255 kmem_cache_free(revoke_table_cache, journal->j_revoke_table[0]);
256 kmem_cache_free(revoke_table_cache, journal->j_revoke_table[1]);
257 journal->j_revoke = NULL;
258 return -ENOMEM;
259 }
260
261 for (tmp = 0; tmp < hash_size; tmp++)
262 INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]);
263
264 jbd_lock_init(&journal->j_revoke_lock);
265
266 return 0;
267}
#define INIT_LIST_HEAD(ptr)
Definition: list.h:24
#define is_power_of_2(x)
Definition: memory.c:2306
#define kmalloc(size, gfp)
Definition: module.h:1125
#define GFP_KERNEL
Definition: module.h:668
#define shift
Definition: input.c:1755
#define UL
Definition: tui.h:165

Referenced by journal_init_common().

◆ journal_init_revoke_caches()

int __init journal_init_revoke_caches ( void  )

Definition at line 170 of file revoke.c.

171{
172 revoke_record_cache = kmem_cache_create("revoke_record",
173 sizeof(struct jbd_revoke_record_s),
174 0,
176 NULL);
177 if (revoke_record_cache == 0)
178 return -ENOMEM;
179
180 revoke_table_cache = kmem_cache_create("revoke_table",
181 sizeof(struct jbd_revoke_table_s),
182 0, SLAB_TEMPORARY, NULL);
183 if (revoke_table_cache == 0) {
186 return -ENOMEM;
187 }
188 return 0;
189}
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
#define SLAB_HWCACHE_ALIGN
Definition: module.h:1131
#define SLAB_TEMPORARY
Definition: module.h:1133

Referenced by journal_init_caches().

◆ journal_set_revoke()

int journal_set_revoke ( journal_t *  journal,
unsigned long  blocknr,
tid_t  sequence 
)

Definition at line 646 of file revoke.c.

649{
651
653 if (record) {
654 /* If we have multiple occurrences, only record the
655 * latest sequence number in the hashed record */
656 if (tid_gt(sequence, record->sequence))
657 record->sequence = sequence;
658 return 0;
659 }
660 return insert_revoke_hash(journal, blocknr, sequence);
661}
static struct recvd_message * sequence
Definition: SystemMenu.c:63
static int tid_gt(tid_t x, tid_t y)
Definition: jbd.h:1085
static int insert_revoke_hash(journal_t *journal, unsigned long blocknr, tid_t seq)
Definition: revoke.c:119
static struct jbd_revoke_record_s * find_revoke_record(journal_t *journal, unsigned long blocknr)
Definition: revoke.c:149

Referenced by scan_revoke_records().

◆ journal_test_revoke()

int journal_test_revoke ( journal_t *  journal,
unsigned long  blocknr,
tid_t  sequence 
)

Definition at line 670 of file revoke.c.

673{
675
677 if (!record)
678 return 0;
679 if (tid_gt(sequence, record->sequence))
680 return 0;
681 return 1;
682}

Referenced by do_one_pass().

Variable Documentation

◆ revoke_record_cache

struct kmem_cache* revoke_record_cache = NULL
static

◆ revoke_table_cache