/*
* These routines are used by the resource group routines (rgrp.c)
* to keep track of block allocation. Each block is represented by two
- * bits. One bit indicates whether or not the block is used. (1=used,
- * 0=free) The other bit indicates whether or not the block contains a
- * dinode or not. (1=dinode, 0=not-dinode) So, each byte represents
- * GFS2_NBBY (i.e. 4) blocks.
+ * bits. So, each byte represents GFS2_NBBY (i.e. 4) blocks.
+ *
+ * 0 = Free
+ * 1 = Used (not metadata)
+ * 2 = Unlinked (still in use) inode
+ * 3 = Used (metadata)
*/
static const char valid_change[16] = {
/* current */
- /* n */ 0, 1, 0, 1,
+ /* n */ 0, 1, 1, 1,
/* e */ 1, 0, 0, 0,
- /* w */ 0, 0, 0, 0,
+ /* w */ 0, 0, 0, 1,
1, 0, 0, 0
};
tmp = rgd->rd_ri.ri_data -
rgd->rd_rg.rg_free -
rgd->rd_rg.rg_dinodes;
- if (count[1] != tmp) {
+ if (count[1] + count[2] != tmp) {
if (gfs2_consist_rgrpd(rgd))
fs_err(sdp, "used data mismatch: %u != %u\n",
count[1], tmp);
return;
}
- if (count[2]) {
+ if (count[3] != rgd->rd_rg.rg_dinodes) {
if (gfs2_consist_rgrpd(rgd))
- fs_err(sdp, "free metadata mismatch: %u != 0\n",
- count[2]);
+ fs_err(sdp, "used metadata mismatch: %u != %u\n",
+ count[3], rgd->rd_rg.rg_dinodes);
return;
}
- if (count[3] != rgd->rd_rg.rg_dinodes) {
+ if (count[2] > count[3]) {
if (gfs2_consist_rgrpd(rgd))
- fs_err(sdp, "used metadata mismatch: %u != %u\n",
- count[3], rgd->rd_rg.rg_dinodes);
+ fs_err(sdp, "unlinked inodes > inodes: %u\n",
+ count[2]);
return;
}
+
}
static inline int rgrp_contains_block(struct gfs2_rindex *ri, uint64_t block)
uint32_t bytes_left, bytes;
int x;
+ if (!length)
+ return -EINVAL;
+
rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_KERNEL);
if (!rgd->rd_bits)
return -ENOMEM;
static int gfs2_ri_update(struct gfs2_inode *ip)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
- struct inode *inode = ip->i_vnode;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
+ struct inode *inode = &ip->i_inode;
struct gfs2_rgrpd *rgd;
char buf[sizeof(struct gfs2_rindex)];
struct file_ra_state ra_state;
list_add_tail(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list);
gfs2_rindex_in(&rgd->rd_ri, buf);
-
error = compute_bitstructs(rgd);
if (error)
goto fail;
}
sdp->sd_rindex_vn = ip->i_gl->gl_vn;
-
return 0;
- fail:
+fail:
clear_rgrpdi(sdp);
-
return error;
}
int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh)
{
- struct gfs2_inode *ip = sdp->sd_rindex->u.generic_ip;
+ struct gfs2_inode *ip = GFS2_I(sdp->sd_rindex);
struct gfs2_glock *gl = ip->i_gl;
int error;
error = gfs2_meta_reread(sdp, bi->bi_bh, DIO_WAIT);
if (error)
goto fail;
- if (gfs2_metatype_check(sdp, bi->bi_bh,
- (y) ? GFS2_METATYPE_RB :
+ if (gfs2_metatype_check(sdp, bi->bi_bh, y ? GFS2_METATYPE_RB :
GFS2_METATYPE_RG)) {
error = -EIO;
goto fail;
return 0;
- fail:
+fail:
while (x--) {
bi = rgd->rd_bits + x;
brelse(bi->bi_bh);
if (!bi->bi_clone)
continue;
memcpy(bi->bi_clone + bi->bi_offset,
- bi->bi_bh->b_data + bi->bi_offset,
- bi->bi_len);
+ bi->bi_bh->b_data + bi->bi_offset, bi->bi_len);
}
spin_lock(&sdp->sd_rindex_spin);
goto out;
}
- first:
+first:
rgd = list_entry(sdp->sd_rindex_recent_list.next, struct gfs2_rgrpd,
rd_recent);
-
- out:
+out:
spin_unlock(&sdp->sd_rindex_spin);
-
return rgd;
}
if (!list_empty(head))
rgd = list_entry(head->next, struct gfs2_rgrpd, rd_recent);
- out:
+out:
spin_unlock(&sdp->sd_rindex_spin);
-
return rgd;
}
}
list_add_tail(&new_rgd->rd_recent, &sdp->sd_rindex_recent_list);
- out:
+out:
spin_unlock(&sdp->sd_rindex_spin);
}
static int get_local_rgrp(struct gfs2_inode *ip)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_rgrpd *rgd, *begin = NULL;
struct gfs2_alloc *al = &ip->i_alloc;
int flags = LM_FLAG_TRY;
}
}
- out:
+out:
ip->i_last_rg_alloc = rgd->rd_ri.ri_addr;
if (begin) {
int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_alloc *al = &ip->i_alloc;
int error;
void gfs2_inplace_release(struct gfs2_inode *ip)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_alloc *al = &ip->i_alloc;
if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1)
gfs2_assert(rgd->rd_sbd, buf < length);
buf_block = rgrp_block - bi->bi_start * GFS2_NBBY;
- type = gfs2_testbit(rgd,
- bi->bi_bh->b_data + bi->bi_offset,
+ type = gfs2_testbit(rgd, bi->bi_bh->b_data + bi->bi_offset,
bi->bi_len, buf_block);
return type;
* Returns: the allocated block
*/
-uint64_t gfs2_alloc_data(struct gfs2_inode *ip)
+u64 gfs2_alloc_data(struct gfs2_inode *ip)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_alloc *al = &ip->i_alloc;
struct gfs2_rgrpd *rgd = al->al_rgd;
uint32_t goal, blk;
* Returns: the allocated block
*/
-uint64_t gfs2_alloc_meta(struct gfs2_inode *ip)
+u64 gfs2_alloc_meta(struct gfs2_inode *ip)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_alloc *al = &ip->i_alloc;
struct gfs2_rgrpd *rgd = al->al_rgd;
uint32_t goal, blk;
* Returns: the block allocated
*/
-uint64_t gfs2_alloc_di(struct gfs2_inode *dip)
+u64 gfs2_alloc_di(struct gfs2_inode *dip, u64 *generation)
{
- struct gfs2_sbd *sdp = dip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
struct gfs2_alloc *al = &dip->i_alloc;
struct gfs2_rgrpd *rgd = al->al_rgd;
- uint32_t blk;
- uint64_t block;
+ u32 blk;
+ u64 block;
blk = rgblk_search(rgd, rgd->rd_last_alloc_meta,
GFS2_BLKST_FREE, GFS2_BLKST_DINODE);
gfs2_assert_withdraw(sdp, rgd->rd_rg.rg_free);
rgd->rd_rg.rg_free--;
rgd->rd_rg.rg_dinodes++;
-
+ *generation = rgd->rd_rg.rg_igeneration++;
gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data);
void gfs2_free_data(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_rgrpd *rgd;
rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE);
void gfs2_free_meta(struct gfs2_inode *ip, uint64_t bstart, uint32_t blen)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_rgrpd *rgd;
rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE);
gfs2_trans_add_rg(rgd);
gfs2_statfs_change(sdp, 0, +blen, 0);
- gfs2_quota_change(ip, -(int64_t)blen,
- ip->i_di.di_uid, ip->i_di.di_gid);
+ gfs2_quota_change(ip, -(int64_t)blen, ip->i_di.di_uid, ip->i_di.di_gid);
gfs2_meta_wipe(ip, bstart, blen);
}
-void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno)
+void gfs2_unlink_di(struct inode *inode)
+{
+ struct gfs2_inode *ip = GFS2_I(inode);
+ struct gfs2_sbd *sdp = GFS2_SB(inode);
+ struct gfs2_rgrpd *rgd;
+ u64 blkno = ip->i_num.no_addr;
+
+ rgd = rgblk_free(sdp, blkno, 1, GFS2_BLKST_UNLINKED);
+ if (!rgd)
+ return;
+ gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
+ gfs2_rgrp_out(&rgd->rd_rg, rgd->rd_bits[0].bi_bh->b_data);
+ gfs2_trans_add_rg(rgd);
+}
+
+static void gfs2_free_uninit_di(struct gfs2_rgrpd *rgd, uint64_t blkno)
{
struct gfs2_sbd *sdp = rgd->rd_sbd;
struct gfs2_rgrpd *tmp_rgd;
gfs2_trans_add_rg(rgd);
}
-/**
- * gfs2_free_uninit_di - free a dinode block
- * @rgd: the resource group that contains the dinode
- * @ip: the inode
- *
- */
void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip)
{