Skip to content
Snippets Groups Projects
Commit c4bc58c2 authored by Johann Lombardi's avatar Johann Lombardi
Browse files

Branch b1_6

b=11039
i=nathan
i=scjody
(get approval by email on rmg@)

Remove obsolete kernel patches.
parent 604d8cc4
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 20072 deletions
This diff is collapsed.
Index: linux-2.6.9-5.0.3.EL/include/asm-i386/thread_info.h
===================================================================
--- linux-2.6.9-5.0.3.EL.orig/include/asm-i386/thread_info.h 2005-02-25 10:25:33.000000000 +0200
+++ linux-2.6.9-5.0.3.EL/include/asm-i386/thread_info.h 2005-02-25 20:19:11.676139032 +0200
@@ -54,7 +54,7 @@
#endif
#define PREEMPT_ACTIVE 0x4000000
-#define THREAD_SIZE (4096)
+#define THREAD_SIZE (8192)
#define STACK_WARN (THREAD_SIZE/8)
/*
This diff is collapsed.
diff -urN clean/arch/mips/kernel/irixelf.c linux-2.6.5-SLES9_SP1_BRANCH_91/arch/mips/kernel/irixelf.c
--- clean/arch/mips/kernel/irixelf.c 2005-01-09 12:25:26.000000000 -0500
+++ linux-2.6.5-SLES9_SP1_BRANCH_91/arch/mips/kernel/irixelf.c 2005-01-19 19:29:59.909824951 -0500
@@ -128,7 +128,7 @@
end = PAGE_ALIGN(end);
if (end <= start)
return;
- do_brk(start, end - start);
+ do_brk_locked(start, end - start);
}
diff -urN clean/arch/x86_64/ia32/ia32_aout.c linux-2.6.5-SLES9_SP1_BRANCH_91/arch/x86_64/ia32/ia32_aout.c
--- clean/arch/x86_64/ia32/ia32_aout.c 2005-01-09 12:25:33.000000000 -0500
+++ linux-2.6.5-SLES9_SP1_BRANCH_91/arch/x86_64/ia32/ia32_aout.c 2005-01-19 19:30:50.255145196 -0500
@@ -114,7 +114,7 @@
start = PAGE_ALIGN(start);
end = PAGE_ALIGN(end);
if (end > start) {
- unsigned long addr = do_brk(start, end - start);
+ unsigned long addr = do_brk_locked(start, end - start);
if (BAD_ADDR(addr))
return addr;
}
@@ -327,7 +327,7 @@
pos = 32;
map_size = ex.a_text+ex.a_data;
- error = do_brk(text_addr & PAGE_MASK, map_size);
+ error = do_brk_locked(text_addr & PAGE_MASK, map_size);
if (error != (text_addr & PAGE_MASK)) {
send_sig(SIGKILL, current, 0);
return error;
@@ -363,7 +363,7 @@
if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
loff_t pos = fd_offset;
- do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+ do_brk_locked(N_TXTADDR(ex), ex.a_text+ex.a_data);
bprm->file->f_op->read(bprm->file,(char *)N_TXTADDR(ex),
ex.a_text+ex.a_data, &pos);
flush_icache_range((unsigned long) N_TXTADDR(ex),
@@ -476,7 +476,7 @@
}
#endif
- do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+ do_brk_locked(start_addr, ex.a_text + ex.a_data + ex.a_bss);
file->f_op->read(file, (char *)start_addr,
ex.a_text + ex.a_data, &pos);
@@ -500,7 +500,7 @@
len = PAGE_ALIGN(ex.a_text + ex.a_data);
bss = ex.a_text + ex.a_data + ex.a_bss;
if (bss > len) {
- error = do_brk(start_addr + len, bss - len);
+ error = do_brk_locked(start_addr + len, bss - len);
retval = error;
if (error != start_addr + len)
goto out;
diff -urN clean/fs/binfmt_aout.c linux-2.6.5-SLES9_SP1_BRANCH_91/fs/binfmt_aout.c
--- clean/fs/binfmt_aout.c 2005-01-09 12:25:33.000000000 -0500
+++ linux-2.6.5-SLES9_SP1_BRANCH_91/fs/binfmt_aout.c 2005-01-19 19:31:40.480490745 -0500
@@ -51,7 +51,7 @@
start = PAGE_ALIGN(start);
end = PAGE_ALIGN(end);
if (end > start) {
- unsigned long addr = do_brk(start, end - start);
+ unsigned long addr = do_brk_locked(start, end - start);
if (BAD_ADDR(addr))
return addr;
}
@@ -323,10 +323,10 @@
loff_t pos = fd_offset;
/* Fuck me plenty... */
/* <AOL></AOL> */
- error = do_brk(N_TXTADDR(ex), ex.a_text);
+ error = do_brk_locked(N_TXTADDR(ex), ex.a_text);
bprm->file->f_op->read(bprm->file, (char *) N_TXTADDR(ex),
ex.a_text, &pos);
- error = do_brk(N_DATADDR(ex), ex.a_data);
+ error = do_brk_locked(N_DATADDR(ex), ex.a_data);
bprm->file->f_op->read(bprm->file, (char *) N_DATADDR(ex),
ex.a_data, &pos);
goto beyond_if;
@@ -347,7 +347,7 @@
map_size = ex.a_text+ex.a_data;
#endif
- error = do_brk(text_addr & PAGE_MASK, map_size);
+ error = do_brk_locked(text_addr & PAGE_MASK, map_size);
if (error != (text_addr & PAGE_MASK)) {
send_sig(SIGKILL, current, 0);
return error;
@@ -381,7 +381,7 @@
if (!bprm->file->f_op->mmap||((fd_offset & ~PAGE_MASK) != 0)) {
loff_t pos = fd_offset;
- do_brk(N_TXTADDR(ex), ex.a_text+ex.a_data);
+ do_brk_locked(N_TXTADDR(ex), ex.a_text+ex.a_data);
bprm->file->f_op->read(bprm->file,(char *)N_TXTADDR(ex),
ex.a_text+ex.a_data, &pos);
flush_icache_range((unsigned long) N_TXTADDR(ex),
@@ -486,7 +486,7 @@
error_time = jiffies;
}
- do_brk(start_addr, ex.a_text + ex.a_data + ex.a_bss);
+ do_brk_locked(start_addr, ex.a_text + ex.a_data + ex.a_bss);
file->f_op->read(file, (char *)start_addr,
ex.a_text + ex.a_data, &pos);
@@ -510,7 +510,7 @@
len = PAGE_ALIGN(ex.a_text + ex.a_data);
bss = ex.a_text + ex.a_data + ex.a_bss;
if (bss > len) {
- error = do_brk(start_addr + len, bss - len);
+ error = do_brk_locked(start_addr + len, bss - len);
retval = error;
if (error != start_addr + len)
goto out;
diff -urN clean/fs/binfmt_elf.c linux-2.6.5-SLES9_SP1_BRANCH_91/fs/binfmt_elf.c
--- clean/fs/binfmt_elf.c 2005-01-09 12:25:33.000000000 -0500
+++ linux-2.6.5-SLES9_SP1_BRANCH_91/fs/binfmt_elf.c 2005-01-19 19:29:59.914823791 -0500
@@ -88,7 +88,7 @@
start = ELF_PAGEALIGN(start);
end = ELF_PAGEALIGN(end);
if (end > start) {
- unsigned long addr = do_brk(start, end - start);
+ unsigned long addr = do_brk_locked(start, end - start);
if (BAD_ADDR(addr))
return addr;
}
@@ -406,7 +406,7 @@
/* Map the last of the bss segment */
if (last_bss > elf_bss) {
- error = do_brk(elf_bss, last_bss - elf_bss);
+ error = do_brk_locked(elf_bss, last_bss - elf_bss);
if (BAD_ADDR(error))
goto out_close;
}
@@ -446,7 +446,7 @@
goto out;
}
- do_brk(0, text_data);
+ do_brk_locked(0, text_data);
if (!interpreter->f_op || !interpreter->f_op->read)
goto out;
if (interpreter->f_op->read(interpreter, addr, text_data, &offset) < 0)
@@ -454,7 +454,7 @@
flush_icache_range((unsigned long)addr,
(unsigned long)addr + text_data);
- do_brk(ELF_PAGESTART(text_data + ELF_MIN_ALIGN - 1),
+ do_brk_locked(ELF_PAGESTART(text_data + ELF_MIN_ALIGN - 1),
interp_ex->a_bss);
elf_entry = interp_ex->a_entry;
@@ -1006,7 +1006,7 @@
len = ELF_PAGESTART(elf_phdata->p_filesz + elf_phdata->p_vaddr + ELF_MIN_ALIGN - 1);
bss = elf_phdata->p_memsz + elf_phdata->p_vaddr;
if (bss > len)
- do_brk(len, bss - len);
+ do_brk_locked(len, bss - len);
error = 0;
out_free_ph:
diff -urN clean/include/linux/mm.h linux-2.6.5-SLES9_SP1_BRANCH_91/include/linux/mm.h
--- clean/include/linux/mm.h 2005-01-09 12:25:34.000000000 -0500
+++ linux-2.6.5-SLES9_SP1_BRANCH_91/include/linux/mm.h 2005-01-19 19:29:59.915823559 -0500
@@ -821,6 +821,7 @@
extern int do_munmap(struct mm_struct *, unsigned long, size_t);
extern unsigned long do_brk(unsigned long, unsigned long);
+extern unsigned long do_brk_locked(unsigned long, unsigned long);
/* vma merging helpers */
static inline void
diff -urN clean/mm/mmap.c linux-2.6.5-SLES9_SP1_BRANCH_91/mm/mmap.c
--- clean/mm/mmap.c 2005-01-09 12:25:34.000000000 -0500
+++ linux-2.6.5-SLES9_SP1_BRANCH_91/mm/mmap.c 2005-01-19 19:29:59.917823095 -0500
@@ -1658,6 +1658,20 @@
EXPORT_SYMBOL(do_brk);
+/* locking version of do_brk. */
+unsigned long do_brk_locked(unsigned long addr, unsigned long len)
+{
+ unsigned long ret;
+
+ down_write(&current->mm->mmap_sem);
+ ret = do_brk(addr, len);
+ up_write(&current->mm->mmap_sem);
+
+ return ret;
+}
+
+EXPORT_SYMBOL(do_brk_locked);
+
/* Release all mmaps. */
void exit_mmap(struct mm_struct *mm)
{
diff -urN clean/mm/nommu.c linux-2.6.5-SLES9_SP1_BRANCH_91/mm/nommu.c
--- clean/mm/nommu.c 2005-01-09 12:25:27.000000000 -0500
+++ linux-2.6.5-SLES9_SP1_BRANCH_91/mm/nommu.c 2005-01-19 19:29:59.918822864 -0500
@@ -227,6 +227,11 @@
return audit_lresult(mm->brk = brk);
}
+unsigned long do_brk_locked(unsigned long addr, unsigned long len)
+{
+ return -ENOMEM;
+}
+
/*
* Combine the mmap "prot" and "flags" argument into one "vm_flags" used
* internally. Essentially, translate the "PROT_xxx" and "MAP_xxx" bits
--- linux-2.6.9/arch/i386/kernel/apic.c.orig 2005-08-04 08:11:13.000000000 -0400
+++ linux-2.6.9/arch/i386/kernel/apic.c 2005-08-04 08:27:04.000000000 -0400
@@ -1125,8 +1125,10 @@ asmlinkage void smp_local_timer_interrup
void smp_apic_timer_interrupt(struct pt_regs regs)
{
+#ifdef CONFIG_4KSTACKS
union irq_ctx *curctx;
union irq_ctx *irqctx;
+#endif
int cpu;
u32 *isp;
@@ -1147,11 +1149,11 @@ void smp_apic_timer_interrupt(struct pt_
* interrupt lock, which is the WrongThing (tm) to do.
*/
irq_enter();
+
+#ifdef CONFIG_4KSTACKS
curctx = (union irq_ctx *) current_thread_info();
irqctx = hardirq_ctx[cpu];
- if (curctx == irqctx) {
- smp_local_timer_interrupt(&regs);
- } else {
+ if (curctx != irqctx) {
/* build the stack frame on the IRQ stack */
isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
irqctx->tinfo.task = curctx->tinfo.task;
@@ -1167,7 +1169,10 @@ void smp_apic_timer_interrupt(struct pt_
: : "b"(isp)
: "memory", "cc", "edx", "ecx"
);
- }
+ } else
+#endif
+ smp_local_timer_interrupt(&regs);
+
irq_exit();
}
--- linux-2.6.9/include/asm-i386/crashdump.h.orig 2005-08-04 08:11:22.000000000 -0400
+++ linux-2.6.9/include/asm-i386/crashdump.h 2005-08-04 08:27:04.000000000 -0400
@@ -48,12 +48,14 @@ extern unsigned long next_ram_page (unsi
static inline void platform_init_stack(void **stackptr)
{
+#ifdef CONFIG_4KSTACKS
*stackptr = (void *)kmalloc(sizeof(union irq_ctx), GFP_KERNEL);
if (*stackptr)
memset(*stackptr, 0, sizeof(union irq_ctx));
else
printk(KERN_WARNING
"crashdump: unable to allocate separate stack\n");
+#endif
}
typedef asmlinkage void (*crashdump_func_t)(struct pt_regs *, void *);
@@ -62,6 +64,7 @@ static inline void platform_start_crashd
crashdump_func_t dumpfunc,
struct pt_regs *regs)
{
+#ifdef CONFIG_4KSTACKS
u32 *dsp;
union irq_ctx * curctx;
union irq_ctx * dumpctx;
@@ -90,6 +93,10 @@ static inline void platform_start_crashd
: "memory", "cc", "edx", "ecx"
);
}
+#else
+ dumpfunc(regs, NULL);
+#endif
+
}
#define platform_cleanup_stack(stackptr) \
Index: linux-2.6.5-SLES9_SP1_BRANCH_2004111114454891/drivers/block/ll_rw_blk.c
===================================================================
--- linux-2.6.5-SLES9_SP1_BRANCH_2004111114454891.orig/drivers/block/ll_rw_blk.c 2005-06-28 01:53:39.000000000 -0600
+++ linux-2.6.5-SLES9_SP1_BRANCH_2004111114454891/drivers/block/ll_rw_blk.c 2005-06-28 01:58:45.000000000 -0600
@@ -1380,12 +1380,12 @@
static int __make_request(request_queue_t *, struct bio *);
static elevator_t *chosen_elevator =
-#if defined(CONFIG_IOSCHED_AS)
+#if defined(CONFIG_IOSCHED_CFQ)
+ &iosched_cfq;
+#elif defined(CONFIG_IOSCHED_AS)
&iosched_as;
#elif defined(CONFIG_IOSCHED_DEADLINE)
&iosched_deadline;
-#elif defined(CONFIG_IOSCHED_CFQ)
- &iosched_cfq;
#elif defined(CONFIG_IOSCHED_NOOP)
&elevator_noop;
#else
Index: linux-stage/include/linux/ext3_fs.h
===================================================================
--- linux-stage.orig/include/linux/ext3_fs.h
+++ linux-stage/include/linux/ext3_fs.h
@@ -921,6 +921,7 @@ extern unsigned ext3_list_backups(struct
unsigned *five, unsigned *seven);
/* super.c */
+extern void ext3_commit_super (struct super_block *, struct ext3_super_block *, int);
extern void ext3_error (struct super_block *, const char *, const char *, ...)
__attribute__ ((format (printf, 3, 4)));
extern void __ext3_std_error (struct super_block *, const char *, int);
Index: linux-stage/fs/ext3/super.c
===================================================================
--- linux-stage.orig/fs/ext3/super.c
+++ linux-stage/fs/ext3/super.c
@@ -47,9 +47,6 @@ static int ext3_load_journal(struct supe
unsigned long journal_devnum);
static int ext3_create_journal(struct super_block *, struct ext3_super_block *,
int);
-static void ext3_commit_super (struct super_block * sb,
- struct ext3_super_block * es,
- int sync);
static void ext3_mark_recovery_complete(struct super_block * sb,
struct ext3_super_block * es);
static void ext3_clear_journal_err(struct super_block * sb,
@@ -2175,7 +2172,7 @@ static int ext3_create_journal(struct su
return 0;
}
-static void ext3_commit_super (struct super_block * sb,
+void ext3_commit_super (struct super_block * sb,
struct ext3_super_block * es,
int sync)
{
Index: linux-stage/fs/ext3/namei.c
===================================================================
--- linux-stage.orig/fs/ext3/namei.c
+++ linux-stage/fs/ext3/namei.c
@@ -1591,7 +1591,7 @@ static int ext3_delete_entry (handle_t *
struct buffer_head * bh)
{
struct ext3_dir_entry_2 * de, * pde;
- int i;
+ int i, err;
i = 0;
pde = NULL;
@@ -1601,7 +1601,9 @@ static int ext3_delete_entry (handle_t *
return -EIO;
if (de == de_del) {
BUFFER_TRACE(bh, "get_write_access");
- ext3_journal_get_write_access(handle, bh);
+ err = ext3_journal_get_write_access(handle, bh);
+ if (err)
+ return err;
if (pde)
pde->rec_len =
cpu_to_le16(le16_to_cpu(pde->rec_len) +
Index: linux-stage/fs/ext3/inode.c
===================================================================
--- linux-stage.orig/fs/ext3/inode.c
+++ linux-stage/fs/ext3/inode.c
@@ -1838,8 +1838,18 @@ ext3_clear_blocks(handle_t *handle, stru
ext3_mark_inode_dirty(handle, inode);
ext3_journal_test_restart(handle, inode);
if (bh) {
+ int err;
BUFFER_TRACE(bh, "retaking write access");
- ext3_journal_get_write_access(handle, bh);
+ err = ext3_journal_get_write_access(handle, bh);
+ if (err) {
+ struct super_block *sb = inode->i_sb;
+ struct ext3_super_block *es = EXT3_SB(sb)->s_es;
+ printk (KERN_CRIT"EXT3-fs: can't continue truncate\n");
+ EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS;
+ es->s_state |= cpu_to_le16(EXT3_ERROR_FS);
+ ext3_commit_super(sb, es, 1);
+ return;
+ }
}
}
- minor fixes
- multiblock get_block() for direct I/O
Index: linux-2.6.9-full/include/linux/ext3_extents.h
===================================================================
--- linux-2.6.9-full.orig/include/linux/ext3_extents.h 2007-03-23 15:57:00.000000000 +0300
+++ linux-2.6.9-full/include/linux/ext3_extents.h 2007-03-28 00:59:32.000000000 +0400
@@ -205,7 +205,7 @@ typedef int (*ext_prepare_callback)(stru
#define EXT_DEPTH(__tree__) (EXT_ROOT_HDR(__tree__)->eh_depth)
#define EXT_GENERATION(__tree__) EXT_HDR_GEN(EXT_ROOT_HDR(__tree__))
-#define EXT_ASSERT(__x__) if (!(__x__)) BUG();
+#define EXT_ASSERT(__x__) if (unlikely(!(__x__))) BUG();
#define EXT_CHECK_PATH(tree,path) \
{ \
Index: linux-2.6.9-full/fs/ext3/extents.c
===================================================================
--- linux-2.6.9-full.orig/fs/ext3/extents.c 2007-03-23 15:57:00.000000000 +0300
+++ linux-2.6.9-full/fs/ext3/extents.c 2007-03-28 00:59:41.000000000 +0400
@@ -895,6 +895,8 @@ repeat:
/* if we found index with free entry, then use that
* entry: create all needed subtree and add new leaf */
err = ext3_ext_split(handle, tree, path, newext, i);
+ if (err)
+ goto out;
/* refill path */
ext3_ext_drop_refs(path);
@@ -904,12 +906,16 @@ repeat:
} else {
/* tree is full, time to grow in depth */
err = ext3_ext_grow_indepth(handle, tree, path, newext);
+ if (err)
+ goto out;
/* refill path */
ext3_ext_drop_refs(path);
path = ext3_ext_find_extent(tree, newext->ee_block, path);
- if (IS_ERR(path))
+ if (IS_ERR(path)) {
err = PTR_ERR(path);
+ goto out;
+ }
/*
* only first (depth 0 -> 1) produces free space
@@ -922,10 +928,8 @@ repeat:
}
}
- if (err)
- return err;
-
- return 0;
+out:
+ return err;
}
/*
@@ -1992,21 +1996,10 @@ static int ext3_new_block_cb(handle_t *h
EXT_ASSERT(ex->ee_start);
EXT_ASSERT(ex->ee_len);
- /* reuse block from the extent to order data/metadata */
- newblock = ex->ee_start++;
- ex->ee_len--;
- if (ex->ee_len == 0) {
- ex->ee_len = 1;
- /* allocate new block for the extent */
- goal = ext3_ext_find_goal(inode, path, ex->ee_block);
- ex->ee_start = ext3_new_block(handle, inode, goal, err);
- ex->ee_start_hi = 0;
- if (ex->ee_start == 0) {
- /* error occured: restore old extent */
- ex->ee_start = newblock;
- return 0;
- }
- }
+ /* allocate new block for the extent */
+ goal = ext3_ext_find_goal(inode, path, ex->ee_block);
+ newblock = ext3_new_block(handle, inode, goal, err);
+
return newblock;
}
Index: linux-2.6.5-7.283-full/include/linux/ext3_fs.h
===================================================================
--- linux-2.6.5-7.283-full.orig/include/linux/ext3_fs.h 2007-03-28 02:13:37.000000000 +0400
+++ linux-2.6.5-7.283-full/include/linux/ext3_fs.h 2007-03-28 02:21:37.000000000 +0400
@@ -815,7 +815,7 @@ extern struct inode_operations ext3_fast
/* extents.c */
extern int ext3_ext_writepage_trans_blocks(struct inode *, int);
-extern int ext3_ext_get_block(handle_t *, struct inode *, long,
+extern int ext3_ext_get_block(handle_t *, struct inode *, long, int,
struct buffer_head *, int, int);
extern void ext3_ext_truncate(struct inode *, struct page *);
extern void ext3_ext_init(struct super_block *);
Index: linux-2.6.5-7.283-full/fs/ext3/extents.c
===================================================================
--- linux-2.6.5-7.283-full.orig/fs/ext3/extents.c 2007-03-28 02:14:25.000000000 +0400
+++ linux-2.6.5-7.283-full/fs/ext3/extents.c 2007-03-28 02:21:37.000000000 +0400
@@ -2024,7 +2024,8 @@ void ext3_init_tree_desc(struct ext3_ext
}
int ext3_ext_get_block(handle_t *handle, struct inode *inode,
- long iblock, struct buffer_head *bh_result,
+ long iblock, int max_blocks,
+ struct buffer_head *bh_result,
int create, int extend_disksize)
{
struct ext3_ext_path *path = NULL;
@@ -2032,6 +2033,11 @@ int ext3_ext_get_block(handle_t *handle,
struct ext3_extent *ex;
int goal, newblock, err = 0, depth;
struct ext3_extents_tree tree;
+ unsigned long next;
+ int allocated = 0;
+
+ /* until we have multiblock allocation */
+ max_blocks = 1;
__clear_bit(BH_New, &bh_result->b_state);
ext3_init_tree_desc(&tree, inode);
@@ -2051,6 +2057,9 @@ int ext3_ext_get_block(handle_t *handle,
} else if (goal == EXT3_EXT_CACHE_EXTENT) {
/* block is already allocated */
newblock = iblock - newex.ee_block + newex.ee_start;
+ /* number of remaining blocks in the extent */
+ EXT_ASSERT(iblock >= newex.ee_block);
+ allocated = newex.ee_len - (iblock - newex.ee_block);
goto out;
} else {
EXT_ASSERT(0);
@@ -2078,6 +2087,8 @@ int ext3_ext_get_block(handle_t *handle,
/* if found exent covers block, simple return it */
if (iblock >= ex->ee_block && iblock < ex->ee_block + ex->ee_len) {
newblock = iblock - ex->ee_block + ex->ee_start;
+ /* number of remaining blocks in the extent */
+ allocated = ex->ee_len - (iblock - ex->ee_block);
ext_debug(&tree, "%d fit into %d:%d -> %d\n",
(int) iblock, ex->ee_block, ex->ee_len,
newblock);
@@ -2098,6 +2109,15 @@ int ext3_ext_get_block(handle_t *handle,
goto out2;
}
+ /* find next allocated block so that we know how many
+ * blocks we can allocate without ovelapping next extent */
+ EXT_ASSERT(iblock >= ex->ee_block + ex->ee_len);
+ next = ext3_ext_next_allocated_block(path);
+ EXT_ASSERT(next > iblock);
+ allocated = next - iblock;
+ if (allocated > max_blocks)
+ allocated = max_blocks;
+
/* allocate new block */
goal = ext3_ext_find_goal(inode, path, iblock);
newblock = ext3_new_block(handle, inode, goal, &err);
@@ -2112,8 +2132,11 @@ int ext3_ext_get_block(handle_t *handle,
newex.ee_start_hi = 0;
newex.ee_len = 1;
err = ext3_ext_insert_extent(handle, &tree, path, &newex);
- if (err)
+ if (err) {
+ /* free data blocks we just allocated */
+ ext3_free_blocks(handle, inode, newex.ee_start, newex.ee_len);
goto out2;
+ }
if (extend_disksize && inode->i_size > EXT3_I(inode)->i_disksize)
EXT3_I(inode)->i_disksize = inode->i_size;
@@ -2125,10 +2148,13 @@ int ext3_ext_get_block(handle_t *handle,
ext3_ext_put_in_cache(&tree, newex.ee_block, newex.ee_len,
newex.ee_start, EXT3_EXT_CACHE_EXTENT);
out:
+ if (allocated > max_blocks)
+ allocated = max_blocks;
ext3_ext_show_leaf(&tree, path);
__set_bit(BH_Mapped, &bh_result->b_state);
bh_result->b_bdev = inode->i_sb->s_bdev;
bh_result->b_blocknr = newblock;
+ bh_result->b_size = (allocated << inode->i_blkbits);
out2:
if (path) {
ext3_ext_drop_refs(path);
Index: linux-2.6.5-7.283-full/fs/ext3/inode.c
===================================================================
--- linux-2.6.5-7.283-full.orig/fs/ext3/inode.c 2007-03-28 02:13:37.000000000 +0400
+++ linux-2.6.5-7.283-full/fs/ext3/inode.c 2007-03-28 02:50:19.000000000 +0400
@@ -800,13 +800,17 @@ changed:
static inline int
ext3_get_block_wrap(handle_t *handle, struct inode *inode, long block,
- struct buffer_head *bh, int create, int extend_disksize)
+ int max_blocks, struct buffer_head *bh, int create,
+ int extend_disksize)
{
+ int ret;
if (EXT3_I(inode)->i_flags & EXT3_EXTENTS_FL)
- return ext3_ext_get_block(handle, inode, block, bh, create,
- extend_disksize);
- return ext3_get_block_handle(handle, inode, block, bh, create,
+ return ext3_ext_get_block(handle, inode, block, max_blocks,
+ bh, create, extend_disksize);
+ ret = ext3_get_block_handle(handle, inode, block, bh, create,
extend_disksize);
+ bh->b_size = (1 << inode->i_blkbits);
+ return ret;
}
static int ext3_get_block(struct inode *inode, sector_t iblock,
@@ -819,7 +823,7 @@ static int ext3_get_block(struct inode *
handle = ext3_journal_current_handle();
J_ASSERT(handle != 0);
}
- ret = ext3_get_block_wrap(handle, inode, iblock,
+ ret = ext3_get_block_wrap(handle, inode, iblock, 1,
bh_result, create, 1);
return ret;
}
@@ -847,10 +851,8 @@ ext3_direct_io_get_blocks(struct inode *
}
}
if (ret == 0)
- ret = ext3_get_block_wrap(handle, inode, iblock,
+ ret = ext3_get_block_wrap(handle, inode, iblock, max_blocks,
bh_result, create, 0);
- if (ret == 0)
- bh_result->b_size = (1 << inode->i_blkbits);
return ret;
}
@@ -869,7 +871,7 @@ struct buffer_head *ext3_getblk(handle_t
dummy.b_state = 0;
dummy.b_blocknr = -1000;
buffer_trace_init(&dummy.b_history);
- *errp = ext3_get_block_wrap(handle, inode, block, &dummy, create, 1);
+ *errp = ext3_get_block_wrap(handle, inode, block, 1, &dummy, create, 1);
if (!*errp && buffer_mapped(&dummy)) {
struct buffer_head *bh;
bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
--- linux-2.6.9-full/include/linux/ext3_fs.h 2007-03-23 15:57:00.000000000 +0300
+++ linux-2.6.9-full/include/linux/ext3_fs.h 2007-02-16 17:16:23.000000000 +0300
@@ -850,7 +850,7 @@ extern struct inode_operations ext3_fast
/* extents.c */
extern int ext3_ext_writepage_trans_blocks(struct inode *, int);
-extern int ext3_ext_get_block(handle_t *, struct inode *, long,
+extern int ext3_ext_get_block(handle_t *, struct inode *, long, int,
struct buffer_head *, int, int);
extern void ext3_ext_truncate(struct inode *, struct page *);
extern void ext3_ext_init(struct super_block *);
--- linux-2.6.9-full/fs/ext3/extents.c 2007-03-23 15:57:00.000000000 +0300
+++ linux-2.6.9-full/fs/ext3/extents.c 2007-02-22 17:45:05.000000000 +0300
@@ -2031,7 +2168,8 @@ void ext3_init_tree_desc(struct ext3_ext
}
int ext3_ext_get_block(handle_t *handle, struct inode *inode,
- long iblock, struct buffer_head *bh_result,
+ long iblock, int max_blocks,
+ struct buffer_head *bh_result,
int create, int extend_disksize)
{
struct ext3_ext_path *path = NULL;
@@ -2039,6 +2177,11 @@ int ext3_ext_get_block(handle_t *handle,
struct ext3_extent *ex;
int goal, newblock, err = 0, depth;
struct ext3_extents_tree tree;
+ unsigned long next;
+ int allocated = 0;
+
+ /* until we have multiblock allocation */
+ max_blocks = 1;
clear_buffer_new(bh_result);
ext3_init_tree_desc(&tree, inode);
@@ -2058,6 +2201,9 @@ int ext3_ext_get_block(handle_t *handle,
} else if (goal == EXT3_EXT_CACHE_EXTENT) {
/* block is already allocated */
newblock = iblock - newex.ee_block + newex.ee_start;
+ /* number of remaining blocks in the extent */
+ EXT_ASSERT(iblock >= newex.ee_block);
+ allocated = newex.ee_len - (iblock - newex.ee_block);
goto out;
} else {
EXT_ASSERT(0);
@@ -2085,6 +2231,8 @@ int ext3_ext_get_block(handle_t *handle,
/* if found exent covers block, simple return it */
if (iblock >= ex->ee_block && iblock < ex->ee_block + ex->ee_len) {
newblock = iblock - ex->ee_block + ex->ee_start;
+ /* number of remaining blocks in the extent */
+ allocated = ex->ee_len - (iblock - ex->ee_block);
ext_debug(&tree, "%d fit into %d:%d -> %d\n",
(int) iblock, ex->ee_block, ex->ee_len,
newblock);
@@ -2105,6 +2253,15 @@ int ext3_ext_get_block(handle_t *handle,
goto out2;
}
+ /* find next allocated block so that we know how many
+ * blocks we can allocate without ovelapping next extent */
+ EXT_ASSERT(iblock >= ex->ee_block + ex->ee_len);
+ next = ext3_ext_next_allocated_block(path);
+ EXT_ASSERT(next > iblock);
+ allocated = next - iblock;
+ if (allocated > max_blocks)
+ allocated = max_blocks;
+
/* allocate new block */
goal = ext3_ext_find_goal(inode, path, iblock);
newblock = ext3_new_block(handle, inode, goal, &err);
@@ -2119,8 +2276,11 @@ int ext3_ext_get_block(handle_t *handle,
newex.ee_start_hi = 0;
newex.ee_len = 1;
err = ext3_ext_insert_extent(handle, &tree, path, &newex);
- if (err)
+ if (err) {
+ /* free data blocks we just allocated */
+ ext3_free_blocks(handle, inode, newex.ee_start, newex.ee_len);
goto out2;
+ }
if (extend_disksize && inode->i_size > EXT3_I(inode)->i_disksize)
EXT3_I(inode)->i_disksize = inode->i_size;
@@ -2132,8 +2292,11 @@ int ext3_ext_get_block(handle_t *handle,
ext3_ext_put_in_cache(&tree, newex.ee_block, newex.ee_len,
newex.ee_start, EXT3_EXT_CACHE_EXTENT);
out:
+ if (allocated > max_blocks)
+ allocated = max_blocks;
ext3_ext_show_leaf(&tree, path);
map_bh(bh_result, inode->i_sb, newblock);
+ bh_result->b_size = (allocated << inode->i_blkbits);
out2:
if (path) {
ext3_ext_drop_refs(path);
--- linux-2.6.9-full/fs/ext3/inode.c 2007-03-23 15:57:00.000000000 +0300
+++ linux-2.6.9-full/fs/ext3/inode.c 2007-02-16 17:17:03.000000000 +0300
@@ -798,13 +798,17 @@ changed:
static inline int
ext3_get_block_wrap(handle_t *handle, struct inode *inode, long block,
- struct buffer_head *bh, int create, int extend_disksize)
+ int max_blocks, struct buffer_head *bh, int create,
+ int extend_disksize)
{
+ int ret;
if (EXT3_I(inode)->i_flags & EXT3_EXTENTS_FL)
- return ext3_ext_get_block(handle, inode, block, bh, create,
- extend_disksize);
- return ext3_get_block_handle(handle, inode, block, bh, create,
+ return ext3_ext_get_block(handle, inode, block, max_blocks,
+ bh, create, extend_disksize);
+ ret = ext3_get_block_handle(handle, inode, block, bh, create,
extend_disksize);
+ bh->b_size = (1 << inode->i_blkbits);
+ return ret;
}
static int ext3_get_block(struct inode *inode, sector_t iblock,
@@ -817,7 +821,7 @@ static int ext3_get_block(struct inode *
handle = ext3_journal_current_handle();
J_ASSERT(handle != 0);
}
- ret = ext3_get_block_wrap(handle, inode, iblock,
+ ret = ext3_get_block_wrap(handle, inode, iblock, 1,
bh_result, create, 1);
return ret;
}
@@ -862,9 +866,8 @@ ext3_direct_io_get_blocks(struct inode *
get_block:
if (ret == 0)
- ret = ext3_get_block_wrap(handle, inode, iblock,
+ ret = ext3_get_block_wrap(handle, inode, iblock, max_blocks,
bh_result, create, 0);
- bh_result->b_size = (1 << inode->i_blkbits);
return ret;
}
@@ -882,7 +885,7 @@ struct buffer_head *ext3_getblk(handle_t
dummy.b_state = 0;
dummy.b_blocknr = -1000;
buffer_trace_init(&dummy.b_history);
- *errp = ext3_get_block_wrap(handle, inode, block, &dummy, create, 1);
+ *errp = ext3_get_block_wrap(handle, inode, block, 1, &dummy, create, 1);
if (!*errp && buffer_mapped(&dummy)) {
struct buffer_head *bh;
bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
Index: linux-2.6.9-full/include/linux/ext3_extents.h
===================================================================
--- linux-2.6.9-full.orig/include/linux/ext3_extents.h 2007-03-23 15:57:00.000000000 +0300
+++ linux-2.6.9-full/include/linux/ext3_extents.h 2007-03-26 22:08:16.000000000 +0400
@@ -242,6 +242,8 @@ struct ext3_extent_tree_stats {
int leaf_num;
};
+extern int ext3_ext_search_left(struct ext3_extents_tree *, struct ext3_ext_path *, unsigned long *, unsigned long *);
+extern int ext3_ext_search_right(struct ext3_extents_tree *, struct ext3_ext_path *, unsigned long *, unsigned long *);
extern void ext3_init_tree_desc(struct ext3_extents_tree *, struct inode *);
extern int ext3_extent_tree_init(handle_t *, struct ext3_extents_tree *);
extern int ext3_ext_calc_credits_for_insert(struct ext3_extents_tree *, struct ext3_ext_path *);
Index: linux-2.6.9-full/fs/ext3/extents.c
===================================================================
--- linux-2.6.9-full.orig/fs/ext3/extents.c 2007-03-23 15:57:00.000000000 +0300
+++ linux-2.6.9-full/fs/ext3/extents.c 2007-03-26 22:07:37.000000000 +0400
@@ -929,6 +929,150 @@ repeat:
}
/*
+ * search the closest allocated block to the left for *logical
+ * and returns it at @logical + it's physical address at @phys
+ * if *logical is the smallest allocated block, the function
+ * returns 0 at @phys
+ * return value contains 0 (success) or error code
+ */
+int
+ext3_ext_search_left(struct ext3_extents_tree *tree, struct ext3_ext_path *path,
+ unsigned long *logical, unsigned long *phys)
+{
+ struct ext3_extent_idx *ix;
+ struct ext3_extent *ex;
+ int depth;
+
+ BUG_ON(path == NULL);
+ depth = path->p_depth;
+ *phys = 0;
+
+ if (depth == 0 && path->p_ext == NULL)
+ return 0;
+
+ /* usually extent in the path covers blocks smaller
+ * then *logical, but it can be that extent is the
+ * first one in the file */
+
+ ex = path[depth].p_ext;
+ if (*logical < ex->ee_block) {
+ BUG_ON(EXT_FIRST_EXTENT(path[depth].p_hdr) != ex);
+ while (--depth >= 0) {
+ ix = path[depth].p_idx;
+ BUG_ON(ix != EXT_FIRST_INDEX(path[depth].p_hdr));
+ }
+ return 0;
+ }
+
+ BUG_ON(*logical < ex->ee_block + ex->ee_len);
+
+ *logical = ex->ee_block + ex->ee_len - 1;
+ *phys = ex->ee_start + ex->ee_len - 1;
+ return 0;
+}
+EXPORT_SYMBOL(ext3_ext_search_left);
+
+/*
+ * search the closest allocated block to the right for *logical
+ * and returns it at @logical + it's physical address at @phys
+ * if *logical is the smallest allocated block, the function
+ * returns 0 at @phys
+ * return value contains 0 (success) or error code
+ */
+int
+ext3_ext_search_right(struct ext3_extents_tree *tree, struct ext3_ext_path *path,
+ unsigned long *logical, unsigned long *phys)
+{
+ struct buffer_head *bh = NULL;
+ struct ext3_extent_header *eh;
+ struct ext3_extent_idx *ix;
+ struct ext3_extent *ex;
+ unsigned long block;
+ int depth;
+
+ BUG_ON(path == NULL);
+ depth = path->p_depth;
+ *phys = 0;
+
+ if (depth == 0 && path->p_ext == NULL)
+ return 0;
+
+ /* usually extent in the path covers blocks smaller
+ * then *logical, but it can be that extent is the
+ * first one in the file */
+
+ ex = path[depth].p_ext;
+ if (*logical < ex->ee_block) {
+ BUG_ON(EXT_FIRST_EXTENT(path[depth].p_hdr) != ex);
+ while (--depth >= 0) {
+ ix = path[depth].p_idx;
+ BUG_ON(ix != EXT_FIRST_INDEX(path[depth].p_hdr));
+ }
+ *logical = ex->ee_block;
+ *phys = ex->ee_start;
+ return 0;
+ }
+
+ BUG_ON(*logical < ex->ee_block + ex->ee_len);
+
+ if (ex != EXT_LAST_EXTENT(path[depth].p_hdr)) {
+ /* next allocated block in this leaf */
+ ex++;
+ *logical = ex->ee_block;
+ *phys = ex->ee_start;
+ return 0;
+ }
+
+ /* go up and search for index to the right */
+ while (--depth >= 0) {
+ ix = path[depth].p_idx;
+ if (ix != EXT_LAST_INDEX(path[depth].p_hdr))
+ break;
+ }
+
+ if (depth < 0) {
+ /* we've gone up to the root and
+ * found no index to the right */
+ return 0;
+ }
+
+ /* we've found index to the right, let's
+ * follow it and find the closest allocated
+ * block to the right */
+ ix++;
+ block = ix->ei_leaf;
+ while (++depth < path->p_depth) {
+ bh = sb_bread(tree->inode->i_sb, block);
+ if (bh == NULL)
+ return -EIO;
+ eh = EXT_BLOCK_HDR(bh);
+ if (ext3_ext_check_header(eh)) {
+ brelse(bh);
+ return -EIO;
+ }
+ ix = EXT_FIRST_INDEX(eh);
+ block = ix->ei_leaf;
+ brelse(bh);
+ }
+
+ bh = sb_bread(tree->inode->i_sb, block);
+ if (bh == NULL)
+ return -EIO;
+ eh = EXT_BLOCK_HDR(bh);
+ if (ext3_ext_check_header(eh)) {
+ brelse(bh);
+ return -EIO;
+ }
+ ex = EXT_FIRST_EXTENT(eh);
+ *logical = ex->ee_block;
+ *phys = ex->ee_start;
+ brelse(bh);
+ return 0;
+
+}
+EXPORT_SYMBOL(ext3_ext_search_right);
+
+/*
* returns allocated block in subsequent extent or EXT_MAX_BLOCK
* NOTE: it consider block number from index entry as
* allocated block. thus, index entries have to be consistent
Signed-off-by: Johann Lombardi <johann.lombardi@bull.net>
Index: linux-2.6.9-full/fs/ext3/super.c
===================================================================
--- linux-2.6.9-full.orig/fs/ext3/super.c 2006-05-20 01:14:14.000000000 +0400
+++ linux-2.6.9-full/fs/ext3/super.c 2006-05-20 01:17:10.000000000 +0400
@@ -39,7 +39,8 @@
#include "xattr.h"
#include "acl.h"
-static int ext3_load_journal(struct super_block *, struct ext3_super_block *);
+static int ext3_load_journal(struct super_block *, struct ext3_super_block *,
+ unsigned long journal_devnum);
static int ext3_create_journal(struct super_block *, struct ext3_super_block *,
int);
static void ext3_commit_super (struct super_block * sb,
@@ -591,7 +592,7 @@ enum {
Opt_nouid32, Opt_check, Opt_nocheck, Opt_debug, Opt_oldalloc, Opt_orlov,
Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
Opt_reservation, Opt_noreservation, Opt_noload,
- Opt_commit, Opt_journal_update, Opt_journal_inum,
+ Opt_commit, Opt_journal_update, Opt_journal_inum, Opt_journal_dev,
Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0,
@@ -630,6 +631,7 @@ static match_table_t tokens = {
{Opt_commit, "commit=%u"},
{Opt_journal_update, "journal=update"},
{Opt_journal_inum, "journal=%u"},
+ {Opt_journal_dev, "journal_dev=%u"},
{Opt_abort, "abort"},
{Opt_data_journal, "data=journal"},
{Opt_data_ordered, "data=ordered"},
@@ -675,8 +677,9 @@ static unsigned long get_sb_block(void *
return sb_block;
}
-static int parse_options (char * options, struct super_block *sb,
- unsigned long * inum, unsigned long *n_blocks_count, int is_remount)
+static int parse_options (char *options, struct super_block *sb,
+ unsigned long *inum, unsigned long *journal_devnum,
+ unsigned long *n_blocks_count, int is_remount)
{
struct ext3_sb_info *sbi = EXT3_SB(sb);
char * p;
@@ -816,6 +819,16 @@ static int parse_options (char * options
return 0;
*inum = option;
break;
+ case Opt_journal_dev:
+ if (is_remount) {
+ printk(KERN_ERR "EXT3-fs: cannot specify "
+ "journal on remount\n");
+ return 0;
+ }
+ if (match_int(&args[0], &option))
+ return 0;
+ *journal_devnum = option;
+ break;
case Opt_noload:
set_opt (sbi->s_mount_opt, NOLOAD);
break;
@@ -1278,6 +1291,7 @@ static int ext3_fill_super (struct super
unsigned long logic_sb_block;
unsigned long offset = 0;
unsigned long journal_inum = 0;
+ unsigned long journal_devnum = 0;
unsigned long def_mount_opts;
struct inode *root;
int blocksize;
@@ -1361,7 +1375,8 @@ static int ext3_fill_super (struct super
set_opt(sbi->s_mount_opt, RESERVATION);
- if (!parse_options ((char *) data, sb, &journal_inum, NULL, 0))
+ if (!parse_options ((char *) data, sb, &journal_inum, &journal_devnum,
+ NULL, 0))
goto failed_mount;
set_sb_time_gran(sb, 1000000000U);
@@ -1567,7 +1582,7 @@ static int ext3_fill_super (struct super
*/
if (!test_opt(sb, NOLOAD) &&
EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
- if (ext3_load_journal(sb, es))
+ if (ext3_load_journal(sb, es, journal_devnum))
goto failed_mount2;
} else if (journal_inum) {
if (ext3_create_journal(sb, es, journal_inum))
@@ -1831,15 +1846,24 @@ out_bdev:
return NULL;
}
-static int ext3_load_journal(struct super_block * sb,
- struct ext3_super_block * es)
+static int ext3_load_journal(struct super_block *sb,
+ struct ext3_super_block *es,
+ unsigned long journal_devnum)
{
journal_t *journal;
int journal_inum = le32_to_cpu(es->s_journal_inum);
- dev_t journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
+ dev_t journal_dev;
int err = 0;
int really_read_only;
+ if (journal_devnum &&
+ journal_devnum != le32_to_cpu(es->s_journal_dev)) {
+ printk(KERN_INFO "EXT3-fs: external journal device major/minor "
+ "numbers have changed\n");
+ journal_dev = new_decode_dev(journal_devnum);
+ } else
+ journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
+
really_read_only = bdev_read_only(sb->s_bdev);
/*
@@ -1898,6 +1922,16 @@ static int ext3_load_journal(struct supe
EXT3_SB(sb)->s_journal = journal;
ext3_clear_journal_err(sb, es);
+
+ if (journal_devnum &&
+ journal_devnum != le32_to_cpu(es->s_journal_dev)) {
+ es->s_journal_dev = cpu_to_le32(journal_devnum);
+ sb->s_dirt = 1;
+
+ /* Make sure we flush the recovery flag to disk. */
+ ext3_commit_super(sb, es, 1);
+ }
+
return 0;
}
@@ -2105,13 +2139,13 @@ int ext3_remount (struct super_block * s
{
struct ext3_super_block * es;
struct ext3_sb_info *sbi = EXT3_SB(sb);
- unsigned long tmp;
+ unsigned long tmp1, tmp2;
unsigned long n_blocks_count = 0;
/*
* Allow the "check" option to be passed as a remount option.
*/
- if (!parse_options(data, sb, &tmp, &n_blocks_count, 1))
+ if (!parse_options(data, sb, &tmp1, &tmp2, &n_blocks_count, 1))
return -EINVAL;
if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
Index: linux-2.6.16.27-0.9-full/include/linux/ext3_fs_i.h
===================================================================
--- linux-2.6.16.27-0.9-full.orig/include/linux/ext3_fs_i.h 2007-03-28 16:03:20.000000000 +0400
+++ linux-2.6.16.27-0.9-full/include/linux/ext3_fs_i.h 2007-03-28 19:40:53.000000000 +0400
@@ -139,6 +139,8 @@ struct ext3_inode_info {
/* mballoc */
struct list_head i_prealloc_list;
spinlock_t i_prealloc_lock;
+
+ void *i_filterdata;
};
#endif /* _LINUX_EXT3_FS_I */
Index: linux-2.6.16.27-0.9-full/fs/ext3/super.c
===================================================================
--- linux-2.6.16.27-0.9-full.orig/fs/ext3/super.c 2007-03-28 18:20:17.000000000 +0400
+++ linux-2.6.16.27-0.9-full/fs/ext3/super.c 2007-03-28 19:40:53.000000000 +0400
@@ -462,6 +462,7 @@ static struct inode *ext3_alloc_inode(st
memset(&ei->i_cached_extent, 0, sizeof(ei->i_cached_extent));
INIT_LIST_HEAD(&ei->i_prealloc_list);
spin_lock_init(&ei->i_prealloc_lock);
+ ei->i_filterdata = NULL;
return &ei->vfs_inode;
}
Index: linux-2.6.5-SLES9_SP1_BRANCH_2004111114454891/fs/ext3/namei.c
===================================================================
--- linux-2.6.5-SLES9_SP1_BRANCH_2004111114454891.orig/fs/ext3/namei.c 2005-04-04 05:06:46.000000000 -0600
+++ linux-2.6.5-SLES9_SP1_BRANCH_2004111114454891/fs/ext3/namei.c 2005-04-04 05:09:18.000000000 -0600
@@ -926,8 +926,16 @@
struct inode *dir = dentry->d_parent->d_inode;
sb = dir->i_sb;
- if (!(frame = dx_probe (dentry, 0, &hinfo, frames, err)))
- return NULL;
+ /* NFS may look up ".." - look at dx_root directory block */
+ if (namelen > 2 || name[0] != '.'||(name[1] != '.' && name[1] != '\0')){
+ if (!(frame = dx_probe(dentry, NULL, &hinfo, frames, err)))
+ return NULL;
+ } else {
+ frame = frames;
+ frame->bh = NULL; /* for dx_release() */
+ frame->at = (struct dx_entry *)frames; /* hack for zero entry*/
+ dx_set_block(frame->at, 0); /* dx_root block is 0 */
+ }
hash = hinfo.hash;
do {
block = dx_get_block(frame->at);
This diff is collapsed.
Index: linux-2.6.16-sles10/fs/ext3/inode.c
===================================================================
--- linux-2.6.16-sles10.orig/fs/ext3/inode.c
+++ linux-2.6.16-sles10/fs/ext3/inode.c
@@ -2558,6 +2558,13 @@ void ext3_read_inode(struct inode * inod
EXT3_INODE_GET_XTIME(i_atime, inode, raw_inode);
EXT3_EINODE_GET_XTIME(i_crtime, ei, raw_inode);
+ ei->i_fs_version = le32_to_cpu(raw_inode->i_disk_version);
+ if (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) {
+ if (EXT3_FITS_IN_INODE(raw_inode, ei, i_version_hi))
+ ei->i_fs_version |= (__u64)(le32_to_cpu(raw_inode->i_version_hi))
+ << 32;
+ }
+
if (S_ISREG(inode->i_mode)) {
inode->i_op = &ext3_file_inode_operations;
inode->i_fop = &ext3_file_operations;
@@ -2696,8 +2703,14 @@ static int ext3_do_update_inode(handle_t
} else for (block = 0; block < EXT3_N_BLOCKS; block++)
raw_inode->i_block[block] = ei->i_data[block];
- if (ei->i_extra_isize)
+ raw_inode->i_disk_version = cpu_to_le32(ei->i_fs_version);
+ if (ei->i_extra_isize) {
+ if (EXT3_FITS_IN_INODE(raw_inode, ei, i_version_hi)) {
+ raw_inode->i_version_hi = cpu_to_le32(ei->i_fs_version
+ >> 32);
+ }
raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize);
+ }
BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata");
rc = ext3_journal_dirty_metadata(handle, bh);
@@ -2971,10 +2984,32 @@ ext3_reserve_inode_write(handle_t *handl
int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode)
{
struct ext3_iloc iloc;
- int err;
+ int err, ret;
+ static int expand_message;
might_sleep();
err = ext3_reserve_inode_write(handle, inode, &iloc);
+ if (EXT3_I(inode)->i_extra_isize <
+ EXT3_SB(inode->i_sb)->s_want_extra_isize &&
+ !(EXT3_I(inode)->i_state & EXT3_STATE_NO_EXPAND)) {
+ /* We need extra buffer credits since we may write into EA block
+ * with this same handle */
+ if ((ext3_journal_extend(handle,
+ EXT3_DATA_TRANS_BLOCKS(inode->i_sb))) == 0) {
+ ret = ext3_expand_extra_isize(inode,
+ EXT3_SB(inode->i_sb)->s_want_extra_isize,
+ iloc, handle);
+ if (ret) {
+ EXT3_I(inode)->i_state |= EXT3_STATE_NO_EXPAND;
+ if (!expand_message) {
+ ext3_warning(inode->i_sb, __FUNCTION__,
+ "Unable to expand inode %lu. Delete some"
+ " EAs or run e2fsck.", inode->i_ino);
+ expand_message = 1;
+ }
+ }
+ }
+ }
if (!err)
err = ext3_mark_iloc_dirty(handle, inode, &iloc);
return err;
Index: linux-2.6.16-sles10/include/linux/ext3_fs.h
===================================================================
--- linux-2.6.16-sles10.orig/include/linux/ext3_fs.h
+++ linux-2.6.16-sles10/include/linux/ext3_fs.h
@@ -205,6 +205,7 @@ struct ext3_group_desc
#define EXT3_STATE_JDATA 0x00000001 /* journaled data exists */
#define EXT3_STATE_NEW 0x00000002 /* inode is newly created */
#define EXT3_STATE_XATTR 0x00000004 /* has in-inode xattrs */
+#define EXT3_STATE_NO_EXPAND 0x00000008 /* No space for expansion */
/* Used to pass group descriptor data when online resize is done */
struct ext3_new_group_input {
@@ -281,7 +282,7 @@ struct ext3_inode {
__le32 i_flags; /* File flags */
union {
struct {
- __u32 l_i_reserved1;
+ __u32 l_i_version;
} linux1;
struct {
__u32 h_i_translator;
@@ -326,6 +327,7 @@ struct ext3_inode {
__le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
__le32 i_crtime; /* File Creation time */
__le32 i_crtime_extra; /* extra File Creation time (nsec << 2 | epoch) */
+ __le32 i_version_hi; /* high 32 bits for 64-bit version */
};
#define i_size_high i_dir_acl
@@ -388,6 +390,8 @@ do { \
raw_inode->xtime ## _extra); \
} while (0)
+#define i_disk_version osd1.linux1.l_i_version
+
#if defined(__KERNEL__) || defined(__linux__)
#define i_reserved1 osd1.linux1.l_i_reserved1
#define i_frag osd2.linux2.l_i_frag
Index: linux-2.6.16-sles10/include/linux/ext3_fs_i.h
===================================================================
--- linux-2.6.16-sles10.orig/include/linux/ext3_fs_i.h
+++ linux-2.6.16-sles10/include/linux/ext3_fs_i.h
@@ -20,6 +20,8 @@
#include <linux/rbtree.h>
#include <linux/seqlock.h>
+#define HAVE_DISK_INODE_VERSION
+
struct ext3_reserve_window {
__u32 _rsv_start; /* First byte reserved */
__u32 _rsv_end; /* Last byte reserved or 0 */
@@ -138,6 +140,8 @@ struct ext3_inode_info {
__u32 i_cached_extent[4];
void *i_filterdata;
+
+ __u64 i_fs_version;
};
#endif /* _LINUX_EXT3_FS_I */
Index: linux-2.6.16-sles10/fs/ext3/xattr.c
===================================================================
--- linux-2.6.16-sles10.orig/fs/ext3/xattr.c
+++ linux-2.6.16-sles10/fs/ext3/xattr.c
@@ -505,6 +505,20 @@ ext3_xattr_release_block(handle_t *handl
}
}
+static inline size_t ext3_xattr_free_space(struct ext3_xattr_entry *last,
+ size_t *min_offs, void *base, int *total)
+{
+ for (; !IS_LAST_ENTRY(last); last = EXT3_XATTR_NEXT(last)) {
+ *total += EXT3_XATTR_LEN(last->e_name_len);
+ if (!last->e_value_block && last->e_value_size) {
+ size_t offs = le16_to_cpu(last->e_value_offs);
+ if (offs < *min_offs)
+ *min_offs = offs;
+ }
+ }
+ return (*min_offs - ((void *)last - base) - sizeof(__u32));
+}
+
struct ext3_xattr_info {
int name_index;
const char *name;
@@ -1007,6 +1021,8 @@ ext3_xattr_set_handle(handle_t *handle,
if (!error) {
ext3_xattr_update_super_block(handle, inode->i_sb);
inode->i_ctime = ext3_current_time(inode);
+ if (!value)
+ EXT3_I(inode)->i_state &= ~EXT3_STATE_NO_EXPAND;
ext3_mark_inode_dirty(handle, inode);
/*
* The bh is consumed by ext3_mark_iloc_dirty, even with
@@ -1059,6 +1075,249 @@ retry:
return error;
}
+static void ext3_xattr_shift_entries(struct ext3_xattr_entry *entry,
+ int value_offs_shift, void *to,
+ void *from, size_t n, int blocksize)
+{
+ struct ext3_xattr_entry *last = entry;
+ int new_offs;
+
+ /* Adjust the value offsets of the entries */
+ for (; !IS_LAST_ENTRY(last); last = EXT3_XATTR_NEXT(last)) {
+ if (!last->e_value_block && last->e_value_size) {
+ new_offs = le16_to_cpu(last->e_value_offs) +
+ value_offs_shift;
+ BUG_ON(new_offs + le32_to_cpu(last->e_value_size) >
+ blocksize);
+ last->e_value_offs = cpu_to_le16(new_offs);
+ }
+ }
+ /* Shift the entries by n bytes */
+ memmove(to, from, n);
+}
+
+/* Expand an inode by new_extra_isize bytes.
+ * Returns 0 on success or negative error number on failure.
+ */
+int ext3_expand_extra_isize(struct inode *inode, int new_extra_isize,
+ struct ext3_iloc iloc, handle_t *handle)
+{
+ struct ext3_inode *raw_inode;
+ struct ext3_xattr_ibody_header *header;
+ struct ext3_xattr_entry *entry, *last, *first;
+ struct buffer_head *bh = NULL;
+ struct ext3_xattr_ibody_find *is = NULL;
+ struct ext3_xattr_block_find *bs = NULL;
+ char *buffer = NULL, *b_entry_name = NULL;
+ size_t min_offs, free;
+ int total_ino, total_blk;
+ void *base, *start, *end;
+ int extra_isize = 0, error = 0, tried_min_extra_isize = 0;
+ int s_min_extra_isize = EXT3_SB(inode->i_sb)->s_es->s_min_extra_isize;
+
+ down_write(&EXT3_I(inode)->xattr_sem);
+
+retry:
+ if (EXT3_I(inode)->i_extra_isize >= new_extra_isize) {
+ up_write(&EXT3_I(inode)->xattr_sem);
+ return 0;
+ }
+
+ raw_inode = ext3_raw_inode(&iloc);
+
+ header = IHDR(inode, raw_inode);
+ entry = IFIRST(header);
+
+ /* No extended attributes present */
+ if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR) ||
+ header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC)) {
+ memset((void *)raw_inode + EXT3_GOOD_OLD_INODE_SIZE, 0,
+ new_extra_isize);
+ EXT3_I(inode)->i_extra_isize = new_extra_isize;
+ goto cleanup;
+ }
+
+ /*
+ * Check if enough free space is available in the inode to shift the
+ * entries ahead by new_extra_isize.
+ */
+
+ base = start = entry;
+ end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;
+ min_offs = end - base;
+ last = entry;
+ total_ino = sizeof(struct ext3_xattr_ibody_header);
+
+ free = ext3_xattr_free_space(last, &min_offs, base, &total_ino);
+ if (free >= new_extra_isize) {
+ entry = IFIRST(header);
+ ext3_xattr_shift_entries(entry, EXT3_I(inode)->i_extra_isize -
+ new_extra_isize, (void *)raw_inode +
+ EXT3_GOOD_OLD_INODE_SIZE + new_extra_isize,
+ (void *)header, total_ino,
+ inode->i_sb->s_blocksize);
+ EXT3_I(inode)->i_extra_isize = new_extra_isize;
+ error = 0;
+ goto cleanup;
+ }
+
+ /*
+ * Enough free space isn't available in the inode, check if
+ * EA block can hold new_extra_isize bytes.
+ */
+ if (EXT3_I(inode)->i_file_acl) {
+ bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl);
+ error = -EIO;
+ if (!bh)
+ goto cleanup;
+ if (ext3_xattr_check_block(bh)) {
+ ext3_error(inode->i_sb, __FUNCTION__,
+ "inode %lu: bad block %d", inode->i_ino,
+ EXT3_I(inode)->i_file_acl);
+ error = -EIO;
+ goto cleanup;
+ }
+ base = BHDR(bh);
+ first = BFIRST(bh);
+ end = bh->b_data + bh->b_size;
+ min_offs = end - base;
+ free = ext3_xattr_free_space(first, &min_offs, base,
+ &total_blk);
+ if (free < new_extra_isize) {
+ if (!tried_min_extra_isize && s_min_extra_isize) {
+ tried_min_extra_isize++;
+ new_extra_isize = s_min_extra_isize;
+ goto retry;
+ }
+ error = -1;
+ goto cleanup;
+ }
+ } else {
+ free = inode->i_sb->s_blocksize;
+ }
+
+ while (new_extra_isize > 0) {
+ size_t offs, size, entry_size;
+ struct ext3_xattr_entry *small_entry = NULL;
+ struct ext3_xattr_info i = {
+ .value = NULL,
+ .value_len = 0,
+ };
+ unsigned int total_size, shift_bytes, temp = ~0U;
+
+ is = (struct ext3_xattr_ibody_find *) kmalloc(sizeof(struct
+ ext3_xattr_ibody_find), GFP_KERNEL);
+ bs = (struct ext3_xattr_block_find *) kmalloc(sizeof(struct
+ ext3_xattr_block_find), GFP_KERNEL);
+ memset((void *)is, 0, sizeof(struct ext3_xattr_ibody_find));
+ memset((void *)bs, 0, sizeof(struct ext3_xattr_block_find));
+
+ is->s.not_found = bs->s.not_found = -ENODATA;
+ is->iloc.bh = NULL;
+ bs->bh = NULL;
+
+ last = IFIRST(header);
+ /* Find the entry best suited to be pushed into EA block */
+ entry = NULL;
+ for (; !IS_LAST_ENTRY(last); last = EXT3_XATTR_NEXT(last)) {
+ total_size = EXT3_XATTR_SIZE(le32_to_cpu(last->e_value_size)) +
+ EXT3_XATTR_LEN(last->e_name_len);
+ if (total_size <= free && total_size < temp) {
+ if (total_size < new_extra_isize) {
+ small_entry = last;
+ } else {
+ entry = last;
+ temp = total_size;
+ }
+ }
+ }
+
+ if (entry == NULL) {
+ if (small_entry) {
+ entry = small_entry;
+ } else {
+ if (!tried_min_extra_isize &&
+ s_min_extra_isize) {
+ tried_min_extra_isize++;
+ new_extra_isize = s_min_extra_isize;
+ goto retry;
+ }
+ error = -1;
+ goto cleanup;
+ }
+ }
+ offs = le16_to_cpu(entry->e_value_offs);
+ size = le32_to_cpu(entry->e_value_size);
+ entry_size = EXT3_XATTR_LEN(entry->e_name_len);
+ i.name_index = entry->e_name_index,
+ buffer = kmalloc(EXT3_XATTR_SIZE(size), GFP_KERNEL);
+ b_entry_name = kmalloc(entry->e_name_len + 1, GFP_KERNEL);
+ /* Save the entry name and the entry value */
+ memcpy((void *)buffer, (void *)IFIRST(header) + offs,
+ EXT3_XATTR_SIZE(size));
+ memcpy((void *)b_entry_name, (void *)entry->e_name,
+ entry->e_name_len);
+ b_entry_name[entry->e_name_len] = '\0';
+ i.name = b_entry_name;
+
+ error = ext3_get_inode_loc(inode, &is->iloc);
+ if (error)
+ goto cleanup;
+
+ error = ext3_xattr_ibody_find(inode, &i, is);
+ if (error)
+ goto cleanup;
+
+ /* Remove the chosen entry from the inode */
+ error = ext3_xattr_ibody_set(handle, inode, &i, is);
+
+ entry = IFIRST(header);
+ if (entry_size + EXT3_XATTR_SIZE(size) >= new_extra_isize)
+ shift_bytes = new_extra_isize;
+ else
+ shift_bytes = entry_size + size;
+ /* Adjust the offsets and shift the remaining entries ahead */
+ ext3_xattr_shift_entries(entry, EXT3_I(inode)->i_extra_isize -
+ shift_bytes, (void *)raw_inode +
+ EXT3_GOOD_OLD_INODE_SIZE + extra_isize + shift_bytes,
+ (void *)header, total_ino - entry_size,
+ inode->i_sb->s_blocksize);
+
+ extra_isize += shift_bytes;
+ new_extra_isize -= shift_bytes;
+ EXT3_I(inode)->i_extra_isize = extra_isize;
+
+ i.name = b_entry_name;
+ i.value = buffer;
+ i.value_len = cpu_to_le32(size);
+ error = ext3_xattr_block_find(inode, &i, bs);
+ if (error)
+ goto cleanup;
+
+ /* Add entry which was removed from the inode into the block */
+ error = ext3_xattr_block_set(handle, inode, &i, bs);
+ if (error)
+ goto cleanup;
+ }
+
+cleanup:
+ if (b_entry_name)
+ kfree(b_entry_name);
+ if (buffer)
+ kfree(buffer);
+ if (is) {
+ brelse(is->iloc.bh);
+ kfree(is);
+ }
+ if (bs)
+ kfree(bs);
+ brelse(bh);
+ up_write(&EXT3_I(inode)->xattr_sem);
+ return error;
+}
+
+
+
/*
* ext3_xattr_delete_inode()
*
Index: linux-2.6.16-sles10/fs/ext3/xattr.h
===================================================================
--- linux-2.6.16-sles10.orig/fs/ext3/xattr.h
+++ linux-2.6.16-sles10/fs/ext3/xattr.h
@@ -75,6 +75,9 @@ extern int ext3_xattr_set_handle(handle_
extern void ext3_xattr_delete_inode(handle_t *, struct inode *);
extern void ext3_xattr_put_super(struct super_block *);
+int ext3_expand_extra_isize(struct inode *inode, int new_extra_isize,
+ struct ext3_iloc iloc, handle_t *handle);
+
extern int init_ext3_xattr(void);
extern void exit_ext3_xattr(void);
Index: linux-2.6.18/fs/ext3/inode.c
===================================================================
--- linux-2.6.18.orig/fs/ext3/inode.c
+++ linux-2.6.18/fs/ext3/inode.c
@@ -2703,6 +2703,13 @@ void ext3_read_inode(struct inode * inod
EXT3_INODE_GET_XTIME(i_atime, inode, raw_inode);
EXT3_EINODE_GET_XTIME(i_crtime, ei, raw_inode);
+ ei->i_fs_version = le32_to_cpu(raw_inode->i_disk_version);
+ if (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) {
+ if (EXT3_FITS_IN_INODE(raw_inode, ei, i_version_hi))
+ ei->i_fs_version |= (__u64)(le32_to_cpu(raw_inode->i_version_hi))
+ << 32;
+ }
+
if (S_ISREG(inode->i_mode)) {
inode->i_op = &ext3_file_inode_operations;
inode->i_fop = &ext3_file_operations;
@@ -2841,8 +2848,14 @@ static int ext3_do_update_inode(handle_t
} else for (block = 0; block < EXT3_N_BLOCKS; block++)
raw_inode->i_block[block] = ei->i_data[block];
- if (ei->i_extra_isize)
+ raw_inode->i_disk_version = cpu_to_le32(ei->i_fs_version);
+ if (ei->i_extra_isize) {
+ if (EXT3_FITS_IN_INODE(raw_inode, ei, i_version_hi)) {
+ raw_inode->i_version_hi = cpu_to_le32(ei->i_fs_version
+ >> 32);
+ }
raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize);
+ }
BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata");
rc = ext3_journal_dirty_metadata(handle, bh);
@@ -3116,10 +3129,32 @@ ext3_reserve_inode_write(handle_t *handl
int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode)
{
struct ext3_iloc iloc;
- int err;
+ int err, ret;
+ static int expand_message;
might_sleep();
err = ext3_reserve_inode_write(handle, inode, &iloc);
+ if (EXT3_I(inode)->i_extra_isize <
+ EXT3_SB(inode->i_sb)->s_want_extra_isize &&
+ !(EXT3_I(inode)->i_state & EXT3_STATE_NO_EXPAND)) {
+ /* We need extra buffer credits since we may write into EA block
+ * with this same handle */
+ if ((ext3_journal_extend(handle,
+ EXT3_DATA_TRANS_BLOCKS(inode->i_sb))) == 0) {
+ ret = ext3_expand_extra_isize(inode,
+ EXT3_SB(inode->i_sb)->s_want_extra_isize,
+ iloc, handle);
+ if (ret) {
+ EXT3_I(inode)->i_state |= EXT3_STATE_NO_EXPAND;
+ if (!expand_message) {
+ ext3_warning(inode->i_sb, __FUNCTION__,
+ "Unable to expand inode %lu. Delete some"
+ " EAs or run e2fsck.", inode->i_ino);
+ expand_message = 1;
+ }
+ }
+ }
+ }
if (!err)
err = ext3_mark_iloc_dirty(handle, inode, &iloc);
return err;
Index: linux-2.6.18/include/linux/ext3_fs.h
===================================================================
--- linux-2.6.18.orig/include/linux/ext3_fs.h
+++ linux-2.6.18/include/linux/ext3_fs.h
@@ -201,6 +201,7 @@ struct ext3_group_desc
#define EXT3_STATE_JDATA 0x00000001 /* journaled data exists */
#define EXT3_STATE_NEW 0x00000002 /* inode is newly created */
#define EXT3_STATE_XATTR 0x00000004 /* has in-inode xattrs */
+#define EXT3_STATE_NO_EXPAND 0x00000008 /* No space for expansion */
/* Used to pass group descriptor data when online resize is done */
struct ext3_new_group_input {
@@ -277,7 +278,7 @@ struct ext3_inode {
__le32 i_flags; /* File flags */
union {
struct {
- __u32 l_i_reserved1;
+ __u32 l_i_version;
} linux1;
struct {
__u32 h_i_translator;
@@ -322,6 +323,7 @@ struct ext3_inode {
__le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
__le32 i_crtime; /* File Creation time */
__le32 i_crtime_extra; /* extra File Creation time (nsec << 2 | epoch) */
+ __le32 i_version_hi; /* high 32 bits for 64-bit version */
};
#define i_size_high i_dir_acl
@@ -384,6 +386,8 @@ do { \
raw_inode->xtime ## _extra); \
} while (0)
+#define i_disk_version osd1.linux1.l_i_version
+
#if defined(__KERNEL__) || defined(__linux__)
#define i_reserved1 osd1.linux1.l_i_reserved1
#define i_frag osd2.linux2.l_i_frag
Index: linux-2.6.18/include/linux/ext3_fs_i.h
===================================================================
--- linux-2.6.18.orig/include/linux/ext3_fs_i.h
+++ linux-2.6.18/include/linux/ext3_fs_i.h
@@ -21,6 +21,8 @@
#include <linux/seqlock.h>
#include <linux/mutex.h>
+#define HAVE_DISK_INODE_VERSION
+
/* data type for block offset of block group */
typedef int ext3_grpblk_t;
@@ -147,6 +149,8 @@ struct ext3_inode_info {
struct timespec i_crtime;
void *i_filterdata;
+
+ __u64 i_fs_version;
};
#endif /* _LINUX_EXT3_FS_I */
Index: linux-2.6.18/fs/ext3/xattr.c
===================================================================
--- linux-2.6.18.orig/fs/ext3/xattr.c
+++ linux-2.6.18/fs/ext3/xattr.c
@@ -505,6 +505,20 @@ ext3_xattr_release_block(handle_t *handl
}
}
+static inline size_t ext3_xattr_free_space(struct ext3_xattr_entry *last,
+ size_t *min_offs, void *base, int *total)
+{
+ for (; !IS_LAST_ENTRY(last); last = EXT3_XATTR_NEXT(last)) {
+ *total += EXT3_XATTR_LEN(last->e_name_len);
+ if (!last->e_value_block && last->e_value_size) {
+ size_t offs = le16_to_cpu(last->e_value_offs);
+ if (offs < *min_offs)
+ *min_offs = offs;
+ }
+ }
+ return (*min_offs - ((void *)last - base) - sizeof(__u32));
+}
+
struct ext3_xattr_info {
int name_index;
const char *name;
@@ -1008,6 +1022,8 @@ ext3_xattr_set_handle(handle_t *handle,
if (!error) {
ext3_xattr_update_super_block(handle, inode->i_sb);
inode->i_ctime = ext3_current_time(inode);
+ if (!value)
+ EXT3_I(inode)->i_state &= ~EXT3_STATE_NO_EXPAND;
error = ext3_mark_iloc_dirty(handle, inode, &is.iloc);
/*
* The bh is consumed by ext3_mark_iloc_dirty, even with
@@ -1060,6 +1076,249 @@ retry:
return error;
}
+static void ext3_xattr_shift_entries(struct ext3_xattr_entry *entry,
+ int value_offs_shift, void *to,
+ void *from, size_t n, int blocksize)
+{
+ struct ext3_xattr_entry *last = entry;
+ int new_offs;
+
+ /* Adjust the value offsets of the entries */
+ for (; !IS_LAST_ENTRY(last); last = EXT3_XATTR_NEXT(last)) {
+ if (!last->e_value_block && last->e_value_size) {
+ new_offs = le16_to_cpu(last->e_value_offs) +
+ value_offs_shift;
+ BUG_ON(new_offs + le32_to_cpu(last->e_value_size) >
+ blocksize);
+ last->e_value_offs = cpu_to_le16(new_offs);
+ }
+ }
+ /* Shift the entries by n bytes */
+ memmove(to, from, n);
+}
+
+/* Expand an inode by new_extra_isize bytes.
+ * Returns 0 on success or negative error number on failure.
+ */
+int ext3_expand_extra_isize(struct inode *inode, int new_extra_isize,
+ struct ext3_iloc iloc, handle_t *handle)
+{
+ struct ext3_inode *raw_inode;
+ struct ext3_xattr_ibody_header *header;
+ struct ext3_xattr_entry *entry, *last, *first;
+ struct buffer_head *bh = NULL;
+ struct ext3_xattr_ibody_find *is = NULL;
+ struct ext3_xattr_block_find *bs = NULL;
+ char *buffer = NULL, *b_entry_name = NULL;
+ size_t min_offs, free;
+ int total_ino, total_blk;
+ void *base, *start, *end;
+ int extra_isize = 0, error = 0, tried_min_extra_isize = 0;
+ int s_min_extra_isize = EXT3_SB(inode->i_sb)->s_es->s_min_extra_isize;
+
+ down_write(&EXT3_I(inode)->xattr_sem);
+
+retry:
+ if (EXT3_I(inode)->i_extra_isize >= new_extra_isize) {
+ up_write(&EXT3_I(inode)->xattr_sem);
+ return 0;
+ }
+
+ raw_inode = ext3_raw_inode(&iloc);
+
+ header = IHDR(inode, raw_inode);
+ entry = IFIRST(header);
+
+ /* No extended attributes present */
+ if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR) ||
+ header->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC)) {
+ memset((void *)raw_inode + EXT3_GOOD_OLD_INODE_SIZE, 0,
+ new_extra_isize);
+ EXT3_I(inode)->i_extra_isize = new_extra_isize;
+ goto cleanup;
+ }
+
+ /*
+ * Check if enough free space is available in the inode to shift the
+ * entries ahead by new_extra_isize.
+ */
+
+ base = start = entry;
+ end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size;
+ min_offs = end - base;
+ last = entry;
+ total_ino = sizeof(struct ext3_xattr_ibody_header);
+
+ free = ext3_xattr_free_space(last, &min_offs, base, &total_ino);
+ if (free >= new_extra_isize) {
+ entry = IFIRST(header);
+ ext3_xattr_shift_entries(entry, EXT3_I(inode)->i_extra_isize -
+ new_extra_isize, (void *)raw_inode +
+ EXT3_GOOD_OLD_INODE_SIZE + new_extra_isize,
+ (void *)header, total_ino,
+ inode->i_sb->s_blocksize);
+ EXT3_I(inode)->i_extra_isize = new_extra_isize;
+ error = 0;
+ goto cleanup;
+ }
+
+ /*
+ * Enough free space isn't available in the inode, check if
+ * EA block can hold new_extra_isize bytes.
+ */
+ if (EXT3_I(inode)->i_file_acl) {
+ bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl);
+ error = -EIO;
+ if (!bh)
+ goto cleanup;
+ if (ext3_xattr_check_block(bh)) {
+ ext3_error(inode->i_sb, __FUNCTION__,
+ "inode %lu: bad block "E3FSBLK, inode->i_ino,
+ EXT3_I(inode)->i_file_acl);
+ error = -EIO;
+ goto cleanup;
+ }
+ base = BHDR(bh);
+ first = BFIRST(bh);
+ end = bh->b_data + bh->b_size;
+ min_offs = end - base;
+ free = ext3_xattr_free_space(first, &min_offs, base,
+ &total_blk);
+ if (free < new_extra_isize) {
+ if (!tried_min_extra_isize && s_min_extra_isize) {
+ tried_min_extra_isize++;
+ new_extra_isize = s_min_extra_isize;
+ goto retry;
+ }
+ error = -1;
+ goto cleanup;
+ }
+ } else {
+ free = inode->i_sb->s_blocksize;
+ }
+
+ while (new_extra_isize > 0) {
+ size_t offs, size, entry_size;
+ struct ext3_xattr_entry *small_entry = NULL;
+ struct ext3_xattr_info i = {
+ .value = NULL,
+ .value_len = 0,
+ };
+ unsigned int total_size, shift_bytes, temp = ~0U;
+
+ is = (struct ext3_xattr_ibody_find *) kmalloc(sizeof(struct
+ ext3_xattr_ibody_find), GFP_KERNEL);
+ bs = (struct ext3_xattr_block_find *) kmalloc(sizeof(struct
+ ext3_xattr_block_find), GFP_KERNEL);
+ memset((void *)is, 0, sizeof(struct ext3_xattr_ibody_find));
+ memset((void *)bs, 0, sizeof(struct ext3_xattr_block_find));
+
+ is->s.not_found = bs->s.not_found = -ENODATA;
+ is->iloc.bh = NULL;
+ bs->bh = NULL;
+
+ last = IFIRST(header);
+ /* Find the entry best suited to be pushed into EA block */
+ entry = NULL;
+ for (; !IS_LAST_ENTRY(last); last = EXT3_XATTR_NEXT(last)) {
+ total_size = EXT3_XATTR_SIZE(le32_to_cpu(last->e_value_size)) +
+ EXT3_XATTR_LEN(last->e_name_len);
+ if (total_size <= free && total_size < temp) {
+ if (total_size < new_extra_isize) {
+ small_entry = last;
+ } else {
+ entry = last;
+ temp = total_size;
+ }
+ }
+ }
+
+ if (entry == NULL) {
+ if (small_entry) {
+ entry = small_entry;
+ } else {
+ if (!tried_min_extra_isize &&
+ s_min_extra_isize) {
+ tried_min_extra_isize++;
+ new_extra_isize = s_min_extra_isize;
+ goto retry;
+ }
+ error = -1;
+ goto cleanup;
+ }
+ }
+ offs = le16_to_cpu(entry->e_value_offs);
+ size = le32_to_cpu(entry->e_value_size);
+ entry_size = EXT3_XATTR_LEN(entry->e_name_len);
+ i.name_index = entry->e_name_index,
+ buffer = kmalloc(EXT3_XATTR_SIZE(size), GFP_KERNEL);
+ b_entry_name = kmalloc(entry->e_name_len + 1, GFP_KERNEL);
+ /* Save the entry name and the entry value */
+ memcpy((void *)buffer, (void *)IFIRST(header) + offs,
+ EXT3_XATTR_SIZE(size));
+ memcpy((void *)b_entry_name, (void *)entry->e_name,
+ entry->e_name_len);
+ b_entry_name[entry->e_name_len] = '\0';
+ i.name = b_entry_name;
+
+ error = ext3_get_inode_loc(inode, &is->iloc);
+ if (error)
+ goto cleanup;
+
+ error = ext3_xattr_ibody_find(inode, &i, is);
+ if (error)
+ goto cleanup;
+
+ /* Remove the chosen entry from the inode */
+ error = ext3_xattr_ibody_set(handle, inode, &i, is);
+
+ entry = IFIRST(header);
+ if (entry_size + EXT3_XATTR_SIZE(size) >= new_extra_isize)
+ shift_bytes = new_extra_isize;
+ else
+ shift_bytes = entry_size + size;
+ /* Adjust the offsets and shift the remaining entries ahead */
+ ext3_xattr_shift_entries(entry, EXT3_I(inode)->i_extra_isize -
+ shift_bytes, (void *)raw_inode +
+ EXT3_GOOD_OLD_INODE_SIZE + extra_isize + shift_bytes,
+ (void *)header, total_ino - entry_size,
+ inode->i_sb->s_blocksize);
+
+ extra_isize += shift_bytes;
+ new_extra_isize -= shift_bytes;
+ EXT3_I(inode)->i_extra_isize = extra_isize;
+
+ i.name = b_entry_name;
+ i.value = buffer;
+ i.value_len = cpu_to_le32(size);
+ error = ext3_xattr_block_find(inode, &i, bs);
+ if (error)
+ goto cleanup;
+
+ /* Add entry which was removed from the inode into the block */
+ error = ext3_xattr_block_set(handle, inode, &i, bs);
+ if (error)
+ goto cleanup;
+ }
+
+cleanup:
+ if (b_entry_name)
+ kfree(b_entry_name);
+ if (buffer)
+ kfree(buffer);
+ if (is) {
+ brelse(is->iloc.bh);
+ kfree(is);
+ }
+ if (bs)
+ kfree(bs);
+ brelse(bh);
+ up_write(&EXT3_I(inode)->xattr_sem);
+ return error;
+}
+
+
+
/*
* ext3_xattr_delete_inode()
*
Index: linux-2.6.18/fs/ext3/xattr.h
===================================================================
--- linux-2.6.18.orig/fs/ext3/xattr.h
+++ linux-2.6.18/fs/ext3/xattr.h
@@ -74,6 +74,9 @@ extern int ext3_xattr_set_handle(handle_
extern void ext3_xattr_delete_inode(handle_t *, struct inode *);
extern void ext3_xattr_put_super(struct super_block *);
+int ext3_expand_extra_isize(struct inode *inode, int new_extra_isize,
+ struct ext3_iloc iloc, handle_t *handle);
+
extern int init_ext3_xattr(void);
extern void exit_ext3_xattr(void);
This diff is collapsed.
Index: linux-2.6.9-full/include/linux/ext3_fs_i.h
===================================================================
--- linux-2.6.9-full.orig/include/linux/ext3_fs_i.h 2007-03-28 01:29:38.000000000 +0400
+++ linux-2.6.9-full/include/linux/ext3_fs_i.h 2007-03-28 15:45:41.000000000 +0400
@@ -130,6 +130,10 @@ struct ext3_inode_info {
struct inode vfs_inode;
__u32 i_cached_extent[4];
+
+ /* mballoc */
+ struct list_head i_prealloc_list;
+ spinlock_t i_prealloc_lock;
};
#endif /* _LINUX_EXT3_FS_I */
Index: linux-2.6.9-full/include/linux/ext3_fs_sb.h
===================================================================
--- linux-2.6.9-full.orig/include/linux/ext3_fs_sb.h 2007-03-28 15:42:16.000000000 +0400
+++ linux-2.6.9-full/include/linux/ext3_fs_sb.h 2007-03-28 15:45:41.000000000 +0400
@@ -23,9 +23,16 @@
#define EXT_INCLUDE
#include <linux/blockgroup_lock.h>
#include <linux/percpu_counter.h>
+#include <linux/list.h>
#endif
#endif
#include <linux/rbtree.h>
+#include <linux/proc_fs.h>
+
+struct ext3_buddy_group_blocks;
+struct ext3_locality_group;
+struct ext3_mb_history;
+#define EXT3_BB_MAX_BLOCKS
/*
* third extended-fs super-block data in memory
Index: linux-2.6.9-full/include/linux/ext3_fs.h
===================================================================
--- linux-2.6.9-full.orig/include/linux/ext3_fs.h 2007-03-28 15:45:07.000000000 +0400
+++ linux-2.6.9-full/include/linux/ext3_fs.h 2007-03-28 15:45:41.000000000 +0400
@@ -389,6 +389,7 @@ struct ext3_inode {
#define EXT3_MOUNT_IOPEN_NOPRIV 0x100000/* Make iopen world-readable */
#define EXT3_MOUNT_EXTENTS 0x200000/* Extents support */
#define EXT3_MOUNT_EXTDEBUG 0x400000/* Extents debug */
+#define EXT3_MOUNT_MBALLOC 0x800000/* Buddy allocation support */
/* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
#ifndef clear_opt
@@ -749,8 +750,9 @@ struct dir_private_info {
extern int ext3_bg_has_super(struct super_block *sb, int group);
extern unsigned long ext3_bg_num_gdb(struct super_block *sb, int group);
extern int ext3_new_block (handle_t *, struct inode *, unsigned long, int *);
+extern int ext3_new_block_old (handle_t *, struct inode *, unsigned long, int *);
extern void ext3_free_blocks (handle_t *, struct inode *, unsigned long,
- unsigned long);
+ unsigned long, int);
extern void ext3_free_blocks_sb (handle_t *, struct super_block *,
unsigned long, unsigned long, int *);
extern unsigned long ext3_count_free_blocks (struct super_block *);
Index: linux-2.6.9-full/fs/ext3/super.c
===================================================================
--- linux-2.6.9-full.orig/fs/ext3/super.c 2007-03-28 15:42:16.000000000 +0400
+++ linux-2.6.9-full/fs/ext3/super.c 2007-03-28 15:45:41.000000000 +0400
@@ -600,6 +600,7 @@ enum {
Opt_ignore, Opt_barrier, Opt_err, Opt_resize,
Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
Opt_extents, Opt_noextents, Opt_extdebug,
+ Opt_mballoc, Opt_nomballoc, Opt_stripe,
};
static match_table_t tokens = {
@@ -653,6 +654,9 @@ static match_table_t tokens = {
{Opt_noextents, "noextents"},
{Opt_extdebug, "extdebug"},
{Opt_barrier, "barrier=%u"},
+ {Opt_mballoc, "mballoc"},
+ {Opt_nomballoc, "nomballoc"},
+ {Opt_stripe, "stripe=%u"},
{Opt_err, NULL},
{Opt_resize, "resize"},
};
@@ -965,6 +969,19 @@ clear_qf_name:
case Opt_extdebug:
set_opt (sbi->s_mount_opt, EXTDEBUG);
break;
+ case Opt_mballoc:
+ set_opt(sbi->s_mount_opt, MBALLOC);
+ break;
+ case Opt_nomballoc:
+ clear_opt(sbi->s_mount_opt, MBALLOC);
+ break;
+ case Opt_stripe:
+ if (match_int(&args[0], &option))
+ return 0;
+ if (option < 0)
+ return 0;
+ sbi->s_stripe = option;
+ break;
default:
printk (KERN_ERR
"EXT3-fs: Unrecognized mount option \"%s\" "
@@ -1654,6 +1671,7 @@ static int ext3_fill_super (struct super
ext3_count_dirs(sb));
ext3_ext_init(sb);
+ ext3_mb_init(sb, needs_recovery);
return 0;
Index: linux-2.6.9-full/fs/ext3/extents.c
===================================================================
--- linux-2.6.9-full.orig/fs/ext3/extents.c 2007-03-28 01:29:41.000000000 +0400
+++ linux-2.6.9-full/fs/ext3/extents.c 2007-03-28 15:45:41.000000000 +0400
@@ -779,7 +779,7 @@ cleanup:
for (i = 0; i < depth; i++) {
if (!ablocks[i])
continue;
- ext3_free_blocks(handle, tree->inode, ablocks[i], 1);
+ ext3_free_blocks(handle, tree->inode, ablocks[i], 1, 1);
}
}
kfree(ablocks);
@@ -1586,7 +1586,7 @@ int ext3_ext_rm_idx(handle_t *handle, st
path->p_idx->ei_leaf);
bh = sb_find_get_block(tree->inode->i_sb, path->p_idx->ei_leaf);
ext3_forget(handle, 1, tree->inode, bh, path->p_idx->ei_leaf);
- ext3_free_blocks(handle, tree->inode, path->p_idx->ei_leaf, 1);
+ ext3_free_blocks(handle, tree->inode, path->p_idx->ei_leaf, 1, 1);
return err;
}
@@ -2071,10 +2071,12 @@ ext3_remove_blocks(struct ext3_extents_t
int needed = ext3_remove_blocks_credits(tree, ex, from, to);
handle_t *handle = ext3_journal_start(tree->inode, needed);
struct buffer_head *bh;
- int i;
+ int i, metadata = 0;
if (IS_ERR(handle))
return PTR_ERR(handle);
+ if (S_ISDIR(tree->inode->i_mode) || S_ISLNK(tree->inode->i_mode))
+ metadata = 1;
if (from >= ex->ee_block && to == ex->ee_block + ex->ee_len - 1) {
/* tail removal */
unsigned long num, start;
@@ -2086,7 +2088,7 @@ ext3_remove_blocks(struct ext3_extents_t
bh = sb_find_get_block(tree->inode->i_sb, start + i);
ext3_forget(handle, 0, tree->inode, bh, start + i);
}
- ext3_free_blocks(handle, tree->inode, start, num);
+ ext3_free_blocks(handle, tree->inode, start, num, metadata);
} else if (from == ex->ee_block && to <= ex->ee_block + ex->ee_len - 1) {
printk("strange request: removal %lu-%lu from %u:%u\n",
from, to, ex->ee_block, ex->ee_len);
@@ -2177,11 +2179,8 @@ int ext3_ext_get_block(handle_t *handle,
struct ext3_extent *ex;
int goal, newblock, err = 0, depth;
struct ext3_extents_tree tree;
- unsigned long next;
- int allocated = 0;
-
- /* until we have multiblock allocation */
- max_blocks = 1;
+ unsigned long allocated = 0;
+ struct ext3_allocation_request ar;
clear_buffer_new(bh_result);
ext3_init_tree_desc(&tree, inode);
@@ -2253,18 +2252,33 @@ int ext3_ext_get_block(handle_t *handle,
goto out2;
}
+ /* find neighbour allocated blocks */
+ ar.lleft = iblock;
+ err = ext3_ext_search_left(&tree, path, &ar.lleft, &ar.pleft);
+ if (err)
+ goto out2;
+ ar.lright = iblock;
+ err = ext3_ext_search_right(&tree, path, &ar.lright, &ar.pright);
+ if (err)
+ goto out2;
+
/* find next allocated block so that we know how many
* blocks we can allocate without ovelapping next extent */
- EXT_ASSERT(iblock >= ex->ee_block + ex->ee_len);
- next = ext3_ext_next_allocated_block(path);
- EXT_ASSERT(next > iblock);
- allocated = next - iblock;
+ EXT_ASSERT(ar.pright == 0 || ar.lright > iblock);
+ if (ar.pright == 0)
+ allocated = EXT_MAX_BLOCK - iblock;
+ else
+ allocated = ar.lright - iblock;
if (allocated > max_blocks)
allocated = max_blocks;
/* allocate new block */
- goal = ext3_ext_find_goal(inode, path, iblock);
- newblock = ext3_new_block(handle, inode, goal, &err);
+ ar.inode = inode;
+ ar.goal = ext3_ext_find_goal(inode, path, iblock);
+ ar.logical = iblock;
+ ar.len = allocated;
+ ar.flags = EXT3_MB_HINT_DATA;
+ newblock = ext3_mb_new_blocks(handle, &ar, &err);
if (!newblock)
goto out2;
ext_debug(&tree, "allocate new block: goal %d, found %d\n",
@@ -2274,11 +2288,14 @@ int ext3_ext_get_block(handle_t *handle,
newex.ee_block = iblock;
newex.ee_start = newblock;
newex.ee_start_hi = 0;
- newex.ee_len = 1;
+ newex.ee_len = ar.len;
err = ext3_ext_insert_extent(handle, &tree, path, &newex);
if (err) {
/* free data blocks we just allocated */
- ext3_free_blocks(handle, inode, newex.ee_start, newex.ee_len);
+ /* not a good idea to call discard here directly,
+ * but otherwise we'd need to call it every free() */
+ ext3_mb_discard_inode_preallocations(inode);
+ ext3_free_blocks(handle, inode, newex.ee_start, newex.ee_len, 0);
goto out2;
}
@@ -2287,6 +2304,7 @@ int ext3_ext_get_block(handle_t *handle,
/* previous routine could use block we allocated */
newblock = newex.ee_start;
+ allocated = newex.ee_len;
set_buffer_new(bh_result);
ext3_ext_put_in_cache(&tree, newex.ee_block, newex.ee_len,
@@ -2339,6 +2357,9 @@ void ext3_ext_truncate(struct inode * in
down(&EXT3_I(inode)->truncate_sem);
ext3_ext_invalidate_cache(&tree);
+ /* it's important to discard preallocations under truncate_sem */
+ ext3_mb_discard_inode_preallocations(inode);
+
/*
* TODO: optimization is possible here
* probably we need not scaning at all,
Index: linux-2.6.9-full/fs/ext3/Makefile
===================================================================
--- linux-2.6.9-full.orig/fs/ext3/Makefile 2007-03-28 01:29:38.000000000 +0400
+++ linux-2.6.9-full/fs/ext3/Makefile 2007-03-28 15:45:41.000000000 +0400
@@ -6,7 +6,7 @@ obj-$(CONFIG_EXT3_FS) += ext3.o
ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
ioctl.o namei.o super.o symlink.o hash.o resize.o \
- extents.o
+ extents.o mballoc.o
ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
Index: linux-2.6.9-full/fs/ext3/xattr.c
===================================================================
--- linux-2.6.9-full.orig/fs/ext3/xattr.c 2006-05-18 23:57:04.000000000 +0400
+++ linux-2.6.9-full/fs/ext3/xattr.c 2007-03-28 15:45:41.000000000 +0400
@@ -1281,7 +1281,7 @@ ext3_xattr_set_handle2(handle_t *handle,
new_bh = sb_getblk(sb, block);
if (!new_bh) {
getblk_failed:
- ext3_free_blocks(handle, inode, block, 1);
+ ext3_free_blocks(handle, inode, block, 1, 1);
error = -EIO;
goto cleanup;
}
@@ -1328,7 +1328,7 @@ getblk_failed:
if (ce)
mb_cache_entry_free(ce);
ea_bdebug(old_bh, "freeing");
- ext3_free_blocks(handle, inode, old_bh->b_blocknr, 1);
+ ext3_free_blocks(handle, inode, old_bh->b_blocknr, 1, 1);
/* ext3_forget() calls bforget() for us, but we
let our caller release old_bh, so we need to
@@ -1427,7 +1427,7 @@ ext3_xattr_delete_inode(handle_t *handle
if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
if (ce)
mb_cache_entry_free(ce);
- ext3_free_blocks(handle, inode, EXT3_I(inode)->i_file_acl, 1);
+ ext3_free_blocks(handle, inode, EXT3_I(inode)->i_file_acl, 1, 1);
get_bh(bh);
ext3_forget(handle, 1, inode, bh, EXT3_I(inode)->i_file_acl);
} else {
Index: linux-2.6.9-full/fs/ext3/balloc.c
===================================================================
--- linux-2.6.9-full.orig/fs/ext3/balloc.c 2006-03-10 18:20:03.000000000 +0300
+++ linux-2.6.9-full/fs/ext3/balloc.c 2007-03-28 15:45:41.000000000 +0400
@@ -79,7 +79,7 @@ struct ext3_group_desc * ext3_get_group_
*
* Return buffer_head on success or NULL in case of failure.
*/
-static struct buffer_head *
+struct buffer_head *
read_block_bitmap(struct super_block *sb, unsigned int block_group)
{
struct ext3_group_desc * desc;
@@ -267,6 +267,8 @@ void ext3_discard_reservation(struct ino
struct reserve_window_node *rsv = &ei->i_rsv_window;
spinlock_t *rsv_lock = &EXT3_SB(inode->i_sb)->s_rsv_window_lock;
+ ext3_mb_discard_inode_preallocations(inode);
+
if (!rsv_is_empty(&rsv->rsv_window)) {
spin_lock(rsv_lock);
if (!rsv_is_empty(&rsv->rsv_window))
@@ -451,21 +453,25 @@ error_return:
return;
}
-/* Free given blocks, update quota and i_blocks field */
-void ext3_free_blocks(handle_t *handle, struct inode *inode,
- unsigned long block, unsigned long count)
+void ext3_free_blocks(handle_t *handle, struct inode * inode,
+ unsigned long block, unsigned long count, int metadata)
{
- struct super_block * sb;
- int dquot_freed_blocks;
+ struct super_block *sb;
+ int freed;
+
+ /* this isn't the right place to decide whether block is metadata
+ * inode.c/extents.c knows better, but for safety ... */
+ if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode) ||
+ ext3_should_journal_data(inode))
+ metadata = 1;
sb = inode->i_sb;
- if (!sb) {
- printk ("ext3_free_blocks: nonexistent device");
- return;
- }
- ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
- if (dquot_freed_blocks)
- DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
+ if (!test_opt(sb, MBALLOC) || !EXT3_SB(sb)->s_group_info)
+ ext3_free_blocks_sb(handle, sb, block, count, &freed);
+ else
+ ext3_mb_free_blocks(handle, inode, block, count, metadata, &freed);
+ if (freed)
+ DQUOT_FREE_BLOCK(inode, freed);
return;
}
@@ -1131,7 +1137,7 @@ int ext3_should_retry_alloc(struct super
* bitmap, and then for any free bit if that fails.
* This function also updates quota and i_blocks field.
*/
-int ext3_new_block(handle_t *handle, struct inode *inode,
+int ext3_new_block_old(handle_t *handle, struct inode *inode,
unsigned long goal, int *errp)
{
struct buffer_head *bitmap_bh = NULL;
Index: linux-2.6.9-full/fs/ext3/inode.c
===================================================================
--- linux-2.6.9-full.orig/fs/ext3/inode.c 2007-03-28 01:29:39.000000000 +0400
+++ linux-2.6.9-full/fs/ext3/inode.c 2007-03-28 15:45:41.000000000 +0400
@@ -572,7 +572,7 @@ static int ext3_alloc_branch(handle_t *h
ext3_journal_forget(handle, branch[i].bh);
}
for (i = 0; i < keys; i++)
- ext3_free_blocks(handle, inode, le32_to_cpu(branch[i].key), 1);
+ ext3_free_blocks(handle, inode, le32_to_cpu(branch[i].key), 1, 0);
return err;
}
@@ -673,7 +673,7 @@ err_out:
if (err == -EAGAIN)
for (i = 0; i < num; i++)
ext3_free_blocks(handle, inode,
- le32_to_cpu(where[i].key), 1);
+ le32_to_cpu(where[i].key), 1, 0);
return err;
}
@@ -1834,7 +1834,7 @@ ext3_clear_blocks(handle_t *handle, stru
}
}
- ext3_free_blocks(handle, inode, block_to_free, count);
+ ext3_free_blocks(handle, inode, block_to_free, count, 0);
}
/**
@@ -2007,7 +2007,7 @@ static void ext3_free_branches(handle_t
ext3_journal_test_restart(handle, inode);
}
- ext3_free_blocks(handle, inode, nr, 1);
+ ext3_free_blocks(handle, inode, nr, 1, 1);
if (parent_bh) {
/*
Index: linux-2.6.16.27-0.9-full/include/linux/ext3_fs_i.h
===================================================================
--- linux-2.6.16.27-0.9-full.orig/include/linux/ext3_fs_i.h 2007-03-28 05:12:50.000000000 +0400
+++ linux-2.6.16.27-0.9-full/include/linux/ext3_fs_i.h 2007-03-28 16:03:20.000000000 +0400
@@ -135,6 +135,10 @@ struct ext3_inode_info {
struct inode vfs_inode;
__u32 i_cached_extent[4];
+
+ /* mballoc */
+ struct list_head i_prealloc_list;
+ spinlock_t i_prealloc_lock;
};
#endif /* _LINUX_EXT3_FS_I */
Index: linux-2.6.16.27-0.9-full/include/linux/ext3_fs_sb.h
===================================================================
--- linux-2.6.16.27-0.9-full.orig/include/linux/ext3_fs_sb.h 2007-03-28 16:03:19.000000000 +0400
+++ linux-2.6.16.27-0.9-full/include/linux/ext3_fs_sb.h 2007-03-28 16:03:20.000000000 +0400
@@ -21,8 +21,15 @@
#include <linux/wait.h>
#include <linux/blockgroup_lock.h>
#include <linux/percpu_counter.h>
+#include <linux/list.h>
#endif
#include <linux/rbtree.h>
+#include <linux/proc_fs.h>
+
+struct ext3_buddy_group_blocks;
+struct ext3_locality_group;
+struct ext3_mb_history;
+#define EXT3_BB_MAX_BLOCKS
/*
* third extended-fs super-block data in memory
Index: linux-2.6.16.27-0.9-full/include/linux/ext3_fs.h
===================================================================
--- linux-2.6.16.27-0.9-full.orig/include/linux/ext3_fs.h 2007-03-28 16:03:19.000000000 +0400
+++ linux-2.6.16.27-0.9-full/include/linux/ext3_fs.h 2007-03-28 16:03:20.000000000 +0400
@@ -407,6 +407,7 @@ struct ext3_inode {
#define EXT3_MOUNT_IOPEN_NOPRIV 0x800000/* Make iopen world-readable */
#define EXT3_MOUNT_EXTENTS 0x1000000/* Extents support */
#define EXT3_MOUNT_EXTDEBUG 0x2000000/* Extents debug */
+#define EXT3_MOUNT_MBALLOC 0x4000000/* Buddy allocation support */
/* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
#ifndef clear_opt
@@ -767,8 +768,9 @@ struct dir_private_info {
extern int ext3_bg_has_super(struct super_block *sb, int group);
extern unsigned long ext3_bg_num_gdb(struct super_block *sb, int group);
extern int ext3_new_block (handle_t *, struct inode *, unsigned long, int *);
+extern int ext3_new_block_old (handle_t *, struct inode *, unsigned long, int *);
extern void ext3_free_blocks (handle_t *, struct inode *, unsigned long,
- unsigned long);
+ unsigned long, int);
extern void ext3_free_blocks_sb (handle_t *, struct super_block *,
unsigned long, unsigned long, int *);
extern unsigned long ext3_count_free_blocks (struct super_block *);
Index: linux-2.6.16.27-0.9-full/fs/ext3/super.c
===================================================================
--- linux-2.6.16.27-0.9-full.orig/fs/ext3/super.c 2007-03-28 16:03:19.000000000 +0400
+++ linux-2.6.16.27-0.9-full/fs/ext3/super.c 2007-03-28 16:03:20.000000000 +0400
@@ -688,6 +688,7 @@ enum {
Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
Opt_extents, Opt_noextents, Opt_extdebug,
+ Opt_mballoc, Opt_nomballoc, Opt_stripe,
Opt_grpquota
};
@@ -743,6 +744,9 @@ static match_table_t tokens = {
{Opt_noextents, "noextents"},
{Opt_extdebug, "extdebug"},
{Opt_barrier, "barrier=%u"},
+ {Opt_mballoc, "mballoc"},
+ {Opt_nomballoc, "nomballoc"},
+ {Opt_stripe, "stripe=%u"},
{Opt_err, NULL},
{Opt_resize, "resize"},
};
@@ -1092,6 +1096,19 @@ clear_qf_name:
case Opt_extdebug:
set_opt (sbi->s_mount_opt, EXTDEBUG);
break;
+ case Opt_mballoc:
+ set_opt(sbi->s_mount_opt, MBALLOC);
+ break;
+ case Opt_nomballoc:
+ clear_opt(sbi->s_mount_opt, MBALLOC);
+ break;
+ case Opt_stripe:
+ if (match_int(&args[0], &option))
+ return 0;
+ if (option < 0)
+ return 0;
+ sbi->s_stripe = option;
+ break;
default:
printk (KERN_ERR
"EXT3-fs: Unrecognized mount option \"%s\" "
@@ -1819,6 +1836,7 @@ static int ext3_fill_super (struct super
ext3_count_dirs(sb));
ext3_ext_init(sb);
+ ext3_mb_init(sb, needs_recovery);
lock_kernel();
return 0;
Index: linux-2.6.16.27-0.9-full/fs/ext3/extents.c
===================================================================
--- linux-2.6.16.27-0.9-full.orig/fs/ext3/extents.c 2007-03-28 05:13:39.000000000 +0400
+++ linux-2.6.16.27-0.9-full/fs/ext3/extents.c 2007-03-28 16:03:20.000000000 +0400
@@ -779,7 +779,7 @@ cleanup:
for (i = 0; i < depth; i++) {
if (!ablocks[i])
continue;
- ext3_free_blocks(handle, tree->inode, ablocks[i], 1);
+ ext3_free_blocks(handle, tree->inode, ablocks[i], 1, 1);
}
}
kfree(ablocks);
@@ -1586,7 +1586,7 @@ int ext3_ext_rm_idx(handle_t *handle, st
path->p_idx->ei_leaf);
bh = sb_find_get_block(tree->inode->i_sb, path->p_idx->ei_leaf);
ext3_forget(handle, 1, tree->inode, bh, path->p_idx->ei_leaf);
- ext3_free_blocks(handle, tree->inode, path->p_idx->ei_leaf, 1);
+ ext3_free_blocks(handle, tree->inode, path->p_idx->ei_leaf, 1, 1);
return err;
}
@@ -2071,10 +2071,12 @@ ext3_remove_blocks(struct ext3_extents_t
int needed = ext3_remove_blocks_credits(tree, ex, from, to);
handle_t *handle = ext3_journal_start(tree->inode, needed);
struct buffer_head *bh;
- int i;
+ int i, metadata = 0;
if (IS_ERR(handle))
return PTR_ERR(handle);
+ if (S_ISDIR(tree->inode->i_mode) || S_ISLNK(tree->inode->i_mode))
+ metadata = 1;
if (from >= ex->ee_block && to == ex->ee_block + ex->ee_len - 1) {
/* tail removal */
unsigned long num, start;
@@ -2086,7 +2088,7 @@ ext3_remove_blocks(struct ext3_extents_t
bh = sb_find_get_block(tree->inode->i_sb, start + i);
ext3_forget(handle, 0, tree->inode, bh, start + i);
}
- ext3_free_blocks(handle, tree->inode, start, num);
+ ext3_free_blocks(handle, tree->inode, start, num, metadata);
} else if (from == ex->ee_block && to <= ex->ee_block + ex->ee_len - 1) {
printk("strange request: removal %lu-%lu from %u:%u\n",
from, to, ex->ee_block, ex->ee_len);
@@ -2177,11 +2179,8 @@ int ext3_ext_get_block(handle_t *handle,
struct ext3_extent *ex;
int goal, newblock, err = 0, depth;
struct ext3_extents_tree tree;
- unsigned long next;
- int allocated = 0;
-
- /* until we have multiblock allocation */
- max_blocks = 1;
+ unsigned long allocated = 0;
+ struct ext3_allocation_request ar;
clear_buffer_new(bh_result);
ext3_init_tree_desc(&tree, inode);
@@ -2253,18 +2252,33 @@ int ext3_ext_get_block(handle_t *handle,
goto out2;
}
+ /* find neighbour allocated blocks */
+ ar.lleft = iblock;
+ err = ext3_ext_search_left(&tree, path, &ar.lleft, &ar.pleft);
+ if (err)
+ goto out2;
+ ar.lright = iblock;
+ err = ext3_ext_search_right(&tree, path, &ar.lright, &ar.pright);
+ if (err)
+ goto out2;
+
/* find next allocated block so that we know how many
* blocks we can allocate without ovelapping next extent */
- EXT_ASSERT(iblock >= ex->ee_block + ex->ee_len);
- next = ext3_ext_next_allocated_block(path);
- EXT_ASSERT(next > iblock);
- allocated = next - iblock;
+ EXT_ASSERT(ar.pright == 0 || ar.lright > iblock);
+ if (ar.pright == 0)
+ allocated = EXT_MAX_BLOCK - iblock;
+ else
+ allocated = ar.lright - iblock;
if (allocated > max_blocks)
allocated = max_blocks;
/* allocate new block */
- goal = ext3_ext_find_goal(inode, path, iblock);
- newblock = ext3_new_block(handle, inode, goal, &err);
+ ar.inode = inode;
+ ar.goal = ext3_ext_find_goal(inode, path, iblock);
+ ar.logical = iblock;
+ ar.len = allocated;
+ ar.flags = EXT3_MB_HINT_DATA;
+ newblock = ext3_mb_new_blocks(handle, &ar, &err);
if (!newblock)
goto out2;
ext_debug(&tree, "allocate new block: goal %d, found %d\n",
@@ -2274,11 +2288,14 @@ int ext3_ext_get_block(handle_t *handle,
newex.ee_block = iblock;
newex.ee_start = newblock;
newex.ee_start_hi = 0;
- newex.ee_len = 1;
+ newex.ee_len = ar.len;
err = ext3_ext_insert_extent(handle, &tree, path, &newex);
if (err) {
/* free data blocks we just allocated */
- ext3_free_blocks(handle, inode, newex.ee_start, newex.ee_len);
+ /* not a good idea to call discard here directly,
+ * but otherwise we'd need to call it every free() */
+ ext3_mb_discard_inode_preallocations(inode);
+ ext3_free_blocks(handle, inode, newex.ee_start, newex.ee_len, 0);
goto out2;
}
@@ -2287,6 +2304,7 @@ int ext3_ext_get_block(handle_t *handle,
/* previous routine could use block we allocated */
newblock = newex.ee_start;
+ allocated = newex.ee_len;
set_buffer_new(bh_result);
ext3_ext_put_in_cache(&tree, newex.ee_block, newex.ee_len,
@@ -2339,6 +2357,9 @@ void ext3_ext_truncate(struct inode * in
down(&EXT3_I(inode)->truncate_sem);
ext3_ext_invalidate_cache(&tree);
+ /* it's important to discard preallocations under truncate_sem */
+ ext3_mb_discard_inode_preallocations(inode);
+
/*
* TODO: optimization is possible here
* probably we need not scaning at all,
Index: linux-2.6.16.27-0.9-full/fs/ext3/Makefile
===================================================================
--- linux-2.6.16.27-0.9-full.orig/fs/ext3/Makefile 2007-03-28 05:12:50.000000000 +0400
+++ linux-2.6.16.27-0.9-full/fs/ext3/Makefile 2007-03-28 16:03:20.000000000 +0400
@@ -6,7 +6,7 @@ obj-$(CONFIG_EXT3_FS) += ext3.o
ext3-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
ioctl.o namei.o super.o symlink.o hash.o resize.o \
- extents.o
+ extents.o mballoc.o
ext3-$(CONFIG_EXT3_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
ext3-$(CONFIG_EXT3_FS_POSIX_ACL) += acl.o
Index: linux-2.6.16.27-0.9-full/fs/ext3/xattr.c
===================================================================
--- linux-2.6.16.27-0.9-full.orig/fs/ext3/xattr.c 2007-03-13 02:56:52.000000000 +0300
+++ linux-2.6.16.27-0.9-full/fs/ext3/xattr.c 2007-03-28 16:03:20.000000000 +0400
@@ -484,7 +484,7 @@ ext3_xattr_release_block(handle_t *handl
ea_bdebug(bh, "refcount now=0; freeing");
if (ce)
mb_cache_entry_free(ce);
- ext3_free_blocks(handle, inode, bh->b_blocknr, 1);
+ ext3_free_blocks(handle, inode, bh->b_blocknr, 1, 1);
get_bh(bh);
ext3_forget(handle, 1, inode, bh, bh->b_blocknr);
} else {
@@ -804,7 +804,7 @@ inserted:
new_bh = sb_getblk(sb, block);
if (!new_bh) {
getblk_failed:
- ext3_free_blocks(handle, inode, block, 1);
+ ext3_free_blocks(handle, inode, block, 1, 1);
error = -EIO;
goto cleanup;
}
Index: linux-2.6.16.27-0.9-full/fs/ext3/balloc.c
===================================================================
--- linux-2.6.16.27-0.9-full.orig/fs/ext3/balloc.c 2007-03-13 02:56:52.000000000 +0300
+++ linux-2.6.16.27-0.9-full/fs/ext3/balloc.c 2007-03-28 16:03:20.000000000 +0400
@@ -80,7 +80,7 @@ struct ext3_group_desc * ext3_get_group_
*
* Return buffer_head on success or NULL in case of failure.
*/
-static struct buffer_head *
+struct buffer_head *
read_block_bitmap(struct super_block *sb, unsigned int block_group)
{
struct ext3_group_desc * desc;
@@ -296,6 +296,8 @@ void ext3_discard_reservation(struct ino
struct ext3_reserve_window_node *rsv;
spinlock_t *rsv_lock = &EXT3_SB(inode->i_sb)->s_rsv_window_lock;
+ ext3_mb_discard_inode_preallocations(inode);
+
if (!block_i)
return;
@@ -491,21 +493,25 @@ error_return:
return;
}
-/* Free given blocks, update quota and i_blocks field */
-void ext3_free_blocks(handle_t *handle, struct inode *inode,
- unsigned long block, unsigned long count)
+void ext3_free_blocks(handle_t *handle, struct inode * inode,
+ unsigned long block, unsigned long count, int metadata)
{
- struct super_block * sb;
- int dquot_freed_blocks;
+ struct super_block *sb;
+ int freed;
+
+ /* this isn't the right place to decide whether block is metadata
+ * inode.c/extents.c knows better, but for safety ... */
+ if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode) ||
+ ext3_should_journal_data(inode))
+ metadata = 1;
sb = inode->i_sb;
- if (!sb) {
- printk ("ext3_free_blocks: nonexistent device");
- return;
- }
- ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
- if (dquot_freed_blocks)
- DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
+ if (!test_opt(sb, MBALLOC) || !EXT3_SB(sb)->s_group_info)
+ ext3_free_blocks_sb(handle, sb, block, count, &freed);
+ else
+ ext3_mb_free_blocks(handle, inode, block, count, metadata, &freed);
+ if (freed)
+ DQUOT_FREE_BLOCK(inode, freed);
return;
}
@@ -1154,7 +1160,7 @@ int ext3_should_retry_alloc(struct super
* bitmap, and then for any free bit if that fails.
* This function also updates quota and i_blocks field.
*/
-int ext3_new_block(handle_t *handle, struct inode *inode,
+int ext3_new_block_old(handle_t *handle, struct inode *inode,
unsigned long goal, int *errp)
{
struct buffer_head *bitmap_bh = NULL;
Index: linux-2.6.16.27-0.9-full/fs/ext3/inode.c
===================================================================
--- linux-2.6.16.27-0.9-full.orig/fs/ext3/inode.c 2007-03-28 05:13:38.000000000 +0400
+++ linux-2.6.16.27-0.9-full/fs/ext3/inode.c 2007-03-28 16:03:20.000000000 +0400
@@ -568,7 +568,7 @@ static int ext3_alloc_branch(handle_t *h
ext3_journal_forget(handle, branch[i].bh);
}
for (i = 0; i < keys; i++)
- ext3_free_blocks(handle, inode, le32_to_cpu(branch[i].key), 1);
+ ext3_free_blocks(handle, inode, le32_to_cpu(branch[i].key), 1, 0);
return err;
}
@@ -1865,7 +1865,7 @@ ext3_clear_blocks(handle_t *handle, stru
}
}
- ext3_free_blocks(handle, inode, block_to_free, count);
+ ext3_free_blocks(handle, inode, block_to_free, count, 0);
}
/**
@@ -2038,7 +2038,7 @@ static void ext3_free_branches(handle_t
ext3_journal_test_restart(handle, inode);
}
- ext3_free_blocks(handle, inode, nr, 1);
+ ext3_free_blocks(handle, inode, nr, 1, 1);
if (parent_bh) {
/*
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment