Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit feaa7bba authored by Steven Whitehouse's avatar Steven Whitehouse
Browse files

[GFS2] Fix unlinked file handling



This patch fixes the way we have been dealing with unlinked,
but still open files. It removes all limits (other than memory
for inodes, as per every other filesystem) on numbers of these
which we can support on GFS2. It also means that (like other
fs) its the responsibility of the last process to close the file
to deallocate the storage, rather than the person who did the
unlinking. Note that with GFS2, those two events might take place
on different nodes.

Also there are a number of other changes:

 o We use the Linux inode subsystem as it was intended to be
used, wrt allocating GFS2 inodes
 o The Linux inode cache is now the point which we use for
local enforcement of only holding one copy of the inode in
core at once (previous to this we used the glock layer).
 o We no longer use the unlinked "special" file. We just ignore it
completely. This makes unlinking more efficient.
 o We now use the 4th block allocation state. The previously unused
state is used to track unlinked but still open inodes.
 o gfs2_inoded is no longer needed
 o Several fields are now no longer needed (and removed) from the in
core struct gfs2_inode
 o Several fields are no longer needed (and removed) from the in core
superblock

There are a number of future possible optimisations and clean ups
which have been made possible by this patch.

Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent 22da645f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ gfs2-y := acl.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \
	glops.o inode.o lm.o log.o lops.o locking.o lvb.o main.o meta_io.o \
	mount.o ondisk.o ops_address.o ops_dentry.o ops_export.o ops_file.o \
	ops_fstype.o ops_inode.o ops_super.o ops_vm.o page.o quota.o \
	recovery.o rgrp.o super.o sys.o trans.o unlinked.o util.o
	recovery.o rgrp.o super.o sys.o trans.o util.o

obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += locking/nolock/
obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += locking/dlm/
+5 −5
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ int gfs2_acl_validate_set(struct gfs2_inode *ip, int access,

int gfs2_acl_validate_remove(struct gfs2_inode *ip, int access)
{
	if (!ip->i_sbd->sd_args.ar_posix_acl)
	if (!GFS2_SB(&ip->i_inode)->sd_args.ar_posix_acl)
		return -EOPNOTSUPP;
	if (current->fsuid != ip->i_di.di_uid && !capable(CAP_FOWNER))
		return -EPERM;
@@ -160,7 +160,7 @@ int gfs2_check_acl_locked(struct inode *inode, int mask)
	struct posix_acl *acl = NULL;
	int error;

	error = acl_get(inode->u.generic_ip, ACL_ACCESS, &acl, NULL, NULL, NULL);
	error = acl_get(GFS2_I(inode), ACL_ACCESS, &acl, NULL, NULL, NULL);
	if (error)
		return error;

@@ -175,7 +175,7 @@ int gfs2_check_acl_locked(struct inode *inode, int mask)

int gfs2_check_acl(struct inode *inode, int mask)
{
	struct gfs2_inode *ip = inode->u.generic_ip;
	struct gfs2_inode *ip = GFS2_I(inode);
	struct gfs2_holder i_gh;
	int error;

@@ -192,7 +192,7 @@ int gfs2_check_acl(struct inode *inode, int mask)

static int munge_mode(struct gfs2_inode *ip, mode_t mode)
{
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
	struct buffer_head *dibh;
	int error;

@@ -217,7 +217,7 @@ static int munge_mode(struct gfs2_inode *ip, mode_t mode)

int gfs2_acl_create(struct gfs2_inode *dip, struct gfs2_inode *ip)
{
	struct gfs2_sbd *sdp = dip->i_sbd;
	struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
	struct posix_acl *acl = NULL, *clone;
	struct gfs2_ea_request er;
	mode_t mode = ip->i_di.di_mode;
+22 −22
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer,

static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size)
{
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
	uint64_t *arr;
	unsigned int max, height;

@@ -169,7 +169,7 @@ static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size)

static int build_height(struct inode *inode, unsigned height)
{
	struct gfs2_inode *ip = inode->u.generic_ip;
	struct gfs2_inode *ip = GFS2_I(inode);
	unsigned new_height = height - ip->i_di.di_height;
	struct buffer_head *dibh;
	struct buffer_head *blocks[GFS2_MAX_META_HEIGHT];
@@ -283,7 +283,7 @@ static int build_height(struct inode *inode, unsigned height)
static void find_metapath(struct gfs2_inode *ip, uint64_t block,
			  struct metapath *mp)
{
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
	uint64_t b = block;
	unsigned int i;

@@ -382,8 +382,8 @@ static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock,
					       int *boundary,
					       struct metapath *mp)
{
	struct gfs2_inode *ip = inode->u.generic_ip;
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_inode *ip = GFS2_I(inode);
	struct gfs2_sbd *sdp = GFS2_SB(inode);
	struct buffer_head *bh;
	int create = *new;
	unsigned int bsize;
@@ -446,7 +446,7 @@ static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock,

static inline void bmap_lock(struct inode *inode, int create)
{
	struct gfs2_inode *ip = inode->u.generic_ip;
	struct gfs2_inode *ip = GFS2_I(inode);
	if (create)
		down_write(&ip->i_rw_mutex);
	else
@@ -455,7 +455,7 @@ static inline void bmap_lock(struct inode *inode, int create)

static inline void bmap_unlock(struct inode *inode, int create)
{
	struct gfs2_inode *ip = inode->u.generic_ip;
	struct gfs2_inode *ip = GFS2_I(inode);
	if (create)
		up_write(&ip->i_rw_mutex);
	else
@@ -481,8 +481,8 @@ int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *

int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen)
{
	struct gfs2_inode *ip = inode->u.generic_ip;
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_inode *ip = GFS2_I(inode);
	struct gfs2_sbd *sdp = GFS2_SB(inode);
	struct metapath mp;
	struct buffer_head *bh;
	int boundary;
@@ -541,7 +541,7 @@ static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh,
			  uint64_t block, int first, block_call_t bc,
			  void *data)
{
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
	struct buffer_head *bh = NULL;
	uint64_t *top, *bottom;
	uint64_t bn;
@@ -609,8 +609,8 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
		    struct buffer_head *bh, uint64_t *top, uint64_t *bottom,
		    unsigned int height, void *data)
{
	struct strip_mine *sm = (struct strip_mine *)data;
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct strip_mine *sm = data;
	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
	struct gfs2_rgrp_list rlist;
	uint64_t bn, bstart;
	uint32_t blen;
@@ -756,7 +756,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,

static int do_grow(struct gfs2_inode *ip, uint64_t size)
{
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
	struct gfs2_alloc *al;
	struct buffer_head *dibh;
	unsigned int h;
@@ -795,7 +795,7 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size)
		h = calc_tree_height(ip, size);
		if (ip->i_di.di_height < h) {
			down_write(&ip->i_rw_mutex);
			error = build_height(ip->i_vnode, h);
			error = build_height(&ip->i_inode, h);
			up_write(&ip->i_rw_mutex);
			if (error)
				goto out_end_trans;
@@ -830,7 +830,7 @@ static int do_grow(struct gfs2_inode *ip, uint64_t size)

static int trunc_start(struct gfs2_inode *ip, uint64_t size)
{
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
	struct buffer_head *dibh;
	int journaled = gfs2_is_jdata(ip);
	int error;
@@ -854,7 +854,7 @@ static int trunc_start(struct gfs2_inode *ip, uint64_t size)

	} else {
		if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1))
			error = gfs2_block_truncate_page(ip->i_vnode->i_mapping);
			error = gfs2_block_truncate_page(ip->i_inode.i_mapping);

		if (!error) {
			ip->i_di.di_size = size;
@@ -883,7 +883,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size)
	if (!size)
		lblock = 0;
	else
		lblock = (size - 1) >> ip->i_sbd->sd_sb.sb_bsize_shift;
		lblock = (size - 1) >> GFS2_SB(&ip->i_inode)->sd_sb.sb_bsize_shift;

	find_metapath(ip, lblock, &mp);
	gfs2_alloc_get(ip);
@@ -911,7 +911,7 @@ static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size)

static int trunc_end(struct gfs2_inode *ip)
{
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
	struct buffer_head *dibh;
	int error;

@@ -990,7 +990,7 @@ int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size)
{
	int error;

	if (gfs2_assert_warn(ip->i_sbd, S_ISREG(ip->i_di.di_mode)))
	if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), S_ISREG(ip->i_di.di_mode)))
		return -EINVAL;

	if (size > ip->i_di.di_size)
@@ -1027,7 +1027,7 @@ int gfs2_file_dealloc(struct gfs2_inode *ip)
void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len,
			    unsigned int *data_blocks, unsigned int *ind_blocks)
{
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
	unsigned int tmp;

	if (gfs2_is_dir(ip)) {
@@ -1057,7 +1057,7 @@ void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len,
int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset,
			      unsigned int len, int *alloc_required)
{
	struct gfs2_sbd *sdp = ip->i_sbd;
	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
	uint64_t lblock, lblock_stop, dblock;
	uint32_t extlen;
	int new = 0;
@@ -1088,7 +1088,7 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset,
	}

	for (; lblock < lblock_stop; lblock += extlen) {
		error = gfs2_extent_map(ip->i_vnode, lblock, &new, &dblock, &extlen);
		error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen);
		if (error)
			return error;

+0 −27
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@
#include "quota.h"
#include "recovery.h"
#include "super.h"
#include "unlinked.h"
#include "util.h"

/* This uses schedule_timeout() instead of msleep() because it's good for
@@ -195,29 +194,3 @@ int gfs2_quotad(void *data)
	return 0;
}
/**
 * gfs2_inoded - Deallocate unlinked inodes
 * @sdp: Pointer to GFS2 superblock
 *
 */

int gfs2_inoded(void *data)
{
	struct gfs2_sbd *sdp = data;
	unsigned long t;
	int error;

	while (!kthread_should_stop()) {
		error = gfs2_unlinked_dealloc(sdp);
		if (error &&
		    error != -EROFS &&
		    !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
			fs_err(sdp, "inoded: error = %d\n", error);

		t = gfs2_tune_get(sdp, gt_inoded_secs) * HZ;
		schedule_timeout_interruptible(t);
	}

	return 0;
}
+0 −1
Original line number Diff line number Diff line
@@ -15,6 +15,5 @@ int gfs2_glockd(void *data);
int gfs2_recoverd(void *data);
int gfs2_logd(void *data);
int gfs2_quotad(void *data);
int gfs2_inoded(void *data);

#endif /* __DAEMON_DOT_H__ */
Loading