blob: c8ce46f7d8e30ee842cc8966a8c034aefae3b98b [file] [log] [blame]
Tao Ma8dec98e2009-08-18 11:19:58 +08001/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * refcounttree.h
5 *
6 * Copyright (C) 2009 Oracle. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17#ifndef OCFS2_REFCOUNTTREE_H
18#define OCFS2_REFCOUNTTREE_H
19
20struct ocfs2_refcount_tree {
21 struct rb_node rf_node;
22 u64 rf_blkno;
23 u32 rf_generation;
Goldwyn Rodrigues83fd9c72010-06-10 17:21:36 -050024 struct kref rf_getcnt;
Tao Ma8dec98e2009-08-18 11:19:58 +080025 struct rw_semaphore rf_sem;
26 struct ocfs2_lock_res rf_lockres;
Tao Ma8dec98e2009-08-18 11:19:58 +080027 int rf_removed;
28
29 /* the following 4 fields are used by caching_info. */
Tao Ma8dec98e2009-08-18 11:19:58 +080030 spinlock_t rf_lock;
Goldwyn Rodrigues83fd9c72010-06-10 17:21:36 -050031 struct ocfs2_caching_info rf_ci;
Tao Ma8dec98e2009-08-18 11:19:58 +080032 struct mutex rf_io_mutex;
33 struct super_block *rf_sb;
34};
35
Tao Ma374a2632009-08-24 11:13:37 +080036void ocfs2_purge_refcount_trees(struct ocfs2_super *osb);
37int ocfs2_lock_refcount_tree(struct ocfs2_super *osb, u64 ref_blkno, int rw,
38 struct ocfs2_refcount_tree **tree,
39 struct buffer_head **ref_bh);
40void ocfs2_unlock_refcount_tree(struct ocfs2_super *osb,
41 struct ocfs2_refcount_tree *tree,
42 int rw);
Tao Ma1823cb02009-08-18 11:24:49 +080043
44int ocfs2_decrease_refcount(struct inode *inode,
45 handle_t *handle, u32 cpos, u32 len,
46 struct ocfs2_alloc_context *meta_ac,
Tao Ma6ae23c52009-08-18 11:30:55 +080047 struct ocfs2_cached_dealloc_ctxt *dealloc,
48 int delete);
Tao Mabcbbb242009-08-18 11:29:12 +080049int ocfs2_prepare_refcount_change_for_del(struct inode *inode,
Tristan Ye78f94672010-05-11 17:54:42 +080050 u64 refcount_loc,
Tao Mabcbbb242009-08-18 11:29:12 +080051 u64 phys_blkno,
52 u32 clusters,
53 int *credits,
Tristan Ye78f94672010-05-11 17:54:42 +080054 int *ref_blocks);
Tao Ma15502712010-08-12 10:36:38 +080055int ocfs2_refcount_cow(struct inode *inode,
56 struct file *filep, struct buffer_head *di_bh,
Tao Ma37f8a2b2009-08-26 09:47:28 +080057 u32 cpos, u32 write_len, u32 max_cpos);
Tao Ma492a8a32009-08-18 11:43:17 +080058
59typedef int (ocfs2_post_refcount_func)(struct inode *inode,
60 handle_t *handle,
61 void *para);
62/*
63 * Some refcount caller need to do more work after we modify the data b-tree
64 * during refcount operation(including CoW and add refcount flag), and make the
65 * transaction complete. So it must give us this structure so that we can do it
66 * within our transaction.
67 *
68 */
69struct ocfs2_post_refcount {
70 int credits; /* credits it need for journal. */
71 ocfs2_post_refcount_func *func; /* real function. */
72 void *para;
73};
74
75int ocfs2_refcounted_xattr_delete_need(struct inode *inode,
76 struct ocfs2_caching_info *ref_ci,
77 struct buffer_head *ref_root_bh,
78 struct ocfs2_xattr_value_root *xv,
79 int *meta_add, int *credits);
80int ocfs2_refcount_cow_xattr(struct inode *inode,
81 struct ocfs2_dinode *di,
82 struct ocfs2_xattr_value_buf *vb,
83 struct ocfs2_refcount_tree *ref_tree,
84 struct buffer_head *ref_root_bh,
85 u32 cpos, u32 write_len,
86 struct ocfs2_post_refcount *post);
Tao Ma01292412009-09-21 13:04:19 +080087int ocfs2_add_refcount_flag(struct inode *inode,
88 struct ocfs2_extent_tree *data_et,
89 struct ocfs2_caching_info *ref_ci,
90 struct buffer_head *ref_root_bh,
91 u32 cpos, u32 p_cluster, u32 num_clusters,
92 struct ocfs2_cached_dealloc_ctxt *dealloc,
93 struct ocfs2_post_refcount *post);
Tao Ma8b2c0db2009-08-18 11:43:49 +080094int ocfs2_remove_refcount_tree(struct inode *inode, struct buffer_head *di_bh);
95int ocfs2_try_remove_refcount_tree(struct inode *inode,
96 struct buffer_head *di_bh);
Tao Ma2999d122009-08-18 11:43:55 +080097int ocfs2_increase_refcount(handle_t *handle,
98 struct ocfs2_caching_info *ci,
99 struct buffer_head *ref_root_bh,
100 u64 cpos, u32 len,
101 struct ocfs2_alloc_context *meta_ac,
102 struct ocfs2_cached_dealloc_ctxt *dealloc);
Tao Mabd508732009-09-21 11:25:14 +0800103int ocfs2_reflink_ioctl(struct inode *inode,
104 const char __user *oldname,
105 const char __user *newname,
106 bool preserve);
Tao Ma8dec98e2009-08-18 11:19:58 +0800107#endif /* OCFS2_REFCOUNTTREE_H */