nilfs2: add routines to save and restore bmap state
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Mon, 30 Aug 2010 14:42:18 +0000 (23:42 +0900)
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Sat, 23 Oct 2010 00:24:37 +0000 (09:24 +0900)
This adds routines to save and restore the state of bmap structure.
The bmap state is stored in a given nilfs_bmap_store object.

These routines will be used to roll back the state of dat inode
without using gcdat inode.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
fs/nilfs2/bmap.c
fs/nilfs2/bmap.h

index 3dbdc1d..0024440 100644 (file)
@@ -548,3 +548,21 @@ void nilfs_bmap_commit_gcdat(struct nilfs_bmap *gcbmap, struct nilfs_bmap *bmap)
        lockdep_set_class(&bmap->b_sem, &nilfs_bmap_dat_lock_key);
        bmap->b_inode = &NILFS_BMAP_I(bmap)->vfs_inode;
 }
+
+void nilfs_bmap_save(const struct nilfs_bmap *bmap,
+                    struct nilfs_bmap_store *store)
+{
+       memcpy(store->data, bmap->b_u.u_data, sizeof(store->data));
+       store->last_allocated_key = bmap->b_last_allocated_key;
+       store->last_allocated_ptr = bmap->b_last_allocated_ptr;
+       store->state = bmap->b_state;
+}
+
+void nilfs_bmap_restore(struct nilfs_bmap *bmap,
+                       const struct nilfs_bmap_store *store)
+{
+       memcpy(bmap->b_u.u_data, store->data, sizeof(store->data));
+       bmap->b_last_allocated_key = store->last_allocated_key;
+       bmap->b_last_allocated_ptr = store->last_allocated_ptr;
+       bmap->b_state = store->state;
+}
index a20569b..5f3339e 100644 (file)
@@ -135,6 +135,12 @@ struct nilfs_bmap {
 /* state */
 #define NILFS_BMAP_DIRTY       0x00000001
 
+struct nilfs_bmap_store {
+       __le64 data[NILFS_BMAP_SIZE / sizeof(__le64)];
+       __u64 last_allocated_key;
+       __u64 last_allocated_ptr;
+       int state;
+};
 
 int nilfs_bmap_test_and_clear_dirty(struct nilfs_bmap *);
 int nilfs_bmap_read(struct nilfs_bmap *, struct nilfs_inode *);
@@ -156,6 +162,8 @@ void nilfs_bmap_init_gc(struct nilfs_bmap *);
 void nilfs_bmap_init_gcdat(struct nilfs_bmap *, struct nilfs_bmap *);
 void nilfs_bmap_commit_gcdat(struct nilfs_bmap *, struct nilfs_bmap *);
 
+void nilfs_bmap_save(const struct nilfs_bmap *, struct nilfs_bmap_store *);
+void nilfs_bmap_restore(struct nilfs_bmap *, const struct nilfs_bmap_store *);
 
 static inline int nilfs_bmap_lookup(struct nilfs_bmap *bmap, __u64 key,
                                    __u64 *ptr)