blob: 9a587ada51edaf2c16cc71af4367ab4fd0de5c7c [file] [log] [blame]
Thomas Gleixner7336d0e2019-05-31 01:09:56 -07001/* SPDX-License-Identifier: GPL-2.0-only */
David Teiglandb3b94fa2006-01-16 16:50:04 +00002/*
3 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Bob Petersonfe6c9912008-01-28 11:13:02 -06004 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00005 */
6
7#ifndef __RGRP_DOT_H__
8#define __RGRP_DOT_H__
9
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Steven Whitehouse66fc0612012-02-08 12:58:32 +000011#include <linux/uaccess.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012
Bob Peterson8e2e0042012-07-19 08:12:40 -040013/* Since each block in the file system is represented by two bits in the
14 * bitmap, one 64-bit word in the bitmap will represent 32 blocks.
15 * By reserving 32 blocks at a time, we can optimize / shortcut how we search
16 * through the bitmaps by looking a word at a time.
17 */
Andreas Gruenbacherad899452018-09-25 12:59:31 +010018#define RGRP_RSRV_MINBLKS 32
Bob Peterson1a855032014-10-29 08:02:30 -050019#define RGRP_RSRV_ADDBLKS 64
Bob Peterson8e2e0042012-07-19 08:12:40 -040020
Steven Whitehousef2f7ba52006-09-05 10:39:21 -040021struct gfs2_rgrpd;
22struct gfs2_sbd;
23struct gfs2_holder;
24
Steven Whitehouse09010972009-05-20 10:48:47 +010025extern void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd);
David Teiglandb3b94fa2006-01-16 16:50:04 +000026
Steven Whitehouse66fc0612012-02-08 12:58:32 +000027extern struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk, bool exact);
Steven Whitehouse8339ee52011-08-31 16:38:29 +010028extern struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp);
29extern struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd);
David Teiglandb3b94fa2006-01-16 16:50:04 +000030
Steven Whitehouse09010972009-05-20 10:48:47 +010031extern void gfs2_clear_rgrpd(struct gfs2_sbd *sdp);
Steven Whitehouse8339ee52011-08-31 16:38:29 +010032extern int gfs2_rindex_update(struct gfs2_sbd *sdp);
33extern void gfs2_free_clones(struct gfs2_rgrpd *rgd);
Bob Peterson7c9ca622011-08-31 09:53:19 +010034extern int gfs2_rgrp_go_lock(struct gfs2_holder *gh);
Bob Peterson39b0f1e2015-06-05 08:38:57 -050035extern void gfs2_rgrp_brelse(struct gfs2_rgrpd *rgd);
David Teiglandb3b94fa2006-01-16 16:50:04 +000036
Bob Peterson8e2e0042012-07-19 08:12:40 -040037extern struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip);
38
Steven Whitehouse9dbe9612012-10-31 10:37:10 +000039#define GFS2_AF_ORLOV 1
Abhi Das25435e52015-03-18 12:04:37 -050040extern int gfs2_inplace_reserve(struct gfs2_inode *ip,
41 struct gfs2_alloc_parms *ap);
Steven Whitehouse09010972009-05-20 10:48:47 +010042extern void gfs2_inplace_release(struct gfs2_inode *ip);
David Teiglandb3b94fa2006-01-16 16:50:04 +000043
Bob Peterson6e87ed02011-11-18 10:58:32 -050044extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
45 bool dinode, u64 *generation);
David Teiglandb3b94fa2006-01-16 16:50:04 +000046
Bob Peterson20095212013-03-13 10:26:38 -040047extern void gfs2_rs_deltree(struct gfs2_blkreserv *rs);
Andreas Gruenbacher15955482020-03-06 10:32:35 -060048extern void gfs2_rs_delete(struct gfs2_inode *ip, atomic_t *wcount);
Andreas Gruenbacher0ddeded2018-10-04 15:36:02 +010049extern void __gfs2_free_blocks(struct gfs2_inode *ip, struct gfs2_rgrpd *rgd,
50 u64 bstart, u32 blen, int meta);
51extern void gfs2_free_meta(struct gfs2_inode *ip, struct gfs2_rgrpd *rgd,
52 u64 bstart, u32 blen);
Steven Whitehouse09010972009-05-20 10:48:47 +010053extern 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);
Bob Petersonc3abc292018-10-04 00:06:23 +010067extern void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist);
Steven Whitehouse09010972009-05-20 10:48:47 +010068extern void gfs2_rlist_free(struct gfs2_rgrp_list *rlist);
69extern u64 gfs2_ri_total(struct gfs2_sbd *sdp);
Andrew Price0e539ca2020-10-07 12:30:58 +010070extern void gfs2_rgrp_dump(struct seq_file *seq, struct gfs2_rgrpd *rgd,
Bob Peterson3792ce92019-05-09 09:21:48 -050071 const char *fs_id_buf);
Steven Whitehouse66fc0612012-02-08 12:58:32 +000072extern int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
73 struct buffer_head *bh,
74 const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed);
75extern int gfs2_fitrim(struct file *filp, void __user *argp);
David Teiglandb3b94fa2006-01-16 16:50:04 +000076
Steven Whitehouse4a993fb2012-07-31 15:21:20 +010077/* This is how to tell if a reservation is in the rgrp tree: */
Bob Petersona097dc7e2015-07-16 08:28:04 -050078static inline bool gfs2_rs_active(const struct gfs2_blkreserv *rs)
Bob Peterson8e2e0042012-07-19 08:12:40 -040079{
Steven Whitehouse4a993fb2012-07-31 15:21:20 +010080 return rs && !RB_EMPTY_NODE(&rs->rs_node);
Bob Peterson8e2e0042012-07-19 08:12:40 -040081}
82
Bob Petersond552a2b2017-02-06 08:28:32 -050083static inline int rgrp_contains_block(struct gfs2_rgrpd *rgd, u64 block)
84{
85 u64 first = rgd->rd_data0;
86 u64 last = first + rgd->rd_data;
87 return first <= block && block < last;
88}
89
Abhi Das00a158b2014-09-18 21:40:28 -050090extern void check_and_update_goal(struct gfs2_inode *ip);
David Teiglandb3b94fa2006-01-16 16:50:04 +000091#endif /* __RGRP_DOT_H__ */