blob: 33292c5fe90c580ace83be2230bc6e6e9276b4f1 [file] [log] [blame]
Chris Masondc17ff82008-01-08 15:46:30 -05001/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
17 */
18
19#ifndef __BTRFS_ORDERED_DATA__
20#define __BTRFS_ORDERED_DATA__
21
22struct btrfs_ordered_inode_tree {
Chris Masone6dcd2d2008-07-17 12:53:50 -040023 struct mutex mutex;
Chris Masondc17ff82008-01-08 15:46:30 -050024 struct rb_root tree;
Chris Masone6dcd2d2008-07-17 12:53:50 -040025 struct rb_node *last;
Chris Masondc17ff82008-01-08 15:46:30 -050026};
27
Chris Masone6dcd2d2008-07-17 12:53:50 -040028struct btrfs_sector_sum {
29 u64 offset;
30 u32 sum;
31};
32
33struct btrfs_ordered_sum {
34 u64 file_offset;
35 u64 len;
36 struct list_head list;
37 struct btrfs_sector_sum sums;
38};
39
40/* bits for the flags field */
41#define BTRFS_ORDERED_IO_DONE 0 /* set when all the pages are written */
42#define BTRFS_ORDERED_COMPLETE 1 /* set when removed from the tree */
43#define BTRFS_ORDERED_START 2 /* set when tree setup */
44
45struct btrfs_ordered_extent {
46 u64 file_offset;
47 u64 start;
48 u64 len;
49 unsigned long flags;
50 atomic_t refs;
51 struct list_head list;
52 struct inode *inode;
53 wait_queue_head_t wait;
54 struct rb_node rb_node;
55};
56
57
58static inline int btrfs_ordered_sum_size(struct btrfs_root *root, u64 bytes)
59{
60 unsigned long num_sectors = (bytes + root->sectorsize - 1) /
61 root->sectorsize;
62 return sizeof(struct btrfs_ordered_sum) +
63 num_sectors * sizeof(struct btrfs_sector_sum);
64}
65
Chris Masondc17ff82008-01-08 15:46:30 -050066static inline void
67btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t)
68{
Chris Masone6dcd2d2008-07-17 12:53:50 -040069 mutex_init(&t->mutex);
Chris Masondc17ff82008-01-08 15:46:30 -050070 t->tree.rb_node = NULL;
Chris Masone6dcd2d2008-07-17 12:53:50 -040071 t->last = NULL;
Chris Masondc17ff82008-01-08 15:46:30 -050072}
73
Chris Masone6dcd2d2008-07-17 12:53:50 -040074int btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry);
75int btrfs_remove_ordered_extent(struct inode *inode,
76 struct btrfs_ordered_extent *entry);
77int btrfs_dec_test_ordered_pending(struct inode *inode,
78 u64 file_offset, u64 io_size);
79int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
80 u64 start, u64 len);
81int btrfs_add_ordered_sum(struct inode *inode, struct btrfs_ordered_sum *sum);
82struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode,
83 u64 file_offset);
84void btrfs_wait_ordered_extent(struct inode *inode,
85 struct btrfs_ordered_extent *entry);
86void btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len);
87struct btrfs_ordered_extent *
88btrfs_lookup_first_ordered_extent(struct inode * inode, u64 file_offset);
89int btrfs_add_ordered_pending(struct inode *inode,
90 struct btrfs_ordered_extent *ordered,
91 u64 start, u64 len);
Chris Masondc17ff82008-01-08 15:46:30 -050092#endif