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

Commit 40c73abb authored by Linus Torvalds's avatar Linus Torvalds
Browse files
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs-2.6:
  ext2: Resolve 'dereferencing pointer to incomplete type' when enabling EXT2_XATTR_DEBUG
  ext3: Remove redundant unlikely()
  ext2: Remove redundant unlikely()
  ext3: speed up file creates by optimizing rec_len functions
  ext2: speed up file creates by optimizing rec_len functions
  ext3: Add more journal error check
  ext3: Add journal error check in resize.c
  quota: Use %pV and __attribute__((format (printf in __quota_error and fix fallout
  ext3: Add FITRIM handling
  ext3: Add batched discard support for ext3
  ext3: Add journal error check into ext3_rename()
  ext3: Use search_dirblock() in ext3_dx_find_entry()
  ext3: Avoid uninitialized memory references with a corrupted htree directory
  ext3: Return error code from generic_check_addressable
  ext3: Add journal error check into ext3_delete_entry()
  ext3: Add error check in ext3_mkdir()
  fs/ext3/super.c: Use printf extension %pV
  fs/ext2/super.c: Use printf extension %pV
  ext3: don't update sb journal_devnum when RO dev
parents 0945f352 d96336b0
Loading
Loading
Loading
Loading
+14 −5
Original line number Original line Diff line number Diff line
@@ -28,21 +28,30 @@


typedef struct ext2_dir_entry_2 ext2_dirent;
typedef struct ext2_dir_entry_2 ext2_dirent;


/*
 * Tests against MAX_REC_LEN etc were put in place for 64k block
 * sizes; if that is not possible on this arch, we can skip
 * those tests and speed things up.
 */
static inline unsigned ext2_rec_len_from_disk(__le16 dlen)
static inline unsigned ext2_rec_len_from_disk(__le16 dlen)
{
{
	unsigned len = le16_to_cpu(dlen);
	unsigned len = le16_to_cpu(dlen);


#if (PAGE_CACHE_SIZE >= 65536)
	if (len == EXT2_MAX_REC_LEN)
	if (len == EXT2_MAX_REC_LEN)
		return 1 << 16;
		return 1 << 16;
#endif
	return len;
	return len;
}
}


static inline __le16 ext2_rec_len_to_disk(unsigned len)
static inline __le16 ext2_rec_len_to_disk(unsigned len)
{
{
#if (PAGE_CACHE_SIZE >= 65536)
	if (len == (1 << 16))
	if (len == (1 << 16))
		return cpu_to_le16(EXT2_MAX_REC_LEN);
		return cpu_to_le16(EXT2_MAX_REC_LEN);
	else
	else
		BUG_ON(len > (1 << 16));
		BUG_ON(len > (1 << 16));
#endif
	return cpu_to_le16(len);
	return cpu_to_le16(len);
}
}


@@ -129,15 +138,15 @@ static void ext2_check_page(struct page *page, int quiet)
		p = (ext2_dirent *)(kaddr + offs);
		p = (ext2_dirent *)(kaddr + offs);
		rec_len = ext2_rec_len_from_disk(p->rec_len);
		rec_len = ext2_rec_len_from_disk(p->rec_len);


		if (rec_len < EXT2_DIR_REC_LEN(1))
		if (unlikely(rec_len < EXT2_DIR_REC_LEN(1)))
			goto Eshort;
			goto Eshort;
		if (rec_len & 3)
		if (unlikely(rec_len & 3))
			goto Ealign;
			goto Ealign;
		if (rec_len < EXT2_DIR_REC_LEN(p->name_len))
		if (unlikely(rec_len < EXT2_DIR_REC_LEN(p->name_len)))
			goto Enamelen;
			goto Enamelen;
		if (((offs + rec_len - 1) ^ offs) & ~(chunk_size-1))
		if (unlikely(((offs + rec_len - 1) ^ offs) & ~(chunk_size-1)))
			goto Espan;
			goto Espan;
		if (le32_to_cpu(p->inode) > max_inumber)
		if (unlikely(le32_to_cpu(p->inode) > max_inumber))
			goto Einumber;
			goto Einumber;
	}
	}
	if (offs != limit)
	if (offs != limit)
+1 −1
Original line number Original line Diff line number Diff line
@@ -67,7 +67,7 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, str
	inode = NULL;
	inode = NULL;
	if (ino) {
	if (ino) {
		inode = ext2_iget(dir->i_sb, ino);
		inode = ext2_iget(dir->i_sb, ino);
		if (unlikely(IS_ERR(inode))) {
		if (IS_ERR(inode)) {
			if (PTR_ERR(inode) == -ESTALE) {
			if (PTR_ERR(inode) == -ESTALE) {
				ext2_error(dir->i_sb, __func__,
				ext2_error(dir->i_sb, __func__,
						"deleted inode referenced: %lu",
						"deleted inode referenced: %lu",
+17 −8
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@ static int ext2_sync_fs(struct super_block *sb, int wait);
void ext2_error(struct super_block *sb, const char *function,
void ext2_error(struct super_block *sb, const char *function,
		const char *fmt, ...)
		const char *fmt, ...)
{
{
	struct va_format vaf;
	va_list args;
	va_list args;
	struct ext2_sb_info *sbi = EXT2_SB(sb);
	struct ext2_sb_info *sbi = EXT2_SB(sb);
	struct ext2_super_block *es = sbi->s_es;
	struct ext2_super_block *es = sbi->s_es;
@@ -59,9 +60,13 @@ void ext2_error (struct super_block * sb, const char * function,
	}
	}


	va_start(args, fmt);
	va_start(args, fmt);
	printk(KERN_CRIT "EXT2-fs (%s): error: %s: ", sb->s_id, function);

	vprintk(fmt, args);
	vaf.fmt = fmt;
	printk("\n");
	vaf.va = &args;

	printk(KERN_CRIT "EXT2-fs (%s): error: %s: %pV\n",
	       sb->s_id, function, &vaf);

	va_end(args);
	va_end(args);


	if (test_opt(sb, ERRORS_PANIC))
	if (test_opt(sb, ERRORS_PANIC))
@@ -76,12 +81,16 @@ void ext2_error (struct super_block * sb, const char * function,
void ext2_msg(struct super_block *sb, const char *prefix,
void ext2_msg(struct super_block *sb, const char *prefix,
		const char *fmt, ...)
		const char *fmt, ...)
{
{
	struct va_format vaf;
	va_list args;
	va_list args;


	va_start(args, fmt);
	va_start(args, fmt);
	printk("%sEXT2-fs (%s): ", prefix, sb->s_id);

	vprintk(fmt, args);
	vaf.fmt = fmt;
	printk("\n");
	vaf.va = &args;

	printk("%sEXT2-fs (%s): %pV\n", prefix, sb->s_id, &vaf);

	va_end(args);
	va_end(args);
}
}


+266 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@
#include <linux/ext3_jbd.h>
#include <linux/ext3_jbd.h>
#include <linux/quotaops.h>
#include <linux/quotaops.h>
#include <linux/buffer_head.h>
#include <linux/buffer_head.h>
#include <linux/blkdev.h>


/*
/*
 * balloc.c contains the blocks allocation and deallocation routines
 * balloc.c contains the blocks allocation and deallocation routines
@@ -39,6 +40,21 @@


#define in_range(b, first, len)	((b) >= (first) && (b) <= (first) + (len) - 1)
#define in_range(b, first, len)	((b) >= (first) && (b) <= (first) + (len) - 1)


/*
 * Calculate the block group number and offset, given a block number
 */
static void ext3_get_group_no_and_offset(struct super_block *sb,
	ext3_fsblk_t blocknr, unsigned long *blockgrpp, ext3_grpblk_t *offsetp)
{
	struct ext3_super_block *es = EXT3_SB(sb)->s_es;

	blocknr = blocknr - le32_to_cpu(es->s_first_data_block);
	if (offsetp)
		*offsetp = blocknr % EXT3_BLOCKS_PER_GROUP(sb);
	if (blockgrpp)
		*blockgrpp = blocknr / EXT3_BLOCKS_PER_GROUP(sb);
}

/**
/**
 * ext3_get_group_desc() -- load group descriptor from disk
 * ext3_get_group_desc() -- load group descriptor from disk
 * @sb:			super block
 * @sb:			super block
@@ -1885,3 +1901,253 @@ unsigned long ext3_bg_num_gdb(struct super_block *sb, int group)
	return ext3_bg_num_gdb_meta(sb,group);
	return ext3_bg_num_gdb_meta(sb,group);


}
}

/**
 * ext3_trim_all_free -- function to trim all free space in alloc. group
 * @sb:			super block for file system
 * @group:		allocation group to trim
 * @start:		first group block to examine
 * @max:		last group block to examine
 * @gdp:		allocation group description structure
 * @minblocks:		minimum extent block count
 *
 * ext3_trim_all_free walks through group's block bitmap searching for free
 * blocks. When the free block is found, it tries to allocate this block and
 * consequent free block to get the biggest free extent possible, until it
 * reaches any used block. Then issue a TRIM command on this extent and free
 * the extent in the block bitmap. This is done until whole group is scanned.
 */
ext3_grpblk_t ext3_trim_all_free(struct super_block *sb, unsigned int group,
				ext3_grpblk_t start, ext3_grpblk_t max,
				ext3_grpblk_t minblocks)
{
	handle_t *handle;
	ext3_grpblk_t next, free_blocks, bit, freed, count = 0;
	ext3_fsblk_t discard_block;
	struct ext3_sb_info *sbi;
	struct buffer_head *gdp_bh, *bitmap_bh = NULL;
	struct ext3_group_desc *gdp;
	int err = 0, ret = 0;

	/*
	 * We will update one block bitmap, and one group descriptor
	 */
	handle = ext3_journal_start_sb(sb, 2);
	if (IS_ERR(handle))
		return PTR_ERR(handle);

	bitmap_bh = read_block_bitmap(sb, group);
	if (!bitmap_bh) {
		err = -EIO;
		goto err_out;
	}

	BUFFER_TRACE(bitmap_bh, "getting undo access");
	err = ext3_journal_get_undo_access(handle, bitmap_bh);
	if (err)
		goto err_out;

	gdp = ext3_get_group_desc(sb, group, &gdp_bh);
	if (!gdp) {
		err = -EIO;
		goto err_out;
	}

	BUFFER_TRACE(gdp_bh, "get_write_access");
	err = ext3_journal_get_write_access(handle, gdp_bh);
	if (err)
		goto err_out;

	free_blocks = le16_to_cpu(gdp->bg_free_blocks_count);
	sbi = EXT3_SB(sb);

	 /* Walk through the whole group */
	while (start < max) {
		start = bitmap_search_next_usable_block(start, bitmap_bh, max);
		if (start < 0)
			break;
		next = start;

		/*
		 * Allocate contiguous free extents by setting bits in the
		 * block bitmap
		 */
		while (next < max
			&& claim_block(sb_bgl_lock(sbi, group),
					next, bitmap_bh)) {
			next++;
		}

		 /* We did not claim any blocks */
		if (next == start)
			continue;

		discard_block = (ext3_fsblk_t)start +
				ext3_group_first_block_no(sb, group);

		/* Update counters */
		spin_lock(sb_bgl_lock(sbi, group));
		le16_add_cpu(&gdp->bg_free_blocks_count, start - next);
		spin_unlock(sb_bgl_lock(sbi, group));
		percpu_counter_sub(&sbi->s_freeblocks_counter, next - start);

		/* Do not issue a TRIM on extents smaller than minblocks */
		if ((next - start) < minblocks)
			goto free_extent;

		 /* Send the TRIM command down to the device */
		err = sb_issue_discard(sb, discard_block, next - start,
				       GFP_NOFS, 0);
		count += (next - start);
free_extent:
		freed = 0;

		/*
		 * Clear bits in the bitmap
		 */
		for (bit = start; bit < next; bit++) {
			BUFFER_TRACE(bitmap_bh, "clear bit");
			if (!ext3_clear_bit_atomic(sb_bgl_lock(sbi, group),
						bit, bitmap_bh->b_data)) {
				ext3_error(sb, __func__,
					"bit already cleared for block "E3FSBLK,
					 (unsigned long)bit);
				BUFFER_TRACE(bitmap_bh, "bit already cleared");
			} else {
				freed++;
			}
		}

		/* Update couters */
		spin_lock(sb_bgl_lock(sbi, group));
		le16_add_cpu(&gdp->bg_free_blocks_count, freed);
		spin_unlock(sb_bgl_lock(sbi, group));
		percpu_counter_add(&sbi->s_freeblocks_counter, freed);

		start = next;
		if (err < 0) {
			if (err != -EOPNOTSUPP)
				ext3_warning(sb, __func__, "Discard command "
					     "returned error %d\n", err);
			break;
		}

		if (fatal_signal_pending(current)) {
			err = -ERESTARTSYS;
			break;
		}

		cond_resched();

		/* No more suitable extents */
		if ((free_blocks - count) < minblocks)
			break;
	}

	/* We dirtied the bitmap block */
	BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");
	ret = ext3_journal_dirty_metadata(handle, bitmap_bh);
	if (!err)
		err = ret;

	/* And the group descriptor block */
	BUFFER_TRACE(gdp_bh, "dirtied group descriptor block");
	ret = ext3_journal_dirty_metadata(handle, gdp_bh);
	if (!err)
		err = ret;

	ext3_debug("trimmed %d blocks in the group %d\n",
		count, group);

err_out:
	if (err)
		count = err;
	ext3_journal_stop(handle);
	brelse(bitmap_bh);

	return count;
}

/**
 * ext3_trim_fs() -- trim ioctl handle function
 * @sb:			superblock for filesystem
 * @start:		First Byte to trim
 * @len:		number of Bytes to trim from start
 * @minlen:		minimum extent length in Bytes
 *
 * ext3_trim_fs goes through all allocation groups containing Bytes from
 * start to start+len. For each such a group ext3_trim_all_free function
 * is invoked to trim all free space.
 */
int ext3_trim_fs(struct super_block *sb, struct fstrim_range *range)
{
	ext3_grpblk_t last_block, first_block, free_blocks;
	unsigned long first_group, last_group;
	unsigned long group, ngroups;
	struct ext3_group_desc *gdp;
	struct ext3_super_block *es = EXT3_SB(sb)->s_es;
	uint64_t start, len, minlen, trimmed;
	ext3_fsblk_t max_blks = le32_to_cpu(es->s_blocks_count);
	int ret = 0;

	start = range->start >> sb->s_blocksize_bits;
	len = range->len >> sb->s_blocksize_bits;
	minlen = range->minlen >> sb->s_blocksize_bits;
	trimmed = 0;

	if (unlikely(minlen > EXT3_BLOCKS_PER_GROUP(sb)))
		return -EINVAL;
	if (start >= max_blks)
		goto out;
	if (start < le32_to_cpu(es->s_first_data_block)) {
		len -= le32_to_cpu(es->s_first_data_block) - start;
		start = le32_to_cpu(es->s_first_data_block);
	}
	if (start + len > max_blks)
		len = max_blks - start;

	ngroups = EXT3_SB(sb)->s_groups_count;
	smp_rmb();

	/* Determine first and last group to examine based on start and len */
	ext3_get_group_no_and_offset(sb, (ext3_fsblk_t) start,
				     &first_group, &first_block);
	ext3_get_group_no_and_offset(sb, (ext3_fsblk_t) (start + len),
				     &last_group, &last_block);
	last_group = (last_group > ngroups - 1) ? ngroups - 1 : last_group;
	last_block = EXT3_BLOCKS_PER_GROUP(sb);

	if (first_group > last_group)
		return -EINVAL;

	for (group = first_group; group <= last_group; group++) {
		gdp = ext3_get_group_desc(sb, group, NULL);
		if (!gdp)
			break;

		free_blocks = le16_to_cpu(gdp->bg_free_blocks_count);
		if (free_blocks < minlen)
			continue;

		if (len >= EXT3_BLOCKS_PER_GROUP(sb))
			len -= (EXT3_BLOCKS_PER_GROUP(sb) - first_block);
		else
			last_block = first_block + len;

		ret = ext3_trim_all_free(sb, group, first_block,
					last_block, minlen);
		if (ret < 0)
			break;

		trimmed += ret;
		first_block = 0;
	}

	if (ret >= 0)
		ret = 0;

out:
	range->len = trimmed * sb->s_blocksize;

	return ret;
}
+8 −7
Original line number Original line Diff line number Diff line
@@ -69,25 +69,26 @@ int ext3_check_dir_entry (const char * function, struct inode * dir,
	const char * error_msg = NULL;
	const char * error_msg = NULL;
	const int rlen = ext3_rec_len_from_disk(de->rec_len);
	const int rlen = ext3_rec_len_from_disk(de->rec_len);


	if (rlen < EXT3_DIR_REC_LEN(1))
	if (unlikely(rlen < EXT3_DIR_REC_LEN(1)))
		error_msg = "rec_len is smaller than minimal";
		error_msg = "rec_len is smaller than minimal";
	else if (rlen % 4 != 0)
	else if (unlikely(rlen % 4 != 0))
		error_msg = "rec_len % 4 != 0";
		error_msg = "rec_len % 4 != 0";
	else if (rlen < EXT3_DIR_REC_LEN(de->name_len))
	else if (unlikely(rlen < EXT3_DIR_REC_LEN(de->name_len)))
		error_msg = "rec_len is too small for name_len";
		error_msg = "rec_len is too small for name_len";
	else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)
	else if (unlikely((((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)))
		error_msg = "directory entry across blocks";
		error_msg = "directory entry across blocks";
	else if (le32_to_cpu(de->inode) >
	else if (unlikely(le32_to_cpu(de->inode) >
			le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count))
			le32_to_cpu(EXT3_SB(dir->i_sb)->s_es->s_inodes_count)))
		error_msg = "inode out of bounds";
		error_msg = "inode out of bounds";


	if (error_msg != NULL)
	if (unlikely(error_msg != NULL))
		ext3_error (dir->i_sb, function,
		ext3_error (dir->i_sb, function,
			"bad entry in directory #%lu: %s - "
			"bad entry in directory #%lu: %s - "
			"offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
			"offset=%lu, inode=%lu, rec_len=%d, name_len=%d",
			dir->i_ino, error_msg, offset,
			dir->i_ino, error_msg, offset,
			(unsigned long) le32_to_cpu(de->inode),
			(unsigned long) le32_to_cpu(de->inode),
			rlen, de->name_len);
			rlen, de->name_len);

	return error_msg == NULL ? 1 : 0;
	return error_msg == NULL ? 1 : 0;
}
}


Loading