blob: ca6e26729b867ee0f458e1acae042034e2a703dc [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Bob Petersonfe6c9912008-01-28 11:13:02 -06003 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
10#ifndef __RGRP_DOT_H__
11#define __RGRP_DOT_H__
12
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Steven Whitehouse66fc0612012-02-08 12:58:32 +000014#include <linux/uaccess.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015
Bob Peterson8e2e0042012-07-19 08:12:40 -040016/* Since each block in the file system is represented by two bits in the
17 * bitmap, one 64-bit word in the bitmap will represent 32 blocks.
18 * By reserving 32 blocks at a time, we can optimize / shortcut how we search
19 * through the bitmaps by looking a word at a time.
20 */
21#define RGRP_RSRV_MINBYTES 8
22#define RGRP_RSRV_MINBLKS ((u32)(RGRP_RSRV_MINBYTES * GFS2_NBBY))
23
Steven Whitehousef2f7ba52006-09-05 10:39:21 -040024struct gfs2_rgrpd;
25struct gfs2_sbd;
26struct gfs2_holder;
27
Steven Whitehouse09010972009-05-20 10:48:47 +010028extern void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd);
David Teiglandb3b94fa2006-01-16 16:50:04 +000029
Steven Whitehouse66fc0612012-02-08 12:58:32 +000030extern struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk, bool exact);
Steven Whitehouse8339ee52011-08-31 16:38:29 +010031extern struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp);
32extern struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd);
David Teiglandb3b94fa2006-01-16 16:50:04 +000033
Steven Whitehouse09010972009-05-20 10:48:47 +010034extern void gfs2_clear_rgrpd(struct gfs2_sbd *sdp);
Steven Whitehouse8339ee52011-08-31 16:38:29 +010035extern int gfs2_rindex_update(struct gfs2_sbd *sdp);
36extern void gfs2_free_clones(struct gfs2_rgrpd *rgd);
Bob Peterson7c9ca622011-08-31 09:53:19 +010037extern int gfs2_rgrp_go_lock(struct gfs2_holder *gh);
38extern void gfs2_rgrp_go_unlock(struct gfs2_holder *gh);
David Teiglandb3b94fa2006-01-16 16:50:04 +000039
Bob Peterson8e2e0042012-07-19 08:12:40 -040040extern struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip);
41
Bob Peterson564e12b2011-11-21 13:36:17 -050042extern int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested);
Steven Whitehouse09010972009-05-20 10:48:47 +010043extern void gfs2_inplace_release(struct gfs2_inode *ip);
David Teiglandb3b94fa2006-01-16 16:50:04 +000044
Bob Peterson6e87ed02011-11-18 10:58:32 -050045extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
46 bool dinode, u64 *generation);
David Teiglandb3b94fa2006-01-16 16:50:04 +000047
Bob Peterson0a305e42012-06-06 11:17:59 +010048extern int gfs2_rs_alloc(struct gfs2_inode *ip);
Bob Peterson8e2e0042012-07-19 08:12:40 -040049extern void gfs2_rs_deltree(struct gfs2_blkreserv *rs);
Bob Peterson0a305e42012-06-06 11:17:59 +010050extern void gfs2_rs_delete(struct gfs2_inode *ip);
Eric Sandeen46fcb2e2011-06-23 10:39:34 -050051extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta);
Steven Whitehouse09010972009-05-20 10:48:47 +010052extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen);
53extern void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip);
54extern void gfs2_unlink_di(struct inode *inode);
Steven Whitehouseacf7e242009-09-08 18:00:30 +010055extern int gfs2_check_blk_type(struct gfs2_sbd *sdp, u64 no_addr,
56 unsigned int type);
David Teiglandb3b94fa2006-01-16 16:50:04 +000057
58struct gfs2_rgrp_list {
59 unsigned int rl_rgrps;
60 unsigned int rl_space;
61 struct gfs2_rgrpd **rl_rgd;
62 struct gfs2_holder *rl_ghs;
63};
64
Steven Whitehouse70b0c362011-09-02 16:08:09 +010065extern void gfs2_rlist_add(struct gfs2_inode *ip, struct gfs2_rgrp_list *rlist,
Steven Whitehouse09010972009-05-20 10:48:47 +010066 u64 block);
67extern void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state);
68extern void gfs2_rlist_free(struct gfs2_rgrp_list *rlist);
69extern u64 gfs2_ri_total(struct gfs2_sbd *sdp);
70extern int gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl);
Steven Whitehouse66fc0612012-02-08 12:58:32 +000071extern int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
72 struct buffer_head *bh,
73 const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed);
74extern int gfs2_fitrim(struct file *filp, void __user *argp);
David Teiglandb3b94fa2006-01-16 16:50:04 +000075
Bob Peterson8e2e0042012-07-19 08:12:40 -040076/* This is how to tell if a multi-block reservation is "inplace" reserved: */
Bob Peterson0a305e42012-06-06 11:17:59 +010077static inline int gfs2_mb_reserved(struct gfs2_inode *ip)
78{
79 if (ip->i_res && ip->i_res->rs_requested)
80 return 1;
81 return 0;
82}
83
Bob Peterson8e2e0042012-07-19 08:12:40 -040084/* This is how to tell if a multi-block reservation is in the rgrp tree: */
85static inline int gfs2_rs_active(struct gfs2_blkreserv *rs)
86{
87 if (rs && rs->rs_bi)
88 return 1;
89 return 0;
90}
91
92static inline u32 gfs2_bi2rgd_blk(const struct gfs2_bitmap *bi, u32 blk)
93{
94 return (bi->bi_start * GFS2_NBBY) + blk;
95}
96
97static inline u64 gfs2_rs_startblk(const struct gfs2_blkreserv *rs)
98{
99 return gfs2_bi2rgd_blk(rs->rs_bi, rs->rs_biblk) + rs->rs_rgd->rd_data0;
100}
101
David Teiglandb3b94fa2006-01-16 16:50:04 +0000102#endif /* __RGRP_DOT_H__ */