Skip to content

Commit

Permalink
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/jack/linux-fs-2.6

* '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
  • Loading branch information
torvalds committed Jan 11, 2011
2 parents 0945f35 + d96336b commit 40c73ab
Show file tree
Hide file tree
Showing 16 changed files with 545 additions and 142 deletions.
19 changes: 14 additions & 5 deletions fs/ext2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,30 @@

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)
{
unsigned len = le16_to_cpu(dlen);

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

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

Expand Down Expand Up @@ -129,15 +138,15 @@ static void ext2_check_page(struct page *page, int quiet)
p = (ext2_dirent *)(kaddr + offs);
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;
if (rec_len & 3)
if (unlikely(rec_len & 3))
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;
if (((offs + rec_len - 1) ^ offs) & ~(chunk_size-1))
if (unlikely(((offs + rec_len - 1) ^ offs) & ~(chunk_size-1)))
goto Espan;
if (le32_to_cpu(p->inode) > max_inumber)
if (unlikely(le32_to_cpu(p->inode) > max_inumber))
goto Einumber;
}
if (offs != limit)
Expand Down
2 changes: 1 addition & 1 deletion fs/ext2/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static struct dentry *ext2_lookup(struct inode * dir, struct dentry *dentry, str
inode = NULL;
if (ino) {
inode = ext2_iget(dir->i_sb, ino);
if (unlikely(IS_ERR(inode))) {
if (IS_ERR(inode)) {
if (PTR_ERR(inode) == -ESTALE) {
ext2_error(dir->i_sb, __func__,
"deleted inode referenced: %lu",
Expand Down
25 changes: 17 additions & 8 deletions fs/ext2/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ static int ext2_remount (struct super_block * sb, int * flags, char * data);
static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf);
static int ext2_sync_fs(struct super_block *sb, int wait);

void ext2_error (struct super_block * sb, const char * function,
const char * fmt, ...)
void ext2_error(struct super_block *sb, const char *function,
const char *fmt, ...)
{
struct va_format vaf;
va_list args;
struct ext2_sb_info *sbi = EXT2_SB(sb);
struct ext2_super_block *es = sbi->s_es;
Expand All @@ -59,9 +60,13 @@ void ext2_error (struct super_block * sb, const char * function,
}

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

vaf.fmt = fmt;
vaf.va = &args;

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

va_end(args);

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

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

vaf.fmt = fmt;
vaf.va = &args;

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

va_end(args);
}

Expand Down
266 changes: 266 additions & 0 deletions fs/ext3/balloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <linux/ext3_jbd.h>
#include <linux/quotaops.h>
#include <linux/buffer_head.h>
#include <linux/blkdev.h>

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

#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
* @sb: super block
Expand Down Expand Up @@ -1885,3 +1901,253 @@ unsigned long ext3_bg_num_gdb(struct super_block *sb, int 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;
}
Loading

0 comments on commit 40c73ab

Please sign in to comment.