diff options
author | Ingo Molnar <mingo@elte.hu> | 2010-01-13 03:58:37 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-01-13 04:08:50 -0500 |
commit | 61405fea92c42d072d9b8bd189689f1502a838af (patch) | |
tree | 013ea3e7ed71f4114004d5852d40b6e89e128f76 /fs | |
parent | 9c443dfdd31eddea6cbe6ee0ca469fbcc4e1dc3b (diff) | |
parent | 1703f2c321a8a531c393e137a82602e16c6061cb (diff) |
Merge branch 'perf/urgent' into perf/core
Merge reason: queue up dependent patch, update to -rc4
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'fs')
142 files changed, 3127 insertions, 2519 deletions
diff --git a/fs/Kconfig b/fs/Kconfig index f8fccaaad628..64d44efad7a5 100644 --- a/fs/Kconfig +++ b/fs/Kconfig | |||
@@ -6,10 +6,6 @@ menu "File systems" | |||
6 | 6 | ||
7 | if BLOCK | 7 | if BLOCK |
8 | 8 | ||
9 | config FS_JOURNAL_INFO | ||
10 | bool | ||
11 | default n | ||
12 | |||
13 | source "fs/ext2/Kconfig" | 9 | source "fs/ext2/Kconfig" |
14 | source "fs/ext3/Kconfig" | 10 | source "fs/ext3/Kconfig" |
15 | source "fs/ext4/Kconfig" | 11 | source "fs/ext4/Kconfig" |
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c index 94f5110c4655..9f0bf13291e5 100644 --- a/fs/anon_inodes.c +++ b/fs/anon_inodes.c | |||
@@ -35,14 +35,13 @@ static int anon_inodefs_get_sb(struct file_system_type *fs_type, int flags, | |||
35 | mnt); | 35 | mnt); |
36 | } | 36 | } |
37 | 37 | ||
38 | static int anon_inodefs_delete_dentry(struct dentry *dentry) | 38 | /* |
39 | * anon_inodefs_dname() is called from d_path(). | ||
40 | */ | ||
41 | static char *anon_inodefs_dname(struct dentry *dentry, char *buffer, int buflen) | ||
39 | { | 42 | { |
40 | /* | 43 | return dynamic_dname(dentry, buffer, buflen, "anon_inode:%s", |
41 | * We faked vfs to believe the dentry was hashed when we created it. | 44 | dentry->d_name.name); |
42 | * Now we restore the flag so that dput() will work correctly. | ||
43 | */ | ||
44 | dentry->d_flags |= DCACHE_UNHASHED; | ||
45 | return 1; | ||
46 | } | 45 | } |
47 | 46 | ||
48 | static struct file_system_type anon_inode_fs_type = { | 47 | static struct file_system_type anon_inode_fs_type = { |
@@ -51,7 +50,7 @@ static struct file_system_type anon_inode_fs_type = { | |||
51 | .kill_sb = kill_anon_super, | 50 | .kill_sb = kill_anon_super, |
52 | }; | 51 | }; |
53 | static const struct dentry_operations anon_inodefs_dentry_operations = { | 52 | static const struct dentry_operations anon_inodefs_dentry_operations = { |
54 | .d_delete = anon_inodefs_delete_dentry, | 53 | .d_dname = anon_inodefs_dname, |
55 | }; | 54 | }; |
56 | 55 | ||
57 | /* | 56 | /* |
@@ -119,18 +118,16 @@ struct file *anon_inode_getfile(const char *name, | |||
119 | atomic_inc(&anon_inode_inode->i_count); | 118 | atomic_inc(&anon_inode_inode->i_count); |
120 | 119 | ||
121 | path.dentry->d_op = &anon_inodefs_dentry_operations; | 120 | path.dentry->d_op = &anon_inodefs_dentry_operations; |
122 | /* Do not publish this dentry inside the global dentry hash table */ | ||
123 | path.dentry->d_flags &= ~DCACHE_UNHASHED; | ||
124 | d_instantiate(path.dentry, anon_inode_inode); | 121 | d_instantiate(path.dentry, anon_inode_inode); |
125 | 122 | ||
126 | error = -ENFILE; | 123 | error = -ENFILE; |
127 | file = alloc_file(&path, FMODE_READ | FMODE_WRITE, fops); | 124 | file = alloc_file(&path, OPEN_FMODE(flags), fops); |
128 | if (!file) | 125 | if (!file) |
129 | goto err_dput; | 126 | goto err_dput; |
130 | file->f_mapping = anon_inode_inode->i_mapping; | 127 | file->f_mapping = anon_inode_inode->i_mapping; |
131 | 128 | ||
132 | file->f_pos = 0; | 129 | file->f_pos = 0; |
133 | file->f_flags = O_RDWR | (flags & O_NONBLOCK); | 130 | file->f_flags = flags & (O_ACCMODE | O_NONBLOCK); |
134 | file->f_version = 0; | 131 | file->f_version = 0; |
135 | file->private_data = priv; | 132 | file->private_data = priv; |
136 | 133 | ||
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c index b639dcf7c778..346b69405363 100644 --- a/fs/binfmt_aout.c +++ b/fs/binfmt_aout.c | |||
@@ -32,7 +32,7 @@ | |||
32 | 32 | ||
33 | static int load_aout_binary(struct linux_binprm *, struct pt_regs * regs); | 33 | static int load_aout_binary(struct linux_binprm *, struct pt_regs * regs); |
34 | static int load_aout_library(struct file*); | 34 | static int load_aout_library(struct file*); |
35 | static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit); | 35 | static int aout_core_dump(struct coredump_params *cprm); |
36 | 36 | ||
37 | static struct linux_binfmt aout_format = { | 37 | static struct linux_binfmt aout_format = { |
38 | .module = THIS_MODULE, | 38 | .module = THIS_MODULE, |
@@ -89,8 +89,9 @@ if (file->f_op->llseek) { \ | |||
89 | * dumping of the process results in another error.. | 89 | * dumping of the process results in another error.. |
90 | */ | 90 | */ |
91 | 91 | ||
92 | static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit) | 92 | static int aout_core_dump(struct coredump_params *cprm) |
93 | { | 93 | { |
94 | struct file *file = cprm->file; | ||
94 | mm_segment_t fs; | 95 | mm_segment_t fs; |
95 | int has_dumped = 0; | 96 | int has_dumped = 0; |
96 | unsigned long dump_start, dump_size; | 97 | unsigned long dump_start, dump_size; |
@@ -108,16 +109,16 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u | |||
108 | current->flags |= PF_DUMPCORE; | 109 | current->flags |= PF_DUMPCORE; |
109 | strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm)); | 110 | strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm)); |
110 | dump.u_ar0 = offsetof(struct user, regs); | 111 | dump.u_ar0 = offsetof(struct user, regs); |
111 | dump.signal = signr; | 112 | dump.signal = cprm->signr; |
112 | aout_dump_thread(regs, &dump); | 113 | aout_dump_thread(cprm->regs, &dump); |
113 | 114 | ||
114 | /* If the size of the dump file exceeds the rlimit, then see what would happen | 115 | /* If the size of the dump file exceeds the rlimit, then see what would happen |
115 | if we wrote the stack, but not the data area. */ | 116 | if we wrote the stack, but not the data area. */ |
116 | if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit) | 117 | if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit) |
117 | dump.u_dsize = 0; | 118 | dump.u_dsize = 0; |
118 | 119 | ||
119 | /* Make sure we have enough room to write the stack and data areas. */ | 120 | /* Make sure we have enough room to write the stack and data areas. */ |
120 | if ((dump.u_ssize + 1) * PAGE_SIZE > limit) | 121 | if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit) |
121 | dump.u_ssize = 0; | 122 | dump.u_ssize = 0; |
122 | 123 | ||
123 | /* make sure we actually have a data and stack area to dump */ | 124 | /* make sure we actually have a data and stack area to dump */ |
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 97b6e9efeb7f..edd90c49003c 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c | |||
@@ -45,7 +45,7 @@ static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *, | |||
45 | * don't even try. | 45 | * don't even try. |
46 | */ | 46 | */ |
47 | #ifdef CONFIG_ELF_CORE | 47 | #ifdef CONFIG_ELF_CORE |
48 | static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit); | 48 | static int elf_core_dump(struct coredump_params *cprm); |
49 | #else | 49 | #else |
50 | #define elf_core_dump NULL | 50 | #define elf_core_dump NULL |
51 | #endif | 51 | #endif |
@@ -1272,8 +1272,9 @@ static int writenote(struct memelfnote *men, struct file *file, | |||
1272 | } | 1272 | } |
1273 | #undef DUMP_WRITE | 1273 | #undef DUMP_WRITE |
1274 | 1274 | ||
1275 | #define DUMP_WRITE(addr, nr) \ | 1275 | #define DUMP_WRITE(addr, nr) \ |
1276 | if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \ | 1276 | if ((size += (nr)) > cprm->limit || \ |
1277 | !dump_write(cprm->file, (addr), (nr))) \ | ||
1277 | goto end_coredump; | 1278 | goto end_coredump; |
1278 | 1279 | ||
1279 | static void fill_elf_header(struct elfhdr *elf, int segs, | 1280 | static void fill_elf_header(struct elfhdr *elf, int segs, |
@@ -1901,7 +1902,7 @@ static struct vm_area_struct *next_vma(struct vm_area_struct *this_vma, | |||
1901 | * and then they are actually written out. If we run out of core limit | 1902 | * and then they are actually written out. If we run out of core limit |
1902 | * we just truncate. | 1903 | * we just truncate. |
1903 | */ | 1904 | */ |
1904 | static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit) | 1905 | static int elf_core_dump(struct coredump_params *cprm) |
1905 | { | 1906 | { |
1906 | int has_dumped = 0; | 1907 | int has_dumped = 0; |
1907 | mm_segment_t fs; | 1908 | mm_segment_t fs; |
@@ -1947,7 +1948,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un | |||
1947 | * notes. This also sets up the file header. | 1948 | * notes. This also sets up the file header. |
1948 | */ | 1949 | */ |
1949 | if (!fill_note_info(elf, segs + 1, /* including notes section */ | 1950 | if (!fill_note_info(elf, segs + 1, /* including notes section */ |
1950 | &info, signr, regs)) | 1951 | &info, cprm->signr, cprm->regs)) |
1951 | goto cleanup; | 1952 | goto cleanup; |
1952 | 1953 | ||
1953 | has_dumped = 1; | 1954 | has_dumped = 1; |
@@ -2009,14 +2010,14 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un | |||
2009 | #endif | 2010 | #endif |
2010 | 2011 | ||
2011 | /* write out the notes section */ | 2012 | /* write out the notes section */ |
2012 | if (!write_note_info(&info, file, &foffset)) | 2013 | if (!write_note_info(&info, cprm->file, &foffset)) |
2013 | goto end_coredump; | 2014 | goto end_coredump; |
2014 | 2015 | ||
2015 | if (elf_coredump_extra_notes_write(file, &foffset)) | 2016 | if (elf_coredump_extra_notes_write(cprm->file, &foffset)) |
2016 | goto end_coredump; | 2017 | goto end_coredump; |
2017 | 2018 | ||
2018 | /* Align to page */ | 2019 | /* Align to page */ |
2019 | if (!dump_seek(file, dataoff - foffset)) | 2020 | if (!dump_seek(cprm->file, dataoff - foffset)) |
2020 | goto end_coredump; | 2021 | goto end_coredump; |
2021 | 2022 | ||
2022 | for (vma = first_vma(current, gate_vma); vma != NULL; | 2023 | for (vma = first_vma(current, gate_vma); vma != NULL; |
@@ -2033,12 +2034,13 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un | |||
2033 | page = get_dump_page(addr); | 2034 | page = get_dump_page(addr); |
2034 | if (page) { | 2035 | if (page) { |
2035 | void *kaddr = kmap(page); | 2036 | void *kaddr = kmap(page); |
2036 | stop = ((size += PAGE_SIZE) > limit) || | 2037 | stop = ((size += PAGE_SIZE) > cprm->limit) || |
2037 | !dump_write(file, kaddr, PAGE_SIZE); | 2038 | !dump_write(cprm->file, kaddr, |
2039 | PAGE_SIZE); | ||
2038 | kunmap(page); | 2040 | kunmap(page); |
2039 | page_cache_release(page); | 2041 | page_cache_release(page); |
2040 | } else | 2042 | } else |
2041 | stop = !dump_seek(file, PAGE_SIZE); | 2043 | stop = !dump_seek(cprm->file, PAGE_SIZE); |
2042 | if (stop) | 2044 | if (stop) |
2043 | goto end_coredump; | 2045 | goto end_coredump; |
2044 | } | 2046 | } |
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 7b055385db8e..c57d9ce5ff7e 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c | |||
@@ -76,7 +76,7 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *, | |||
76 | struct file *, struct mm_struct *); | 76 | struct file *, struct mm_struct *); |
77 | 77 | ||
78 | #ifdef CONFIG_ELF_CORE | 78 | #ifdef CONFIG_ELF_CORE |
79 | static int elf_fdpic_core_dump(long, struct pt_regs *, struct file *, unsigned long limit); | 79 | static int elf_fdpic_core_dump(struct coredump_params *cprm); |
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | static struct linux_binfmt elf_fdpic_format = { | 82 | static struct linux_binfmt elf_fdpic_format = { |
@@ -171,6 +171,9 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, | |||
171 | #ifdef ELF_FDPIC_PLAT_INIT | 171 | #ifdef ELF_FDPIC_PLAT_INIT |
172 | unsigned long dynaddr; | 172 | unsigned long dynaddr; |
173 | #endif | 173 | #endif |
174 | #ifndef CONFIG_MMU | ||
175 | unsigned long stack_prot; | ||
176 | #endif | ||
174 | struct file *interpreter = NULL; /* to shut gcc up */ | 177 | struct file *interpreter = NULL; /* to shut gcc up */ |
175 | char *interpreter_name = NULL; | 178 | char *interpreter_name = NULL; |
176 | int executable_stack; | 179 | int executable_stack; |
@@ -316,6 +319,8 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, | |||
316 | * defunct, deceased, etc. after this point we have to exit via | 319 | * defunct, deceased, etc. after this point we have to exit via |
317 | * error_kill */ | 320 | * error_kill */ |
318 | set_personality(PER_LINUX_FDPIC); | 321 | set_personality(PER_LINUX_FDPIC); |
322 | if (elf_read_implies_exec(&exec_params.hdr, executable_stack)) | ||
323 | current->personality |= READ_IMPLIES_EXEC; | ||
319 | set_binfmt(&elf_fdpic_format); | 324 | set_binfmt(&elf_fdpic_format); |
320 | 325 | ||
321 | current->mm->start_code = 0; | 326 | current->mm->start_code = 0; |
@@ -377,9 +382,13 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm, | |||
377 | if (stack_size < PAGE_SIZE * 2) | 382 | if (stack_size < PAGE_SIZE * 2) |
378 | stack_size = PAGE_SIZE * 2; | 383 | stack_size = PAGE_SIZE * 2; |
379 | 384 | ||
385 | stack_prot = PROT_READ | PROT_WRITE; | ||
386 | if (executable_stack == EXSTACK_ENABLE_X || | ||
387 | (executable_stack == EXSTACK_DEFAULT && VM_STACK_FLAGS & VM_EXEC)) | ||
388 | stack_prot |= PROT_EXEC; | ||
389 | |||
380 | down_write(¤t->mm->mmap_sem); | 390 | down_write(¤t->mm->mmap_sem); |
381 | current->mm->start_brk = do_mmap(NULL, 0, stack_size, | 391 | current->mm->start_brk = do_mmap(NULL, 0, stack_size, stack_prot, |
382 | PROT_READ | PROT_WRITE | PROT_EXEC, | ||
383 | MAP_PRIVATE | MAP_ANONYMOUS | | 392 | MAP_PRIVATE | MAP_ANONYMOUS | |
384 | MAP_UNINITIALIZED | MAP_GROWSDOWN, | 393 | MAP_UNINITIALIZED | MAP_GROWSDOWN, |
385 | 0); | 394 | 0); |
@@ -1326,8 +1335,9 @@ static int writenote(struct memelfnote *men, struct file *file) | |||
1326 | #undef DUMP_WRITE | 1335 | #undef DUMP_WRITE |
1327 | #undef DUMP_SEEK | 1336 | #undef DUMP_SEEK |
1328 | 1337 | ||
1329 | #define DUMP_WRITE(addr, nr) \ | 1338 | #define DUMP_WRITE(addr, nr) \ |
1330 | if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \ | 1339 | if ((size += (nr)) > cprm->limit || \ |
1340 | !dump_write(cprm->file, (addr), (nr))) \ | ||
1331 | goto end_coredump; | 1341 | goto end_coredump; |
1332 | 1342 | ||
1333 | static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs) | 1343 | static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs) |
@@ -1582,8 +1592,7 @@ static int elf_fdpic_dump_segments(struct file *file, size_t *size, | |||
1582 | * and then they are actually written out. If we run out of core limit | 1592 | * and then they are actually written out. If we run out of core limit |
1583 | * we just truncate. | 1593 | * we just truncate. |
1584 | */ | 1594 | */ |
1585 | static int elf_fdpic_core_dump(long signr, struct pt_regs *regs, | 1595 | static int elf_fdpic_core_dump(struct coredump_params *cprm) |
1586 | struct file *file, unsigned long limit) | ||
1587 | { | 1596 | { |
1588 | #define NUM_NOTES 6 | 1597 | #define NUM_NOTES 6 |
1589 | int has_dumped = 0; | 1598 | int has_dumped = 0; |
@@ -1642,7 +1651,7 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs, | |||
1642 | goto cleanup; | 1651 | goto cleanup; |
1643 | #endif | 1652 | #endif |
1644 | 1653 | ||
1645 | if (signr) { | 1654 | if (cprm->signr) { |
1646 | struct core_thread *ct; | 1655 | struct core_thread *ct; |
1647 | struct elf_thread_status *tmp; | 1656 | struct elf_thread_status *tmp; |
1648 | 1657 | ||
@@ -1661,14 +1670,14 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs, | |||
1661 | int sz; | 1670 | int sz; |
1662 | 1671 | ||
1663 | tmp = list_entry(t, struct elf_thread_status, list); | 1672 | tmp = list_entry(t, struct elf_thread_status, list); |
1664 | sz = elf_dump_thread_status(signr, tmp); | 1673 | sz = elf_dump_thread_status(cprm->signr, tmp); |
1665 | thread_status_size += sz; | 1674 | thread_status_size += sz; |
1666 | } | 1675 | } |
1667 | } | 1676 | } |
1668 | 1677 | ||
1669 | /* now collect the dump for the current */ | 1678 | /* now collect the dump for the current */ |
1670 | fill_prstatus(prstatus, current, signr); | 1679 | fill_prstatus(prstatus, current, cprm->signr); |
1671 | elf_core_copy_regs(&prstatus->pr_reg, regs); | 1680 | elf_core_copy_regs(&prstatus->pr_reg, cprm->regs); |
1672 | 1681 | ||
1673 | segs = current->mm->map_count; | 1682 | segs = current->mm->map_count; |
1674 | #ifdef ELF_CORE_EXTRA_PHDRS | 1683 | #ifdef ELF_CORE_EXTRA_PHDRS |
@@ -1703,7 +1712,7 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs, | |||
1703 | 1712 | ||
1704 | /* Try to dump the FPU. */ | 1713 | /* Try to dump the FPU. */ |
1705 | if ((prstatus->pr_fpvalid = | 1714 | if ((prstatus->pr_fpvalid = |
1706 | elf_core_copy_task_fpregs(current, regs, fpu))) | 1715 | elf_core_copy_task_fpregs(current, cprm->regs, fpu))) |
1707 | fill_note(notes + numnote++, | 1716 | fill_note(notes + numnote++, |
1708 | "CORE", NT_PRFPREG, sizeof(*fpu), fpu); | 1717 | "CORE", NT_PRFPREG, sizeof(*fpu), fpu); |
1709 | #ifdef ELF_CORE_COPY_XFPREGS | 1718 | #ifdef ELF_CORE_COPY_XFPREGS |
@@ -1774,7 +1783,7 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs, | |||
1774 | 1783 | ||
1775 | /* write out the notes section */ | 1784 | /* write out the notes section */ |
1776 | for (i = 0; i < numnote; i++) | 1785 | for (i = 0; i < numnote; i++) |
1777 | if (!writenote(notes + i, file)) | 1786 | if (!writenote(notes + i, cprm->file)) |
1778 | goto end_coredump; | 1787 | goto end_coredump; |
1779 | 1788 | ||
1780 | /* write out the thread status notes section */ | 1789 | /* write out the thread status notes section */ |
@@ -1783,25 +1792,26 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs, | |||
1783 | list_entry(t, struct elf_thread_status, list); | 1792 | list_entry(t, struct elf_thread_status, list); |
1784 | 1793 | ||
1785 | for (i = 0; i < tmp->num_notes; i++) | 1794 | for (i = 0; i < tmp->num_notes; i++) |
1786 | if (!writenote(&tmp->notes[i], file)) | 1795 | if (!writenote(&tmp->notes[i], cprm->file)) |
1787 | goto end_coredump; | 1796 | goto end_coredump; |
1788 | } | 1797 | } |
1789 | 1798 | ||
1790 | if (!dump_seek(file, dataoff)) | 1799 | if (!dump_seek(cprm->file, dataoff)) |
1791 | goto end_coredump; | 1800 | goto end_coredump; |
1792 | 1801 | ||
1793 | if (elf_fdpic_dump_segments(file, &size, &limit, mm_flags) < 0) | 1802 | if (elf_fdpic_dump_segments(cprm->file, &size, &cprm->limit, |
1803 | mm_flags) < 0) | ||
1794 | goto end_coredump; | 1804 | goto end_coredump; |
1795 | 1805 | ||
1796 | #ifdef ELF_CORE_WRITE_EXTRA_DATA | 1806 | #ifdef ELF_CORE_WRITE_EXTRA_DATA |
1797 | ELF_CORE_WRITE_EXTRA_DATA; | 1807 | ELF_CORE_WRITE_EXTRA_DATA; |
1798 | #endif | 1808 | #endif |
1799 | 1809 | ||
1800 | if (file->f_pos != offset) { | 1810 | if (cprm->file->f_pos != offset) { |
1801 | /* Sanity check */ | 1811 | /* Sanity check */ |
1802 | printk(KERN_WARNING | 1812 | printk(KERN_WARNING |
1803 | "elf_core_dump: file->f_pos (%lld) != offset (%lld)\n", | 1813 | "elf_core_dump: file->f_pos (%lld) != offset (%lld)\n", |
1804 | file->f_pos, offset); | 1814 | cprm->file->f_pos, offset); |
1805 | } | 1815 | } |
1806 | 1816 | ||
1807 | end_coredump: | 1817 | end_coredump: |
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c index a2796651e756..d4a00ea1054c 100644 --- a/fs/binfmt_flat.c +++ b/fs/binfmt_flat.c | |||
@@ -87,7 +87,7 @@ static int load_flat_shared_library(int id, struct lib_info *p); | |||
87 | #endif | 87 | #endif |
88 | 88 | ||
89 | static int load_flat_binary(struct linux_binprm *, struct pt_regs * regs); | 89 | static int load_flat_binary(struct linux_binprm *, struct pt_regs * regs); |
90 | static int flat_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit); | 90 | static int flat_core_dump(struct coredump_params *cprm); |
91 | 91 | ||
92 | static struct linux_binfmt flat_format = { | 92 | static struct linux_binfmt flat_format = { |
93 | .module = THIS_MODULE, | 93 | .module = THIS_MODULE, |
@@ -102,10 +102,10 @@ static struct linux_binfmt flat_format = { | |||
102 | * Currently only a stub-function. | 102 | * Currently only a stub-function. |
103 | */ | 103 | */ |
104 | 104 | ||
105 | static int flat_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit) | 105 | static int flat_core_dump(struct coredump_params *cprm) |
106 | { | 106 | { |
107 | printk("Process %s:%d received signr %d and should have core dumped\n", | 107 | printk("Process %s:%d received signr %d and should have core dumped\n", |
108 | current->comm, current->pid, (int) signr); | 108 | current->comm, current->pid, (int) cprm->signr); |
109 | return(1); | 109 | return(1); |
110 | } | 110 | } |
111 | 111 | ||
diff --git a/fs/binfmt_som.c b/fs/binfmt_som.c index eff74b9c9e77..2a9b5330cc5e 100644 --- a/fs/binfmt_som.c +++ b/fs/binfmt_som.c | |||
@@ -43,7 +43,7 @@ static int load_som_library(struct file *); | |||
43 | * don't even try. | 43 | * don't even try. |
44 | */ | 44 | */ |
45 | #if 0 | 45 | #if 0 |
46 | static int som_core_dump(long signr, struct pt_regs *regs, unsigned long limit); | 46 | static int som_core_dump(struct coredump_params *cprm); |
47 | #else | 47 | #else |
48 | #define som_core_dump NULL | 48 | #define som_core_dump NULL |
49 | #endif | 49 | #endif |
diff --git a/fs/btrfs/Kconfig b/fs/btrfs/Kconfig index 402afe0a0bfb..7bb3c020e570 100644 --- a/fs/btrfs/Kconfig +++ b/fs/btrfs/Kconfig | |||
@@ -4,7 +4,6 @@ config BTRFS_FS | |||
4 | select LIBCRC32C | 4 | select LIBCRC32C |
5 | select ZLIB_INFLATE | 5 | select ZLIB_INFLATE |
6 | select ZLIB_DEFLATE | 6 | select ZLIB_DEFLATE |
7 | select FS_JOURNAL_INFO | ||
8 | help | 7 | help |
9 | Btrfs is a new filesystem with extents, writable snapshotting, | 8 | Btrfs is a new filesystem with extents, writable snapshotting, |
10 | support for multiple devices and many more features. | 9 | support for multiple devices and many more features. |
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c index 52cbe47022bf..2e9e69987a82 100644 --- a/fs/btrfs/acl.c +++ b/fs/btrfs/acl.c | |||
@@ -94,7 +94,8 @@ static int btrfs_xattr_acl_get(struct dentry *dentry, const char *name, | |||
94 | /* | 94 | /* |
95 | * Needs to be called with fs_mutex held | 95 | * Needs to be called with fs_mutex held |
96 | */ | 96 | */ |
97 | static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | 97 | static int btrfs_set_acl(struct btrfs_trans_handle *trans, |
98 | struct inode *inode, struct posix_acl *acl, int type) | ||
98 | { | 99 | { |
99 | int ret, size = 0; | 100 | int ret, size = 0; |
100 | const char *name; | 101 | const char *name; |
@@ -140,8 +141,7 @@ static int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | |||
140 | goto out; | 141 | goto out; |
141 | } | 142 | } |
142 | 143 | ||
143 | ret = __btrfs_setxattr(inode, name, value, size, 0); | 144 | ret = __btrfs_setxattr(trans, inode, name, value, size, 0); |
144 | |||
145 | out: | 145 | out: |
146 | kfree(value); | 146 | kfree(value); |
147 | 147 | ||
@@ -154,7 +154,7 @@ out: | |||
154 | static int btrfs_xattr_acl_set(struct dentry *dentry, const char *name, | 154 | static int btrfs_xattr_acl_set(struct dentry *dentry, const char *name, |
155 | const void *value, size_t size, int flags, int type) | 155 | const void *value, size_t size, int flags, int type) |
156 | { | 156 | { |
157 | int ret = 0; | 157 | int ret; |
158 | struct posix_acl *acl = NULL; | 158 | struct posix_acl *acl = NULL; |
159 | 159 | ||
160 | if (value) { | 160 | if (value) { |
@@ -167,7 +167,7 @@ static int btrfs_xattr_acl_set(struct dentry *dentry, const char *name, | |||
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | ret = btrfs_set_acl(dentry->d_inode, acl, type); | 170 | ret = btrfs_set_acl(NULL, dentry->d_inode, acl, type); |
171 | 171 | ||
172 | posix_acl_release(acl); | 172 | posix_acl_release(acl); |
173 | 173 | ||
@@ -196,7 +196,8 @@ int btrfs_check_acl(struct inode *inode, int mask) | |||
196 | * stuff has been fixed to work with that. If the locking stuff changes, we | 196 | * stuff has been fixed to work with that. If the locking stuff changes, we |
197 | * need to re-evaluate the acl locking stuff. | 197 | * need to re-evaluate the acl locking stuff. |
198 | */ | 198 | */ |
199 | int btrfs_init_acl(struct inode *inode, struct inode *dir) | 199 | int btrfs_init_acl(struct btrfs_trans_handle *trans, |
200 | struct inode *inode, struct inode *dir) | ||
200 | { | 201 | { |
201 | struct posix_acl *acl = NULL; | 202 | struct posix_acl *acl = NULL; |
202 | int ret = 0; | 203 | int ret = 0; |
@@ -221,7 +222,8 @@ int btrfs_init_acl(struct inode *inode, struct inode *dir) | |||
221 | mode_t mode; | 222 | mode_t mode; |
222 | 223 | ||
223 | if (S_ISDIR(inode->i_mode)) { | 224 | if (S_ISDIR(inode->i_mode)) { |
224 | ret = btrfs_set_acl(inode, acl, ACL_TYPE_DEFAULT); | 225 | ret = btrfs_set_acl(trans, inode, acl, |
226 | ACL_TYPE_DEFAULT); | ||
225 | if (ret) | 227 | if (ret) |
226 | goto failed; | 228 | goto failed; |
227 | } | 229 | } |
@@ -236,7 +238,7 @@ int btrfs_init_acl(struct inode *inode, struct inode *dir) | |||
236 | inode->i_mode = mode; | 238 | inode->i_mode = mode; |
237 | if (ret > 0) { | 239 | if (ret > 0) { |
238 | /* we need an acl */ | 240 | /* we need an acl */ |
239 | ret = btrfs_set_acl(inode, clone, | 241 | ret = btrfs_set_acl(trans, inode, clone, |
240 | ACL_TYPE_ACCESS); | 242 | ACL_TYPE_ACCESS); |
241 | } | 243 | } |
242 | } | 244 | } |
@@ -269,7 +271,7 @@ int btrfs_acl_chmod(struct inode *inode) | |||
269 | 271 | ||
270 | ret = posix_acl_chmod_masq(clone, inode->i_mode); | 272 | ret = posix_acl_chmod_masq(clone, inode->i_mode); |
271 | if (!ret) | 273 | if (!ret) |
272 | ret = btrfs_set_acl(inode, clone, ACL_TYPE_ACCESS); | 274 | ret = btrfs_set_acl(NULL, inode, clone, ACL_TYPE_ACCESS); |
273 | 275 | ||
274 | posix_acl_release(clone); | 276 | posix_acl_release(clone); |
275 | 277 | ||
@@ -297,7 +299,8 @@ int btrfs_acl_chmod(struct inode *inode) | |||
297 | return 0; | 299 | return 0; |
298 | } | 300 | } |
299 | 301 | ||
300 | int btrfs_init_acl(struct inode *inode, struct inode *dir) | 302 | int btrfs_init_acl(struct btrfs_trans_handle *trans, |
303 | struct inode *inode, struct inode *dir) | ||
301 | { | 304 | { |
302 | return 0; | 305 | return 0; |
303 | } | 306 | } |
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index f6783a42f010..3f1f50d9d916 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h | |||
@@ -44,9 +44,6 @@ struct btrfs_inode { | |||
44 | */ | 44 | */ |
45 | struct extent_io_tree io_failure_tree; | 45 | struct extent_io_tree io_failure_tree; |
46 | 46 | ||
47 | /* held while inesrting or deleting extents from files */ | ||
48 | struct mutex extent_mutex; | ||
49 | |||
50 | /* held while logging the inode in tree-log.c */ | 47 | /* held while logging the inode in tree-log.c */ |
51 | struct mutex log_mutex; | 48 | struct mutex log_mutex; |
52 | 49 | ||
@@ -166,7 +163,7 @@ static inline struct btrfs_inode *BTRFS_I(struct inode *inode) | |||
166 | 163 | ||
167 | static inline void btrfs_i_size_write(struct inode *inode, u64 size) | 164 | static inline void btrfs_i_size_write(struct inode *inode, u64 size) |
168 | { | 165 | { |
169 | inode->i_size = size; | 166 | i_size_write(inode, size); |
170 | BTRFS_I(inode)->disk_i_size = size; | 167 | BTRFS_I(inode)->disk_i_size = size; |
171 | } | 168 | } |
172 | 169 | ||
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index ec96f3a6d536..c4bc570a396e 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -37,6 +37,11 @@ static int balance_node_right(struct btrfs_trans_handle *trans, | |||
37 | struct extent_buffer *src_buf); | 37 | struct extent_buffer *src_buf); |
38 | static int del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, | 38 | static int del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
39 | struct btrfs_path *path, int level, int slot); | 39 | struct btrfs_path *path, int level, int slot); |
40 | static int setup_items_for_insert(struct btrfs_trans_handle *trans, | ||
41 | struct btrfs_root *root, struct btrfs_path *path, | ||
42 | struct btrfs_key *cpu_key, u32 *data_size, | ||
43 | u32 total_data, u32 total_size, int nr); | ||
44 | |||
40 | 45 | ||
41 | struct btrfs_path *btrfs_alloc_path(void) | 46 | struct btrfs_path *btrfs_alloc_path(void) |
42 | { | 47 | { |
@@ -451,9 +456,8 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, | |||
451 | extent_buffer_get(cow); | 456 | extent_buffer_get(cow); |
452 | spin_unlock(&root->node_lock); | 457 | spin_unlock(&root->node_lock); |
453 | 458 | ||
454 | btrfs_free_extent(trans, root, buf->start, buf->len, | 459 | btrfs_free_tree_block(trans, root, buf->start, buf->len, |
455 | parent_start, root->root_key.objectid, | 460 | parent_start, root->root_key.objectid, level); |
456 | level, 0); | ||
457 | free_extent_buffer(buf); | 461 | free_extent_buffer(buf); |
458 | add_root_to_dirty_list(root); | 462 | add_root_to_dirty_list(root); |
459 | } else { | 463 | } else { |
@@ -468,9 +472,8 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans, | |||
468 | btrfs_set_node_ptr_generation(parent, parent_slot, | 472 | btrfs_set_node_ptr_generation(parent, parent_slot, |
469 | trans->transid); | 473 | trans->transid); |
470 | btrfs_mark_buffer_dirty(parent); | 474 | btrfs_mark_buffer_dirty(parent); |
471 | btrfs_free_extent(trans, root, buf->start, buf->len, | 475 | btrfs_free_tree_block(trans, root, buf->start, buf->len, |
472 | parent_start, root->root_key.objectid, | 476 | parent_start, root->root_key.objectid, level); |
473 | level, 0); | ||
474 | } | 477 | } |
475 | if (unlock_orig) | 478 | if (unlock_orig) |
476 | btrfs_tree_unlock(buf); | 479 | btrfs_tree_unlock(buf); |
@@ -1030,8 +1033,8 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, | |||
1030 | btrfs_tree_unlock(mid); | 1033 | btrfs_tree_unlock(mid); |
1031 | /* once for the path */ | 1034 | /* once for the path */ |
1032 | free_extent_buffer(mid); | 1035 | free_extent_buffer(mid); |
1033 | ret = btrfs_free_extent(trans, root, mid->start, mid->len, | 1036 | ret = btrfs_free_tree_block(trans, root, mid->start, mid->len, |
1034 | 0, root->root_key.objectid, level, 1); | 1037 | 0, root->root_key.objectid, level); |
1035 | /* once for the root ptr */ | 1038 | /* once for the root ptr */ |
1036 | free_extent_buffer(mid); | 1039 | free_extent_buffer(mid); |
1037 | return ret; | 1040 | return ret; |
@@ -1095,10 +1098,10 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, | |||
1095 | 1); | 1098 | 1); |
1096 | if (wret) | 1099 | if (wret) |
1097 | ret = wret; | 1100 | ret = wret; |
1098 | wret = btrfs_free_extent(trans, root, bytenr, | 1101 | wret = btrfs_free_tree_block(trans, root, |
1099 | blocksize, 0, | 1102 | bytenr, blocksize, 0, |
1100 | root->root_key.objectid, | 1103 | root->root_key.objectid, |
1101 | level, 0); | 1104 | level); |
1102 | if (wret) | 1105 | if (wret) |
1103 | ret = wret; | 1106 | ret = wret; |
1104 | } else { | 1107 | } else { |
@@ -1143,9 +1146,8 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, | |||
1143 | wret = del_ptr(trans, root, path, level + 1, pslot); | 1146 | wret = del_ptr(trans, root, path, level + 1, pslot); |
1144 | if (wret) | 1147 | if (wret) |
1145 | ret = wret; | 1148 | ret = wret; |
1146 | wret = btrfs_free_extent(trans, root, bytenr, blocksize, | 1149 | wret = btrfs_free_tree_block(trans, root, bytenr, blocksize, |
1147 | 0, root->root_key.objectid, | 1150 | 0, root->root_key.objectid, level); |
1148 | level, 0); | ||
1149 | if (wret) | 1151 | if (wret) |
1150 | ret = wret; | 1152 | ret = wret; |
1151 | } else { | 1153 | } else { |
@@ -2997,75 +2999,85 @@ again: | |||
2997 | return ret; | 2999 | return ret; |
2998 | } | 3000 | } |
2999 | 3001 | ||
3000 | /* | 3002 | static noinline int setup_leaf_for_split(struct btrfs_trans_handle *trans, |
3001 | * This function splits a single item into two items, | 3003 | struct btrfs_root *root, |
3002 | * giving 'new_key' to the new item and splitting the | 3004 | struct btrfs_path *path, int ins_len) |
3003 | * old one at split_offset (from the start of the item). | ||
3004 | * | ||
3005 | * The path may be released by this operation. After | ||
3006 | * the split, the path is pointing to the old item. The | ||
3007 | * new item is going to be in the same node as the old one. | ||
3008 | * | ||
3009 | * Note, the item being split must be smaller enough to live alone on | ||
3010 | * a tree block with room for one extra struct btrfs_item | ||
3011 | * | ||
3012 | * This allows us to split the item in place, keeping a lock on the | ||
3013 | * leaf the entire time. | ||
3014 | */ | ||
3015 | int btrfs_split_item(struct btrfs_trans_handle *trans, | ||
3016 | struct btrfs_root *root, | ||
3017 | struct btrfs_path *path, | ||
3018 | struct btrfs_key *new_key, | ||
3019 | unsigned long split_offset) | ||
3020 | { | 3005 | { |
3021 | u32 item_size; | 3006 | struct btrfs_key key; |
3022 | struct extent_buffer *leaf; | 3007 | struct extent_buffer *leaf; |
3023 | struct btrfs_key orig_key; | 3008 | struct btrfs_file_extent_item *fi; |
3024 | struct btrfs_item *item; | 3009 | u64 extent_len = 0; |
3025 | struct btrfs_item *new_item; | 3010 | u32 item_size; |
3026 | int ret = 0; | 3011 | int ret; |
3027 | int slot; | ||
3028 | u32 nritems; | ||
3029 | u32 orig_offset; | ||
3030 | struct btrfs_disk_key disk_key; | ||
3031 | char *buf; | ||
3032 | 3012 | ||
3033 | leaf = path->nodes[0]; | 3013 | leaf = path->nodes[0]; |
3034 | btrfs_item_key_to_cpu(leaf, &orig_key, path->slots[0]); | 3014 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); |
3035 | if (btrfs_leaf_free_space(root, leaf) >= sizeof(struct btrfs_item)) | 3015 | |
3036 | goto split; | 3016 | BUG_ON(key.type != BTRFS_EXTENT_DATA_KEY && |
3017 | key.type != BTRFS_EXTENT_CSUM_KEY); | ||
3018 | |||
3019 | if (btrfs_leaf_free_space(root, leaf) >= ins_len) | ||
3020 | return 0; | ||
3037 | 3021 | ||
3038 | item_size = btrfs_item_size_nr(leaf, path->slots[0]); | 3022 | item_size = btrfs_item_size_nr(leaf, path->slots[0]); |
3023 | if (key.type == BTRFS_EXTENT_DATA_KEY) { | ||
3024 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
3025 | struct btrfs_file_extent_item); | ||
3026 | extent_len = btrfs_file_extent_num_bytes(leaf, fi); | ||
3027 | } | ||
3039 | btrfs_release_path(root, path); | 3028 | btrfs_release_path(root, path); |
3040 | 3029 | ||
3041 | path->search_for_split = 1; | ||
3042 | path->keep_locks = 1; | 3030 | path->keep_locks = 1; |
3043 | 3031 | path->search_for_split = 1; | |
3044 | ret = btrfs_search_slot(trans, root, &orig_key, path, 0, 1); | 3032 | ret = btrfs_search_slot(trans, root, &key, path, 0, 1); |
3045 | path->search_for_split = 0; | 3033 | path->search_for_split = 0; |
3034 | if (ret < 0) | ||
3035 | goto err; | ||
3046 | 3036 | ||
3037 | ret = -EAGAIN; | ||
3038 | leaf = path->nodes[0]; | ||
3047 | /* if our item isn't there or got smaller, return now */ | 3039 | /* if our item isn't there or got smaller, return now */ |
3048 | if (ret != 0 || item_size != btrfs_item_size_nr(path->nodes[0], | 3040 | if (ret > 0 || item_size != btrfs_item_size_nr(leaf, path->slots[0])) |
3049 | path->slots[0])) { | 3041 | goto err; |
3050 | path->keep_locks = 0; | 3042 | |
3051 | return -EAGAIN; | 3043 | if (key.type == BTRFS_EXTENT_DATA_KEY) { |
3044 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
3045 | struct btrfs_file_extent_item); | ||
3046 | if (extent_len != btrfs_file_extent_num_bytes(leaf, fi)) | ||
3047 | goto err; | ||
3052 | } | 3048 | } |
3053 | 3049 | ||
3054 | btrfs_set_path_blocking(path); | 3050 | btrfs_set_path_blocking(path); |
3055 | ret = split_leaf(trans, root, &orig_key, path, | 3051 | ret = split_leaf(trans, root, &key, path, ins_len, 1); |
3056 | sizeof(struct btrfs_item), 1); | ||
3057 | path->keep_locks = 0; | ||
3058 | BUG_ON(ret); | 3052 | BUG_ON(ret); |
3059 | 3053 | ||
3054 | path->keep_locks = 0; | ||
3060 | btrfs_unlock_up_safe(path, 1); | 3055 | btrfs_unlock_up_safe(path, 1); |
3056 | return 0; | ||
3057 | err: | ||
3058 | path->keep_locks = 0; | ||
3059 | return ret; | ||
3060 | } | ||
3061 | |||
3062 | static noinline int split_item(struct btrfs_trans_handle *trans, | ||
3063 | struct btrfs_root *root, | ||
3064 | struct btrfs_path *path, | ||
3065 | struct btrfs_key *new_key, | ||
3066 | unsigned long split_offset) | ||
3067 | { | ||
3068 | struct extent_buffer *leaf; | ||
3069 | struct btrfs_item *item; | ||
3070 | struct btrfs_item *new_item; | ||
3071 | int slot; | ||
3072 | char *buf; | ||
3073 | u32 nritems; | ||
3074 | u32 item_size; | ||
3075 | u32 orig_offset; | ||
3076 | struct btrfs_disk_key disk_key; | ||
3077 | |||
3061 | leaf = path->nodes[0]; | 3078 | leaf = path->nodes[0]; |
3062 | BUG_ON(btrfs_leaf_free_space(root, leaf) < sizeof(struct btrfs_item)); | 3079 | BUG_ON(btrfs_leaf_free_space(root, leaf) < sizeof(struct btrfs_item)); |
3063 | 3080 | ||
3064 | split: | ||
3065 | /* | ||
3066 | * make sure any changes to the path from split_leaf leave it | ||
3067 | * in a blocking state | ||
3068 | */ | ||
3069 | btrfs_set_path_blocking(path); | 3081 | btrfs_set_path_blocking(path); |
3070 | 3082 | ||
3071 | item = btrfs_item_nr(leaf, path->slots[0]); | 3083 | item = btrfs_item_nr(leaf, path->slots[0]); |
@@ -3073,19 +3085,19 @@ split: | |||
3073 | item_size = btrfs_item_size(leaf, item); | 3085 | item_size = btrfs_item_size(leaf, item); |
3074 | 3086 | ||
3075 | buf = kmalloc(item_size, GFP_NOFS); | 3087 | buf = kmalloc(item_size, GFP_NOFS); |
3088 | if (!buf) | ||
3089 | return -ENOMEM; | ||
3090 | |||
3076 | read_extent_buffer(leaf, buf, btrfs_item_ptr_offset(leaf, | 3091 | read_extent_buffer(leaf, buf, btrfs_item_ptr_offset(leaf, |
3077 | path->slots[0]), item_size); | 3092 | path->slots[0]), item_size); |
3078 | slot = path->slots[0] + 1; | ||
3079 | leaf = path->nodes[0]; | ||
3080 | 3093 | ||
3094 | slot = path->slots[0] + 1; | ||
3081 | nritems = btrfs_header_nritems(leaf); | 3095 | nritems = btrfs_header_nritems(leaf); |
3082 | |||
3083 | if (slot != nritems) { | 3096 | if (slot != nritems) { |
3084 | /* shift the items */ | 3097 | /* shift the items */ |
3085 | memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + 1), | 3098 | memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + 1), |
3086 | btrfs_item_nr_offset(slot), | 3099 | btrfs_item_nr_offset(slot), |
3087 | (nritems - slot) * sizeof(struct btrfs_item)); | 3100 | (nritems - slot) * sizeof(struct btrfs_item)); |
3088 | |||
3089 | } | 3101 | } |
3090 | 3102 | ||
3091 | btrfs_cpu_key_to_disk(&disk_key, new_key); | 3103 | btrfs_cpu_key_to_disk(&disk_key, new_key); |
@@ -3113,16 +3125,81 @@ split: | |||
3113 | item_size - split_offset); | 3125 | item_size - split_offset); |
3114 | btrfs_mark_buffer_dirty(leaf); | 3126 | btrfs_mark_buffer_dirty(leaf); |
3115 | 3127 | ||
3116 | ret = 0; | 3128 | BUG_ON(btrfs_leaf_free_space(root, leaf) < 0); |
3117 | if (btrfs_leaf_free_space(root, leaf) < 0) { | ||
3118 | btrfs_print_leaf(root, leaf); | ||
3119 | BUG(); | ||
3120 | } | ||
3121 | kfree(buf); | 3129 | kfree(buf); |
3130 | return 0; | ||
3131 | } | ||
3132 | |||
3133 | /* | ||
3134 | * This function splits a single item into two items, | ||
3135 | * giving 'new_key' to the new item and splitting the | ||
3136 | * old one at split_offset (from the start of the item). | ||
3137 | * | ||
3138 | * The path may be released by this operation. After | ||
3139 | * the split, the path is pointing to the old item. The | ||
3140 | * new item is going to be in the same node as the old one. | ||
3141 | * | ||
3142 | * Note, the item being split must be smaller enough to live alone on | ||
3143 | * a tree block with room for one extra struct btrfs_item | ||
3144 | * | ||
3145 | * This allows us to split the item in place, keeping a lock on the | ||
3146 | * leaf the entire time. | ||
3147 | */ | ||
3148 | int btrfs_split_item(struct btrfs_trans_handle *trans, | ||
3149 | struct btrfs_root *root, | ||
3150 | struct btrfs_path *path, | ||
3151 | struct btrfs_key *new_key, | ||
3152 | unsigned long split_offset) | ||
3153 | { | ||
3154 | int ret; | ||
3155 | ret = setup_leaf_for_split(trans, root, path, | ||
3156 | sizeof(struct btrfs_item)); | ||
3157 | if (ret) | ||
3158 | return ret; | ||
3159 | |||
3160 | ret = split_item(trans, root, path, new_key, split_offset); | ||
3122 | return ret; | 3161 | return ret; |
3123 | } | 3162 | } |
3124 | 3163 | ||
3125 | /* | 3164 | /* |
3165 | * This function duplicate a item, giving 'new_key' to the new item. | ||
3166 | * It guarantees both items live in the same tree leaf and the new item | ||
3167 | * is contiguous with the original item. | ||
3168 | * | ||
3169 | * This allows us to split file extent in place, keeping a lock on the | ||
3170 | * leaf the entire time. | ||
3171 | */ | ||
3172 | int btrfs_duplicate_item(struct btrfs_trans_handle *trans, | ||
3173 | struct btrfs_root *root, | ||
3174 | struct btrfs_path *path, | ||
3175 | struct btrfs_key *new_key) | ||
3176 | { | ||
3177 | struct extent_buffer *leaf; | ||
3178 | int ret; | ||
3179 | u32 item_size; | ||
3180 | |||
3181 | leaf = path->nodes[0]; | ||
3182 | item_size = btrfs_item_size_nr(leaf, path->slots[0]); | ||
3183 | ret = setup_leaf_for_split(trans, root, path, | ||
3184 | item_size + sizeof(struct btrfs_item)); | ||
3185 | if (ret) | ||
3186 | return ret; | ||
3187 | |||
3188 | path->slots[0]++; | ||
3189 | ret = setup_items_for_insert(trans, root, path, new_key, &item_size, | ||
3190 | item_size, item_size + | ||
3191 | sizeof(struct btrfs_item), 1); | ||
3192 | BUG_ON(ret); | ||
3193 | |||
3194 | leaf = path->nodes[0]; | ||
3195 | memcpy_extent_buffer(leaf, | ||
3196 | btrfs_item_ptr_offset(leaf, path->slots[0]), | ||
3197 | btrfs_item_ptr_offset(leaf, path->slots[0] - 1), | ||
3198 | item_size); | ||
3199 | return 0; | ||
3200 | } | ||
3201 | |||
3202 | /* | ||
3126 | * make the item pointed to by the path smaller. new_size indicates | 3203 | * make the item pointed to by the path smaller. new_size indicates |
3127 | * how small to make it, and from_end tells us if we just chop bytes | 3204 | * how small to make it, and from_end tells us if we just chop bytes |
3128 | * off the end of the item or if we shift the item to chop bytes off | 3205 | * off the end of the item or if we shift the item to chop bytes off |
@@ -3714,8 +3791,8 @@ static noinline int btrfs_del_leaf(struct btrfs_trans_handle *trans, | |||
3714 | */ | 3791 | */ |
3715 | btrfs_unlock_up_safe(path, 0); | 3792 | btrfs_unlock_up_safe(path, 0); |
3716 | 3793 | ||
3717 | ret = btrfs_free_extent(trans, root, leaf->start, leaf->len, | 3794 | ret = btrfs_free_tree_block(trans, root, leaf->start, leaf->len, |
3718 | 0, root->root_key.objectid, 0, 0); | 3795 | 0, root->root_key.objectid, 0); |
3719 | return ret; | 3796 | return ret; |
3720 | } | 3797 | } |
3721 | /* | 3798 | /* |
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 444b3e9b92a4..9f806dd04c27 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -310,6 +310,9 @@ struct btrfs_header { | |||
310 | #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ | 310 | #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ |
311 | sizeof(struct btrfs_item) - \ | 311 | sizeof(struct btrfs_item) - \ |
312 | sizeof(struct btrfs_file_extent_item)) | 312 | sizeof(struct btrfs_file_extent_item)) |
313 | #define BTRFS_MAX_XATTR_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ | ||
314 | sizeof(struct btrfs_item) -\ | ||
315 | sizeof(struct btrfs_dir_item)) | ||
313 | 316 | ||
314 | 317 | ||
315 | /* | 318 | /* |
@@ -859,8 +862,9 @@ struct btrfs_fs_info { | |||
859 | struct mutex ordered_operations_mutex; | 862 | struct mutex ordered_operations_mutex; |
860 | struct rw_semaphore extent_commit_sem; | 863 | struct rw_semaphore extent_commit_sem; |
861 | 864 | ||
862 | struct rw_semaphore subvol_sem; | 865 | struct rw_semaphore cleanup_work_sem; |
863 | 866 | ||
867 | struct rw_semaphore subvol_sem; | ||
864 | struct srcu_struct subvol_srcu; | 868 | struct srcu_struct subvol_srcu; |
865 | 869 | ||
866 | struct list_head trans_list; | 870 | struct list_head trans_list; |
@@ -868,6 +872,9 @@ struct btrfs_fs_info { | |||
868 | struct list_head dead_roots; | 872 | struct list_head dead_roots; |
869 | struct list_head caching_block_groups; | 873 | struct list_head caching_block_groups; |
870 | 874 | ||
875 | spinlock_t delayed_iput_lock; | ||
876 | struct list_head delayed_iputs; | ||
877 | |||
871 | atomic_t nr_async_submits; | 878 | atomic_t nr_async_submits; |
872 | atomic_t async_submit_draining; | 879 | atomic_t async_submit_draining; |
873 | atomic_t nr_async_bios; | 880 | atomic_t nr_async_bios; |
@@ -1034,12 +1041,12 @@ struct btrfs_root { | |||
1034 | int ref_cows; | 1041 | int ref_cows; |
1035 | int track_dirty; | 1042 | int track_dirty; |
1036 | int in_radix; | 1043 | int in_radix; |
1044 | int clean_orphans; | ||
1037 | 1045 | ||
1038 | u64 defrag_trans_start; | 1046 | u64 defrag_trans_start; |
1039 | struct btrfs_key defrag_progress; | 1047 | struct btrfs_key defrag_progress; |
1040 | struct btrfs_key defrag_max; | 1048 | struct btrfs_key defrag_max; |
1041 | int defrag_running; | 1049 | int defrag_running; |
1042 | int defrag_level; | ||
1043 | char *name; | 1050 | char *name; |
1044 | int in_sysfs; | 1051 | int in_sysfs; |
1045 | 1052 | ||
@@ -1975,6 +1982,10 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, | |||
1975 | u64 parent, u64 root_objectid, | 1982 | u64 parent, u64 root_objectid, |
1976 | struct btrfs_disk_key *key, int level, | 1983 | struct btrfs_disk_key *key, int level, |
1977 | u64 hint, u64 empty_size); | 1984 | u64 hint, u64 empty_size); |
1985 | int btrfs_free_tree_block(struct btrfs_trans_handle *trans, | ||
1986 | struct btrfs_root *root, | ||
1987 | u64 bytenr, u32 blocksize, | ||
1988 | u64 parent, u64 root_objectid, int level); | ||
1978 | struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans, | 1989 | struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans, |
1979 | struct btrfs_root *root, | 1990 | struct btrfs_root *root, |
1980 | u64 bytenr, u32 blocksize, | 1991 | u64 bytenr, u32 blocksize, |
@@ -2089,6 +2100,10 @@ int btrfs_split_item(struct btrfs_trans_handle *trans, | |||
2089 | struct btrfs_path *path, | 2100 | struct btrfs_path *path, |
2090 | struct btrfs_key *new_key, | 2101 | struct btrfs_key *new_key, |
2091 | unsigned long split_offset); | 2102 | unsigned long split_offset); |
2103 | int btrfs_duplicate_item(struct btrfs_trans_handle *trans, | ||
2104 | struct btrfs_root *root, | ||
2105 | struct btrfs_path *path, | ||
2106 | struct btrfs_key *new_key); | ||
2092 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root | 2107 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root |
2093 | *root, struct btrfs_key *key, struct btrfs_path *p, int | 2108 | *root, struct btrfs_key *key, struct btrfs_path *p, int |
2094 | ins_len, int cow); | 2109 | ins_len, int cow); |
@@ -2196,9 +2211,10 @@ int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, | |||
2196 | struct btrfs_path *path, | 2211 | struct btrfs_path *path, |
2197 | struct btrfs_dir_item *di); | 2212 | struct btrfs_dir_item *di); |
2198 | int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, | 2213 | int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, |
2199 | struct btrfs_root *root, const char *name, | 2214 | struct btrfs_root *root, |
2200 | u16 name_len, const void *data, u16 data_len, | 2215 | struct btrfs_path *path, u64 objectid, |
2201 | u64 dir); | 2216 | const char *name, u16 name_len, |
2217 | const void *data, u16 data_len); | ||
2202 | struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans, | 2218 | struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans, |
2203 | struct btrfs_root *root, | 2219 | struct btrfs_root *root, |
2204 | struct btrfs_path *path, u64 dir, | 2220 | struct btrfs_path *path, u64 dir, |
@@ -2292,7 +2308,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, | |||
2292 | struct inode *inode, u64 new_size, | 2308 | struct inode *inode, u64 new_size, |
2293 | u32 min_type); | 2309 | u32 min_type); |
2294 | 2310 | ||
2295 | int btrfs_start_delalloc_inodes(struct btrfs_root *root); | 2311 | int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput); |
2296 | int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end); | 2312 | int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end); |
2297 | int btrfs_writepages(struct address_space *mapping, | 2313 | int btrfs_writepages(struct address_space *mapping, |
2298 | struct writeback_control *wbc); | 2314 | struct writeback_control *wbc); |
@@ -2332,6 +2348,8 @@ int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode); | |||
2332 | void btrfs_orphan_cleanup(struct btrfs_root *root); | 2348 | void btrfs_orphan_cleanup(struct btrfs_root *root); |
2333 | int btrfs_cont_expand(struct inode *inode, loff_t size); | 2349 | int btrfs_cont_expand(struct inode *inode, loff_t size); |
2334 | int btrfs_invalidate_inodes(struct btrfs_root *root); | 2350 | int btrfs_invalidate_inodes(struct btrfs_root *root); |
2351 | void btrfs_add_delayed_iput(struct inode *inode); | ||
2352 | void btrfs_run_delayed_iputs(struct btrfs_root *root); | ||
2335 | extern const struct dentry_operations btrfs_dentry_operations; | 2353 | extern const struct dentry_operations btrfs_dentry_operations; |
2336 | 2354 | ||
2337 | /* ioctl.c */ | 2355 | /* ioctl.c */ |
@@ -2345,12 +2363,9 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, | |||
2345 | int skip_pinned); | 2363 | int skip_pinned); |
2346 | int btrfs_check_file(struct btrfs_root *root, struct inode *inode); | 2364 | int btrfs_check_file(struct btrfs_root *root, struct inode *inode); |
2347 | extern const struct file_operations btrfs_file_operations; | 2365 | extern const struct file_operations btrfs_file_operations; |
2348 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, | 2366 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, |
2349 | struct btrfs_root *root, struct inode *inode, | 2367 | u64 start, u64 end, u64 *hint_byte, int drop_cache); |
2350 | u64 start, u64 end, u64 locked_end, | ||
2351 | u64 inline_limit, u64 *hint_block, int drop_cache); | ||
2352 | int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, | 2368 | int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, |
2353 | struct btrfs_root *root, | ||
2354 | struct inode *inode, u64 start, u64 end); | 2369 | struct inode *inode, u64 start, u64 end); |
2355 | int btrfs_release_file(struct inode *inode, struct file *file); | 2370 | int btrfs_release_file(struct inode *inode, struct file *file); |
2356 | 2371 | ||
@@ -2380,7 +2395,8 @@ int btrfs_check_acl(struct inode *inode, int mask); | |||
2380 | #else | 2395 | #else |
2381 | #define btrfs_check_acl NULL | 2396 | #define btrfs_check_acl NULL |
2382 | #endif | 2397 | #endif |
2383 | int btrfs_init_acl(struct inode *inode, struct inode *dir); | 2398 | int btrfs_init_acl(struct btrfs_trans_handle *trans, |
2399 | struct inode *inode, struct inode *dir); | ||
2384 | int btrfs_acl_chmod(struct inode *inode); | 2400 | int btrfs_acl_chmod(struct inode *inode); |
2385 | 2401 | ||
2386 | /* relocation.c */ | 2402 | /* relocation.c */ |
diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index f3a6075519cc..e9103b3baa49 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c | |||
@@ -68,12 +68,12 @@ static struct btrfs_dir_item *insert_with_overflow(struct btrfs_trans_handle | |||
68 | * into the tree | 68 | * into the tree |
69 | */ | 69 | */ |
70 | int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, | 70 | int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, |
71 | struct btrfs_root *root, const char *name, | 71 | struct btrfs_root *root, |
72 | u16 name_len, const void *data, u16 data_len, | 72 | struct btrfs_path *path, u64 objectid, |
73 | u64 dir) | 73 | const char *name, u16 name_len, |
74 | const void *data, u16 data_len) | ||
74 | { | 75 | { |
75 | int ret = 0; | 76 | int ret = 0; |
76 | struct btrfs_path *path; | ||
77 | struct btrfs_dir_item *dir_item; | 77 | struct btrfs_dir_item *dir_item; |
78 | unsigned long name_ptr, data_ptr; | 78 | unsigned long name_ptr, data_ptr; |
79 | struct btrfs_key key, location; | 79 | struct btrfs_key key, location; |
@@ -81,15 +81,11 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, | |||
81 | struct extent_buffer *leaf; | 81 | struct extent_buffer *leaf; |
82 | u32 data_size; | 82 | u32 data_size; |
83 | 83 | ||
84 | key.objectid = dir; | 84 | BUG_ON(name_len + data_len > BTRFS_MAX_XATTR_SIZE(root)); |
85 | |||
86 | key.objectid = objectid; | ||
85 | btrfs_set_key_type(&key, BTRFS_XATTR_ITEM_KEY); | 87 | btrfs_set_key_type(&key, BTRFS_XATTR_ITEM_KEY); |
86 | key.offset = btrfs_name_hash(name, name_len); | 88 | key.offset = btrfs_name_hash(name, name_len); |
87 | path = btrfs_alloc_path(); | ||
88 | if (!path) | ||
89 | return -ENOMEM; | ||
90 | if (name_len + data_len + sizeof(struct btrfs_dir_item) > | ||
91 | BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item)) | ||
92 | return -ENOSPC; | ||
93 | 89 | ||
94 | data_size = sizeof(*dir_item) + name_len + data_len; | 90 | data_size = sizeof(*dir_item) + name_len + data_len; |
95 | dir_item = insert_with_overflow(trans, root, path, &key, data_size, | 91 | dir_item = insert_with_overflow(trans, root, path, &key, data_size, |
@@ -117,7 +113,6 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, | |||
117 | write_extent_buffer(leaf, data, data_ptr, data_len); | 113 | write_extent_buffer(leaf, data, data_ptr, data_len); |
118 | btrfs_mark_buffer_dirty(path->nodes[0]); | 114 | btrfs_mark_buffer_dirty(path->nodes[0]); |
119 | 115 | ||
120 | btrfs_free_path(path); | ||
121 | return ret; | 116 | return ret; |
122 | } | 117 | } |
123 | 118 | ||
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 02b6afbd7450..009e3bd18f23 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -892,6 +892,8 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
892 | root->stripesize = stripesize; | 892 | root->stripesize = stripesize; |
893 | root->ref_cows = 0; | 893 | root->ref_cows = 0; |
894 | root->track_dirty = 0; | 894 | root->track_dirty = 0; |
895 | root->in_radix = 0; | ||
896 | root->clean_orphans = 0; | ||
895 | 897 | ||
896 | root->fs_info = fs_info; | 898 | root->fs_info = fs_info; |
897 | root->objectid = objectid; | 899 | root->objectid = objectid; |
@@ -928,7 +930,6 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
928 | root->defrag_trans_start = fs_info->generation; | 930 | root->defrag_trans_start = fs_info->generation; |
929 | init_completion(&root->kobj_unregister); | 931 | init_completion(&root->kobj_unregister); |
930 | root->defrag_running = 0; | 932 | root->defrag_running = 0; |
931 | root->defrag_level = 0; | ||
932 | root->root_key.objectid = objectid; | 933 | root->root_key.objectid = objectid; |
933 | root->anon_super.s_root = NULL; | 934 | root->anon_super.s_root = NULL; |
934 | root->anon_super.s_dev = 0; | 935 | root->anon_super.s_dev = 0; |
@@ -980,12 +981,12 @@ int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans, | |||
980 | 981 | ||
981 | while (1) { | 982 | while (1) { |
982 | ret = find_first_extent_bit(&log_root_tree->dirty_log_pages, | 983 | ret = find_first_extent_bit(&log_root_tree->dirty_log_pages, |
983 | 0, &start, &end, EXTENT_DIRTY); | 984 | 0, &start, &end, EXTENT_DIRTY | EXTENT_NEW); |
984 | if (ret) | 985 | if (ret) |
985 | break; | 986 | break; |
986 | 987 | ||
987 | clear_extent_dirty(&log_root_tree->dirty_log_pages, | 988 | clear_extent_bits(&log_root_tree->dirty_log_pages, start, end, |
988 | start, end, GFP_NOFS); | 989 | EXTENT_DIRTY | EXTENT_NEW, GFP_NOFS); |
989 | } | 990 | } |
990 | eb = fs_info->log_root_tree->node; | 991 | eb = fs_info->log_root_tree->node; |
991 | 992 | ||
@@ -1210,8 +1211,10 @@ again: | |||
1210 | ret = radix_tree_insert(&fs_info->fs_roots_radix, | 1211 | ret = radix_tree_insert(&fs_info->fs_roots_radix, |
1211 | (unsigned long)root->root_key.objectid, | 1212 | (unsigned long)root->root_key.objectid, |
1212 | root); | 1213 | root); |
1213 | if (ret == 0) | 1214 | if (ret == 0) { |
1214 | root->in_radix = 1; | 1215 | root->in_radix = 1; |
1216 | root->clean_orphans = 1; | ||
1217 | } | ||
1215 | spin_unlock(&fs_info->fs_roots_radix_lock); | 1218 | spin_unlock(&fs_info->fs_roots_radix_lock); |
1216 | radix_tree_preload_end(); | 1219 | radix_tree_preload_end(); |
1217 | if (ret) { | 1220 | if (ret) { |
@@ -1225,10 +1228,6 @@ again: | |||
1225 | ret = btrfs_find_dead_roots(fs_info->tree_root, | 1228 | ret = btrfs_find_dead_roots(fs_info->tree_root, |
1226 | root->root_key.objectid); | 1229 | root->root_key.objectid); |
1227 | WARN_ON(ret); | 1230 | WARN_ON(ret); |
1228 | |||
1229 | if (!(fs_info->sb->s_flags & MS_RDONLY)) | ||
1230 | btrfs_orphan_cleanup(root); | ||
1231 | |||
1232 | return root; | 1231 | return root; |
1233 | fail: | 1232 | fail: |
1234 | free_fs_root(root); | 1233 | free_fs_root(root); |
@@ -1477,6 +1476,7 @@ static int cleaner_kthread(void *arg) | |||
1477 | 1476 | ||
1478 | if (!(root->fs_info->sb->s_flags & MS_RDONLY) && | 1477 | if (!(root->fs_info->sb->s_flags & MS_RDONLY) && |
1479 | mutex_trylock(&root->fs_info->cleaner_mutex)) { | 1478 | mutex_trylock(&root->fs_info->cleaner_mutex)) { |
1479 | btrfs_run_delayed_iputs(root); | ||
1480 | btrfs_clean_old_snapshots(root); | 1480 | btrfs_clean_old_snapshots(root); |
1481 | mutex_unlock(&root->fs_info->cleaner_mutex); | 1481 | mutex_unlock(&root->fs_info->cleaner_mutex); |
1482 | } | 1482 | } |
@@ -1606,6 +1606,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1606 | INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); | 1606 | INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC); |
1607 | INIT_LIST_HEAD(&fs_info->trans_list); | 1607 | INIT_LIST_HEAD(&fs_info->trans_list); |
1608 | INIT_LIST_HEAD(&fs_info->dead_roots); | 1608 | INIT_LIST_HEAD(&fs_info->dead_roots); |
1609 | INIT_LIST_HEAD(&fs_info->delayed_iputs); | ||
1609 | INIT_LIST_HEAD(&fs_info->hashers); | 1610 | INIT_LIST_HEAD(&fs_info->hashers); |
1610 | INIT_LIST_HEAD(&fs_info->delalloc_inodes); | 1611 | INIT_LIST_HEAD(&fs_info->delalloc_inodes); |
1611 | INIT_LIST_HEAD(&fs_info->ordered_operations); | 1612 | INIT_LIST_HEAD(&fs_info->ordered_operations); |
@@ -1614,6 +1615,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1614 | spin_lock_init(&fs_info->new_trans_lock); | 1615 | spin_lock_init(&fs_info->new_trans_lock); |
1615 | spin_lock_init(&fs_info->ref_cache_lock); | 1616 | spin_lock_init(&fs_info->ref_cache_lock); |
1616 | spin_lock_init(&fs_info->fs_roots_radix_lock); | 1617 | spin_lock_init(&fs_info->fs_roots_radix_lock); |
1618 | spin_lock_init(&fs_info->delayed_iput_lock); | ||
1617 | 1619 | ||
1618 | init_completion(&fs_info->kobj_unregister); | 1620 | init_completion(&fs_info->kobj_unregister); |
1619 | fs_info->tree_root = tree_root; | 1621 | fs_info->tree_root = tree_root; |
@@ -1689,6 +1691,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1689 | mutex_init(&fs_info->cleaner_mutex); | 1691 | mutex_init(&fs_info->cleaner_mutex); |
1690 | mutex_init(&fs_info->volume_mutex); | 1692 | mutex_init(&fs_info->volume_mutex); |
1691 | init_rwsem(&fs_info->extent_commit_sem); | 1693 | init_rwsem(&fs_info->extent_commit_sem); |
1694 | init_rwsem(&fs_info->cleanup_work_sem); | ||
1692 | init_rwsem(&fs_info->subvol_sem); | 1695 | init_rwsem(&fs_info->subvol_sem); |
1693 | 1696 | ||
1694 | btrfs_init_free_cluster(&fs_info->meta_alloc_cluster); | 1697 | btrfs_init_free_cluster(&fs_info->meta_alloc_cluster); |
@@ -2386,8 +2389,14 @@ int btrfs_commit_super(struct btrfs_root *root) | |||
2386 | int ret; | 2389 | int ret; |
2387 | 2390 | ||
2388 | mutex_lock(&root->fs_info->cleaner_mutex); | 2391 | mutex_lock(&root->fs_info->cleaner_mutex); |
2392 | btrfs_run_delayed_iputs(root); | ||
2389 | btrfs_clean_old_snapshots(root); | 2393 | btrfs_clean_old_snapshots(root); |
2390 | mutex_unlock(&root->fs_info->cleaner_mutex); | 2394 | mutex_unlock(&root->fs_info->cleaner_mutex); |
2395 | |||
2396 | /* wait until ongoing cleanup work done */ | ||
2397 | down_write(&root->fs_info->cleanup_work_sem); | ||
2398 | up_write(&root->fs_info->cleanup_work_sem); | ||
2399 | |||
2391 | trans = btrfs_start_transaction(root, 1); | 2400 | trans = btrfs_start_transaction(root, 1); |
2392 | ret = btrfs_commit_transaction(trans, root); | 2401 | ret = btrfs_commit_transaction(trans, root); |
2393 | BUG_ON(ret); | 2402 | BUG_ON(ret); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 94627c4cc193..56e50137d0e6 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -195,6 +195,14 @@ static int exclude_super_stripes(struct btrfs_root *root, | |||
195 | int stripe_len; | 195 | int stripe_len; |
196 | int i, nr, ret; | 196 | int i, nr, ret; |
197 | 197 | ||
198 | if (cache->key.objectid < BTRFS_SUPER_INFO_OFFSET) { | ||
199 | stripe_len = BTRFS_SUPER_INFO_OFFSET - cache->key.objectid; | ||
200 | cache->bytes_super += stripe_len; | ||
201 | ret = add_excluded_extent(root, cache->key.objectid, | ||
202 | stripe_len); | ||
203 | BUG_ON(ret); | ||
204 | } | ||
205 | |||
198 | for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { | 206 | for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { |
199 | bytenr = btrfs_sb_offset(i); | 207 | bytenr = btrfs_sb_offset(i); |
200 | ret = btrfs_rmap_block(&root->fs_info->mapping_tree, | 208 | ret = btrfs_rmap_block(&root->fs_info->mapping_tree, |
@@ -255,7 +263,7 @@ static u64 add_new_free_space(struct btrfs_block_group_cache *block_group, | |||
255 | if (ret) | 263 | if (ret) |
256 | break; | 264 | break; |
257 | 265 | ||
258 | if (extent_start == start) { | 266 | if (extent_start <= start) { |
259 | start = extent_end + 1; | 267 | start = extent_end + 1; |
260 | } else if (extent_start > start && extent_start < end) { | 268 | } else if (extent_start > start && extent_start < end) { |
261 | size = extent_start - start; | 269 | size = extent_start - start; |
@@ -2880,9 +2888,9 @@ static noinline void flush_delalloc_async(struct btrfs_work *work) | |||
2880 | root = async->root; | 2888 | root = async->root; |
2881 | info = async->info; | 2889 | info = async->info; |
2882 | 2890 | ||
2883 | btrfs_start_delalloc_inodes(root); | 2891 | btrfs_start_delalloc_inodes(root, 0); |
2884 | wake_up(&info->flush_wait); | 2892 | wake_up(&info->flush_wait); |
2885 | btrfs_wait_ordered_extents(root, 0); | 2893 | btrfs_wait_ordered_extents(root, 0, 0); |
2886 | 2894 | ||
2887 | spin_lock(&info->lock); | 2895 | spin_lock(&info->lock); |
2888 | info->flushing = 0; | 2896 | info->flushing = 0; |
@@ -2956,8 +2964,8 @@ static void flush_delalloc(struct btrfs_root *root, | |||
2956 | return; | 2964 | return; |
2957 | 2965 | ||
2958 | flush: | 2966 | flush: |
2959 | btrfs_start_delalloc_inodes(root); | 2967 | btrfs_start_delalloc_inodes(root, 0); |
2960 | btrfs_wait_ordered_extents(root, 0); | 2968 | btrfs_wait_ordered_extents(root, 0, 0); |
2961 | 2969 | ||
2962 | spin_lock(&info->lock); | 2970 | spin_lock(&info->lock); |
2963 | info->flushing = 0; | 2971 | info->flushing = 0; |
@@ -3454,14 +3462,6 @@ static int update_block_group(struct btrfs_trans_handle *trans, | |||
3454 | else | 3462 | else |
3455 | old_val -= num_bytes; | 3463 | old_val -= num_bytes; |
3456 | btrfs_set_super_bytes_used(&info->super_copy, old_val); | 3464 | btrfs_set_super_bytes_used(&info->super_copy, old_val); |
3457 | |||
3458 | /* block accounting for root item */ | ||
3459 | old_val = btrfs_root_used(&root->root_item); | ||
3460 | if (alloc) | ||
3461 | old_val += num_bytes; | ||
3462 | else | ||
3463 | old_val -= num_bytes; | ||
3464 | btrfs_set_root_used(&root->root_item, old_val); | ||
3465 | spin_unlock(&info->delalloc_lock); | 3465 | spin_unlock(&info->delalloc_lock); |
3466 | 3466 | ||
3467 | while (total) { | 3467 | while (total) { |
@@ -4049,6 +4049,21 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, | |||
4049 | return ret; | 4049 | return ret; |
4050 | } | 4050 | } |
4051 | 4051 | ||
4052 | int btrfs_free_tree_block(struct btrfs_trans_handle *trans, | ||
4053 | struct btrfs_root *root, | ||
4054 | u64 bytenr, u32 blocksize, | ||
4055 | u64 parent, u64 root_objectid, int level) | ||
4056 | { | ||
4057 | u64 used; | ||
4058 | spin_lock(&root->node_lock); | ||
4059 | used = btrfs_root_used(&root->root_item) - blocksize; | ||
4060 | btrfs_set_root_used(&root->root_item, used); | ||
4061 | spin_unlock(&root->node_lock); | ||
4062 | |||
4063 | return btrfs_free_extent(trans, root, bytenr, blocksize, | ||
4064 | parent, root_objectid, level, 0); | ||
4065 | } | ||
4066 | |||
4052 | static u64 stripe_align(struct btrfs_root *root, u64 val) | 4067 | static u64 stripe_align(struct btrfs_root *root, u64 val) |
4053 | { | 4068 | { |
4054 | u64 mask = ((u64)root->stripesize - 1); | 4069 | u64 mask = ((u64)root->stripesize - 1); |
@@ -4578,7 +4593,6 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, | |||
4578 | { | 4593 | { |
4579 | int ret; | 4594 | int ret; |
4580 | u64 search_start = 0; | 4595 | u64 search_start = 0; |
4581 | struct btrfs_fs_info *info = root->fs_info; | ||
4582 | 4596 | ||
4583 | data = btrfs_get_alloc_profile(root, data); | 4597 | data = btrfs_get_alloc_profile(root, data); |
4584 | again: | 4598 | again: |
@@ -4586,17 +4600,9 @@ again: | |||
4586 | * the only place that sets empty_size is btrfs_realloc_node, which | 4600 | * the only place that sets empty_size is btrfs_realloc_node, which |
4587 | * is not called recursively on allocations | 4601 | * is not called recursively on allocations |
4588 | */ | 4602 | */ |
4589 | if (empty_size || root->ref_cows) { | 4603 | if (empty_size || root->ref_cows) |
4590 | if (!(data & BTRFS_BLOCK_GROUP_METADATA)) { | ||
4591 | ret = do_chunk_alloc(trans, root->fs_info->extent_root, | ||
4592 | 2 * 1024 * 1024, | ||
4593 | BTRFS_BLOCK_GROUP_METADATA | | ||
4594 | (info->metadata_alloc_profile & | ||
4595 | info->avail_metadata_alloc_bits), 0); | ||
4596 | } | ||
4597 | ret = do_chunk_alloc(trans, root->fs_info->extent_root, | 4604 | ret = do_chunk_alloc(trans, root->fs_info->extent_root, |
4598 | num_bytes + 2 * 1024 * 1024, data, 0); | 4605 | num_bytes + 2 * 1024 * 1024, data, 0); |
4599 | } | ||
4600 | 4606 | ||
4601 | WARN_ON(num_bytes < root->sectorsize); | 4607 | WARN_ON(num_bytes < root->sectorsize); |
4602 | ret = find_free_extent(trans, root, num_bytes, empty_size, | 4608 | ret = find_free_extent(trans, root, num_bytes, empty_size, |
@@ -4897,6 +4903,14 @@ static int alloc_tree_block(struct btrfs_trans_handle *trans, | |||
4897 | extent_op); | 4903 | extent_op); |
4898 | BUG_ON(ret); | 4904 | BUG_ON(ret); |
4899 | } | 4905 | } |
4906 | |||
4907 | if (root_objectid == root->root_key.objectid) { | ||
4908 | u64 used; | ||
4909 | spin_lock(&root->node_lock); | ||
4910 | used = btrfs_root_used(&root->root_item) + num_bytes; | ||
4911 | btrfs_set_root_used(&root->root_item, used); | ||
4912 | spin_unlock(&root->node_lock); | ||
4913 | } | ||
4900 | return ret; | 4914 | return ret; |
4901 | } | 4915 | } |
4902 | 4916 | ||
@@ -4919,8 +4933,16 @@ struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans, | |||
4919 | btrfs_set_buffer_uptodate(buf); | 4933 | btrfs_set_buffer_uptodate(buf); |
4920 | 4934 | ||
4921 | if (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID) { | 4935 | if (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID) { |
4922 | set_extent_dirty(&root->dirty_log_pages, buf->start, | 4936 | /* |
4923 | buf->start + buf->len - 1, GFP_NOFS); | 4937 | * we allow two log transactions at a time, use different |
4938 | * EXENT bit to differentiate dirty pages. | ||
4939 | */ | ||
4940 | if (root->log_transid % 2 == 0) | ||
4941 | set_extent_dirty(&root->dirty_log_pages, buf->start, | ||
4942 | buf->start + buf->len - 1, GFP_NOFS); | ||
4943 | else | ||
4944 | set_extent_new(&root->dirty_log_pages, buf->start, | ||
4945 | buf->start + buf->len - 1, GFP_NOFS); | ||
4924 | } else { | 4946 | } else { |
4925 | set_extent_dirty(&trans->transaction->dirty_pages, buf->start, | 4947 | set_extent_dirty(&trans->transaction->dirty_pages, buf->start, |
4926 | buf->start + buf->len - 1, GFP_NOFS); | 4948 | buf->start + buf->len - 1, GFP_NOFS); |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 77f759302e12..feaa13b105d9 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -179,18 +179,14 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, | |||
179 | } | 179 | } |
180 | flags = em->flags; | 180 | flags = em->flags; |
181 | if (skip_pinned && test_bit(EXTENT_FLAG_PINNED, &em->flags)) { | 181 | if (skip_pinned && test_bit(EXTENT_FLAG_PINNED, &em->flags)) { |
182 | if (em->start <= start && | 182 | if (testend && em->start + em->len >= start + len) { |
183 | (!testend || em->start + em->len >= start + len)) { | ||
184 | free_extent_map(em); | 183 | free_extent_map(em); |
185 | write_unlock(&em_tree->lock); | 184 | write_unlock(&em_tree->lock); |
186 | break; | 185 | break; |
187 | } | 186 | } |
188 | if (start < em->start) { | 187 | start = em->start + em->len; |
189 | len = em->start - start; | 188 | if (testend) |
190 | } else { | ||
191 | len = start + len - (em->start + em->len); | 189 | len = start + len - (em->start + em->len); |
192 | start = em->start + em->len; | ||
193 | } | ||
194 | free_extent_map(em); | 190 | free_extent_map(em); |
195 | write_unlock(&em_tree->lock); | 191 | write_unlock(&em_tree->lock); |
196 | continue; | 192 | continue; |
@@ -265,319 +261,247 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, | |||
265 | * If an extent intersects the range but is not entirely inside the range | 261 | * If an extent intersects the range but is not entirely inside the range |
266 | * it is either truncated or split. Anything entirely inside the range | 262 | * it is either truncated or split. Anything entirely inside the range |
267 | * is deleted from the tree. | 263 | * is deleted from the tree. |
268 | * | ||
269 | * inline_limit is used to tell this code which offsets in the file to keep | ||
270 | * if they contain inline extents. | ||
271 | */ | 264 | */ |
272 | noinline int btrfs_drop_extents(struct btrfs_trans_handle *trans, | 265 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, |
273 | struct btrfs_root *root, struct inode *inode, | 266 | u64 start, u64 end, u64 *hint_byte, int drop_cache) |
274 | u64 start, u64 end, u64 locked_end, | ||
275 | u64 inline_limit, u64 *hint_byte, int drop_cache) | ||
276 | { | 267 | { |
277 | u64 extent_end = 0; | 268 | struct btrfs_root *root = BTRFS_I(inode)->root; |
278 | u64 search_start = start; | ||
279 | u64 ram_bytes = 0; | ||
280 | u64 disk_bytenr = 0; | ||
281 | u64 orig_locked_end = locked_end; | ||
282 | u8 compression; | ||
283 | u8 encryption; | ||
284 | u16 other_encoding = 0; | ||
285 | struct extent_buffer *leaf; | 269 | struct extent_buffer *leaf; |
286 | struct btrfs_file_extent_item *extent; | 270 | struct btrfs_file_extent_item *fi; |
287 | struct btrfs_path *path; | 271 | struct btrfs_path *path; |
288 | struct btrfs_key key; | 272 | struct btrfs_key key; |
289 | struct btrfs_file_extent_item old; | 273 | struct btrfs_key new_key; |
290 | int keep; | 274 | u64 search_start = start; |
291 | int slot; | 275 | u64 disk_bytenr = 0; |
292 | int bookend; | 276 | u64 num_bytes = 0; |
293 | int found_type = 0; | 277 | u64 extent_offset = 0; |
294 | int found_extent; | 278 | u64 extent_end = 0; |
295 | int found_inline; | 279 | int del_nr = 0; |
280 | int del_slot = 0; | ||
281 | int extent_type; | ||
296 | int recow; | 282 | int recow; |
297 | int ret; | 283 | int ret; |
298 | 284 | ||
299 | inline_limit = 0; | ||
300 | if (drop_cache) | 285 | if (drop_cache) |
301 | btrfs_drop_extent_cache(inode, start, end - 1, 0); | 286 | btrfs_drop_extent_cache(inode, start, end - 1, 0); |
302 | 287 | ||
303 | path = btrfs_alloc_path(); | 288 | path = btrfs_alloc_path(); |
304 | if (!path) | 289 | if (!path) |
305 | return -ENOMEM; | 290 | return -ENOMEM; |
291 | |||
306 | while (1) { | 292 | while (1) { |
307 | recow = 0; | 293 | recow = 0; |
308 | btrfs_release_path(root, path); | ||
309 | ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino, | 294 | ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino, |
310 | search_start, -1); | 295 | search_start, -1); |
311 | if (ret < 0) | 296 | if (ret < 0) |
312 | goto out; | 297 | break; |
313 | if (ret > 0) { | 298 | if (ret > 0 && path->slots[0] > 0 && search_start == start) { |
314 | if (path->slots[0] == 0) { | 299 | leaf = path->nodes[0]; |
315 | ret = 0; | 300 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0] - 1); |
316 | goto out; | 301 | if (key.objectid == inode->i_ino && |
317 | } | 302 | key.type == BTRFS_EXTENT_DATA_KEY) |
318 | path->slots[0]--; | 303 | path->slots[0]--; |
319 | } | 304 | } |
305 | ret = 0; | ||
320 | next_slot: | 306 | next_slot: |
321 | keep = 0; | ||
322 | bookend = 0; | ||
323 | found_extent = 0; | ||
324 | found_inline = 0; | ||
325 | compression = 0; | ||
326 | encryption = 0; | ||
327 | extent = NULL; | ||
328 | leaf = path->nodes[0]; | 307 | leaf = path->nodes[0]; |
329 | slot = path->slots[0]; | 308 | if (path->slots[0] >= btrfs_header_nritems(leaf)) { |
330 | ret = 0; | 309 | BUG_ON(del_nr > 0); |
331 | btrfs_item_key_to_cpu(leaf, &key, slot); | 310 | ret = btrfs_next_leaf(root, path); |
332 | if (btrfs_key_type(&key) == BTRFS_EXTENT_DATA_KEY && | 311 | if (ret < 0) |
333 | key.offset >= end) { | 312 | break; |
334 | goto out; | 313 | if (ret > 0) { |
335 | } | 314 | ret = 0; |
336 | if (btrfs_key_type(&key) > BTRFS_EXTENT_DATA_KEY || | 315 | break; |
337 | key.objectid != inode->i_ino) { | ||
338 | goto out; | ||
339 | } | ||
340 | if (recow) { | ||
341 | search_start = max(key.offset, start); | ||
342 | continue; | ||
343 | } | ||
344 | if (btrfs_key_type(&key) == BTRFS_EXTENT_DATA_KEY) { | ||
345 | extent = btrfs_item_ptr(leaf, slot, | ||
346 | struct btrfs_file_extent_item); | ||
347 | found_type = btrfs_file_extent_type(leaf, extent); | ||
348 | compression = btrfs_file_extent_compression(leaf, | ||
349 | extent); | ||
350 | encryption = btrfs_file_extent_encryption(leaf, | ||
351 | extent); | ||
352 | other_encoding = btrfs_file_extent_other_encoding(leaf, | ||
353 | extent); | ||
354 | if (found_type == BTRFS_FILE_EXTENT_REG || | ||
355 | found_type == BTRFS_FILE_EXTENT_PREALLOC) { | ||
356 | extent_end = | ||
357 | btrfs_file_extent_disk_bytenr(leaf, | ||
358 | extent); | ||
359 | if (extent_end) | ||
360 | *hint_byte = extent_end; | ||
361 | |||
362 | extent_end = key.offset + | ||
363 | btrfs_file_extent_num_bytes(leaf, extent); | ||
364 | ram_bytes = btrfs_file_extent_ram_bytes(leaf, | ||
365 | extent); | ||
366 | found_extent = 1; | ||
367 | } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { | ||
368 | found_inline = 1; | ||
369 | extent_end = key.offset + | ||
370 | btrfs_file_extent_inline_len(leaf, extent); | ||
371 | } | 316 | } |
317 | leaf = path->nodes[0]; | ||
318 | recow = 1; | ||
319 | } | ||
320 | |||
321 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); | ||
322 | if (key.objectid > inode->i_ino || | ||
323 | key.type > BTRFS_EXTENT_DATA_KEY || key.offset >= end) | ||
324 | break; | ||
325 | |||
326 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
327 | struct btrfs_file_extent_item); | ||
328 | extent_type = btrfs_file_extent_type(leaf, fi); | ||
329 | |||
330 | if (extent_type == BTRFS_FILE_EXTENT_REG || | ||
331 | extent_type == BTRFS_FILE_EXTENT_PREALLOC) { | ||
332 | disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi); | ||
333 | num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi); | ||
334 | extent_offset = btrfs_file_extent_offset(leaf, fi); | ||
335 | extent_end = key.offset + | ||
336 | btrfs_file_extent_num_bytes(leaf, fi); | ||
337 | } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) { | ||
338 | extent_end = key.offset + | ||
339 | btrfs_file_extent_inline_len(leaf, fi); | ||
372 | } else { | 340 | } else { |
341 | WARN_ON(1); | ||
373 | extent_end = search_start; | 342 | extent_end = search_start; |
374 | } | 343 | } |
375 | 344 | ||
376 | /* we found nothing we can drop */ | 345 | if (extent_end <= search_start) { |
377 | if ((!found_extent && !found_inline) || | 346 | path->slots[0]++; |
378 | search_start >= extent_end) { | ||
379 | int nextret; | ||
380 | u32 nritems; | ||
381 | nritems = btrfs_header_nritems(leaf); | ||
382 | if (slot >= nritems - 1) { | ||
383 | nextret = btrfs_next_leaf(root, path); | ||
384 | if (nextret) | ||
385 | goto out; | ||
386 | recow = 1; | ||
387 | } else { | ||
388 | path->slots[0]++; | ||
389 | } | ||
390 | goto next_slot; | 347 | goto next_slot; |
391 | } | 348 | } |
392 | 349 | ||
393 | if (end <= extent_end && start >= key.offset && found_inline) | 350 | search_start = max(key.offset, start); |
394 | *hint_byte = EXTENT_MAP_INLINE; | 351 | if (recow) { |
395 | 352 | btrfs_release_path(root, path); | |
396 | if (found_extent) { | 353 | continue; |
397 | read_extent_buffer(leaf, &old, (unsigned long)extent, | ||
398 | sizeof(old)); | ||
399 | } | ||
400 | |||
401 | if (end < extent_end && end >= key.offset) { | ||
402 | bookend = 1; | ||
403 | if (found_inline && start <= key.offset) | ||
404 | keep = 1; | ||
405 | } | 354 | } |
406 | 355 | ||
407 | if (bookend && found_extent) { | 356 | /* |
408 | if (locked_end < extent_end) { | 357 | * | - range to drop - | |
409 | ret = try_lock_extent(&BTRFS_I(inode)->io_tree, | 358 | * | -------- extent -------- | |
410 | locked_end, extent_end - 1, | 359 | */ |
411 | GFP_NOFS); | 360 | if (start > key.offset && end < extent_end) { |
412 | if (!ret) { | 361 | BUG_ON(del_nr > 0); |
413 | btrfs_release_path(root, path); | 362 | BUG_ON(extent_type == BTRFS_FILE_EXTENT_INLINE); |
414 | lock_extent(&BTRFS_I(inode)->io_tree, | 363 | |
415 | locked_end, extent_end - 1, | 364 | memcpy(&new_key, &key, sizeof(new_key)); |
416 | GFP_NOFS); | 365 | new_key.offset = start; |
417 | locked_end = extent_end; | 366 | ret = btrfs_duplicate_item(trans, root, path, |
418 | continue; | 367 | &new_key); |
419 | } | 368 | if (ret == -EAGAIN) { |
420 | locked_end = extent_end; | 369 | btrfs_release_path(root, path); |
370 | continue; | ||
421 | } | 371 | } |
422 | disk_bytenr = le64_to_cpu(old.disk_bytenr); | 372 | if (ret < 0) |
423 | if (disk_bytenr != 0) { | 373 | break; |
374 | |||
375 | leaf = path->nodes[0]; | ||
376 | fi = btrfs_item_ptr(leaf, path->slots[0] - 1, | ||
377 | struct btrfs_file_extent_item); | ||
378 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
379 | start - key.offset); | ||
380 | |||
381 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
382 | struct btrfs_file_extent_item); | ||
383 | |||
384 | extent_offset += start - key.offset; | ||
385 | btrfs_set_file_extent_offset(leaf, fi, extent_offset); | ||
386 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
387 | extent_end - start); | ||
388 | btrfs_mark_buffer_dirty(leaf); | ||
389 | |||
390 | if (disk_bytenr > 0) { | ||
424 | ret = btrfs_inc_extent_ref(trans, root, | 391 | ret = btrfs_inc_extent_ref(trans, root, |
425 | disk_bytenr, | 392 | disk_bytenr, num_bytes, 0, |
426 | le64_to_cpu(old.disk_num_bytes), 0, | 393 | root->root_key.objectid, |
427 | root->root_key.objectid, | 394 | new_key.objectid, |
428 | key.objectid, key.offset - | 395 | start - extent_offset); |
429 | le64_to_cpu(old.offset)); | ||
430 | BUG_ON(ret); | 396 | BUG_ON(ret); |
397 | *hint_byte = disk_bytenr; | ||
431 | } | 398 | } |
399 | key.offset = start; | ||
432 | } | 400 | } |
401 | /* | ||
402 | * | ---- range to drop ----- | | ||
403 | * | -------- extent -------- | | ||
404 | */ | ||
405 | if (start <= key.offset && end < extent_end) { | ||
406 | BUG_ON(extent_type == BTRFS_FILE_EXTENT_INLINE); | ||
433 | 407 | ||
434 | if (found_inline) { | 408 | memcpy(&new_key, &key, sizeof(new_key)); |
435 | u64 mask = root->sectorsize - 1; | 409 | new_key.offset = end; |
436 | search_start = (extent_end + mask) & ~mask; | 410 | btrfs_set_item_key_safe(trans, root, path, &new_key); |
437 | } else | 411 | |
438 | search_start = extent_end; | 412 | extent_offset += end - key.offset; |
439 | 413 | btrfs_set_file_extent_offset(leaf, fi, extent_offset); | |
440 | /* truncate existing extent */ | 414 | btrfs_set_file_extent_num_bytes(leaf, fi, |
441 | if (start > key.offset) { | 415 | extent_end - end); |
442 | u64 new_num; | 416 | btrfs_mark_buffer_dirty(leaf); |
443 | u64 old_num; | 417 | if (disk_bytenr > 0) { |
444 | keep = 1; | 418 | inode_sub_bytes(inode, end - key.offset); |
445 | WARN_ON(start & (root->sectorsize - 1)); | 419 | *hint_byte = disk_bytenr; |
446 | if (found_extent) { | ||
447 | new_num = start - key.offset; | ||
448 | old_num = btrfs_file_extent_num_bytes(leaf, | ||
449 | extent); | ||
450 | *hint_byte = | ||
451 | btrfs_file_extent_disk_bytenr(leaf, | ||
452 | extent); | ||
453 | if (btrfs_file_extent_disk_bytenr(leaf, | ||
454 | extent)) { | ||
455 | inode_sub_bytes(inode, old_num - | ||
456 | new_num); | ||
457 | } | ||
458 | btrfs_set_file_extent_num_bytes(leaf, | ||
459 | extent, new_num); | ||
460 | btrfs_mark_buffer_dirty(leaf); | ||
461 | } else if (key.offset < inline_limit && | ||
462 | (end > extent_end) && | ||
463 | (inline_limit < extent_end)) { | ||
464 | u32 new_size; | ||
465 | new_size = btrfs_file_extent_calc_inline_size( | ||
466 | inline_limit - key.offset); | ||
467 | inode_sub_bytes(inode, extent_end - | ||
468 | inline_limit); | ||
469 | btrfs_set_file_extent_ram_bytes(leaf, extent, | ||
470 | new_size); | ||
471 | if (!compression && !encryption) { | ||
472 | btrfs_truncate_item(trans, root, path, | ||
473 | new_size, 1); | ||
474 | } | ||
475 | } | 420 | } |
421 | break; | ||
476 | } | 422 | } |
477 | /* delete the entire extent */ | ||
478 | if (!keep) { | ||
479 | if (found_inline) | ||
480 | inode_sub_bytes(inode, extent_end - | ||
481 | key.offset); | ||
482 | ret = btrfs_del_item(trans, root, path); | ||
483 | /* TODO update progress marker and return */ | ||
484 | BUG_ON(ret); | ||
485 | extent = NULL; | ||
486 | btrfs_release_path(root, path); | ||
487 | /* the extent will be freed later */ | ||
488 | } | ||
489 | if (bookend && found_inline && start <= key.offset) { | ||
490 | u32 new_size; | ||
491 | new_size = btrfs_file_extent_calc_inline_size( | ||
492 | extent_end - end); | ||
493 | inode_sub_bytes(inode, end - key.offset); | ||
494 | btrfs_set_file_extent_ram_bytes(leaf, extent, | ||
495 | new_size); | ||
496 | if (!compression && !encryption) | ||
497 | ret = btrfs_truncate_item(trans, root, path, | ||
498 | new_size, 0); | ||
499 | BUG_ON(ret); | ||
500 | } | ||
501 | /* create bookend, splitting the extent in two */ | ||
502 | if (bookend && found_extent) { | ||
503 | struct btrfs_key ins; | ||
504 | ins.objectid = inode->i_ino; | ||
505 | ins.offset = end; | ||
506 | btrfs_set_key_type(&ins, BTRFS_EXTENT_DATA_KEY); | ||
507 | 423 | ||
508 | btrfs_release_path(root, path); | 424 | search_start = extent_end; |
509 | path->leave_spinning = 1; | 425 | /* |
510 | ret = btrfs_insert_empty_item(trans, root, path, &ins, | 426 | * | ---- range to drop ----- | |
511 | sizeof(*extent)); | 427 | * | -------- extent -------- | |
512 | BUG_ON(ret); | 428 | */ |
429 | if (start > key.offset && end >= extent_end) { | ||
430 | BUG_ON(del_nr > 0); | ||
431 | BUG_ON(extent_type == BTRFS_FILE_EXTENT_INLINE); | ||
513 | 432 | ||
514 | leaf = path->nodes[0]; | 433 | btrfs_set_file_extent_num_bytes(leaf, fi, |
515 | extent = btrfs_item_ptr(leaf, path->slots[0], | 434 | start - key.offset); |
516 | struct btrfs_file_extent_item); | 435 | btrfs_mark_buffer_dirty(leaf); |
517 | write_extent_buffer(leaf, &old, | 436 | if (disk_bytenr > 0) { |
518 | (unsigned long)extent, sizeof(old)); | 437 | inode_sub_bytes(inode, extent_end - start); |
519 | 438 | *hint_byte = disk_bytenr; | |
520 | btrfs_set_file_extent_compression(leaf, extent, | 439 | } |
521 | compression); | 440 | if (end == extent_end) |
522 | btrfs_set_file_extent_encryption(leaf, extent, | 441 | break; |
523 | encryption); | ||
524 | btrfs_set_file_extent_other_encoding(leaf, extent, | ||
525 | other_encoding); | ||
526 | btrfs_set_file_extent_offset(leaf, extent, | ||
527 | le64_to_cpu(old.offset) + end - key.offset); | ||
528 | WARN_ON(le64_to_cpu(old.num_bytes) < | ||
529 | (extent_end - end)); | ||
530 | btrfs_set_file_extent_num_bytes(leaf, extent, | ||
531 | extent_end - end); | ||
532 | 442 | ||
533 | /* | 443 | path->slots[0]++; |
534 | * set the ram bytes to the size of the full extent | 444 | goto next_slot; |
535 | * before splitting. This is a worst case flag, | ||
536 | * but its the best we can do because we don't know | ||
537 | * how splitting affects compression | ||
538 | */ | ||
539 | btrfs_set_file_extent_ram_bytes(leaf, extent, | ||
540 | ram_bytes); | ||
541 | btrfs_set_file_extent_type(leaf, extent, found_type); | ||
542 | |||
543 | btrfs_unlock_up_safe(path, 1); | ||
544 | btrfs_mark_buffer_dirty(path->nodes[0]); | ||
545 | btrfs_set_lock_blocking(path->nodes[0]); | ||
546 | |||
547 | path->leave_spinning = 0; | ||
548 | btrfs_release_path(root, path); | ||
549 | if (disk_bytenr != 0) | ||
550 | inode_add_bytes(inode, extent_end - end); | ||
551 | } | 445 | } |
552 | 446 | ||
553 | if (found_extent && !keep) { | 447 | /* |
554 | u64 old_disk_bytenr = le64_to_cpu(old.disk_bytenr); | 448 | * | ---- range to drop ----- | |
449 | * | ------ extent ------ | | ||
450 | */ | ||
451 | if (start <= key.offset && end >= extent_end) { | ||
452 | if (del_nr == 0) { | ||
453 | del_slot = path->slots[0]; | ||
454 | del_nr = 1; | ||
455 | } else { | ||
456 | BUG_ON(del_slot + del_nr != path->slots[0]); | ||
457 | del_nr++; | ||
458 | } | ||
555 | 459 | ||
556 | if (old_disk_bytenr != 0) { | 460 | if (extent_type == BTRFS_FILE_EXTENT_INLINE) { |
557 | inode_sub_bytes(inode, | 461 | inode_sub_bytes(inode, |
558 | le64_to_cpu(old.num_bytes)); | 462 | extent_end - key.offset); |
463 | extent_end = ALIGN(extent_end, | ||
464 | root->sectorsize); | ||
465 | } else if (disk_bytenr > 0) { | ||
559 | ret = btrfs_free_extent(trans, root, | 466 | ret = btrfs_free_extent(trans, root, |
560 | old_disk_bytenr, | 467 | disk_bytenr, num_bytes, 0, |
561 | le64_to_cpu(old.disk_num_bytes), | 468 | root->root_key.objectid, |
562 | 0, root->root_key.objectid, | ||
563 | key.objectid, key.offset - | 469 | key.objectid, key.offset - |
564 | le64_to_cpu(old.offset)); | 470 | extent_offset); |
565 | BUG_ON(ret); | 471 | BUG_ON(ret); |
566 | *hint_byte = old_disk_bytenr; | 472 | inode_sub_bytes(inode, |
473 | extent_end - key.offset); | ||
474 | *hint_byte = disk_bytenr; | ||
567 | } | 475 | } |
568 | } | ||
569 | 476 | ||
570 | if (search_start >= end) { | 477 | if (end == extent_end) |
571 | ret = 0; | 478 | break; |
572 | goto out; | 479 | |
480 | if (path->slots[0] + 1 < btrfs_header_nritems(leaf)) { | ||
481 | path->slots[0]++; | ||
482 | goto next_slot; | ||
483 | } | ||
484 | |||
485 | ret = btrfs_del_items(trans, root, path, del_slot, | ||
486 | del_nr); | ||
487 | BUG_ON(ret); | ||
488 | |||
489 | del_nr = 0; | ||
490 | del_slot = 0; | ||
491 | |||
492 | btrfs_release_path(root, path); | ||
493 | continue; | ||
573 | } | 494 | } |
495 | |||
496 | BUG_ON(1); | ||
574 | } | 497 | } |
575 | out: | 498 | |
576 | btrfs_free_path(path); | 499 | if (del_nr > 0) { |
577 | if (locked_end > orig_locked_end) { | 500 | ret = btrfs_del_items(trans, root, path, del_slot, del_nr); |
578 | unlock_extent(&BTRFS_I(inode)->io_tree, orig_locked_end, | 501 | BUG_ON(ret); |
579 | locked_end - 1, GFP_NOFS); | ||
580 | } | 502 | } |
503 | |||
504 | btrfs_free_path(path); | ||
581 | return ret; | 505 | return ret; |
582 | } | 506 | } |
583 | 507 | ||
@@ -620,23 +544,23 @@ static int extent_mergeable(struct extent_buffer *leaf, int slot, | |||
620 | * two or three. | 544 | * two or three. |
621 | */ | 545 | */ |
622 | int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, | 546 | int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, |
623 | struct btrfs_root *root, | ||
624 | struct inode *inode, u64 start, u64 end) | 547 | struct inode *inode, u64 start, u64 end) |
625 | { | 548 | { |
549 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
626 | struct extent_buffer *leaf; | 550 | struct extent_buffer *leaf; |
627 | struct btrfs_path *path; | 551 | struct btrfs_path *path; |
628 | struct btrfs_file_extent_item *fi; | 552 | struct btrfs_file_extent_item *fi; |
629 | struct btrfs_key key; | 553 | struct btrfs_key key; |
554 | struct btrfs_key new_key; | ||
630 | u64 bytenr; | 555 | u64 bytenr; |
631 | u64 num_bytes; | 556 | u64 num_bytes; |
632 | u64 extent_end; | 557 | u64 extent_end; |
633 | u64 orig_offset; | 558 | u64 orig_offset; |
634 | u64 other_start; | 559 | u64 other_start; |
635 | u64 other_end; | 560 | u64 other_end; |
636 | u64 split = start; | 561 | u64 split; |
637 | u64 locked_end = end; | 562 | int del_nr = 0; |
638 | int extent_type; | 563 | int del_slot = 0; |
639 | int split_end = 1; | ||
640 | int ret; | 564 | int ret; |
641 | 565 | ||
642 | btrfs_drop_extent_cache(inode, start, end - 1, 0); | 566 | btrfs_drop_extent_cache(inode, start, end - 1, 0); |
@@ -644,12 +568,10 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, | |||
644 | path = btrfs_alloc_path(); | 568 | path = btrfs_alloc_path(); |
645 | BUG_ON(!path); | 569 | BUG_ON(!path); |
646 | again: | 570 | again: |
571 | split = start; | ||
647 | key.objectid = inode->i_ino; | 572 | key.objectid = inode->i_ino; |
648 | key.type = BTRFS_EXTENT_DATA_KEY; | 573 | key.type = BTRFS_EXTENT_DATA_KEY; |
649 | if (split == start) | 574 | key.offset = split; |
650 | key.offset = split; | ||
651 | else | ||
652 | key.offset = split - 1; | ||
653 | 575 | ||
654 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); | 576 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); |
655 | if (ret > 0 && path->slots[0] > 0) | 577 | if (ret > 0 && path->slots[0] > 0) |
@@ -661,8 +583,8 @@ again: | |||
661 | key.type != BTRFS_EXTENT_DATA_KEY); | 583 | key.type != BTRFS_EXTENT_DATA_KEY); |
662 | fi = btrfs_item_ptr(leaf, path->slots[0], | 584 | fi = btrfs_item_ptr(leaf, path->slots[0], |
663 | struct btrfs_file_extent_item); | 585 | struct btrfs_file_extent_item); |
664 | extent_type = btrfs_file_extent_type(leaf, fi); | 586 | BUG_ON(btrfs_file_extent_type(leaf, fi) != |
665 | BUG_ON(extent_type != BTRFS_FILE_EXTENT_PREALLOC); | 587 | BTRFS_FILE_EXTENT_PREALLOC); |
666 | extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi); | 588 | extent_end = key.offset + btrfs_file_extent_num_bytes(leaf, fi); |
667 | BUG_ON(key.offset > start || extent_end < end); | 589 | BUG_ON(key.offset > start || extent_end < end); |
668 | 590 | ||
@@ -670,150 +592,91 @@ again: | |||
670 | num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi); | 592 | num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi); |
671 | orig_offset = key.offset - btrfs_file_extent_offset(leaf, fi); | 593 | orig_offset = key.offset - btrfs_file_extent_offset(leaf, fi); |
672 | 594 | ||
673 | if (key.offset == start) | 595 | while (start > key.offset || end < extent_end) { |
674 | split = end; | 596 | if (key.offset == start) |
675 | 597 | split = end; | |
676 | if (key.offset == start && extent_end == end) { | 598 | |
677 | int del_nr = 0; | 599 | memcpy(&new_key, &key, sizeof(new_key)); |
678 | int del_slot = 0; | 600 | new_key.offset = split; |
679 | other_start = end; | 601 | ret = btrfs_duplicate_item(trans, root, path, &new_key); |
680 | other_end = 0; | 602 | if (ret == -EAGAIN) { |
681 | if (extent_mergeable(leaf, path->slots[0] + 1, inode->i_ino, | 603 | btrfs_release_path(root, path); |
682 | bytenr, &other_start, &other_end)) { | 604 | goto again; |
683 | extent_end = other_end; | ||
684 | del_slot = path->slots[0] + 1; | ||
685 | del_nr++; | ||
686 | ret = btrfs_free_extent(trans, root, bytenr, num_bytes, | ||
687 | 0, root->root_key.objectid, | ||
688 | inode->i_ino, orig_offset); | ||
689 | BUG_ON(ret); | ||
690 | } | ||
691 | other_start = 0; | ||
692 | other_end = start; | ||
693 | if (extent_mergeable(leaf, path->slots[0] - 1, inode->i_ino, | ||
694 | bytenr, &other_start, &other_end)) { | ||
695 | key.offset = other_start; | ||
696 | del_slot = path->slots[0]; | ||
697 | del_nr++; | ||
698 | ret = btrfs_free_extent(trans, root, bytenr, num_bytes, | ||
699 | 0, root->root_key.objectid, | ||
700 | inode->i_ino, orig_offset); | ||
701 | BUG_ON(ret); | ||
702 | } | ||
703 | split_end = 0; | ||
704 | if (del_nr == 0) { | ||
705 | btrfs_set_file_extent_type(leaf, fi, | ||
706 | BTRFS_FILE_EXTENT_REG); | ||
707 | goto done; | ||
708 | } | 605 | } |
606 | BUG_ON(ret < 0); | ||
709 | 607 | ||
710 | fi = btrfs_item_ptr(leaf, del_slot - 1, | 608 | leaf = path->nodes[0]; |
609 | fi = btrfs_item_ptr(leaf, path->slots[0] - 1, | ||
711 | struct btrfs_file_extent_item); | 610 | struct btrfs_file_extent_item); |
712 | btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_REG); | ||
713 | btrfs_set_file_extent_num_bytes(leaf, fi, | 611 | btrfs_set_file_extent_num_bytes(leaf, fi, |
714 | extent_end - key.offset); | 612 | split - key.offset); |
613 | |||
614 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
615 | struct btrfs_file_extent_item); | ||
616 | |||
617 | btrfs_set_file_extent_offset(leaf, fi, split - orig_offset); | ||
618 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
619 | extent_end - split); | ||
715 | btrfs_mark_buffer_dirty(leaf); | 620 | btrfs_mark_buffer_dirty(leaf); |
716 | 621 | ||
717 | ret = btrfs_del_items(trans, root, path, del_slot, del_nr); | 622 | ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0, |
623 | root->root_key.objectid, | ||
624 | inode->i_ino, orig_offset); | ||
718 | BUG_ON(ret); | 625 | BUG_ON(ret); |
719 | goto release; | ||
720 | } else if (split == start) { | ||
721 | if (locked_end < extent_end) { | ||
722 | ret = try_lock_extent(&BTRFS_I(inode)->io_tree, | ||
723 | locked_end, extent_end - 1, GFP_NOFS); | ||
724 | if (!ret) { | ||
725 | btrfs_release_path(root, path); | ||
726 | lock_extent(&BTRFS_I(inode)->io_tree, | ||
727 | locked_end, extent_end - 1, GFP_NOFS); | ||
728 | locked_end = extent_end; | ||
729 | goto again; | ||
730 | } | ||
731 | locked_end = extent_end; | ||
732 | } | ||
733 | btrfs_set_file_extent_num_bytes(leaf, fi, split - key.offset); | ||
734 | } else { | ||
735 | BUG_ON(key.offset != start); | ||
736 | key.offset = split; | ||
737 | btrfs_set_file_extent_offset(leaf, fi, key.offset - | ||
738 | orig_offset); | ||
739 | btrfs_set_file_extent_num_bytes(leaf, fi, extent_end - split); | ||
740 | btrfs_set_item_key_safe(trans, root, path, &key); | ||
741 | extent_end = split; | ||
742 | } | ||
743 | 626 | ||
744 | if (extent_end == end) { | 627 | if (split == start) { |
745 | split_end = 0; | 628 | key.offset = start; |
746 | extent_type = BTRFS_FILE_EXTENT_REG; | 629 | } else { |
747 | } | 630 | BUG_ON(start != key.offset); |
748 | if (extent_end == end && split == start) { | ||
749 | other_start = end; | ||
750 | other_end = 0; | ||
751 | if (extent_mergeable(leaf, path->slots[0] + 1, inode->i_ino, | ||
752 | bytenr, &other_start, &other_end)) { | ||
753 | path->slots[0]++; | ||
754 | fi = btrfs_item_ptr(leaf, path->slots[0], | ||
755 | struct btrfs_file_extent_item); | ||
756 | key.offset = split; | ||
757 | btrfs_set_item_key_safe(trans, root, path, &key); | ||
758 | btrfs_set_file_extent_offset(leaf, fi, key.offset - | ||
759 | orig_offset); | ||
760 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
761 | other_end - split); | ||
762 | goto done; | ||
763 | } | ||
764 | } | ||
765 | if (extent_end == end && split == end) { | ||
766 | other_start = 0; | ||
767 | other_end = start; | ||
768 | if (extent_mergeable(leaf, path->slots[0] - 1 , inode->i_ino, | ||
769 | bytenr, &other_start, &other_end)) { | ||
770 | path->slots[0]--; | 631 | path->slots[0]--; |
771 | fi = btrfs_item_ptr(leaf, path->slots[0], | 632 | extent_end = end; |
772 | struct btrfs_file_extent_item); | ||
773 | btrfs_set_file_extent_num_bytes(leaf, fi, extent_end - | ||
774 | other_start); | ||
775 | goto done; | ||
776 | } | 633 | } |
777 | } | 634 | } |
778 | 635 | ||
779 | btrfs_mark_buffer_dirty(leaf); | ||
780 | |||
781 | ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0, | ||
782 | root->root_key.objectid, | ||
783 | inode->i_ino, orig_offset); | ||
784 | BUG_ON(ret); | ||
785 | btrfs_release_path(root, path); | ||
786 | |||
787 | key.offset = start; | ||
788 | ret = btrfs_insert_empty_item(trans, root, path, &key, sizeof(*fi)); | ||
789 | BUG_ON(ret); | ||
790 | |||
791 | leaf = path->nodes[0]; | ||
792 | fi = btrfs_item_ptr(leaf, path->slots[0], | 636 | fi = btrfs_item_ptr(leaf, path->slots[0], |
793 | struct btrfs_file_extent_item); | 637 | struct btrfs_file_extent_item); |
794 | btrfs_set_file_extent_generation(leaf, fi, trans->transid); | ||
795 | btrfs_set_file_extent_type(leaf, fi, extent_type); | ||
796 | btrfs_set_file_extent_disk_bytenr(leaf, fi, bytenr); | ||
797 | btrfs_set_file_extent_disk_num_bytes(leaf, fi, num_bytes); | ||
798 | btrfs_set_file_extent_offset(leaf, fi, key.offset - orig_offset); | ||
799 | btrfs_set_file_extent_num_bytes(leaf, fi, extent_end - key.offset); | ||
800 | btrfs_set_file_extent_ram_bytes(leaf, fi, num_bytes); | ||
801 | btrfs_set_file_extent_compression(leaf, fi, 0); | ||
802 | btrfs_set_file_extent_encryption(leaf, fi, 0); | ||
803 | btrfs_set_file_extent_other_encoding(leaf, fi, 0); | ||
804 | done: | ||
805 | btrfs_mark_buffer_dirty(leaf); | ||
806 | 638 | ||
807 | release: | 639 | other_start = end; |
808 | btrfs_release_path(root, path); | 640 | other_end = 0; |
809 | if (split_end && split == start) { | 641 | if (extent_mergeable(leaf, path->slots[0] + 1, inode->i_ino, |
810 | split = end; | 642 | bytenr, &other_start, &other_end)) { |
811 | goto again; | 643 | extent_end = other_end; |
644 | del_slot = path->slots[0] + 1; | ||
645 | del_nr++; | ||
646 | ret = btrfs_free_extent(trans, root, bytenr, num_bytes, | ||
647 | 0, root->root_key.objectid, | ||
648 | inode->i_ino, orig_offset); | ||
649 | BUG_ON(ret); | ||
812 | } | 650 | } |
813 | if (locked_end > end) { | 651 | other_start = 0; |
814 | unlock_extent(&BTRFS_I(inode)->io_tree, end, locked_end - 1, | 652 | other_end = start; |
815 | GFP_NOFS); | 653 | if (extent_mergeable(leaf, path->slots[0] - 1, inode->i_ino, |
654 | bytenr, &other_start, &other_end)) { | ||
655 | key.offset = other_start; | ||
656 | del_slot = path->slots[0]; | ||
657 | del_nr++; | ||
658 | ret = btrfs_free_extent(trans, root, bytenr, num_bytes, | ||
659 | 0, root->root_key.objectid, | ||
660 | inode->i_ino, orig_offset); | ||
661 | BUG_ON(ret); | ||
816 | } | 662 | } |
663 | if (del_nr == 0) { | ||
664 | btrfs_set_file_extent_type(leaf, fi, | ||
665 | BTRFS_FILE_EXTENT_REG); | ||
666 | btrfs_mark_buffer_dirty(leaf); | ||
667 | goto out; | ||
668 | } | ||
669 | |||
670 | fi = btrfs_item_ptr(leaf, del_slot - 1, | ||
671 | struct btrfs_file_extent_item); | ||
672 | btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_REG); | ||
673 | btrfs_set_file_extent_num_bytes(leaf, fi, | ||
674 | extent_end - key.offset); | ||
675 | btrfs_mark_buffer_dirty(leaf); | ||
676 | |||
677 | ret = btrfs_del_items(trans, root, path, del_slot, del_nr); | ||
678 | BUG_ON(ret); | ||
679 | out: | ||
817 | btrfs_free_path(path); | 680 | btrfs_free_path(path); |
818 | return 0; | 681 | return 0; |
819 | } | 682 | } |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b3ad168a0bfc..5440bab23635 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -88,13 +88,14 @@ static noinline int cow_file_range(struct inode *inode, | |||
88 | u64 start, u64 end, int *page_started, | 88 | u64 start, u64 end, int *page_started, |
89 | unsigned long *nr_written, int unlock); | 89 | unsigned long *nr_written, int unlock); |
90 | 90 | ||
91 | static int btrfs_init_inode_security(struct inode *inode, struct inode *dir) | 91 | static int btrfs_init_inode_security(struct btrfs_trans_handle *trans, |
92 | struct inode *inode, struct inode *dir) | ||
92 | { | 93 | { |
93 | int err; | 94 | int err; |
94 | 95 | ||
95 | err = btrfs_init_acl(inode, dir); | 96 | err = btrfs_init_acl(trans, inode, dir); |
96 | if (!err) | 97 | if (!err) |
97 | err = btrfs_xattr_security_init(inode, dir); | 98 | err = btrfs_xattr_security_init(trans, inode, dir); |
98 | return err; | 99 | return err; |
99 | } | 100 | } |
100 | 101 | ||
@@ -188,8 +189,18 @@ static noinline int insert_inline_extent(struct btrfs_trans_handle *trans, | |||
188 | btrfs_mark_buffer_dirty(leaf); | 189 | btrfs_mark_buffer_dirty(leaf); |
189 | btrfs_free_path(path); | 190 | btrfs_free_path(path); |
190 | 191 | ||
192 | /* | ||
193 | * we're an inline extent, so nobody can | ||
194 | * extend the file past i_size without locking | ||
195 | * a page we already have locked. | ||
196 | * | ||
197 | * We must do any isize and inode updates | ||
198 | * before we unlock the pages. Otherwise we | ||
199 | * could end up racing with unlink. | ||
200 | */ | ||
191 | BTRFS_I(inode)->disk_i_size = inode->i_size; | 201 | BTRFS_I(inode)->disk_i_size = inode->i_size; |
192 | btrfs_update_inode(trans, root, inode); | 202 | btrfs_update_inode(trans, root, inode); |
203 | |||
193 | return 0; | 204 | return 0; |
194 | fail: | 205 | fail: |
195 | btrfs_free_path(path); | 206 | btrfs_free_path(path); |
@@ -230,8 +241,7 @@ static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans, | |||
230 | return 1; | 241 | return 1; |
231 | } | 242 | } |
232 | 243 | ||
233 | ret = btrfs_drop_extents(trans, root, inode, start, | 244 | ret = btrfs_drop_extents(trans, inode, start, aligned_end, |
234 | aligned_end, aligned_end, start, | ||
235 | &hint_byte, 1); | 245 | &hint_byte, 1); |
236 | BUG_ON(ret); | 246 | BUG_ON(ret); |
237 | 247 | ||
@@ -416,7 +426,6 @@ again: | |||
416 | start, end, | 426 | start, end, |
417 | total_compressed, pages); | 427 | total_compressed, pages); |
418 | } | 428 | } |
419 | btrfs_end_transaction(trans, root); | ||
420 | if (ret == 0) { | 429 | if (ret == 0) { |
421 | /* | 430 | /* |
422 | * inline extent creation worked, we don't need | 431 | * inline extent creation worked, we don't need |
@@ -430,9 +439,11 @@ again: | |||
430 | EXTENT_CLEAR_DELALLOC | | 439 | EXTENT_CLEAR_DELALLOC | |
431 | EXTENT_CLEAR_ACCOUNTING | | 440 | EXTENT_CLEAR_ACCOUNTING | |
432 | EXTENT_SET_WRITEBACK | EXTENT_END_WRITEBACK); | 441 | EXTENT_SET_WRITEBACK | EXTENT_END_WRITEBACK); |
433 | ret = 0; | 442 | |
443 | btrfs_end_transaction(trans, root); | ||
434 | goto free_pages_out; | 444 | goto free_pages_out; |
435 | } | 445 | } |
446 | btrfs_end_transaction(trans, root); | ||
436 | } | 447 | } |
437 | 448 | ||
438 | if (will_compress) { | 449 | if (will_compress) { |
@@ -543,7 +554,6 @@ static noinline int submit_compressed_extents(struct inode *inode, | |||
543 | if (list_empty(&async_cow->extents)) | 554 | if (list_empty(&async_cow->extents)) |
544 | return 0; | 555 | return 0; |
545 | 556 | ||
546 | trans = btrfs_join_transaction(root, 1); | ||
547 | 557 | ||
548 | while (!list_empty(&async_cow->extents)) { | 558 | while (!list_empty(&async_cow->extents)) { |
549 | async_extent = list_entry(async_cow->extents.next, | 559 | async_extent = list_entry(async_cow->extents.next, |
@@ -590,19 +600,15 @@ retry: | |||
590 | lock_extent(io_tree, async_extent->start, | 600 | lock_extent(io_tree, async_extent->start, |
591 | async_extent->start + async_extent->ram_size - 1, | 601 | async_extent->start + async_extent->ram_size - 1, |
592 | GFP_NOFS); | 602 | GFP_NOFS); |
593 | /* | ||
594 | * here we're doing allocation and writeback of the | ||
595 | * compressed pages | ||
596 | */ | ||
597 | btrfs_drop_extent_cache(inode, async_extent->start, | ||
598 | async_extent->start + | ||
599 | async_extent->ram_size - 1, 0); | ||
600 | 603 | ||
604 | trans = btrfs_join_transaction(root, 1); | ||
601 | ret = btrfs_reserve_extent(trans, root, | 605 | ret = btrfs_reserve_extent(trans, root, |
602 | async_extent->compressed_size, | 606 | async_extent->compressed_size, |
603 | async_extent->compressed_size, | 607 | async_extent->compressed_size, |
604 | 0, alloc_hint, | 608 | 0, alloc_hint, |
605 | (u64)-1, &ins, 1); | 609 | (u64)-1, &ins, 1); |
610 | btrfs_end_transaction(trans, root); | ||
611 | |||
606 | if (ret) { | 612 | if (ret) { |
607 | int i; | 613 | int i; |
608 | for (i = 0; i < async_extent->nr_pages; i++) { | 614 | for (i = 0; i < async_extent->nr_pages; i++) { |
@@ -618,6 +624,14 @@ retry: | |||
618 | goto retry; | 624 | goto retry; |
619 | } | 625 | } |
620 | 626 | ||
627 | /* | ||
628 | * here we're doing allocation and writeback of the | ||
629 | * compressed pages | ||
630 | */ | ||
631 | btrfs_drop_extent_cache(inode, async_extent->start, | ||
632 | async_extent->start + | ||
633 | async_extent->ram_size - 1, 0); | ||
634 | |||
621 | em = alloc_extent_map(GFP_NOFS); | 635 | em = alloc_extent_map(GFP_NOFS); |
622 | em->start = async_extent->start; | 636 | em->start = async_extent->start; |
623 | em->len = async_extent->ram_size; | 637 | em->len = async_extent->ram_size; |
@@ -649,8 +663,6 @@ retry: | |||
649 | BTRFS_ORDERED_COMPRESSED); | 663 | BTRFS_ORDERED_COMPRESSED); |
650 | BUG_ON(ret); | 664 | BUG_ON(ret); |
651 | 665 | ||
652 | btrfs_end_transaction(trans, root); | ||
653 | |||
654 | /* | 666 | /* |
655 | * clear dirty, set writeback and unlock the pages. | 667 | * clear dirty, set writeback and unlock the pages. |
656 | */ | 668 | */ |
@@ -672,13 +684,11 @@ retry: | |||
672 | async_extent->nr_pages); | 684 | async_extent->nr_pages); |
673 | 685 | ||
674 | BUG_ON(ret); | 686 | BUG_ON(ret); |
675 | trans = btrfs_join_transaction(root, 1); | ||
676 | alloc_hint = ins.objectid + ins.offset; | 687 | alloc_hint = ins.objectid + ins.offset; |
677 | kfree(async_extent); | 688 | kfree(async_extent); |
678 | cond_resched(); | 689 | cond_resched(); |
679 | } | 690 | } |
680 | 691 | ||
681 | btrfs_end_transaction(trans, root); | ||
682 | return 0; | 692 | return 0; |
683 | } | 693 | } |
684 | 694 | ||
@@ -742,6 +752,7 @@ static noinline int cow_file_range(struct inode *inode, | |||
742 | EXTENT_CLEAR_DIRTY | | 752 | EXTENT_CLEAR_DIRTY | |
743 | EXTENT_SET_WRITEBACK | | 753 | EXTENT_SET_WRITEBACK | |
744 | EXTENT_END_WRITEBACK); | 754 | EXTENT_END_WRITEBACK); |
755 | |||
745 | *nr_written = *nr_written + | 756 | *nr_written = *nr_written + |
746 | (end - start + PAGE_CACHE_SIZE) / PAGE_CACHE_SIZE; | 757 | (end - start + PAGE_CACHE_SIZE) / PAGE_CACHE_SIZE; |
747 | *page_started = 1; | 758 | *page_started = 1; |
@@ -1596,7 +1607,6 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, | |||
1596 | struct inode *inode, u64 file_pos, | 1607 | struct inode *inode, u64 file_pos, |
1597 | u64 disk_bytenr, u64 disk_num_bytes, | 1608 | u64 disk_bytenr, u64 disk_num_bytes, |
1598 | u64 num_bytes, u64 ram_bytes, | 1609 | u64 num_bytes, u64 ram_bytes, |
1599 | u64 locked_end, | ||
1600 | u8 compression, u8 encryption, | 1610 | u8 compression, u8 encryption, |
1601 | u16 other_encoding, int extent_type) | 1611 | u16 other_encoding, int extent_type) |
1602 | { | 1612 | { |
@@ -1622,9 +1632,8 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, | |||
1622 | * the caller is expected to unpin it and allow it to be merged | 1632 | * the caller is expected to unpin it and allow it to be merged |
1623 | * with the others. | 1633 | * with the others. |
1624 | */ | 1634 | */ |
1625 | ret = btrfs_drop_extents(trans, root, inode, file_pos, | 1635 | ret = btrfs_drop_extents(trans, inode, file_pos, file_pos + num_bytes, |
1626 | file_pos + num_bytes, locked_end, | 1636 | &hint, 0); |
1627 | file_pos, &hint, 0); | ||
1628 | BUG_ON(ret); | 1637 | BUG_ON(ret); |
1629 | 1638 | ||
1630 | ins.objectid = inode->i_ino; | 1639 | ins.objectid = inode->i_ino; |
@@ -1730,23 +1739,32 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1730 | } | 1739 | } |
1731 | } | 1740 | } |
1732 | 1741 | ||
1733 | trans = btrfs_join_transaction(root, 1); | ||
1734 | |||
1735 | if (!ordered_extent) | 1742 | if (!ordered_extent) |
1736 | ordered_extent = btrfs_lookup_ordered_extent(inode, start); | 1743 | ordered_extent = btrfs_lookup_ordered_extent(inode, start); |
1737 | BUG_ON(!ordered_extent); | 1744 | BUG_ON(!ordered_extent); |
1738 | if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) | 1745 | if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) { |
1739 | goto nocow; | 1746 | BUG_ON(!list_empty(&ordered_extent->list)); |
1747 | ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent); | ||
1748 | if (!ret) { | ||
1749 | trans = btrfs_join_transaction(root, 1); | ||
1750 | ret = btrfs_update_inode(trans, root, inode); | ||
1751 | BUG_ON(ret); | ||
1752 | btrfs_end_transaction(trans, root); | ||
1753 | } | ||
1754 | goto out; | ||
1755 | } | ||
1740 | 1756 | ||
1741 | lock_extent(io_tree, ordered_extent->file_offset, | 1757 | lock_extent(io_tree, ordered_extent->file_offset, |
1742 | ordered_extent->file_offset + ordered_extent->len - 1, | 1758 | ordered_extent->file_offset + ordered_extent->len - 1, |
1743 | GFP_NOFS); | 1759 | GFP_NOFS); |
1744 | 1760 | ||
1761 | trans = btrfs_join_transaction(root, 1); | ||
1762 | |||
1745 | if (test_bit(BTRFS_ORDERED_COMPRESSED, &ordered_extent->flags)) | 1763 | if (test_bit(BTRFS_ORDERED_COMPRESSED, &ordered_extent->flags)) |
1746 | compressed = 1; | 1764 | compressed = 1; |
1747 | if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) { | 1765 | if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) { |
1748 | BUG_ON(compressed); | 1766 | BUG_ON(compressed); |
1749 | ret = btrfs_mark_extent_written(trans, root, inode, | 1767 | ret = btrfs_mark_extent_written(trans, inode, |
1750 | ordered_extent->file_offset, | 1768 | ordered_extent->file_offset, |
1751 | ordered_extent->file_offset + | 1769 | ordered_extent->file_offset + |
1752 | ordered_extent->len); | 1770 | ordered_extent->len); |
@@ -1758,8 +1776,6 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1758 | ordered_extent->disk_len, | 1776 | ordered_extent->disk_len, |
1759 | ordered_extent->len, | 1777 | ordered_extent->len, |
1760 | ordered_extent->len, | 1778 | ordered_extent->len, |
1761 | ordered_extent->file_offset + | ||
1762 | ordered_extent->len, | ||
1763 | compressed, 0, 0, | 1779 | compressed, 0, 0, |
1764 | BTRFS_FILE_EXTENT_REG); | 1780 | BTRFS_FILE_EXTENT_REG); |
1765 | unpin_extent_cache(&BTRFS_I(inode)->extent_tree, | 1781 | unpin_extent_cache(&BTRFS_I(inode)->extent_tree, |
@@ -1770,22 +1786,20 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1770 | unlock_extent(io_tree, ordered_extent->file_offset, | 1786 | unlock_extent(io_tree, ordered_extent->file_offset, |
1771 | ordered_extent->file_offset + ordered_extent->len - 1, | 1787 | ordered_extent->file_offset + ordered_extent->len - 1, |
1772 | GFP_NOFS); | 1788 | GFP_NOFS); |
1773 | nocow: | ||
1774 | add_pending_csums(trans, inode, ordered_extent->file_offset, | 1789 | add_pending_csums(trans, inode, ordered_extent->file_offset, |
1775 | &ordered_extent->list); | 1790 | &ordered_extent->list); |
1776 | 1791 | ||
1777 | mutex_lock(&BTRFS_I(inode)->extent_mutex); | 1792 | /* this also removes the ordered extent from the tree */ |
1778 | btrfs_ordered_update_i_size(inode, ordered_extent); | 1793 | btrfs_ordered_update_i_size(inode, 0, ordered_extent); |
1779 | btrfs_update_inode(trans, root, inode); | 1794 | ret = btrfs_update_inode(trans, root, inode); |
1780 | btrfs_remove_ordered_extent(inode, ordered_extent); | 1795 | BUG_ON(ret); |
1781 | mutex_unlock(&BTRFS_I(inode)->extent_mutex); | 1796 | btrfs_end_transaction(trans, root); |
1782 | 1797 | out: | |
1783 | /* once for us */ | 1798 | /* once for us */ |
1784 | btrfs_put_ordered_extent(ordered_extent); | 1799 | btrfs_put_ordered_extent(ordered_extent); |
1785 | /* once for the tree */ | 1800 | /* once for the tree */ |
1786 | btrfs_put_ordered_extent(ordered_extent); | 1801 | btrfs_put_ordered_extent(ordered_extent); |
1787 | 1802 | ||
1788 | btrfs_end_transaction(trans, root); | ||
1789 | return 0; | 1803 | return 0; |
1790 | } | 1804 | } |
1791 | 1805 | ||
@@ -2008,6 +2022,54 @@ zeroit: | |||
2008 | return -EIO; | 2022 | return -EIO; |
2009 | } | 2023 | } |
2010 | 2024 | ||
2025 | struct delayed_iput { | ||
2026 | struct list_head list; | ||
2027 | struct inode *inode; | ||
2028 | }; | ||
2029 | |||
2030 | void btrfs_add_delayed_iput(struct inode *inode) | ||
2031 | { | ||
2032 | struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info; | ||
2033 | struct delayed_iput *delayed; | ||
2034 | |||
2035 | if (atomic_add_unless(&inode->i_count, -1, 1)) | ||
2036 | return; | ||
2037 | |||
2038 | delayed = kmalloc(sizeof(*delayed), GFP_NOFS | __GFP_NOFAIL); | ||
2039 | delayed->inode = inode; | ||
2040 | |||
2041 | spin_lock(&fs_info->delayed_iput_lock); | ||
2042 | list_add_tail(&delayed->list, &fs_info->delayed_iputs); | ||
2043 | spin_unlock(&fs_info->delayed_iput_lock); | ||
2044 | } | ||
2045 | |||
2046 | void btrfs_run_delayed_iputs(struct btrfs_root *root) | ||
2047 | { | ||
2048 | LIST_HEAD(list); | ||
2049 | struct btrfs_fs_info *fs_info = root->fs_info; | ||
2050 | struct delayed_iput *delayed; | ||
2051 | int empty; | ||
2052 | |||
2053 | spin_lock(&fs_info->delayed_iput_lock); | ||
2054 | empty = list_empty(&fs_info->delayed_iputs); | ||
2055 | spin_unlock(&fs_info->delayed_iput_lock); | ||
2056 | if (empty) | ||
2057 | return; | ||
2058 | |||
2059 | down_read(&root->fs_info->cleanup_work_sem); | ||
2060 | spin_lock(&fs_info->delayed_iput_lock); | ||
2061 | list_splice_init(&fs_info->delayed_iputs, &list); | ||
2062 | spin_unlock(&fs_info->delayed_iput_lock); | ||
2063 | |||
2064 | while (!list_empty(&list)) { | ||
2065 | delayed = list_entry(list.next, struct delayed_iput, list); | ||
2066 | list_del(&delayed->list); | ||
2067 | iput(delayed->inode); | ||
2068 | kfree(delayed); | ||
2069 | } | ||
2070 | up_read(&root->fs_info->cleanup_work_sem); | ||
2071 | } | ||
2072 | |||
2011 | /* | 2073 | /* |
2012 | * This creates an orphan entry for the given inode in case something goes | 2074 | * This creates an orphan entry for the given inode in case something goes |
2013 | * wrong in the middle of an unlink/truncate. | 2075 | * wrong in the middle of an unlink/truncate. |
@@ -2080,16 +2142,17 @@ void btrfs_orphan_cleanup(struct btrfs_root *root) | |||
2080 | struct inode *inode; | 2142 | struct inode *inode; |
2081 | int ret = 0, nr_unlink = 0, nr_truncate = 0; | 2143 | int ret = 0, nr_unlink = 0, nr_truncate = 0; |
2082 | 2144 | ||
2083 | path = btrfs_alloc_path(); | 2145 | if (!xchg(&root->clean_orphans, 0)) |
2084 | if (!path) | ||
2085 | return; | 2146 | return; |
2147 | |||
2148 | path = btrfs_alloc_path(); | ||
2149 | BUG_ON(!path); | ||
2086 | path->reada = -1; | 2150 | path->reada = -1; |
2087 | 2151 | ||
2088 | key.objectid = BTRFS_ORPHAN_OBJECTID; | 2152 | key.objectid = BTRFS_ORPHAN_OBJECTID; |
2089 | btrfs_set_key_type(&key, BTRFS_ORPHAN_ITEM_KEY); | 2153 | btrfs_set_key_type(&key, BTRFS_ORPHAN_ITEM_KEY); |
2090 | key.offset = (u64)-1; | 2154 | key.offset = (u64)-1; |
2091 | 2155 | ||
2092 | |||
2093 | while (1) { | 2156 | while (1) { |
2094 | ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); | 2157 | ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); |
2095 | if (ret < 0) { | 2158 | if (ret < 0) { |
@@ -2834,37 +2897,40 @@ out: | |||
2834 | * min_type is the minimum key type to truncate down to. If set to 0, this | 2897 | * min_type is the minimum key type to truncate down to. If set to 0, this |
2835 | * will kill all the items on this inode, including the INODE_ITEM_KEY. | 2898 | * will kill all the items on this inode, including the INODE_ITEM_KEY. |
2836 | */ | 2899 | */ |
2837 | noinline int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, | 2900 | int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, |
2838 | struct btrfs_root *root, | 2901 | struct btrfs_root *root, |
2839 | struct inode *inode, | 2902 | struct inode *inode, |
2840 | u64 new_size, u32 min_type) | 2903 | u64 new_size, u32 min_type) |
2841 | { | 2904 | { |
2842 | int ret; | ||
2843 | struct btrfs_path *path; | 2905 | struct btrfs_path *path; |
2844 | struct btrfs_key key; | ||
2845 | struct btrfs_key found_key; | ||
2846 | u32 found_type = (u8)-1; | ||
2847 | struct extent_buffer *leaf; | 2906 | struct extent_buffer *leaf; |
2848 | struct btrfs_file_extent_item *fi; | 2907 | struct btrfs_file_extent_item *fi; |
2908 | struct btrfs_key key; | ||
2909 | struct btrfs_key found_key; | ||
2849 | u64 extent_start = 0; | 2910 | u64 extent_start = 0; |
2850 | u64 extent_num_bytes = 0; | 2911 | u64 extent_num_bytes = 0; |
2851 | u64 extent_offset = 0; | 2912 | u64 extent_offset = 0; |
2852 | u64 item_end = 0; | 2913 | u64 item_end = 0; |
2914 | u64 mask = root->sectorsize - 1; | ||
2915 | u32 found_type = (u8)-1; | ||
2853 | int found_extent; | 2916 | int found_extent; |
2854 | int del_item; | 2917 | int del_item; |
2855 | int pending_del_nr = 0; | 2918 | int pending_del_nr = 0; |
2856 | int pending_del_slot = 0; | 2919 | int pending_del_slot = 0; |
2857 | int extent_type = -1; | 2920 | int extent_type = -1; |
2858 | int encoding; | 2921 | int encoding; |
2859 | u64 mask = root->sectorsize - 1; | 2922 | int ret; |
2923 | int err = 0; | ||
2924 | |||
2925 | BUG_ON(new_size > 0 && min_type != BTRFS_EXTENT_DATA_KEY); | ||
2860 | 2926 | ||
2861 | if (root->ref_cows) | 2927 | if (root->ref_cows) |
2862 | btrfs_drop_extent_cache(inode, new_size & (~mask), (u64)-1, 0); | 2928 | btrfs_drop_extent_cache(inode, new_size & (~mask), (u64)-1, 0); |
2929 | |||
2863 | path = btrfs_alloc_path(); | 2930 | path = btrfs_alloc_path(); |
2864 | BUG_ON(!path); | 2931 | BUG_ON(!path); |
2865 | path->reada = -1; | 2932 | path->reada = -1; |
2866 | 2933 | ||
2867 | /* FIXME, add redo link to tree so we don't leak on crash */ | ||
2868 | key.objectid = inode->i_ino; | 2934 | key.objectid = inode->i_ino; |
2869 | key.offset = (u64)-1; | 2935 | key.offset = (u64)-1; |
2870 | key.type = (u8)-1; | 2936 | key.type = (u8)-1; |
@@ -2872,17 +2938,17 @@ noinline int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, | |||
2872 | search_again: | 2938 | search_again: |
2873 | path->leave_spinning = 1; | 2939 | path->leave_spinning = 1; |
2874 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); | 2940 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); |
2875 | if (ret < 0) | 2941 | if (ret < 0) { |
2876 | goto error; | 2942 | err = ret; |
2943 | goto out; | ||
2944 | } | ||
2877 | 2945 | ||
2878 | if (ret > 0) { | 2946 | if (ret > 0) { |
2879 | /* there are no items in the tree for us to truncate, we're | 2947 | /* there are no items in the tree for us to truncate, we're |
2880 | * done | 2948 | * done |
2881 | */ | 2949 | */ |
2882 | if (path->slots[0] == 0) { | 2950 | if (path->slots[0] == 0) |
2883 | ret = 0; | 2951 | goto out; |
2884 | goto error; | ||
2885 | } | ||
2886 | path->slots[0]--; | 2952 | path->slots[0]--; |
2887 | } | 2953 | } |
2888 | 2954 | ||
@@ -2917,28 +2983,17 @@ search_again: | |||
2917 | } | 2983 | } |
2918 | item_end--; | 2984 | item_end--; |
2919 | } | 2985 | } |
2920 | if (item_end < new_size) { | 2986 | if (found_type > min_type) { |
2921 | if (found_type == BTRFS_DIR_ITEM_KEY) | 2987 | del_item = 1; |
2922 | found_type = BTRFS_INODE_ITEM_KEY; | 2988 | } else { |
2923 | else if (found_type == BTRFS_EXTENT_ITEM_KEY) | 2989 | if (item_end < new_size) |
2924 | found_type = BTRFS_EXTENT_DATA_KEY; | ||
2925 | else if (found_type == BTRFS_EXTENT_DATA_KEY) | ||
2926 | found_type = BTRFS_XATTR_ITEM_KEY; | ||
2927 | else if (found_type == BTRFS_XATTR_ITEM_KEY) | ||
2928 | found_type = BTRFS_INODE_REF_KEY; | ||
2929 | else if (found_type) | ||
2930 | found_type--; | ||
2931 | else | ||
2932 | break; | 2990 | break; |
2933 | btrfs_set_key_type(&key, found_type); | 2991 | if (found_key.offset >= new_size) |
2934 | goto next; | 2992 | del_item = 1; |
2993 | else | ||
2994 | del_item = 0; | ||
2935 | } | 2995 | } |
2936 | if (found_key.offset >= new_size) | ||
2937 | del_item = 1; | ||
2938 | else | ||
2939 | del_item = 0; | ||
2940 | found_extent = 0; | 2996 | found_extent = 0; |
2941 | |||
2942 | /* FIXME, shrink the extent if the ref count is only 1 */ | 2997 | /* FIXME, shrink the extent if the ref count is only 1 */ |
2943 | if (found_type != BTRFS_EXTENT_DATA_KEY) | 2998 | if (found_type != BTRFS_EXTENT_DATA_KEY) |
2944 | goto delete; | 2999 | goto delete; |
@@ -3025,42 +3080,36 @@ delete: | |||
3025 | inode->i_ino, extent_offset); | 3080 | inode->i_ino, extent_offset); |
3026 | BUG_ON(ret); | 3081 | BUG_ON(ret); |
3027 | } | 3082 | } |
3028 | next: | ||
3029 | if (path->slots[0] == 0) { | ||
3030 | if (pending_del_nr) | ||
3031 | goto del_pending; | ||
3032 | btrfs_release_path(root, path); | ||
3033 | if (found_type == BTRFS_INODE_ITEM_KEY) | ||
3034 | break; | ||
3035 | goto search_again; | ||
3036 | } | ||
3037 | 3083 | ||
3038 | path->slots[0]--; | 3084 | if (found_type == BTRFS_INODE_ITEM_KEY) |
3039 | if (pending_del_nr && | 3085 | break; |
3040 | path->slots[0] + 1 != pending_del_slot) { | 3086 | |
3041 | struct btrfs_key debug; | 3087 | if (path->slots[0] == 0 || |
3042 | del_pending: | 3088 | path->slots[0] != pending_del_slot) { |
3043 | btrfs_item_key_to_cpu(path->nodes[0], &debug, | 3089 | if (root->ref_cows) { |
3044 | pending_del_slot); | 3090 | err = -EAGAIN; |
3045 | ret = btrfs_del_items(trans, root, path, | 3091 | goto out; |
3046 | pending_del_slot, | 3092 | } |
3047 | pending_del_nr); | 3093 | if (pending_del_nr) { |
3048 | BUG_ON(ret); | 3094 | ret = btrfs_del_items(trans, root, path, |
3049 | pending_del_nr = 0; | 3095 | pending_del_slot, |
3096 | pending_del_nr); | ||
3097 | BUG_ON(ret); | ||
3098 | pending_del_nr = 0; | ||
3099 | } | ||
3050 | btrfs_release_path(root, path); | 3100 | btrfs_release_path(root, path); |
3051 | if (found_type == BTRFS_INODE_ITEM_KEY) | ||
3052 | break; | ||
3053 | goto search_again; | 3101 | goto search_again; |
3102 | } else { | ||
3103 | path->slots[0]--; | ||
3054 | } | 3104 | } |
3055 | } | 3105 | } |
3056 | ret = 0; | 3106 | out: |
3057 | error: | ||
3058 | if (pending_del_nr) { | 3107 | if (pending_del_nr) { |
3059 | ret = btrfs_del_items(trans, root, path, pending_del_slot, | 3108 | ret = btrfs_del_items(trans, root, path, pending_del_slot, |
3060 | pending_del_nr); | 3109 | pending_del_nr); |
3061 | } | 3110 | } |
3062 | btrfs_free_path(path); | 3111 | btrfs_free_path(path); |
3063 | return ret; | 3112 | return err; |
3064 | } | 3113 | } |
3065 | 3114 | ||
3066 | /* | 3115 | /* |
@@ -3180,10 +3229,6 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) | |||
3180 | if (size <= hole_start) | 3229 | if (size <= hole_start) |
3181 | return 0; | 3230 | return 0; |
3182 | 3231 | ||
3183 | err = btrfs_truncate_page(inode->i_mapping, inode->i_size); | ||
3184 | if (err) | ||
3185 | return err; | ||
3186 | |||
3187 | while (1) { | 3232 | while (1) { |
3188 | struct btrfs_ordered_extent *ordered; | 3233 | struct btrfs_ordered_extent *ordered; |
3189 | btrfs_wait_ordered_range(inode, hole_start, | 3234 | btrfs_wait_ordered_range(inode, hole_start, |
@@ -3196,9 +3241,6 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) | |||
3196 | btrfs_put_ordered_extent(ordered); | 3241 | btrfs_put_ordered_extent(ordered); |
3197 | } | 3242 | } |
3198 | 3243 | ||
3199 | trans = btrfs_start_transaction(root, 1); | ||
3200 | btrfs_set_trans_block_group(trans, inode); | ||
3201 | |||
3202 | cur_offset = hole_start; | 3244 | cur_offset = hole_start; |
3203 | while (1) { | 3245 | while (1) { |
3204 | em = btrfs_get_extent(inode, NULL, 0, cur_offset, | 3246 | em = btrfs_get_extent(inode, NULL, 0, cur_offset, |
@@ -3206,40 +3248,120 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) | |||
3206 | BUG_ON(IS_ERR(em) || !em); | 3248 | BUG_ON(IS_ERR(em) || !em); |
3207 | last_byte = min(extent_map_end(em), block_end); | 3249 | last_byte = min(extent_map_end(em), block_end); |
3208 | last_byte = (last_byte + mask) & ~mask; | 3250 | last_byte = (last_byte + mask) & ~mask; |
3209 | if (test_bit(EXTENT_FLAG_VACANCY, &em->flags)) { | 3251 | if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) { |
3210 | u64 hint_byte = 0; | 3252 | u64 hint_byte = 0; |
3211 | hole_size = last_byte - cur_offset; | 3253 | hole_size = last_byte - cur_offset; |
3212 | err = btrfs_drop_extents(trans, root, inode, | ||
3213 | cur_offset, | ||
3214 | cur_offset + hole_size, | ||
3215 | block_end, | ||
3216 | cur_offset, &hint_byte, 1); | ||
3217 | if (err) | ||
3218 | break; | ||
3219 | 3254 | ||
3220 | err = btrfs_reserve_metadata_space(root, 1); | 3255 | err = btrfs_reserve_metadata_space(root, 2); |
3221 | if (err) | 3256 | if (err) |
3222 | break; | 3257 | break; |
3223 | 3258 | ||
3259 | trans = btrfs_start_transaction(root, 1); | ||
3260 | btrfs_set_trans_block_group(trans, inode); | ||
3261 | |||
3262 | err = btrfs_drop_extents(trans, inode, cur_offset, | ||
3263 | cur_offset + hole_size, | ||
3264 | &hint_byte, 1); | ||
3265 | BUG_ON(err); | ||
3266 | |||
3224 | err = btrfs_insert_file_extent(trans, root, | 3267 | err = btrfs_insert_file_extent(trans, root, |
3225 | inode->i_ino, cur_offset, 0, | 3268 | inode->i_ino, cur_offset, 0, |
3226 | 0, hole_size, 0, hole_size, | 3269 | 0, hole_size, 0, hole_size, |
3227 | 0, 0, 0); | 3270 | 0, 0, 0); |
3271 | BUG_ON(err); | ||
3272 | |||
3228 | btrfs_drop_extent_cache(inode, hole_start, | 3273 | btrfs_drop_extent_cache(inode, hole_start, |
3229 | last_byte - 1, 0); | 3274 | last_byte - 1, 0); |
3230 | btrfs_unreserve_metadata_space(root, 1); | 3275 | |
3276 | btrfs_end_transaction(trans, root); | ||
3277 | btrfs_unreserve_metadata_space(root, 2); | ||
3231 | } | 3278 | } |
3232 | free_extent_map(em); | 3279 | free_extent_map(em); |
3233 | cur_offset = last_byte; | 3280 | cur_offset = last_byte; |
3234 | if (err || cur_offset >= block_end) | 3281 | if (cur_offset >= block_end) |
3235 | break; | 3282 | break; |
3236 | } | 3283 | } |
3237 | 3284 | ||
3238 | btrfs_end_transaction(trans, root); | ||
3239 | unlock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); | 3285 | unlock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); |
3240 | return err; | 3286 | return err; |
3241 | } | 3287 | } |
3242 | 3288 | ||
3289 | static int btrfs_setattr_size(struct inode *inode, struct iattr *attr) | ||
3290 | { | ||
3291 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
3292 | struct btrfs_trans_handle *trans; | ||
3293 | unsigned long nr; | ||
3294 | int ret; | ||
3295 | |||
3296 | if (attr->ia_size == inode->i_size) | ||
3297 | return 0; | ||
3298 | |||
3299 | if (attr->ia_size > inode->i_size) { | ||
3300 | unsigned long limit; | ||
3301 | limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; | ||
3302 | if (attr->ia_size > inode->i_sb->s_maxbytes) | ||
3303 | return -EFBIG; | ||
3304 | if (limit != RLIM_INFINITY && attr->ia_size > limit) { | ||
3305 | send_sig(SIGXFSZ, current, 0); | ||
3306 | return -EFBIG; | ||
3307 | } | ||
3308 | } | ||
3309 | |||
3310 | ret = btrfs_reserve_metadata_space(root, 1); | ||
3311 | if (ret) | ||
3312 | return ret; | ||
3313 | |||
3314 | trans = btrfs_start_transaction(root, 1); | ||
3315 | btrfs_set_trans_block_group(trans, inode); | ||
3316 | |||
3317 | ret = btrfs_orphan_add(trans, inode); | ||
3318 | BUG_ON(ret); | ||
3319 | |||
3320 | nr = trans->blocks_used; | ||
3321 | btrfs_end_transaction(trans, root); | ||
3322 | btrfs_unreserve_metadata_space(root, 1); | ||
3323 | btrfs_btree_balance_dirty(root, nr); | ||
3324 | |||
3325 | if (attr->ia_size > inode->i_size) { | ||
3326 | ret = btrfs_cont_expand(inode, attr->ia_size); | ||
3327 | if (ret) { | ||
3328 | btrfs_truncate(inode); | ||
3329 | return ret; | ||
3330 | } | ||
3331 | |||
3332 | i_size_write(inode, attr->ia_size); | ||
3333 | btrfs_ordered_update_i_size(inode, inode->i_size, NULL); | ||
3334 | |||
3335 | trans = btrfs_start_transaction(root, 1); | ||
3336 | btrfs_set_trans_block_group(trans, inode); | ||
3337 | |||
3338 | ret = btrfs_update_inode(trans, root, inode); | ||
3339 | BUG_ON(ret); | ||
3340 | if (inode->i_nlink > 0) { | ||
3341 | ret = btrfs_orphan_del(trans, inode); | ||
3342 | BUG_ON(ret); | ||
3343 | } | ||
3344 | nr = trans->blocks_used; | ||
3345 | btrfs_end_transaction(trans, root); | ||
3346 | btrfs_btree_balance_dirty(root, nr); | ||
3347 | return 0; | ||
3348 | } | ||
3349 | |||
3350 | /* | ||
3351 | * We're truncating a file that used to have good data down to | ||
3352 | * zero. Make sure it gets into the ordered flush list so that | ||
3353 | * any new writes get down to disk quickly. | ||
3354 | */ | ||
3355 | if (attr->ia_size == 0) | ||
3356 | BTRFS_I(inode)->ordered_data_close = 1; | ||
3357 | |||
3358 | /* we don't support swapfiles, so vmtruncate shouldn't fail */ | ||
3359 | ret = vmtruncate(inode, attr->ia_size); | ||
3360 | BUG_ON(ret); | ||
3361 | |||
3362 | return 0; | ||
3363 | } | ||
3364 | |||
3243 | static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) | 3365 | static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) |
3244 | { | 3366 | { |
3245 | struct inode *inode = dentry->d_inode; | 3367 | struct inode *inode = dentry->d_inode; |
@@ -3250,23 +3372,14 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
3250 | return err; | 3372 | return err; |
3251 | 3373 | ||
3252 | if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) { | 3374 | if (S_ISREG(inode->i_mode) && (attr->ia_valid & ATTR_SIZE)) { |
3253 | if (attr->ia_size > inode->i_size) { | 3375 | err = btrfs_setattr_size(inode, attr); |
3254 | err = btrfs_cont_expand(inode, attr->ia_size); | 3376 | if (err) |
3255 | if (err) | 3377 | return err; |
3256 | return err; | ||
3257 | } else if (inode->i_size > 0 && | ||
3258 | attr->ia_size == 0) { | ||
3259 | |||
3260 | /* we're truncating a file that used to have good | ||
3261 | * data down to zero. Make sure it gets into | ||
3262 | * the ordered flush list so that any new writes | ||
3263 | * get down to disk quickly. | ||
3264 | */ | ||
3265 | BTRFS_I(inode)->ordered_data_close = 1; | ||
3266 | } | ||
3267 | } | 3378 | } |
3379 | attr->ia_valid &= ~ATTR_SIZE; | ||
3268 | 3380 | ||
3269 | err = inode_setattr(inode, attr); | 3381 | if (attr->ia_valid) |
3382 | err = inode_setattr(inode, attr); | ||
3270 | 3383 | ||
3271 | if (!err && ((attr->ia_valid & ATTR_MODE))) | 3384 | if (!err && ((attr->ia_valid & ATTR_MODE))) |
3272 | err = btrfs_acl_chmod(inode); | 3385 | err = btrfs_acl_chmod(inode); |
@@ -3287,36 +3400,43 @@ void btrfs_delete_inode(struct inode *inode) | |||
3287 | } | 3400 | } |
3288 | btrfs_wait_ordered_range(inode, 0, (u64)-1); | 3401 | btrfs_wait_ordered_range(inode, 0, (u64)-1); |
3289 | 3402 | ||
3403 | if (root->fs_info->log_root_recovering) { | ||
3404 | BUG_ON(!list_empty(&BTRFS_I(inode)->i_orphan)); | ||
3405 | goto no_delete; | ||
3406 | } | ||
3407 | |||
3290 | if (inode->i_nlink > 0) { | 3408 | if (inode->i_nlink > 0) { |
3291 | BUG_ON(btrfs_root_refs(&root->root_item) != 0); | 3409 | BUG_ON(btrfs_root_refs(&root->root_item) != 0); |
3292 | goto no_delete; | 3410 | goto no_delete; |
3293 | } | 3411 | } |
3294 | 3412 | ||
3295 | btrfs_i_size_write(inode, 0); | 3413 | btrfs_i_size_write(inode, 0); |
3296 | trans = btrfs_join_transaction(root, 1); | ||
3297 | 3414 | ||
3298 | btrfs_set_trans_block_group(trans, inode); | 3415 | while (1) { |
3299 | ret = btrfs_truncate_inode_items(trans, root, inode, inode->i_size, 0); | 3416 | trans = btrfs_start_transaction(root, 1); |
3300 | if (ret) { | 3417 | btrfs_set_trans_block_group(trans, inode); |
3301 | btrfs_orphan_del(NULL, inode); | 3418 | ret = btrfs_truncate_inode_items(trans, root, inode, 0, 0); |
3302 | goto no_delete_lock; | ||
3303 | } | ||
3304 | 3419 | ||
3305 | btrfs_orphan_del(trans, inode); | 3420 | if (ret != -EAGAIN) |
3421 | break; | ||
3306 | 3422 | ||
3307 | nr = trans->blocks_used; | 3423 | nr = trans->blocks_used; |
3308 | clear_inode(inode); | 3424 | btrfs_end_transaction(trans, root); |
3425 | trans = NULL; | ||
3426 | btrfs_btree_balance_dirty(root, nr); | ||
3427 | } | ||
3309 | 3428 | ||
3310 | btrfs_end_transaction(trans, root); | 3429 | if (ret == 0) { |
3311 | btrfs_btree_balance_dirty(root, nr); | 3430 | ret = btrfs_orphan_del(trans, inode); |
3312 | return; | 3431 | BUG_ON(ret); |
3432 | } | ||
3313 | 3433 | ||
3314 | no_delete_lock: | ||
3315 | nr = trans->blocks_used; | 3434 | nr = trans->blocks_used; |
3316 | btrfs_end_transaction(trans, root); | 3435 | btrfs_end_transaction(trans, root); |
3317 | btrfs_btree_balance_dirty(root, nr); | 3436 | btrfs_btree_balance_dirty(root, nr); |
3318 | no_delete: | 3437 | no_delete: |
3319 | clear_inode(inode); | 3438 | clear_inode(inode); |
3439 | return; | ||
3320 | } | 3440 | } |
3321 | 3441 | ||
3322 | /* | 3442 | /* |
@@ -3569,7 +3689,6 @@ static noinline void init_btrfs_i(struct inode *inode) | |||
3569 | INIT_LIST_HEAD(&BTRFS_I(inode)->ordered_operations); | 3689 | INIT_LIST_HEAD(&BTRFS_I(inode)->ordered_operations); |
3570 | RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node); | 3690 | RB_CLEAR_NODE(&BTRFS_I(inode)->rb_node); |
3571 | btrfs_ordered_inode_tree_init(&BTRFS_I(inode)->ordered_tree); | 3691 | btrfs_ordered_inode_tree_init(&BTRFS_I(inode)->ordered_tree); |
3572 | mutex_init(&BTRFS_I(inode)->extent_mutex); | ||
3573 | mutex_init(&BTRFS_I(inode)->log_mutex); | 3692 | mutex_init(&BTRFS_I(inode)->log_mutex); |
3574 | } | 3693 | } |
3575 | 3694 | ||
@@ -3695,6 +3814,13 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) | |||
3695 | } | 3814 | } |
3696 | srcu_read_unlock(&root->fs_info->subvol_srcu, index); | 3815 | srcu_read_unlock(&root->fs_info->subvol_srcu, index); |
3697 | 3816 | ||
3817 | if (root != sub_root) { | ||
3818 | down_read(&root->fs_info->cleanup_work_sem); | ||
3819 | if (!(inode->i_sb->s_flags & MS_RDONLY)) | ||
3820 | btrfs_orphan_cleanup(sub_root); | ||
3821 | up_read(&root->fs_info->cleanup_work_sem); | ||
3822 | } | ||
3823 | |||
3698 | return inode; | 3824 | return inode; |
3699 | } | 3825 | } |
3700 | 3826 | ||
@@ -4219,7 +4345,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, | |||
4219 | if (IS_ERR(inode)) | 4345 | if (IS_ERR(inode)) |
4220 | goto out_unlock; | 4346 | goto out_unlock; |
4221 | 4347 | ||
4222 | err = btrfs_init_inode_security(inode, dir); | 4348 | err = btrfs_init_inode_security(trans, inode, dir); |
4223 | if (err) { | 4349 | if (err) { |
4224 | drop_inode = 1; | 4350 | drop_inode = 1; |
4225 | goto out_unlock; | 4351 | goto out_unlock; |
@@ -4290,7 +4416,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, | |||
4290 | if (IS_ERR(inode)) | 4416 | if (IS_ERR(inode)) |
4291 | goto out_unlock; | 4417 | goto out_unlock; |
4292 | 4418 | ||
4293 | err = btrfs_init_inode_security(inode, dir); | 4419 | err = btrfs_init_inode_security(trans, inode, dir); |
4294 | if (err) { | 4420 | if (err) { |
4295 | drop_inode = 1; | 4421 | drop_inode = 1; |
4296 | goto out_unlock; | 4422 | goto out_unlock; |
@@ -4336,6 +4462,10 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, | |||
4336 | if (inode->i_nlink == 0) | 4462 | if (inode->i_nlink == 0) |
4337 | return -ENOENT; | 4463 | return -ENOENT; |
4338 | 4464 | ||
4465 | /* do not allow sys_link's with other subvols of the same device */ | ||
4466 | if (root->objectid != BTRFS_I(inode)->root->objectid) | ||
4467 | return -EPERM; | ||
4468 | |||
4339 | /* | 4469 | /* |
4340 | * 1 item for inode ref | 4470 | * 1 item for inode ref |
4341 | * 2 items for dir items | 4471 | * 2 items for dir items |
@@ -4423,7 +4553,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
4423 | 4553 | ||
4424 | drop_on_err = 1; | 4554 | drop_on_err = 1; |
4425 | 4555 | ||
4426 | err = btrfs_init_inode_security(inode, dir); | 4556 | err = btrfs_init_inode_security(trans, inode, dir); |
4427 | if (err) | 4557 | if (err) |
4428 | goto out_fail; | 4558 | goto out_fail; |
4429 | 4559 | ||
@@ -5074,17 +5204,20 @@ static void btrfs_truncate(struct inode *inode) | |||
5074 | unsigned long nr; | 5204 | unsigned long nr; |
5075 | u64 mask = root->sectorsize - 1; | 5205 | u64 mask = root->sectorsize - 1; |
5076 | 5206 | ||
5077 | if (!S_ISREG(inode->i_mode)) | 5207 | if (!S_ISREG(inode->i_mode)) { |
5078 | return; | 5208 | WARN_ON(1); |
5079 | if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) | ||
5080 | return; | 5209 | return; |
5210 | } | ||
5081 | 5211 | ||
5082 | ret = btrfs_truncate_page(inode->i_mapping, inode->i_size); | 5212 | ret = btrfs_truncate_page(inode->i_mapping, inode->i_size); |
5083 | if (ret) | 5213 | if (ret) |
5084 | return; | 5214 | return; |
5215 | |||
5085 | btrfs_wait_ordered_range(inode, inode->i_size & (~mask), (u64)-1); | 5216 | btrfs_wait_ordered_range(inode, inode->i_size & (~mask), (u64)-1); |
5217 | btrfs_ordered_update_i_size(inode, inode->i_size, NULL); | ||
5086 | 5218 | ||
5087 | trans = btrfs_start_transaction(root, 1); | 5219 | trans = btrfs_start_transaction(root, 1); |
5220 | btrfs_set_trans_block_group(trans, inode); | ||
5088 | 5221 | ||
5089 | /* | 5222 | /* |
5090 | * setattr is responsible for setting the ordered_data_close flag, | 5223 | * setattr is responsible for setting the ordered_data_close flag, |
@@ -5106,21 +5239,32 @@ static void btrfs_truncate(struct inode *inode) | |||
5106 | if (inode->i_size == 0 && BTRFS_I(inode)->ordered_data_close) | 5239 | if (inode->i_size == 0 && BTRFS_I(inode)->ordered_data_close) |
5107 | btrfs_add_ordered_operation(trans, root, inode); | 5240 | btrfs_add_ordered_operation(trans, root, inode); |
5108 | 5241 | ||
5109 | btrfs_set_trans_block_group(trans, inode); | 5242 | while (1) { |
5110 | btrfs_i_size_write(inode, inode->i_size); | 5243 | ret = btrfs_truncate_inode_items(trans, root, inode, |
5244 | inode->i_size, | ||
5245 | BTRFS_EXTENT_DATA_KEY); | ||
5246 | if (ret != -EAGAIN) | ||
5247 | break; | ||
5111 | 5248 | ||
5112 | ret = btrfs_orphan_add(trans, inode); | 5249 | ret = btrfs_update_inode(trans, root, inode); |
5113 | if (ret) | 5250 | BUG_ON(ret); |
5114 | goto out; | 5251 | |
5115 | /* FIXME, add redo link to tree so we don't leak on crash */ | 5252 | nr = trans->blocks_used; |
5116 | ret = btrfs_truncate_inode_items(trans, root, inode, inode->i_size, | 5253 | btrfs_end_transaction(trans, root); |
5117 | BTRFS_EXTENT_DATA_KEY); | 5254 | btrfs_btree_balance_dirty(root, nr); |
5118 | btrfs_update_inode(trans, root, inode); | 5255 | |
5256 | trans = btrfs_start_transaction(root, 1); | ||
5257 | btrfs_set_trans_block_group(trans, inode); | ||
5258 | } | ||
5119 | 5259 | ||
5120 | ret = btrfs_orphan_del(trans, inode); | 5260 | if (ret == 0 && inode->i_nlink > 0) { |
5261 | ret = btrfs_orphan_del(trans, inode); | ||
5262 | BUG_ON(ret); | ||
5263 | } | ||
5264 | |||
5265 | ret = btrfs_update_inode(trans, root, inode); | ||
5121 | BUG_ON(ret); | 5266 | BUG_ON(ret); |
5122 | 5267 | ||
5123 | out: | ||
5124 | nr = trans->blocks_used; | 5268 | nr = trans->blocks_used; |
5125 | ret = btrfs_end_transaction_throttle(trans, root); | 5269 | ret = btrfs_end_transaction_throttle(trans, root); |
5126 | BUG_ON(ret); | 5270 | BUG_ON(ret); |
@@ -5217,9 +5361,9 @@ void btrfs_destroy_inode(struct inode *inode) | |||
5217 | 5361 | ||
5218 | spin_lock(&root->list_lock); | 5362 | spin_lock(&root->list_lock); |
5219 | if (!list_empty(&BTRFS_I(inode)->i_orphan)) { | 5363 | if (!list_empty(&BTRFS_I(inode)->i_orphan)) { |
5220 | printk(KERN_ERR "BTRFS: inode %lu: inode still on the orphan" | 5364 | printk(KERN_INFO "BTRFS: inode %lu still on the orphan list\n", |
5221 | " list\n", inode->i_ino); | 5365 | inode->i_ino); |
5222 | dump_stack(); | 5366 | list_del_init(&BTRFS_I(inode)->i_orphan); |
5223 | } | 5367 | } |
5224 | spin_unlock(&root->list_lock); | 5368 | spin_unlock(&root->list_lock); |
5225 | 5369 | ||
@@ -5476,7 +5620,7 @@ out_fail: | |||
5476 | * some fairly slow code that needs optimization. This walks the list | 5620 | * some fairly slow code that needs optimization. This walks the list |
5477 | * of all the inodes with pending delalloc and forces them to disk. | 5621 | * of all the inodes with pending delalloc and forces them to disk. |
5478 | */ | 5622 | */ |
5479 | int btrfs_start_delalloc_inodes(struct btrfs_root *root) | 5623 | int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput) |
5480 | { | 5624 | { |
5481 | struct list_head *head = &root->fs_info->delalloc_inodes; | 5625 | struct list_head *head = &root->fs_info->delalloc_inodes; |
5482 | struct btrfs_inode *binode; | 5626 | struct btrfs_inode *binode; |
@@ -5495,7 +5639,10 @@ int btrfs_start_delalloc_inodes(struct btrfs_root *root) | |||
5495 | spin_unlock(&root->fs_info->delalloc_lock); | 5639 | spin_unlock(&root->fs_info->delalloc_lock); |
5496 | if (inode) { | 5640 | if (inode) { |
5497 | filemap_flush(inode->i_mapping); | 5641 | filemap_flush(inode->i_mapping); |
5498 | iput(inode); | 5642 | if (delay_iput) |
5643 | btrfs_add_delayed_iput(inode); | ||
5644 | else | ||
5645 | iput(inode); | ||
5499 | } | 5646 | } |
5500 | cond_resched(); | 5647 | cond_resched(); |
5501 | spin_lock(&root->fs_info->delalloc_lock); | 5648 | spin_lock(&root->fs_info->delalloc_lock); |
@@ -5569,7 +5716,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | |||
5569 | if (IS_ERR(inode)) | 5716 | if (IS_ERR(inode)) |
5570 | goto out_unlock; | 5717 | goto out_unlock; |
5571 | 5718 | ||
5572 | err = btrfs_init_inode_security(inode, dir); | 5719 | err = btrfs_init_inode_security(trans, inode, dir); |
5573 | if (err) { | 5720 | if (err) { |
5574 | drop_inode = 1; | 5721 | drop_inode = 1; |
5575 | goto out_unlock; | 5722 | goto out_unlock; |
@@ -5641,10 +5788,10 @@ out_fail: | |||
5641 | return err; | 5788 | return err; |
5642 | } | 5789 | } |
5643 | 5790 | ||
5644 | static int prealloc_file_range(struct btrfs_trans_handle *trans, | 5791 | static int prealloc_file_range(struct inode *inode, u64 start, u64 end, |
5645 | struct inode *inode, u64 start, u64 end, | 5792 | u64 alloc_hint, int mode) |
5646 | u64 locked_end, u64 alloc_hint, int mode) | ||
5647 | { | 5793 | { |
5794 | struct btrfs_trans_handle *trans; | ||
5648 | struct btrfs_root *root = BTRFS_I(inode)->root; | 5795 | struct btrfs_root *root = BTRFS_I(inode)->root; |
5649 | struct btrfs_key ins; | 5796 | struct btrfs_key ins; |
5650 | u64 alloc_size; | 5797 | u64 alloc_size; |
@@ -5655,43 +5802,56 @@ static int prealloc_file_range(struct btrfs_trans_handle *trans, | |||
5655 | while (num_bytes > 0) { | 5802 | while (num_bytes > 0) { |
5656 | alloc_size = min(num_bytes, root->fs_info->max_extent); | 5803 | alloc_size = min(num_bytes, root->fs_info->max_extent); |
5657 | 5804 | ||
5658 | ret = btrfs_reserve_metadata_space(root, 1); | 5805 | trans = btrfs_start_transaction(root, 1); |
5659 | if (ret) | ||
5660 | goto out; | ||
5661 | 5806 | ||
5662 | ret = btrfs_reserve_extent(trans, root, alloc_size, | 5807 | ret = btrfs_reserve_extent(trans, root, alloc_size, |
5663 | root->sectorsize, 0, alloc_hint, | 5808 | root->sectorsize, 0, alloc_hint, |
5664 | (u64)-1, &ins, 1); | 5809 | (u64)-1, &ins, 1); |
5665 | if (ret) { | 5810 | if (ret) { |
5666 | WARN_ON(1); | 5811 | WARN_ON(1); |
5667 | goto out; | 5812 | goto stop_trans; |
5813 | } | ||
5814 | |||
5815 | ret = btrfs_reserve_metadata_space(root, 3); | ||
5816 | if (ret) { | ||
5817 | btrfs_free_reserved_extent(root, ins.objectid, | ||
5818 | ins.offset); | ||
5819 | goto stop_trans; | ||
5668 | } | 5820 | } |
5821 | |||
5669 | ret = insert_reserved_file_extent(trans, inode, | 5822 | ret = insert_reserved_file_extent(trans, inode, |
5670 | cur_offset, ins.objectid, | 5823 | cur_offset, ins.objectid, |
5671 | ins.offset, ins.offset, | 5824 | ins.offset, ins.offset, |
5672 | ins.offset, locked_end, | 5825 | ins.offset, 0, 0, 0, |
5673 | 0, 0, 0, | ||
5674 | BTRFS_FILE_EXTENT_PREALLOC); | 5826 | BTRFS_FILE_EXTENT_PREALLOC); |
5675 | BUG_ON(ret); | 5827 | BUG_ON(ret); |
5676 | btrfs_drop_extent_cache(inode, cur_offset, | 5828 | btrfs_drop_extent_cache(inode, cur_offset, |
5677 | cur_offset + ins.offset -1, 0); | 5829 | cur_offset + ins.offset -1, 0); |
5830 | |||
5678 | num_bytes -= ins.offset; | 5831 | num_bytes -= ins.offset; |
5679 | cur_offset += ins.offset; | 5832 | cur_offset += ins.offset; |
5680 | alloc_hint = ins.objectid + ins.offset; | 5833 | alloc_hint = ins.objectid + ins.offset; |
5681 | btrfs_unreserve_metadata_space(root, 1); | 5834 | |
5682 | } | ||
5683 | out: | ||
5684 | if (cur_offset > start) { | ||
5685 | inode->i_ctime = CURRENT_TIME; | 5835 | inode->i_ctime = CURRENT_TIME; |
5686 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; | 5836 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; |
5687 | if (!(mode & FALLOC_FL_KEEP_SIZE) && | 5837 | if (!(mode & FALLOC_FL_KEEP_SIZE) && |
5688 | cur_offset > i_size_read(inode)) | 5838 | cur_offset > inode->i_size) { |
5689 | btrfs_i_size_write(inode, cur_offset); | 5839 | i_size_write(inode, cur_offset); |
5840 | btrfs_ordered_update_i_size(inode, cur_offset, NULL); | ||
5841 | } | ||
5842 | |||
5690 | ret = btrfs_update_inode(trans, root, inode); | 5843 | ret = btrfs_update_inode(trans, root, inode); |
5691 | BUG_ON(ret); | 5844 | BUG_ON(ret); |
5845 | |||
5846 | btrfs_end_transaction(trans, root); | ||
5847 | btrfs_unreserve_metadata_space(root, 3); | ||
5692 | } | 5848 | } |
5849 | return ret; | ||
5693 | 5850 | ||
5851 | stop_trans: | ||
5852 | btrfs_end_transaction(trans, root); | ||
5694 | return ret; | 5853 | return ret; |
5854 | |||
5695 | } | 5855 | } |
5696 | 5856 | ||
5697 | static long btrfs_fallocate(struct inode *inode, int mode, | 5857 | static long btrfs_fallocate(struct inode *inode, int mode, |
@@ -5705,8 +5865,6 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5705 | u64 locked_end; | 5865 | u64 locked_end; |
5706 | u64 mask = BTRFS_I(inode)->root->sectorsize - 1; | 5866 | u64 mask = BTRFS_I(inode)->root->sectorsize - 1; |
5707 | struct extent_map *em; | 5867 | struct extent_map *em; |
5708 | struct btrfs_trans_handle *trans; | ||
5709 | struct btrfs_root *root; | ||
5710 | int ret; | 5868 | int ret; |
5711 | 5869 | ||
5712 | alloc_start = offset & ~mask; | 5870 | alloc_start = offset & ~mask; |
@@ -5725,9 +5883,7 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5725 | goto out; | 5883 | goto out; |
5726 | } | 5884 | } |
5727 | 5885 | ||
5728 | root = BTRFS_I(inode)->root; | 5886 | ret = btrfs_check_data_free_space(BTRFS_I(inode)->root, inode, |
5729 | |||
5730 | ret = btrfs_check_data_free_space(root, inode, | ||
5731 | alloc_end - alloc_start); | 5887 | alloc_end - alloc_start); |
5732 | if (ret) | 5888 | if (ret) |
5733 | goto out; | 5889 | goto out; |
@@ -5736,12 +5892,6 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5736 | while (1) { | 5892 | while (1) { |
5737 | struct btrfs_ordered_extent *ordered; | 5893 | struct btrfs_ordered_extent *ordered; |
5738 | 5894 | ||
5739 | trans = btrfs_start_transaction(BTRFS_I(inode)->root, 1); | ||
5740 | if (!trans) { | ||
5741 | ret = -EIO; | ||
5742 | goto out_free; | ||
5743 | } | ||
5744 | |||
5745 | /* the extent lock is ordered inside the running | 5895 | /* the extent lock is ordered inside the running |
5746 | * transaction | 5896 | * transaction |
5747 | */ | 5897 | */ |
@@ -5755,8 +5905,6 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5755 | btrfs_put_ordered_extent(ordered); | 5905 | btrfs_put_ordered_extent(ordered); |
5756 | unlock_extent(&BTRFS_I(inode)->io_tree, | 5906 | unlock_extent(&BTRFS_I(inode)->io_tree, |
5757 | alloc_start, locked_end, GFP_NOFS); | 5907 | alloc_start, locked_end, GFP_NOFS); |
5758 | btrfs_end_transaction(trans, BTRFS_I(inode)->root); | ||
5759 | |||
5760 | /* | 5908 | /* |
5761 | * we can't wait on the range with the transaction | 5909 | * we can't wait on the range with the transaction |
5762 | * running or with the extent lock held | 5910 | * running or with the extent lock held |
@@ -5777,10 +5925,12 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5777 | BUG_ON(IS_ERR(em) || !em); | 5925 | BUG_ON(IS_ERR(em) || !em); |
5778 | last_byte = min(extent_map_end(em), alloc_end); | 5926 | last_byte = min(extent_map_end(em), alloc_end); |
5779 | last_byte = (last_byte + mask) & ~mask; | 5927 | last_byte = (last_byte + mask) & ~mask; |
5780 | if (em->block_start == EXTENT_MAP_HOLE) { | 5928 | if (em->block_start == EXTENT_MAP_HOLE || |
5781 | ret = prealloc_file_range(trans, inode, cur_offset, | 5929 | (cur_offset >= inode->i_size && |
5782 | last_byte, locked_end + 1, | 5930 | !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { |
5783 | alloc_hint, mode); | 5931 | ret = prealloc_file_range(inode, |
5932 | cur_offset, last_byte, | ||
5933 | alloc_hint, mode); | ||
5784 | if (ret < 0) { | 5934 | if (ret < 0) { |
5785 | free_extent_map(em); | 5935 | free_extent_map(em); |
5786 | break; | 5936 | break; |
@@ -5799,9 +5949,8 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5799 | unlock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, | 5949 | unlock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, |
5800 | GFP_NOFS); | 5950 | GFP_NOFS); |
5801 | 5951 | ||
5802 | btrfs_end_transaction(trans, BTRFS_I(inode)->root); | 5952 | btrfs_free_reserved_data_space(BTRFS_I(inode)->root, inode, |
5803 | out_free: | 5953 | alloc_end - alloc_start); |
5804 | btrfs_free_reserved_data_space(root, inode, alloc_end - alloc_start); | ||
5805 | out: | 5954 | out: |
5806 | mutex_unlock(&inode->i_mutex); | 5955 | mutex_unlock(&inode->i_mutex); |
5807 | return ret; | 5956 | return ret; |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index cdbb054102b9..645a17927a8f 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -237,7 +237,6 @@ static noinline int create_subvol(struct btrfs_root *root, | |||
237 | u64 objectid; | 237 | u64 objectid; |
238 | u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID; | 238 | u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID; |
239 | u64 index = 0; | 239 | u64 index = 0; |
240 | unsigned long nr = 1; | ||
241 | 240 | ||
242 | /* | 241 | /* |
243 | * 1 - inode item | 242 | * 1 - inode item |
@@ -290,7 +289,7 @@ static noinline int create_subvol(struct btrfs_root *root, | |||
290 | btrfs_set_root_generation(&root_item, trans->transid); | 289 | btrfs_set_root_generation(&root_item, trans->transid); |
291 | btrfs_set_root_level(&root_item, 0); | 290 | btrfs_set_root_level(&root_item, 0); |
292 | btrfs_set_root_refs(&root_item, 1); | 291 | btrfs_set_root_refs(&root_item, 1); |
293 | btrfs_set_root_used(&root_item, 0); | 292 | btrfs_set_root_used(&root_item, leaf->len); |
294 | btrfs_set_root_last_snapshot(&root_item, 0); | 293 | btrfs_set_root_last_snapshot(&root_item, 0); |
295 | 294 | ||
296 | memset(&root_item.drop_progress, 0, sizeof(root_item.drop_progress)); | 295 | memset(&root_item.drop_progress, 0, sizeof(root_item.drop_progress)); |
@@ -342,24 +341,21 @@ static noinline int create_subvol(struct btrfs_root *root, | |||
342 | 341 | ||
343 | d_instantiate(dentry, btrfs_lookup_dentry(dir, dentry)); | 342 | d_instantiate(dentry, btrfs_lookup_dentry(dir, dentry)); |
344 | fail: | 343 | fail: |
345 | nr = trans->blocks_used; | ||
346 | err = btrfs_commit_transaction(trans, root); | 344 | err = btrfs_commit_transaction(trans, root); |
347 | if (err && !ret) | 345 | if (err && !ret) |
348 | ret = err; | 346 | ret = err; |
349 | 347 | ||
350 | btrfs_unreserve_metadata_space(root, 6); | 348 | btrfs_unreserve_metadata_space(root, 6); |
351 | btrfs_btree_balance_dirty(root, nr); | ||
352 | return ret; | 349 | return ret; |
353 | } | 350 | } |
354 | 351 | ||
355 | static int create_snapshot(struct btrfs_root *root, struct dentry *dentry, | 352 | static int create_snapshot(struct btrfs_root *root, struct dentry *dentry, |
356 | char *name, int namelen) | 353 | char *name, int namelen) |
357 | { | 354 | { |
355 | struct inode *inode; | ||
358 | struct btrfs_pending_snapshot *pending_snapshot; | 356 | struct btrfs_pending_snapshot *pending_snapshot; |
359 | struct btrfs_trans_handle *trans; | 357 | struct btrfs_trans_handle *trans; |
360 | int ret = 0; | 358 | int ret; |
361 | int err; | ||
362 | unsigned long nr = 0; | ||
363 | 359 | ||
364 | if (!root->ref_cows) | 360 | if (!root->ref_cows) |
365 | return -EINVAL; | 361 | return -EINVAL; |
@@ -372,20 +368,20 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry, | |||
372 | */ | 368 | */ |
373 | ret = btrfs_reserve_metadata_space(root, 6); | 369 | ret = btrfs_reserve_metadata_space(root, 6); |
374 | if (ret) | 370 | if (ret) |
375 | goto fail_unlock; | 371 | goto fail; |
376 | 372 | ||
377 | pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS); | 373 | pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS); |
378 | if (!pending_snapshot) { | 374 | if (!pending_snapshot) { |
379 | ret = -ENOMEM; | 375 | ret = -ENOMEM; |
380 | btrfs_unreserve_metadata_space(root, 6); | 376 | btrfs_unreserve_metadata_space(root, 6); |
381 | goto fail_unlock; | 377 | goto fail; |
382 | } | 378 | } |
383 | pending_snapshot->name = kmalloc(namelen + 1, GFP_NOFS); | 379 | pending_snapshot->name = kmalloc(namelen + 1, GFP_NOFS); |
384 | if (!pending_snapshot->name) { | 380 | if (!pending_snapshot->name) { |
385 | ret = -ENOMEM; | 381 | ret = -ENOMEM; |
386 | kfree(pending_snapshot); | 382 | kfree(pending_snapshot); |
387 | btrfs_unreserve_metadata_space(root, 6); | 383 | btrfs_unreserve_metadata_space(root, 6); |
388 | goto fail_unlock; | 384 | goto fail; |
389 | } | 385 | } |
390 | memcpy(pending_snapshot->name, name, namelen); | 386 | memcpy(pending_snapshot->name, name, namelen); |
391 | pending_snapshot->name[namelen] = '\0'; | 387 | pending_snapshot->name[namelen] = '\0'; |
@@ -395,10 +391,19 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry, | |||
395 | pending_snapshot->root = root; | 391 | pending_snapshot->root = root; |
396 | list_add(&pending_snapshot->list, | 392 | list_add(&pending_snapshot->list, |
397 | &trans->transaction->pending_snapshots); | 393 | &trans->transaction->pending_snapshots); |
398 | err = btrfs_commit_transaction(trans, root); | 394 | ret = btrfs_commit_transaction(trans, root); |
395 | BUG_ON(ret); | ||
396 | btrfs_unreserve_metadata_space(root, 6); | ||
399 | 397 | ||
400 | fail_unlock: | 398 | inode = btrfs_lookup_dentry(dentry->d_parent->d_inode, dentry); |
401 | btrfs_btree_balance_dirty(root, nr); | 399 | if (IS_ERR(inode)) { |
400 | ret = PTR_ERR(inode); | ||
401 | goto fail; | ||
402 | } | ||
403 | BUG_ON(!inode); | ||
404 | d_instantiate(dentry, inode); | ||
405 | ret = 0; | ||
406 | fail: | ||
402 | return ret; | 407 | return ret; |
403 | } | 408 | } |
404 | 409 | ||
@@ -1027,8 +1032,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, | |||
1027 | BUG_ON(!trans); | 1032 | BUG_ON(!trans); |
1028 | 1033 | ||
1029 | /* punch hole in destination first */ | 1034 | /* punch hole in destination first */ |
1030 | btrfs_drop_extents(trans, root, inode, off, off + len, | 1035 | btrfs_drop_extents(trans, inode, off, off + len, &hint_byte, 1); |
1031 | off + len, 0, &hint_byte, 1); | ||
1032 | 1036 | ||
1033 | /* clone data */ | 1037 | /* clone data */ |
1034 | key.objectid = src->i_ino; | 1038 | key.objectid = src->i_ino; |
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 5799bc46a309..b10a49d4bc6a 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c | |||
@@ -291,16 +291,16 @@ int btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry) | |||
291 | 291 | ||
292 | /* | 292 | /* |
293 | * remove an ordered extent from the tree. No references are dropped | 293 | * remove an ordered extent from the tree. No references are dropped |
294 | * but, anyone waiting on this extent is woken up. | 294 | * and you must wake_up entry->wait. You must hold the tree mutex |
295 | * while you call this function. | ||
295 | */ | 296 | */ |
296 | int btrfs_remove_ordered_extent(struct inode *inode, | 297 | static int __btrfs_remove_ordered_extent(struct inode *inode, |
297 | struct btrfs_ordered_extent *entry) | 298 | struct btrfs_ordered_extent *entry) |
298 | { | 299 | { |
299 | struct btrfs_ordered_inode_tree *tree; | 300 | struct btrfs_ordered_inode_tree *tree; |
300 | struct rb_node *node; | 301 | struct rb_node *node; |
301 | 302 | ||
302 | tree = &BTRFS_I(inode)->ordered_tree; | 303 | tree = &BTRFS_I(inode)->ordered_tree; |
303 | mutex_lock(&tree->mutex); | ||
304 | node = &entry->rb_node; | 304 | node = &entry->rb_node; |
305 | rb_erase(node, &tree->tree); | 305 | rb_erase(node, &tree->tree); |
306 | tree->last = NULL; | 306 | tree->last = NULL; |
@@ -326,16 +326,34 @@ int btrfs_remove_ordered_extent(struct inode *inode, | |||
326 | } | 326 | } |
327 | spin_unlock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); | 327 | spin_unlock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); |
328 | 328 | ||
329 | return 0; | ||
330 | } | ||
331 | |||
332 | /* | ||
333 | * remove an ordered extent from the tree. No references are dropped | ||
334 | * but any waiters are woken. | ||
335 | */ | ||
336 | int btrfs_remove_ordered_extent(struct inode *inode, | ||
337 | struct btrfs_ordered_extent *entry) | ||
338 | { | ||
339 | struct btrfs_ordered_inode_tree *tree; | ||
340 | int ret; | ||
341 | |||
342 | tree = &BTRFS_I(inode)->ordered_tree; | ||
343 | mutex_lock(&tree->mutex); | ||
344 | ret = __btrfs_remove_ordered_extent(inode, entry); | ||
329 | mutex_unlock(&tree->mutex); | 345 | mutex_unlock(&tree->mutex); |
330 | wake_up(&entry->wait); | 346 | wake_up(&entry->wait); |
331 | return 0; | 347 | |
348 | return ret; | ||
332 | } | 349 | } |
333 | 350 | ||
334 | /* | 351 | /* |
335 | * wait for all the ordered extents in a root. This is done when balancing | 352 | * wait for all the ordered extents in a root. This is done when balancing |
336 | * space between drives. | 353 | * space between drives. |
337 | */ | 354 | */ |
338 | int btrfs_wait_ordered_extents(struct btrfs_root *root, int nocow_only) | 355 | int btrfs_wait_ordered_extents(struct btrfs_root *root, |
356 | int nocow_only, int delay_iput) | ||
339 | { | 357 | { |
340 | struct list_head splice; | 358 | struct list_head splice; |
341 | struct list_head *cur; | 359 | struct list_head *cur; |
@@ -372,7 +390,10 @@ int btrfs_wait_ordered_extents(struct btrfs_root *root, int nocow_only) | |||
372 | if (inode) { | 390 | if (inode) { |
373 | btrfs_start_ordered_extent(inode, ordered, 1); | 391 | btrfs_start_ordered_extent(inode, ordered, 1); |
374 | btrfs_put_ordered_extent(ordered); | 392 | btrfs_put_ordered_extent(ordered); |
375 | iput(inode); | 393 | if (delay_iput) |
394 | btrfs_add_delayed_iput(inode); | ||
395 | else | ||
396 | iput(inode); | ||
376 | } else { | 397 | } else { |
377 | btrfs_put_ordered_extent(ordered); | 398 | btrfs_put_ordered_extent(ordered); |
378 | } | 399 | } |
@@ -430,7 +451,7 @@ again: | |||
430 | btrfs_wait_ordered_range(inode, 0, (u64)-1); | 451 | btrfs_wait_ordered_range(inode, 0, (u64)-1); |
431 | else | 452 | else |
432 | filemap_flush(inode->i_mapping); | 453 | filemap_flush(inode->i_mapping); |
433 | iput(inode); | 454 | btrfs_add_delayed_iput(inode); |
434 | } | 455 | } |
435 | 456 | ||
436 | cond_resched(); | 457 | cond_resched(); |
@@ -589,7 +610,7 @@ out: | |||
589 | * After an extent is done, call this to conditionally update the on disk | 610 | * After an extent is done, call this to conditionally update the on disk |
590 | * i_size. i_size is updated to cover any fully written part of the file. | 611 | * i_size. i_size is updated to cover any fully written part of the file. |
591 | */ | 612 | */ |
592 | int btrfs_ordered_update_i_size(struct inode *inode, | 613 | int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, |
593 | struct btrfs_ordered_extent *ordered) | 614 | struct btrfs_ordered_extent *ordered) |
594 | { | 615 | { |
595 | struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree; | 616 | struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree; |
@@ -597,18 +618,30 @@ int btrfs_ordered_update_i_size(struct inode *inode, | |||
597 | u64 disk_i_size; | 618 | u64 disk_i_size; |
598 | u64 new_i_size; | 619 | u64 new_i_size; |
599 | u64 i_size_test; | 620 | u64 i_size_test; |
621 | u64 i_size = i_size_read(inode); | ||
600 | struct rb_node *node; | 622 | struct rb_node *node; |
623 | struct rb_node *prev = NULL; | ||
601 | struct btrfs_ordered_extent *test; | 624 | struct btrfs_ordered_extent *test; |
625 | int ret = 1; | ||
626 | |||
627 | if (ordered) | ||
628 | offset = entry_end(ordered); | ||
602 | 629 | ||
603 | mutex_lock(&tree->mutex); | 630 | mutex_lock(&tree->mutex); |
604 | disk_i_size = BTRFS_I(inode)->disk_i_size; | 631 | disk_i_size = BTRFS_I(inode)->disk_i_size; |
605 | 632 | ||
633 | /* truncate file */ | ||
634 | if (disk_i_size > i_size) { | ||
635 | BTRFS_I(inode)->disk_i_size = i_size; | ||
636 | ret = 0; | ||
637 | goto out; | ||
638 | } | ||
639 | |||
606 | /* | 640 | /* |
607 | * if the disk i_size is already at the inode->i_size, or | 641 | * if the disk i_size is already at the inode->i_size, or |
608 | * this ordered extent is inside the disk i_size, we're done | 642 | * this ordered extent is inside the disk i_size, we're done |
609 | */ | 643 | */ |
610 | if (disk_i_size >= inode->i_size || | 644 | if (disk_i_size == i_size || offset <= disk_i_size) { |
611 | ordered->file_offset + ordered->len <= disk_i_size) { | ||
612 | goto out; | 645 | goto out; |
613 | } | 646 | } |
614 | 647 | ||
@@ -616,8 +649,7 @@ int btrfs_ordered_update_i_size(struct inode *inode, | |||
616 | * we can't update the disk_isize if there are delalloc bytes | 649 | * we can't update the disk_isize if there are delalloc bytes |
617 | * between disk_i_size and this ordered extent | 650 | * between disk_i_size and this ordered extent |
618 | */ | 651 | */ |
619 | if (test_range_bit(io_tree, disk_i_size, | 652 | if (test_range_bit(io_tree, disk_i_size, offset - 1, |
620 | ordered->file_offset + ordered->len - 1, | ||
621 | EXTENT_DELALLOC, 0, NULL)) { | 653 | EXTENT_DELALLOC, 0, NULL)) { |
622 | goto out; | 654 | goto out; |
623 | } | 655 | } |
@@ -626,20 +658,32 @@ int btrfs_ordered_update_i_size(struct inode *inode, | |||
626 | * if we find an ordered extent then we can't update disk i_size | 658 | * if we find an ordered extent then we can't update disk i_size |
627 | * yet | 659 | * yet |
628 | */ | 660 | */ |
629 | node = &ordered->rb_node; | 661 | if (ordered) { |
630 | while (1) { | 662 | node = rb_prev(&ordered->rb_node); |
631 | node = rb_prev(node); | 663 | } else { |
632 | if (!node) | 664 | prev = tree_search(tree, offset); |
633 | break; | 665 | /* |
666 | * we insert file extents without involving ordered struct, | ||
667 | * so there should be no ordered struct cover this offset | ||
668 | */ | ||
669 | if (prev) { | ||
670 | test = rb_entry(prev, struct btrfs_ordered_extent, | ||
671 | rb_node); | ||
672 | BUG_ON(offset_in_entry(test, offset)); | ||
673 | } | ||
674 | node = prev; | ||
675 | } | ||
676 | while (node) { | ||
634 | test = rb_entry(node, struct btrfs_ordered_extent, rb_node); | 677 | test = rb_entry(node, struct btrfs_ordered_extent, rb_node); |
635 | if (test->file_offset + test->len <= disk_i_size) | 678 | if (test->file_offset + test->len <= disk_i_size) |
636 | break; | 679 | break; |
637 | if (test->file_offset >= inode->i_size) | 680 | if (test->file_offset >= i_size) |
638 | break; | 681 | break; |
639 | if (test->file_offset >= disk_i_size) | 682 | if (test->file_offset >= disk_i_size) |
640 | goto out; | 683 | goto out; |
684 | node = rb_prev(node); | ||
641 | } | 685 | } |
642 | new_i_size = min_t(u64, entry_end(ordered), i_size_read(inode)); | 686 | new_i_size = min_t(u64, offset, i_size); |
643 | 687 | ||
644 | /* | 688 | /* |
645 | * at this point, we know we can safely update i_size to at least | 689 | * at this point, we know we can safely update i_size to at least |
@@ -647,7 +691,14 @@ int btrfs_ordered_update_i_size(struct inode *inode, | |||
647 | * walk forward and see if ios from higher up in the file have | 691 | * walk forward and see if ios from higher up in the file have |
648 | * finished. | 692 | * finished. |
649 | */ | 693 | */ |
650 | node = rb_next(&ordered->rb_node); | 694 | if (ordered) { |
695 | node = rb_next(&ordered->rb_node); | ||
696 | } else { | ||
697 | if (prev) | ||
698 | node = rb_next(prev); | ||
699 | else | ||
700 | node = rb_first(&tree->tree); | ||
701 | } | ||
651 | i_size_test = 0; | 702 | i_size_test = 0; |
652 | if (node) { | 703 | if (node) { |
653 | /* | 704 | /* |
@@ -655,10 +706,10 @@ int btrfs_ordered_update_i_size(struct inode *inode, | |||
655 | * between our ordered extent and the next one. | 706 | * between our ordered extent and the next one. |
656 | */ | 707 | */ |
657 | test = rb_entry(node, struct btrfs_ordered_extent, rb_node); | 708 | test = rb_entry(node, struct btrfs_ordered_extent, rb_node); |
658 | if (test->file_offset > entry_end(ordered)) | 709 | if (test->file_offset > offset) |
659 | i_size_test = test->file_offset; | 710 | i_size_test = test->file_offset; |
660 | } else { | 711 | } else { |
661 | i_size_test = i_size_read(inode); | 712 | i_size_test = i_size; |
662 | } | 713 | } |
663 | 714 | ||
664 | /* | 715 | /* |
@@ -667,15 +718,25 @@ int btrfs_ordered_update_i_size(struct inode *inode, | |||
667 | * are no delalloc bytes in this area, it is safe to update | 718 | * are no delalloc bytes in this area, it is safe to update |
668 | * disk_i_size to the end of the region. | 719 | * disk_i_size to the end of the region. |
669 | */ | 720 | */ |
670 | if (i_size_test > entry_end(ordered) && | 721 | if (i_size_test > offset && |
671 | !test_range_bit(io_tree, entry_end(ordered), i_size_test - 1, | 722 | !test_range_bit(io_tree, offset, i_size_test - 1, |
672 | EXTENT_DELALLOC, 0, NULL)) { | 723 | EXTENT_DELALLOC, 0, NULL)) { |
673 | new_i_size = min_t(u64, i_size_test, i_size_read(inode)); | 724 | new_i_size = min_t(u64, i_size_test, i_size); |
674 | } | 725 | } |
675 | BTRFS_I(inode)->disk_i_size = new_i_size; | 726 | BTRFS_I(inode)->disk_i_size = new_i_size; |
727 | ret = 0; | ||
676 | out: | 728 | out: |
729 | /* | ||
730 | * we need to remove the ordered extent with the tree lock held | ||
731 | * so that other people calling this function don't find our fully | ||
732 | * processed ordered entry and skip updating the i_size | ||
733 | */ | ||
734 | if (ordered) | ||
735 | __btrfs_remove_ordered_extent(inode, ordered); | ||
677 | mutex_unlock(&tree->mutex); | 736 | mutex_unlock(&tree->mutex); |
678 | return 0; | 737 | if (ordered) |
738 | wake_up(&ordered->wait); | ||
739 | return ret; | ||
679 | } | 740 | } |
680 | 741 | ||
681 | /* | 742 | /* |
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index f82e87488ca8..1fe1282ef47c 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h | |||
@@ -150,12 +150,13 @@ void btrfs_start_ordered_extent(struct inode *inode, | |||
150 | int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len); | 150 | int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len); |
151 | struct btrfs_ordered_extent * | 151 | struct btrfs_ordered_extent * |
152 | btrfs_lookup_first_ordered_extent(struct inode * inode, u64 file_offset); | 152 | btrfs_lookup_first_ordered_extent(struct inode * inode, u64 file_offset); |
153 | int btrfs_ordered_update_i_size(struct inode *inode, | 153 | int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, |
154 | struct btrfs_ordered_extent *ordered); | 154 | struct btrfs_ordered_extent *ordered); |
155 | int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, u32 *sum); | 155 | int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, u32 *sum); |
156 | int btrfs_wait_ordered_extents(struct btrfs_root *root, int nocow_only); | ||
157 | int btrfs_run_ordered_operations(struct btrfs_root *root, int wait); | 156 | int btrfs_run_ordered_operations(struct btrfs_root *root, int wait); |
158 | int btrfs_add_ordered_operation(struct btrfs_trans_handle *trans, | 157 | int btrfs_add_ordered_operation(struct btrfs_trans_handle *trans, |
159 | struct btrfs_root *root, | 158 | struct btrfs_root *root, |
160 | struct inode *inode); | 159 | struct inode *inode); |
160 | int btrfs_wait_ordered_extents(struct btrfs_root *root, | ||
161 | int nocow_only, int delay_iput); | ||
161 | #endif | 162 | #endif |
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index cfcc93c93a7b..a9728680eca8 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c | |||
@@ -1561,6 +1561,20 @@ static int invalidate_extent_cache(struct btrfs_root *root, | |||
1561 | return 0; | 1561 | return 0; |
1562 | } | 1562 | } |
1563 | 1563 | ||
1564 | static void put_inodes(struct list_head *list) | ||
1565 | { | ||
1566 | struct inodevec *ivec; | ||
1567 | while (!list_empty(list)) { | ||
1568 | ivec = list_entry(list->next, struct inodevec, list); | ||
1569 | list_del(&ivec->list); | ||
1570 | while (ivec->nr > 0) { | ||
1571 | ivec->nr--; | ||
1572 | iput(ivec->inode[ivec->nr]); | ||
1573 | } | ||
1574 | kfree(ivec); | ||
1575 | } | ||
1576 | } | ||
1577 | |||
1564 | static int find_next_key(struct btrfs_path *path, int level, | 1578 | static int find_next_key(struct btrfs_path *path, int level, |
1565 | struct btrfs_key *key) | 1579 | struct btrfs_key *key) |
1566 | 1580 | ||
@@ -1723,6 +1737,11 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc, | |||
1723 | 1737 | ||
1724 | btrfs_btree_balance_dirty(root, nr); | 1738 | btrfs_btree_balance_dirty(root, nr); |
1725 | 1739 | ||
1740 | /* | ||
1741 | * put inodes outside transaction, otherwise we may deadlock. | ||
1742 | */ | ||
1743 | put_inodes(&inode_list); | ||
1744 | |||
1726 | if (replaced && rc->stage == UPDATE_DATA_PTRS) | 1745 | if (replaced && rc->stage == UPDATE_DATA_PTRS) |
1727 | invalidate_extent_cache(root, &key, &next_key); | 1746 | invalidate_extent_cache(root, &key, &next_key); |
1728 | } | 1747 | } |
@@ -1752,19 +1771,7 @@ out: | |||
1752 | 1771 | ||
1753 | btrfs_btree_balance_dirty(root, nr); | 1772 | btrfs_btree_balance_dirty(root, nr); |
1754 | 1773 | ||
1755 | /* | 1774 | put_inodes(&inode_list); |
1756 | * put inodes while we aren't holding the tree locks | ||
1757 | */ | ||
1758 | while (!list_empty(&inode_list)) { | ||
1759 | struct inodevec *ivec; | ||
1760 | ivec = list_entry(inode_list.next, struct inodevec, list); | ||
1761 | list_del(&ivec->list); | ||
1762 | while (ivec->nr > 0) { | ||
1763 | ivec->nr--; | ||
1764 | iput(ivec->inode[ivec->nr]); | ||
1765 | } | ||
1766 | kfree(ivec); | ||
1767 | } | ||
1768 | 1775 | ||
1769 | if (replaced && rc->stage == UPDATE_DATA_PTRS) | 1776 | if (replaced && rc->stage == UPDATE_DATA_PTRS) |
1770 | invalidate_extent_cache(root, &key, &next_key); | 1777 | invalidate_extent_cache(root, &key, &next_key); |
@@ -3534,8 +3541,8 @@ int btrfs_relocate_block_group(struct btrfs_root *extent_root, u64 group_start) | |||
3534 | (unsigned long long)rc->block_group->key.objectid, | 3541 | (unsigned long long)rc->block_group->key.objectid, |
3535 | (unsigned long long)rc->block_group->flags); | 3542 | (unsigned long long)rc->block_group->flags); |
3536 | 3543 | ||
3537 | btrfs_start_delalloc_inodes(fs_info->tree_root); | 3544 | btrfs_start_delalloc_inodes(fs_info->tree_root, 0); |
3538 | btrfs_wait_ordered_extents(fs_info->tree_root, 0); | 3545 | btrfs_wait_ordered_extents(fs_info->tree_root, 0, 0); |
3539 | 3546 | ||
3540 | while (1) { | 3547 | while (1) { |
3541 | rc->extents_found = 0; | 3548 | rc->extents_found = 0; |
@@ -3755,6 +3762,7 @@ out: | |||
3755 | BTRFS_DATA_RELOC_TREE_OBJECTID); | 3762 | BTRFS_DATA_RELOC_TREE_OBJECTID); |
3756 | if (IS_ERR(fs_root)) | 3763 | if (IS_ERR(fs_root)) |
3757 | err = PTR_ERR(fs_root); | 3764 | err = PTR_ERR(fs_root); |
3765 | btrfs_orphan_cleanup(fs_root); | ||
3758 | } | 3766 | } |
3759 | return err; | 3767 | return err; |
3760 | } | 3768 | } |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 752a5463bf53..3f9b45704fcd 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -128,6 +128,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
128 | substring_t args[MAX_OPT_ARGS]; | 128 | substring_t args[MAX_OPT_ARGS]; |
129 | char *p, *num; | 129 | char *p, *num; |
130 | int intarg; | 130 | int intarg; |
131 | int ret = 0; | ||
131 | 132 | ||
132 | if (!options) | 133 | if (!options) |
133 | return 0; | 134 | return 0; |
@@ -262,12 +263,18 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
262 | case Opt_discard: | 263 | case Opt_discard: |
263 | btrfs_set_opt(info->mount_opt, DISCARD); | 264 | btrfs_set_opt(info->mount_opt, DISCARD); |
264 | break; | 265 | break; |
266 | case Opt_err: | ||
267 | printk(KERN_INFO "btrfs: unrecognized mount option " | ||
268 | "'%s'\n", p); | ||
269 | ret = -EINVAL; | ||
270 | goto out; | ||
265 | default: | 271 | default: |
266 | break; | 272 | break; |
267 | } | 273 | } |
268 | } | 274 | } |
275 | out: | ||
269 | kfree(options); | 276 | kfree(options); |
270 | return 0; | 277 | return ret; |
271 | } | 278 | } |
272 | 279 | ||
273 | /* | 280 | /* |
@@ -405,8 +412,8 @@ int btrfs_sync_fs(struct super_block *sb, int wait) | |||
405 | return 0; | 412 | return 0; |
406 | } | 413 | } |
407 | 414 | ||
408 | btrfs_start_delalloc_inodes(root); | 415 | btrfs_start_delalloc_inodes(root, 0); |
409 | btrfs_wait_ordered_extents(root, 0); | 416 | btrfs_wait_ordered_extents(root, 0, 0); |
410 | 417 | ||
411 | trans = btrfs_start_transaction(root, 1); | 418 | trans = btrfs_start_transaction(root, 1); |
412 | ret = btrfs_commit_transaction(trans, root); | 419 | ret = btrfs_commit_transaction(trans, root); |
@@ -450,6 +457,8 @@ static int btrfs_show_options(struct seq_file *seq, struct vfsmount *vfs) | |||
450 | seq_puts(seq, ",notreelog"); | 457 | seq_puts(seq, ",notreelog"); |
451 | if (btrfs_test_opt(root, FLUSHONCOMMIT)) | 458 | if (btrfs_test_opt(root, FLUSHONCOMMIT)) |
452 | seq_puts(seq, ",flushoncommit"); | 459 | seq_puts(seq, ",flushoncommit"); |
460 | if (btrfs_test_opt(root, DISCARD)) | ||
461 | seq_puts(seq, ",discard"); | ||
453 | if (!(root->fs_info->sb->s_flags & MS_POSIXACL)) | 462 | if (!(root->fs_info->sb->s_flags & MS_POSIXACL)) |
454 | seq_puts(seq, ",noacl"); | 463 | seq_puts(seq, ",noacl"); |
455 | return 0; | 464 | return 0; |
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index c207e8c32c9b..b2acc79f1b34 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -333,6 +333,9 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, | |||
333 | memset(trans, 0, sizeof(*trans)); | 333 | memset(trans, 0, sizeof(*trans)); |
334 | kmem_cache_free(btrfs_trans_handle_cachep, trans); | 334 | kmem_cache_free(btrfs_trans_handle_cachep, trans); |
335 | 335 | ||
336 | if (throttle) | ||
337 | btrfs_run_delayed_iputs(root); | ||
338 | |||
336 | return 0; | 339 | return 0; |
337 | } | 340 | } |
338 | 341 | ||
@@ -354,7 +357,7 @@ int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans, | |||
354 | * those extents are sent to disk but does not wait on them | 357 | * those extents are sent to disk but does not wait on them |
355 | */ | 358 | */ |
356 | int btrfs_write_marked_extents(struct btrfs_root *root, | 359 | int btrfs_write_marked_extents(struct btrfs_root *root, |
357 | struct extent_io_tree *dirty_pages) | 360 | struct extent_io_tree *dirty_pages, int mark) |
358 | { | 361 | { |
359 | int ret; | 362 | int ret; |
360 | int err = 0; | 363 | int err = 0; |
@@ -367,7 +370,7 @@ int btrfs_write_marked_extents(struct btrfs_root *root, | |||
367 | 370 | ||
368 | while (1) { | 371 | while (1) { |
369 | ret = find_first_extent_bit(dirty_pages, start, &start, &end, | 372 | ret = find_first_extent_bit(dirty_pages, start, &start, &end, |
370 | EXTENT_DIRTY); | 373 | mark); |
371 | if (ret) | 374 | if (ret) |
372 | break; | 375 | break; |
373 | while (start <= end) { | 376 | while (start <= end) { |
@@ -413,7 +416,7 @@ int btrfs_write_marked_extents(struct btrfs_root *root, | |||
413 | * on all the pages and clear them from the dirty pages state tree | 416 | * on all the pages and clear them from the dirty pages state tree |
414 | */ | 417 | */ |
415 | int btrfs_wait_marked_extents(struct btrfs_root *root, | 418 | int btrfs_wait_marked_extents(struct btrfs_root *root, |
416 | struct extent_io_tree *dirty_pages) | 419 | struct extent_io_tree *dirty_pages, int mark) |
417 | { | 420 | { |
418 | int ret; | 421 | int ret; |
419 | int err = 0; | 422 | int err = 0; |
@@ -425,12 +428,12 @@ int btrfs_wait_marked_extents(struct btrfs_root *root, | |||
425 | unsigned long index; | 428 | unsigned long index; |
426 | 429 | ||
427 | while (1) { | 430 | while (1) { |
428 | ret = find_first_extent_bit(dirty_pages, 0, &start, &end, | 431 | ret = find_first_extent_bit(dirty_pages, start, &start, &end, |
429 | EXTENT_DIRTY); | 432 | mark); |
430 | if (ret) | 433 | if (ret) |
431 | break; | 434 | break; |
432 | 435 | ||
433 | clear_extent_dirty(dirty_pages, start, end, GFP_NOFS); | 436 | clear_extent_bits(dirty_pages, start, end, mark, GFP_NOFS); |
434 | while (start <= end) { | 437 | while (start <= end) { |
435 | index = start >> PAGE_CACHE_SHIFT; | 438 | index = start >> PAGE_CACHE_SHIFT; |
436 | start = (u64)(index + 1) << PAGE_CACHE_SHIFT; | 439 | start = (u64)(index + 1) << PAGE_CACHE_SHIFT; |
@@ -460,13 +463,13 @@ int btrfs_wait_marked_extents(struct btrfs_root *root, | |||
460 | * those extents are on disk for transaction or log commit | 463 | * those extents are on disk for transaction or log commit |
461 | */ | 464 | */ |
462 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | 465 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, |
463 | struct extent_io_tree *dirty_pages) | 466 | struct extent_io_tree *dirty_pages, int mark) |
464 | { | 467 | { |
465 | int ret; | 468 | int ret; |
466 | int ret2; | 469 | int ret2; |
467 | 470 | ||
468 | ret = btrfs_write_marked_extents(root, dirty_pages); | 471 | ret = btrfs_write_marked_extents(root, dirty_pages, mark); |
469 | ret2 = btrfs_wait_marked_extents(root, dirty_pages); | 472 | ret2 = btrfs_wait_marked_extents(root, dirty_pages, mark); |
470 | return ret || ret2; | 473 | return ret || ret2; |
471 | } | 474 | } |
472 | 475 | ||
@@ -479,7 +482,8 @@ int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, | |||
479 | return filemap_write_and_wait(btree_inode->i_mapping); | 482 | return filemap_write_and_wait(btree_inode->i_mapping); |
480 | } | 483 | } |
481 | return btrfs_write_and_wait_marked_extents(root, | 484 | return btrfs_write_and_wait_marked_extents(root, |
482 | &trans->transaction->dirty_pages); | 485 | &trans->transaction->dirty_pages, |
486 | EXTENT_DIRTY); | ||
483 | } | 487 | } |
484 | 488 | ||
485 | /* | 489 | /* |
@@ -497,13 +501,16 @@ static int update_cowonly_root(struct btrfs_trans_handle *trans, | |||
497 | { | 501 | { |
498 | int ret; | 502 | int ret; |
499 | u64 old_root_bytenr; | 503 | u64 old_root_bytenr; |
504 | u64 old_root_used; | ||
500 | struct btrfs_root *tree_root = root->fs_info->tree_root; | 505 | struct btrfs_root *tree_root = root->fs_info->tree_root; |
501 | 506 | ||
507 | old_root_used = btrfs_root_used(&root->root_item); | ||
502 | btrfs_write_dirty_block_groups(trans, root); | 508 | btrfs_write_dirty_block_groups(trans, root); |
503 | 509 | ||
504 | while (1) { | 510 | while (1) { |
505 | old_root_bytenr = btrfs_root_bytenr(&root->root_item); | 511 | old_root_bytenr = btrfs_root_bytenr(&root->root_item); |
506 | if (old_root_bytenr == root->node->start) | 512 | if (old_root_bytenr == root->node->start && |
513 | old_root_used == btrfs_root_used(&root->root_item)) | ||
507 | break; | 514 | break; |
508 | 515 | ||
509 | btrfs_set_root_node(&root->root_item, root->node); | 516 | btrfs_set_root_node(&root->root_item, root->node); |
@@ -512,6 +519,7 @@ static int update_cowonly_root(struct btrfs_trans_handle *trans, | |||
512 | &root->root_item); | 519 | &root->root_item); |
513 | BUG_ON(ret); | 520 | BUG_ON(ret); |
514 | 521 | ||
522 | old_root_used = btrfs_root_used(&root->root_item); | ||
515 | ret = btrfs_write_dirty_block_groups(trans, root); | 523 | ret = btrfs_write_dirty_block_groups(trans, root); |
516 | BUG_ON(ret); | 524 | BUG_ON(ret); |
517 | } | 525 | } |
@@ -795,7 +803,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, | |||
795 | memcpy(&pending->root_key, &key, sizeof(key)); | 803 | memcpy(&pending->root_key, &key, sizeof(key)); |
796 | fail: | 804 | fail: |
797 | kfree(new_root_item); | 805 | kfree(new_root_item); |
798 | btrfs_unreserve_metadata_space(root, 6); | ||
799 | return ret; | 806 | return ret; |
800 | } | 807 | } |
801 | 808 | ||
@@ -807,7 +814,6 @@ static noinline int finish_pending_snapshot(struct btrfs_fs_info *fs_info, | |||
807 | u64 index = 0; | 814 | u64 index = 0; |
808 | struct btrfs_trans_handle *trans; | 815 | struct btrfs_trans_handle *trans; |
809 | struct inode *parent_inode; | 816 | struct inode *parent_inode; |
810 | struct inode *inode; | ||
811 | struct btrfs_root *parent_root; | 817 | struct btrfs_root *parent_root; |
812 | 818 | ||
813 | parent_inode = pending->dentry->d_parent->d_inode; | 819 | parent_inode = pending->dentry->d_parent->d_inode; |
@@ -839,8 +845,6 @@ static noinline int finish_pending_snapshot(struct btrfs_fs_info *fs_info, | |||
839 | 845 | ||
840 | BUG_ON(ret); | 846 | BUG_ON(ret); |
841 | 847 | ||
842 | inode = btrfs_lookup_dentry(parent_inode, pending->dentry); | ||
843 | d_instantiate(pending->dentry, inode); | ||
844 | fail: | 848 | fail: |
845 | btrfs_end_transaction(trans, fs_info->fs_root); | 849 | btrfs_end_transaction(trans, fs_info->fs_root); |
846 | return ret; | 850 | return ret; |
@@ -994,11 +998,11 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, | |||
994 | mutex_unlock(&root->fs_info->trans_mutex); | 998 | mutex_unlock(&root->fs_info->trans_mutex); |
995 | 999 | ||
996 | if (flush_on_commit) { | 1000 | if (flush_on_commit) { |
997 | btrfs_start_delalloc_inodes(root); | 1001 | btrfs_start_delalloc_inodes(root, 1); |
998 | ret = btrfs_wait_ordered_extents(root, 0); | 1002 | ret = btrfs_wait_ordered_extents(root, 0, 1); |
999 | BUG_ON(ret); | 1003 | BUG_ON(ret); |
1000 | } else if (snap_pending) { | 1004 | } else if (snap_pending) { |
1001 | ret = btrfs_wait_ordered_extents(root, 1); | 1005 | ret = btrfs_wait_ordered_extents(root, 0, 1); |
1002 | BUG_ON(ret); | 1006 | BUG_ON(ret); |
1003 | } | 1007 | } |
1004 | 1008 | ||
@@ -1116,6 +1120,10 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, | |||
1116 | current->journal_info = NULL; | 1120 | current->journal_info = NULL; |
1117 | 1121 | ||
1118 | kmem_cache_free(btrfs_trans_handle_cachep, trans); | 1122 | kmem_cache_free(btrfs_trans_handle_cachep, trans); |
1123 | |||
1124 | if (current != root->fs_info->transaction_kthread) | ||
1125 | btrfs_run_delayed_iputs(root); | ||
1126 | |||
1119 | return ret; | 1127 | return ret; |
1120 | } | 1128 | } |
1121 | 1129 | ||
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index d4e3e7a6938c..93c7ccb33118 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h | |||
@@ -107,10 +107,10 @@ void btrfs_throttle(struct btrfs_root *root); | |||
107 | int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, | 107 | int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, |
108 | struct btrfs_root *root); | 108 | struct btrfs_root *root); |
109 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, | 109 | int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, |
110 | struct extent_io_tree *dirty_pages); | 110 | struct extent_io_tree *dirty_pages, int mark); |
111 | int btrfs_write_marked_extents(struct btrfs_root *root, | 111 | int btrfs_write_marked_extents(struct btrfs_root *root, |
112 | struct extent_io_tree *dirty_pages); | 112 | struct extent_io_tree *dirty_pages, int mark); |
113 | int btrfs_wait_marked_extents(struct btrfs_root *root, | 113 | int btrfs_wait_marked_extents(struct btrfs_root *root, |
114 | struct extent_io_tree *dirty_pages); | 114 | struct extent_io_tree *dirty_pages, int mark); |
115 | int btrfs_transaction_in_commit(struct btrfs_fs_info *info); | 115 | int btrfs_transaction_in_commit(struct btrfs_fs_info *info); |
116 | #endif | 116 | #endif |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 741666a7676a..4a9434b622ec 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -542,8 +542,8 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
542 | 542 | ||
543 | saved_nbytes = inode_get_bytes(inode); | 543 | saved_nbytes = inode_get_bytes(inode); |
544 | /* drop any overlapping extents */ | 544 | /* drop any overlapping extents */ |
545 | ret = btrfs_drop_extents(trans, root, inode, | 545 | ret = btrfs_drop_extents(trans, inode, start, extent_end, |
546 | start, extent_end, extent_end, start, &alloc_hint, 1); | 546 | &alloc_hint, 1); |
547 | BUG_ON(ret); | 547 | BUG_ON(ret); |
548 | 548 | ||
549 | if (found_type == BTRFS_FILE_EXTENT_REG || | 549 | if (found_type == BTRFS_FILE_EXTENT_REG || |
@@ -930,6 +930,17 @@ out_nowrite: | |||
930 | return 0; | 930 | return 0; |
931 | } | 931 | } |
932 | 932 | ||
933 | static int insert_orphan_item(struct btrfs_trans_handle *trans, | ||
934 | struct btrfs_root *root, u64 offset) | ||
935 | { | ||
936 | int ret; | ||
937 | ret = btrfs_find_orphan_item(root, offset); | ||
938 | if (ret > 0) | ||
939 | ret = btrfs_insert_orphan_item(trans, root, offset); | ||
940 | return ret; | ||
941 | } | ||
942 | |||
943 | |||
933 | /* | 944 | /* |
934 | * There are a few corners where the link count of the file can't | 945 | * There are a few corners where the link count of the file can't |
935 | * be properly maintained during replay. So, instead of adding | 946 | * be properly maintained during replay. So, instead of adding |
@@ -997,9 +1008,13 @@ static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans, | |||
997 | } | 1008 | } |
998 | BTRFS_I(inode)->index_cnt = (u64)-1; | 1009 | BTRFS_I(inode)->index_cnt = (u64)-1; |
999 | 1010 | ||
1000 | if (inode->i_nlink == 0 && S_ISDIR(inode->i_mode)) { | 1011 | if (inode->i_nlink == 0) { |
1001 | ret = replay_dir_deletes(trans, root, NULL, path, | 1012 | if (S_ISDIR(inode->i_mode)) { |
1002 | inode->i_ino, 1); | 1013 | ret = replay_dir_deletes(trans, root, NULL, path, |
1014 | inode->i_ino, 1); | ||
1015 | BUG_ON(ret); | ||
1016 | } | ||
1017 | ret = insert_orphan_item(trans, root, inode->i_ino); | ||
1003 | BUG_ON(ret); | 1018 | BUG_ON(ret); |
1004 | } | 1019 | } |
1005 | btrfs_free_path(path); | 1020 | btrfs_free_path(path); |
@@ -1587,7 +1602,6 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb, | |||
1587 | /* inode keys are done during the first stage */ | 1602 | /* inode keys are done during the first stage */ |
1588 | if (key.type == BTRFS_INODE_ITEM_KEY && | 1603 | if (key.type == BTRFS_INODE_ITEM_KEY && |
1589 | wc->stage == LOG_WALK_REPLAY_INODES) { | 1604 | wc->stage == LOG_WALK_REPLAY_INODES) { |
1590 | struct inode *inode; | ||
1591 | struct btrfs_inode_item *inode_item; | 1605 | struct btrfs_inode_item *inode_item; |
1592 | u32 mode; | 1606 | u32 mode; |
1593 | 1607 | ||
@@ -1603,31 +1617,16 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb, | |||
1603 | eb, i, &key); | 1617 | eb, i, &key); |
1604 | BUG_ON(ret); | 1618 | BUG_ON(ret); |
1605 | 1619 | ||
1606 | /* for regular files, truncate away | 1620 | /* for regular files, make sure corresponding |
1607 | * extents past the new EOF | 1621 | * orhpan item exist. extents past the new EOF |
1622 | * will be truncated later by orphan cleanup. | ||
1608 | */ | 1623 | */ |
1609 | if (S_ISREG(mode)) { | 1624 | if (S_ISREG(mode)) { |
1610 | inode = read_one_inode(root, | 1625 | ret = insert_orphan_item(wc->trans, root, |
1611 | key.objectid); | 1626 | key.objectid); |
1612 | BUG_ON(!inode); | ||
1613 | |||
1614 | ret = btrfs_truncate_inode_items(wc->trans, | ||
1615 | root, inode, inode->i_size, | ||
1616 | BTRFS_EXTENT_DATA_KEY); | ||
1617 | BUG_ON(ret); | 1627 | BUG_ON(ret); |
1618 | |||
1619 | /* if the nlink count is zero here, the iput | ||
1620 | * will free the inode. We bump it to make | ||
1621 | * sure it doesn't get freed until the link | ||
1622 | * count fixup is done | ||
1623 | */ | ||
1624 | if (inode->i_nlink == 0) { | ||
1625 | btrfs_inc_nlink(inode); | ||
1626 | btrfs_update_inode(wc->trans, | ||
1627 | root, inode); | ||
1628 | } | ||
1629 | iput(inode); | ||
1630 | } | 1628 | } |
1629 | |||
1631 | ret = link_to_fixup_dir(wc->trans, root, | 1630 | ret = link_to_fixup_dir(wc->trans, root, |
1632 | path, key.objectid); | 1631 | path, key.objectid); |
1633 | BUG_ON(ret); | 1632 | BUG_ON(ret); |
@@ -1977,10 +1976,11 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
1977 | { | 1976 | { |
1978 | int index1; | 1977 | int index1; |
1979 | int index2; | 1978 | int index2; |
1979 | int mark; | ||
1980 | int ret; | 1980 | int ret; |
1981 | struct btrfs_root *log = root->log_root; | 1981 | struct btrfs_root *log = root->log_root; |
1982 | struct btrfs_root *log_root_tree = root->fs_info->log_root_tree; | 1982 | struct btrfs_root *log_root_tree = root->fs_info->log_root_tree; |
1983 | u64 log_transid = 0; | 1983 | unsigned long log_transid = 0; |
1984 | 1984 | ||
1985 | mutex_lock(&root->log_mutex); | 1985 | mutex_lock(&root->log_mutex); |
1986 | index1 = root->log_transid % 2; | 1986 | index1 = root->log_transid % 2; |
@@ -2014,24 +2014,29 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2014 | goto out; | 2014 | goto out; |
2015 | } | 2015 | } |
2016 | 2016 | ||
2017 | log_transid = root->log_transid; | ||
2018 | if (log_transid % 2 == 0) | ||
2019 | mark = EXTENT_DIRTY; | ||
2020 | else | ||
2021 | mark = EXTENT_NEW; | ||
2022 | |||
2017 | /* we start IO on all the marked extents here, but we don't actually | 2023 | /* we start IO on all the marked extents here, but we don't actually |
2018 | * wait for them until later. | 2024 | * wait for them until later. |
2019 | */ | 2025 | */ |
2020 | ret = btrfs_write_marked_extents(log, &log->dirty_log_pages); | 2026 | ret = btrfs_write_marked_extents(log, &log->dirty_log_pages, mark); |
2021 | BUG_ON(ret); | 2027 | BUG_ON(ret); |
2022 | 2028 | ||
2023 | btrfs_set_root_node(&log->root_item, log->node); | 2029 | btrfs_set_root_node(&log->root_item, log->node); |
2024 | 2030 | ||
2025 | root->log_batch = 0; | 2031 | root->log_batch = 0; |
2026 | log_transid = root->log_transid; | ||
2027 | root->log_transid++; | 2032 | root->log_transid++; |
2028 | log->log_transid = root->log_transid; | 2033 | log->log_transid = root->log_transid; |
2029 | root->log_start_pid = 0; | 2034 | root->log_start_pid = 0; |
2030 | smp_mb(); | 2035 | smp_mb(); |
2031 | /* | 2036 | /* |
2032 | * log tree has been flushed to disk, new modifications of | 2037 | * IO has been started, blocks of the log tree have WRITTEN flag set |
2033 | * the log will be written to new positions. so it's safe to | 2038 | * in their headers. new modifications of the log will be written to |
2034 | * allow log writers to go in. | 2039 | * new positions. so it's safe to allow log writers to go in. |
2035 | */ | 2040 | */ |
2036 | mutex_unlock(&root->log_mutex); | 2041 | mutex_unlock(&root->log_mutex); |
2037 | 2042 | ||
@@ -2052,7 +2057,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2052 | 2057 | ||
2053 | index2 = log_root_tree->log_transid % 2; | 2058 | index2 = log_root_tree->log_transid % 2; |
2054 | if (atomic_read(&log_root_tree->log_commit[index2])) { | 2059 | if (atomic_read(&log_root_tree->log_commit[index2])) { |
2055 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | 2060 | btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); |
2056 | wait_log_commit(trans, log_root_tree, | 2061 | wait_log_commit(trans, log_root_tree, |
2057 | log_root_tree->log_transid); | 2062 | log_root_tree->log_transid); |
2058 | mutex_unlock(&log_root_tree->log_mutex); | 2063 | mutex_unlock(&log_root_tree->log_mutex); |
@@ -2072,16 +2077,17 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2072 | * check the full commit flag again | 2077 | * check the full commit flag again |
2073 | */ | 2078 | */ |
2074 | if (root->fs_info->last_trans_log_full_commit == trans->transid) { | 2079 | if (root->fs_info->last_trans_log_full_commit == trans->transid) { |
2075 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | 2080 | btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); |
2076 | mutex_unlock(&log_root_tree->log_mutex); | 2081 | mutex_unlock(&log_root_tree->log_mutex); |
2077 | ret = -EAGAIN; | 2082 | ret = -EAGAIN; |
2078 | goto out_wake_log_root; | 2083 | goto out_wake_log_root; |
2079 | } | 2084 | } |
2080 | 2085 | ||
2081 | ret = btrfs_write_and_wait_marked_extents(log_root_tree, | 2086 | ret = btrfs_write_and_wait_marked_extents(log_root_tree, |
2082 | &log_root_tree->dirty_log_pages); | 2087 | &log_root_tree->dirty_log_pages, |
2088 | EXTENT_DIRTY | EXTENT_NEW); | ||
2083 | BUG_ON(ret); | 2089 | BUG_ON(ret); |
2084 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | 2090 | btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); |
2085 | 2091 | ||
2086 | btrfs_set_super_log_root(&root->fs_info->super_for_commit, | 2092 | btrfs_set_super_log_root(&root->fs_info->super_for_commit, |
2087 | log_root_tree->node->start); | 2093 | log_root_tree->node->start); |
@@ -2147,12 +2153,12 @@ int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root) | |||
2147 | 2153 | ||
2148 | while (1) { | 2154 | while (1) { |
2149 | ret = find_first_extent_bit(&log->dirty_log_pages, | 2155 | ret = find_first_extent_bit(&log->dirty_log_pages, |
2150 | 0, &start, &end, EXTENT_DIRTY); | 2156 | 0, &start, &end, EXTENT_DIRTY | EXTENT_NEW); |
2151 | if (ret) | 2157 | if (ret) |
2152 | break; | 2158 | break; |
2153 | 2159 | ||
2154 | clear_extent_dirty(&log->dirty_log_pages, | 2160 | clear_extent_bits(&log->dirty_log_pages, start, end, |
2155 | start, end, GFP_NOFS); | 2161 | EXTENT_DIRTY | EXTENT_NEW, GFP_NOFS); |
2156 | } | 2162 | } |
2157 | 2163 | ||
2158 | if (log->log_transid > 0) { | 2164 | if (log->log_transid > 0) { |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 7eda483d7b5a..198cff28766d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -2209,7 +2209,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, | |||
2209 | max_chunk_size = 10 * calc_size; | 2209 | max_chunk_size = 10 * calc_size; |
2210 | min_stripe_size = 64 * 1024 * 1024; | 2210 | min_stripe_size = 64 * 1024 * 1024; |
2211 | } else if (type & BTRFS_BLOCK_GROUP_METADATA) { | 2211 | } else if (type & BTRFS_BLOCK_GROUP_METADATA) { |
2212 | max_chunk_size = 4 * calc_size; | 2212 | max_chunk_size = 256 * 1024 * 1024; |
2213 | min_stripe_size = 32 * 1024 * 1024; | 2213 | min_stripe_size = 32 * 1024 * 1024; |
2214 | } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) { | 2214 | } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) { |
2215 | calc_size = 8 * 1024 * 1024; | 2215 | calc_size = 8 * 1024 * 1024; |
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c index b6dd5967c48a..193b58f7d3f3 100644 --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c | |||
@@ -85,22 +85,23 @@ out: | |||
85 | return ret; | 85 | return ret; |
86 | } | 86 | } |
87 | 87 | ||
88 | int __btrfs_setxattr(struct inode *inode, const char *name, | 88 | static int do_setxattr(struct btrfs_trans_handle *trans, |
89 | const void *value, size_t size, int flags) | 89 | struct inode *inode, const char *name, |
90 | const void *value, size_t size, int flags) | ||
90 | { | 91 | { |
91 | struct btrfs_dir_item *di; | 92 | struct btrfs_dir_item *di; |
92 | struct btrfs_root *root = BTRFS_I(inode)->root; | 93 | struct btrfs_root *root = BTRFS_I(inode)->root; |
93 | struct btrfs_trans_handle *trans; | ||
94 | struct btrfs_path *path; | 94 | struct btrfs_path *path; |
95 | int ret = 0, mod = 0; | 95 | size_t name_len = strlen(name); |
96 | int ret = 0; | ||
97 | |||
98 | if (name_len + size > BTRFS_MAX_XATTR_SIZE(root)) | ||
99 | return -ENOSPC; | ||
96 | 100 | ||
97 | path = btrfs_alloc_path(); | 101 | path = btrfs_alloc_path(); |
98 | if (!path) | 102 | if (!path) |
99 | return -ENOMEM; | 103 | return -ENOMEM; |
100 | 104 | ||
101 | trans = btrfs_join_transaction(root, 1); | ||
102 | btrfs_set_trans_block_group(trans, inode); | ||
103 | |||
104 | /* first lets see if we already have this xattr */ | 105 | /* first lets see if we already have this xattr */ |
105 | di = btrfs_lookup_xattr(trans, root, path, inode->i_ino, name, | 106 | di = btrfs_lookup_xattr(trans, root, path, inode->i_ino, name, |
106 | strlen(name), -1); | 107 | strlen(name), -1); |
@@ -118,15 +119,12 @@ int __btrfs_setxattr(struct inode *inode, const char *name, | |||
118 | } | 119 | } |
119 | 120 | ||
120 | ret = btrfs_delete_one_dir_name(trans, root, path, di); | 121 | ret = btrfs_delete_one_dir_name(trans, root, path, di); |
121 | if (ret) | 122 | BUG_ON(ret); |
122 | goto out; | ||
123 | btrfs_release_path(root, path); | 123 | btrfs_release_path(root, path); |
124 | 124 | ||
125 | /* if we don't have a value then we are removing the xattr */ | 125 | /* if we don't have a value then we are removing the xattr */ |
126 | if (!value) { | 126 | if (!value) |
127 | mod = 1; | ||
128 | goto out; | 127 | goto out; |
129 | } | ||
130 | } else { | 128 | } else { |
131 | btrfs_release_path(root, path); | 129 | btrfs_release_path(root, path); |
132 | 130 | ||
@@ -138,20 +136,45 @@ int __btrfs_setxattr(struct inode *inode, const char *name, | |||
138 | } | 136 | } |
139 | 137 | ||
140 | /* ok we have to create a completely new xattr */ | 138 | /* ok we have to create a completely new xattr */ |
141 | ret = btrfs_insert_xattr_item(trans, root, name, strlen(name), | 139 | ret = btrfs_insert_xattr_item(trans, root, path, inode->i_ino, |
142 | value, size, inode->i_ino); | 140 | name, name_len, value, size); |
141 | BUG_ON(ret); | ||
142 | out: | ||
143 | btrfs_free_path(path); | ||
144 | return ret; | ||
145 | } | ||
146 | |||
147 | int __btrfs_setxattr(struct btrfs_trans_handle *trans, | ||
148 | struct inode *inode, const char *name, | ||
149 | const void *value, size_t size, int flags) | ||
150 | { | ||
151 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
152 | int ret; | ||
153 | |||
154 | if (trans) | ||
155 | return do_setxattr(trans, inode, name, value, size, flags); | ||
156 | |||
157 | ret = btrfs_reserve_metadata_space(root, 2); | ||
143 | if (ret) | 158 | if (ret) |
144 | goto out; | 159 | return ret; |
145 | mod = 1; | ||
146 | 160 | ||
147 | out: | 161 | trans = btrfs_start_transaction(root, 1); |
148 | if (mod) { | 162 | if (!trans) { |
149 | inode->i_ctime = CURRENT_TIME; | 163 | ret = -ENOMEM; |
150 | ret = btrfs_update_inode(trans, root, inode); | 164 | goto out; |
151 | } | 165 | } |
166 | btrfs_set_trans_block_group(trans, inode); | ||
152 | 167 | ||
153 | btrfs_end_transaction(trans, root); | 168 | ret = do_setxattr(trans, inode, name, value, size, flags); |
154 | btrfs_free_path(path); | 169 | if (ret) |
170 | goto out; | ||
171 | |||
172 | inode->i_ctime = CURRENT_TIME; | ||
173 | ret = btrfs_update_inode(trans, root, inode); | ||
174 | BUG_ON(ret); | ||
175 | out: | ||
176 | btrfs_end_transaction_throttle(trans, root); | ||
177 | btrfs_unreserve_metadata_space(root, 2); | ||
155 | return ret; | 178 | return ret; |
156 | } | 179 | } |
157 | 180 | ||
@@ -314,7 +337,9 @@ int btrfs_setxattr(struct dentry *dentry, const char *name, const void *value, | |||
314 | 337 | ||
315 | if (size == 0) | 338 | if (size == 0) |
316 | value = ""; /* empty EA, do not remove */ | 339 | value = ""; /* empty EA, do not remove */ |
317 | return __btrfs_setxattr(dentry->d_inode, name, value, size, flags); | 340 | |
341 | return __btrfs_setxattr(NULL, dentry->d_inode, name, value, size, | ||
342 | flags); | ||
318 | } | 343 | } |
319 | 344 | ||
320 | int btrfs_removexattr(struct dentry *dentry, const char *name) | 345 | int btrfs_removexattr(struct dentry *dentry, const char *name) |
@@ -329,10 +354,13 @@ int btrfs_removexattr(struct dentry *dentry, const char *name) | |||
329 | 354 | ||
330 | if (!btrfs_is_valid_xattr(name)) | 355 | if (!btrfs_is_valid_xattr(name)) |
331 | return -EOPNOTSUPP; | 356 | return -EOPNOTSUPP; |
332 | return __btrfs_setxattr(dentry->d_inode, name, NULL, 0, XATTR_REPLACE); | 357 | |
358 | return __btrfs_setxattr(NULL, dentry->d_inode, name, NULL, 0, | ||
359 | XATTR_REPLACE); | ||
333 | } | 360 | } |
334 | 361 | ||
335 | int btrfs_xattr_security_init(struct inode *inode, struct inode *dir) | 362 | int btrfs_xattr_security_init(struct btrfs_trans_handle *trans, |
363 | struct inode *inode, struct inode *dir) | ||
336 | { | 364 | { |
337 | int err; | 365 | int err; |
338 | size_t len; | 366 | size_t len; |
@@ -354,7 +382,7 @@ int btrfs_xattr_security_init(struct inode *inode, struct inode *dir) | |||
354 | } else { | 382 | } else { |
355 | strcpy(name, XATTR_SECURITY_PREFIX); | 383 | strcpy(name, XATTR_SECURITY_PREFIX); |
356 | strcpy(name + XATTR_SECURITY_PREFIX_LEN, suffix); | 384 | strcpy(name + XATTR_SECURITY_PREFIX_LEN, suffix); |
357 | err = __btrfs_setxattr(inode, name, value, len, 0); | 385 | err = __btrfs_setxattr(trans, inode, name, value, len, 0); |
358 | kfree(name); | 386 | kfree(name); |
359 | } | 387 | } |
360 | 388 | ||
diff --git a/fs/btrfs/xattr.h b/fs/btrfs/xattr.h index c71e9c3cf3f7..721efa0346e0 100644 --- a/fs/btrfs/xattr.h +++ b/fs/btrfs/xattr.h | |||
@@ -27,15 +27,16 @@ extern struct xattr_handler *btrfs_xattr_handlers[]; | |||
27 | 27 | ||
28 | extern ssize_t __btrfs_getxattr(struct inode *inode, const char *name, | 28 | extern ssize_t __btrfs_getxattr(struct inode *inode, const char *name, |
29 | void *buffer, size_t size); | 29 | void *buffer, size_t size); |
30 | extern int __btrfs_setxattr(struct inode *inode, const char *name, | 30 | extern int __btrfs_setxattr(struct btrfs_trans_handle *trans, |
31 | const void *value, size_t size, int flags); | 31 | struct inode *inode, const char *name, |
32 | 32 | const void *value, size_t size, int flags); | |
33 | extern ssize_t btrfs_getxattr(struct dentry *dentry, const char *name, | 33 | extern ssize_t btrfs_getxattr(struct dentry *dentry, const char *name, |
34 | void *buffer, size_t size); | 34 | void *buffer, size_t size); |
35 | extern int btrfs_setxattr(struct dentry *dentry, const char *name, | 35 | extern int btrfs_setxattr(struct dentry *dentry, const char *name, |
36 | const void *value, size_t size, int flags); | 36 | const void *value, size_t size, int flags); |
37 | extern int btrfs_removexattr(struct dentry *dentry, const char *name); | 37 | extern int btrfs_removexattr(struct dentry *dentry, const char *name); |
38 | 38 | ||
39 | extern int btrfs_xattr_security_init(struct inode *inode, struct inode *dir); | 39 | extern int btrfs_xattr_security_init(struct btrfs_trans_handle *trans, |
40 | struct inode *inode, struct inode *dir); | ||
40 | 41 | ||
41 | #endif /* __XATTR__ */ | 42 | #endif /* __XATTR__ */ |
diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES index 094ea65afc85..7b2600b380d7 100644 --- a/fs/cifs/CHANGES +++ b/fs/cifs/CHANGES | |||
@@ -5,7 +5,9 @@ have duplicated data). Fix oops in cifs_lookup. Workaround problem | |||
5 | mounting to OS/400 Netserve. Fix oops in cifs_get_tcp_session. | 5 | mounting to OS/400 Netserve. Fix oops in cifs_get_tcp_session. |
6 | Disable use of server inode numbers when server only | 6 | Disable use of server inode numbers when server only |
7 | partially supports them (e.g. for one server querying inode numbers on | 7 | partially supports them (e.g. for one server querying inode numbers on |
8 | FindFirst fails but QPathInfo queries works). | 8 | FindFirst fails but QPathInfo queries works). Fix oops with dfs in |
9 | cifs_put_smb_ses. Fix mmap to work on directio mounts (needed | ||
10 | for OpenOffice when on forcedirectio mount e.g.) | ||
9 | 11 | ||
10 | Version 1.60 | 12 | Version 1.60 |
11 | ------------- | 13 | ------------- |
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 29f1da761bbf..8c6a03627176 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c | |||
@@ -758,7 +758,7 @@ const struct file_operations cifs_file_ops = { | |||
758 | }; | 758 | }; |
759 | 759 | ||
760 | const struct file_operations cifs_file_direct_ops = { | 760 | const struct file_operations cifs_file_direct_ops = { |
761 | /* no mmap, no aio, no readv - | 761 | /* no aio, no readv - |
762 | BB reevaluate whether they can be done with directio, no cache */ | 762 | BB reevaluate whether they can be done with directio, no cache */ |
763 | .read = cifs_user_read, | 763 | .read = cifs_user_read, |
764 | .write = cifs_user_write, | 764 | .write = cifs_user_write, |
@@ -767,6 +767,7 @@ const struct file_operations cifs_file_direct_ops = { | |||
767 | .lock = cifs_lock, | 767 | .lock = cifs_lock, |
768 | .fsync = cifs_fsync, | 768 | .fsync = cifs_fsync, |
769 | .flush = cifs_flush, | 769 | .flush = cifs_flush, |
770 | .mmap = cifs_file_mmap, | ||
770 | .splice_read = generic_file_splice_read, | 771 | .splice_read = generic_file_splice_read, |
771 | #ifdef CONFIG_CIFS_POSIX | 772 | #ifdef CONFIG_CIFS_POSIX |
772 | .unlocked_ioctl = cifs_ioctl, | 773 | .unlocked_ioctl = cifs_ioctl, |
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 63ea83ff687f..3bbcaa716b3c 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -2287,12 +2287,12 @@ int | |||
2287 | cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, | 2287 | cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, |
2288 | char *mount_data_global, const char *devname) | 2288 | char *mount_data_global, const char *devname) |
2289 | { | 2289 | { |
2290 | int rc = 0; | 2290 | int rc; |
2291 | int xid; | 2291 | int xid; |
2292 | struct smb_vol *volume_info; | 2292 | struct smb_vol *volume_info; |
2293 | struct cifsSesInfo *pSesInfo = NULL; | 2293 | struct cifsSesInfo *pSesInfo; |
2294 | struct cifsTconInfo *tcon = NULL; | 2294 | struct cifsTconInfo *tcon; |
2295 | struct TCP_Server_Info *srvTcp = NULL; | 2295 | struct TCP_Server_Info *srvTcp; |
2296 | char *full_path; | 2296 | char *full_path; |
2297 | char *mount_data = mount_data_global; | 2297 | char *mount_data = mount_data_global; |
2298 | #ifdef CONFIG_CIFS_DFS_UPCALL | 2298 | #ifdef CONFIG_CIFS_DFS_UPCALL |
@@ -2301,6 +2301,10 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, | |||
2301 | int referral_walks_count = 0; | 2301 | int referral_walks_count = 0; |
2302 | try_mount_again: | 2302 | try_mount_again: |
2303 | #endif | 2303 | #endif |
2304 | rc = 0; | ||
2305 | tcon = NULL; | ||
2306 | pSesInfo = NULL; | ||
2307 | srvTcp = NULL; | ||
2304 | full_path = NULL; | 2308 | full_path = NULL; |
2305 | 2309 | ||
2306 | xid = GetXid(); | 2310 | xid = GetXid(); |
@@ -2597,6 +2601,7 @@ remote_path_check: | |||
2597 | 2601 | ||
2598 | cleanup_volume_info(&volume_info); | 2602 | cleanup_volume_info(&volume_info); |
2599 | referral_walks_count++; | 2603 | referral_walks_count++; |
2604 | FreeXid(xid); | ||
2600 | goto try_mount_again; | 2605 | goto try_mount_again; |
2601 | } | 2606 | } |
2602 | #else /* No DFS support, return error on mount */ | 2607 | #else /* No DFS support, return error on mount */ |
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c index 14cbc831422a..332dd00f0894 100644 --- a/fs/compat_ioctl.c +++ b/fs/compat_ioctl.c | |||
@@ -1600,8 +1600,6 @@ static long do_ioctl_trans(int fd, unsigned int cmd, | |||
1600 | case KDSKBMETA: | 1600 | case KDSKBMETA: |
1601 | case KDSKBLED: | 1601 | case KDSKBLED: |
1602 | case KDSETLED: | 1602 | case KDSETLED: |
1603 | /* SG stuff */ | ||
1604 | case SG_SET_TRANSFORM: | ||
1605 | /* AUTOFS */ | 1603 | /* AUTOFS */ |
1606 | case AUTOFS_IOC_READY: | 1604 | case AUTOFS_IOC_READY: |
1607 | case AUTOFS_IOC_FAIL: | 1605 | case AUTOFS_IOC_FAIL: |
diff --git a/fs/direct-io.c b/fs/direct-io.c index 4012885d027f..e82adc2debb7 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c | |||
@@ -1206,7 +1206,7 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | |||
1206 | * NOTE: filesystems with their own locking have to handle this | 1206 | * NOTE: filesystems with their own locking have to handle this |
1207 | * on their own. | 1207 | * on their own. |
1208 | */ | 1208 | */ |
1209 | if (dio->flags & DIO_LOCKING) { | 1209 | if (flags & DIO_LOCKING) { |
1210 | if (unlikely((rw & WRITE) && retval < 0)) { | 1210 | if (unlikely((rw & WRITE) && retval < 0)) { |
1211 | loff_t isize = i_size_read(inode); | 1211 | loff_t isize = i_size_read(inode); |
1212 | if (end > isize) | 1212 | if (end > isize) |
diff --git a/fs/ecryptfs/dentry.c b/fs/ecryptfs/dentry.c index 2dda5ade75bc..8f006a0d6076 100644 --- a/fs/ecryptfs/dentry.c +++ b/fs/ecryptfs/dentry.c | |||
@@ -62,7 +62,7 @@ static int ecryptfs_d_revalidate(struct dentry *dentry, struct nameidata *nd) | |||
62 | struct inode *lower_inode = | 62 | struct inode *lower_inode = |
63 | ecryptfs_inode_to_lower(dentry->d_inode); | 63 | ecryptfs_inode_to_lower(dentry->d_inode); |
64 | 64 | ||
65 | fsstack_copy_attr_all(dentry->d_inode, lower_inode, NULL); | 65 | fsstack_copy_attr_all(dentry->d_inode, lower_inode); |
66 | } | 66 | } |
67 | out: | 67 | out: |
68 | return rc; | 68 | return rc; |
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 056fed62d0de..429ca0b3ba08 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -626,9 +626,9 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
626 | lower_new_dir_dentry->d_inode, lower_new_dentry); | 626 | lower_new_dir_dentry->d_inode, lower_new_dentry); |
627 | if (rc) | 627 | if (rc) |
628 | goto out_lock; | 628 | goto out_lock; |
629 | fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode, NULL); | 629 | fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode); |
630 | if (new_dir != old_dir) | 630 | if (new_dir != old_dir) |
631 | fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode, NULL); | 631 | fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); |
632 | out_lock: | 632 | out_lock: |
633 | unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); | 633 | unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); |
634 | dput(lower_new_dentry->d_parent); | 634 | dput(lower_new_dentry->d_parent); |
@@ -967,7 +967,7 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
967 | rc = notify_change(lower_dentry, ia); | 967 | rc = notify_change(lower_dentry, ia); |
968 | mutex_unlock(&lower_dentry->d_inode->i_mutex); | 968 | mutex_unlock(&lower_dentry->d_inode->i_mutex); |
969 | out: | 969 | out: |
970 | fsstack_copy_attr_all(inode, lower_inode, NULL); | 970 | fsstack_copy_attr_all(inode, lower_inode); |
971 | return rc; | 971 | return rc; |
972 | } | 972 | } |
973 | 973 | ||
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index 101fe4c7b1ee..567bc4b9f70a 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c | |||
@@ -189,7 +189,7 @@ int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry, | |||
189 | init_special_inode(inode, lower_inode->i_mode, | 189 | init_special_inode(inode, lower_inode->i_mode, |
190 | lower_inode->i_rdev); | 190 | lower_inode->i_rdev); |
191 | dentry->d_op = &ecryptfs_dops; | 191 | dentry->d_op = &ecryptfs_dops; |
192 | fsstack_copy_attr_all(inode, lower_inode, NULL); | 192 | fsstack_copy_attr_all(inode, lower_inode); |
193 | /* This size will be overwritten for real files w/ headers and | 193 | /* This size will be overwritten for real files w/ headers and |
194 | * other metadata */ | 194 | * other metadata */ |
195 | fsstack_copy_inode_size(inode, lower_inode); | 195 | fsstack_copy_inode_size(inode, lower_inode); |
diff --git a/fs/eventfd.c b/fs/eventfd.c index 8b47e4200e65..d26402ff06ea 100644 --- a/fs/eventfd.c +++ b/fs/eventfd.c | |||
@@ -339,7 +339,7 @@ struct file *eventfd_file_create(unsigned int count, int flags) | |||
339 | ctx->flags = flags; | 339 | ctx->flags = flags; |
340 | 340 | ||
341 | file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx, | 341 | file = anon_inode_getfile("[eventfd]", &eventfd_fops, ctx, |
342 | flags & EFD_SHARED_FCNTL_FLAGS); | 342 | O_RDWR | (flags & EFD_SHARED_FCNTL_FLAGS)); |
343 | if (IS_ERR(file)) | 343 | if (IS_ERR(file)) |
344 | eventfd_free_ctx(ctx); | 344 | eventfd_free_ctx(ctx); |
345 | 345 | ||
diff --git a/fs/eventpoll.c b/fs/eventpoll.c index 366c503f9657..bd056a5b4efc 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c | |||
@@ -1206,7 +1206,7 @@ SYSCALL_DEFINE1(epoll_create1, int, flags) | |||
1206 | * a file structure and a free file descriptor. | 1206 | * a file structure and a free file descriptor. |
1207 | */ | 1207 | */ |
1208 | error = anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep, | 1208 | error = anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep, |
1209 | flags & O_CLOEXEC); | 1209 | O_RDWR | (flags & O_CLOEXEC)); |
1210 | if (error < 0) | 1210 | if (error < 0) |
1211 | ep_free(ep); | 1211 | ep_free(ep); |
1212 | 1212 | ||
@@ -826,7 +826,9 @@ static int de_thread(struct task_struct *tsk) | |||
826 | attach_pid(tsk, PIDTYPE_PID, task_pid(leader)); | 826 | attach_pid(tsk, PIDTYPE_PID, task_pid(leader)); |
827 | transfer_pid(leader, tsk, PIDTYPE_PGID); | 827 | transfer_pid(leader, tsk, PIDTYPE_PGID); |
828 | transfer_pid(leader, tsk, PIDTYPE_SID); | 828 | transfer_pid(leader, tsk, PIDTYPE_SID); |
829 | |||
829 | list_replace_rcu(&leader->tasks, &tsk->tasks); | 830 | list_replace_rcu(&leader->tasks, &tsk->tasks); |
831 | list_replace_init(&leader->sibling, &tsk->sibling); | ||
830 | 832 | ||
831 | tsk->group_leader = tsk; | 833 | tsk->group_leader = tsk; |
832 | leader->group_leader = tsk; | 834 | leader->group_leader = tsk; |
@@ -1761,17 +1763,20 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs) | |||
1761 | struct mm_struct *mm = current->mm; | 1763 | struct mm_struct *mm = current->mm; |
1762 | struct linux_binfmt * binfmt; | 1764 | struct linux_binfmt * binfmt; |
1763 | struct inode * inode; | 1765 | struct inode * inode; |
1764 | struct file * file; | ||
1765 | const struct cred *old_cred; | 1766 | const struct cred *old_cred; |
1766 | struct cred *cred; | 1767 | struct cred *cred; |
1767 | int retval = 0; | 1768 | int retval = 0; |
1768 | int flag = 0; | 1769 | int flag = 0; |
1769 | int ispipe = 0; | 1770 | int ispipe = 0; |
1770 | unsigned long core_limit = current->signal->rlim[RLIMIT_CORE].rlim_cur; | ||
1771 | char **helper_argv = NULL; | 1771 | char **helper_argv = NULL; |
1772 | int helper_argc = 0; | 1772 | int helper_argc = 0; |
1773 | int dump_count = 0; | 1773 | int dump_count = 0; |
1774 | static atomic_t core_dump_count = ATOMIC_INIT(0); | 1774 | static atomic_t core_dump_count = ATOMIC_INIT(0); |
1775 | struct coredump_params cprm = { | ||
1776 | .signr = signr, | ||
1777 | .regs = regs, | ||
1778 | .limit = current->signal->rlim[RLIMIT_CORE].rlim_cur, | ||
1779 | }; | ||
1775 | 1780 | ||
1776 | audit_core_dumps(signr); | 1781 | audit_core_dumps(signr); |
1777 | 1782 | ||
@@ -1827,15 +1832,15 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs) | |||
1827 | ispipe = format_corename(corename, signr); | 1832 | ispipe = format_corename(corename, signr); |
1828 | unlock_kernel(); | 1833 | unlock_kernel(); |
1829 | 1834 | ||
1830 | if ((!ispipe) && (core_limit < binfmt->min_coredump)) | 1835 | if ((!ispipe) && (cprm.limit < binfmt->min_coredump)) |
1831 | goto fail_unlock; | 1836 | goto fail_unlock; |
1832 | 1837 | ||
1833 | if (ispipe) { | 1838 | if (ispipe) { |
1834 | if (core_limit == 0) { | 1839 | if (cprm.limit == 0) { |
1835 | /* | 1840 | /* |
1836 | * Normally core limits are irrelevant to pipes, since | 1841 | * Normally core limits are irrelevant to pipes, since |
1837 | * we're not writing to the file system, but we use | 1842 | * we're not writing to the file system, but we use |
1838 | * core_limit of 0 here as a speacial value. Any | 1843 | * cprm.limit of 0 here as a speacial value. Any |
1839 | * non-zero limit gets set to RLIM_INFINITY below, but | 1844 | * non-zero limit gets set to RLIM_INFINITY below, but |
1840 | * a limit of 0 skips the dump. This is a consistent | 1845 | * a limit of 0 skips the dump. This is a consistent |
1841 | * way to catch recursive crashes. We can still crash | 1846 | * way to catch recursive crashes. We can still crash |
@@ -1868,25 +1873,25 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs) | |||
1868 | goto fail_dropcount; | 1873 | goto fail_dropcount; |
1869 | } | 1874 | } |
1870 | 1875 | ||
1871 | core_limit = RLIM_INFINITY; | 1876 | cprm.limit = RLIM_INFINITY; |
1872 | 1877 | ||
1873 | /* SIGPIPE can happen, but it's just never processed */ | 1878 | /* SIGPIPE can happen, but it's just never processed */ |
1874 | if (call_usermodehelper_pipe(helper_argv[0], helper_argv, NULL, | 1879 | if (call_usermodehelper_pipe(helper_argv[0], helper_argv, NULL, |
1875 | &file)) { | 1880 | &cprm.file)) { |
1876 | printk(KERN_INFO "Core dump to %s pipe failed\n", | 1881 | printk(KERN_INFO "Core dump to %s pipe failed\n", |
1877 | corename); | 1882 | corename); |
1878 | goto fail_dropcount; | 1883 | goto fail_dropcount; |
1879 | } | 1884 | } |
1880 | } else | 1885 | } else |
1881 | file = filp_open(corename, | 1886 | cprm.file = filp_open(corename, |
1882 | O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag, | 1887 | O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag, |
1883 | 0600); | 1888 | 0600); |
1884 | if (IS_ERR(file)) | 1889 | if (IS_ERR(cprm.file)) |
1885 | goto fail_dropcount; | 1890 | goto fail_dropcount; |
1886 | inode = file->f_path.dentry->d_inode; | 1891 | inode = cprm.file->f_path.dentry->d_inode; |
1887 | if (inode->i_nlink > 1) | 1892 | if (inode->i_nlink > 1) |
1888 | goto close_fail; /* multiple links - don't dump */ | 1893 | goto close_fail; /* multiple links - don't dump */ |
1889 | if (!ispipe && d_unhashed(file->f_path.dentry)) | 1894 | if (!ispipe && d_unhashed(cprm.file->f_path.dentry)) |
1890 | goto close_fail; | 1895 | goto close_fail; |
1891 | 1896 | ||
1892 | /* AK: actually i see no reason to not allow this for named pipes etc., | 1897 | /* AK: actually i see no reason to not allow this for named pipes etc., |
@@ -1899,21 +1904,22 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs) | |||
1899 | */ | 1904 | */ |
1900 | if (inode->i_uid != current_fsuid()) | 1905 | if (inode->i_uid != current_fsuid()) |
1901 | goto close_fail; | 1906 | goto close_fail; |
1902 | if (!file->f_op) | 1907 | if (!cprm.file->f_op) |
1903 | goto close_fail; | 1908 | goto close_fail; |
1904 | if (!file->f_op->write) | 1909 | if (!cprm.file->f_op->write) |
1905 | goto close_fail; | 1910 | goto close_fail; |
1906 | if (!ispipe && do_truncate(file->f_path.dentry, 0, 0, file) != 0) | 1911 | if (!ispipe && |
1912 | do_truncate(cprm.file->f_path.dentry, 0, 0, cprm.file) != 0) | ||
1907 | goto close_fail; | 1913 | goto close_fail; |
1908 | 1914 | ||
1909 | retval = binfmt->core_dump(signr, regs, file, core_limit); | 1915 | retval = binfmt->core_dump(&cprm); |
1910 | 1916 | ||
1911 | if (retval) | 1917 | if (retval) |
1912 | current->signal->group_exit_code |= 0x80; | 1918 | current->signal->group_exit_code |= 0x80; |
1913 | close_fail: | 1919 | close_fail: |
1914 | if (ispipe && core_pipe_limit) | 1920 | if (ispipe && core_pipe_limit) |
1915 | wait_for_dump_helpers(file); | 1921 | wait_for_dump_helpers(cprm.file); |
1916 | filp_close(file, NULL); | 1922 | filp_close(cprm.file, NULL); |
1917 | fail_dropcount: | 1923 | fail_dropcount: |
1918 | if (dump_count) | 1924 | if (dump_count) |
1919 | atomic_dec(&core_dump_count); | 1925 | atomic_dec(&core_dump_count); |
diff --git a/fs/exofs/inode.c b/fs/exofs/inode.c index 698a8636d39c..2afbcebeda71 100644 --- a/fs/exofs/inode.c +++ b/fs/exofs/inode.c | |||
@@ -738,13 +738,28 @@ static int exofs_write_begin_export(struct file *file, | |||
738 | fsdata); | 738 | fsdata); |
739 | } | 739 | } |
740 | 740 | ||
741 | static int exofs_write_end(struct file *file, struct address_space *mapping, | ||
742 | loff_t pos, unsigned len, unsigned copied, | ||
743 | struct page *page, void *fsdata) | ||
744 | { | ||
745 | struct inode *inode = mapping->host; | ||
746 | /* According to comment in simple_write_end i_mutex is held */ | ||
747 | loff_t i_size = inode->i_size; | ||
748 | int ret; | ||
749 | |||
750 | ret = simple_write_end(file, mapping,pos, len, copied, page, fsdata); | ||
751 | if (i_size != inode->i_size) | ||
752 | mark_inode_dirty(inode); | ||
753 | return ret; | ||
754 | } | ||
755 | |||
741 | const struct address_space_operations exofs_aops = { | 756 | const struct address_space_operations exofs_aops = { |
742 | .readpage = exofs_readpage, | 757 | .readpage = exofs_readpage, |
743 | .readpages = exofs_readpages, | 758 | .readpages = exofs_readpages, |
744 | .writepage = exofs_writepage, | 759 | .writepage = exofs_writepage, |
745 | .writepages = exofs_writepages, | 760 | .writepages = exofs_writepages, |
746 | .write_begin = exofs_write_begin_export, | 761 | .write_begin = exofs_write_begin_export, |
747 | .write_end = simple_write_end, | 762 | .write_end = exofs_write_end, |
748 | }; | 763 | }; |
749 | 764 | ||
750 | /****************************************************************************** | 765 | /****************************************************************************** |
diff --git a/fs/exofs/pnfs.h b/fs/exofs/pnfs.h index 423033addd1f..c52e9888b8ab 100644 --- a/fs/exofs/pnfs.h +++ b/fs/exofs/pnfs.h | |||
@@ -15,13 +15,7 @@ | |||
15 | #ifndef __EXOFS_PNFS_H__ | 15 | #ifndef __EXOFS_PNFS_H__ |
16 | #define __EXOFS_PNFS_H__ | 16 | #define __EXOFS_PNFS_H__ |
17 | 17 | ||
18 | #if defined(CONFIG_PNFS) | 18 | #if ! defined(__PNFS_OSD_XDR_H__) |
19 | |||
20 | |||
21 | /* FIXME: move this file to: linux/exportfs/pnfs_osd_xdr.h */ | ||
22 | #include "../nfs/objlayout/pnfs_osd_xdr.h" | ||
23 | |||
24 | #else /* defined(CONFIG_PNFS) */ | ||
25 | 19 | ||
26 | enum pnfs_iomode { | 20 | enum pnfs_iomode { |
27 | IOMODE_READ = 1, | 21 | IOMODE_READ = 1, |
@@ -46,6 +40,6 @@ struct pnfs_osd_data_map { | |||
46 | u32 odm_raid_algorithm; | 40 | u32 odm_raid_algorithm; |
47 | }; | 41 | }; |
48 | 42 | ||
49 | #endif /* else defined(CONFIG_PNFS) */ | 43 | #endif /* ! defined(__PNFS_OSD_XDR_H__) */ |
50 | 44 | ||
51 | #endif /* __EXOFS_PNFS_H__ */ | 45 | #endif /* __EXOFS_PNFS_H__ */ |
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index ad14227f509e..455e6e6e5cb9 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c | |||
@@ -970,7 +970,7 @@ static int ext3_get_block(struct inode *inode, sector_t iblock, | |||
970 | if (max_blocks > DIO_MAX_BLOCKS) | 970 | if (max_blocks > DIO_MAX_BLOCKS) |
971 | max_blocks = DIO_MAX_BLOCKS; | 971 | max_blocks = DIO_MAX_BLOCKS; |
972 | handle = ext3_journal_start(inode, DIO_CREDITS + | 972 | handle = ext3_journal_start(inode, DIO_CREDITS + |
973 | 2 * EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb)); | 973 | EXT3_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb)); |
974 | if (IS_ERR(handle)) { | 974 | if (IS_ERR(handle)) { |
975 | ret = PTR_ERR(handle); | 975 | ret = PTR_ERR(handle); |
976 | goto out; | 976 | goto out; |
@@ -3146,8 +3146,8 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr) | |||
3146 | 3146 | ||
3147 | /* (user+group)*(old+new) structure, inode write (sb, | 3147 | /* (user+group)*(old+new) structure, inode write (sb, |
3148 | * inode block, ? - but truncate inode update has it) */ | 3148 | * inode block, ? - but truncate inode update has it) */ |
3149 | handle = ext3_journal_start(inode, 2*(EXT3_QUOTA_INIT_BLOCKS(inode->i_sb)+ | 3149 | handle = ext3_journal_start(inode, EXT3_MAXQUOTAS_INIT_BLOCKS(inode->i_sb)+ |
3150 | EXT3_QUOTA_DEL_BLOCKS(inode->i_sb))+3); | 3150 | EXT3_MAXQUOTAS_DEL_BLOCKS(inode->i_sb)+3); |
3151 | if (IS_ERR(handle)) { | 3151 | if (IS_ERR(handle)) { |
3152 | error = PTR_ERR(handle); | 3152 | error = PTR_ERR(handle); |
3153 | goto err_out; | 3153 | goto err_out; |
@@ -3239,7 +3239,7 @@ static int ext3_writepage_trans_blocks(struct inode *inode) | |||
3239 | #ifdef CONFIG_QUOTA | 3239 | #ifdef CONFIG_QUOTA |
3240 | /* We know that structure was already allocated during vfs_dq_init so | 3240 | /* We know that structure was already allocated during vfs_dq_init so |
3241 | * we will be updating only the data blocks + inodes */ | 3241 | * we will be updating only the data blocks + inodes */ |
3242 | ret += 2*EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb); | 3242 | ret += EXT3_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb); |
3243 | #endif | 3243 | #endif |
3244 | 3244 | ||
3245 | return ret; | 3245 | return ret; |
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c index aad6400c9b77..7b0e44f7d66f 100644 --- a/fs/ext3/namei.c +++ b/fs/ext3/namei.c | |||
@@ -1699,7 +1699,7 @@ static int ext3_create (struct inode * dir, struct dentry * dentry, int mode, | |||
1699 | retry: | 1699 | retry: |
1700 | handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + | 1700 | handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + |
1701 | EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + | 1701 | EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + |
1702 | 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); | 1702 | EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb)); |
1703 | if (IS_ERR(handle)) | 1703 | if (IS_ERR(handle)) |
1704 | return PTR_ERR(handle); | 1704 | return PTR_ERR(handle); |
1705 | 1705 | ||
@@ -1733,7 +1733,7 @@ static int ext3_mknod (struct inode * dir, struct dentry *dentry, | |||
1733 | retry: | 1733 | retry: |
1734 | handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + | 1734 | handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + |
1735 | EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + | 1735 | EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + |
1736 | 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); | 1736 | EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb)); |
1737 | if (IS_ERR(handle)) | 1737 | if (IS_ERR(handle)) |
1738 | return PTR_ERR(handle); | 1738 | return PTR_ERR(handle); |
1739 | 1739 | ||
@@ -1769,7 +1769,7 @@ static int ext3_mkdir(struct inode * dir, struct dentry * dentry, int mode) | |||
1769 | retry: | 1769 | retry: |
1770 | handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + | 1770 | handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + |
1771 | EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + | 1771 | EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + |
1772 | 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); | 1772 | EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb)); |
1773 | if (IS_ERR(handle)) | 1773 | if (IS_ERR(handle)) |
1774 | return PTR_ERR(handle); | 1774 | return PTR_ERR(handle); |
1775 | 1775 | ||
@@ -1920,7 +1920,7 @@ int ext3_orphan_add(handle_t *handle, struct inode *inode) | |||
1920 | struct ext3_iloc iloc; | 1920 | struct ext3_iloc iloc; |
1921 | int err = 0, rc; | 1921 | int err = 0, rc; |
1922 | 1922 | ||
1923 | lock_super(sb); | 1923 | mutex_lock(&EXT3_SB(sb)->s_orphan_lock); |
1924 | if (!list_empty(&EXT3_I(inode)->i_orphan)) | 1924 | if (!list_empty(&EXT3_I(inode)->i_orphan)) |
1925 | goto out_unlock; | 1925 | goto out_unlock; |
1926 | 1926 | ||
@@ -1929,9 +1929,13 @@ int ext3_orphan_add(handle_t *handle, struct inode *inode) | |||
1929 | 1929 | ||
1930 | /* @@@ FIXME: Observation from aviro: | 1930 | /* @@@ FIXME: Observation from aviro: |
1931 | * I think I can trigger J_ASSERT in ext3_orphan_add(). We block | 1931 | * I think I can trigger J_ASSERT in ext3_orphan_add(). We block |
1932 | * here (on lock_super()), so race with ext3_link() which might bump | 1932 | * here (on s_orphan_lock), so race with ext3_link() which might bump |
1933 | * ->i_nlink. For, say it, character device. Not a regular file, | 1933 | * ->i_nlink. For, say it, character device. Not a regular file, |
1934 | * not a directory, not a symlink and ->i_nlink > 0. | 1934 | * not a directory, not a symlink and ->i_nlink > 0. |
1935 | * | ||
1936 | * tytso, 4/25/2009: I'm not sure how that could happen; | ||
1937 | * shouldn't the fs core protect us from these sort of | ||
1938 | * unlink()/link() races? | ||
1935 | */ | 1939 | */ |
1936 | J_ASSERT ((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || | 1940 | J_ASSERT ((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || |
1937 | S_ISLNK(inode->i_mode)) || inode->i_nlink == 0); | 1941 | S_ISLNK(inode->i_mode)) || inode->i_nlink == 0); |
@@ -1968,7 +1972,7 @@ int ext3_orphan_add(handle_t *handle, struct inode *inode) | |||
1968 | jbd_debug(4, "orphan inode %lu will point to %d\n", | 1972 | jbd_debug(4, "orphan inode %lu will point to %d\n", |
1969 | inode->i_ino, NEXT_ORPHAN(inode)); | 1973 | inode->i_ino, NEXT_ORPHAN(inode)); |
1970 | out_unlock: | 1974 | out_unlock: |
1971 | unlock_super(sb); | 1975 | mutex_unlock(&EXT3_SB(sb)->s_orphan_lock); |
1972 | ext3_std_error(inode->i_sb, err); | 1976 | ext3_std_error(inode->i_sb, err); |
1973 | return err; | 1977 | return err; |
1974 | } | 1978 | } |
@@ -1986,11 +1990,9 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode) | |||
1986 | struct ext3_iloc iloc; | 1990 | struct ext3_iloc iloc; |
1987 | int err = 0; | 1991 | int err = 0; |
1988 | 1992 | ||
1989 | lock_super(inode->i_sb); | 1993 | mutex_lock(&EXT3_SB(inode->i_sb)->s_orphan_lock); |
1990 | if (list_empty(&ei->i_orphan)) { | 1994 | if (list_empty(&ei->i_orphan)) |
1991 | unlock_super(inode->i_sb); | 1995 | goto out; |
1992 | return 0; | ||
1993 | } | ||
1994 | 1996 | ||
1995 | ino_next = NEXT_ORPHAN(inode); | 1997 | ino_next = NEXT_ORPHAN(inode); |
1996 | prev = ei->i_orphan.prev; | 1998 | prev = ei->i_orphan.prev; |
@@ -2040,7 +2042,7 @@ int ext3_orphan_del(handle_t *handle, struct inode *inode) | |||
2040 | out_err: | 2042 | out_err: |
2041 | ext3_std_error(inode->i_sb, err); | 2043 | ext3_std_error(inode->i_sb, err); |
2042 | out: | 2044 | out: |
2043 | unlock_super(inode->i_sb); | 2045 | mutex_unlock(&EXT3_SB(inode->i_sb)->s_orphan_lock); |
2044 | return err; | 2046 | return err; |
2045 | 2047 | ||
2046 | out_brelse: | 2048 | out_brelse: |
@@ -2175,7 +2177,7 @@ static int ext3_symlink (struct inode * dir, | |||
2175 | retry: | 2177 | retry: |
2176 | handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + | 2178 | handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + |
2177 | EXT3_INDEX_EXTRA_TRANS_BLOCKS + 5 + | 2179 | EXT3_INDEX_EXTRA_TRANS_BLOCKS + 5 + |
2178 | 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); | 2180 | EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb)); |
2179 | if (IS_ERR(handle)) | 2181 | if (IS_ERR(handle)) |
2180 | return PTR_ERR(handle); | 2182 | return PTR_ERR(handle); |
2181 | 2183 | ||
diff --git a/fs/ext3/resize.c b/fs/ext3/resize.c index 5f83b6179178..54351ac7cef9 100644 --- a/fs/ext3/resize.c +++ b/fs/ext3/resize.c | |||
@@ -209,7 +209,7 @@ static int setup_new_group_blocks(struct super_block *sb, | |||
209 | if (IS_ERR(handle)) | 209 | if (IS_ERR(handle)) |
210 | return PTR_ERR(handle); | 210 | return PTR_ERR(handle); |
211 | 211 | ||
212 | lock_super(sb); | 212 | mutex_lock(&sbi->s_resize_lock); |
213 | if (input->group != sbi->s_groups_count) { | 213 | if (input->group != sbi->s_groups_count) { |
214 | err = -EBUSY; | 214 | err = -EBUSY; |
215 | goto exit_journal; | 215 | goto exit_journal; |
@@ -324,7 +324,7 @@ exit_bh: | |||
324 | brelse(bh); | 324 | brelse(bh); |
325 | 325 | ||
326 | exit_journal: | 326 | exit_journal: |
327 | unlock_super(sb); | 327 | mutex_unlock(&sbi->s_resize_lock); |
328 | if ((err2 = ext3_journal_stop(handle)) && !err) | 328 | if ((err2 = ext3_journal_stop(handle)) && !err) |
329 | err = err2; | 329 | err = err2; |
330 | 330 | ||
@@ -662,11 +662,12 @@ exit_free: | |||
662 | * important part is that the new block and inode counts are in the backup | 662 | * important part is that the new block and inode counts are in the backup |
663 | * superblocks, and the location of the new group metadata in the GDT backups. | 663 | * superblocks, and the location of the new group metadata in the GDT backups. |
664 | * | 664 | * |
665 | * We do not need lock_super() for this, because these blocks are not | 665 | * We do not need take the s_resize_lock for this, because these |
666 | * otherwise touched by the filesystem code when it is mounted. We don't | 666 | * blocks are not otherwise touched by the filesystem code when it is |
667 | * need to worry about last changing from sbi->s_groups_count, because the | 667 | * mounted. We don't need to worry about last changing from |
668 | * worst that can happen is that we do not copy the full number of backups | 668 | * sbi->s_groups_count, because the worst that can happen is that we |
669 | * at this time. The resize which changed s_groups_count will backup again. | 669 | * do not copy the full number of backups at this time. The resize |
670 | * which changed s_groups_count will backup again. | ||
670 | */ | 671 | */ |
671 | static void update_backups(struct super_block *sb, | 672 | static void update_backups(struct super_block *sb, |
672 | int blk_off, char *data, int size) | 673 | int blk_off, char *data, int size) |
@@ -825,7 +826,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) | |||
825 | goto exit_put; | 826 | goto exit_put; |
826 | } | 827 | } |
827 | 828 | ||
828 | lock_super(sb); | 829 | mutex_lock(&sbi->s_resize_lock); |
829 | if (input->group != sbi->s_groups_count) { | 830 | if (input->group != sbi->s_groups_count) { |
830 | ext3_warning(sb, __func__, | 831 | ext3_warning(sb, __func__, |
831 | "multiple resizers run on filesystem!"); | 832 | "multiple resizers run on filesystem!"); |
@@ -856,7 +857,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) | |||
856 | /* | 857 | /* |
857 | * OK, now we've set up the new group. Time to make it active. | 858 | * OK, now we've set up the new group. Time to make it active. |
858 | * | 859 | * |
859 | * Current kernels don't lock all allocations via lock_super(), | 860 | * We do not lock all allocations via s_resize_lock |
860 | * so we have to be safe wrt. concurrent accesses the group | 861 | * so we have to be safe wrt. concurrent accesses the group |
861 | * data. So we need to be careful to set all of the relevant | 862 | * data. So we need to be careful to set all of the relevant |
862 | * group descriptor data etc. *before* we enable the group. | 863 | * group descriptor data etc. *before* we enable the group. |
@@ -900,12 +901,12 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) | |||
900 | * | 901 | * |
901 | * The precise rules we use are: | 902 | * The precise rules we use are: |
902 | * | 903 | * |
903 | * * Writers of s_groups_count *must* hold lock_super | 904 | * * Writers of s_groups_count *must* hold s_resize_lock |
904 | * AND | 905 | * AND |
905 | * * Writers must perform a smp_wmb() after updating all dependent | 906 | * * Writers must perform a smp_wmb() after updating all dependent |
906 | * data and before modifying the groups count | 907 | * data and before modifying the groups count |
907 | * | 908 | * |
908 | * * Readers must hold lock_super() over the access | 909 | * * Readers must hold s_resize_lock over the access |
909 | * OR | 910 | * OR |
910 | * * Readers must perform an smp_rmb() after reading the groups count | 911 | * * Readers must perform an smp_rmb() after reading the groups count |
911 | * and before reading any dependent data. | 912 | * and before reading any dependent data. |
@@ -936,7 +937,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input) | |||
936 | ext3_journal_dirty_metadata(handle, sbi->s_sbh); | 937 | ext3_journal_dirty_metadata(handle, sbi->s_sbh); |
937 | 938 | ||
938 | exit_journal: | 939 | exit_journal: |
939 | unlock_super(sb); | 940 | mutex_unlock(&sbi->s_resize_lock); |
940 | if ((err2 = ext3_journal_stop(handle)) && !err) | 941 | if ((err2 = ext3_journal_stop(handle)) && !err) |
941 | err = err2; | 942 | err = err2; |
942 | if (!err) { | 943 | if (!err) { |
@@ -973,7 +974,7 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, | |||
973 | 974 | ||
974 | /* We don't need to worry about locking wrt other resizers just | 975 | /* We don't need to worry about locking wrt other resizers just |
975 | * yet: we're going to revalidate es->s_blocks_count after | 976 | * yet: we're going to revalidate es->s_blocks_count after |
976 | * taking lock_super() below. */ | 977 | * taking the s_resize_lock below. */ |
977 | o_blocks_count = le32_to_cpu(es->s_blocks_count); | 978 | o_blocks_count = le32_to_cpu(es->s_blocks_count); |
978 | o_groups_count = EXT3_SB(sb)->s_groups_count; | 979 | o_groups_count = EXT3_SB(sb)->s_groups_count; |
979 | 980 | ||
@@ -1045,11 +1046,11 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, | |||
1045 | goto exit_put; | 1046 | goto exit_put; |
1046 | } | 1047 | } |
1047 | 1048 | ||
1048 | lock_super(sb); | 1049 | mutex_lock(&EXT3_SB(sb)->s_resize_lock); |
1049 | if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) { | 1050 | if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) { |
1050 | ext3_warning(sb, __func__, | 1051 | ext3_warning(sb, __func__, |
1051 | "multiple resizers run on filesystem!"); | 1052 | "multiple resizers run on filesystem!"); |
1052 | unlock_super(sb); | 1053 | mutex_unlock(&EXT3_SB(sb)->s_resize_lock); |
1053 | ext3_journal_stop(handle); | 1054 | ext3_journal_stop(handle); |
1054 | err = -EBUSY; | 1055 | err = -EBUSY; |
1055 | goto exit_put; | 1056 | goto exit_put; |
@@ -1059,13 +1060,13 @@ int ext3_group_extend(struct super_block *sb, struct ext3_super_block *es, | |||
1059 | EXT3_SB(sb)->s_sbh))) { | 1060 | EXT3_SB(sb)->s_sbh))) { |
1060 | ext3_warning(sb, __func__, | 1061 | ext3_warning(sb, __func__, |
1061 | "error %d on journal write access", err); | 1062 | "error %d on journal write access", err); |
1062 | unlock_super(sb); | 1063 | mutex_unlock(&EXT3_SB(sb)->s_resize_lock); |
1063 | ext3_journal_stop(handle); | 1064 | ext3_journal_stop(handle); |
1064 | goto exit_put; | 1065 | goto exit_put; |
1065 | } | 1066 | } |
1066 | es->s_blocks_count = cpu_to_le32(o_blocks_count + add); | 1067 | es->s_blocks_count = cpu_to_le32(o_blocks_count + add); |
1067 | ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); | 1068 | ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); |
1068 | unlock_super(sb); | 1069 | mutex_unlock(&EXT3_SB(sb)->s_resize_lock); |
1069 | ext3_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count, | 1070 | ext3_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count, |
1070 | o_blocks_count + add); | 1071 | o_blocks_count + add); |
1071 | ext3_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks); | 1072 | ext3_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks); |
diff --git a/fs/ext3/super.c b/fs/ext3/super.c index 7ad1e8c30bd0..afa2b569da10 100644 --- a/fs/ext3/super.c +++ b/fs/ext3/super.c | |||
@@ -1928,6 +1928,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) | |||
1928 | sb->dq_op = &ext3_quota_operations; | 1928 | sb->dq_op = &ext3_quota_operations; |
1929 | #endif | 1929 | #endif |
1930 | INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ | 1930 | INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ |
1931 | mutex_init(&sbi->s_orphan_lock); | ||
1932 | mutex_init(&sbi->s_resize_lock); | ||
1931 | 1933 | ||
1932 | sb->s_root = NULL; | 1934 | sb->s_root = NULL; |
1933 | 1935 | ||
@@ -2014,14 +2016,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent) | |||
2014 | } | 2016 | } |
2015 | 2017 | ||
2016 | ext3_setup_super (sb, es, sb->s_flags & MS_RDONLY); | 2018 | ext3_setup_super (sb, es, sb->s_flags & MS_RDONLY); |
2017 | /* | 2019 | |
2018 | * akpm: core read_super() calls in here with the superblock locked. | ||
2019 | * That deadlocks, because orphan cleanup needs to lock the superblock | ||
2020 | * in numerous places. Here we just pop the lock - it's relatively | ||
2021 | * harmless, because we are now ready to accept write_super() requests, | ||
2022 | * and aviro says that's the only reason for hanging onto the | ||
2023 | * superblock lock. | ||
2024 | */ | ||
2025 | EXT3_SB(sb)->s_mount_state |= EXT3_ORPHAN_FS; | 2020 | EXT3_SB(sb)->s_mount_state |= EXT3_ORPHAN_FS; |
2026 | ext3_orphan_cleanup(sb, es); | 2021 | ext3_orphan_cleanup(sb, es); |
2027 | EXT3_SB(sb)->s_mount_state &= ~EXT3_ORPHAN_FS; | 2022 | EXT3_SB(sb)->s_mount_state &= ~EXT3_ORPHAN_FS; |
@@ -2403,13 +2398,11 @@ static void ext3_mark_recovery_complete(struct super_block * sb, | |||
2403 | if (journal_flush(journal) < 0) | 2398 | if (journal_flush(journal) < 0) |
2404 | goto out; | 2399 | goto out; |
2405 | 2400 | ||
2406 | lock_super(sb); | ||
2407 | if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER) && | 2401 | if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER) && |
2408 | sb->s_flags & MS_RDONLY) { | 2402 | sb->s_flags & MS_RDONLY) { |
2409 | EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); | 2403 | EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); |
2410 | ext3_commit_super(sb, es, 1); | 2404 | ext3_commit_super(sb, es, 1); |
2411 | } | 2405 | } |
2412 | unlock_super(sb); | ||
2413 | 2406 | ||
2414 | out: | 2407 | out: |
2415 | journal_unlock_updates(journal); | 2408 | journal_unlock_updates(journal); |
@@ -2601,13 +2594,7 @@ static int ext3_remount (struct super_block * sb, int * flags, char * data) | |||
2601 | (sbi->s_mount_state & EXT3_VALID_FS)) | 2594 | (sbi->s_mount_state & EXT3_VALID_FS)) |
2602 | es->s_state = cpu_to_le16(sbi->s_mount_state); | 2595 | es->s_state = cpu_to_le16(sbi->s_mount_state); |
2603 | 2596 | ||
2604 | /* | ||
2605 | * We have to unlock super so that we can wait for | ||
2606 | * transactions. | ||
2607 | */ | ||
2608 | unlock_super(sb); | ||
2609 | ext3_mark_recovery_complete(sb, es); | 2597 | ext3_mark_recovery_complete(sb, es); |
2610 | lock_super(sb); | ||
2611 | } else { | 2598 | } else { |
2612 | __le32 ret; | 2599 | __le32 ret; |
2613 | if ((ret = EXT3_HAS_RO_COMPAT_FEATURE(sb, | 2600 | if ((ret = EXT3_HAS_RO_COMPAT_FEATURE(sb, |
diff --git a/fs/ext4/Kconfig b/fs/ext4/Kconfig index e5f6774846e4..9ed1bb1f319f 100644 --- a/fs/ext4/Kconfig +++ b/fs/ext4/Kconfig | |||
@@ -2,7 +2,6 @@ config EXT4_FS | |||
2 | tristate "The Extended 4 (ext4) filesystem" | 2 | tristate "The Extended 4 (ext4) filesystem" |
3 | select JBD2 | 3 | select JBD2 |
4 | select CRC16 | 4 | select CRC16 |
5 | select FS_JOURNAL_INFO | ||
6 | help | 5 | help |
7 | This is the next generation of the ext3 filesystem. | 6 | This is the next generation of the ext3 filesystem. |
8 | 7 | ||
@@ -29,6 +28,7 @@ config EXT4_FS | |||
29 | 28 | ||
30 | config EXT4_USE_FOR_EXT23 | 29 | config EXT4_USE_FOR_EXT23 |
31 | bool "Use ext4 for ext2/ext3 file systems" | 30 | bool "Use ext4 for ext2/ext3 file systems" |
31 | depends on EXT4_FS | ||
32 | depends on EXT3_FS=n || EXT2_FS=n | 32 | depends on EXT3_FS=n || EXT2_FS=n |
33 | default y | 33 | default y |
34 | help | 34 | help |
diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c index 4df8621ec31c..a60ab9aad57d 100644 --- a/fs/ext4/block_validity.c +++ b/fs/ext4/block_validity.c | |||
@@ -16,7 +16,6 @@ | |||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/swap.h> | 17 | #include <linux/swap.h> |
18 | #include <linux/pagemap.h> | 18 | #include <linux/pagemap.h> |
19 | #include <linux/version.h> | ||
20 | #include <linux/blkdev.h> | 19 | #include <linux/blkdev.h> |
21 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
22 | #include "ext4.h" | 21 | #include "ext4.h" |
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index ab31e65d46d0..af7b62699ea9 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -699,11 +699,17 @@ struct ext4_inode_info { | |||
699 | unsigned int i_reserved_meta_blocks; | 699 | unsigned int i_reserved_meta_blocks; |
700 | unsigned int i_allocated_meta_blocks; | 700 | unsigned int i_allocated_meta_blocks; |
701 | unsigned short i_delalloc_reserved_flag; | 701 | unsigned short i_delalloc_reserved_flag; |
702 | sector_t i_da_metadata_calc_last_lblock; | ||
703 | int i_da_metadata_calc_len; | ||
702 | 704 | ||
703 | /* on-disk additional length */ | 705 | /* on-disk additional length */ |
704 | __u16 i_extra_isize; | 706 | __u16 i_extra_isize; |
705 | 707 | ||
706 | spinlock_t i_block_reservation_lock; | 708 | spinlock_t i_block_reservation_lock; |
709 | #ifdef CONFIG_QUOTA | ||
710 | /* quota space reservation, managed internally by quota code */ | ||
711 | qsize_t i_reserved_quota; | ||
712 | #endif | ||
707 | 713 | ||
708 | /* completed async DIOs that might need unwritten extents handling */ | 714 | /* completed async DIOs that might need unwritten extents handling */ |
709 | struct list_head i_aio_dio_complete_list; | 715 | struct list_head i_aio_dio_complete_list; |
@@ -1435,7 +1441,7 @@ extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks); | |||
1435 | extern int ext4_block_truncate_page(handle_t *handle, | 1441 | extern int ext4_block_truncate_page(handle_t *handle, |
1436 | struct address_space *mapping, loff_t from); | 1442 | struct address_space *mapping, loff_t from); |
1437 | extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf); | 1443 | extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf); |
1438 | extern qsize_t ext4_get_reserved_space(struct inode *inode); | 1444 | extern qsize_t *ext4_get_reserved_space(struct inode *inode); |
1439 | extern int flush_aio_dio_completed_IO(struct inode *inode); | 1445 | extern int flush_aio_dio_completed_IO(struct inode *inode); |
1440 | /* ioctl.c */ | 1446 | /* ioctl.c */ |
1441 | extern long ext4_ioctl(struct file *, unsigned int, unsigned long); | 1447 | extern long ext4_ioctl(struct file *, unsigned int, unsigned long); |
diff --git a/fs/ext4/ext4_extents.h b/fs/ext4/ext4_extents.h index 2ca686454e87..bdb6ce7e2eb4 100644 --- a/fs/ext4/ext4_extents.h +++ b/fs/ext4/ext4_extents.h | |||
@@ -225,7 +225,8 @@ static inline void ext4_ext_mark_initialized(struct ext4_extent *ext) | |||
225 | ext->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ext)); | 225 | ext->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ext)); |
226 | } | 226 | } |
227 | 227 | ||
228 | extern int ext4_ext_calc_metadata_amount(struct inode *inode, int blocks); | 228 | extern int ext4_ext_calc_metadata_amount(struct inode *inode, |
229 | sector_t lblocks); | ||
229 | extern ext4_fsblk_t ext_pblock(struct ext4_extent *ex); | 230 | extern ext4_fsblk_t ext_pblock(struct ext4_extent *ex); |
230 | extern ext4_fsblk_t idx_pblock(struct ext4_extent_idx *); | 231 | extern ext4_fsblk_t idx_pblock(struct ext4_extent_idx *); |
231 | extern void ext4_ext_store_pblock(struct ext4_extent *, ext4_fsblk_t); | 232 | extern void ext4_ext_store_pblock(struct ext4_extent *, ext4_fsblk_t); |
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 3a7928f825e4..7d7b74e94687 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -296,29 +296,44 @@ static inline int ext4_ext_space_root_idx(struct inode *inode, int check) | |||
296 | * to allocate @blocks | 296 | * to allocate @blocks |
297 | * Worse case is one block per extent | 297 | * Worse case is one block per extent |
298 | */ | 298 | */ |
299 | int ext4_ext_calc_metadata_amount(struct inode *inode, int blocks) | 299 | int ext4_ext_calc_metadata_amount(struct inode *inode, sector_t lblock) |
300 | { | 300 | { |
301 | int lcap, icap, rcap, leafs, idxs, num; | 301 | struct ext4_inode_info *ei = EXT4_I(inode); |
302 | int newextents = blocks; | 302 | int idxs, num = 0; |
303 | |||
304 | rcap = ext4_ext_space_root_idx(inode, 0); | ||
305 | lcap = ext4_ext_space_block(inode, 0); | ||
306 | icap = ext4_ext_space_block_idx(inode, 0); | ||
307 | 303 | ||
308 | /* number of new leaf blocks needed */ | 304 | idxs = ((inode->i_sb->s_blocksize - sizeof(struct ext4_extent_header)) |
309 | num = leafs = (newextents + lcap - 1) / lcap; | 305 | / sizeof(struct ext4_extent_idx)); |
310 | 306 | ||
311 | /* | 307 | /* |
312 | * Worse case, we need separate index block(s) | 308 | * If the new delayed allocation block is contiguous with the |
313 | * to link all new leaf blocks | 309 | * previous da block, it can share index blocks with the |
310 | * previous block, so we only need to allocate a new index | ||
311 | * block every idxs leaf blocks. At ldxs**2 blocks, we need | ||
312 | * an additional index block, and at ldxs**3 blocks, yet | ||
313 | * another index blocks. | ||
314 | */ | 314 | */ |
315 | idxs = (leafs + icap - 1) / icap; | 315 | if (ei->i_da_metadata_calc_len && |
316 | do { | 316 | ei->i_da_metadata_calc_last_lblock+1 == lblock) { |
317 | num += idxs; | 317 | if ((ei->i_da_metadata_calc_len % idxs) == 0) |
318 | idxs = (idxs + icap - 1) / icap; | 318 | num++; |
319 | } while (idxs > rcap); | 319 | if ((ei->i_da_metadata_calc_len % (idxs*idxs)) == 0) |
320 | num++; | ||
321 | if ((ei->i_da_metadata_calc_len % (idxs*idxs*idxs)) == 0) { | ||
322 | num++; | ||
323 | ei->i_da_metadata_calc_len = 0; | ||
324 | } else | ||
325 | ei->i_da_metadata_calc_len++; | ||
326 | ei->i_da_metadata_calc_last_lblock++; | ||
327 | return num; | ||
328 | } | ||
320 | 329 | ||
321 | return num; | 330 | /* |
331 | * In the worst case we need a new set of index blocks at | ||
332 | * every level of the inode's extent tree. | ||
333 | */ | ||
334 | ei->i_da_metadata_calc_len = 1; | ||
335 | ei->i_da_metadata_calc_last_lblock = lblock; | ||
336 | return ext_depth(inode) + 1; | ||
322 | } | 337 | } |
323 | 338 | ||
324 | static int | 339 | static int |
@@ -3023,6 +3038,14 @@ out: | |||
3023 | return err; | 3038 | return err; |
3024 | } | 3039 | } |
3025 | 3040 | ||
3041 | static void unmap_underlying_metadata_blocks(struct block_device *bdev, | ||
3042 | sector_t block, int count) | ||
3043 | { | ||
3044 | int i; | ||
3045 | for (i = 0; i < count; i++) | ||
3046 | unmap_underlying_metadata(bdev, block + i); | ||
3047 | } | ||
3048 | |||
3026 | static int | 3049 | static int |
3027 | ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, | 3050 | ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, |
3028 | ext4_lblk_t iblock, unsigned int max_blocks, | 3051 | ext4_lblk_t iblock, unsigned int max_blocks, |
@@ -3098,6 +3121,18 @@ out: | |||
3098 | } else | 3121 | } else |
3099 | allocated = ret; | 3122 | allocated = ret; |
3100 | set_buffer_new(bh_result); | 3123 | set_buffer_new(bh_result); |
3124 | /* | ||
3125 | * if we allocated more blocks than requested | ||
3126 | * we need to make sure we unmap the extra block | ||
3127 | * allocated. The actual needed block will get | ||
3128 | * unmapped later when we find the buffer_head marked | ||
3129 | * new. | ||
3130 | */ | ||
3131 | if (allocated > max_blocks) { | ||
3132 | unmap_underlying_metadata_blocks(inode->i_sb->s_bdev, | ||
3133 | newblock + max_blocks, | ||
3134 | allocated - max_blocks); | ||
3135 | } | ||
3101 | map_out: | 3136 | map_out: |
3102 | set_buffer_mapped(bh_result); | 3137 | set_buffer_mapped(bh_result); |
3103 | out1: | 3138 | out1: |
@@ -3190,7 +3225,13 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, | |||
3190 | * this situation is possible, though, _during_ tree modification; | 3225 | * this situation is possible, though, _during_ tree modification; |
3191 | * this is why assert can't be put in ext4_ext_find_extent() | 3226 | * this is why assert can't be put in ext4_ext_find_extent() |
3192 | */ | 3227 | */ |
3193 | BUG_ON(path[depth].p_ext == NULL && depth != 0); | 3228 | if (path[depth].p_ext == NULL && depth != 0) { |
3229 | ext4_error(inode->i_sb, __func__, "bad extent address " | ||
3230 | "inode: %lu, iblock: %d, depth: %d", | ||
3231 | inode->i_ino, iblock, depth); | ||
3232 | err = -EIO; | ||
3233 | goto out2; | ||
3234 | } | ||
3194 | eh = path[depth].p_hdr; | 3235 | eh = path[depth].p_hdr; |
3195 | 3236 | ||
3196 | ex = path[depth].p_ext; | 3237 | ex = path[depth].p_ext; |
diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c index 0b22497d92e1..98bd140aad01 100644 --- a/fs/ext4/fsync.c +++ b/fs/ext4/fsync.c | |||
@@ -88,9 +88,21 @@ int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync) | |||
88 | return ext4_force_commit(inode->i_sb); | 88 | return ext4_force_commit(inode->i_sb); |
89 | 89 | ||
90 | commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid; | 90 | commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid; |
91 | if (jbd2_log_start_commit(journal, commit_tid)) | 91 | if (jbd2_log_start_commit(journal, commit_tid)) { |
92 | /* | ||
93 | * When the journal is on a different device than the | ||
94 | * fs data disk, we need to issue the barrier in | ||
95 | * writeback mode. (In ordered mode, the jbd2 layer | ||
96 | * will take care of issuing the barrier. In | ||
97 | * data=journal, all of the data blocks are written to | ||
98 | * the journal device.) | ||
99 | */ | ||
100 | if (ext4_should_writeback_data(inode) && | ||
101 | (journal->j_fs_dev != journal->j_dev) && | ||
102 | (journal->j_flags & JBD2_BARRIER)) | ||
103 | blkdev_issue_flush(inode->i_sb->s_bdev, NULL); | ||
92 | jbd2_log_wait_commit(journal, commit_tid); | 104 | jbd2_log_wait_commit(journal, commit_tid); |
93 | else if (journal->j_flags & JBD2_BARRIER) | 105 | } else if (journal->j_flags & JBD2_BARRIER) |
94 | blkdev_issue_flush(inode->i_sb->s_bdev, NULL); | 106 | blkdev_issue_flush(inode->i_sb->s_bdev, NULL); |
95 | return ret; | 107 | return ret; |
96 | } | 108 | } |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5352db1a3086..c818972c8302 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -1003,83 +1003,94 @@ out: | |||
1003 | return err; | 1003 | return err; |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | qsize_t ext4_get_reserved_space(struct inode *inode) | 1006 | #ifdef CONFIG_QUOTA |
1007 | qsize_t *ext4_get_reserved_space(struct inode *inode) | ||
1007 | { | 1008 | { |
1008 | unsigned long long total; | 1009 | return &EXT4_I(inode)->i_reserved_quota; |
1009 | |||
1010 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1011 | total = EXT4_I(inode)->i_reserved_data_blocks + | ||
1012 | EXT4_I(inode)->i_reserved_meta_blocks; | ||
1013 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1014 | |||
1015 | return (total << inode->i_blkbits); | ||
1016 | } | 1010 | } |
1011 | #endif | ||
1012 | |||
1017 | /* | 1013 | /* |
1018 | * Calculate the number of metadata blocks need to reserve | 1014 | * Calculate the number of metadata blocks need to reserve |
1019 | * to allocate @blocks for non extent file based file | 1015 | * to allocate a new block at @lblocks for non extent file based file |
1020 | */ | 1016 | */ |
1021 | static int ext4_indirect_calc_metadata_amount(struct inode *inode, int blocks) | 1017 | static int ext4_indirect_calc_metadata_amount(struct inode *inode, |
1018 | sector_t lblock) | ||
1022 | { | 1019 | { |
1023 | int icap = EXT4_ADDR_PER_BLOCK(inode->i_sb); | 1020 | struct ext4_inode_info *ei = EXT4_I(inode); |
1024 | int ind_blks, dind_blks, tind_blks; | 1021 | int dind_mask = EXT4_ADDR_PER_BLOCK(inode->i_sb) - 1; |
1025 | 1022 | int blk_bits; | |
1026 | /* number of new indirect blocks needed */ | ||
1027 | ind_blks = (blocks + icap - 1) / icap; | ||
1028 | 1023 | ||
1029 | dind_blks = (ind_blks + icap - 1) / icap; | 1024 | if (lblock < EXT4_NDIR_BLOCKS) |
1025 | return 0; | ||
1030 | 1026 | ||
1031 | tind_blks = 1; | 1027 | lblock -= EXT4_NDIR_BLOCKS; |
1032 | 1028 | ||
1033 | return ind_blks + dind_blks + tind_blks; | 1029 | if (ei->i_da_metadata_calc_len && |
1030 | (lblock & dind_mask) == ei->i_da_metadata_calc_last_lblock) { | ||
1031 | ei->i_da_metadata_calc_len++; | ||
1032 | return 0; | ||
1033 | } | ||
1034 | ei->i_da_metadata_calc_last_lblock = lblock & dind_mask; | ||
1035 | ei->i_da_metadata_calc_len = 1; | ||
1036 | blk_bits = roundup_pow_of_two(lblock + 1); | ||
1037 | return (blk_bits / EXT4_ADDR_PER_BLOCK_BITS(inode->i_sb)) + 1; | ||
1034 | } | 1038 | } |
1035 | 1039 | ||
1036 | /* | 1040 | /* |
1037 | * Calculate the number of metadata blocks need to reserve | 1041 | * Calculate the number of metadata blocks need to reserve |
1038 | * to allocate given number of blocks | 1042 | * to allocate a block located at @lblock |
1039 | */ | 1043 | */ |
1040 | static int ext4_calc_metadata_amount(struct inode *inode, int blocks) | 1044 | static int ext4_calc_metadata_amount(struct inode *inode, sector_t lblock) |
1041 | { | 1045 | { |
1042 | if (!blocks) | ||
1043 | return 0; | ||
1044 | |||
1045 | if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) | 1046 | if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) |
1046 | return ext4_ext_calc_metadata_amount(inode, blocks); | 1047 | return ext4_ext_calc_metadata_amount(inode, lblock); |
1047 | 1048 | ||
1048 | return ext4_indirect_calc_metadata_amount(inode, blocks); | 1049 | return ext4_indirect_calc_metadata_amount(inode, lblock); |
1049 | } | 1050 | } |
1050 | 1051 | ||
1052 | /* | ||
1053 | * Called with i_data_sem down, which is important since we can call | ||
1054 | * ext4_discard_preallocations() from here. | ||
1055 | */ | ||
1051 | static void ext4_da_update_reserve_space(struct inode *inode, int used) | 1056 | static void ext4_da_update_reserve_space(struct inode *inode, int used) |
1052 | { | 1057 | { |
1053 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 1058 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
1054 | int total, mdb, mdb_free; | 1059 | struct ext4_inode_info *ei = EXT4_I(inode); |
1055 | 1060 | int mdb_free = 0; | |
1056 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | 1061 | |
1057 | /* recalculate the number of metablocks still need to be reserved */ | 1062 | spin_lock(&ei->i_block_reservation_lock); |
1058 | total = EXT4_I(inode)->i_reserved_data_blocks - used; | 1063 | if (unlikely(used > ei->i_reserved_data_blocks)) { |
1059 | mdb = ext4_calc_metadata_amount(inode, total); | 1064 | ext4_msg(inode->i_sb, KERN_NOTICE, "%s: ino %lu, used %d " |
1060 | 1065 | "with only %d reserved data blocks\n", | |
1061 | /* figure out how many metablocks to release */ | 1066 | __func__, inode->i_ino, used, |
1062 | BUG_ON(mdb > EXT4_I(inode)->i_reserved_meta_blocks); | 1067 | ei->i_reserved_data_blocks); |
1063 | mdb_free = EXT4_I(inode)->i_reserved_meta_blocks - mdb; | 1068 | WARN_ON(1); |
1064 | 1069 | used = ei->i_reserved_data_blocks; | |
1065 | if (mdb_free) { | 1070 | } |
1066 | /* Account for allocated meta_blocks */ | 1071 | |
1067 | mdb_free -= EXT4_I(inode)->i_allocated_meta_blocks; | 1072 | /* Update per-inode reservations */ |
1068 | 1073 | ei->i_reserved_data_blocks -= used; | |
1069 | /* update fs dirty blocks counter */ | 1074 | used += ei->i_allocated_meta_blocks; |
1075 | ei->i_reserved_meta_blocks -= ei->i_allocated_meta_blocks; | ||
1076 | ei->i_allocated_meta_blocks = 0; | ||
1077 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, used); | ||
1078 | |||
1079 | if (ei->i_reserved_data_blocks == 0) { | ||
1080 | /* | ||
1081 | * We can release all of the reserved metadata blocks | ||
1082 | * only when we have written all of the delayed | ||
1083 | * allocation blocks. | ||
1084 | */ | ||
1085 | mdb_free = ei->i_reserved_meta_blocks; | ||
1086 | ei->i_reserved_meta_blocks = 0; | ||
1087 | ei->i_da_metadata_calc_len = 0; | ||
1070 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, mdb_free); | 1088 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, mdb_free); |
1071 | EXT4_I(inode)->i_allocated_meta_blocks = 0; | ||
1072 | EXT4_I(inode)->i_reserved_meta_blocks = mdb; | ||
1073 | } | 1089 | } |
1074 | |||
1075 | /* update per-inode reservations */ | ||
1076 | BUG_ON(used > EXT4_I(inode)->i_reserved_data_blocks); | ||
1077 | EXT4_I(inode)->i_reserved_data_blocks -= used; | ||
1078 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | 1090 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); |
1079 | 1091 | ||
1080 | /* | 1092 | /* Update quota subsystem */ |
1081 | * free those over-booking quota for metadata blocks | 1093 | vfs_dq_claim_block(inode, used); |
1082 | */ | ||
1083 | if (mdb_free) | 1094 | if (mdb_free) |
1084 | vfs_dq_release_reservation_block(inode, mdb_free); | 1095 | vfs_dq_release_reservation_block(inode, mdb_free); |
1085 | 1096 | ||
@@ -1088,7 +1099,8 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used) | |||
1088 | * there aren't any writers on the inode, we can discard the | 1099 | * there aren't any writers on the inode, we can discard the |
1089 | * inode's preallocations. | 1100 | * inode's preallocations. |
1090 | */ | 1101 | */ |
1091 | if (!total && (atomic_read(&inode->i_writecount) == 0)) | 1102 | if ((ei->i_reserved_data_blocks == 0) && |
1103 | (atomic_read(&inode->i_writecount) == 0)) | ||
1092 | ext4_discard_preallocations(inode); | 1104 | ext4_discard_preallocations(inode); |
1093 | } | 1105 | } |
1094 | 1106 | ||
@@ -1797,11 +1809,15 @@ static int ext4_journalled_write_end(struct file *file, | |||
1797 | return ret ? ret : copied; | 1809 | return ret ? ret : copied; |
1798 | } | 1810 | } |
1799 | 1811 | ||
1800 | static int ext4_da_reserve_space(struct inode *inode, int nrblocks) | 1812 | /* |
1813 | * Reserve a single block located at lblock | ||
1814 | */ | ||
1815 | static int ext4_da_reserve_space(struct inode *inode, sector_t lblock) | ||
1801 | { | 1816 | { |
1802 | int retries = 0; | 1817 | int retries = 0; |
1803 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 1818 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
1804 | unsigned long md_needed, mdblocks, total = 0; | 1819 | struct ext4_inode_info *ei = EXT4_I(inode); |
1820 | unsigned long md_needed, md_reserved; | ||
1805 | 1821 | ||
1806 | /* | 1822 | /* |
1807 | * recalculate the amount of metadata blocks to reserve | 1823 | * recalculate the amount of metadata blocks to reserve |
@@ -1809,86 +1825,90 @@ static int ext4_da_reserve_space(struct inode *inode, int nrblocks) | |||
1809 | * worse case is one extent per block | 1825 | * worse case is one extent per block |
1810 | */ | 1826 | */ |
1811 | repeat: | 1827 | repeat: |
1812 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | 1828 | spin_lock(&ei->i_block_reservation_lock); |
1813 | total = EXT4_I(inode)->i_reserved_data_blocks + nrblocks; | 1829 | md_reserved = ei->i_reserved_meta_blocks; |
1814 | mdblocks = ext4_calc_metadata_amount(inode, total); | 1830 | md_needed = ext4_calc_metadata_amount(inode, lblock); |
1815 | BUG_ON(mdblocks < EXT4_I(inode)->i_reserved_meta_blocks); | 1831 | spin_unlock(&ei->i_block_reservation_lock); |
1816 | |||
1817 | md_needed = mdblocks - EXT4_I(inode)->i_reserved_meta_blocks; | ||
1818 | total = md_needed + nrblocks; | ||
1819 | 1832 | ||
1820 | /* | 1833 | /* |
1821 | * Make quota reservation here to prevent quota overflow | 1834 | * Make quota reservation here to prevent quota overflow |
1822 | * later. Real quota accounting is done at pages writeout | 1835 | * later. Real quota accounting is done at pages writeout |
1823 | * time. | 1836 | * time. |
1824 | */ | 1837 | */ |
1825 | if (vfs_dq_reserve_block(inode, total)) { | 1838 | if (vfs_dq_reserve_block(inode, md_needed + 1)) { |
1826 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | 1839 | /* |
1840 | * We tend to badly over-estimate the amount of | ||
1841 | * metadata blocks which are needed, so if we have | ||
1842 | * reserved any metadata blocks, try to force out the | ||
1843 | * inode and see if we have any better luck. | ||
1844 | */ | ||
1845 | if (md_reserved && retries++ <= 3) | ||
1846 | goto retry; | ||
1827 | return -EDQUOT; | 1847 | return -EDQUOT; |
1828 | } | 1848 | } |
1829 | 1849 | ||
1830 | if (ext4_claim_free_blocks(sbi, total)) { | 1850 | if (ext4_claim_free_blocks(sbi, md_needed + 1)) { |
1831 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | 1851 | vfs_dq_release_reservation_block(inode, md_needed + 1); |
1832 | vfs_dq_release_reservation_block(inode, total); | ||
1833 | if (ext4_should_retry_alloc(inode->i_sb, &retries)) { | 1852 | if (ext4_should_retry_alloc(inode->i_sb, &retries)) { |
1853 | retry: | ||
1854 | if (md_reserved) | ||
1855 | write_inode_now(inode, (retries == 3)); | ||
1834 | yield(); | 1856 | yield(); |
1835 | goto repeat; | 1857 | goto repeat; |
1836 | } | 1858 | } |
1837 | return -ENOSPC; | 1859 | return -ENOSPC; |
1838 | } | 1860 | } |
1839 | EXT4_I(inode)->i_reserved_data_blocks += nrblocks; | 1861 | spin_lock(&ei->i_block_reservation_lock); |
1840 | EXT4_I(inode)->i_reserved_meta_blocks = mdblocks; | 1862 | ei->i_reserved_data_blocks++; |
1863 | ei->i_reserved_meta_blocks += md_needed; | ||
1864 | spin_unlock(&ei->i_block_reservation_lock); | ||
1841 | 1865 | ||
1842 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1843 | return 0; /* success */ | 1866 | return 0; /* success */ |
1844 | } | 1867 | } |
1845 | 1868 | ||
1846 | static void ext4_da_release_space(struct inode *inode, int to_free) | 1869 | static void ext4_da_release_space(struct inode *inode, int to_free) |
1847 | { | 1870 | { |
1848 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 1871 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
1849 | int total, mdb, mdb_free, release; | 1872 | struct ext4_inode_info *ei = EXT4_I(inode); |
1850 | 1873 | ||
1851 | if (!to_free) | 1874 | if (!to_free) |
1852 | return; /* Nothing to release, exit */ | 1875 | return; /* Nothing to release, exit */ |
1853 | 1876 | ||
1854 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | 1877 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); |
1855 | 1878 | ||
1856 | if (!EXT4_I(inode)->i_reserved_data_blocks) { | 1879 | if (unlikely(to_free > ei->i_reserved_data_blocks)) { |
1857 | /* | 1880 | /* |
1858 | * if there is no reserved blocks, but we try to free some | 1881 | * if there aren't enough reserved blocks, then the |
1859 | * then the counter is messed up somewhere. | 1882 | * counter is messed up somewhere. Since this |
1860 | * but since this function is called from invalidate | 1883 | * function is called from invalidate page, it's |
1861 | * page, it's harmless to return without any action | 1884 | * harmless to return without any action. |
1862 | */ | 1885 | */ |
1863 | printk(KERN_INFO "ext4 delalloc try to release %d reserved " | 1886 | ext4_msg(inode->i_sb, KERN_NOTICE, "ext4_da_release_space: " |
1864 | "blocks for inode %lu, but there is no reserved " | 1887 | "ino %lu, to_free %d with only %d reserved " |
1865 | "data blocks\n", to_free, inode->i_ino); | 1888 | "data blocks\n", inode->i_ino, to_free, |
1866 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | 1889 | ei->i_reserved_data_blocks); |
1867 | return; | 1890 | WARN_ON(1); |
1891 | to_free = ei->i_reserved_data_blocks; | ||
1868 | } | 1892 | } |
1893 | ei->i_reserved_data_blocks -= to_free; | ||
1869 | 1894 | ||
1870 | /* recalculate the number of metablocks still need to be reserved */ | 1895 | if (ei->i_reserved_data_blocks == 0) { |
1871 | total = EXT4_I(inode)->i_reserved_data_blocks - to_free; | 1896 | /* |
1872 | mdb = ext4_calc_metadata_amount(inode, total); | 1897 | * We can release all of the reserved metadata blocks |
1873 | 1898 | * only when we have written all of the delayed | |
1874 | /* figure out how many metablocks to release */ | 1899 | * allocation blocks. |
1875 | BUG_ON(mdb > EXT4_I(inode)->i_reserved_meta_blocks); | 1900 | */ |
1876 | mdb_free = EXT4_I(inode)->i_reserved_meta_blocks - mdb; | 1901 | to_free += ei->i_reserved_meta_blocks; |
1877 | 1902 | ei->i_reserved_meta_blocks = 0; | |
1878 | release = to_free + mdb_free; | 1903 | ei->i_da_metadata_calc_len = 0; |
1879 | 1904 | } | |
1880 | /* update fs dirty blocks counter for truncate case */ | ||
1881 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, release); | ||
1882 | 1905 | ||
1883 | /* update per-inode reservations */ | 1906 | /* update fs dirty blocks counter */ |
1884 | BUG_ON(to_free > EXT4_I(inode)->i_reserved_data_blocks); | 1907 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, to_free); |
1885 | EXT4_I(inode)->i_reserved_data_blocks -= to_free; | ||
1886 | 1908 | ||
1887 | BUG_ON(mdb > EXT4_I(inode)->i_reserved_meta_blocks); | ||
1888 | EXT4_I(inode)->i_reserved_meta_blocks = mdb; | ||
1889 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | 1909 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); |
1890 | 1910 | ||
1891 | vfs_dq_release_reservation_block(inode, release); | 1911 | vfs_dq_release_reservation_block(inode, to_free); |
1892 | } | 1912 | } |
1893 | 1913 | ||
1894 | static void ext4_da_page_release_reservation(struct page *page, | 1914 | static void ext4_da_page_release_reservation(struct page *page, |
@@ -2494,7 +2514,7 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, | |||
2494 | * XXX: __block_prepare_write() unmaps passed block, | 2514 | * XXX: __block_prepare_write() unmaps passed block, |
2495 | * is it OK? | 2515 | * is it OK? |
2496 | */ | 2516 | */ |
2497 | ret = ext4_da_reserve_space(inode, 1); | 2517 | ret = ext4_da_reserve_space(inode, iblock); |
2498 | if (ret) | 2518 | if (ret) |
2499 | /* not enough space to reserve */ | 2519 | /* not enough space to reserve */ |
2500 | return ret; | 2520 | return ret; |
@@ -2968,8 +2988,7 @@ retry: | |||
2968 | out_writepages: | 2988 | out_writepages: |
2969 | if (!no_nrwrite_index_update) | 2989 | if (!no_nrwrite_index_update) |
2970 | wbc->no_nrwrite_index_update = 0; | 2990 | wbc->no_nrwrite_index_update = 0; |
2971 | if (wbc->nr_to_write > nr_to_writebump) | 2991 | wbc->nr_to_write -= nr_to_writebump; |
2972 | wbc->nr_to_write -= nr_to_writebump; | ||
2973 | wbc->range_start = range_start; | 2992 | wbc->range_start = range_start; |
2974 | trace_ext4_da_writepages_result(inode, wbc, ret, pages_written); | 2993 | trace_ext4_da_writepages_result(inode, wbc, ret, pages_written); |
2975 | return ret; | 2994 | return ret; |
@@ -2994,11 +3013,18 @@ static int ext4_nonda_switch(struct super_block *sb) | |||
2994 | if (2 * free_blocks < 3 * dirty_blocks || | 3013 | if (2 * free_blocks < 3 * dirty_blocks || |
2995 | free_blocks < (dirty_blocks + EXT4_FREEBLOCKS_WATERMARK)) { | 3014 | free_blocks < (dirty_blocks + EXT4_FREEBLOCKS_WATERMARK)) { |
2996 | /* | 3015 | /* |
2997 | * free block count is less that 150% of dirty blocks | 3016 | * free block count is less than 150% of dirty blocks |
2998 | * or free blocks is less that watermark | 3017 | * or free blocks is less than watermark |
2999 | */ | 3018 | */ |
3000 | return 1; | 3019 | return 1; |
3001 | } | 3020 | } |
3021 | /* | ||
3022 | * Even if we don't switch but are nearing capacity, | ||
3023 | * start pushing delalloc when 1/2 of free blocks are dirty. | ||
3024 | */ | ||
3025 | if (free_blocks < 2 * dirty_blocks) | ||
3026 | writeback_inodes_sb_if_idle(sb); | ||
3027 | |||
3002 | return 0; | 3028 | return 0; |
3003 | } | 3029 | } |
3004 | 3030 | ||
@@ -4794,6 +4820,9 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4794 | ((__u64)le16_to_cpu(raw_inode->i_file_acl_high)) << 32; | 4820 | ((__u64)le16_to_cpu(raw_inode->i_file_acl_high)) << 32; |
4795 | inode->i_size = ext4_isize(raw_inode); | 4821 | inode->i_size = ext4_isize(raw_inode); |
4796 | ei->i_disksize = inode->i_size; | 4822 | ei->i_disksize = inode->i_size; |
4823 | #ifdef CONFIG_QUOTA | ||
4824 | ei->i_reserved_quota = 0; | ||
4825 | #endif | ||
4797 | inode->i_generation = le32_to_cpu(raw_inode->i_generation); | 4826 | inode->i_generation = le32_to_cpu(raw_inode->i_generation); |
4798 | ei->i_block_group = iloc.block_group; | 4827 | ei->i_block_group = iloc.block_group; |
4799 | ei->i_last_alloc_group = ~0; | 4828 | ei->i_last_alloc_group = ~0; |
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index b1fd3daadc9c..d34afad3e137 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
@@ -2755,12 +2755,6 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, | |||
2755 | if (!(ac->ac_flags & EXT4_MB_DELALLOC_RESERVED)) | 2755 | if (!(ac->ac_flags & EXT4_MB_DELALLOC_RESERVED)) |
2756 | /* release all the reserved blocks if non delalloc */ | 2756 | /* release all the reserved blocks if non delalloc */ |
2757 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, reserv_blks); | 2757 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, reserv_blks); |
2758 | else { | ||
2759 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, | ||
2760 | ac->ac_b_ex.fe_len); | ||
2761 | /* convert reserved quota blocks to real quota blocks */ | ||
2762 | vfs_dq_claim_block(ac->ac_inode, ac->ac_b_ex.fe_len); | ||
2763 | } | ||
2764 | 2758 | ||
2765 | if (sbi->s_log_groups_per_flex) { | 2759 | if (sbi->s_log_groups_per_flex) { |
2766 | ext4_group_t flex_group = ext4_flex_group(sbi, | 2760 | ext4_group_t flex_group = ext4_flex_group(sbi, |
diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h index 0ca811061bc7..436521cae456 100644 --- a/fs/ext4/mballoc.h +++ b/fs/ext4/mballoc.h | |||
@@ -17,7 +17,6 @@ | |||
17 | #include <linux/proc_fs.h> | 17 | #include <linux/proc_fs.h> |
18 | #include <linux/pagemap.h> | 18 | #include <linux/pagemap.h> |
19 | #include <linux/seq_file.h> | 19 | #include <linux/seq_file.h> |
20 | #include <linux/version.h> | ||
21 | #include <linux/blkdev.h> | 20 | #include <linux/blkdev.h> |
22 | #include <linux/mutex.h> | 21 | #include <linux/mutex.h> |
23 | #include "ext4_jbd2.h" | 22 | #include "ext4_jbd2.h" |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 827bde1f2594..735c20d5fd56 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -702,8 +702,12 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) | |||
702 | ei->i_reserved_data_blocks = 0; | 702 | ei->i_reserved_data_blocks = 0; |
703 | ei->i_reserved_meta_blocks = 0; | 703 | ei->i_reserved_meta_blocks = 0; |
704 | ei->i_allocated_meta_blocks = 0; | 704 | ei->i_allocated_meta_blocks = 0; |
705 | ei->i_da_metadata_calc_len = 0; | ||
705 | ei->i_delalloc_reserved_flag = 0; | 706 | ei->i_delalloc_reserved_flag = 0; |
706 | spin_lock_init(&(ei->i_block_reservation_lock)); | 707 | spin_lock_init(&(ei->i_block_reservation_lock)); |
708 | #ifdef CONFIG_QUOTA | ||
709 | ei->i_reserved_quota = 0; | ||
710 | #endif | ||
707 | INIT_LIST_HEAD(&ei->i_aio_dio_complete_list); | 711 | INIT_LIST_HEAD(&ei->i_aio_dio_complete_list); |
708 | ei->cur_aio_dio = NULL; | 712 | ei->cur_aio_dio = NULL; |
709 | ei->i_sync_tid = 0; | 713 | ei->i_sync_tid = 0; |
@@ -1014,7 +1018,9 @@ static const struct dquot_operations ext4_quota_operations = { | |||
1014 | .reserve_space = dquot_reserve_space, | 1018 | .reserve_space = dquot_reserve_space, |
1015 | .claim_space = dquot_claim_space, | 1019 | .claim_space = dquot_claim_space, |
1016 | .release_rsv = dquot_release_reserved_space, | 1020 | .release_rsv = dquot_release_reserved_space, |
1021 | #ifdef CONFIG_QUOTA | ||
1017 | .get_reserved_space = ext4_get_reserved_space, | 1022 | .get_reserved_space = ext4_get_reserved_space, |
1023 | #endif | ||
1018 | .alloc_inode = dquot_alloc_inode, | 1024 | .alloc_inode = dquot_alloc_inode, |
1019 | .free_space = dquot_free_space, | 1025 | .free_space = dquot_free_space, |
1020 | .free_inode = dquot_free_inode, | 1026 | .free_inode = dquot_free_inode, |
@@ -2169,9 +2175,9 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a, | |||
2169 | struct super_block *sb = sbi->s_buddy_cache->i_sb; | 2175 | struct super_block *sb = sbi->s_buddy_cache->i_sb; |
2170 | 2176 | ||
2171 | return snprintf(buf, PAGE_SIZE, "%llu\n", | 2177 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
2172 | sbi->s_kbytes_written + | 2178 | (unsigned long long)(sbi->s_kbytes_written + |
2173 | ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - | 2179 | ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - |
2174 | EXT4_SB(sb)->s_sectors_written_start) >> 1)); | 2180 | EXT4_SB(sb)->s_sectors_written_start) >> 1))); |
2175 | } | 2181 | } |
2176 | 2182 | ||
2177 | static ssize_t inode_readahead_blks_store(struct ext4_attr *a, | 2183 | static ssize_t inode_readahead_blks_store(struct ext4_attr *a, |
@@ -4000,6 +4006,7 @@ static inline void unregister_as_ext2(void) | |||
4000 | { | 4006 | { |
4001 | unregister_filesystem(&ext2_fs_type); | 4007 | unregister_filesystem(&ext2_fs_type); |
4002 | } | 4008 | } |
4009 | MODULE_ALIAS("ext2"); | ||
4003 | #else | 4010 | #else |
4004 | static inline void register_as_ext2(void) { } | 4011 | static inline void register_as_ext2(void) { } |
4005 | static inline void unregister_as_ext2(void) { } | 4012 | static inline void unregister_as_ext2(void) { } |
@@ -4026,6 +4033,7 @@ static inline void unregister_as_ext3(void) | |||
4026 | { | 4033 | { |
4027 | unregister_filesystem(&ext3_fs_type); | 4034 | unregister_filesystem(&ext3_fs_type); |
4028 | } | 4035 | } |
4036 | MODULE_ALIAS("ext3"); | ||
4029 | #else | 4037 | #else |
4030 | static inline void register_as_ext3(void) { } | 4038 | static inline void register_as_ext3(void) { } |
4031 | static inline void unregister_as_ext3(void) { } | 4039 | static inline void unregister_as_ext3(void) { } |
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 83218bebbc7c..f3a2f7ed45aa 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c | |||
@@ -1332,6 +1332,8 @@ retry: | |||
1332 | goto cleanup; | 1332 | goto cleanup; |
1333 | kfree(b_entry_name); | 1333 | kfree(b_entry_name); |
1334 | kfree(buffer); | 1334 | kfree(buffer); |
1335 | b_entry_name = NULL; | ||
1336 | buffer = NULL; | ||
1335 | brelse(is->iloc.bh); | 1337 | brelse(is->iloc.bh); |
1336 | kfree(is); | 1338 | kfree(is); |
1337 | kfree(bs); | 1339 | kfree(bs); |
diff --git a/fs/file_table.c b/fs/file_table.c index 0afacf654398..69652c5bd5f0 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -186,10 +186,8 @@ struct file *alloc_file(struct path *path, fmode_t mode, | |||
186 | * that we can do debugging checks at __fput() | 186 | * that we can do debugging checks at __fput() |
187 | */ | 187 | */ |
188 | if ((mode & FMODE_WRITE) && !special_file(path->dentry->d_inode->i_mode)) { | 188 | if ((mode & FMODE_WRITE) && !special_file(path->dentry->d_inode->i_mode)) { |
189 | int error = 0; | ||
190 | file_take_write(file); | 189 | file_take_write(file); |
191 | error = mnt_clone_write(path->mnt); | 190 | WARN_ON(mnt_clone_write(path->mnt)); |
192 | WARN_ON(error); | ||
193 | } | 191 | } |
194 | ima_counts_get(file); | 192 | ima_counts_get(file); |
195 | return file; | 193 | return file; |
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 49bc1b8e8f19..1a7c42c64ff4 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c | |||
@@ -242,6 +242,7 @@ static void bdi_sync_writeback(struct backing_dev_info *bdi, | |||
242 | /** | 242 | /** |
243 | * bdi_start_writeback - start writeback | 243 | * bdi_start_writeback - start writeback |
244 | * @bdi: the backing device to write from | 244 | * @bdi: the backing device to write from |
245 | * @sb: write inodes from this super_block | ||
245 | * @nr_pages: the number of pages to write | 246 | * @nr_pages: the number of pages to write |
246 | * | 247 | * |
247 | * Description: | 248 | * Description: |
@@ -1187,6 +1188,23 @@ void writeback_inodes_sb(struct super_block *sb) | |||
1187 | EXPORT_SYMBOL(writeback_inodes_sb); | 1188 | EXPORT_SYMBOL(writeback_inodes_sb); |
1188 | 1189 | ||
1189 | /** | 1190 | /** |
1191 | * writeback_inodes_sb_if_idle - start writeback if none underway | ||
1192 | * @sb: the superblock | ||
1193 | * | ||
1194 | * Invoke writeback_inodes_sb if no writeback is currently underway. | ||
1195 | * Returns 1 if writeback was started, 0 if not. | ||
1196 | */ | ||
1197 | int writeback_inodes_sb_if_idle(struct super_block *sb) | ||
1198 | { | ||
1199 | if (!writeback_in_progress(sb->s_bdi)) { | ||
1200 | writeback_inodes_sb(sb); | ||
1201 | return 1; | ||
1202 | } else | ||
1203 | return 0; | ||
1204 | } | ||
1205 | EXPORT_SYMBOL(writeback_inodes_sb_if_idle); | ||
1206 | |||
1207 | /** | ||
1190 | * sync_inodes_sb - sync sb inode pages | 1208 | * sync_inodes_sb - sync sb inode pages |
1191 | * @sb: the superblock | 1209 | * @sb: the superblock |
1192 | * | 1210 | * |
diff --git a/fs/gfs2/Kconfig b/fs/gfs2/Kconfig index b192c661caa6..4dcddf83326f 100644 --- a/fs/gfs2/Kconfig +++ b/fs/gfs2/Kconfig | |||
@@ -10,7 +10,6 @@ config GFS2_FS | |||
10 | select SLOW_WORK | 10 | select SLOW_WORK |
11 | select QUOTA | 11 | select QUOTA |
12 | select QUOTACTL | 12 | select QUOTACTL |
13 | select FS_JOURNAL_INFO | ||
14 | help | 13 | help |
15 | A cluster filesystem. | 14 | A cluster filesystem. |
16 | 15 | ||
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 4eb308aa3234..a6abbae8a278 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c | |||
@@ -569,6 +569,40 @@ static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) | |||
569 | return ret; | 569 | return ret; |
570 | } | 570 | } |
571 | 571 | ||
572 | /** | ||
573 | * gfs2_file_aio_write - Perform a write to a file | ||
574 | * @iocb: The io context | ||
575 | * @iov: The data to write | ||
576 | * @nr_segs: Number of @iov segments | ||
577 | * @pos: The file position | ||
578 | * | ||
579 | * We have to do a lock/unlock here to refresh the inode size for | ||
580 | * O_APPEND writes, otherwise we can land up writing at the wrong | ||
581 | * offset. There is still a race, but provided the app is using its | ||
582 | * own file locking, this will make O_APPEND work as expected. | ||
583 | * | ||
584 | */ | ||
585 | |||
586 | static ssize_t gfs2_file_aio_write(struct kiocb *iocb, const struct iovec *iov, | ||
587 | unsigned long nr_segs, loff_t pos) | ||
588 | { | ||
589 | struct file *file = iocb->ki_filp; | ||
590 | |||
591 | if (file->f_flags & O_APPEND) { | ||
592 | struct dentry *dentry = file->f_dentry; | ||
593 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); | ||
594 | struct gfs2_holder gh; | ||
595 | int ret; | ||
596 | |||
597 | ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh); | ||
598 | if (ret) | ||
599 | return ret; | ||
600 | gfs2_glock_dq_uninit(&gh); | ||
601 | } | ||
602 | |||
603 | return generic_file_aio_write(iocb, iov, nr_segs, pos); | ||
604 | } | ||
605 | |||
572 | #ifdef CONFIG_GFS2_FS_LOCKING_DLM | 606 | #ifdef CONFIG_GFS2_FS_LOCKING_DLM |
573 | 607 | ||
574 | /** | 608 | /** |
@@ -711,7 +745,7 @@ const struct file_operations gfs2_file_fops = { | |||
711 | .read = do_sync_read, | 745 | .read = do_sync_read, |
712 | .aio_read = generic_file_aio_read, | 746 | .aio_read = generic_file_aio_read, |
713 | .write = do_sync_write, | 747 | .write = do_sync_write, |
714 | .aio_write = generic_file_aio_write, | 748 | .aio_write = gfs2_file_aio_write, |
715 | .unlocked_ioctl = gfs2_ioctl, | 749 | .unlocked_ioctl = gfs2_ioctl, |
716 | .mmap = gfs2_mmap, | 750 | .mmap = gfs2_mmap, |
717 | .open = gfs2_open, | 751 | .open = gfs2_open, |
@@ -741,7 +775,7 @@ const struct file_operations gfs2_file_fops_nolock = { | |||
741 | .read = do_sync_read, | 775 | .read = do_sync_read, |
742 | .aio_read = generic_file_aio_read, | 776 | .aio_read = generic_file_aio_read, |
743 | .write = do_sync_write, | 777 | .write = do_sync_write, |
744 | .aio_write = generic_file_aio_write, | 778 | .aio_write = gfs2_file_aio_write, |
745 | .unlocked_ioctl = gfs2_ioctl, | 779 | .unlocked_ioctl = gfs2_ioctl, |
746 | .mmap = gfs2_mmap, | 780 | .mmap = gfs2_mmap, |
747 | .open = gfs2_open, | 781 | .open = gfs2_open, |
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 3ff32fa793da..6e220f4eee7d 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c | |||
@@ -125,7 +125,7 @@ static struct inode *gfs2_iget_skip(struct super_block *sb, | |||
125 | * directory entry when gfs2_inode_lookup() is invoked. Part of the code | 125 | * directory entry when gfs2_inode_lookup() is invoked. Part of the code |
126 | * segment inside gfs2_inode_lookup code needs to get moved around. | 126 | * segment inside gfs2_inode_lookup code needs to get moved around. |
127 | * | 127 | * |
128 | * Clean up I_LOCK and I_NEW as well. | 128 | * Clears I_NEW as well. |
129 | **/ | 129 | **/ |
130 | 130 | ||
131 | void gfs2_set_iop(struct inode *inode) | 131 | void gfs2_set_iop(struct inode *inode) |
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c index cb8d7a93d5ec..6f68a5f18eb8 100644 --- a/fs/gfs2/meta_io.c +++ b/fs/gfs2/meta_io.c | |||
@@ -121,7 +121,7 @@ struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp) | |||
121 | if (aspace) { | 121 | if (aspace) { |
122 | mapping_set_gfp_mask(aspace->i_mapping, GFP_NOFS); | 122 | mapping_set_gfp_mask(aspace->i_mapping, GFP_NOFS); |
123 | aspace->i_mapping->a_ops = &aspace_aops; | 123 | aspace->i_mapping->a_ops = &aspace_aops; |
124 | aspace->i_size = ~0ULL; | 124 | aspace->i_size = MAX_LFS_FILESIZE; |
125 | ip = GFS2_I(aspace); | 125 | ip = GFS2_I(aspace); |
126 | clear_bit(GIF_USER, &ip->i_flags); | 126 | clear_bit(GIF_USER, &ip->i_flags); |
127 | insert_inode_hash(aspace); | 127 | insert_inode_hash(aspace); |
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c index 247436c10deb..78f73ca1ef3e 100644 --- a/fs/gfs2/ops_inode.c +++ b/fs/gfs2/ops_inode.c | |||
@@ -748,7 +748,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, | |||
748 | struct gfs2_rgrpd *nrgd; | 748 | struct gfs2_rgrpd *nrgd; |
749 | unsigned int num_gh; | 749 | unsigned int num_gh; |
750 | int dir_rename = 0; | 750 | int dir_rename = 0; |
751 | int alloc_required; | 751 | int alloc_required = 0; |
752 | unsigned int x; | 752 | unsigned int x; |
753 | int error; | 753 | int error; |
754 | 754 | ||
@@ -867,7 +867,9 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, | |||
867 | goto out_gunlock; | 867 | goto out_gunlock; |
868 | } | 868 | } |
869 | 869 | ||
870 | alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name); | 870 | if (nip == NULL) |
871 | alloc_required = gfs2_diradd_alloc_required(ndir, &ndentry->d_name); | ||
872 | error = alloc_required; | ||
871 | if (error < 0) | 873 | if (error < 0) |
872 | goto out_gunlock; | 874 | goto out_gunlock; |
873 | error = 0; | 875 | error = 0; |
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c index 8a04108e0c22..c2ebdf2c01d4 100644 --- a/fs/gfs2/xattr.c +++ b/fs/gfs2/xattr.c | |||
@@ -1296,6 +1296,7 @@ fail: | |||
1296 | 1296 | ||
1297 | int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data) | 1297 | int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data) |
1298 | { | 1298 | { |
1299 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | ||
1299 | struct gfs2_ea_location el; | 1300 | struct gfs2_ea_location el; |
1300 | struct buffer_head *dibh; | 1301 | struct buffer_head *dibh; |
1301 | int error; | 1302 | int error; |
@@ -1305,16 +1306,17 @@ int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data) | |||
1305 | return error; | 1306 | return error; |
1306 | 1307 | ||
1307 | if (GFS2_EA_IS_STUFFED(el.el_ea)) { | 1308 | if (GFS2_EA_IS_STUFFED(el.el_ea)) { |
1308 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + RES_EATTR, 0); | 1309 | error = gfs2_trans_begin(sdp, RES_DINODE + RES_EATTR, 0); |
1309 | if (error) | 1310 | if (error == 0) { |
1310 | return error; | 1311 | gfs2_trans_add_bh(ip->i_gl, el.el_bh, 1); |
1311 | 1312 | memcpy(GFS2_EA2DATA(el.el_ea), data, | |
1312 | gfs2_trans_add_bh(ip->i_gl, el.el_bh, 1); | 1313 | GFS2_EA_DATA_LEN(el.el_ea)); |
1313 | memcpy(GFS2_EA2DATA(el.el_ea), data, | 1314 | } |
1314 | GFS2_EA_DATA_LEN(el.el_ea)); | 1315 | } else { |
1315 | } else | ||
1316 | error = ea_acl_chmod_unstuffed(ip, el.el_ea, data); | 1316 | error = ea_acl_chmod_unstuffed(ip, el.el_ea, data); |
1317 | } | ||
1317 | 1318 | ||
1319 | brelse(el.el_bh); | ||
1318 | if (error) | 1320 | if (error) |
1319 | return error; | 1321 | return error; |
1320 | 1322 | ||
@@ -1327,8 +1329,7 @@ int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data) | |||
1327 | brelse(dibh); | 1329 | brelse(dibh); |
1328 | } | 1330 | } |
1329 | 1331 | ||
1330 | gfs2_trans_end(GFS2_SB(&ip->i_inode)); | 1332 | gfs2_trans_end(sdp); |
1331 | |||
1332 | return error; | 1333 | return error; |
1333 | } | 1334 | } |
1334 | 1335 | ||
diff --git a/fs/inode.c b/fs/inode.c index 06c1f02de611..03dfeb2e3928 100644 --- a/fs/inode.c +++ b/fs/inode.c | |||
@@ -113,7 +113,7 @@ static void wake_up_inode(struct inode *inode) | |||
113 | * Prevent speculative execution through spin_unlock(&inode_lock); | 113 | * Prevent speculative execution through spin_unlock(&inode_lock); |
114 | */ | 114 | */ |
115 | smp_mb(); | 115 | smp_mb(); |
116 | wake_up_bit(&inode->i_state, __I_LOCK); | 116 | wake_up_bit(&inode->i_state, __I_NEW); |
117 | } | 117 | } |
118 | 118 | ||
119 | /** | 119 | /** |
@@ -690,17 +690,17 @@ void unlock_new_inode(struct inode *inode) | |||
690 | } | 690 | } |
691 | #endif | 691 | #endif |
692 | /* | 692 | /* |
693 | * This is special! We do not need the spinlock when clearing I_LOCK, | 693 | * This is special! We do not need the spinlock when clearing I_NEW, |
694 | * because we're guaranteed that nobody else tries to do anything about | 694 | * because we're guaranteed that nobody else tries to do anything about |
695 | * the state of the inode when it is locked, as we just created it (so | 695 | * the state of the inode when it is locked, as we just created it (so |
696 | * there can be no old holders that haven't tested I_LOCK). | 696 | * there can be no old holders that haven't tested I_NEW). |
697 | * However we must emit the memory barrier so that other CPUs reliably | 697 | * However we must emit the memory barrier so that other CPUs reliably |
698 | * see the clearing of I_LOCK after the other inode initialisation has | 698 | * see the clearing of I_NEW after the other inode initialisation has |
699 | * completed. | 699 | * completed. |
700 | */ | 700 | */ |
701 | smp_mb(); | 701 | smp_mb(); |
702 | WARN_ON((inode->i_state & (I_LOCK|I_NEW)) != (I_LOCK|I_NEW)); | 702 | WARN_ON(!(inode->i_state & I_NEW)); |
703 | inode->i_state &= ~(I_LOCK|I_NEW); | 703 | inode->i_state &= ~I_NEW; |
704 | wake_up_inode(inode); | 704 | wake_up_inode(inode); |
705 | } | 705 | } |
706 | EXPORT_SYMBOL(unlock_new_inode); | 706 | EXPORT_SYMBOL(unlock_new_inode); |
@@ -731,7 +731,7 @@ static struct inode *get_new_inode(struct super_block *sb, | |||
731 | goto set_failed; | 731 | goto set_failed; |
732 | 732 | ||
733 | __inode_add_to_lists(sb, head, inode); | 733 | __inode_add_to_lists(sb, head, inode); |
734 | inode->i_state = I_LOCK|I_NEW; | 734 | inode->i_state = I_NEW; |
735 | spin_unlock(&inode_lock); | 735 | spin_unlock(&inode_lock); |
736 | 736 | ||
737 | /* Return the locked inode with I_NEW set, the | 737 | /* Return the locked inode with I_NEW set, the |
@@ -778,7 +778,7 @@ static struct inode *get_new_inode_fast(struct super_block *sb, | |||
778 | if (!old) { | 778 | if (!old) { |
779 | inode->i_ino = ino; | 779 | inode->i_ino = ino; |
780 | __inode_add_to_lists(sb, head, inode); | 780 | __inode_add_to_lists(sb, head, inode); |
781 | inode->i_state = I_LOCK|I_NEW; | 781 | inode->i_state = I_NEW; |
782 | spin_unlock(&inode_lock); | 782 | spin_unlock(&inode_lock); |
783 | 783 | ||
784 | /* Return the locked inode with I_NEW set, the | 784 | /* Return the locked inode with I_NEW set, the |
@@ -1083,7 +1083,7 @@ int insert_inode_locked(struct inode *inode) | |||
1083 | ino_t ino = inode->i_ino; | 1083 | ino_t ino = inode->i_ino; |
1084 | struct hlist_head *head = inode_hashtable + hash(sb, ino); | 1084 | struct hlist_head *head = inode_hashtable + hash(sb, ino); |
1085 | 1085 | ||
1086 | inode->i_state |= I_LOCK|I_NEW; | 1086 | inode->i_state |= I_NEW; |
1087 | while (1) { | 1087 | while (1) { |
1088 | struct hlist_node *node; | 1088 | struct hlist_node *node; |
1089 | struct inode *old = NULL; | 1089 | struct inode *old = NULL; |
@@ -1120,7 +1120,7 @@ int insert_inode_locked4(struct inode *inode, unsigned long hashval, | |||
1120 | struct super_block *sb = inode->i_sb; | 1120 | struct super_block *sb = inode->i_sb; |
1121 | struct hlist_head *head = inode_hashtable + hash(sb, hashval); | 1121 | struct hlist_head *head = inode_hashtable + hash(sb, hashval); |
1122 | 1122 | ||
1123 | inode->i_state |= I_LOCK|I_NEW; | 1123 | inode->i_state |= I_NEW; |
1124 | 1124 | ||
1125 | while (1) { | 1125 | while (1) { |
1126 | struct hlist_node *node; | 1126 | struct hlist_node *node; |
@@ -1510,7 +1510,7 @@ EXPORT_SYMBOL(inode_wait); | |||
1510 | * until the deletion _might_ have completed. Callers are responsible | 1510 | * until the deletion _might_ have completed. Callers are responsible |
1511 | * to recheck inode state. | 1511 | * to recheck inode state. |
1512 | * | 1512 | * |
1513 | * It doesn't matter if I_LOCK is not set initially, a call to | 1513 | * It doesn't matter if I_NEW is not set initially, a call to |
1514 | * wake_up_inode() after removing from the hash list will DTRT. | 1514 | * wake_up_inode() after removing from the hash list will DTRT. |
1515 | * | 1515 | * |
1516 | * This is called with inode_lock held. | 1516 | * This is called with inode_lock held. |
@@ -1518,8 +1518,8 @@ EXPORT_SYMBOL(inode_wait); | |||
1518 | static void __wait_on_freeing_inode(struct inode *inode) | 1518 | static void __wait_on_freeing_inode(struct inode *inode) |
1519 | { | 1519 | { |
1520 | wait_queue_head_t *wq; | 1520 | wait_queue_head_t *wq; |
1521 | DEFINE_WAIT_BIT(wait, &inode->i_state, __I_LOCK); | 1521 | DEFINE_WAIT_BIT(wait, &inode->i_state, __I_NEW); |
1522 | wq = bit_waitqueue(&inode->i_state, __I_LOCK); | 1522 | wq = bit_waitqueue(&inode->i_state, __I_NEW); |
1523 | prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE); | 1523 | prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE); |
1524 | spin_unlock(&inode_lock); | 1524 | spin_unlock(&inode_lock); |
1525 | schedule(); | 1525 | schedule(); |
diff --git a/fs/internal.h b/fs/internal.h index f67cd141d9a8..e96a1667d749 100644 --- a/fs/internal.h +++ b/fs/internal.h | |||
@@ -85,3 +85,10 @@ extern struct file *get_empty_filp(void); | |||
85 | * super.c | 85 | * super.c |
86 | */ | 86 | */ |
87 | extern int do_remount_sb(struct super_block *, int, void *, int); | 87 | extern int do_remount_sb(struct super_block *, int, void *, int); |
88 | |||
89 | /* | ||
90 | * open.c | ||
91 | */ | ||
92 | struct nameidata; | ||
93 | extern struct file *nameidata_to_filp(struct nameidata *); | ||
94 | extern void release_open_intent(struct nameidata *); | ||
diff --git a/fs/jbd/Kconfig b/fs/jbd/Kconfig index a8408983abd4..4e28beeed157 100644 --- a/fs/jbd/Kconfig +++ b/fs/jbd/Kconfig | |||
@@ -1,6 +1,5 @@ | |||
1 | config JBD | 1 | config JBD |
2 | tristate | 2 | tristate |
3 | select FS_JOURNAL_INFO | ||
4 | help | 3 | help |
5 | This is a generic journalling layer for block devices. It is | 4 | This is a generic journalling layer for block devices. It is |
6 | currently used by the ext3 file system, but it could also be | 5 | currently used by the ext3 file system, but it could also be |
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c index 4160afad6d00..bd224eec9b07 100644 --- a/fs/jbd/journal.c +++ b/fs/jbd/journal.c | |||
@@ -1913,7 +1913,7 @@ static void __init jbd_create_debugfs_entry(void) | |||
1913 | { | 1913 | { |
1914 | jbd_debugfs_dir = debugfs_create_dir("jbd", NULL); | 1914 | jbd_debugfs_dir = debugfs_create_dir("jbd", NULL); |
1915 | if (jbd_debugfs_dir) | 1915 | if (jbd_debugfs_dir) |
1916 | jbd_debug = debugfs_create_u8("jbd-debug", S_IRUGO, | 1916 | jbd_debug = debugfs_create_u8("jbd-debug", S_IRUGO | S_IWUSR, |
1917 | jbd_debugfs_dir, | 1917 | jbd_debugfs_dir, |
1918 | &journal_enable_debug); | 1918 | &journal_enable_debug); |
1919 | } | 1919 | } |
diff --git a/fs/jbd2/Kconfig b/fs/jbd2/Kconfig index 0f7d1ceafdfd..f32f346f4b0a 100644 --- a/fs/jbd2/Kconfig +++ b/fs/jbd2/Kconfig | |||
@@ -1,7 +1,6 @@ | |||
1 | config JBD2 | 1 | config JBD2 |
2 | tristate | 2 | tristate |
3 | select CRC32 | 3 | select CRC32 |
4 | select FS_JOURNAL_INFO | ||
5 | help | 4 | help |
6 | This is a generic journaling layer for block devices that support | 5 | This is a generic journaling layer for block devices that support |
7 | both 32-bit and 64-bit block numbers. It is currently used by | 6 | both 32-bit and 64-bit block numbers. It is currently used by |
diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c index ca0f5eb62b20..886849370950 100644 --- a/fs/jbd2/checkpoint.c +++ b/fs/jbd2/checkpoint.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/jbd2.h> | 22 | #include <linux/jbd2.h> |
23 | #include <linux/errno.h> | 23 | #include <linux/errno.h> |
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/blkdev.h> | ||
25 | #include <trace/events/jbd2.h> | 26 | #include <trace/events/jbd2.h> |
26 | 27 | ||
27 | /* | 28 | /* |
@@ -515,6 +516,20 @@ int jbd2_cleanup_journal_tail(journal_t *journal) | |||
515 | journal->j_tail_sequence = first_tid; | 516 | journal->j_tail_sequence = first_tid; |
516 | journal->j_tail = blocknr; | 517 | journal->j_tail = blocknr; |
517 | spin_unlock(&journal->j_state_lock); | 518 | spin_unlock(&journal->j_state_lock); |
519 | |||
520 | /* | ||
521 | * If there is an external journal, we need to make sure that | ||
522 | * any data blocks that were recently written out --- perhaps | ||
523 | * by jbd2_log_do_checkpoint() --- are flushed out before we | ||
524 | * drop the transactions from the external journal. It's | ||
525 | * unlikely this will be necessary, especially with a | ||
526 | * appropriately sized journal, but we need this to guarantee | ||
527 | * correctness. Fortunately jbd2_cleanup_journal_tail() | ||
528 | * doesn't get called all that often. | ||
529 | */ | ||
530 | if ((journal->j_fs_dev != journal->j_dev) && | ||
531 | (journal->j_flags & JBD2_BARRIER)) | ||
532 | blkdev_issue_flush(journal->j_fs_dev, NULL); | ||
518 | if (!(journal->j_flags & JBD2_ABORT)) | 533 | if (!(journal->j_flags & JBD2_ABORT)) |
519 | jbd2_journal_update_superblock(journal, 1); | 534 | jbd2_journal_update_superblock(journal, 1); |
520 | return 0; | 535 | return 0; |
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 6a10238d2c63..1bc74b6f26d2 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c | |||
@@ -259,6 +259,7 @@ static int journal_submit_data_buffers(journal_t *journal, | |||
259 | ret = err; | 259 | ret = err; |
260 | spin_lock(&journal->j_list_lock); | 260 | spin_lock(&journal->j_list_lock); |
261 | J_ASSERT(jinode->i_transaction == commit_transaction); | 261 | J_ASSERT(jinode->i_transaction == commit_transaction); |
262 | commit_transaction->t_flushed_data_blocks = 1; | ||
262 | jinode->i_flags &= ~JI_COMMIT_RUNNING; | 263 | jinode->i_flags &= ~JI_COMMIT_RUNNING; |
263 | wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING); | 264 | wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING); |
264 | } | 265 | } |
@@ -708,8 +709,17 @@ start_journal_io: | |||
708 | } | 709 | } |
709 | } | 710 | } |
710 | 711 | ||
711 | /* Done it all: now write the commit record asynchronously. */ | 712 | /* |
713 | * If the journal is not located on the file system device, | ||
714 | * then we must flush the file system device before we issue | ||
715 | * the commit record | ||
716 | */ | ||
717 | if (commit_transaction->t_flushed_data_blocks && | ||
718 | (journal->j_fs_dev != journal->j_dev) && | ||
719 | (journal->j_flags & JBD2_BARRIER)) | ||
720 | blkdev_issue_flush(journal->j_fs_dev, NULL); | ||
712 | 721 | ||
722 | /* Done it all: now write the commit record asynchronously. */ | ||
713 | if (JBD2_HAS_INCOMPAT_FEATURE(journal, | 723 | if (JBD2_HAS_INCOMPAT_FEATURE(journal, |
714 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) { | 724 | JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) { |
715 | err = journal_submit_commit_record(journal, commit_transaction, | 725 | err = journal_submit_commit_record(journal, commit_transaction, |
@@ -720,13 +730,6 @@ start_journal_io: | |||
720 | blkdev_issue_flush(journal->j_dev, NULL); | 730 | blkdev_issue_flush(journal->j_dev, NULL); |
721 | } | 731 | } |
722 | 732 | ||
723 | /* | ||
724 | * This is the right place to wait for data buffers both for ASYNC | ||
725 | * and !ASYNC commit. If commit is ASYNC, we need to wait only after | ||
726 | * the commit block went to disk (which happens above). If commit is | ||
727 | * SYNC, we need to wait for data buffers before we start writing | ||
728 | * commit block, which happens below in such setting. | ||
729 | */ | ||
730 | err = journal_finish_inode_data_buffers(journal, commit_transaction); | 733 | err = journal_finish_inode_data_buffers(journal, commit_transaction); |
731 | if (err) { | 734 | if (err) { |
732 | printk(KERN_WARNING | 735 | printk(KERN_WARNING |
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index b7ca3a92a4db..ac0d027595d0 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c | |||
@@ -814,7 +814,7 @@ static journal_t * journal_init_common (void) | |||
814 | journal_t *journal; | 814 | journal_t *journal; |
815 | int err; | 815 | int err; |
816 | 816 | ||
817 | journal = kzalloc(sizeof(*journal), GFP_KERNEL|__GFP_NOFAIL); | 817 | journal = kzalloc(sizeof(*journal), GFP_KERNEL); |
818 | if (!journal) | 818 | if (!journal) |
819 | goto fail; | 819 | goto fail; |
820 | 820 | ||
@@ -2115,7 +2115,8 @@ static void __init jbd2_create_debugfs_entry(void) | |||
2115 | { | 2115 | { |
2116 | jbd2_debugfs_dir = debugfs_create_dir("jbd2", NULL); | 2116 | jbd2_debugfs_dir = debugfs_create_dir("jbd2", NULL); |
2117 | if (jbd2_debugfs_dir) | 2117 | if (jbd2_debugfs_dir) |
2118 | jbd2_debug = debugfs_create_u8(JBD2_DEBUG_NAME, S_IRUGO, | 2118 | jbd2_debug = debugfs_create_u8(JBD2_DEBUG_NAME, |
2119 | S_IRUGO | S_IWUSR, | ||
2119 | jbd2_debugfs_dir, | 2120 | jbd2_debugfs_dir, |
2120 | &jbd2_journal_enable_debug); | 2121 | &jbd2_journal_enable_debug); |
2121 | } | 2122 | } |
diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c index f26e4d03ada5..d945ea76b445 100644 --- a/fs/jfs/jfs_txnmgr.c +++ b/fs/jfs/jfs_txnmgr.c | |||
@@ -1292,7 +1292,7 @@ int txCommit(tid_t tid, /* transaction identifier */ | |||
1292 | */ | 1292 | */ |
1293 | /* | 1293 | /* |
1294 | * I believe this code is no longer needed. Splitting I_LOCK | 1294 | * I believe this code is no longer needed. Splitting I_LOCK |
1295 | * into two bits, I_LOCK and I_SYNC should prevent this | 1295 | * into two bits, I_NEW and I_SYNC should prevent this |
1296 | * deadlock as well. But since I don't have a JFS testload | 1296 | * deadlock as well. But since I don't have a JFS testload |
1297 | * to verify this, only a trivial s/I_LOCK/I_SYNC/ was done. | 1297 | * to verify this, only a trivial s/I_LOCK/I_SYNC/ was done. |
1298 | * Joern | 1298 | * Joern |
diff --git a/fs/jfs/super.c b/fs/jfs/super.c index 2234c73fc577..d929a822a74e 100644 --- a/fs/jfs/super.c +++ b/fs/jfs/super.c | |||
@@ -524,7 +524,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent) | |||
524 | * Page cache is indexed by long. | 524 | * Page cache is indexed by long. |
525 | * I would use MAX_LFS_FILESIZE, but it's only half as big | 525 | * I would use MAX_LFS_FILESIZE, but it's only half as big |
526 | */ | 526 | */ |
527 | sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, sb->s_maxbytes); | 527 | sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, (u64)sb->s_maxbytes); |
528 | #endif | 528 | #endif |
529 | sb->s_time_gran = 1; | 529 | sb->s_time_gran = 1; |
530 | return 0; | 530 | return 0; |
diff --git a/fs/namei.c b/fs/namei.c index d2783c8a770b..b55440baf7ab 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -37,8 +37,6 @@ | |||
37 | 37 | ||
38 | #include "internal.h" | 38 | #include "internal.h" |
39 | 39 | ||
40 | #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) | ||
41 | |||
42 | /* [Feb-1997 T. Schoebel-Theuer] | 40 | /* [Feb-1997 T. Schoebel-Theuer] |
43 | * Fundamental changes in the pathname lookup mechanisms (namei) | 41 | * Fundamental changes in the pathname lookup mechanisms (namei) |
44 | * were necessary because of omirr. The reason is that omirr needs | 42 | * were necessary because of omirr. The reason is that omirr needs |
@@ -234,6 +232,7 @@ int generic_permission(struct inode *inode, int mask, | |||
234 | /* | 232 | /* |
235 | * Searching includes executable on directories, else just read. | 233 | * Searching includes executable on directories, else just read. |
236 | */ | 234 | */ |
235 | mask &= MAY_READ | MAY_WRITE | MAY_EXEC; | ||
237 | if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE))) | 236 | if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE))) |
238 | if (capable(CAP_DAC_READ_SEARCH)) | 237 | if (capable(CAP_DAC_READ_SEARCH)) |
239 | return 0; | 238 | return 0; |
@@ -1640,6 +1639,7 @@ struct file *do_filp_open(int dfd, const char *pathname, | |||
1640 | if (filp == NULL) | 1639 | if (filp == NULL) |
1641 | return ERR_PTR(-ENFILE); | 1640 | return ERR_PTR(-ENFILE); |
1642 | nd.intent.open.file = filp; | 1641 | nd.intent.open.file = filp; |
1642 | filp->f_flags = open_flag; | ||
1643 | nd.intent.open.flags = flag; | 1643 | nd.intent.open.flags = flag; |
1644 | nd.intent.open.create_mode = 0; | 1644 | nd.intent.open.create_mode = 0; |
1645 | error = do_path_lookup(dfd, pathname, | 1645 | error = do_path_lookup(dfd, pathname, |
@@ -1685,6 +1685,7 @@ struct file *do_filp_open(int dfd, const char *pathname, | |||
1685 | if (filp == NULL) | 1685 | if (filp == NULL) |
1686 | goto exit_parent; | 1686 | goto exit_parent; |
1687 | nd.intent.open.file = filp; | 1687 | nd.intent.open.file = filp; |
1688 | filp->f_flags = open_flag; | ||
1688 | nd.intent.open.flags = flag; | 1689 | nd.intent.open.flags = flag; |
1689 | nd.intent.open.create_mode = mode; | 1690 | nd.intent.open.create_mode = mode; |
1690 | dir = nd.path.dentry; | 1691 | dir = nd.path.dentry; |
@@ -1725,7 +1726,7 @@ do_last: | |||
1725 | mnt_drop_write(nd.path.mnt); | 1726 | mnt_drop_write(nd.path.mnt); |
1726 | goto exit; | 1727 | goto exit; |
1727 | } | 1728 | } |
1728 | filp = nameidata_to_filp(&nd, open_flag); | 1729 | filp = nameidata_to_filp(&nd); |
1729 | mnt_drop_write(nd.path.mnt); | 1730 | mnt_drop_write(nd.path.mnt); |
1730 | if (nd.root.mnt) | 1731 | if (nd.root.mnt) |
1731 | path_put(&nd.root); | 1732 | path_put(&nd.root); |
@@ -1764,7 +1765,7 @@ do_last: | |||
1764 | 1765 | ||
1765 | path_to_nameidata(&path, &nd); | 1766 | path_to_nameidata(&path, &nd); |
1766 | error = -EISDIR; | 1767 | error = -EISDIR; |
1767 | if (path.dentry->d_inode && S_ISDIR(path.dentry->d_inode->i_mode)) | 1768 | if (S_ISDIR(path.dentry->d_inode->i_mode)) |
1768 | goto exit; | 1769 | goto exit; |
1769 | ok: | 1770 | ok: |
1770 | /* | 1771 | /* |
@@ -1789,7 +1790,7 @@ ok: | |||
1789 | mnt_drop_write(nd.path.mnt); | 1790 | mnt_drop_write(nd.path.mnt); |
1790 | goto exit; | 1791 | goto exit; |
1791 | } | 1792 | } |
1792 | filp = nameidata_to_filp(&nd, open_flag); | 1793 | filp = nameidata_to_filp(&nd); |
1793 | if (!IS_ERR(filp)) { | 1794 | if (!IS_ERR(filp)) { |
1794 | error = ima_path_check(&filp->f_path, filp->f_mode & | 1795 | error = ima_path_check(&filp->f_path, filp->f_mode & |
1795 | (MAY_READ | MAY_WRITE | MAY_EXEC)); | 1796 | (MAY_READ | MAY_WRITE | MAY_EXEC)); |
diff --git a/fs/namespace.c b/fs/namespace.c index faab1273281e..7d70d63ceb29 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -2068,7 +2068,7 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns, | |||
2068 | * create_mnt_ns - creates a private namespace and adds a root filesystem | 2068 | * create_mnt_ns - creates a private namespace and adds a root filesystem |
2069 | * @mnt: pointer to the new root filesystem mountpoint | 2069 | * @mnt: pointer to the new root filesystem mountpoint |
2070 | */ | 2070 | */ |
2071 | static struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt) | 2071 | struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt) |
2072 | { | 2072 | { |
2073 | struct mnt_namespace *new_ns; | 2073 | struct mnt_namespace *new_ns; |
2074 | 2074 | ||
@@ -2080,6 +2080,7 @@ static struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt) | |||
2080 | } | 2080 | } |
2081 | return new_ns; | 2081 | return new_ns; |
2082 | } | 2082 | } |
2083 | EXPORT_SYMBOL(create_mnt_ns); | ||
2083 | 2084 | ||
2084 | SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, | 2085 | SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, |
2085 | char __user *, type, unsigned long, flags, void __user *, data) | 2086 | char __user *, type, unsigned long, flags, void __user *, data) |
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 2c5ace4f00a7..3c7f03b669fb 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c | |||
@@ -1615,6 +1615,7 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1615 | goto out; | 1615 | goto out; |
1616 | 1616 | ||
1617 | new_dentry = dentry; | 1617 | new_dentry = dentry; |
1618 | rehash = NULL; | ||
1618 | new_inode = NULL; | 1619 | new_inode = NULL; |
1619 | } | 1620 | } |
1620 | } | 1621 | } |
diff --git a/fs/nfs/super.c b/fs/nfs/super.c index d5b112bcf3de..ce907efc5508 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
@@ -2648,13 +2648,21 @@ out_freepage: | |||
2648 | static int nfs_follow_remote_path(struct vfsmount *root_mnt, | 2648 | static int nfs_follow_remote_path(struct vfsmount *root_mnt, |
2649 | const char *export_path, struct vfsmount *mnt_target) | 2649 | const char *export_path, struct vfsmount *mnt_target) |
2650 | { | 2650 | { |
2651 | struct mnt_namespace *ns_private; | ||
2651 | struct nameidata nd; | 2652 | struct nameidata nd; |
2652 | struct super_block *s; | 2653 | struct super_block *s; |
2653 | int ret; | 2654 | int ret; |
2654 | 2655 | ||
2656 | ns_private = create_mnt_ns(root_mnt); | ||
2657 | ret = PTR_ERR(ns_private); | ||
2658 | if (IS_ERR(ns_private)) | ||
2659 | goto out_mntput; | ||
2660 | |||
2655 | ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt, | 2661 | ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt, |
2656 | export_path, LOOKUP_FOLLOW, &nd); | 2662 | export_path, LOOKUP_FOLLOW, &nd); |
2657 | 2663 | ||
2664 | put_mnt_ns(ns_private); | ||
2665 | |||
2658 | if (ret != 0) | 2666 | if (ret != 0) |
2659 | goto out_err; | 2667 | goto out_err; |
2660 | 2668 | ||
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c index 1c12177b908c..55c8e63af0be 100644 --- a/fs/nfsd/nfsfh.c +++ b/fs/nfsd/nfsfh.c | |||
@@ -89,7 +89,7 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp, | |||
89 | int flags = nfsexp_flags(rqstp, exp); | 89 | int flags = nfsexp_flags(rqstp, exp); |
90 | 90 | ||
91 | /* Check if the request originated from a secure port. */ | 91 | /* Check if the request originated from a secure port. */ |
92 | if (!rqstp->rq_secure && (flags & NFSEXP_INSECURE_PORT)) { | 92 | if (!rqstp->rq_secure && !(flags & NFSEXP_INSECURE_PORT)) { |
93 | RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]); | 93 | RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]); |
94 | dprintk(KERN_WARNING | 94 | dprintk(KERN_WARNING |
95 | "nfsd: request from insecure port %s!\n", | 95 | "nfsd: request from insecure port %s!\n", |
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 7c2e337d05af..c194793b642b 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c | |||
@@ -780,12 +780,9 @@ static inline int nfsd_dosync(struct file *filp, struct dentry *dp, | |||
780 | int (*fsync) (struct file *, struct dentry *, int); | 780 | int (*fsync) (struct file *, struct dentry *, int); |
781 | int err; | 781 | int err; |
782 | 782 | ||
783 | err = filemap_fdatawrite(inode->i_mapping); | 783 | err = filemap_write_and_wait(inode->i_mapping); |
784 | if (err == 0 && fop && (fsync = fop->fsync)) | 784 | if (err == 0 && fop && (fsync = fop->fsync)) |
785 | err = fsync(filp, dp, 0); | 785 | err = fsync(filp, dp, 0); |
786 | if (err == 0) | ||
787 | err = filemap_fdatawait(inode->i_mapping); | ||
788 | |||
789 | return err; | 786 | return err; |
790 | } | 787 | } |
791 | 788 | ||
diff --git a/fs/nilfs2/Kconfig b/fs/nilfs2/Kconfig index 1225af7b2166..251da07b2a1d 100644 --- a/fs/nilfs2/Kconfig +++ b/fs/nilfs2/Kconfig | |||
@@ -2,7 +2,6 @@ config NILFS2_FS | |||
2 | tristate "NILFS2 file system support (EXPERIMENTAL)" | 2 | tristate "NILFS2 file system support (EXPERIMENTAL)" |
3 | depends on EXPERIMENTAL | 3 | depends on EXPERIMENTAL |
4 | select CRC32 | 4 | select CRC32 |
5 | select FS_JOURNAL_INFO | ||
6 | help | 5 | help |
7 | NILFS2 is a log-structured file system (LFS) supporting continuous | 6 | NILFS2 is a log-structured file system (LFS) supporting continuous |
8 | snapshotting. In addition to versioning capability of the entire | 7 | snapshotting. In addition to versioning capability of the entire |
diff --git a/fs/nilfs2/bmap.c b/fs/nilfs2/bmap.c index f4a14ea2ed9c..effdbdbe6c11 100644 --- a/fs/nilfs2/bmap.c +++ b/fs/nilfs2/bmap.c | |||
@@ -417,8 +417,8 @@ __u64 nilfs_bmap_data_get_key(const struct nilfs_bmap *bmap, | |||
417 | 417 | ||
418 | key = page_index(bh->b_page) << (PAGE_CACHE_SHIFT - | 418 | key = page_index(bh->b_page) << (PAGE_CACHE_SHIFT - |
419 | bmap->b_inode->i_blkbits); | 419 | bmap->b_inode->i_blkbits); |
420 | for (pbh = page_buffers(bh->b_page); pbh != bh; | 420 | for (pbh = page_buffers(bh->b_page); pbh != bh; pbh = pbh->b_this_page) |
421 | pbh = pbh->b_this_page, key++); | 421 | key++; |
422 | 422 | ||
423 | return key; | 423 | return key; |
424 | } | 424 | } |
diff --git a/fs/nilfs2/cpfile.c b/fs/nilfs2/cpfile.c index d5ad54e204a5..18737818db63 100644 --- a/fs/nilfs2/cpfile.c +++ b/fs/nilfs2/cpfile.c | |||
@@ -328,19 +328,24 @@ int nilfs_cpfile_delete_checkpoints(struct inode *cpfile, | |||
328 | tnicps += nicps; | 328 | tnicps += nicps; |
329 | nilfs_mdt_mark_buffer_dirty(cp_bh); | 329 | nilfs_mdt_mark_buffer_dirty(cp_bh); |
330 | nilfs_mdt_mark_dirty(cpfile); | 330 | nilfs_mdt_mark_dirty(cpfile); |
331 | if (!nilfs_cpfile_is_in_first(cpfile, cno) && | 331 | if (!nilfs_cpfile_is_in_first(cpfile, cno)) { |
332 | (count = nilfs_cpfile_block_sub_valid_checkpoints( | 332 | count = |
333 | cpfile, cp_bh, kaddr, nicps)) == 0) { | 333 | nilfs_cpfile_block_sub_valid_checkpoints( |
334 | /* make hole */ | 334 | cpfile, cp_bh, kaddr, nicps); |
335 | kunmap_atomic(kaddr, KM_USER0); | 335 | if (count == 0) { |
336 | brelse(cp_bh); | 336 | /* make hole */ |
337 | ret = nilfs_cpfile_delete_checkpoint_block( | 337 | kunmap_atomic(kaddr, KM_USER0); |
338 | cpfile, cno); | 338 | brelse(cp_bh); |
339 | if (ret == 0) | 339 | ret = |
340 | continue; | 340 | nilfs_cpfile_delete_checkpoint_block( |
341 | printk(KERN_ERR "%s: cannot delete block\n", | 341 | cpfile, cno); |
342 | __func__); | 342 | if (ret == 0) |
343 | break; | 343 | continue; |
344 | printk(KERN_ERR | ||
345 | "%s: cannot delete block\n", | ||
346 | __func__); | ||
347 | break; | ||
348 | } | ||
344 | } | 349 | } |
345 | } | 350 | } |
346 | 351 | ||
diff --git a/fs/nilfs2/direct.c b/fs/nilfs2/direct.c index d369ac718277..236753df5cdf 100644 --- a/fs/nilfs2/direct.c +++ b/fs/nilfs2/direct.c | |||
@@ -51,11 +51,11 @@ static int nilfs_direct_lookup(const struct nilfs_bmap *bmap, | |||
51 | struct nilfs_direct *direct; | 51 | struct nilfs_direct *direct; |
52 | __u64 ptr; | 52 | __u64 ptr; |
53 | 53 | ||
54 | direct = (struct nilfs_direct *)bmap; | 54 | direct = (struct nilfs_direct *)bmap; /* XXX: use macro for level 1 */ |
55 | if ((key > NILFS_DIRECT_KEY_MAX) || | 55 | if (key > NILFS_DIRECT_KEY_MAX || level != 1) |
56 | (level != 1) || /* XXX: use macro for level 1 */ | 56 | return -ENOENT; |
57 | ((ptr = nilfs_direct_get_ptr(direct, key)) == | 57 | ptr = nilfs_direct_get_ptr(direct, key); |
58 | NILFS_BMAP_INVALID_PTR)) | 58 | if (ptr == NILFS_BMAP_INVALID_PTR) |
59 | return -ENOENT; | 59 | return -ENOENT; |
60 | 60 | ||
61 | if (ptrp != NULL) | 61 | if (ptrp != NULL) |
@@ -73,9 +73,10 @@ static int nilfs_direct_lookup_contig(const struct nilfs_bmap *bmap, | |||
73 | sector_t blocknr; | 73 | sector_t blocknr; |
74 | int ret, cnt; | 74 | int ret, cnt; |
75 | 75 | ||
76 | if (key > NILFS_DIRECT_KEY_MAX || | 76 | if (key > NILFS_DIRECT_KEY_MAX) |
77 | (ptr = nilfs_direct_get_ptr(direct, key)) == | 77 | return -ENOENT; |
78 | NILFS_BMAP_INVALID_PTR) | 78 | ptr = nilfs_direct_get_ptr(direct, key); |
79 | if (ptr == NILFS_BMAP_INVALID_PTR) | ||
79 | return -ENOENT; | 80 | return -ENOENT; |
80 | 81 | ||
81 | if (NILFS_BMAP_USE_VBN(bmap)) { | 82 | if (NILFS_BMAP_USE_VBN(bmap)) { |
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c index f6af76042d80..d6b2b83de363 100644 --- a/fs/nilfs2/ioctl.c +++ b/fs/nilfs2/ioctl.c | |||
@@ -480,7 +480,7 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp, | |||
480 | unsigned int cmd, void __user *argp) | 480 | unsigned int cmd, void __user *argp) |
481 | { | 481 | { |
482 | struct nilfs_argv argv[5]; | 482 | struct nilfs_argv argv[5]; |
483 | const static size_t argsz[5] = { | 483 | static const size_t argsz[5] = { |
484 | sizeof(struct nilfs_vdesc), | 484 | sizeof(struct nilfs_vdesc), |
485 | sizeof(struct nilfs_period), | 485 | sizeof(struct nilfs_period), |
486 | sizeof(__u64), | 486 | sizeof(__u64), |
diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 9938034762cc..dc2505abb6d7 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c | |||
@@ -530,7 +530,7 @@ err_corrupt_attr: | |||
530 | * the ntfs inode. | 530 | * the ntfs inode. |
531 | * | 531 | * |
532 | * Q: What locks are held when the function is called? | 532 | * Q: What locks are held when the function is called? |
533 | * A: i_state has I_LOCK set, hence the inode is locked, also | 533 | * A: i_state has I_NEW set, hence the inode is locked, also |
534 | * i_count is set to 1, so it is not going to go away | 534 | * i_count is set to 1, so it is not going to go away |
535 | * i_flags is set to 0 and we have no business touching it. Only an ioctl() | 535 | * i_flags is set to 0 and we have no business touching it. Only an ioctl() |
536 | * is allowed to write to them. We should of course be honouring them but | 536 | * is allowed to write to them. We should of course be honouring them but |
@@ -1207,7 +1207,7 @@ err_out: | |||
1207 | * necessary fields in @vi as well as initializing the ntfs inode. | 1207 | * necessary fields in @vi as well as initializing the ntfs inode. |
1208 | * | 1208 | * |
1209 | * Q: What locks are held when the function is called? | 1209 | * Q: What locks are held when the function is called? |
1210 | * A: i_state has I_LOCK set, hence the inode is locked, also | 1210 | * A: i_state has I_NEW set, hence the inode is locked, also |
1211 | * i_count is set to 1, so it is not going to go away | 1211 | * i_count is set to 1, so it is not going to go away |
1212 | * | 1212 | * |
1213 | * Return 0 on success and -errno on error. In the error case, the inode will | 1213 | * Return 0 on success and -errno on error. In the error case, the inode will |
@@ -1474,7 +1474,7 @@ err_out: | |||
1474 | * normal directory inodes. | 1474 | * normal directory inodes. |
1475 | * | 1475 | * |
1476 | * Q: What locks are held when the function is called? | 1476 | * Q: What locks are held when the function is called? |
1477 | * A: i_state has I_LOCK set, hence the inode is locked, also | 1477 | * A: i_state has I_NEW set, hence the inode is locked, also |
1478 | * i_count is set to 1, so it is not going to go away | 1478 | * i_count is set to 1, so it is not going to go away |
1479 | * | 1479 | * |
1480 | * Return 0 on success and -errno on error. In the error case, the inode will | 1480 | * Return 0 on success and -errno on error. In the error case, the inode will |
diff --git a/fs/ocfs2/Kconfig b/fs/ocfs2/Kconfig index 701b7a3a872e..0d840669698e 100644 --- a/fs/ocfs2/Kconfig +++ b/fs/ocfs2/Kconfig | |||
@@ -6,6 +6,7 @@ config OCFS2_FS | |||
6 | select CRC32 | 6 | select CRC32 |
7 | select QUOTA | 7 | select QUOTA |
8 | select QUOTA_TREE | 8 | select QUOTA_TREE |
9 | select FS_POSIX_ACL | ||
9 | help | 10 | help |
10 | OCFS2 is a general purpose extent based shared disk cluster file | 11 | OCFS2 is a general purpose extent based shared disk cluster file |
11 | system with many similarities to ext3. It supports 64 bit inode | 12 | system with many similarities to ext3. It supports 64 bit inode |
@@ -74,12 +75,3 @@ config OCFS2_DEBUG_FS | |||
74 | This option will enable expensive consistency checks. Enable | 75 | This option will enable expensive consistency checks. Enable |
75 | this option for debugging only as it is likely to decrease | 76 | this option for debugging only as it is likely to decrease |
76 | performance of the filesystem. | 77 | performance of the filesystem. |
77 | |||
78 | config OCFS2_FS_POSIX_ACL | ||
79 | bool "OCFS2 POSIX Access Control Lists" | ||
80 | depends on OCFS2_FS | ||
81 | select FS_POSIX_ACL | ||
82 | default n | ||
83 | help | ||
84 | Posix Access Control Lists (ACLs) support permissions for users and | ||
85 | groups beyond the owner/group/world scheme. | ||
diff --git a/fs/ocfs2/Makefile b/fs/ocfs2/Makefile index 31f25ce32c97..600d2d2ade11 100644 --- a/fs/ocfs2/Makefile +++ b/fs/ocfs2/Makefile | |||
@@ -39,11 +39,8 @@ ocfs2-objs := \ | |||
39 | ver.o \ | 39 | ver.o \ |
40 | quota_local.o \ | 40 | quota_local.o \ |
41 | quota_global.o \ | 41 | quota_global.o \ |
42 | xattr.o | 42 | xattr.o \ |
43 | 43 | acl.o | |
44 | ifeq ($(CONFIG_OCFS2_FS_POSIX_ACL),y) | ||
45 | ocfs2-objs += acl.o | ||
46 | endif | ||
47 | 44 | ||
48 | ocfs2_stackglue-objs := stackglue.o | 45 | ocfs2_stackglue-objs := stackglue.o |
49 | ocfs2_stack_o2cb-objs := stack_o2cb.o | 46 | ocfs2_stack_o2cb-objs := stack_o2cb.o |
diff --git a/fs/ocfs2/acl.c b/fs/ocfs2/acl.c index e3e47415d851..0501974bedd0 100644 --- a/fs/ocfs2/acl.c +++ b/fs/ocfs2/acl.c | |||
@@ -98,15 +98,11 @@ static struct posix_acl *ocfs2_get_acl_nolock(struct inode *inode, | |||
98 | int type, | 98 | int type, |
99 | struct buffer_head *di_bh) | 99 | struct buffer_head *di_bh) |
100 | { | 100 | { |
101 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | ||
102 | int name_index; | 101 | int name_index; |
103 | char *value = NULL; | 102 | char *value = NULL; |
104 | struct posix_acl *acl; | 103 | struct posix_acl *acl; |
105 | int retval; | 104 | int retval; |
106 | 105 | ||
107 | if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) | ||
108 | return NULL; | ||
109 | |||
110 | switch (type) { | 106 | switch (type) { |
111 | case ACL_TYPE_ACCESS: | 107 | case ACL_TYPE_ACCESS: |
112 | name_index = OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS; | 108 | name_index = OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS; |
diff --git a/fs/ocfs2/acl.h b/fs/ocfs2/acl.h index 8f6389ed4da5..5c5d31f05853 100644 --- a/fs/ocfs2/acl.h +++ b/fs/ocfs2/acl.h | |||
@@ -26,8 +26,6 @@ struct ocfs2_acl_entry { | |||
26 | __le32 e_id; | 26 | __le32 e_id; |
27 | }; | 27 | }; |
28 | 28 | ||
29 | #ifdef CONFIG_OCFS2_FS_POSIX_ACL | ||
30 | |||
31 | extern int ocfs2_check_acl(struct inode *, int); | 29 | extern int ocfs2_check_acl(struct inode *, int); |
32 | extern int ocfs2_acl_chmod(struct inode *); | 30 | extern int ocfs2_acl_chmod(struct inode *); |
33 | extern int ocfs2_init_acl(handle_t *, struct inode *, struct inode *, | 31 | extern int ocfs2_init_acl(handle_t *, struct inode *, struct inode *, |
@@ -35,24 +33,4 @@ extern int ocfs2_init_acl(handle_t *, struct inode *, struct inode *, | |||
35 | struct ocfs2_alloc_context *, | 33 | struct ocfs2_alloc_context *, |
36 | struct ocfs2_alloc_context *); | 34 | struct ocfs2_alloc_context *); |
37 | 35 | ||
38 | #else /* CONFIG_OCFS2_FS_POSIX_ACL*/ | ||
39 | |||
40 | #define ocfs2_check_acl NULL | ||
41 | static inline int ocfs2_acl_chmod(struct inode *inode) | ||
42 | { | ||
43 | return 0; | ||
44 | } | ||
45 | static inline int ocfs2_init_acl(handle_t *handle, | ||
46 | struct inode *inode, | ||
47 | struct inode *dir, | ||
48 | struct buffer_head *di_bh, | ||
49 | struct buffer_head *dir_bh, | ||
50 | struct ocfs2_alloc_context *meta_ac, | ||
51 | struct ocfs2_alloc_context *data_ac) | ||
52 | { | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | #endif /* CONFIG_OCFS2_FS_POSIX_ACL*/ | ||
57 | |||
58 | #endif /* OCFS2_ACL_H */ | 36 | #endif /* OCFS2_ACL_H */ |
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index fb4e672579b8..d17bdc718f74 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c | |||
@@ -1765,9 +1765,9 @@ set_and_inc: | |||
1765 | * | 1765 | * |
1766 | * The array index of the subtree root is passed back. | 1766 | * The array index of the subtree root is passed back. |
1767 | */ | 1767 | */ |
1768 | static int ocfs2_find_subtree_root(struct ocfs2_extent_tree *et, | 1768 | int ocfs2_find_subtree_root(struct ocfs2_extent_tree *et, |
1769 | struct ocfs2_path *left, | 1769 | struct ocfs2_path *left, |
1770 | struct ocfs2_path *right) | 1770 | struct ocfs2_path *right) |
1771 | { | 1771 | { |
1772 | int i = 0; | 1772 | int i = 0; |
1773 | 1773 | ||
@@ -2872,8 +2872,8 @@ out: | |||
2872 | * This looks similar, but is subtly different to | 2872 | * This looks similar, but is subtly different to |
2873 | * ocfs2_find_cpos_for_left_leaf(). | 2873 | * ocfs2_find_cpos_for_left_leaf(). |
2874 | */ | 2874 | */ |
2875 | static int ocfs2_find_cpos_for_right_leaf(struct super_block *sb, | 2875 | int ocfs2_find_cpos_for_right_leaf(struct super_block *sb, |
2876 | struct ocfs2_path *path, u32 *cpos) | 2876 | struct ocfs2_path *path, u32 *cpos) |
2877 | { | 2877 | { |
2878 | int i, j, ret = 0; | 2878 | int i, j, ret = 0; |
2879 | u64 blkno; | 2879 | u64 blkno; |
diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h index 9c122d574464..1db4359ccb90 100644 --- a/fs/ocfs2/alloc.h +++ b/fs/ocfs2/alloc.h | |||
@@ -317,4 +317,9 @@ int ocfs2_path_bh_journal_access(handle_t *handle, | |||
317 | int ocfs2_journal_access_path(struct ocfs2_caching_info *ci, | 317 | int ocfs2_journal_access_path(struct ocfs2_caching_info *ci, |
318 | handle_t *handle, | 318 | handle_t *handle, |
319 | struct ocfs2_path *path); | 319 | struct ocfs2_path *path); |
320 | int ocfs2_find_cpos_for_right_leaf(struct super_block *sb, | ||
321 | struct ocfs2_path *path, u32 *cpos); | ||
322 | int ocfs2_find_subtree_root(struct ocfs2_extent_tree *et, | ||
323 | struct ocfs2_path *left, | ||
324 | struct ocfs2_path *right); | ||
320 | #endif /* OCFS2_ALLOC_H */ | 325 | #endif /* OCFS2_ALLOC_H */ |
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c index c452d116b892..eda5b8bcddd5 100644 --- a/fs/ocfs2/cluster/heartbeat.c +++ b/fs/ocfs2/cluster/heartbeat.c | |||
@@ -176,7 +176,8 @@ static void o2hb_write_timeout(struct work_struct *work) | |||
176 | 176 | ||
177 | static void o2hb_arm_write_timeout(struct o2hb_region *reg) | 177 | static void o2hb_arm_write_timeout(struct o2hb_region *reg) |
178 | { | 178 | { |
179 | mlog(0, "Queue write timeout for %u ms\n", O2HB_MAX_WRITE_TIMEOUT_MS); | 179 | mlog(ML_HEARTBEAT, "Queue write timeout for %u ms\n", |
180 | O2HB_MAX_WRITE_TIMEOUT_MS); | ||
180 | 181 | ||
181 | cancel_delayed_work(®->hr_write_timeout_work); | 182 | cancel_delayed_work(®->hr_write_timeout_work); |
182 | reg->hr_last_timeout_start = jiffies; | 183 | reg->hr_last_timeout_start = jiffies; |
@@ -874,7 +875,8 @@ static int o2hb_thread(void *data) | |||
874 | do_gettimeofday(&after_hb); | 875 | do_gettimeofday(&after_hb); |
875 | elapsed_msec = o2hb_elapsed_msecs(&before_hb, &after_hb); | 876 | elapsed_msec = o2hb_elapsed_msecs(&before_hb, &after_hb); |
876 | 877 | ||
877 | mlog(0, "start = %lu.%lu, end = %lu.%lu, msec = %u\n", | 878 | mlog(ML_HEARTBEAT, |
879 | "start = %lu.%lu, end = %lu.%lu, msec = %u\n", | ||
878 | before_hb.tv_sec, (unsigned long) before_hb.tv_usec, | 880 | before_hb.tv_sec, (unsigned long) before_hb.tv_usec, |
879 | after_hb.tv_sec, (unsigned long) after_hb.tv_usec, | 881 | after_hb.tv_sec, (unsigned long) after_hb.tv_usec, |
880 | elapsed_msec); | 882 | elapsed_msec); |
diff --git a/fs/ocfs2/cluster/nodemanager.c b/fs/ocfs2/cluster/nodemanager.c index 7ee6188bc79a..c81142e3ef84 100644 --- a/fs/ocfs2/cluster/nodemanager.c +++ b/fs/ocfs2/cluster/nodemanager.c | |||
@@ -35,6 +35,10 @@ | |||
35 | * cluster references throughout where nodes are looked up */ | 35 | * cluster references throughout where nodes are looked up */ |
36 | struct o2nm_cluster *o2nm_single_cluster = NULL; | 36 | struct o2nm_cluster *o2nm_single_cluster = NULL; |
37 | 37 | ||
38 | char *o2nm_fence_method_desc[O2NM_FENCE_METHODS] = { | ||
39 | "reset", /* O2NM_FENCE_RESET */ | ||
40 | "panic", /* O2NM_FENCE_PANIC */ | ||
41 | }; | ||
38 | 42 | ||
39 | struct o2nm_node *o2nm_get_node_by_num(u8 node_num) | 43 | struct o2nm_node *o2nm_get_node_by_num(u8 node_num) |
40 | { | 44 | { |
@@ -579,6 +583,43 @@ static ssize_t o2nm_cluster_attr_reconnect_delay_ms_write( | |||
579 | return o2nm_cluster_attr_write(page, count, | 583 | return o2nm_cluster_attr_write(page, count, |
580 | &cluster->cl_reconnect_delay_ms); | 584 | &cluster->cl_reconnect_delay_ms); |
581 | } | 585 | } |
586 | |||
587 | static ssize_t o2nm_cluster_attr_fence_method_read( | ||
588 | struct o2nm_cluster *cluster, char *page) | ||
589 | { | ||
590 | ssize_t ret = 0; | ||
591 | |||
592 | if (cluster) | ||
593 | ret = sprintf(page, "%s\n", | ||
594 | o2nm_fence_method_desc[cluster->cl_fence_method]); | ||
595 | return ret; | ||
596 | } | ||
597 | |||
598 | static ssize_t o2nm_cluster_attr_fence_method_write( | ||
599 | struct o2nm_cluster *cluster, const char *page, size_t count) | ||
600 | { | ||
601 | unsigned int i; | ||
602 | |||
603 | if (page[count - 1] != '\n') | ||
604 | goto bail; | ||
605 | |||
606 | for (i = 0; i < O2NM_FENCE_METHODS; ++i) { | ||
607 | if (count != strlen(o2nm_fence_method_desc[i]) + 1) | ||
608 | continue; | ||
609 | if (strncasecmp(page, o2nm_fence_method_desc[i], count - 1)) | ||
610 | continue; | ||
611 | if (cluster->cl_fence_method != i) { | ||
612 | printk(KERN_INFO "ocfs2: Changing fence method to %s\n", | ||
613 | o2nm_fence_method_desc[i]); | ||
614 | cluster->cl_fence_method = i; | ||
615 | } | ||
616 | return count; | ||
617 | } | ||
618 | |||
619 | bail: | ||
620 | return -EINVAL; | ||
621 | } | ||
622 | |||
582 | static struct o2nm_cluster_attribute o2nm_cluster_attr_idle_timeout_ms = { | 623 | static struct o2nm_cluster_attribute o2nm_cluster_attr_idle_timeout_ms = { |
583 | .attr = { .ca_owner = THIS_MODULE, | 624 | .attr = { .ca_owner = THIS_MODULE, |
584 | .ca_name = "idle_timeout_ms", | 625 | .ca_name = "idle_timeout_ms", |
@@ -603,10 +644,19 @@ static struct o2nm_cluster_attribute o2nm_cluster_attr_reconnect_delay_ms = { | |||
603 | .store = o2nm_cluster_attr_reconnect_delay_ms_write, | 644 | .store = o2nm_cluster_attr_reconnect_delay_ms_write, |
604 | }; | 645 | }; |
605 | 646 | ||
647 | static struct o2nm_cluster_attribute o2nm_cluster_attr_fence_method = { | ||
648 | .attr = { .ca_owner = THIS_MODULE, | ||
649 | .ca_name = "fence_method", | ||
650 | .ca_mode = S_IRUGO | S_IWUSR }, | ||
651 | .show = o2nm_cluster_attr_fence_method_read, | ||
652 | .store = o2nm_cluster_attr_fence_method_write, | ||
653 | }; | ||
654 | |||
606 | static struct configfs_attribute *o2nm_cluster_attrs[] = { | 655 | static struct configfs_attribute *o2nm_cluster_attrs[] = { |
607 | &o2nm_cluster_attr_idle_timeout_ms.attr, | 656 | &o2nm_cluster_attr_idle_timeout_ms.attr, |
608 | &o2nm_cluster_attr_keepalive_delay_ms.attr, | 657 | &o2nm_cluster_attr_keepalive_delay_ms.attr, |
609 | &o2nm_cluster_attr_reconnect_delay_ms.attr, | 658 | &o2nm_cluster_attr_reconnect_delay_ms.attr, |
659 | &o2nm_cluster_attr_fence_method.attr, | ||
610 | NULL, | 660 | NULL, |
611 | }; | 661 | }; |
612 | static ssize_t o2nm_cluster_show(struct config_item *item, | 662 | static ssize_t o2nm_cluster_show(struct config_item *item, |
@@ -778,6 +828,7 @@ static struct config_group *o2nm_cluster_group_make_group(struct config_group *g | |||
778 | cluster->cl_reconnect_delay_ms = O2NET_RECONNECT_DELAY_MS_DEFAULT; | 828 | cluster->cl_reconnect_delay_ms = O2NET_RECONNECT_DELAY_MS_DEFAULT; |
779 | cluster->cl_idle_timeout_ms = O2NET_IDLE_TIMEOUT_MS_DEFAULT; | 829 | cluster->cl_idle_timeout_ms = O2NET_IDLE_TIMEOUT_MS_DEFAULT; |
780 | cluster->cl_keepalive_delay_ms = O2NET_KEEPALIVE_DELAY_MS_DEFAULT; | 830 | cluster->cl_keepalive_delay_ms = O2NET_KEEPALIVE_DELAY_MS_DEFAULT; |
831 | cluster->cl_fence_method = O2NM_FENCE_RESET; | ||
781 | 832 | ||
782 | ret = &cluster->cl_group; | 833 | ret = &cluster->cl_group; |
783 | o2nm_single_cluster = cluster; | 834 | o2nm_single_cluster = cluster; |
diff --git a/fs/ocfs2/cluster/nodemanager.h b/fs/ocfs2/cluster/nodemanager.h index c992ea0da4ad..09ea2d388bbb 100644 --- a/fs/ocfs2/cluster/nodemanager.h +++ b/fs/ocfs2/cluster/nodemanager.h | |||
@@ -33,6 +33,12 @@ | |||
33 | #include <linux/configfs.h> | 33 | #include <linux/configfs.h> |
34 | #include <linux/rbtree.h> | 34 | #include <linux/rbtree.h> |
35 | 35 | ||
36 | enum o2nm_fence_method { | ||
37 | O2NM_FENCE_RESET = 0, | ||
38 | O2NM_FENCE_PANIC, | ||
39 | O2NM_FENCE_METHODS, /* Number of fence methods */ | ||
40 | }; | ||
41 | |||
36 | struct o2nm_node { | 42 | struct o2nm_node { |
37 | spinlock_t nd_lock; | 43 | spinlock_t nd_lock; |
38 | struct config_item nd_item; | 44 | struct config_item nd_item; |
@@ -58,6 +64,7 @@ struct o2nm_cluster { | |||
58 | unsigned int cl_idle_timeout_ms; | 64 | unsigned int cl_idle_timeout_ms; |
59 | unsigned int cl_keepalive_delay_ms; | 65 | unsigned int cl_keepalive_delay_ms; |
60 | unsigned int cl_reconnect_delay_ms; | 66 | unsigned int cl_reconnect_delay_ms; |
67 | enum o2nm_fence_method cl_fence_method; | ||
61 | 68 | ||
62 | /* this bitmap is part of a hack for disk bitmap.. will go eventually. - zab */ | 69 | /* this bitmap is part of a hack for disk bitmap.. will go eventually. - zab */ |
63 | unsigned long cl_nodes_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; | 70 | unsigned long cl_nodes_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
diff --git a/fs/ocfs2/cluster/quorum.c b/fs/ocfs2/cluster/quorum.c index bbacf7da48a4..639024033fce 100644 --- a/fs/ocfs2/cluster/quorum.c +++ b/fs/ocfs2/cluster/quorum.c | |||
@@ -74,8 +74,20 @@ static void o2quo_fence_self(void) | |||
74 | * threads can still schedule, etc, etc */ | 74 | * threads can still schedule, etc, etc */ |
75 | o2hb_stop_all_regions(); | 75 | o2hb_stop_all_regions(); |
76 | 76 | ||
77 | printk("ocfs2 is very sorry to be fencing this system by restarting\n"); | 77 | switch (o2nm_single_cluster->cl_fence_method) { |
78 | emergency_restart(); | 78 | case O2NM_FENCE_PANIC: |
79 | panic("*** ocfs2 is very sorry to be fencing this system by " | ||
80 | "panicing ***\n"); | ||
81 | break; | ||
82 | default: | ||
83 | WARN_ON(o2nm_single_cluster->cl_fence_method >= | ||
84 | O2NM_FENCE_METHODS); | ||
85 | case O2NM_FENCE_RESET: | ||
86 | printk(KERN_ERR "*** ocfs2 is very sorry to be fencing this " | ||
87 | "system by restarting ***\n"); | ||
88 | emergency_restart(); | ||
89 | break; | ||
90 | }; | ||
79 | } | 91 | } |
80 | 92 | ||
81 | /* Indicate that a timeout occured on a hearbeat region write. The | 93 | /* Indicate that a timeout occured on a hearbeat region write. The |
diff --git a/fs/ocfs2/dlm/dlmrecovery.c b/fs/ocfs2/dlm/dlmrecovery.c index d9fa3d22e17c..2f9e4e19a4f2 100644 --- a/fs/ocfs2/dlm/dlmrecovery.c +++ b/fs/ocfs2/dlm/dlmrecovery.c | |||
@@ -2589,6 +2589,14 @@ retry: | |||
2589 | "begin reco msg (%d)\n", dlm->name, nodenum, ret); | 2589 | "begin reco msg (%d)\n", dlm->name, nodenum, ret); |
2590 | ret = 0; | 2590 | ret = 0; |
2591 | } | 2591 | } |
2592 | if (ret == -EAGAIN) { | ||
2593 | mlog(0, "%s: trying to start recovery of node " | ||
2594 | "%u, but node %u is waiting for last recovery " | ||
2595 | "to complete, backoff for a bit\n", dlm->name, | ||
2596 | dead_node, nodenum); | ||
2597 | msleep(100); | ||
2598 | goto retry; | ||
2599 | } | ||
2592 | if (ret < 0) { | 2600 | if (ret < 0) { |
2593 | struct dlm_lock_resource *res; | 2601 | struct dlm_lock_resource *res; |
2594 | /* this is now a serious problem, possibly ENOMEM | 2602 | /* this is now a serious problem, possibly ENOMEM |
@@ -2608,14 +2616,6 @@ retry: | |||
2608 | * another ENOMEM */ | 2616 | * another ENOMEM */ |
2609 | msleep(100); | 2617 | msleep(100); |
2610 | goto retry; | 2618 | goto retry; |
2611 | } else if (ret == EAGAIN) { | ||
2612 | mlog(0, "%s: trying to start recovery of node " | ||
2613 | "%u, but node %u is waiting for last recovery " | ||
2614 | "to complete, backoff for a bit\n", dlm->name, | ||
2615 | dead_node, nodenum); | ||
2616 | /* TODO Look into replacing msleep with cond_resched() */ | ||
2617 | msleep(100); | ||
2618 | goto retry; | ||
2619 | } | 2619 | } |
2620 | } | 2620 | } |
2621 | 2621 | ||
@@ -2639,7 +2639,7 @@ int dlm_begin_reco_handler(struct o2net_msg *msg, u32 len, void *data, | |||
2639 | dlm->name, br->node_idx, br->dead_node, | 2639 | dlm->name, br->node_idx, br->dead_node, |
2640 | dlm->reco.dead_node, dlm->reco.new_master); | 2640 | dlm->reco.dead_node, dlm->reco.new_master); |
2641 | spin_unlock(&dlm->spinlock); | 2641 | spin_unlock(&dlm->spinlock); |
2642 | return EAGAIN; | 2642 | return -EAGAIN; |
2643 | } | 2643 | } |
2644 | spin_unlock(&dlm->spinlock); | 2644 | spin_unlock(&dlm->spinlock); |
2645 | 2645 | ||
diff --git a/fs/ocfs2/extent_map.c b/fs/ocfs2/extent_map.c index 843db64e9d4a..d35a27f4523e 100644 --- a/fs/ocfs2/extent_map.c +++ b/fs/ocfs2/extent_map.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include "extent_map.h" | 37 | #include "extent_map.h" |
38 | #include "inode.h" | 38 | #include "inode.h" |
39 | #include "super.h" | 39 | #include "super.h" |
40 | #include "symlink.h" | ||
40 | 41 | ||
41 | #include "buffer_head_io.h" | 42 | #include "buffer_head_io.h" |
42 | 43 | ||
@@ -703,6 +704,12 @@ out: | |||
703 | return ret; | 704 | return ret; |
704 | } | 705 | } |
705 | 706 | ||
707 | /* | ||
708 | * The ocfs2_fiemap_inline() may be a little bit misleading, since | ||
709 | * it not only handles the fiemap for inlined files, but also deals | ||
710 | * with the fast symlink, cause they have no difference for extent | ||
711 | * mapping per se. | ||
712 | */ | ||
706 | static int ocfs2_fiemap_inline(struct inode *inode, struct buffer_head *di_bh, | 713 | static int ocfs2_fiemap_inline(struct inode *inode, struct buffer_head *di_bh, |
707 | struct fiemap_extent_info *fieinfo, | 714 | struct fiemap_extent_info *fieinfo, |
708 | u64 map_start) | 715 | u64 map_start) |
@@ -715,11 +722,18 @@ static int ocfs2_fiemap_inline(struct inode *inode, struct buffer_head *di_bh, | |||
715 | struct ocfs2_inode_info *oi = OCFS2_I(inode); | 722 | struct ocfs2_inode_info *oi = OCFS2_I(inode); |
716 | 723 | ||
717 | di = (struct ocfs2_dinode *)di_bh->b_data; | 724 | di = (struct ocfs2_dinode *)di_bh->b_data; |
718 | id_count = le16_to_cpu(di->id2.i_data.id_count); | 725 | if (ocfs2_inode_is_fast_symlink(inode)) |
726 | id_count = ocfs2_fast_symlink_chars(inode->i_sb); | ||
727 | else | ||
728 | id_count = le16_to_cpu(di->id2.i_data.id_count); | ||
719 | 729 | ||
720 | if (map_start < id_count) { | 730 | if (map_start < id_count) { |
721 | phys = oi->ip_blkno << inode->i_sb->s_blocksize_bits; | 731 | phys = oi->ip_blkno << inode->i_sb->s_blocksize_bits; |
722 | phys += offsetof(struct ocfs2_dinode, id2.i_data.id_data); | 732 | if (ocfs2_inode_is_fast_symlink(inode)) |
733 | phys += offsetof(struct ocfs2_dinode, id2.i_symlink); | ||
734 | else | ||
735 | phys += offsetof(struct ocfs2_dinode, | ||
736 | id2.i_data.id_data); | ||
723 | 737 | ||
724 | ret = fiemap_fill_next_extent(fieinfo, 0, phys, id_count, | 738 | ret = fiemap_fill_next_extent(fieinfo, 0, phys, id_count, |
725 | flags); | 739 | flags); |
@@ -756,9 +770,10 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | |||
756 | down_read(&OCFS2_I(inode)->ip_alloc_sem); | 770 | down_read(&OCFS2_I(inode)->ip_alloc_sem); |
757 | 771 | ||
758 | /* | 772 | /* |
759 | * Handle inline-data separately. | 773 | * Handle inline-data and fast symlink separately. |
760 | */ | 774 | */ |
761 | if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { | 775 | if ((OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) || |
776 | ocfs2_inode_is_fast_symlink(inode)) { | ||
762 | ret = ocfs2_fiemap_inline(inode, di_bh, fieinfo, map_start); | 777 | ret = ocfs2_fiemap_inline(inode, di_bh, fieinfo, map_start); |
763 | goto out_unlock; | 778 | goto out_unlock; |
764 | } | 779 | } |
@@ -786,6 +801,8 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | |||
786 | fe_flags = 0; | 801 | fe_flags = 0; |
787 | if (rec.e_flags & OCFS2_EXT_UNWRITTEN) | 802 | if (rec.e_flags & OCFS2_EXT_UNWRITTEN) |
788 | fe_flags |= FIEMAP_EXTENT_UNWRITTEN; | 803 | fe_flags |= FIEMAP_EXTENT_UNWRITTEN; |
804 | if (rec.e_flags & OCFS2_EXT_REFCOUNTED) | ||
805 | fe_flags |= FIEMAP_EXTENT_SHARED; | ||
789 | if (is_last) | 806 | if (is_last) |
790 | fe_flags |= FIEMAP_EXTENT_LAST; | 807 | fe_flags |= FIEMAP_EXTENT_LAST; |
791 | len_bytes = (u64)le16_to_cpu(rec.e_leaf_clusters) << osb->s_clustersize_bits; | 808 | len_bytes = (u64)le16_to_cpu(rec.e_leaf_clusters) << osb->s_clustersize_bits; |
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 3d30a1c974a8..06ccf6a86d35 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c | |||
@@ -1772,7 +1772,8 @@ static int ocfs2_prepare_inode_for_write(struct dentry *dentry, | |||
1772 | loff_t *ppos, | 1772 | loff_t *ppos, |
1773 | size_t count, | 1773 | size_t count, |
1774 | int appending, | 1774 | int appending, |
1775 | int *direct_io) | 1775 | int *direct_io, |
1776 | int *has_refcount) | ||
1776 | { | 1777 | { |
1777 | int ret = 0, meta_level = 0; | 1778 | int ret = 0, meta_level = 0; |
1778 | struct inode *inode = dentry->d_inode; | 1779 | struct inode *inode = dentry->d_inode; |
@@ -1833,6 +1834,8 @@ static int ocfs2_prepare_inode_for_write(struct dentry *dentry, | |||
1833 | saved_pos, | 1834 | saved_pos, |
1834 | count, | 1835 | count, |
1835 | &meta_level); | 1836 | &meta_level); |
1837 | if (has_refcount) | ||
1838 | *has_refcount = 1; | ||
1836 | } | 1839 | } |
1837 | 1840 | ||
1838 | if (ret < 0) { | 1841 | if (ret < 0) { |
@@ -1856,6 +1859,10 @@ static int ocfs2_prepare_inode_for_write(struct dentry *dentry, | |||
1856 | break; | 1859 | break; |
1857 | } | 1860 | } |
1858 | 1861 | ||
1862 | if (has_refcount && *has_refcount == 1) { | ||
1863 | *direct_io = 0; | ||
1864 | break; | ||
1865 | } | ||
1859 | /* | 1866 | /* |
1860 | * Allowing concurrent direct writes means | 1867 | * Allowing concurrent direct writes means |
1861 | * i_size changes wouldn't be synchronized, so | 1868 | * i_size changes wouldn't be synchronized, so |
@@ -1899,7 +1906,7 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb, | |||
1899 | loff_t pos) | 1906 | loff_t pos) |
1900 | { | 1907 | { |
1901 | int ret, direct_io, appending, rw_level, have_alloc_sem = 0; | 1908 | int ret, direct_io, appending, rw_level, have_alloc_sem = 0; |
1902 | int can_do_direct; | 1909 | int can_do_direct, has_refcount = 0; |
1903 | ssize_t written = 0; | 1910 | ssize_t written = 0; |
1904 | size_t ocount; /* original count */ | 1911 | size_t ocount; /* original count */ |
1905 | size_t count; /* after file limit checks */ | 1912 | size_t count; /* after file limit checks */ |
@@ -1942,7 +1949,7 @@ relock: | |||
1942 | can_do_direct = direct_io; | 1949 | can_do_direct = direct_io; |
1943 | ret = ocfs2_prepare_inode_for_write(file->f_path.dentry, ppos, | 1950 | ret = ocfs2_prepare_inode_for_write(file->f_path.dentry, ppos, |
1944 | iocb->ki_left, appending, | 1951 | iocb->ki_left, appending, |
1945 | &can_do_direct); | 1952 | &can_do_direct, &has_refcount); |
1946 | if (ret < 0) { | 1953 | if (ret < 0) { |
1947 | mlog_errno(ret); | 1954 | mlog_errno(ret); |
1948 | goto out; | 1955 | goto out; |
@@ -2006,14 +2013,16 @@ out_dio: | |||
2006 | /* buffered aio wouldn't have proper lock coverage today */ | 2013 | /* buffered aio wouldn't have proper lock coverage today */ |
2007 | BUG_ON(ret == -EIOCBQUEUED && !(file->f_flags & O_DIRECT)); | 2014 | BUG_ON(ret == -EIOCBQUEUED && !(file->f_flags & O_DIRECT)); |
2008 | 2015 | ||
2009 | if ((file->f_flags & O_DSYNC && !direct_io) || IS_SYNC(inode)) { | 2016 | if ((file->f_flags & O_DSYNC && !direct_io) || IS_SYNC(inode) || |
2017 | (file->f_flags & O_DIRECT && has_refcount)) { | ||
2010 | ret = filemap_fdatawrite_range(file->f_mapping, pos, | 2018 | ret = filemap_fdatawrite_range(file->f_mapping, pos, |
2011 | pos + count - 1); | 2019 | pos + count - 1); |
2012 | if (ret < 0) | 2020 | if (ret < 0) |
2013 | written = ret; | 2021 | written = ret; |
2014 | 2022 | ||
2015 | if (!ret && (old_size != i_size_read(inode) || | 2023 | if (!ret && (old_size != i_size_read(inode) || |
2016 | old_clusters != OCFS2_I(inode)->ip_clusters)) { | 2024 | old_clusters != OCFS2_I(inode)->ip_clusters || |
2025 | has_refcount)) { | ||
2017 | ret = jbd2_journal_force_commit(osb->journal->j_journal); | 2026 | ret = jbd2_journal_force_commit(osb->journal->j_journal); |
2018 | if (ret < 0) | 2027 | if (ret < 0) |
2019 | written = ret; | 2028 | written = ret; |
@@ -2062,7 +2071,7 @@ static int ocfs2_splice_to_file(struct pipe_inode_info *pipe, | |||
2062 | int ret; | 2071 | int ret; |
2063 | 2072 | ||
2064 | ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, &sd->pos, | 2073 | ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, &sd->pos, |
2065 | sd->total_len, 0, NULL); | 2074 | sd->total_len, 0, NULL, NULL); |
2066 | if (ret < 0) { | 2075 | if (ret < 0) { |
2067 | mlog_errno(ret); | 2076 | mlog_errno(ret); |
2068 | return ret; | 2077 | return ret; |
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c index f010b22b1c44..50fb26a6a5f5 100644 --- a/fs/ocfs2/namei.c +++ b/fs/ocfs2/namei.c | |||
@@ -2108,6 +2108,7 @@ int ocfs2_create_inode_in_orphan(struct inode *dir, | |||
2108 | } | 2108 | } |
2109 | did_quota_inode = 1; | 2109 | did_quota_inode = 1; |
2110 | 2110 | ||
2111 | inode->i_nlink = 0; | ||
2111 | /* do the real work now. */ | 2112 | /* do the real work now. */ |
2112 | status = ocfs2_mknod_locked(osb, dir, inode, | 2113 | status = ocfs2_mknod_locked(osb, dir, inode, |
2113 | 0, &new_di_bh, parent_di_bh, handle, | 2114 | 0, &new_di_bh, parent_di_bh, handle, |
@@ -2136,6 +2137,7 @@ int ocfs2_create_inode_in_orphan(struct inode *dir, | |||
2136 | if (status < 0) | 2137 | if (status < 0) |
2137 | mlog_errno(status); | 2138 | mlog_errno(status); |
2138 | 2139 | ||
2140 | insert_inode_hash(inode); | ||
2139 | leave: | 2141 | leave: |
2140 | if (status < 0 && did_quota_inode) | 2142 | if (status < 0 && did_quota_inode) |
2141 | vfs_dq_free_inode(inode); | 2143 | vfs_dq_free_inode(inode); |
@@ -2267,6 +2269,8 @@ int ocfs2_mv_orphaned_inode_to_new(struct inode *dir, | |||
2267 | di = (struct ocfs2_dinode *)di_bh->b_data; | 2269 | di = (struct ocfs2_dinode *)di_bh->b_data; |
2268 | le32_add_cpu(&di->i_flags, -OCFS2_ORPHANED_FL); | 2270 | le32_add_cpu(&di->i_flags, -OCFS2_ORPHANED_FL); |
2269 | di->i_orphaned_slot = 0; | 2271 | di->i_orphaned_slot = 0; |
2272 | inode->i_nlink = 1; | ||
2273 | ocfs2_set_links_count(di, inode->i_nlink); | ||
2270 | ocfs2_journal_dirty(handle, di_bh); | 2274 | ocfs2_journal_dirty(handle, di_bh); |
2271 | 2275 | ||
2272 | status = ocfs2_add_entry(handle, dentry, inode, | 2276 | status = ocfs2_add_entry(handle, dentry, inode, |
@@ -2284,7 +2288,6 @@ int ocfs2_mv_orphaned_inode_to_new(struct inode *dir, | |||
2284 | goto out_commit; | 2288 | goto out_commit; |
2285 | } | 2289 | } |
2286 | 2290 | ||
2287 | insert_inode_hash(inode); | ||
2288 | dentry->d_op = &ocfs2_dentry_ops; | 2291 | dentry->d_op = &ocfs2_dentry_ops; |
2289 | d_instantiate(dentry, inode); | 2292 | d_instantiate(dentry, inode); |
2290 | status = 0; | 2293 | status = 0; |
@@ -2326,4 +2329,5 @@ const struct inode_operations ocfs2_dir_iops = { | |||
2326 | .getxattr = generic_getxattr, | 2329 | .getxattr = generic_getxattr, |
2327 | .listxattr = ocfs2_listxattr, | 2330 | .listxattr = ocfs2_listxattr, |
2328 | .removexattr = generic_removexattr, | 2331 | .removexattr = generic_removexattr, |
2332 | .fiemap = ocfs2_fiemap, | ||
2329 | }; | 2333 | }; |
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h index d963d8638709..9362eea7424b 100644 --- a/fs/ocfs2/ocfs2.h +++ b/fs/ocfs2/ocfs2.h | |||
@@ -245,9 +245,11 @@ enum ocfs2_mount_options | |||
245 | OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */ | 245 | OCFS2_MOUNT_LOCALFLOCKS = 1 << 5, /* No cluster aware user file locks */ |
246 | OCFS2_MOUNT_NOUSERXATTR = 1 << 6, /* No user xattr */ | 246 | OCFS2_MOUNT_NOUSERXATTR = 1 << 6, /* No user xattr */ |
247 | OCFS2_MOUNT_INODE64 = 1 << 7, /* Allow inode numbers > 2^32 */ | 247 | OCFS2_MOUNT_INODE64 = 1 << 7, /* Allow inode numbers > 2^32 */ |
248 | OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */ | 248 | OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* Force POSIX access control lists */ |
249 | OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */ | 249 | OCFS2_MOUNT_NO_POSIX_ACL = 1 << 9, /* Disable POSIX access |
250 | OCFS2_MOUNT_GRPQUOTA = 1 << 10, /* We support group quotas */ | 250 | control lists */ |
251 | OCFS2_MOUNT_USRQUOTA = 1 << 10, /* We support user quotas */ | ||
252 | OCFS2_MOUNT_GRPQUOTA = 1 << 11, /* We support group quotas */ | ||
251 | }; | 253 | }; |
252 | 254 | ||
253 | #define OCFS2_OSB_SOFT_RO 0x0001 | 255 | #define OCFS2_OSB_SOFT_RO 0x0001 |
diff --git a/fs/ocfs2/ocfs2_fs.h b/fs/ocfs2/ocfs2_fs.h index e9431e4a5e7c..1a1a679e51b5 100644 --- a/fs/ocfs2/ocfs2_fs.h +++ b/fs/ocfs2/ocfs2_fs.h | |||
@@ -1202,7 +1202,7 @@ struct ocfs2_local_disk_dqinfo { | |||
1202 | /* Header of one chunk of a quota file */ | 1202 | /* Header of one chunk of a quota file */ |
1203 | struct ocfs2_local_disk_chunk { | 1203 | struct ocfs2_local_disk_chunk { |
1204 | __le32 dqc_free; /* Number of free entries in the bitmap */ | 1204 | __le32 dqc_free; /* Number of free entries in the bitmap */ |
1205 | u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding | 1205 | __u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding |
1206 | * chunk of quota file */ | 1206 | * chunk of quota file */ |
1207 | }; | 1207 | }; |
1208 | 1208 | ||
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 30967e3f5e43..74db2be75dd6 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c | |||
@@ -276,7 +276,7 @@ static void ocfs2_erase_refcount_tree_from_list(struct ocfs2_super *osb, | |||
276 | spin_unlock(&osb->osb_lock); | 276 | spin_unlock(&osb->osb_lock); |
277 | } | 277 | } |
278 | 278 | ||
279 | void ocfs2_kref_remove_refcount_tree(struct kref *kref) | 279 | static void ocfs2_kref_remove_refcount_tree(struct kref *kref) |
280 | { | 280 | { |
281 | struct ocfs2_refcount_tree *tree = | 281 | struct ocfs2_refcount_tree *tree = |
282 | container_of(kref, struct ocfs2_refcount_tree, rf_getcnt); | 282 | container_of(kref, struct ocfs2_refcount_tree, rf_getcnt); |
@@ -524,23 +524,6 @@ out: | |||
524 | return ret; | 524 | return ret; |
525 | } | 525 | } |
526 | 526 | ||
527 | int ocfs2_lock_refcount_tree_by_inode(struct inode *inode, int rw, | ||
528 | struct ocfs2_refcount_tree **ret_tree, | ||
529 | struct buffer_head **ref_bh) | ||
530 | { | ||
531 | int ret; | ||
532 | u64 ref_blkno; | ||
533 | |||
534 | ret = ocfs2_get_refcount_block(inode, &ref_blkno); | ||
535 | if (ret) { | ||
536 | mlog_errno(ret); | ||
537 | return ret; | ||
538 | } | ||
539 | |||
540 | return ocfs2_lock_refcount_tree(OCFS2_SB(inode->i_sb), ref_blkno, | ||
541 | rw, ret_tree, ref_bh); | ||
542 | } | ||
543 | |||
544 | void ocfs2_unlock_refcount_tree(struct ocfs2_super *osb, | 527 | void ocfs2_unlock_refcount_tree(struct ocfs2_super *osb, |
545 | struct ocfs2_refcount_tree *tree, int rw) | 528 | struct ocfs2_refcount_tree *tree, int rw) |
546 | { | 529 | { |
@@ -969,6 +952,103 @@ out: | |||
969 | } | 952 | } |
970 | 953 | ||
971 | /* | 954 | /* |
955 | * Find the end range for a leaf refcount block indicated by | ||
956 | * el->l_recs[index].e_blkno. | ||
957 | */ | ||
958 | static int ocfs2_get_refcount_cpos_end(struct ocfs2_caching_info *ci, | ||
959 | struct buffer_head *ref_root_bh, | ||
960 | struct ocfs2_extent_block *eb, | ||
961 | struct ocfs2_extent_list *el, | ||
962 | int index, u32 *cpos_end) | ||
963 | { | ||
964 | int ret, i, subtree_root; | ||
965 | u32 cpos; | ||
966 | u64 blkno; | ||
967 | struct super_block *sb = ocfs2_metadata_cache_get_super(ci); | ||
968 | struct ocfs2_path *left_path = NULL, *right_path = NULL; | ||
969 | struct ocfs2_extent_tree et; | ||
970 | struct ocfs2_extent_list *tmp_el; | ||
971 | |||
972 | if (index < le16_to_cpu(el->l_next_free_rec) - 1) { | ||
973 | /* | ||
974 | * We have a extent rec after index, so just use the e_cpos | ||
975 | * of the next extent rec. | ||
976 | */ | ||
977 | *cpos_end = le32_to_cpu(el->l_recs[index+1].e_cpos); | ||
978 | return 0; | ||
979 | } | ||
980 | |||
981 | if (!eb || (eb && !eb->h_next_leaf_blk)) { | ||
982 | /* | ||
983 | * We are the last extent rec, so any high cpos should | ||
984 | * be stored in this leaf refcount block. | ||
985 | */ | ||
986 | *cpos_end = UINT_MAX; | ||
987 | return 0; | ||
988 | } | ||
989 | |||
990 | /* | ||
991 | * If the extent block isn't the last one, we have to find | ||
992 | * the subtree root between this extent block and the next | ||
993 | * leaf extent block and get the corresponding e_cpos from | ||
994 | * the subroot. Otherwise we may corrupt the b-tree. | ||
995 | */ | ||
996 | ocfs2_init_refcount_extent_tree(&et, ci, ref_root_bh); | ||
997 | |||
998 | left_path = ocfs2_new_path_from_et(&et); | ||
999 | if (!left_path) { | ||
1000 | ret = -ENOMEM; | ||
1001 | mlog_errno(ret); | ||
1002 | goto out; | ||
1003 | } | ||
1004 | |||
1005 | cpos = le32_to_cpu(eb->h_list.l_recs[index].e_cpos); | ||
1006 | ret = ocfs2_find_path(ci, left_path, cpos); | ||
1007 | if (ret) { | ||
1008 | mlog_errno(ret); | ||
1009 | goto out; | ||
1010 | } | ||
1011 | |||
1012 | right_path = ocfs2_new_path_from_path(left_path); | ||
1013 | if (!right_path) { | ||
1014 | ret = -ENOMEM; | ||
1015 | mlog_errno(ret); | ||
1016 | goto out; | ||
1017 | } | ||
1018 | |||
1019 | ret = ocfs2_find_cpos_for_right_leaf(sb, left_path, &cpos); | ||
1020 | if (ret) { | ||
1021 | mlog_errno(ret); | ||
1022 | goto out; | ||
1023 | } | ||
1024 | |||
1025 | ret = ocfs2_find_path(ci, right_path, cpos); | ||
1026 | if (ret) { | ||
1027 | mlog_errno(ret); | ||
1028 | goto out; | ||
1029 | } | ||
1030 | |||
1031 | subtree_root = ocfs2_find_subtree_root(&et, left_path, | ||
1032 | right_path); | ||
1033 | |||
1034 | tmp_el = left_path->p_node[subtree_root].el; | ||
1035 | blkno = left_path->p_node[subtree_root+1].bh->b_blocknr; | ||
1036 | for (i = 0; i < le32_to_cpu(tmp_el->l_next_free_rec); i++) { | ||
1037 | if (le64_to_cpu(tmp_el->l_recs[i].e_blkno) == blkno) { | ||
1038 | *cpos_end = le32_to_cpu(tmp_el->l_recs[i+1].e_cpos); | ||
1039 | break; | ||
1040 | } | ||
1041 | } | ||
1042 | |||
1043 | BUG_ON(i == le32_to_cpu(tmp_el->l_next_free_rec)); | ||
1044 | |||
1045 | out: | ||
1046 | ocfs2_free_path(left_path); | ||
1047 | ocfs2_free_path(right_path); | ||
1048 | return ret; | ||
1049 | } | ||
1050 | |||
1051 | /* | ||
972 | * Given a cpos and len, try to find the refcount record which contains cpos. | 1052 | * Given a cpos and len, try to find the refcount record which contains cpos. |
973 | * 1. If cpos can be found in one refcount record, return the record. | 1053 | * 1. If cpos can be found in one refcount record, return the record. |
974 | * 2. If cpos can't be found, return a fake record which start from cpos | 1054 | * 2. If cpos can't be found, return a fake record which start from cpos |
@@ -983,10 +1063,10 @@ static int ocfs2_get_refcount_rec(struct ocfs2_caching_info *ci, | |||
983 | struct buffer_head **ret_bh) | 1063 | struct buffer_head **ret_bh) |
984 | { | 1064 | { |
985 | int ret = 0, i, found; | 1065 | int ret = 0, i, found; |
986 | u32 low_cpos; | 1066 | u32 low_cpos, uninitialized_var(cpos_end); |
987 | struct ocfs2_extent_list *el; | 1067 | struct ocfs2_extent_list *el; |
988 | struct ocfs2_extent_rec *tmp, *rec = NULL; | 1068 | struct ocfs2_extent_rec *rec = NULL; |
989 | struct ocfs2_extent_block *eb; | 1069 | struct ocfs2_extent_block *eb = NULL; |
990 | struct buffer_head *eb_bh = NULL, *ref_leaf_bh = NULL; | 1070 | struct buffer_head *eb_bh = NULL, *ref_leaf_bh = NULL; |
991 | struct super_block *sb = ocfs2_metadata_cache_get_super(ci); | 1071 | struct super_block *sb = ocfs2_metadata_cache_get_super(ci); |
992 | struct ocfs2_refcount_block *rb = | 1072 | struct ocfs2_refcount_block *rb = |
@@ -1034,12 +1114,16 @@ static int ocfs2_get_refcount_rec(struct ocfs2_caching_info *ci, | |||
1034 | } | 1114 | } |
1035 | } | 1115 | } |
1036 | 1116 | ||
1037 | /* adjust len when we have ocfs2_extent_rec after it. */ | 1117 | if (found) { |
1038 | if (found && i < le16_to_cpu(el->l_next_free_rec) - 1) { | 1118 | ret = ocfs2_get_refcount_cpos_end(ci, ref_root_bh, |
1039 | tmp = &el->l_recs[i+1]; | 1119 | eb, el, i, &cpos_end); |
1120 | if (ret) { | ||
1121 | mlog_errno(ret); | ||
1122 | goto out; | ||
1123 | } | ||
1040 | 1124 | ||
1041 | if (le32_to_cpu(tmp->e_cpos) < cpos + len) | 1125 | if (cpos_end < low_cpos + len) |
1042 | len = le32_to_cpu(tmp->e_cpos) - cpos; | 1126 | len = cpos_end - low_cpos; |
1043 | } | 1127 | } |
1044 | 1128 | ||
1045 | ret = ocfs2_read_refcount_block(ci, le64_to_cpu(rec->e_blkno), | 1129 | ret = ocfs2_read_refcount_block(ci, le64_to_cpu(rec->e_blkno), |
@@ -1418,7 +1502,7 @@ static int ocfs2_divide_leaf_refcount_block(struct buffer_head *ref_leaf_bh, | |||
1418 | 1502 | ||
1419 | /* change old and new rl_used accordingly. */ | 1503 | /* change old and new rl_used accordingly. */ |
1420 | le16_add_cpu(&rl->rl_used, -num_moved); | 1504 | le16_add_cpu(&rl->rl_used, -num_moved); |
1421 | new_rl->rl_used = cpu_to_le32(num_moved); | 1505 | new_rl->rl_used = cpu_to_le16(num_moved); |
1422 | 1506 | ||
1423 | sort(&rl->rl_recs, le16_to_cpu(rl->rl_used), | 1507 | sort(&rl->rl_recs, le16_to_cpu(rl->rl_used), |
1424 | sizeof(struct ocfs2_refcount_rec), | 1508 | sizeof(struct ocfs2_refcount_rec), |
@@ -1797,7 +1881,8 @@ static int ocfs2_split_refcount_rec(handle_t *handle, | |||
1797 | recs_need++; | 1881 | recs_need++; |
1798 | 1882 | ||
1799 | /* If the leaf block don't have enough record, expand it. */ | 1883 | /* If the leaf block don't have enough record, expand it. */ |
1800 | if (le16_to_cpu(rf_list->rl_used) + recs_need > rf_list->rl_count) { | 1884 | if (le16_to_cpu(rf_list->rl_used) + recs_need > |
1885 | le16_to_cpu(rf_list->rl_count)) { | ||
1801 | struct ocfs2_refcount_rec tmp_rec; | 1886 | struct ocfs2_refcount_rec tmp_rec; |
1802 | u64 cpos = le64_to_cpu(orig_rec->r_cpos); | 1887 | u64 cpos = le64_to_cpu(orig_rec->r_cpos); |
1803 | len = le32_to_cpu(orig_rec->r_clusters); | 1888 | len = le32_to_cpu(orig_rec->r_clusters); |
@@ -1859,7 +1944,7 @@ static int ocfs2_split_refcount_rec(handle_t *handle, | |||
1859 | memcpy(tail_rec, orig_rec, sizeof(struct ocfs2_refcount_rec)); | 1944 | memcpy(tail_rec, orig_rec, sizeof(struct ocfs2_refcount_rec)); |
1860 | le64_add_cpu(&tail_rec->r_cpos, | 1945 | le64_add_cpu(&tail_rec->r_cpos, |
1861 | le32_to_cpu(tail_rec->r_clusters) - len); | 1946 | le32_to_cpu(tail_rec->r_clusters) - len); |
1862 | tail_rec->r_clusters = le32_to_cpu(len); | 1947 | tail_rec->r_clusters = cpu_to_le32(len); |
1863 | } | 1948 | } |
1864 | 1949 | ||
1865 | /* | 1950 | /* |
@@ -3840,8 +3925,7 @@ static int ocfs2_add_refcounted_extent(struct inode *inode, | |||
3840 | } | 3925 | } |
3841 | 3926 | ||
3842 | ret = ocfs2_insert_extent(handle, et, cpos, | 3927 | ret = ocfs2_insert_extent(handle, et, cpos, |
3843 | cpu_to_le64(ocfs2_clusters_to_blocks(inode->i_sb, | 3928 | ocfs2_clusters_to_blocks(inode->i_sb, p_cluster), |
3844 | p_cluster)), | ||
3845 | num_clusters, ext_flags, meta_ac); | 3929 | num_clusters, ext_flags, meta_ac); |
3846 | if (ret) { | 3930 | if (ret) { |
3847 | mlog_errno(ret); | 3931 | mlog_errno(ret); |
@@ -4253,8 +4337,8 @@ static int ocfs2_user_path_parent(const char __user *path, | |||
4253 | * @new_dentry: target dentry | 4337 | * @new_dentry: target dentry |
4254 | * @preserve: if true, preserve all file attributes | 4338 | * @preserve: if true, preserve all file attributes |
4255 | */ | 4339 | */ |
4256 | int ocfs2_vfs_reflink(struct dentry *old_dentry, struct inode *dir, | 4340 | static int ocfs2_vfs_reflink(struct dentry *old_dentry, struct inode *dir, |
4257 | struct dentry *new_dentry, bool preserve) | 4341 | struct dentry *new_dentry, bool preserve) |
4258 | { | 4342 | { |
4259 | struct inode *inode = old_dentry->d_inode; | 4343 | struct inode *inode = old_dentry->d_inode; |
4260 | int error; | 4344 | int error; |
diff --git a/fs/ocfs2/stack_user.c b/fs/ocfs2/stack_user.c index ff4c798a5635..da78a2a334fd 100644 --- a/fs/ocfs2/stack_user.c +++ b/fs/ocfs2/stack_user.c | |||
@@ -814,7 +814,7 @@ static int fs_protocol_compare(struct ocfs2_protocol_version *existing, | |||
814 | static int user_cluster_connect(struct ocfs2_cluster_connection *conn) | 814 | static int user_cluster_connect(struct ocfs2_cluster_connection *conn) |
815 | { | 815 | { |
816 | dlm_lockspace_t *fsdlm; | 816 | dlm_lockspace_t *fsdlm; |
817 | struct ocfs2_live_connection *control; | 817 | struct ocfs2_live_connection *uninitialized_var(control); |
818 | int rc = 0; | 818 | int rc = 0; |
819 | 819 | ||
820 | BUG_ON(conn == NULL); | 820 | BUG_ON(conn == NULL); |
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index 14f47d2bfe02..26069917a9f5 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c | |||
@@ -100,6 +100,8 @@ struct mount_options | |||
100 | static int ocfs2_parse_options(struct super_block *sb, char *options, | 100 | static int ocfs2_parse_options(struct super_block *sb, char *options, |
101 | struct mount_options *mopt, | 101 | struct mount_options *mopt, |
102 | int is_remount); | 102 | int is_remount); |
103 | static int ocfs2_check_set_options(struct super_block *sb, | ||
104 | struct mount_options *options); | ||
103 | static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt); | 105 | static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt); |
104 | static void ocfs2_put_super(struct super_block *sb); | 106 | static void ocfs2_put_super(struct super_block *sb); |
105 | static int ocfs2_mount_volume(struct super_block *sb); | 107 | static int ocfs2_mount_volume(struct super_block *sb); |
@@ -600,7 +602,8 @@ static int ocfs2_remount(struct super_block *sb, int *flags, char *data) | |||
600 | 602 | ||
601 | lock_kernel(); | 603 | lock_kernel(); |
602 | 604 | ||
603 | if (!ocfs2_parse_options(sb, data, &parsed_options, 1)) { | 605 | if (!ocfs2_parse_options(sb, data, &parsed_options, 1) || |
606 | !ocfs2_check_set_options(sb, &parsed_options)) { | ||
604 | ret = -EINVAL; | 607 | ret = -EINVAL; |
605 | goto out; | 608 | goto out; |
606 | } | 609 | } |
@@ -691,8 +694,6 @@ unlock_osb: | |||
691 | if (!ret) { | 694 | if (!ret) { |
692 | /* Only save off the new mount options in case of a successful | 695 | /* Only save off the new mount options in case of a successful |
693 | * remount. */ | 696 | * remount. */ |
694 | if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR)) | ||
695 | parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL; | ||
696 | osb->s_mount_opt = parsed_options.mount_opt; | 697 | osb->s_mount_opt = parsed_options.mount_opt; |
697 | osb->s_atime_quantum = parsed_options.atime_quantum; | 698 | osb->s_atime_quantum = parsed_options.atime_quantum; |
698 | osb->preferred_slot = parsed_options.slot; | 699 | osb->preferred_slot = parsed_options.slot; |
@@ -701,6 +702,10 @@ unlock_osb: | |||
701 | 702 | ||
702 | if (!ocfs2_is_hard_readonly(osb)) | 703 | if (!ocfs2_is_hard_readonly(osb)) |
703 | ocfs2_set_journal_params(osb); | 704 | ocfs2_set_journal_params(osb); |
705 | |||
706 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | | ||
707 | ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? | ||
708 | MS_POSIXACL : 0); | ||
704 | } | 709 | } |
705 | out: | 710 | out: |
706 | unlock_kernel(); | 711 | unlock_kernel(); |
@@ -1011,31 +1016,16 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent) | |||
1011 | brelse(bh); | 1016 | brelse(bh); |
1012 | bh = NULL; | 1017 | bh = NULL; |
1013 | 1018 | ||
1014 | if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR)) | 1019 | if (!ocfs2_check_set_options(sb, &parsed_options)) { |
1015 | parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL; | 1020 | status = -EINVAL; |
1016 | 1021 | goto read_super_error; | |
1022 | } | ||
1017 | osb->s_mount_opt = parsed_options.mount_opt; | 1023 | osb->s_mount_opt = parsed_options.mount_opt; |
1018 | osb->s_atime_quantum = parsed_options.atime_quantum; | 1024 | osb->s_atime_quantum = parsed_options.atime_quantum; |
1019 | osb->preferred_slot = parsed_options.slot; | 1025 | osb->preferred_slot = parsed_options.slot; |
1020 | osb->osb_commit_interval = parsed_options.commit_interval; | 1026 | osb->osb_commit_interval = parsed_options.commit_interval; |
1021 | osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt); | 1027 | osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt); |
1022 | osb->local_alloc_bits = osb->local_alloc_default_bits; | 1028 | osb->local_alloc_bits = osb->local_alloc_default_bits; |
1023 | if (osb->s_mount_opt & OCFS2_MOUNT_USRQUOTA && | ||
1024 | !OCFS2_HAS_RO_COMPAT_FEATURE(sb, | ||
1025 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) { | ||
1026 | status = -EINVAL; | ||
1027 | mlog(ML_ERROR, "User quotas were requested, but this " | ||
1028 | "filesystem does not have the feature enabled.\n"); | ||
1029 | goto read_super_error; | ||
1030 | } | ||
1031 | if (osb->s_mount_opt & OCFS2_MOUNT_GRPQUOTA && | ||
1032 | !OCFS2_HAS_RO_COMPAT_FEATURE(sb, | ||
1033 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) { | ||
1034 | status = -EINVAL; | ||
1035 | mlog(ML_ERROR, "Group quotas were requested, but this " | ||
1036 | "filesystem does not have the feature enabled.\n"); | ||
1037 | goto read_super_error; | ||
1038 | } | ||
1039 | 1029 | ||
1040 | status = ocfs2_verify_userspace_stack(osb, &parsed_options); | 1030 | status = ocfs2_verify_userspace_stack(osb, &parsed_options); |
1041 | if (status) | 1031 | if (status) |
@@ -1245,6 +1235,40 @@ static struct file_system_type ocfs2_fs_type = { | |||
1245 | .next = NULL | 1235 | .next = NULL |
1246 | }; | 1236 | }; |
1247 | 1237 | ||
1238 | static int ocfs2_check_set_options(struct super_block *sb, | ||
1239 | struct mount_options *options) | ||
1240 | { | ||
1241 | if (options->mount_opt & OCFS2_MOUNT_USRQUOTA && | ||
1242 | !OCFS2_HAS_RO_COMPAT_FEATURE(sb, | ||
1243 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) { | ||
1244 | mlog(ML_ERROR, "User quotas were requested, but this " | ||
1245 | "filesystem does not have the feature enabled.\n"); | ||
1246 | return 0; | ||
1247 | } | ||
1248 | if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA && | ||
1249 | !OCFS2_HAS_RO_COMPAT_FEATURE(sb, | ||
1250 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) { | ||
1251 | mlog(ML_ERROR, "Group quotas were requested, but this " | ||
1252 | "filesystem does not have the feature enabled.\n"); | ||
1253 | return 0; | ||
1254 | } | ||
1255 | if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL && | ||
1256 | !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) { | ||
1257 | mlog(ML_ERROR, "ACL support requested but extended attributes " | ||
1258 | "feature is not enabled\n"); | ||
1259 | return 0; | ||
1260 | } | ||
1261 | /* No ACL setting specified? Use XATTR feature... */ | ||
1262 | if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL | | ||
1263 | OCFS2_MOUNT_NO_POSIX_ACL))) { | ||
1264 | if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) | ||
1265 | options->mount_opt |= OCFS2_MOUNT_POSIX_ACL; | ||
1266 | else | ||
1267 | options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL; | ||
1268 | } | ||
1269 | return 1; | ||
1270 | } | ||
1271 | |||
1248 | static int ocfs2_parse_options(struct super_block *sb, | 1272 | static int ocfs2_parse_options(struct super_block *sb, |
1249 | char *options, | 1273 | char *options, |
1250 | struct mount_options *mopt, | 1274 | struct mount_options *mopt, |
@@ -1392,40 +1416,19 @@ static int ocfs2_parse_options(struct super_block *sb, | |||
1392 | mopt->mount_opt |= OCFS2_MOUNT_INODE64; | 1416 | mopt->mount_opt |= OCFS2_MOUNT_INODE64; |
1393 | break; | 1417 | break; |
1394 | case Opt_usrquota: | 1418 | case Opt_usrquota: |
1395 | /* We check only on remount, otherwise features | ||
1396 | * aren't yet initialized. */ | ||
1397 | if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb, | ||
1398 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) { | ||
1399 | mlog(ML_ERROR, "User quota requested but " | ||
1400 | "filesystem feature is not set\n"); | ||
1401 | status = 0; | ||
1402 | goto bail; | ||
1403 | } | ||
1404 | mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA; | 1419 | mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA; |
1405 | break; | 1420 | break; |
1406 | case Opt_grpquota: | 1421 | case Opt_grpquota: |
1407 | if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb, | ||
1408 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) { | ||
1409 | mlog(ML_ERROR, "Group quota requested but " | ||
1410 | "filesystem feature is not set\n"); | ||
1411 | status = 0; | ||
1412 | goto bail; | ||
1413 | } | ||
1414 | mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA; | 1422 | mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA; |
1415 | break; | 1423 | break; |
1416 | #ifdef CONFIG_OCFS2_FS_POSIX_ACL | ||
1417 | case Opt_acl: | 1424 | case Opt_acl: |
1418 | mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL; | 1425 | mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL; |
1426 | mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL; | ||
1419 | break; | 1427 | break; |
1420 | case Opt_noacl: | 1428 | case Opt_noacl: |
1429 | mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL; | ||
1421 | mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL; | 1430 | mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL; |
1422 | break; | 1431 | break; |
1423 | #else | ||
1424 | case Opt_acl: | ||
1425 | case Opt_noacl: | ||
1426 | printk(KERN_INFO "ocfs2 (no)acl options not supported\n"); | ||
1427 | break; | ||
1428 | #endif | ||
1429 | default: | 1432 | default: |
1430 | mlog(ML_ERROR, | 1433 | mlog(ML_ERROR, |
1431 | "Unrecognized mount option \"%s\" " | 1434 | "Unrecognized mount option \"%s\" " |
@@ -1502,12 +1505,10 @@ static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt) | |||
1502 | if (opts & OCFS2_MOUNT_INODE64) | 1505 | if (opts & OCFS2_MOUNT_INODE64) |
1503 | seq_printf(s, ",inode64"); | 1506 | seq_printf(s, ",inode64"); |
1504 | 1507 | ||
1505 | #ifdef CONFIG_OCFS2_FS_POSIX_ACL | ||
1506 | if (opts & OCFS2_MOUNT_POSIX_ACL) | 1508 | if (opts & OCFS2_MOUNT_POSIX_ACL) |
1507 | seq_printf(s, ",acl"); | 1509 | seq_printf(s, ",acl"); |
1508 | else | 1510 | else |
1509 | seq_printf(s, ",noacl"); | 1511 | seq_printf(s, ",noacl"); |
1510 | #endif | ||
1511 | 1512 | ||
1512 | return 0; | 1513 | return 0; |
1513 | } | 1514 | } |
diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c index e3421030a69f..49b133ccbf11 100644 --- a/fs/ocfs2/symlink.c +++ b/fs/ocfs2/symlink.c | |||
@@ -163,6 +163,7 @@ const struct inode_operations ocfs2_symlink_inode_operations = { | |||
163 | .getxattr = generic_getxattr, | 163 | .getxattr = generic_getxattr, |
164 | .listxattr = ocfs2_listxattr, | 164 | .listxattr = ocfs2_listxattr, |
165 | .removexattr = generic_removexattr, | 165 | .removexattr = generic_removexattr, |
166 | .fiemap = ocfs2_fiemap, | ||
166 | }; | 167 | }; |
167 | const struct inode_operations ocfs2_fast_symlink_inode_operations = { | 168 | const struct inode_operations ocfs2_fast_symlink_inode_operations = { |
168 | .readlink = ocfs2_readlink, | 169 | .readlink = ocfs2_readlink, |
@@ -174,4 +175,5 @@ const struct inode_operations ocfs2_fast_symlink_inode_operations = { | |||
174 | .getxattr = generic_getxattr, | 175 | .getxattr = generic_getxattr, |
175 | .listxattr = ocfs2_listxattr, | 176 | .listxattr = ocfs2_listxattr, |
176 | .removexattr = generic_removexattr, | 177 | .removexattr = generic_removexattr, |
178 | .fiemap = ocfs2_fiemap, | ||
177 | }; | 179 | }; |
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c index 43c114831c0d..8fc6fb071c6d 100644 --- a/fs/ocfs2/xattr.c +++ b/fs/ocfs2/xattr.c | |||
@@ -98,10 +98,8 @@ static struct ocfs2_xattr_def_value_root def_xv = { | |||
98 | 98 | ||
99 | struct xattr_handler *ocfs2_xattr_handlers[] = { | 99 | struct xattr_handler *ocfs2_xattr_handlers[] = { |
100 | &ocfs2_xattr_user_handler, | 100 | &ocfs2_xattr_user_handler, |
101 | #ifdef CONFIG_OCFS2_FS_POSIX_ACL | ||
102 | &ocfs2_xattr_acl_access_handler, | 101 | &ocfs2_xattr_acl_access_handler, |
103 | &ocfs2_xattr_acl_default_handler, | 102 | &ocfs2_xattr_acl_default_handler, |
104 | #endif | ||
105 | &ocfs2_xattr_trusted_handler, | 103 | &ocfs2_xattr_trusted_handler, |
106 | &ocfs2_xattr_security_handler, | 104 | &ocfs2_xattr_security_handler, |
107 | NULL | 105 | NULL |
@@ -109,12 +107,10 @@ struct xattr_handler *ocfs2_xattr_handlers[] = { | |||
109 | 107 | ||
110 | static struct xattr_handler *ocfs2_xattr_handler_map[OCFS2_XATTR_MAX] = { | 108 | static struct xattr_handler *ocfs2_xattr_handler_map[OCFS2_XATTR_MAX] = { |
111 | [OCFS2_XATTR_INDEX_USER] = &ocfs2_xattr_user_handler, | 109 | [OCFS2_XATTR_INDEX_USER] = &ocfs2_xattr_user_handler, |
112 | #ifdef CONFIG_OCFS2_FS_POSIX_ACL | ||
113 | [OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS] | 110 | [OCFS2_XATTR_INDEX_POSIX_ACL_ACCESS] |
114 | = &ocfs2_xattr_acl_access_handler, | 111 | = &ocfs2_xattr_acl_access_handler, |
115 | [OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT] | 112 | [OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT] |
116 | = &ocfs2_xattr_acl_default_handler, | 113 | = &ocfs2_xattr_acl_default_handler, |
117 | #endif | ||
118 | [OCFS2_XATTR_INDEX_TRUSTED] = &ocfs2_xattr_trusted_handler, | 114 | [OCFS2_XATTR_INDEX_TRUSTED] = &ocfs2_xattr_trusted_handler, |
119 | [OCFS2_XATTR_INDEX_SECURITY] = &ocfs2_xattr_security_handler, | 115 | [OCFS2_XATTR_INDEX_SECURITY] = &ocfs2_xattr_security_handler, |
120 | }; | 116 | }; |
@@ -6064,7 +6060,7 @@ static int ocfs2_value_metas_in_xattr_header(struct super_block *sb, | |||
6064 | * to the extent block, so just calculate a maximum record num. | 6060 | * to the extent block, so just calculate a maximum record num. |
6065 | */ | 6061 | */ |
6066 | if (!xv->xr_list.l_tree_depth) | 6062 | if (!xv->xr_list.l_tree_depth) |
6067 | *num_recs += xv->xr_list.l_next_free_rec; | 6063 | *num_recs += le16_to_cpu(xv->xr_list.l_next_free_rec); |
6068 | else | 6064 | else |
6069 | *num_recs += ocfs2_clusters_for_bytes(sb, | 6065 | *num_recs += ocfs2_clusters_for_bytes(sb, |
6070 | XATTR_SIZE_MAX); | 6066 | XATTR_SIZE_MAX); |
diff --git a/fs/ocfs2/xattr.h b/fs/ocfs2/xattr.h index 08e36389f56d..abd72a47f520 100644 --- a/fs/ocfs2/xattr.h +++ b/fs/ocfs2/xattr.h | |||
@@ -40,10 +40,8 @@ struct ocfs2_security_xattr_info { | |||
40 | extern struct xattr_handler ocfs2_xattr_user_handler; | 40 | extern struct xattr_handler ocfs2_xattr_user_handler; |
41 | extern struct xattr_handler ocfs2_xattr_trusted_handler; | 41 | extern struct xattr_handler ocfs2_xattr_trusted_handler; |
42 | extern struct xattr_handler ocfs2_xattr_security_handler; | 42 | extern struct xattr_handler ocfs2_xattr_security_handler; |
43 | #ifdef CONFIG_OCFS2_FS_POSIX_ACL | ||
44 | extern struct xattr_handler ocfs2_xattr_acl_access_handler; | 43 | extern struct xattr_handler ocfs2_xattr_acl_access_handler; |
45 | extern struct xattr_handler ocfs2_xattr_acl_default_handler; | 44 | extern struct xattr_handler ocfs2_xattr_acl_default_handler; |
46 | #endif | ||
47 | extern struct xattr_handler *ocfs2_xattr_handlers[]; | 45 | extern struct xattr_handler *ocfs2_xattr_handlers[]; |
48 | 46 | ||
49 | ssize_t ocfs2_listxattr(struct dentry *, char *, size_t); | 47 | ssize_t ocfs2_listxattr(struct dentry *, char *, size_t); |
@@ -821,15 +821,14 @@ static inline int __get_file_write_access(struct inode *inode, | |||
821 | } | 821 | } |
822 | 822 | ||
823 | static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, | 823 | static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, |
824 | int flags, struct file *f, | 824 | struct file *f, |
825 | int (*open)(struct inode *, struct file *), | 825 | int (*open)(struct inode *, struct file *), |
826 | const struct cred *cred) | 826 | const struct cred *cred) |
827 | { | 827 | { |
828 | struct inode *inode; | 828 | struct inode *inode; |
829 | int error; | 829 | int error; |
830 | 830 | ||
831 | f->f_flags = flags; | 831 | f->f_mode = OPEN_FMODE(f->f_flags) | FMODE_LSEEK | |
832 | f->f_mode = (__force fmode_t)((flags+1) & O_ACCMODE) | FMODE_LSEEK | | ||
833 | FMODE_PREAD | FMODE_PWRITE; | 832 | FMODE_PREAD | FMODE_PWRITE; |
834 | inode = dentry->d_inode; | 833 | inode = dentry->d_inode; |
835 | if (f->f_mode & FMODE_WRITE) { | 834 | if (f->f_mode & FMODE_WRITE) { |
@@ -930,7 +929,6 @@ struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry | |||
930 | if (IS_ERR(dentry)) | 929 | if (IS_ERR(dentry)) |
931 | goto out_err; | 930 | goto out_err; |
932 | nd->intent.open.file = __dentry_open(dget(dentry), mntget(nd->path.mnt), | 931 | nd->intent.open.file = __dentry_open(dget(dentry), mntget(nd->path.mnt), |
933 | nd->intent.open.flags - 1, | ||
934 | nd->intent.open.file, | 932 | nd->intent.open.file, |
935 | open, cred); | 933 | open, cred); |
936 | out: | 934 | out: |
@@ -949,7 +947,7 @@ EXPORT_SYMBOL_GPL(lookup_instantiate_filp); | |||
949 | * | 947 | * |
950 | * Note that this function destroys the original nameidata | 948 | * Note that this function destroys the original nameidata |
951 | */ | 949 | */ |
952 | struct file *nameidata_to_filp(struct nameidata *nd, int flags) | 950 | struct file *nameidata_to_filp(struct nameidata *nd) |
953 | { | 951 | { |
954 | const struct cred *cred = current_cred(); | 952 | const struct cred *cred = current_cred(); |
955 | struct file *filp; | 953 | struct file *filp; |
@@ -958,7 +956,7 @@ struct file *nameidata_to_filp(struct nameidata *nd, int flags) | |||
958 | filp = nd->intent.open.file; | 956 | filp = nd->intent.open.file; |
959 | /* Has the filesystem initialised the file for us? */ | 957 | /* Has the filesystem initialised the file for us? */ |
960 | if (filp->f_path.dentry == NULL) | 958 | if (filp->f_path.dentry == NULL) |
961 | filp = __dentry_open(nd->path.dentry, nd->path.mnt, flags, filp, | 959 | filp = __dentry_open(nd->path.dentry, nd->path.mnt, filp, |
962 | NULL, cred); | 960 | NULL, cred); |
963 | else | 961 | else |
964 | path_put(&nd->path); | 962 | path_put(&nd->path); |
@@ -997,7 +995,8 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags, | |||
997 | return ERR_PTR(error); | 995 | return ERR_PTR(error); |
998 | } | 996 | } |
999 | 997 | ||
1000 | return __dentry_open(dentry, mnt, flags, f, NULL, cred); | 998 | f->f_flags = flags; |
999 | return __dentry_open(dentry, mnt, f, NULL, cred); | ||
1001 | } | 1000 | } |
1002 | EXPORT_SYMBOL(dentry_open); | 1001 | EXPORT_SYMBOL(dentry_open); |
1003 | 1002 | ||
@@ -906,17 +906,6 @@ void free_pipe_info(struct inode *inode) | |||
906 | } | 906 | } |
907 | 907 | ||
908 | static struct vfsmount *pipe_mnt __read_mostly; | 908 | static struct vfsmount *pipe_mnt __read_mostly; |
909 | static int pipefs_delete_dentry(struct dentry *dentry) | ||
910 | { | ||
911 | /* | ||
912 | * At creation time, we pretended this dentry was hashed | ||
913 | * (by clearing DCACHE_UNHASHED bit in d_flags) | ||
914 | * At delete time, we restore the truth : not hashed. | ||
915 | * (so that dput() can proceed correctly) | ||
916 | */ | ||
917 | dentry->d_flags |= DCACHE_UNHASHED; | ||
918 | return 0; | ||
919 | } | ||
920 | 909 | ||
921 | /* | 910 | /* |
922 | * pipefs_dname() is called from d_path(). | 911 | * pipefs_dname() is called from d_path(). |
@@ -928,7 +917,6 @@ static char *pipefs_dname(struct dentry *dentry, char *buffer, int buflen) | |||
928 | } | 917 | } |
929 | 918 | ||
930 | static const struct dentry_operations pipefs_dentry_operations = { | 919 | static const struct dentry_operations pipefs_dentry_operations = { |
931 | .d_delete = pipefs_delete_dentry, | ||
932 | .d_dname = pipefs_dname, | 920 | .d_dname = pipefs_dname, |
933 | }; | 921 | }; |
934 | 922 | ||
@@ -989,12 +977,6 @@ struct file *create_write_pipe(int flags) | |||
989 | path.mnt = mntget(pipe_mnt); | 977 | path.mnt = mntget(pipe_mnt); |
990 | 978 | ||
991 | path.dentry->d_op = &pipefs_dentry_operations; | 979 | path.dentry->d_op = &pipefs_dentry_operations; |
992 | /* | ||
993 | * We dont want to publish this dentry into global dentry hash table. | ||
994 | * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED | ||
995 | * This permits a working /proc/$pid/fd/XXX on pipes | ||
996 | */ | ||
997 | path.dentry->d_flags &= ~DCACHE_UNHASHED; | ||
998 | d_instantiate(path.dentry, inode); | 980 | d_instantiate(path.dentry, inode); |
999 | 981 | ||
1000 | err = -ENFILE; | 982 | err = -ENFILE; |
diff --git a/fs/proc/array.c b/fs/proc/array.c index 4badde179b18..13b5d0708175 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c | |||
@@ -134,13 +134,16 @@ static inline void task_name(struct seq_file *m, struct task_struct *p) | |||
134 | * simple bit tests. | 134 | * simple bit tests. |
135 | */ | 135 | */ |
136 | static const char *task_state_array[] = { | 136 | static const char *task_state_array[] = { |
137 | "R (running)", /* 0 */ | 137 | "R (running)", /* 0 */ |
138 | "S (sleeping)", /* 1 */ | 138 | "S (sleeping)", /* 1 */ |
139 | "D (disk sleep)", /* 2 */ | 139 | "D (disk sleep)", /* 2 */ |
140 | "T (stopped)", /* 4 */ | 140 | "T (stopped)", /* 4 */ |
141 | "T (tracing stop)", /* 8 */ | 141 | "t (tracing stop)", /* 8 */ |
142 | "Z (zombie)", /* 16 */ | 142 | "Z (zombie)", /* 16 */ |
143 | "X (dead)" /* 32 */ | 143 | "X (dead)", /* 32 */ |
144 | "x (dead)", /* 64 */ | ||
145 | "K (wakekill)", /* 128 */ | ||
146 | "W (waking)", /* 256 */ | ||
144 | }; | 147 | }; |
145 | 148 | ||
146 | static inline const char *get_task_state(struct task_struct *tsk) | 149 | static inline const char *get_task_state(struct task_struct *tsk) |
@@ -148,6 +151,8 @@ static inline const char *get_task_state(struct task_struct *tsk) | |||
148 | unsigned int state = (tsk->state & TASK_REPORT) | tsk->exit_state; | 151 | unsigned int state = (tsk->state & TASK_REPORT) | tsk->exit_state; |
149 | const char **p = &task_state_array[0]; | 152 | const char **p = &task_state_array[0]; |
150 | 153 | ||
154 | BUILD_BUG_ON(1 + ilog2(TASK_STATE_MAX) != ARRAY_SIZE(task_state_array)); | ||
155 | |||
151 | while (state) { | 156 | while (state) { |
152 | p++; | 157 | p++; |
153 | state >>= 1; | 158 | state >>= 1; |
@@ -322,94 +327,6 @@ static inline void task_context_switch_counts(struct seq_file *m, | |||
322 | p->nivcsw); | 327 | p->nivcsw); |
323 | } | 328 | } |
324 | 329 | ||
325 | #ifdef CONFIG_MMU | ||
326 | |||
327 | struct stack_stats { | ||
328 | struct vm_area_struct *vma; | ||
329 | unsigned long startpage; | ||
330 | unsigned long usage; | ||
331 | }; | ||
332 | |||
333 | static int stack_usage_pte_range(pmd_t *pmd, unsigned long addr, | ||
334 | unsigned long end, struct mm_walk *walk) | ||
335 | { | ||
336 | struct stack_stats *ss = walk->private; | ||
337 | struct vm_area_struct *vma = ss->vma; | ||
338 | pte_t *pte, ptent; | ||
339 | spinlock_t *ptl; | ||
340 | int ret = 0; | ||
341 | |||
342 | pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); | ||
343 | for (; addr != end; pte++, addr += PAGE_SIZE) { | ||
344 | ptent = *pte; | ||
345 | |||
346 | #ifdef CONFIG_STACK_GROWSUP | ||
347 | if (pte_present(ptent) || is_swap_pte(ptent)) | ||
348 | ss->usage = addr - ss->startpage + PAGE_SIZE; | ||
349 | #else | ||
350 | if (pte_present(ptent) || is_swap_pte(ptent)) { | ||
351 | ss->usage = ss->startpage - addr + PAGE_SIZE; | ||
352 | pte++; | ||
353 | ret = 1; | ||
354 | break; | ||
355 | } | ||
356 | #endif | ||
357 | } | ||
358 | pte_unmap_unlock(pte - 1, ptl); | ||
359 | cond_resched(); | ||
360 | return ret; | ||
361 | } | ||
362 | |||
363 | static inline unsigned long get_stack_usage_in_bytes(struct vm_area_struct *vma, | ||
364 | struct task_struct *task) | ||
365 | { | ||
366 | struct stack_stats ss; | ||
367 | struct mm_walk stack_walk = { | ||
368 | .pmd_entry = stack_usage_pte_range, | ||
369 | .mm = vma->vm_mm, | ||
370 | .private = &ss, | ||
371 | }; | ||
372 | |||
373 | if (!vma->vm_mm || is_vm_hugetlb_page(vma)) | ||
374 | return 0; | ||
375 | |||
376 | ss.vma = vma; | ||
377 | ss.startpage = task->stack_start & PAGE_MASK; | ||
378 | ss.usage = 0; | ||
379 | |||
380 | #ifdef CONFIG_STACK_GROWSUP | ||
381 | walk_page_range(KSTK_ESP(task) & PAGE_MASK, vma->vm_end, | ||
382 | &stack_walk); | ||
383 | #else | ||
384 | walk_page_range(vma->vm_start, (KSTK_ESP(task) & PAGE_MASK) + PAGE_SIZE, | ||
385 | &stack_walk); | ||
386 | #endif | ||
387 | return ss.usage; | ||
388 | } | ||
389 | |||
390 | static inline void task_show_stack_usage(struct seq_file *m, | ||
391 | struct task_struct *task) | ||
392 | { | ||
393 | struct vm_area_struct *vma; | ||
394 | struct mm_struct *mm = get_task_mm(task); | ||
395 | |||
396 | if (mm) { | ||
397 | down_read(&mm->mmap_sem); | ||
398 | vma = find_vma(mm, task->stack_start); | ||
399 | if (vma) | ||
400 | seq_printf(m, "Stack usage:\t%lu kB\n", | ||
401 | get_stack_usage_in_bytes(vma, task) >> 10); | ||
402 | |||
403 | up_read(&mm->mmap_sem); | ||
404 | mmput(mm); | ||
405 | } | ||
406 | } | ||
407 | #else | ||
408 | static void task_show_stack_usage(struct seq_file *m, struct task_struct *task) | ||
409 | { | ||
410 | } | ||
411 | #endif /* CONFIG_MMU */ | ||
412 | |||
413 | static void task_cpus_allowed(struct seq_file *m, struct task_struct *task) | 330 | static void task_cpus_allowed(struct seq_file *m, struct task_struct *task) |
414 | { | 331 | { |
415 | seq_printf(m, "Cpus_allowed:\t"); | 332 | seq_printf(m, "Cpus_allowed:\t"); |
@@ -440,7 +357,6 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, | |||
440 | task_show_regs(m, task); | 357 | task_show_regs(m, task); |
441 | #endif | 358 | #endif |
442 | task_context_switch_counts(m, task); | 359 | task_context_switch_counts(m, task); |
443 | task_show_stack_usage(m, task); | ||
444 | return 0; | 360 | return 0; |
445 | } | 361 | } |
446 | 362 | ||
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 47c03f4336b8..f277c4a111cb 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c | |||
@@ -361,12 +361,11 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, | |||
361 | if (!pte_present(ptent)) | 361 | if (!pte_present(ptent)) |
362 | continue; | 362 | continue; |
363 | 363 | ||
364 | mss->resident += PAGE_SIZE; | ||
365 | |||
366 | page = vm_normal_page(vma, addr, ptent); | 364 | page = vm_normal_page(vma, addr, ptent); |
367 | if (!page) | 365 | if (!page) |
368 | continue; | 366 | continue; |
369 | 367 | ||
368 | mss->resident += PAGE_SIZE; | ||
370 | /* Accumulate the size in pages that have been accessed. */ | 369 | /* Accumulate the size in pages that have been accessed. */ |
371 | if (pte_young(ptent) || PageReferenced(page)) | 370 | if (pte_young(ptent) || PageReferenced(page)) |
372 | mss->referenced += PAGE_SIZE; | 371 | mss->referenced += PAGE_SIZE; |
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index cd6bb9a33c13..3fc62b097bed 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c | |||
@@ -323,6 +323,30 @@ int dquot_mark_dquot_dirty(struct dquot *dquot) | |||
323 | } | 323 | } |
324 | EXPORT_SYMBOL(dquot_mark_dquot_dirty); | 324 | EXPORT_SYMBOL(dquot_mark_dquot_dirty); |
325 | 325 | ||
326 | /* Dirtify all the dquots - this can block when journalling */ | ||
327 | static inline int mark_all_dquot_dirty(struct dquot * const *dquot) | ||
328 | { | ||
329 | int ret, err, cnt; | ||
330 | |||
331 | ret = err = 0; | ||
332 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { | ||
333 | if (dquot[cnt]) | ||
334 | /* Even in case of error we have to continue */ | ||
335 | ret = mark_dquot_dirty(dquot[cnt]); | ||
336 | if (!err) | ||
337 | err = ret; | ||
338 | } | ||
339 | return err; | ||
340 | } | ||
341 | |||
342 | static inline void dqput_all(struct dquot **dquot) | ||
343 | { | ||
344 | unsigned int cnt; | ||
345 | |||
346 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) | ||
347 | dqput(dquot[cnt]); | ||
348 | } | ||
349 | |||
326 | /* This function needs dq_list_lock */ | 350 | /* This function needs dq_list_lock */ |
327 | static inline int clear_dquot_dirty(struct dquot *dquot) | 351 | static inline int clear_dquot_dirty(struct dquot *dquot) |
328 | { | 352 | { |
@@ -1268,8 +1292,7 @@ int dquot_initialize(struct inode *inode, int type) | |||
1268 | out_err: | 1292 | out_err: |
1269 | up_write(&sb_dqopt(sb)->dqptr_sem); | 1293 | up_write(&sb_dqopt(sb)->dqptr_sem); |
1270 | /* Drop unused references */ | 1294 | /* Drop unused references */ |
1271 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) | 1295 | dqput_all(got); |
1272 | dqput(got[cnt]); | ||
1273 | return ret; | 1296 | return ret; |
1274 | } | 1297 | } |
1275 | EXPORT_SYMBOL(dquot_initialize); | 1298 | EXPORT_SYMBOL(dquot_initialize); |
@@ -1288,9 +1311,7 @@ int dquot_drop(struct inode *inode) | |||
1288 | inode->i_dquot[cnt] = NULL; | 1311 | inode->i_dquot[cnt] = NULL; |
1289 | } | 1312 | } |
1290 | up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); | 1313 | up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1291 | 1314 | dqput_all(put); | |
1292 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) | ||
1293 | dqput(put[cnt]); | ||
1294 | return 0; | 1315 | return 0; |
1295 | } | 1316 | } |
1296 | EXPORT_SYMBOL(dquot_drop); | 1317 | EXPORT_SYMBOL(dquot_drop); |
@@ -1319,6 +1340,70 @@ void vfs_dq_drop(struct inode *inode) | |||
1319 | EXPORT_SYMBOL(vfs_dq_drop); | 1340 | EXPORT_SYMBOL(vfs_dq_drop); |
1320 | 1341 | ||
1321 | /* | 1342 | /* |
1343 | * inode_reserved_space is managed internally by quota, and protected by | ||
1344 | * i_lock similar to i_blocks+i_bytes. | ||
1345 | */ | ||
1346 | static qsize_t *inode_reserved_space(struct inode * inode) | ||
1347 | { | ||
1348 | /* Filesystem must explicitly define it's own method in order to use | ||
1349 | * quota reservation interface */ | ||
1350 | BUG_ON(!inode->i_sb->dq_op->get_reserved_space); | ||
1351 | return inode->i_sb->dq_op->get_reserved_space(inode); | ||
1352 | } | ||
1353 | |||
1354 | static void inode_add_rsv_space(struct inode *inode, qsize_t number) | ||
1355 | { | ||
1356 | spin_lock(&inode->i_lock); | ||
1357 | *inode_reserved_space(inode) += number; | ||
1358 | spin_unlock(&inode->i_lock); | ||
1359 | } | ||
1360 | |||
1361 | |||
1362 | static void inode_claim_rsv_space(struct inode *inode, qsize_t number) | ||
1363 | { | ||
1364 | spin_lock(&inode->i_lock); | ||
1365 | *inode_reserved_space(inode) -= number; | ||
1366 | __inode_add_bytes(inode, number); | ||
1367 | spin_unlock(&inode->i_lock); | ||
1368 | } | ||
1369 | |||
1370 | static void inode_sub_rsv_space(struct inode *inode, qsize_t number) | ||
1371 | { | ||
1372 | spin_lock(&inode->i_lock); | ||
1373 | *inode_reserved_space(inode) -= number; | ||
1374 | spin_unlock(&inode->i_lock); | ||
1375 | } | ||
1376 | |||
1377 | static qsize_t inode_get_rsv_space(struct inode *inode) | ||
1378 | { | ||
1379 | qsize_t ret; | ||
1380 | |||
1381 | if (!inode->i_sb->dq_op->get_reserved_space) | ||
1382 | return 0; | ||
1383 | spin_lock(&inode->i_lock); | ||
1384 | ret = *inode_reserved_space(inode); | ||
1385 | spin_unlock(&inode->i_lock); | ||
1386 | return ret; | ||
1387 | } | ||
1388 | |||
1389 | static void inode_incr_space(struct inode *inode, qsize_t number, | ||
1390 | int reserve) | ||
1391 | { | ||
1392 | if (reserve) | ||
1393 | inode_add_rsv_space(inode, number); | ||
1394 | else | ||
1395 | inode_add_bytes(inode, number); | ||
1396 | } | ||
1397 | |||
1398 | static void inode_decr_space(struct inode *inode, qsize_t number, int reserve) | ||
1399 | { | ||
1400 | if (reserve) | ||
1401 | inode_sub_rsv_space(inode, number); | ||
1402 | else | ||
1403 | inode_sub_bytes(inode, number); | ||
1404 | } | ||
1405 | |||
1406 | /* | ||
1322 | * Following four functions update i_blocks+i_bytes fields and | 1407 | * Following four functions update i_blocks+i_bytes fields and |
1323 | * quota information (together with appropriate checks) | 1408 | * quota information (together with appropriate checks) |
1324 | * NOTE: We absolutely rely on the fact that caller dirties | 1409 | * NOTE: We absolutely rely on the fact that caller dirties |
@@ -1336,6 +1421,21 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, | |||
1336 | int cnt, ret = QUOTA_OK; | 1421 | int cnt, ret = QUOTA_OK; |
1337 | char warntype[MAXQUOTAS]; | 1422 | char warntype[MAXQUOTAS]; |
1338 | 1423 | ||
1424 | /* | ||
1425 | * First test before acquiring mutex - solves deadlocks when we | ||
1426 | * re-enter the quota code and are already holding the mutex | ||
1427 | */ | ||
1428 | if (IS_NOQUOTA(inode)) { | ||
1429 | inode_incr_space(inode, number, reserve); | ||
1430 | goto out; | ||
1431 | } | ||
1432 | |||
1433 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | ||
1434 | if (IS_NOQUOTA(inode)) { | ||
1435 | inode_incr_space(inode, number, reserve); | ||
1436 | goto out_unlock; | ||
1437 | } | ||
1438 | |||
1339 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) | 1439 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
1340 | warntype[cnt] = QUOTA_NL_NOWARN; | 1440 | warntype[cnt] = QUOTA_NL_NOWARN; |
1341 | 1441 | ||
@@ -1346,7 +1446,8 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, | |||
1346 | if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) | 1446 | if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) |
1347 | == NO_QUOTA) { | 1447 | == NO_QUOTA) { |
1348 | ret = NO_QUOTA; | 1448 | ret = NO_QUOTA; |
1349 | goto out_unlock; | 1449 | spin_unlock(&dq_data_lock); |
1450 | goto out_flush_warn; | ||
1350 | } | 1451 | } |
1351 | } | 1452 | } |
1352 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { | 1453 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
@@ -1357,64 +1458,29 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, | |||
1357 | else | 1458 | else |
1358 | dquot_incr_space(inode->i_dquot[cnt], number); | 1459 | dquot_incr_space(inode->i_dquot[cnt], number); |
1359 | } | 1460 | } |
1360 | if (!reserve) | 1461 | inode_incr_space(inode, number, reserve); |
1361 | inode_add_bytes(inode, number); | ||
1362 | out_unlock: | ||
1363 | spin_unlock(&dq_data_lock); | 1462 | spin_unlock(&dq_data_lock); |
1463 | |||
1464 | if (reserve) | ||
1465 | goto out_flush_warn; | ||
1466 | mark_all_dquot_dirty(inode->i_dquot); | ||
1467 | out_flush_warn: | ||
1364 | flush_warnings(inode->i_dquot, warntype); | 1468 | flush_warnings(inode->i_dquot, warntype); |
1469 | out_unlock: | ||
1470 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | ||
1471 | out: | ||
1365 | return ret; | 1472 | return ret; |
1366 | } | 1473 | } |
1367 | 1474 | ||
1368 | int dquot_alloc_space(struct inode *inode, qsize_t number, int warn) | 1475 | int dquot_alloc_space(struct inode *inode, qsize_t number, int warn) |
1369 | { | 1476 | { |
1370 | int cnt, ret = QUOTA_OK; | 1477 | return __dquot_alloc_space(inode, number, warn, 0); |
1371 | |||
1372 | /* | ||
1373 | * First test before acquiring mutex - solves deadlocks when we | ||
1374 | * re-enter the quota code and are already holding the mutex | ||
1375 | */ | ||
1376 | if (IS_NOQUOTA(inode)) { | ||
1377 | inode_add_bytes(inode, number); | ||
1378 | goto out; | ||
1379 | } | ||
1380 | |||
1381 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | ||
1382 | if (IS_NOQUOTA(inode)) { | ||
1383 | inode_add_bytes(inode, number); | ||
1384 | goto out_unlock; | ||
1385 | } | ||
1386 | |||
1387 | ret = __dquot_alloc_space(inode, number, warn, 0); | ||
1388 | if (ret == NO_QUOTA) | ||
1389 | goto out_unlock; | ||
1390 | |||
1391 | /* Dirtify all the dquots - this can block when journalling */ | ||
1392 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) | ||
1393 | if (inode->i_dquot[cnt]) | ||
1394 | mark_dquot_dirty(inode->i_dquot[cnt]); | ||
1395 | out_unlock: | ||
1396 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | ||
1397 | out: | ||
1398 | return ret; | ||
1399 | } | 1478 | } |
1400 | EXPORT_SYMBOL(dquot_alloc_space); | 1479 | EXPORT_SYMBOL(dquot_alloc_space); |
1401 | 1480 | ||
1402 | int dquot_reserve_space(struct inode *inode, qsize_t number, int warn) | 1481 | int dquot_reserve_space(struct inode *inode, qsize_t number, int warn) |
1403 | { | 1482 | { |
1404 | int ret = QUOTA_OK; | 1483 | return __dquot_alloc_space(inode, number, warn, 1); |
1405 | |||
1406 | if (IS_NOQUOTA(inode)) | ||
1407 | goto out; | ||
1408 | |||
1409 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | ||
1410 | if (IS_NOQUOTA(inode)) | ||
1411 | goto out_unlock; | ||
1412 | |||
1413 | ret = __dquot_alloc_space(inode, number, warn, 1); | ||
1414 | out_unlock: | ||
1415 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | ||
1416 | out: | ||
1417 | return ret; | ||
1418 | } | 1484 | } |
1419 | EXPORT_SYMBOL(dquot_reserve_space); | 1485 | EXPORT_SYMBOL(dquot_reserve_space); |
1420 | 1486 | ||
@@ -1455,10 +1521,7 @@ int dquot_alloc_inode(const struct inode *inode, qsize_t number) | |||
1455 | warn_put_all: | 1521 | warn_put_all: |
1456 | spin_unlock(&dq_data_lock); | 1522 | spin_unlock(&dq_data_lock); |
1457 | if (ret == QUOTA_OK) | 1523 | if (ret == QUOTA_OK) |
1458 | /* Dirtify all the dquots - this can block when journalling */ | 1524 | mark_all_dquot_dirty(inode->i_dquot); |
1459 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) | ||
1460 | if (inode->i_dquot[cnt]) | ||
1461 | mark_dquot_dirty(inode->i_dquot[cnt]); | ||
1462 | flush_warnings(inode->i_dquot, warntype); | 1525 | flush_warnings(inode->i_dquot, warntype); |
1463 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | 1526 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1464 | return ret; | 1527 | return ret; |
@@ -1471,14 +1534,14 @@ int dquot_claim_space(struct inode *inode, qsize_t number) | |||
1471 | int ret = QUOTA_OK; | 1534 | int ret = QUOTA_OK; |
1472 | 1535 | ||
1473 | if (IS_NOQUOTA(inode)) { | 1536 | if (IS_NOQUOTA(inode)) { |
1474 | inode_add_bytes(inode, number); | 1537 | inode_claim_rsv_space(inode, number); |
1475 | goto out; | 1538 | goto out; |
1476 | } | 1539 | } |
1477 | 1540 | ||
1478 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | 1541 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1479 | if (IS_NOQUOTA(inode)) { | 1542 | if (IS_NOQUOTA(inode)) { |
1480 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | 1543 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1481 | inode_add_bytes(inode, number); | 1544 | inode_claim_rsv_space(inode, number); |
1482 | goto out; | 1545 | goto out; |
1483 | } | 1546 | } |
1484 | 1547 | ||
@@ -1490,12 +1553,9 @@ int dquot_claim_space(struct inode *inode, qsize_t number) | |||
1490 | number); | 1553 | number); |
1491 | } | 1554 | } |
1492 | /* Update inode bytes */ | 1555 | /* Update inode bytes */ |
1493 | inode_add_bytes(inode, number); | 1556 | inode_claim_rsv_space(inode, number); |
1494 | spin_unlock(&dq_data_lock); | 1557 | spin_unlock(&dq_data_lock); |
1495 | /* Dirtify all the dquots - this can block when journalling */ | 1558 | mark_all_dquot_dirty(inode->i_dquot); |
1496 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) | ||
1497 | if (inode->i_dquot[cnt]) | ||
1498 | mark_dquot_dirty(inode->i_dquot[cnt]); | ||
1499 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | 1559 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1500 | out: | 1560 | out: |
1501 | return ret; | 1561 | return ret; |
@@ -1503,38 +1563,9 @@ out: | |||
1503 | EXPORT_SYMBOL(dquot_claim_space); | 1563 | EXPORT_SYMBOL(dquot_claim_space); |
1504 | 1564 | ||
1505 | /* | 1565 | /* |
1506 | * Release reserved quota space | ||
1507 | */ | ||
1508 | void dquot_release_reserved_space(struct inode *inode, qsize_t number) | ||
1509 | { | ||
1510 | int cnt; | ||
1511 | |||
1512 | if (IS_NOQUOTA(inode)) | ||
1513 | goto out; | ||
1514 | |||
1515 | down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | ||
1516 | if (IS_NOQUOTA(inode)) | ||
1517 | goto out_unlock; | ||
1518 | |||
1519 | spin_lock(&dq_data_lock); | ||
1520 | /* Release reserved dquots */ | ||
1521 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { | ||
1522 | if (inode->i_dquot[cnt]) | ||
1523 | dquot_free_reserved_space(inode->i_dquot[cnt], number); | ||
1524 | } | ||
1525 | spin_unlock(&dq_data_lock); | ||
1526 | |||
1527 | out_unlock: | ||
1528 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | ||
1529 | out: | ||
1530 | return; | ||
1531 | } | ||
1532 | EXPORT_SYMBOL(dquot_release_reserved_space); | ||
1533 | |||
1534 | /* | ||
1535 | * This operation can block, but only after everything is updated | 1566 | * This operation can block, but only after everything is updated |
1536 | */ | 1567 | */ |
1537 | int dquot_free_space(struct inode *inode, qsize_t number) | 1568 | int __dquot_free_space(struct inode *inode, qsize_t number, int reserve) |
1538 | { | 1569 | { |
1539 | unsigned int cnt; | 1570 | unsigned int cnt; |
1540 | char warntype[MAXQUOTAS]; | 1571 | char warntype[MAXQUOTAS]; |
@@ -1543,7 +1574,7 @@ int dquot_free_space(struct inode *inode, qsize_t number) | |||
1543 | * re-enter the quota code and are already holding the mutex */ | 1574 | * re-enter the quota code and are already holding the mutex */ |
1544 | if (IS_NOQUOTA(inode)) { | 1575 | if (IS_NOQUOTA(inode)) { |
1545 | out_sub: | 1576 | out_sub: |
1546 | inode_sub_bytes(inode, number); | 1577 | inode_decr_space(inode, number, reserve); |
1547 | return QUOTA_OK; | 1578 | return QUOTA_OK; |
1548 | } | 1579 | } |
1549 | 1580 | ||
@@ -1558,21 +1589,40 @@ out_sub: | |||
1558 | if (!inode->i_dquot[cnt]) | 1589 | if (!inode->i_dquot[cnt]) |
1559 | continue; | 1590 | continue; |
1560 | warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number); | 1591 | warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number); |
1561 | dquot_decr_space(inode->i_dquot[cnt], number); | 1592 | if (reserve) |
1593 | dquot_free_reserved_space(inode->i_dquot[cnt], number); | ||
1594 | else | ||
1595 | dquot_decr_space(inode->i_dquot[cnt], number); | ||
1562 | } | 1596 | } |
1563 | inode_sub_bytes(inode, number); | 1597 | inode_decr_space(inode, number, reserve); |
1564 | spin_unlock(&dq_data_lock); | 1598 | spin_unlock(&dq_data_lock); |
1565 | /* Dirtify all the dquots - this can block when journalling */ | 1599 | |
1566 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) | 1600 | if (reserve) |
1567 | if (inode->i_dquot[cnt]) | 1601 | goto out_unlock; |
1568 | mark_dquot_dirty(inode->i_dquot[cnt]); | 1602 | mark_all_dquot_dirty(inode->i_dquot); |
1603 | out_unlock: | ||
1569 | flush_warnings(inode->i_dquot, warntype); | 1604 | flush_warnings(inode->i_dquot, warntype); |
1570 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | 1605 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1571 | return QUOTA_OK; | 1606 | return QUOTA_OK; |
1572 | } | 1607 | } |
1608 | |||
1609 | int dquot_free_space(struct inode *inode, qsize_t number) | ||
1610 | { | ||
1611 | return __dquot_free_space(inode, number, 0); | ||
1612 | } | ||
1573 | EXPORT_SYMBOL(dquot_free_space); | 1613 | EXPORT_SYMBOL(dquot_free_space); |
1574 | 1614 | ||
1575 | /* | 1615 | /* |
1616 | * Release reserved quota space | ||
1617 | */ | ||
1618 | void dquot_release_reserved_space(struct inode *inode, qsize_t number) | ||
1619 | { | ||
1620 | __dquot_free_space(inode, number, 1); | ||
1621 | |||
1622 | } | ||
1623 | EXPORT_SYMBOL(dquot_release_reserved_space); | ||
1624 | |||
1625 | /* | ||
1576 | * This operation can block, but only after everything is updated | 1626 | * This operation can block, but only after everything is updated |
1577 | */ | 1627 | */ |
1578 | int dquot_free_inode(const struct inode *inode, qsize_t number) | 1628 | int dquot_free_inode(const struct inode *inode, qsize_t number) |
@@ -1599,10 +1649,7 @@ int dquot_free_inode(const struct inode *inode, qsize_t number) | |||
1599 | dquot_decr_inodes(inode->i_dquot[cnt], number); | 1649 | dquot_decr_inodes(inode->i_dquot[cnt], number); |
1600 | } | 1650 | } |
1601 | spin_unlock(&dq_data_lock); | 1651 | spin_unlock(&dq_data_lock); |
1602 | /* Dirtify all the dquots - this can block when journalling */ | 1652 | mark_all_dquot_dirty(inode->i_dquot); |
1603 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) | ||
1604 | if (inode->i_dquot[cnt]) | ||
1605 | mark_dquot_dirty(inode->i_dquot[cnt]); | ||
1606 | flush_warnings(inode->i_dquot, warntype); | 1653 | flush_warnings(inode->i_dquot, warntype); |
1607 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); | 1654 | up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1608 | return QUOTA_OK; | 1655 | return QUOTA_OK; |
@@ -1610,19 +1657,6 @@ int dquot_free_inode(const struct inode *inode, qsize_t number) | |||
1610 | EXPORT_SYMBOL(dquot_free_inode); | 1657 | EXPORT_SYMBOL(dquot_free_inode); |
1611 | 1658 | ||
1612 | /* | 1659 | /* |
1613 | * call back function, get reserved quota space from underlying fs | ||
1614 | */ | ||
1615 | qsize_t dquot_get_reserved_space(struct inode *inode) | ||
1616 | { | ||
1617 | qsize_t reserved_space = 0; | ||
1618 | |||
1619 | if (sb_any_quota_active(inode->i_sb) && | ||
1620 | inode->i_sb->dq_op->get_reserved_space) | ||
1621 | reserved_space = inode->i_sb->dq_op->get_reserved_space(inode); | ||
1622 | return reserved_space; | ||
1623 | } | ||
1624 | |||
1625 | /* | ||
1626 | * Transfer the number of inode and blocks from one diskquota to an other. | 1660 | * Transfer the number of inode and blocks from one diskquota to an other. |
1627 | * | 1661 | * |
1628 | * This operation can block, but only after everything is updated | 1662 | * This operation can block, but only after everything is updated |
@@ -1665,7 +1699,7 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr) | |||
1665 | } | 1699 | } |
1666 | spin_lock(&dq_data_lock); | 1700 | spin_lock(&dq_data_lock); |
1667 | cur_space = inode_get_bytes(inode); | 1701 | cur_space = inode_get_bytes(inode); |
1668 | rsv_space = dquot_get_reserved_space(inode); | 1702 | rsv_space = inode_get_rsv_space(inode); |
1669 | space = cur_space + rsv_space; | 1703 | space = cur_space + rsv_space; |
1670 | /* Build the transfer_from list and check the limits */ | 1704 | /* Build the transfer_from list and check the limits */ |
1671 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { | 1705 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
@@ -1709,25 +1743,18 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr) | |||
1709 | spin_unlock(&dq_data_lock); | 1743 | spin_unlock(&dq_data_lock); |
1710 | up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); | 1744 | up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); |
1711 | 1745 | ||
1712 | /* Dirtify all the dquots - this can block when journalling */ | 1746 | mark_all_dquot_dirty(transfer_from); |
1713 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { | 1747 | mark_all_dquot_dirty(transfer_to); |
1714 | if (transfer_from[cnt]) | 1748 | /* The reference we got is transferred to the inode */ |
1715 | mark_dquot_dirty(transfer_from[cnt]); | 1749 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) |
1716 | if (transfer_to[cnt]) { | 1750 | transfer_to[cnt] = NULL; |
1717 | mark_dquot_dirty(transfer_to[cnt]); | ||
1718 | /* The reference we got is transferred to the inode */ | ||
1719 | transfer_to[cnt] = NULL; | ||
1720 | } | ||
1721 | } | ||
1722 | warn_put_all: | 1751 | warn_put_all: |
1723 | flush_warnings(transfer_to, warntype_to); | 1752 | flush_warnings(transfer_to, warntype_to); |
1724 | flush_warnings(transfer_from, warntype_from_inodes); | 1753 | flush_warnings(transfer_from, warntype_from_inodes); |
1725 | flush_warnings(transfer_from, warntype_from_space); | 1754 | flush_warnings(transfer_from, warntype_from_space); |
1726 | put_all: | 1755 | put_all: |
1727 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { | 1756 | dqput_all(transfer_from); |
1728 | dqput(transfer_from[cnt]); | 1757 | dqput_all(transfer_to); |
1729 | dqput(transfer_to[cnt]); | ||
1730 | } | ||
1731 | return ret; | 1758 | return ret; |
1732 | over_quota: | 1759 | over_quota: |
1733 | spin_unlock(&dq_data_lock); | 1760 | spin_unlock(&dq_data_lock); |
diff --git a/fs/quota/quota_v2.c b/fs/quota/quota_v2.c index 3dfc23e02135..e3da02f4986f 100644 --- a/fs/quota/quota_v2.c +++ b/fs/quota/quota_v2.c | |||
@@ -97,8 +97,11 @@ static int v2_read_file_info(struct super_block *sb, int type) | |||
97 | unsigned int version; | 97 | unsigned int version; |
98 | 98 | ||
99 | if (!v2_read_header(sb, type, &dqhead)) | 99 | if (!v2_read_header(sb, type, &dqhead)) |
100 | return 0; | 100 | return -1; |
101 | version = le32_to_cpu(dqhead.dqh_version); | 101 | version = le32_to_cpu(dqhead.dqh_version); |
102 | if ((info->dqi_fmt_id == QFMT_VFS_V0 && version != 0) || | ||
103 | (info->dqi_fmt_id == QFMT_VFS_V1 && version != 1)) | ||
104 | return -1; | ||
102 | 105 | ||
103 | size = sb->s_op->quota_read(sb, type, (char *)&dinfo, | 106 | size = sb->s_op->quota_read(sb, type, (char *)&dinfo, |
104 | sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF); | 107 | sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF); |
@@ -120,8 +123,8 @@ static int v2_read_file_info(struct super_block *sb, int type) | |||
120 | info->dqi_maxilimit = 0xffffffff; | 123 | info->dqi_maxilimit = 0xffffffff; |
121 | } else { | 124 | } else { |
122 | /* used space is stored as unsigned 64-bit value */ | 125 | /* used space is stored as unsigned 64-bit value */ |
123 | info->dqi_maxblimit = 0xffffffffffffffff; /* 2^64-1 */ | 126 | info->dqi_maxblimit = 0xffffffffffffffffULL; /* 2^64-1 */ |
124 | info->dqi_maxilimit = 0xffffffffffffffff; | 127 | info->dqi_maxilimit = 0xffffffffffffffffULL; |
125 | } | 128 | } |
126 | info->dqi_bgrace = le32_to_cpu(dinfo.dqi_bgrace); | 129 | info->dqi_bgrace = le32_to_cpu(dinfo.dqi_bgrace); |
127 | info->dqi_igrace = le32_to_cpu(dinfo.dqi_igrace); | 130 | info->dqi_igrace = le32_to_cpu(dinfo.dqi_igrace); |
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c index 32fae4040ebf..2efc57173fd7 100644 --- a/fs/ramfs/file-nommu.c +++ b/fs/ramfs/file-nommu.c | |||
@@ -60,7 +60,7 @@ const struct inode_operations ramfs_file_inode_operations = { | |||
60 | */ | 60 | */ |
61 | int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize) | 61 | int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize) |
62 | { | 62 | { |
63 | unsigned long npages, xpages, loop, limit; | 63 | unsigned long npages, xpages, loop; |
64 | struct page *pages; | 64 | struct page *pages; |
65 | unsigned order; | 65 | unsigned order; |
66 | void *data; | 66 | void *data; |
diff --git a/fs/reiserfs/Kconfig b/fs/reiserfs/Kconfig index ac7cd75c86f8..513f431038f9 100644 --- a/fs/reiserfs/Kconfig +++ b/fs/reiserfs/Kconfig | |||
@@ -1,7 +1,6 @@ | |||
1 | config REISERFS_FS | 1 | config REISERFS_FS |
2 | tristate "Reiserfs support" | 2 | tristate "Reiserfs support" |
3 | select CRC32 | 3 | select CRC32 |
4 | select FS_JOURNAL_INFO | ||
5 | help | 4 | help |
6 | Stores not just filenames but the files themselves in a balanced | 5 | Stores not just filenames but the files themselves in a balanced |
7 | tree. Uses journalling. | 6 | tree. Uses journalling. |
diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c index 685495707181..65c872761177 100644 --- a/fs/reiserfs/bitmap.c +++ b/fs/reiserfs/bitmap.c | |||
@@ -1277,7 +1277,10 @@ int reiserfs_init_bitmap_cache(struct super_block *sb) | |||
1277 | struct reiserfs_bitmap_info *bitmap; | 1277 | struct reiserfs_bitmap_info *bitmap; |
1278 | unsigned int bmap_nr = reiserfs_bmap_count(sb); | 1278 | unsigned int bmap_nr = reiserfs_bmap_count(sb); |
1279 | 1279 | ||
1280 | /* Avoid lock recursion in fault case */ | ||
1281 | reiserfs_write_unlock(sb); | ||
1280 | bitmap = vmalloc(sizeof(*bitmap) * bmap_nr); | 1282 | bitmap = vmalloc(sizeof(*bitmap) * bmap_nr); |
1283 | reiserfs_write_lock(sb); | ||
1281 | if (bitmap == NULL) | 1284 | if (bitmap == NULL) |
1282 | return -ENOMEM; | 1285 | return -ENOMEM; |
1283 | 1286 | ||
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c index 3a28e7751b3c..9087b10209e6 100644 --- a/fs/reiserfs/inode.c +++ b/fs/reiserfs/inode.c | |||
@@ -31,11 +31,12 @@ void reiserfs_delete_inode(struct inode *inode) | |||
31 | JOURNAL_PER_BALANCE_CNT * 2 + | 31 | JOURNAL_PER_BALANCE_CNT * 2 + |
32 | 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb); | 32 | 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb); |
33 | struct reiserfs_transaction_handle th; | 33 | struct reiserfs_transaction_handle th; |
34 | int depth; | ||
34 | int err; | 35 | int err; |
35 | 36 | ||
36 | truncate_inode_pages(&inode->i_data, 0); | 37 | truncate_inode_pages(&inode->i_data, 0); |
37 | 38 | ||
38 | reiserfs_write_lock(inode->i_sb); | 39 | depth = reiserfs_write_lock_once(inode->i_sb); |
39 | 40 | ||
40 | /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */ | 41 | /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */ |
41 | if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */ | 42 | if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) { /* also handles bad_inode case */ |
@@ -74,7 +75,7 @@ void reiserfs_delete_inode(struct inode *inode) | |||
74 | out: | 75 | out: |
75 | clear_inode(inode); /* note this must go after the journal_end to prevent deadlock */ | 76 | clear_inode(inode); /* note this must go after the journal_end to prevent deadlock */ |
76 | inode->i_blocks = 0; | 77 | inode->i_blocks = 0; |
77 | reiserfs_write_unlock(inode->i_sb); | 78 | reiserfs_write_unlock_once(inode->i_sb, depth); |
78 | } | 79 | } |
79 | 80 | ||
80 | static void _make_cpu_key(struct cpu_key *key, int version, __u32 dirid, | 81 | static void _make_cpu_key(struct cpu_key *key, int version, __u32 dirid, |
@@ -2538,6 +2539,12 @@ static int reiserfs_writepage(struct page *page, struct writeback_control *wbc) | |||
2538 | return reiserfs_write_full_page(page, wbc); | 2539 | return reiserfs_write_full_page(page, wbc); |
2539 | } | 2540 | } |
2540 | 2541 | ||
2542 | static void reiserfs_truncate_failed_write(struct inode *inode) | ||
2543 | { | ||
2544 | truncate_inode_pages(inode->i_mapping, inode->i_size); | ||
2545 | reiserfs_truncate_file(inode, 0); | ||
2546 | } | ||
2547 | |||
2541 | static int reiserfs_write_begin(struct file *file, | 2548 | static int reiserfs_write_begin(struct file *file, |
2542 | struct address_space *mapping, | 2549 | struct address_space *mapping, |
2543 | loff_t pos, unsigned len, unsigned flags, | 2550 | loff_t pos, unsigned len, unsigned flags, |
@@ -2604,6 +2611,8 @@ static int reiserfs_write_begin(struct file *file, | |||
2604 | if (ret) { | 2611 | if (ret) { |
2605 | unlock_page(page); | 2612 | unlock_page(page); |
2606 | page_cache_release(page); | 2613 | page_cache_release(page); |
2614 | /* Truncate allocated blocks */ | ||
2615 | reiserfs_truncate_failed_write(inode); | ||
2607 | } | 2616 | } |
2608 | return ret; | 2617 | return ret; |
2609 | } | 2618 | } |
@@ -2701,9 +2710,7 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping, | |||
2701 | ** transaction tracking stuff when the size changes. So, we have | 2710 | ** transaction tracking stuff when the size changes. So, we have |
2702 | ** to do the i_size updates here. | 2711 | ** to do the i_size updates here. |
2703 | */ | 2712 | */ |
2704 | pos += copied; | 2713 | if (pos + copied > inode->i_size) { |
2705 | |||
2706 | if (pos > inode->i_size) { | ||
2707 | struct reiserfs_transaction_handle myth; | 2714 | struct reiserfs_transaction_handle myth; |
2708 | lock_depth = reiserfs_write_lock_once(inode->i_sb); | 2715 | lock_depth = reiserfs_write_lock_once(inode->i_sb); |
2709 | locked = true; | 2716 | locked = true; |
@@ -2721,7 +2728,7 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping, | |||
2721 | goto journal_error; | 2728 | goto journal_error; |
2722 | 2729 | ||
2723 | reiserfs_update_inode_transaction(inode); | 2730 | reiserfs_update_inode_transaction(inode); |
2724 | inode->i_size = pos; | 2731 | inode->i_size = pos + copied; |
2725 | /* | 2732 | /* |
2726 | * this will just nest into our transaction. It's important | 2733 | * this will just nest into our transaction. It's important |
2727 | * to use mark_inode_dirty so the inode gets pushed around on the | 2734 | * to use mark_inode_dirty so the inode gets pushed around on the |
@@ -2751,6 +2758,10 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping, | |||
2751 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); | 2758 | reiserfs_write_unlock_once(inode->i_sb, lock_depth); |
2752 | unlock_page(page); | 2759 | unlock_page(page); |
2753 | page_cache_release(page); | 2760 | page_cache_release(page); |
2761 | |||
2762 | if (pos + len > inode->i_size) | ||
2763 | reiserfs_truncate_failed_write(inode); | ||
2764 | |||
2754 | return ret == 0 ? copied : ret; | 2765 | return ret == 0 ? copied : ret; |
2755 | 2766 | ||
2756 | journal_error: | 2767 | journal_error: |
@@ -3051,13 +3062,14 @@ static ssize_t reiserfs_direct_IO(int rw, struct kiocb *iocb, | |||
3051 | int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) | 3062 | int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) |
3052 | { | 3063 | { |
3053 | struct inode *inode = dentry->d_inode; | 3064 | struct inode *inode = dentry->d_inode; |
3054 | int error; | ||
3055 | unsigned int ia_valid; | 3065 | unsigned int ia_valid; |
3066 | int depth; | ||
3067 | int error; | ||
3056 | 3068 | ||
3057 | /* must be turned off for recursive notify_change calls */ | 3069 | /* must be turned off for recursive notify_change calls */ |
3058 | ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID); | 3070 | ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID); |
3059 | 3071 | ||
3060 | reiserfs_write_lock(inode->i_sb); | 3072 | depth = reiserfs_write_lock_once(inode->i_sb); |
3061 | if (attr->ia_valid & ATTR_SIZE) { | 3073 | if (attr->ia_valid & ATTR_SIZE) { |
3062 | /* version 2 items will be caught by the s_maxbytes check | 3074 | /* version 2 items will be caught by the s_maxbytes check |
3063 | ** done for us in vmtruncate | 3075 | ** done for us in vmtruncate |
@@ -3138,8 +3150,17 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
3138 | journal_end(&th, inode->i_sb, jbegin_count); | 3150 | journal_end(&th, inode->i_sb, jbegin_count); |
3139 | } | 3151 | } |
3140 | } | 3152 | } |
3141 | if (!error) | 3153 | if (!error) { |
3154 | /* | ||
3155 | * Relax the lock here, as it might truncate the | ||
3156 | * inode pages and wait for inode pages locks. | ||
3157 | * To release such page lock, the owner needs the | ||
3158 | * reiserfs lock | ||
3159 | */ | ||
3160 | reiserfs_write_unlock_once(inode->i_sb, depth); | ||
3142 | error = inode_setattr(inode, attr); | 3161 | error = inode_setattr(inode, attr); |
3162 | depth = reiserfs_write_lock_once(inode->i_sb); | ||
3163 | } | ||
3143 | } | 3164 | } |
3144 | 3165 | ||
3145 | if (!error && reiserfs_posixacl(inode->i_sb)) { | 3166 | if (!error && reiserfs_posixacl(inode->i_sb)) { |
@@ -3148,7 +3169,8 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
3148 | } | 3169 | } |
3149 | 3170 | ||
3150 | out: | 3171 | out: |
3151 | reiserfs_write_unlock(inode->i_sb); | 3172 | reiserfs_write_unlock_once(inode->i_sb, depth); |
3173 | |||
3152 | return error; | 3174 | return error; |
3153 | } | 3175 | } |
3154 | 3176 | ||
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c index ace77451ceb1..f53505de0712 100644 --- a/fs/reiserfs/ioctl.c +++ b/fs/reiserfs/ioctl.c | |||
@@ -104,9 +104,10 @@ setflags_out: | |||
104 | err = put_user(inode->i_generation, (int __user *)arg); | 104 | err = put_user(inode->i_generation, (int __user *)arg); |
105 | break; | 105 | break; |
106 | case REISERFS_IOC_SETVERSION: | 106 | case REISERFS_IOC_SETVERSION: |
107 | if (!is_owner_or_cap(inode)) | 107 | if (!is_owner_or_cap(inode)) { |
108 | err = -EPERM; | 108 | err = -EPERM; |
109 | break; | 109 | break; |
110 | } | ||
110 | err = mnt_want_write(filp->f_path.mnt); | 111 | err = mnt_want_write(filp->f_path.mnt); |
111 | if (err) | 112 | if (err) |
112 | break; | 113 | break; |
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index 2f8a7e7b8dab..83ac4d3b3cb0 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c | |||
@@ -2009,10 +2009,11 @@ static int do_journal_release(struct reiserfs_transaction_handle *th, | |||
2009 | destroy_workqueue(commit_wq); | 2009 | destroy_workqueue(commit_wq); |
2010 | commit_wq = NULL; | 2010 | commit_wq = NULL; |
2011 | } | 2011 | } |
2012 | reiserfs_write_lock(sb); | ||
2013 | 2012 | ||
2014 | free_journal_ram(sb); | 2013 | free_journal_ram(sb); |
2015 | 2014 | ||
2015 | reiserfs_write_lock(sb); | ||
2016 | |||
2016 | return 0; | 2017 | return 0; |
2017 | } | 2018 | } |
2018 | 2019 | ||
@@ -2758,11 +2759,18 @@ int journal_init(struct super_block *sb, const char *j_dev_name, | |||
2758 | struct reiserfs_journal *journal; | 2759 | struct reiserfs_journal *journal; |
2759 | struct reiserfs_journal_list *jl; | 2760 | struct reiserfs_journal_list *jl; |
2760 | char b[BDEVNAME_SIZE]; | 2761 | char b[BDEVNAME_SIZE]; |
2762 | int ret; | ||
2761 | 2763 | ||
2764 | /* | ||
2765 | * Unlock here to avoid various RECLAIM-FS-ON <-> IN-RECLAIM-FS | ||
2766 | * dependency inversion warnings. | ||
2767 | */ | ||
2768 | reiserfs_write_unlock(sb); | ||
2762 | journal = SB_JOURNAL(sb) = vmalloc(sizeof(struct reiserfs_journal)); | 2769 | journal = SB_JOURNAL(sb) = vmalloc(sizeof(struct reiserfs_journal)); |
2763 | if (!journal) { | 2770 | if (!journal) { |
2764 | reiserfs_warning(sb, "journal-1256", | 2771 | reiserfs_warning(sb, "journal-1256", |
2765 | "unable to get memory for journal structure"); | 2772 | "unable to get memory for journal structure"); |
2773 | reiserfs_write_lock(sb); | ||
2766 | return 1; | 2774 | return 1; |
2767 | } | 2775 | } |
2768 | memset(journal, 0, sizeof(struct reiserfs_journal)); | 2776 | memset(journal, 0, sizeof(struct reiserfs_journal)); |
@@ -2771,10 +2779,12 @@ int journal_init(struct super_block *sb, const char *j_dev_name, | |||
2771 | INIT_LIST_HEAD(&journal->j_working_list); | 2779 | INIT_LIST_HEAD(&journal->j_working_list); |
2772 | INIT_LIST_HEAD(&journal->j_journal_list); | 2780 | INIT_LIST_HEAD(&journal->j_journal_list); |
2773 | journal->j_persistent_trans = 0; | 2781 | journal->j_persistent_trans = 0; |
2774 | if (reiserfs_allocate_list_bitmaps(sb, | 2782 | ret = reiserfs_allocate_list_bitmaps(sb, journal->j_list_bitmap, |
2775 | journal->j_list_bitmap, | 2783 | reiserfs_bmap_count(sb)); |
2776 | reiserfs_bmap_count(sb))) | 2784 | reiserfs_write_lock(sb); |
2785 | if (ret) | ||
2777 | goto free_and_return; | 2786 | goto free_and_return; |
2787 | |||
2778 | allocate_bitmap_nodes(sb); | 2788 | allocate_bitmap_nodes(sb); |
2779 | 2789 | ||
2780 | /* reserved for journal area support */ | 2790 | /* reserved for journal area support */ |
diff --git a/fs/reiserfs/lock.c b/fs/reiserfs/lock.c index ee2cfc0fd8a7..b87aa2c1afc1 100644 --- a/fs/reiserfs/lock.c +++ b/fs/reiserfs/lock.c | |||
@@ -86,3 +86,12 @@ void reiserfs_check_lock_depth(struct super_block *sb, char *caller) | |||
86 | reiserfs_panic(sb, "%s called without kernel lock held %d", | 86 | reiserfs_panic(sb, "%s called without kernel lock held %d", |
87 | caller); | 87 | caller); |
88 | } | 88 | } |
89 | |||
90 | #ifdef CONFIG_REISERFS_CHECK | ||
91 | void reiserfs_lock_check_recursive(struct super_block *sb) | ||
92 | { | ||
93 | struct reiserfs_sb_info *sb_i = REISERFS_SB(sb); | ||
94 | |||
95 | WARN_ONCE((sb_i->lock_depth > 0), "Unwanted recursive reiserfs lock!\n"); | ||
96 | } | ||
97 | #endif | ||
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c index e296ff72a6cc..9d4dcf0b07cb 100644 --- a/fs/reiserfs/namei.c +++ b/fs/reiserfs/namei.c | |||
@@ -921,6 +921,7 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry) | |||
921 | struct reiserfs_transaction_handle th; | 921 | struct reiserfs_transaction_handle th; |
922 | int jbegin_count; | 922 | int jbegin_count; |
923 | unsigned long savelink; | 923 | unsigned long savelink; |
924 | int depth; | ||
924 | 925 | ||
925 | inode = dentry->d_inode; | 926 | inode = dentry->d_inode; |
926 | 927 | ||
@@ -932,7 +933,7 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry) | |||
932 | JOURNAL_PER_BALANCE_CNT * 2 + 2 + | 933 | JOURNAL_PER_BALANCE_CNT * 2 + 2 + |
933 | 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); | 934 | 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); |
934 | 935 | ||
935 | reiserfs_write_lock(dir->i_sb); | 936 | depth = reiserfs_write_lock_once(dir->i_sb); |
936 | retval = journal_begin(&th, dir->i_sb, jbegin_count); | 937 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
937 | if (retval) | 938 | if (retval) |
938 | goto out_unlink; | 939 | goto out_unlink; |
@@ -993,7 +994,7 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry) | |||
993 | 994 | ||
994 | retval = journal_end(&th, dir->i_sb, jbegin_count); | 995 | retval = journal_end(&th, dir->i_sb, jbegin_count); |
995 | reiserfs_check_path(&path); | 996 | reiserfs_check_path(&path); |
996 | reiserfs_write_unlock(dir->i_sb); | 997 | reiserfs_write_unlock_once(dir->i_sb, depth); |
997 | return retval; | 998 | return retval; |
998 | 999 | ||
999 | end_unlink: | 1000 | end_unlink: |
@@ -1003,7 +1004,7 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry) | |||
1003 | if (err) | 1004 | if (err) |
1004 | retval = err; | 1005 | retval = err; |
1005 | out_unlink: | 1006 | out_unlink: |
1006 | reiserfs_write_unlock(dir->i_sb); | 1007 | reiserfs_write_unlock_once(dir->i_sb, depth); |
1007 | return retval; | 1008 | return retval; |
1008 | } | 1009 | } |
1009 | 1010 | ||
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c index 8c7033a8b67e..81f09fab8ae4 100644 --- a/fs/reiserfs/xattr.c +++ b/fs/reiserfs/xattr.c | |||
@@ -83,7 +83,8 @@ static int xattr_unlink(struct inode *dir, struct dentry *dentry) | |||
83 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); | 83 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); |
84 | vfs_dq_init(dir); | 84 | vfs_dq_init(dir); |
85 | 85 | ||
86 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); | 86 | reiserfs_mutex_lock_nested_safe(&dentry->d_inode->i_mutex, |
87 | I_MUTEX_CHILD, dir->i_sb); | ||
87 | error = dir->i_op->unlink(dir, dentry); | 88 | error = dir->i_op->unlink(dir, dentry); |
88 | mutex_unlock(&dentry->d_inode->i_mutex); | 89 | mutex_unlock(&dentry->d_inode->i_mutex); |
89 | 90 | ||
@@ -98,7 +99,8 @@ static int xattr_rmdir(struct inode *dir, struct dentry *dentry) | |||
98 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); | 99 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); |
99 | vfs_dq_init(dir); | 100 | vfs_dq_init(dir); |
100 | 101 | ||
101 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); | 102 | reiserfs_mutex_lock_nested_safe(&dentry->d_inode->i_mutex, |
103 | I_MUTEX_CHILD, dir->i_sb); | ||
102 | dentry_unhash(dentry); | 104 | dentry_unhash(dentry); |
103 | error = dir->i_op->rmdir(dir, dentry); | 105 | error = dir->i_op->rmdir(dir, dentry); |
104 | if (!error) | 106 | if (!error) |
@@ -235,16 +237,22 @@ static int reiserfs_for_each_xattr(struct inode *inode, | |||
235 | if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1) | 237 | if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1) |
236 | return 0; | 238 | return 0; |
237 | 239 | ||
240 | reiserfs_write_unlock(inode->i_sb); | ||
238 | dir = open_xa_dir(inode, XATTR_REPLACE); | 241 | dir = open_xa_dir(inode, XATTR_REPLACE); |
239 | if (IS_ERR(dir)) { | 242 | if (IS_ERR(dir)) { |
240 | err = PTR_ERR(dir); | 243 | err = PTR_ERR(dir); |
244 | reiserfs_write_lock(inode->i_sb); | ||
241 | goto out; | 245 | goto out; |
242 | } else if (!dir->d_inode) { | 246 | } else if (!dir->d_inode) { |
243 | err = 0; | 247 | err = 0; |
248 | reiserfs_write_lock(inode->i_sb); | ||
244 | goto out_dir; | 249 | goto out_dir; |
245 | } | 250 | } |
246 | 251 | ||
247 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); | 252 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); |
253 | |||
254 | reiserfs_write_lock(inode->i_sb); | ||
255 | |||
248 | buf.xadir = dir; | 256 | buf.xadir = dir; |
249 | err = reiserfs_readdir_dentry(dir, &buf, fill_with_dentries, &pos); | 257 | err = reiserfs_readdir_dentry(dir, &buf, fill_with_dentries, &pos); |
250 | while ((err == 0 || err == -ENOSPC) && buf.count) { | 258 | while ((err == 0 || err == -ENOSPC) && buf.count) { |
@@ -283,8 +291,9 @@ static int reiserfs_for_each_xattr(struct inode *inode, | |||
283 | err = journal_begin(&th, inode->i_sb, blocks); | 291 | err = journal_begin(&th, inode->i_sb, blocks); |
284 | if (!err) { | 292 | if (!err) { |
285 | int jerror; | 293 | int jerror; |
286 | mutex_lock_nested(&dir->d_parent->d_inode->i_mutex, | 294 | reiserfs_mutex_lock_nested_safe( |
287 | I_MUTEX_XATTR); | 295 | &dir->d_parent->d_inode->i_mutex, |
296 | I_MUTEX_XATTR, inode->i_sb); | ||
288 | err = action(dir, data); | 297 | err = action(dir, data); |
289 | jerror = journal_end(&th, inode->i_sb, blocks); | 298 | jerror = journal_end(&th, inode->i_sb, blocks); |
290 | mutex_unlock(&dir->d_parent->d_inode->i_mutex); | 299 | mutex_unlock(&dir->d_parent->d_inode->i_mutex); |
@@ -443,7 +452,9 @@ static int lookup_and_delete_xattr(struct inode *inode, const char *name) | |||
443 | } | 452 | } |
444 | 453 | ||
445 | if (dentry->d_inode) { | 454 | if (dentry->d_inode) { |
455 | reiserfs_write_lock(inode->i_sb); | ||
446 | err = xattr_unlink(xadir->d_inode, dentry); | 456 | err = xattr_unlink(xadir->d_inode, dentry); |
457 | reiserfs_write_unlock(inode->i_sb); | ||
447 | update_ctime(inode); | 458 | update_ctime(inode); |
448 | } | 459 | } |
449 | 460 | ||
@@ -477,15 +488,24 @@ reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th, | |||
477 | if (get_inode_sd_version(inode) == STAT_DATA_V1) | 488 | if (get_inode_sd_version(inode) == STAT_DATA_V1) |
478 | return -EOPNOTSUPP; | 489 | return -EOPNOTSUPP; |
479 | 490 | ||
480 | if (!buffer) | 491 | reiserfs_write_unlock(inode->i_sb); |
481 | return lookup_and_delete_xattr(inode, name); | 492 | |
493 | if (!buffer) { | ||
494 | err = lookup_and_delete_xattr(inode, name); | ||
495 | reiserfs_write_lock(inode->i_sb); | ||
496 | return err; | ||
497 | } | ||
482 | 498 | ||
483 | dentry = xattr_lookup(inode, name, flags); | 499 | dentry = xattr_lookup(inode, name, flags); |
484 | if (IS_ERR(dentry)) | 500 | if (IS_ERR(dentry)) { |
501 | reiserfs_write_lock(inode->i_sb); | ||
485 | return PTR_ERR(dentry); | 502 | return PTR_ERR(dentry); |
503 | } | ||
486 | 504 | ||
487 | down_write(&REISERFS_I(inode)->i_xattr_sem); | 505 | down_write(&REISERFS_I(inode)->i_xattr_sem); |
488 | 506 | ||
507 | reiserfs_write_lock(inode->i_sb); | ||
508 | |||
489 | xahash = xattr_hash(buffer, buffer_size); | 509 | xahash = xattr_hash(buffer, buffer_size); |
490 | while (buffer_pos < buffer_size || buffer_pos == 0) { | 510 | while (buffer_pos < buffer_size || buffer_pos == 0) { |
491 | size_t chunk; | 511 | size_t chunk; |
@@ -540,8 +560,12 @@ reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th, | |||
540 | .ia_size = buffer_size, | 560 | .ia_size = buffer_size, |
541 | .ia_valid = ATTR_SIZE | ATTR_CTIME, | 561 | .ia_valid = ATTR_SIZE | ATTR_CTIME, |
542 | }; | 562 | }; |
563 | |||
564 | reiserfs_write_unlock(inode->i_sb); | ||
543 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR); | 565 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR); |
544 | down_write(&dentry->d_inode->i_alloc_sem); | 566 | down_write(&dentry->d_inode->i_alloc_sem); |
567 | reiserfs_write_lock(inode->i_sb); | ||
568 | |||
545 | err = reiserfs_setattr(dentry, &newattrs); | 569 | err = reiserfs_setattr(dentry, &newattrs); |
546 | up_write(&dentry->d_inode->i_alloc_sem); | 570 | up_write(&dentry->d_inode->i_alloc_sem); |
547 | mutex_unlock(&dentry->d_inode->i_mutex); | 571 | mutex_unlock(&dentry->d_inode->i_mutex); |
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c index cc32e6ada67b..dd20a7883f0f 100644 --- a/fs/reiserfs/xattr_acl.c +++ b/fs/reiserfs/xattr_acl.c | |||
@@ -455,7 +455,9 @@ int reiserfs_acl_chmod(struct inode *inode) | |||
455 | return 0; | 455 | return 0; |
456 | } | 456 | } |
457 | 457 | ||
458 | reiserfs_write_unlock(inode->i_sb); | ||
458 | acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); | 459 | acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); |
460 | reiserfs_write_lock(inode->i_sb); | ||
459 | if (!acl) | 461 | if (!acl) |
460 | return 0; | 462 | return 0; |
461 | if (IS_ERR(acl)) | 463 | if (IS_ERR(acl)) |
diff --git a/fs/signalfd.c b/fs/signalfd.c index b07565c94386..1dabe4ee02fe 100644 --- a/fs/signalfd.c +++ b/fs/signalfd.c | |||
@@ -236,7 +236,7 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask, | |||
236 | * anon_inode_getfd() will install the fd. | 236 | * anon_inode_getfd() will install the fd. |
237 | */ | 237 | */ |
238 | ufd = anon_inode_getfd("[signalfd]", &signalfd_fops, ctx, | 238 | ufd = anon_inode_getfd("[signalfd]", &signalfd_fops, ctx, |
239 | flags & (O_CLOEXEC | O_NONBLOCK)); | 239 | O_RDWR | (flags & (O_CLOEXEC | O_NONBLOCK))); |
240 | if (ufd < 0) | 240 | if (ufd < 0) |
241 | kfree(ctx); | 241 | kfree(ctx); |
242 | } else { | 242 | } else { |
diff --git a/fs/stack.c b/fs/stack.c index 67716f6a1a4a..4a6f7f440658 100644 --- a/fs/stack.c +++ b/fs/stack.c | |||
@@ -7,18 +7,63 @@ | |||
7 | * This function cannot be inlined since i_size_{read,write} is rather | 7 | * This function cannot be inlined since i_size_{read,write} is rather |
8 | * heavy-weight on 32-bit systems | 8 | * heavy-weight on 32-bit systems |
9 | */ | 9 | */ |
10 | void fsstack_copy_inode_size(struct inode *dst, const struct inode *src) | 10 | void fsstack_copy_inode_size(struct inode *dst, struct inode *src) |
11 | { | 11 | { |
12 | i_size_write(dst, i_size_read((struct inode *)src)); | 12 | loff_t i_size; |
13 | dst->i_blocks = src->i_blocks; | 13 | blkcnt_t i_blocks; |
14 | |||
15 | /* | ||
16 | * i_size_read() includes its own seqlocking and protection from | ||
17 | * preemption (see include/linux/fs.h): we need nothing extra for | ||
18 | * that here, and prefer to avoid nesting locks than attempt to keep | ||
19 | * i_size and i_blocks in sync together. | ||
20 | */ | ||
21 | i_size = i_size_read(src); | ||
22 | |||
23 | /* | ||
24 | * But if CONFIG_LBDAF (on 32-bit), we ought to make an effort to | ||
25 | * keep the two halves of i_blocks in sync despite SMP or PREEMPT - | ||
26 | * though stat's generic_fillattr() doesn't bother, and we won't be | ||
27 | * applying quotas (where i_blocks does become important) at the | ||
28 | * upper level. | ||
29 | * | ||
30 | * We don't actually know what locking is used at the lower level; | ||
31 | * but if it's a filesystem that supports quotas, it will be using | ||
32 | * i_lock as in inode_add_bytes(). tmpfs uses other locking, and | ||
33 | * its 32-bit is (just) able to exceed 2TB i_size with the aid of | ||
34 | * holes; but its i_blocks cannot carry into the upper long without | ||
35 | * almost 2TB swap - let's ignore that case. | ||
36 | */ | ||
37 | if (sizeof(i_blocks) > sizeof(long)) | ||
38 | spin_lock(&src->i_lock); | ||
39 | i_blocks = src->i_blocks; | ||
40 | if (sizeof(i_blocks) > sizeof(long)) | ||
41 | spin_unlock(&src->i_lock); | ||
42 | |||
43 | /* | ||
44 | * If CONFIG_SMP or CONFIG_PREEMPT on 32-bit, it's vital for | ||
45 | * fsstack_copy_inode_size() to hold some lock around | ||
46 | * i_size_write(), otherwise i_size_read() may spin forever (see | ||
47 | * include/linux/fs.h). We don't necessarily hold i_mutex when this | ||
48 | * is called, so take i_lock for that case. | ||
49 | * | ||
50 | * And if CONFIG_LBADF (on 32-bit), continue our effort to keep the | ||
51 | * two halves of i_blocks in sync despite SMP or PREEMPT: use i_lock | ||
52 | * for that case too, and do both at once by combining the tests. | ||
53 | * | ||
54 | * There is none of this locking overhead in the 64-bit case. | ||
55 | */ | ||
56 | if (sizeof(i_size) > sizeof(long) || sizeof(i_blocks) > sizeof(long)) | ||
57 | spin_lock(&dst->i_lock); | ||
58 | i_size_write(dst, i_size); | ||
59 | dst->i_blocks = i_blocks; | ||
60 | if (sizeof(i_size) > sizeof(long) || sizeof(i_blocks) > sizeof(long)) | ||
61 | spin_unlock(&dst->i_lock); | ||
14 | } | 62 | } |
15 | EXPORT_SYMBOL_GPL(fsstack_copy_inode_size); | 63 | EXPORT_SYMBOL_GPL(fsstack_copy_inode_size); |
16 | 64 | ||
17 | /* copy all attributes; get_nlinks is optional way to override the i_nlink | 65 | /* copy all attributes */ |
18 | * copying | 66 | void fsstack_copy_attr_all(struct inode *dest, const struct inode *src) |
19 | */ | ||
20 | void fsstack_copy_attr_all(struct inode *dest, const struct inode *src, | ||
21 | int (*get_nlinks)(struct inode *)) | ||
22 | { | 67 | { |
23 | dest->i_mode = src->i_mode; | 68 | dest->i_mode = src->i_mode; |
24 | dest->i_uid = src->i_uid; | 69 | dest->i_uid = src->i_uid; |
@@ -29,14 +74,6 @@ void fsstack_copy_attr_all(struct inode *dest, const struct inode *src, | |||
29 | dest->i_ctime = src->i_ctime; | 74 | dest->i_ctime = src->i_ctime; |
30 | dest->i_blkbits = src->i_blkbits; | 75 | dest->i_blkbits = src->i_blkbits; |
31 | dest->i_flags = src->i_flags; | 76 | dest->i_flags = src->i_flags; |
32 | 77 | dest->i_nlink = src->i_nlink; | |
33 | /* | ||
34 | * Update the nlinks AFTER updating the above fields, because the | ||
35 | * get_links callback may depend on them. | ||
36 | */ | ||
37 | if (!get_nlinks) | ||
38 | dest->i_nlink = src->i_nlink; | ||
39 | else | ||
40 | dest->i_nlink = (*get_nlinks)(dest); | ||
41 | } | 78 | } |
42 | EXPORT_SYMBOL_GPL(fsstack_copy_attr_all); | 79 | EXPORT_SYMBOL_GPL(fsstack_copy_attr_all); |
@@ -401,9 +401,9 @@ SYSCALL_DEFINE4(fstatat64, int, dfd, char __user *, filename, | |||
401 | } | 401 | } |
402 | #endif /* __ARCH_WANT_STAT64 */ | 402 | #endif /* __ARCH_WANT_STAT64 */ |
403 | 403 | ||
404 | void inode_add_bytes(struct inode *inode, loff_t bytes) | 404 | /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */ |
405 | void __inode_add_bytes(struct inode *inode, loff_t bytes) | ||
405 | { | 406 | { |
406 | spin_lock(&inode->i_lock); | ||
407 | inode->i_blocks += bytes >> 9; | 407 | inode->i_blocks += bytes >> 9; |
408 | bytes &= 511; | 408 | bytes &= 511; |
409 | inode->i_bytes += bytes; | 409 | inode->i_bytes += bytes; |
@@ -411,6 +411,12 @@ void inode_add_bytes(struct inode *inode, loff_t bytes) | |||
411 | inode->i_blocks++; | 411 | inode->i_blocks++; |
412 | inode->i_bytes -= 512; | 412 | inode->i_bytes -= 512; |
413 | } | 413 | } |
414 | } | ||
415 | |||
416 | void inode_add_bytes(struct inode *inode, loff_t bytes) | ||
417 | { | ||
418 | spin_lock(&inode->i_lock); | ||
419 | __inode_add_bytes(inode, bytes); | ||
414 | spin_unlock(&inode->i_lock); | 420 | spin_unlock(&inode->i_lock); |
415 | } | 421 | } |
416 | 422 | ||
diff --git a/fs/super.c b/fs/super.c index 19eb70b374bc..aff046b0fe78 100644 --- a/fs/super.c +++ b/fs/super.c | |||
@@ -901,8 +901,9 @@ int get_sb_single(struct file_system_type *fs_type, | |||
901 | return error; | 901 | return error; |
902 | } | 902 | } |
903 | s->s_flags |= MS_ACTIVE; | 903 | s->s_flags |= MS_ACTIVE; |
904 | } else { | ||
905 | do_remount_sb(s, flags, data, 0); | ||
904 | } | 906 | } |
905 | do_remount_sb(s, flags, data, 0); | ||
906 | simple_set_mnt(mnt, s); | 907 | simple_set_mnt(mnt, s); |
907 | return 0; | 908 | return 0; |
908 | } | 909 | } |
@@ -355,6 +355,7 @@ SYSCALL_DEFINE(sync_file_range)(int fd, loff_t offset, loff_t nbytes, | |||
355 | { | 355 | { |
356 | int ret; | 356 | int ret; |
357 | struct file *file; | 357 | struct file *file; |
358 | struct address_space *mapping; | ||
358 | loff_t endbyte; /* inclusive */ | 359 | loff_t endbyte; /* inclusive */ |
359 | int fput_needed; | 360 | int fput_needed; |
360 | umode_t i_mode; | 361 | umode_t i_mode; |
@@ -405,7 +406,28 @@ SYSCALL_DEFINE(sync_file_range)(int fd, loff_t offset, loff_t nbytes, | |||
405 | !S_ISLNK(i_mode)) | 406 | !S_ISLNK(i_mode)) |
406 | goto out_put; | 407 | goto out_put; |
407 | 408 | ||
408 | ret = do_sync_mapping_range(file->f_mapping, offset, endbyte, flags); | 409 | mapping = file->f_mapping; |
410 | if (!mapping) { | ||
411 | ret = -EINVAL; | ||
412 | goto out_put; | ||
413 | } | ||
414 | |||
415 | ret = 0; | ||
416 | if (flags & SYNC_FILE_RANGE_WAIT_BEFORE) { | ||
417 | ret = filemap_fdatawait_range(mapping, offset, endbyte); | ||
418 | if (ret < 0) | ||
419 | goto out_put; | ||
420 | } | ||
421 | |||
422 | if (flags & SYNC_FILE_RANGE_WRITE) { | ||
423 | ret = filemap_fdatawrite_range(mapping, offset, endbyte); | ||
424 | if (ret < 0) | ||
425 | goto out_put; | ||
426 | } | ||
427 | |||
428 | if (flags & SYNC_FILE_RANGE_WAIT_AFTER) | ||
429 | ret = filemap_fdatawait_range(mapping, offset, endbyte); | ||
430 | |||
409 | out_put: | 431 | out_put: |
410 | fput_light(file, fput_needed); | 432 | fput_light(file, fput_needed); |
411 | out: | 433 | out: |
@@ -437,38 +459,3 @@ asmlinkage long SyS_sync_file_range2(long fd, long flags, | |||
437 | } | 459 | } |
438 | SYSCALL_ALIAS(sys_sync_file_range2, SyS_sync_file_range2); | 460 | SYSCALL_ALIAS(sys_sync_file_range2, SyS_sync_file_range2); |
439 | #endif | 461 | #endif |
440 | |||
441 | /* | ||
442 | * `endbyte' is inclusive | ||
443 | */ | ||
444 | int do_sync_mapping_range(struct address_space *mapping, loff_t offset, | ||
445 | loff_t endbyte, unsigned int flags) | ||
446 | { | ||
447 | int ret; | ||
448 | |||
449 | if (!mapping) { | ||
450 | ret = -EINVAL; | ||
451 | goto out; | ||
452 | } | ||
453 | |||
454 | ret = 0; | ||
455 | if (flags & SYNC_FILE_RANGE_WAIT_BEFORE) { | ||
456 | ret = filemap_fdatawait_range(mapping, offset, endbyte); | ||
457 | if (ret < 0) | ||
458 | goto out; | ||
459 | } | ||
460 | |||
461 | if (flags & SYNC_FILE_RANGE_WRITE) { | ||
462 | ret = __filemap_fdatawrite_range(mapping, offset, endbyte, | ||
463 | WB_SYNC_ALL); | ||
464 | if (ret < 0) | ||
465 | goto out; | ||
466 | } | ||
467 | |||
468 | if (flags & SYNC_FILE_RANGE_WAIT_AFTER) { | ||
469 | ret = filemap_fdatawait_range(mapping, offset, endbyte); | ||
470 | } | ||
471 | out: | ||
472 | return ret; | ||
473 | } | ||
474 | EXPORT_SYMBOL_GPL(do_sync_mapping_range); | ||
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c index 60c702bc10ae..a0a500af24a1 100644 --- a/fs/sysfs/bin.c +++ b/fs/sysfs/bin.c | |||
@@ -483,7 +483,8 @@ void unmap_bin_file(struct sysfs_dirent *attr_sd) | |||
483 | * @attr: attribute descriptor. | 483 | * @attr: attribute descriptor. |
484 | */ | 484 | */ |
485 | 485 | ||
486 | int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr) | 486 | int sysfs_create_bin_file(struct kobject *kobj, |
487 | const struct bin_attribute *attr) | ||
487 | { | 488 | { |
488 | BUG_ON(!kobj || !kobj->sd || !attr); | 489 | BUG_ON(!kobj || !kobj->sd || !attr); |
489 | 490 | ||
@@ -497,7 +498,8 @@ int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr) | |||
497 | * @attr: attribute descriptor. | 498 | * @attr: attribute descriptor. |
498 | */ | 499 | */ |
499 | 500 | ||
500 | void sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr) | 501 | void sysfs_remove_bin_file(struct kobject *kobj, |
502 | const struct bin_attribute *attr) | ||
501 | { | 503 | { |
502 | sysfs_hash_and_remove(kobj->sd, attr->attr.name); | 504 | sysfs_hash_and_remove(kobj->sd, attr->attr.name); |
503 | } | 505 | } |
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index f05f2303a8b8..699f371b9f12 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
@@ -106,8 +106,10 @@ static struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd) | |||
106 | return NULL; | 106 | return NULL; |
107 | 107 | ||
108 | t = atomic_cmpxchg(&sd->s_active, v, v + 1); | 108 | t = atomic_cmpxchg(&sd->s_active, v, v + 1); |
109 | if (likely(t == v)) | 109 | if (likely(t == v)) { |
110 | rwsem_acquire_read(&sd->dep_map, 0, 1, _RET_IP_); | ||
110 | return sd; | 111 | return sd; |
112 | } | ||
111 | if (t < 0) | 113 | if (t < 0) |
112 | return NULL; | 114 | return NULL; |
113 | 115 | ||
@@ -130,6 +132,7 @@ static void sysfs_put_active(struct sysfs_dirent *sd) | |||
130 | if (unlikely(!sd)) | 132 | if (unlikely(!sd)) |
131 | return; | 133 | return; |
132 | 134 | ||
135 | rwsem_release(&sd->dep_map, 1, _RET_IP_); | ||
133 | v = atomic_dec_return(&sd->s_active); | 136 | v = atomic_dec_return(&sd->s_active); |
134 | if (likely(v != SD_DEACTIVATED_BIAS)) | 137 | if (likely(v != SD_DEACTIVATED_BIAS)) |
135 | return; | 138 | return; |
@@ -194,15 +197,21 @@ static void sysfs_deactivate(struct sysfs_dirent *sd) | |||
194 | BUG_ON(sd->s_sibling || !(sd->s_flags & SYSFS_FLAG_REMOVED)); | 197 | BUG_ON(sd->s_sibling || !(sd->s_flags & SYSFS_FLAG_REMOVED)); |
195 | sd->s_sibling = (void *)&wait; | 198 | sd->s_sibling = (void *)&wait; |
196 | 199 | ||
200 | rwsem_acquire(&sd->dep_map, 0, 0, _RET_IP_); | ||
197 | /* atomic_add_return() is a mb(), put_active() will always see | 201 | /* atomic_add_return() is a mb(), put_active() will always see |
198 | * the updated sd->s_sibling. | 202 | * the updated sd->s_sibling. |
199 | */ | 203 | */ |
200 | v = atomic_add_return(SD_DEACTIVATED_BIAS, &sd->s_active); | 204 | v = atomic_add_return(SD_DEACTIVATED_BIAS, &sd->s_active); |
201 | 205 | ||
202 | if (v != SD_DEACTIVATED_BIAS) | 206 | if (v != SD_DEACTIVATED_BIAS) { |
207 | lock_contended(&sd->dep_map, _RET_IP_); | ||
203 | wait_for_completion(&wait); | 208 | wait_for_completion(&wait); |
209 | } | ||
204 | 210 | ||
205 | sd->s_sibling = NULL; | 211 | sd->s_sibling = NULL; |
212 | |||
213 | lock_acquired(&sd->dep_map, _RET_IP_); | ||
214 | rwsem_release(&sd->dep_map, 1, _RET_IP_); | ||
206 | } | 215 | } |
207 | 216 | ||
208 | static int sysfs_alloc_ino(ino_t *pino) | 217 | static int sysfs_alloc_ino(ino_t *pino) |
@@ -345,6 +354,7 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type) | |||
345 | 354 | ||
346 | atomic_set(&sd->s_count, 1); | 355 | atomic_set(&sd->s_count, 1); |
347 | atomic_set(&sd->s_active, 0); | 356 | atomic_set(&sd->s_active, 0); |
357 | sysfs_dirent_init_lockdep(sd); | ||
348 | 358 | ||
349 | sd->s_name = name; | 359 | sd->s_name = name; |
350 | sd->s_mode = mode; | 360 | sd->s_mode = mode; |
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index ca52e7b9d8f8..cdd9377a6e06 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
@@ -8,6 +8,7 @@ | |||
8 | * This file is released under the GPLv2. | 8 | * This file is released under the GPLv2. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/lockdep.h> | ||
11 | #include <linux/fs.h> | 12 | #include <linux/fs.h> |
12 | 13 | ||
13 | struct sysfs_open_dirent; | 14 | struct sysfs_open_dirent; |
@@ -50,6 +51,9 @@ struct sysfs_inode_attrs { | |||
50 | struct sysfs_dirent { | 51 | struct sysfs_dirent { |
51 | atomic_t s_count; | 52 | atomic_t s_count; |
52 | atomic_t s_active; | 53 | atomic_t s_active; |
54 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
55 | struct lockdep_map dep_map; | ||
56 | #endif | ||
53 | struct sysfs_dirent *s_parent; | 57 | struct sysfs_dirent *s_parent; |
54 | struct sysfs_dirent *s_sibling; | 58 | struct sysfs_dirent *s_sibling; |
55 | const char *s_name; | 59 | const char *s_name; |
@@ -84,6 +88,17 @@ static inline unsigned int sysfs_type(struct sysfs_dirent *sd) | |||
84 | return sd->s_flags & SYSFS_TYPE_MASK; | 88 | return sd->s_flags & SYSFS_TYPE_MASK; |
85 | } | 89 | } |
86 | 90 | ||
91 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
92 | #define sysfs_dirent_init_lockdep(sd) \ | ||
93 | do { \ | ||
94 | static struct lock_class_key __key; \ | ||
95 | \ | ||
96 | lockdep_init_map(&sd->dep_map, "s_active", &__key, 0); \ | ||
97 | } while(0) | ||
98 | #else | ||
99 | #define sysfs_dirent_init_lockdep(sd) do {} while(0) | ||
100 | #endif | ||
101 | |||
87 | /* | 102 | /* |
88 | * Context structure to be used while adding/removing nodes. | 103 | * Context structure to be used while adding/removing nodes. |
89 | */ | 104 | */ |
diff --git a/fs/timerfd.c b/fs/timerfd.c index b042bd7034b1..1bfc95ad5f71 100644 --- a/fs/timerfd.c +++ b/fs/timerfd.c | |||
@@ -200,7 +200,7 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) | |||
200 | hrtimer_init(&ctx->tmr, clockid, HRTIMER_MODE_ABS); | 200 | hrtimer_init(&ctx->tmr, clockid, HRTIMER_MODE_ABS); |
201 | 201 | ||
202 | ufd = anon_inode_getfd("[timerfd]", &timerfd_fops, ctx, | 202 | ufd = anon_inode_getfd("[timerfd]", &timerfd_fops, ctx, |
203 | flags & TFD_SHARED_FCNTL_FLAGS); | 203 | O_RDWR | (flags & TFD_SHARED_FCNTL_FLAGS)); |
204 | if (ufd < 0) | 204 | if (ufd < 0) |
205 | kfree(ctx); | 205 | kfree(ctx); |
206 | 206 | ||
diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 39849f887e72..16a6444330ec 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c | |||
@@ -45,7 +45,7 @@ | |||
45 | * | 45 | * |
46 | * Similarly, @i_mutex is not always locked in 'ubifs_readpage()', e.g., the | 46 | * Similarly, @i_mutex is not always locked in 'ubifs_readpage()', e.g., the |
47 | * read-ahead path does not lock it ("sys_read -> generic_file_aio_read -> | 47 | * read-ahead path does not lock it ("sys_read -> generic_file_aio_read -> |
48 | * ondemand_readahead -> readpage"). In case of readahead, @I_LOCK flag is not | 48 | * ondemand_readahead -> readpage"). In case of readahead, @I_SYNC flag is not |
49 | * set as well. However, UBIFS disables readahead. | 49 | * set as well. However, UBIFS disables readahead. |
50 | */ | 50 | */ |
51 | 51 | ||
diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c index 618c2701d3a7..e5a3d8e96bb7 100644 --- a/fs/ubifs/gc.c +++ b/fs/ubifs/gc.c | |||
@@ -54,6 +54,7 @@ | |||
54 | */ | 54 | */ |
55 | 55 | ||
56 | #include <linux/pagemap.h> | 56 | #include <linux/pagemap.h> |
57 | #include <linux/list_sort.h> | ||
57 | #include "ubifs.h" | 58 | #include "ubifs.h" |
58 | 59 | ||
59 | /* | 60 | /* |
@@ -108,101 +109,6 @@ static int switch_gc_head(struct ubifs_info *c) | |||
108 | } | 109 | } |
109 | 110 | ||
110 | /** | 111 | /** |
111 | * list_sort - sort a list. | ||
112 | * @priv: private data, passed to @cmp | ||
113 | * @head: the list to sort | ||
114 | * @cmp: the elements comparison function | ||
115 | * | ||
116 | * This function has been implemented by Mark J Roberts <mjr@znex.org>. It | ||
117 | * implements "merge sort" which has O(nlog(n)) complexity. The list is sorted | ||
118 | * in ascending order. | ||
119 | * | ||
120 | * The comparison function @cmp is supposed to return a negative value if @a is | ||
121 | * than @b, and a positive value if @a is greater than @b. If @a and @b are | ||
122 | * equivalent, then it does not matter what this function returns. | ||
123 | */ | ||
124 | static void list_sort(void *priv, struct list_head *head, | ||
125 | int (*cmp)(void *priv, struct list_head *a, | ||
126 | struct list_head *b)) | ||
127 | { | ||
128 | struct list_head *p, *q, *e, *list, *tail, *oldhead; | ||
129 | int insize, nmerges, psize, qsize, i; | ||
130 | |||
131 | if (list_empty(head)) | ||
132 | return; | ||
133 | |||
134 | list = head->next; | ||
135 | list_del(head); | ||
136 | insize = 1; | ||
137 | for (;;) { | ||
138 | p = oldhead = list; | ||
139 | list = tail = NULL; | ||
140 | nmerges = 0; | ||
141 | |||
142 | while (p) { | ||
143 | nmerges++; | ||
144 | q = p; | ||
145 | psize = 0; | ||
146 | for (i = 0; i < insize; i++) { | ||
147 | psize++; | ||
148 | q = q->next == oldhead ? NULL : q->next; | ||
149 | if (!q) | ||
150 | break; | ||
151 | } | ||
152 | |||
153 | qsize = insize; | ||
154 | while (psize > 0 || (qsize > 0 && q)) { | ||
155 | if (!psize) { | ||
156 | e = q; | ||
157 | q = q->next; | ||
158 | qsize--; | ||
159 | if (q == oldhead) | ||
160 | q = NULL; | ||
161 | } else if (!qsize || !q) { | ||
162 | e = p; | ||
163 | p = p->next; | ||
164 | psize--; | ||
165 | if (p == oldhead) | ||
166 | p = NULL; | ||
167 | } else if (cmp(priv, p, q) <= 0) { | ||
168 | e = p; | ||
169 | p = p->next; | ||
170 | psize--; | ||
171 | if (p == oldhead) | ||
172 | p = NULL; | ||
173 | } else { | ||
174 | e = q; | ||
175 | q = q->next; | ||
176 | qsize--; | ||
177 | if (q == oldhead) | ||
178 | q = NULL; | ||
179 | } | ||
180 | if (tail) | ||
181 | tail->next = e; | ||
182 | else | ||
183 | list = e; | ||
184 | e->prev = tail; | ||
185 | tail = e; | ||
186 | } | ||
187 | p = q; | ||
188 | } | ||
189 | |||
190 | tail->next = list; | ||
191 | list->prev = tail; | ||
192 | |||
193 | if (nmerges <= 1) | ||
194 | break; | ||
195 | |||
196 | insize *= 2; | ||
197 | } | ||
198 | |||
199 | head->next = list; | ||
200 | head->prev = list->prev; | ||
201 | list->prev->next = head; | ||
202 | list->prev = head; | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * data_nodes_cmp - compare 2 data nodes. | 112 | * data_nodes_cmp - compare 2 data nodes. |
207 | * @priv: UBIFS file-system description object | 113 | * @priv: UBIFS file-system description object |
208 | * @a: first data node | 114 | * @a: first data node |
diff --git a/fs/xfs/linux-2.6/xfs_acl.c b/fs/xfs/linux-2.6/xfs_acl.c index 2512125dfa7c..883ca5ab8af5 100644 --- a/fs/xfs/linux-2.6/xfs_acl.c +++ b/fs/xfs/linux-2.6/xfs_acl.c | |||
@@ -251,8 +251,9 @@ xfs_set_mode(struct inode *inode, mode_t mode) | |||
251 | if (mode != inode->i_mode) { | 251 | if (mode != inode->i_mode) { |
252 | struct iattr iattr; | 252 | struct iattr iattr; |
253 | 253 | ||
254 | iattr.ia_valid = ATTR_MODE; | 254 | iattr.ia_valid = ATTR_MODE | ATTR_CTIME; |
255 | iattr.ia_mode = mode; | 255 | iattr.ia_mode = mode; |
256 | iattr.ia_ctime = current_fs_time(inode->i_sb); | ||
256 | 257 | ||
257 | error = -xfs_setattr(XFS_I(inode), &iattr, XFS_ATTR_NOACL); | 258 | error = -xfs_setattr(XFS_I(inode), &iattr, XFS_ATTR_NOACL); |
258 | } | 259 | } |
diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c index 1d5b298ba8b2..225946012d0b 100644 --- a/fs/xfs/linux-2.6/xfs_iops.c +++ b/fs/xfs/linux-2.6/xfs_iops.c | |||
@@ -794,7 +794,7 @@ xfs_setup_inode( | |||
794 | struct inode *inode = &ip->i_vnode; | 794 | struct inode *inode = &ip->i_vnode; |
795 | 795 | ||
796 | inode->i_ino = ip->i_ino; | 796 | inode->i_ino = ip->i_ino; |
797 | inode->i_state = I_NEW|I_LOCK; | 797 | inode->i_state = I_NEW; |
798 | inode_add_to_lists(ip->i_mount->m_super, inode); | 798 | inode_add_to_lists(ip->i_mount->m_super, inode); |
799 | 799 | ||
800 | inode->i_mode = ip->i_d.di_mode; | 800 | inode->i_mode = ip->i_d.di_mode; |
diff --git a/fs/xfs/linux-2.6/xfs_trace.h b/fs/xfs/linux-2.6/xfs_trace.h index c40834bdee58..c22a608321a3 100644 --- a/fs/xfs/linux-2.6/xfs_trace.h +++ b/fs/xfs/linux-2.6/xfs_trace.h | |||
@@ -33,51 +33,55 @@ struct xfs_dquot; | |||
33 | struct xlog_ticket; | 33 | struct xlog_ticket; |
34 | struct log; | 34 | struct log; |
35 | 35 | ||
36 | DECLARE_EVENT_CLASS(xfs_attr_list_class, | ||
37 | TP_PROTO(struct xfs_attr_list_context *ctx), | ||
38 | TP_ARGS(ctx), | ||
39 | TP_STRUCT__entry( | ||
40 | __field(dev_t, dev) | ||
41 | __field(xfs_ino_t, ino) | ||
42 | __field(u32, hashval) | ||
43 | __field(u32, blkno) | ||
44 | __field(u32, offset) | ||
45 | __field(void *, alist) | ||
46 | __field(int, bufsize) | ||
47 | __field(int, count) | ||
48 | __field(int, firstu) | ||
49 | __field(int, dupcnt) | ||
50 | __field(int, flags) | ||
51 | ), | ||
52 | TP_fast_assign( | ||
53 | __entry->dev = VFS_I(ctx->dp)->i_sb->s_dev; | ||
54 | __entry->ino = ctx->dp->i_ino; | ||
55 | __entry->hashval = ctx->cursor->hashval; | ||
56 | __entry->blkno = ctx->cursor->blkno; | ||
57 | __entry->offset = ctx->cursor->offset; | ||
58 | __entry->alist = ctx->alist; | ||
59 | __entry->bufsize = ctx->bufsize; | ||
60 | __entry->count = ctx->count; | ||
61 | __entry->firstu = ctx->firstu; | ||
62 | __entry->flags = ctx->flags; | ||
63 | ), | ||
64 | TP_printk("dev %d:%d ino 0x%llx cursor h/b/o 0x%x/0x%x/%u dupcnt %u " | ||
65 | "alist 0x%p size %u count %u firstu %u flags %d %s", | ||
66 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
67 | __entry->ino, | ||
68 | __entry->hashval, | ||
69 | __entry->blkno, | ||
70 | __entry->offset, | ||
71 | __entry->dupcnt, | ||
72 | __entry->alist, | ||
73 | __entry->bufsize, | ||
74 | __entry->count, | ||
75 | __entry->firstu, | ||
76 | __entry->flags, | ||
77 | __print_flags(__entry->flags, "|", XFS_ATTR_FLAGS) | ||
78 | ) | ||
79 | ) | ||
80 | |||
36 | #define DEFINE_ATTR_LIST_EVENT(name) \ | 81 | #define DEFINE_ATTR_LIST_EVENT(name) \ |
37 | TRACE_EVENT(name, \ | 82 | DEFINE_EVENT(xfs_attr_list_class, name, \ |
38 | TP_PROTO(struct xfs_attr_list_context *ctx), \ | 83 | TP_PROTO(struct xfs_attr_list_context *ctx), \ |
39 | TP_ARGS(ctx), \ | 84 | TP_ARGS(ctx)) |
40 | TP_STRUCT__entry( \ | ||
41 | __field(dev_t, dev) \ | ||
42 | __field(xfs_ino_t, ino) \ | ||
43 | __field(u32, hashval) \ | ||
44 | __field(u32, blkno) \ | ||
45 | __field(u32, offset) \ | ||
46 | __field(void *, alist) \ | ||
47 | __field(int, bufsize) \ | ||
48 | __field(int, count) \ | ||
49 | __field(int, firstu) \ | ||
50 | __field(int, dupcnt) \ | ||
51 | __field(int, flags) \ | ||
52 | ), \ | ||
53 | TP_fast_assign( \ | ||
54 | __entry->dev = VFS_I(ctx->dp)->i_sb->s_dev; \ | ||
55 | __entry->ino = ctx->dp->i_ino; \ | ||
56 | __entry->hashval = ctx->cursor->hashval; \ | ||
57 | __entry->blkno = ctx->cursor->blkno; \ | ||
58 | __entry->offset = ctx->cursor->offset; \ | ||
59 | __entry->alist = ctx->alist; \ | ||
60 | __entry->bufsize = ctx->bufsize; \ | ||
61 | __entry->count = ctx->count; \ | ||
62 | __entry->firstu = ctx->firstu; \ | ||
63 | __entry->flags = ctx->flags; \ | ||
64 | ), \ | ||
65 | TP_printk("dev %d:%d ino 0x%llx cursor h/b/o 0x%x/0x%x/%u dupcnt %u " \ | ||
66 | "alist 0x%p size %u count %u firstu %u flags %d %s", \ | ||
67 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | ||
68 | __entry->ino, \ | ||
69 | __entry->hashval, \ | ||
70 | __entry->blkno, \ | ||
71 | __entry->offset, \ | ||
72 | __entry->dupcnt, \ | ||
73 | __entry->alist, \ | ||
74 | __entry->bufsize, \ | ||
75 | __entry->count, \ | ||
76 | __entry->firstu, \ | ||
77 | __entry->flags, \ | ||
78 | __print_flags(__entry->flags, "|", XFS_ATTR_FLAGS) \ | ||
79 | ) \ | ||
80 | ) | ||
81 | DEFINE_ATTR_LIST_EVENT(xfs_attr_list_sf); | 85 | DEFINE_ATTR_LIST_EVENT(xfs_attr_list_sf); |
82 | DEFINE_ATTR_LIST_EVENT(xfs_attr_list_sf_all); | 86 | DEFINE_ATTR_LIST_EVENT(xfs_attr_list_sf_all); |
83 | DEFINE_ATTR_LIST_EVENT(xfs_attr_list_leaf); | 87 | DEFINE_ATTR_LIST_EVENT(xfs_attr_list_leaf); |
@@ -178,91 +182,99 @@ TRACE_EVENT(xfs_iext_insert, | |||
178 | (char *)__entry->caller_ip) | 182 | (char *)__entry->caller_ip) |
179 | ); | 183 | ); |
180 | 184 | ||
185 | DECLARE_EVENT_CLASS(xfs_bmap_class, | ||
186 | TP_PROTO(struct xfs_inode *ip, xfs_extnum_t idx, int state, | ||
187 | unsigned long caller_ip), | ||
188 | TP_ARGS(ip, idx, state, caller_ip), | ||
189 | TP_STRUCT__entry( | ||
190 | __field(dev_t, dev) | ||
191 | __field(xfs_ino_t, ino) | ||
192 | __field(xfs_extnum_t, idx) | ||
193 | __field(xfs_fileoff_t, startoff) | ||
194 | __field(xfs_fsblock_t, startblock) | ||
195 | __field(xfs_filblks_t, blockcount) | ||
196 | __field(xfs_exntst_t, state) | ||
197 | __field(int, bmap_state) | ||
198 | __field(unsigned long, caller_ip) | ||
199 | ), | ||
200 | TP_fast_assign( | ||
201 | struct xfs_ifork *ifp = (state & BMAP_ATTRFORK) ? | ||
202 | ip->i_afp : &ip->i_df; | ||
203 | struct xfs_bmbt_irec r; | ||
204 | |||
205 | xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), &r); | ||
206 | __entry->dev = VFS_I(ip)->i_sb->s_dev; | ||
207 | __entry->ino = ip->i_ino; | ||
208 | __entry->idx = idx; | ||
209 | __entry->startoff = r.br_startoff; | ||
210 | __entry->startblock = r.br_startblock; | ||
211 | __entry->blockcount = r.br_blockcount; | ||
212 | __entry->state = r.br_state; | ||
213 | __entry->bmap_state = state; | ||
214 | __entry->caller_ip = caller_ip; | ||
215 | ), | ||
216 | TP_printk("dev %d:%d ino 0x%llx state %s idx %ld " | ||
217 | "offset %lld block %s count %lld flag %d caller %pf", | ||
218 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
219 | __entry->ino, | ||
220 | __print_flags(__entry->bmap_state, "|", XFS_BMAP_EXT_FLAGS), | ||
221 | (long)__entry->idx, | ||
222 | __entry->startoff, | ||
223 | xfs_fmtfsblock(__entry->startblock), | ||
224 | __entry->blockcount, | ||
225 | __entry->state, | ||
226 | (char *)__entry->caller_ip) | ||
227 | ) | ||
228 | |||
181 | #define DEFINE_BMAP_EVENT(name) \ | 229 | #define DEFINE_BMAP_EVENT(name) \ |
182 | TRACE_EVENT(name, \ | 230 | DEFINE_EVENT(xfs_bmap_class, name, \ |
183 | TP_PROTO(struct xfs_inode *ip, xfs_extnum_t idx, int state, \ | 231 | TP_PROTO(struct xfs_inode *ip, xfs_extnum_t idx, int state, \ |
184 | unsigned long caller_ip), \ | 232 | unsigned long caller_ip), \ |
185 | TP_ARGS(ip, idx, state, caller_ip), \ | 233 | TP_ARGS(ip, idx, state, caller_ip)) |
186 | TP_STRUCT__entry( \ | ||
187 | __field(dev_t, dev) \ | ||
188 | __field(xfs_ino_t, ino) \ | ||
189 | __field(xfs_extnum_t, idx) \ | ||
190 | __field(xfs_fileoff_t, startoff) \ | ||
191 | __field(xfs_fsblock_t, startblock) \ | ||
192 | __field(xfs_filblks_t, blockcount) \ | ||
193 | __field(xfs_exntst_t, state) \ | ||
194 | __field(int, bmap_state) \ | ||
195 | __field(unsigned long, caller_ip) \ | ||
196 | ), \ | ||
197 | TP_fast_assign( \ | ||
198 | struct xfs_ifork *ifp = (state & BMAP_ATTRFORK) ? \ | ||
199 | ip->i_afp : &ip->i_df; \ | ||
200 | struct xfs_bmbt_irec r; \ | ||
201 | \ | ||
202 | xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), &r); \ | ||
203 | __entry->dev = VFS_I(ip)->i_sb->s_dev; \ | ||
204 | __entry->ino = ip->i_ino; \ | ||
205 | __entry->idx = idx; \ | ||
206 | __entry->startoff = r.br_startoff; \ | ||
207 | __entry->startblock = r.br_startblock; \ | ||
208 | __entry->blockcount = r.br_blockcount; \ | ||
209 | __entry->state = r.br_state; \ | ||
210 | __entry->bmap_state = state; \ | ||
211 | __entry->caller_ip = caller_ip; \ | ||
212 | ), \ | ||
213 | TP_printk("dev %d:%d ino 0x%llx state %s idx %ld " \ | ||
214 | "offset %lld block %s count %lld flag %d caller %pf", \ | ||
215 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | ||
216 | __entry->ino, \ | ||
217 | __print_flags(__entry->bmap_state, "|", XFS_BMAP_EXT_FLAGS), \ | ||
218 | (long)__entry->idx, \ | ||
219 | __entry->startoff, \ | ||
220 | xfs_fmtfsblock(__entry->startblock), \ | ||
221 | __entry->blockcount, \ | ||
222 | __entry->state, \ | ||
223 | (char *)__entry->caller_ip) \ | ||
224 | ) | ||
225 | |||
226 | DEFINE_BMAP_EVENT(xfs_iext_remove); | 234 | DEFINE_BMAP_EVENT(xfs_iext_remove); |
227 | DEFINE_BMAP_EVENT(xfs_bmap_pre_update); | 235 | DEFINE_BMAP_EVENT(xfs_bmap_pre_update); |
228 | DEFINE_BMAP_EVENT(xfs_bmap_post_update); | 236 | DEFINE_BMAP_EVENT(xfs_bmap_post_update); |
229 | DEFINE_BMAP_EVENT(xfs_extlist); | 237 | DEFINE_BMAP_EVENT(xfs_extlist); |
230 | 238 | ||
231 | #define DEFINE_BUF_EVENT(tname) \ | 239 | DECLARE_EVENT_CLASS(xfs_buf_class, |
232 | TRACE_EVENT(tname, \ | 240 | TP_PROTO(struct xfs_buf *bp, unsigned long caller_ip), |
233 | TP_PROTO(struct xfs_buf *bp, unsigned long caller_ip), \ | 241 | TP_ARGS(bp, caller_ip), |
234 | TP_ARGS(bp, caller_ip), \ | 242 | TP_STRUCT__entry( |
235 | TP_STRUCT__entry( \ | 243 | __field(dev_t, dev) |
236 | __field(dev_t, dev) \ | 244 | __field(xfs_daddr_t, bno) |
237 | __field(xfs_daddr_t, bno) \ | 245 | __field(size_t, buffer_length) |
238 | __field(size_t, buffer_length) \ | 246 | __field(int, hold) |
239 | __field(int, hold) \ | 247 | __field(int, pincount) |
240 | __field(int, pincount) \ | 248 | __field(unsigned, lockval) |
241 | __field(unsigned, lockval) \ | 249 | __field(unsigned, flags) |
242 | __field(unsigned, flags) \ | 250 | __field(unsigned long, caller_ip) |
243 | __field(unsigned long, caller_ip) \ | 251 | ), |
244 | ), \ | 252 | TP_fast_assign( |
245 | TP_fast_assign( \ | 253 | __entry->dev = bp->b_target->bt_dev; |
246 | __entry->dev = bp->b_target->bt_dev; \ | 254 | __entry->bno = bp->b_bn; |
247 | __entry->bno = bp->b_bn; \ | 255 | __entry->buffer_length = bp->b_buffer_length; |
248 | __entry->buffer_length = bp->b_buffer_length; \ | 256 | __entry->hold = atomic_read(&bp->b_hold); |
249 | __entry->hold = atomic_read(&bp->b_hold); \ | 257 | __entry->pincount = atomic_read(&bp->b_pin_count); |
250 | __entry->pincount = atomic_read(&bp->b_pin_count); \ | 258 | __entry->lockval = xfs_buf_lock_value(bp); |
251 | __entry->lockval = xfs_buf_lock_value(bp); \ | 259 | __entry->flags = bp->b_flags; |
252 | __entry->flags = bp->b_flags; \ | 260 | __entry->caller_ip = caller_ip; |
253 | __entry->caller_ip = caller_ip; \ | 261 | ), |
254 | ), \ | 262 | TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d " |
255 | TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d " \ | 263 | "lock %d flags %s caller %pf", |
256 | "lock %d flags %s caller %pf", \ | 264 | MAJOR(__entry->dev), MINOR(__entry->dev), |
257 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | 265 | (unsigned long long)__entry->bno, |
258 | (unsigned long long)__entry->bno, \ | 266 | __entry->buffer_length, |
259 | __entry->buffer_length, \ | 267 | __entry->hold, |
260 | __entry->hold, \ | 268 | __entry->pincount, |
261 | __entry->pincount, \ | 269 | __entry->lockval, |
262 | __entry->lockval, \ | 270 | __print_flags(__entry->flags, "|", XFS_BUF_FLAGS), |
263 | __print_flags(__entry->flags, "|", XFS_BUF_FLAGS), \ | 271 | (void *)__entry->caller_ip) |
264 | (void *)__entry->caller_ip) \ | ||
265 | ) | 272 | ) |
273 | |||
274 | #define DEFINE_BUF_EVENT(name) \ | ||
275 | DEFINE_EVENT(xfs_buf_class, name, \ | ||
276 | TP_PROTO(struct xfs_buf *bp, unsigned long caller_ip), \ | ||
277 | TP_ARGS(bp, caller_ip)) | ||
266 | DEFINE_BUF_EVENT(xfs_buf_init); | 278 | DEFINE_BUF_EVENT(xfs_buf_init); |
267 | DEFINE_BUF_EVENT(xfs_buf_free); | 279 | DEFINE_BUF_EVENT(xfs_buf_free); |
268 | DEFINE_BUF_EVENT(xfs_buf_hold); | 280 | DEFINE_BUF_EVENT(xfs_buf_hold); |
@@ -299,41 +311,45 @@ DEFINE_BUF_EVENT(xfs_reset_dqcounts); | |||
299 | DEFINE_BUF_EVENT(xfs_inode_item_push); | 311 | DEFINE_BUF_EVENT(xfs_inode_item_push); |
300 | 312 | ||
301 | /* pass flags explicitly */ | 313 | /* pass flags explicitly */ |
302 | #define DEFINE_BUF_FLAGS_EVENT(tname) \ | 314 | DECLARE_EVENT_CLASS(xfs_buf_flags_class, |
303 | TRACE_EVENT(tname, \ | 315 | TP_PROTO(struct xfs_buf *bp, unsigned flags, unsigned long caller_ip), |
304 | TP_PROTO(struct xfs_buf *bp, unsigned flags, unsigned long caller_ip), \ | 316 | TP_ARGS(bp, flags, caller_ip), |
305 | TP_ARGS(bp, flags, caller_ip), \ | 317 | TP_STRUCT__entry( |
306 | TP_STRUCT__entry( \ | 318 | __field(dev_t, dev) |
307 | __field(dev_t, dev) \ | 319 | __field(xfs_daddr_t, bno) |
308 | __field(xfs_daddr_t, bno) \ | 320 | __field(size_t, buffer_length) |
309 | __field(size_t, buffer_length) \ | 321 | __field(int, hold) |
310 | __field(int, hold) \ | 322 | __field(int, pincount) |
311 | __field(int, pincount) \ | 323 | __field(unsigned, lockval) |
312 | __field(unsigned, lockval) \ | 324 | __field(unsigned, flags) |
313 | __field(unsigned, flags) \ | 325 | __field(unsigned long, caller_ip) |
314 | __field(unsigned long, caller_ip) \ | 326 | ), |
315 | ), \ | 327 | TP_fast_assign( |
316 | TP_fast_assign( \ | 328 | __entry->dev = bp->b_target->bt_dev; |
317 | __entry->dev = bp->b_target->bt_dev; \ | 329 | __entry->bno = bp->b_bn; |
318 | __entry->bno = bp->b_bn; \ | 330 | __entry->buffer_length = bp->b_buffer_length; |
319 | __entry->buffer_length = bp->b_buffer_length; \ | 331 | __entry->flags = flags; |
320 | __entry->flags = flags; \ | 332 | __entry->hold = atomic_read(&bp->b_hold); |
321 | __entry->hold = atomic_read(&bp->b_hold); \ | 333 | __entry->pincount = atomic_read(&bp->b_pin_count); |
322 | __entry->pincount = atomic_read(&bp->b_pin_count); \ | 334 | __entry->lockval = xfs_buf_lock_value(bp); |
323 | __entry->lockval = xfs_buf_lock_value(bp); \ | 335 | __entry->caller_ip = caller_ip; |
324 | __entry->caller_ip = caller_ip; \ | 336 | ), |
325 | ), \ | 337 | TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d " |
326 | TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d " \ | 338 | "lock %d flags %s caller %pf", |
327 | "lock %d flags %s caller %pf", \ | 339 | MAJOR(__entry->dev), MINOR(__entry->dev), |
328 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | 340 | (unsigned long long)__entry->bno, |
329 | (unsigned long long)__entry->bno, \ | 341 | __entry->buffer_length, |
330 | __entry->buffer_length, \ | 342 | __entry->hold, |
331 | __entry->hold, \ | 343 | __entry->pincount, |
332 | __entry->pincount, \ | 344 | __entry->lockval, |
333 | __entry->lockval, \ | 345 | __print_flags(__entry->flags, "|", XFS_BUF_FLAGS), |
334 | __print_flags(__entry->flags, "|", XFS_BUF_FLAGS), \ | 346 | (void *)__entry->caller_ip) |
335 | (void *)__entry->caller_ip) \ | ||
336 | ) | 347 | ) |
348 | |||
349 | #define DEFINE_BUF_FLAGS_EVENT(name) \ | ||
350 | DEFINE_EVENT(xfs_buf_flags_class, name, \ | ||
351 | TP_PROTO(struct xfs_buf *bp, unsigned flags, unsigned long caller_ip), \ | ||
352 | TP_ARGS(bp, flags, caller_ip)) | ||
337 | DEFINE_BUF_FLAGS_EVENT(xfs_buf_find); | 353 | DEFINE_BUF_FLAGS_EVENT(xfs_buf_find); |
338 | DEFINE_BUF_FLAGS_EVENT(xfs_buf_get); | 354 | DEFINE_BUF_FLAGS_EVENT(xfs_buf_get); |
339 | DEFINE_BUF_FLAGS_EVENT(xfs_buf_read); | 355 | DEFINE_BUF_FLAGS_EVENT(xfs_buf_read); |
@@ -376,55 +392,58 @@ TRACE_EVENT(xfs_buf_ioerror, | |||
376 | (void *)__entry->caller_ip) | 392 | (void *)__entry->caller_ip) |
377 | ); | 393 | ); |
378 | 394 | ||
379 | #define DEFINE_BUF_ITEM_EVENT(tname) \ | 395 | DECLARE_EVENT_CLASS(xfs_buf_item_class, |
380 | TRACE_EVENT(tname, \ | 396 | TP_PROTO(struct xfs_buf_log_item *bip), |
381 | TP_PROTO(struct xfs_buf_log_item *bip), \ | 397 | TP_ARGS(bip), |
382 | TP_ARGS(bip), \ | 398 | TP_STRUCT__entry( |
383 | TP_STRUCT__entry( \ | 399 | __field(dev_t, dev) |
384 | __field(dev_t, dev) \ | 400 | __field(xfs_daddr_t, buf_bno) |
385 | __field(xfs_daddr_t, buf_bno) \ | 401 | __field(size_t, buf_len) |
386 | __field(size_t, buf_len) \ | 402 | __field(int, buf_hold) |
387 | __field(int, buf_hold) \ | 403 | __field(int, buf_pincount) |
388 | __field(int, buf_pincount) \ | 404 | __field(int, buf_lockval) |
389 | __field(int, buf_lockval) \ | 405 | __field(unsigned, buf_flags) |
390 | __field(unsigned, buf_flags) \ | 406 | __field(unsigned, bli_recur) |
391 | __field(unsigned, bli_recur) \ | 407 | __field(int, bli_refcount) |
392 | __field(int, bli_refcount) \ | 408 | __field(unsigned, bli_flags) |
393 | __field(unsigned, bli_flags) \ | 409 | __field(void *, li_desc) |
394 | __field(void *, li_desc) \ | 410 | __field(unsigned, li_flags) |
395 | __field(unsigned, li_flags) \ | 411 | ), |
396 | ), \ | 412 | TP_fast_assign( |
397 | TP_fast_assign( \ | 413 | __entry->dev = bip->bli_buf->b_target->bt_dev; |
398 | __entry->dev = bip->bli_buf->b_target->bt_dev; \ | 414 | __entry->bli_flags = bip->bli_flags; |
399 | __entry->bli_flags = bip->bli_flags; \ | 415 | __entry->bli_recur = bip->bli_recur; |
400 | __entry->bli_recur = bip->bli_recur; \ | 416 | __entry->bli_refcount = atomic_read(&bip->bli_refcount); |
401 | __entry->bli_refcount = atomic_read(&bip->bli_refcount); \ | 417 | __entry->buf_bno = bip->bli_buf->b_bn; |
402 | __entry->buf_bno = bip->bli_buf->b_bn; \ | 418 | __entry->buf_len = bip->bli_buf->b_buffer_length; |
403 | __entry->buf_len = bip->bli_buf->b_buffer_length; \ | 419 | __entry->buf_flags = bip->bli_buf->b_flags; |
404 | __entry->buf_flags = bip->bli_buf->b_flags; \ | 420 | __entry->buf_hold = atomic_read(&bip->bli_buf->b_hold); |
405 | __entry->buf_hold = atomic_read(&bip->bli_buf->b_hold); \ | 421 | __entry->buf_pincount = atomic_read(&bip->bli_buf->b_pin_count); |
406 | __entry->buf_pincount = \ | 422 | __entry->buf_lockval = xfs_buf_lock_value(bip->bli_buf); |
407 | atomic_read(&bip->bli_buf->b_pin_count); \ | 423 | __entry->li_desc = bip->bli_item.li_desc; |
408 | __entry->buf_lockval = xfs_buf_lock_value(bip->bli_buf); \ | 424 | __entry->li_flags = bip->bli_item.li_flags; |
409 | __entry->li_desc = bip->bli_item.li_desc; \ | 425 | ), |
410 | __entry->li_flags = bip->bli_item.li_flags; \ | 426 | TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d " |
411 | ), \ | 427 | "lock %d flags %s recur %d refcount %d bliflags %s " |
412 | TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d " \ | 428 | "lidesc 0x%p liflags %s", |
413 | "lock %d flags %s recur %d refcount %d bliflags %s " \ | 429 | MAJOR(__entry->dev), MINOR(__entry->dev), |
414 | "lidesc 0x%p liflags %s", \ | 430 | (unsigned long long)__entry->buf_bno, |
415 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | 431 | __entry->buf_len, |
416 | (unsigned long long)__entry->buf_bno, \ | 432 | __entry->buf_hold, |
417 | __entry->buf_len, \ | 433 | __entry->buf_pincount, |
418 | __entry->buf_hold, \ | 434 | __entry->buf_lockval, |
419 | __entry->buf_pincount, \ | 435 | __print_flags(__entry->buf_flags, "|", XFS_BUF_FLAGS), |
420 | __entry->buf_lockval, \ | 436 | __entry->bli_recur, |
421 | __print_flags(__entry->buf_flags, "|", XFS_BUF_FLAGS), \ | 437 | __entry->bli_refcount, |
422 | __entry->bli_recur, \ | 438 | __print_flags(__entry->bli_flags, "|", XFS_BLI_FLAGS), |
423 | __entry->bli_refcount, \ | 439 | __entry->li_desc, |
424 | __print_flags(__entry->bli_flags, "|", XFS_BLI_FLAGS), \ | 440 | __print_flags(__entry->li_flags, "|", XFS_LI_FLAGS)) |
425 | __entry->li_desc, \ | ||
426 | __print_flags(__entry->li_flags, "|", XFS_LI_FLAGS)) \ | ||
427 | ) | 441 | ) |
442 | |||
443 | #define DEFINE_BUF_ITEM_EVENT(name) \ | ||
444 | DEFINE_EVENT(xfs_buf_item_class, name, \ | ||
445 | TP_PROTO(struct xfs_buf_log_item *bip), \ | ||
446 | TP_ARGS(bip)) | ||
428 | DEFINE_BUF_ITEM_EVENT(xfs_buf_item_size); | 447 | DEFINE_BUF_ITEM_EVENT(xfs_buf_item_size); |
429 | DEFINE_BUF_ITEM_EVENT(xfs_buf_item_size_stale); | 448 | DEFINE_BUF_ITEM_EVENT(xfs_buf_item_size_stale); |
430 | DEFINE_BUF_ITEM_EVENT(xfs_buf_item_format); | 449 | DEFINE_BUF_ITEM_EVENT(xfs_buf_item_format); |
@@ -450,78 +469,90 @@ DEFINE_BUF_ITEM_EVENT(xfs_trans_bhold); | |||
450 | DEFINE_BUF_ITEM_EVENT(xfs_trans_bhold_release); | 469 | DEFINE_BUF_ITEM_EVENT(xfs_trans_bhold_release); |
451 | DEFINE_BUF_ITEM_EVENT(xfs_trans_binval); | 470 | DEFINE_BUF_ITEM_EVENT(xfs_trans_binval); |
452 | 471 | ||
472 | DECLARE_EVENT_CLASS(xfs_lock_class, | ||
473 | TP_PROTO(struct xfs_inode *ip, unsigned lock_flags, | ||
474 | unsigned long caller_ip), | ||
475 | TP_ARGS(ip, lock_flags, caller_ip), | ||
476 | TP_STRUCT__entry( | ||
477 | __field(dev_t, dev) | ||
478 | __field(xfs_ino_t, ino) | ||
479 | __field(int, lock_flags) | ||
480 | __field(unsigned long, caller_ip) | ||
481 | ), | ||
482 | TP_fast_assign( | ||
483 | __entry->dev = VFS_I(ip)->i_sb->s_dev; | ||
484 | __entry->ino = ip->i_ino; | ||
485 | __entry->lock_flags = lock_flags; | ||
486 | __entry->caller_ip = caller_ip; | ||
487 | ), | ||
488 | TP_printk("dev %d:%d ino 0x%llx flags %s caller %pf", | ||
489 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
490 | __entry->ino, | ||
491 | __print_flags(__entry->lock_flags, "|", XFS_LOCK_FLAGS), | ||
492 | (void *)__entry->caller_ip) | ||
493 | ) | ||
494 | |||
453 | #define DEFINE_LOCK_EVENT(name) \ | 495 | #define DEFINE_LOCK_EVENT(name) \ |
454 | TRACE_EVENT(name, \ | 496 | DEFINE_EVENT(xfs_lock_class, name, \ |
455 | TP_PROTO(struct xfs_inode *ip, unsigned lock_flags, \ | 497 | TP_PROTO(struct xfs_inode *ip, unsigned lock_flags, \ |
456 | unsigned long caller_ip), \ | 498 | unsigned long caller_ip), \ |
457 | TP_ARGS(ip, lock_flags, caller_ip), \ | 499 | TP_ARGS(ip, lock_flags, caller_ip)) |
458 | TP_STRUCT__entry( \ | ||
459 | __field(dev_t, dev) \ | ||
460 | __field(xfs_ino_t, ino) \ | ||
461 | __field(int, lock_flags) \ | ||
462 | __field(unsigned long, caller_ip) \ | ||
463 | ), \ | ||
464 | TP_fast_assign( \ | ||
465 | __entry->dev = VFS_I(ip)->i_sb->s_dev; \ | ||
466 | __entry->ino = ip->i_ino; \ | ||
467 | __entry->lock_flags = lock_flags; \ | ||
468 | __entry->caller_ip = caller_ip; \ | ||
469 | ), \ | ||
470 | TP_printk("dev %d:%d ino 0x%llx flags %s caller %pf", \ | ||
471 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | ||
472 | __entry->ino, \ | ||
473 | __print_flags(__entry->lock_flags, "|", XFS_LOCK_FLAGS), \ | ||
474 | (void *)__entry->caller_ip) \ | ||
475 | ) | ||
476 | |||
477 | DEFINE_LOCK_EVENT(xfs_ilock); | 500 | DEFINE_LOCK_EVENT(xfs_ilock); |
478 | DEFINE_LOCK_EVENT(xfs_ilock_nowait); | 501 | DEFINE_LOCK_EVENT(xfs_ilock_nowait); |
479 | DEFINE_LOCK_EVENT(xfs_ilock_demote); | 502 | DEFINE_LOCK_EVENT(xfs_ilock_demote); |
480 | DEFINE_LOCK_EVENT(xfs_iunlock); | 503 | DEFINE_LOCK_EVENT(xfs_iunlock); |
481 | 504 | ||
505 | DECLARE_EVENT_CLASS(xfs_iget_class, | ||
506 | TP_PROTO(struct xfs_inode *ip), | ||
507 | TP_ARGS(ip), | ||
508 | TP_STRUCT__entry( | ||
509 | __field(dev_t, dev) | ||
510 | __field(xfs_ino_t, ino) | ||
511 | ), | ||
512 | TP_fast_assign( | ||
513 | __entry->dev = VFS_I(ip)->i_sb->s_dev; | ||
514 | __entry->ino = ip->i_ino; | ||
515 | ), | ||
516 | TP_printk("dev %d:%d ino 0x%llx", | ||
517 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
518 | __entry->ino) | ||
519 | ) | ||
520 | |||
482 | #define DEFINE_IGET_EVENT(name) \ | 521 | #define DEFINE_IGET_EVENT(name) \ |
483 | TRACE_EVENT(name, \ | 522 | DEFINE_EVENT(xfs_iget_class, name, \ |
484 | TP_PROTO(struct xfs_inode *ip), \ | 523 | TP_PROTO(struct xfs_inode *ip), \ |
485 | TP_ARGS(ip), \ | 524 | TP_ARGS(ip)) |
486 | TP_STRUCT__entry( \ | ||
487 | __field(dev_t, dev) \ | ||
488 | __field(xfs_ino_t, ino) \ | ||
489 | ), \ | ||
490 | TP_fast_assign( \ | ||
491 | __entry->dev = VFS_I(ip)->i_sb->s_dev; \ | ||
492 | __entry->ino = ip->i_ino; \ | ||
493 | ), \ | ||
494 | TP_printk("dev %d:%d ino 0x%llx", \ | ||
495 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | ||
496 | __entry->ino) \ | ||
497 | ) | ||
498 | DEFINE_IGET_EVENT(xfs_iget_skip); | 525 | DEFINE_IGET_EVENT(xfs_iget_skip); |
499 | DEFINE_IGET_EVENT(xfs_iget_reclaim); | 526 | DEFINE_IGET_EVENT(xfs_iget_reclaim); |
500 | DEFINE_IGET_EVENT(xfs_iget_found); | 527 | DEFINE_IGET_EVENT(xfs_iget_found); |
501 | DEFINE_IGET_EVENT(xfs_iget_alloc); | 528 | DEFINE_IGET_EVENT(xfs_iget_alloc); |
502 | 529 | ||
530 | DECLARE_EVENT_CLASS(xfs_inode_class, | ||
531 | TP_PROTO(struct xfs_inode *ip, unsigned long caller_ip), | ||
532 | TP_ARGS(ip, caller_ip), | ||
533 | TP_STRUCT__entry( | ||
534 | __field(dev_t, dev) | ||
535 | __field(xfs_ino_t, ino) | ||
536 | __field(int, count) | ||
537 | __field(unsigned long, caller_ip) | ||
538 | ), | ||
539 | TP_fast_assign( | ||
540 | __entry->dev = VFS_I(ip)->i_sb->s_dev; | ||
541 | __entry->ino = ip->i_ino; | ||
542 | __entry->count = atomic_read(&VFS_I(ip)->i_count); | ||
543 | __entry->caller_ip = caller_ip; | ||
544 | ), | ||
545 | TP_printk("dev %d:%d ino 0x%llx count %d caller %pf", | ||
546 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
547 | __entry->ino, | ||
548 | __entry->count, | ||
549 | (char *)__entry->caller_ip) | ||
550 | ) | ||
551 | |||
503 | #define DEFINE_INODE_EVENT(name) \ | 552 | #define DEFINE_INODE_EVENT(name) \ |
504 | TRACE_EVENT(name, \ | 553 | DEFINE_EVENT(xfs_inode_class, name, \ |
505 | TP_PROTO(struct xfs_inode *ip, unsigned long caller_ip), \ | 554 | TP_PROTO(struct xfs_inode *ip, unsigned long caller_ip), \ |
506 | TP_ARGS(ip, caller_ip), \ | 555 | TP_ARGS(ip, caller_ip)) |
507 | TP_STRUCT__entry( \ | ||
508 | __field(dev_t, dev) \ | ||
509 | __field(xfs_ino_t, ino) \ | ||
510 | __field(int, count) \ | ||
511 | __field(unsigned long, caller_ip) \ | ||
512 | ), \ | ||
513 | TP_fast_assign( \ | ||
514 | __entry->dev = VFS_I(ip)->i_sb->s_dev; \ | ||
515 | __entry->ino = ip->i_ino; \ | ||
516 | __entry->count = atomic_read(&VFS_I(ip)->i_count); \ | ||
517 | __entry->caller_ip = caller_ip; \ | ||
518 | ), \ | ||
519 | TP_printk("dev %d:%d ino 0x%llx count %d caller %pf", \ | ||
520 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | ||
521 | __entry->ino, \ | ||
522 | __entry->count, \ | ||
523 | (char *)__entry->caller_ip) \ | ||
524 | ) | ||
525 | DEFINE_INODE_EVENT(xfs_ihold); | 556 | DEFINE_INODE_EVENT(xfs_ihold); |
526 | DEFINE_INODE_EVENT(xfs_irele); | 557 | DEFINE_INODE_EVENT(xfs_irele); |
527 | /* the old xfs_itrace_entry tracer - to be replaced by s.th. in the VFS */ | 558 | /* the old xfs_itrace_entry tracer - to be replaced by s.th. in the VFS */ |
@@ -529,55 +560,59 @@ DEFINE_INODE_EVENT(xfs_inode); | |||
529 | #define xfs_itrace_entry(ip) \ | 560 | #define xfs_itrace_entry(ip) \ |
530 | trace_xfs_inode(ip, _THIS_IP_) | 561 | trace_xfs_inode(ip, _THIS_IP_) |
531 | 562 | ||
532 | #define DEFINE_DQUOT_EVENT(tname) \ | 563 | DECLARE_EVENT_CLASS(xfs_dquot_class, |
533 | TRACE_EVENT(tname, \ | 564 | TP_PROTO(struct xfs_dquot *dqp), |
534 | TP_PROTO(struct xfs_dquot *dqp), \ | 565 | TP_ARGS(dqp), |
535 | TP_ARGS(dqp), \ | 566 | TP_STRUCT__entry( |
536 | TP_STRUCT__entry( \ | 567 | __field(dev_t, dev) |
537 | __field(dev_t, dev) \ | 568 | __field(__be32, id) |
538 | __field(__be32, id) \ | 569 | __field(unsigned, flags) |
539 | __field(unsigned, flags) \ | 570 | __field(unsigned, nrefs) |
540 | __field(unsigned, nrefs) \ | 571 | __field(unsigned long long, res_bcount) |
541 | __field(unsigned long long, res_bcount) \ | 572 | __field(unsigned long long, bcount) |
542 | __field(unsigned long long, bcount) \ | 573 | __field(unsigned long long, icount) |
543 | __field(unsigned long long, icount) \ | 574 | __field(unsigned long long, blk_hardlimit) |
544 | __field(unsigned long long, blk_hardlimit) \ | 575 | __field(unsigned long long, blk_softlimit) |
545 | __field(unsigned long long, blk_softlimit) \ | 576 | __field(unsigned long long, ino_hardlimit) |
546 | __field(unsigned long long, ino_hardlimit) \ | 577 | __field(unsigned long long, ino_softlimit) |
547 | __field(unsigned long long, ino_softlimit) \ | ||
548 | ), \ | ||
549 | TP_fast_assign( \ | ||
550 | __entry->dev = dqp->q_mount->m_super->s_dev; \ | ||
551 | __entry->id = dqp->q_core.d_id; \ | ||
552 | __entry->flags = dqp->dq_flags; \ | ||
553 | __entry->nrefs = dqp->q_nrefs; \ | ||
554 | __entry->res_bcount = dqp->q_res_bcount; \ | ||
555 | __entry->bcount = be64_to_cpu(dqp->q_core.d_bcount); \ | ||
556 | __entry->icount = be64_to_cpu(dqp->q_core.d_icount); \ | ||
557 | __entry->blk_hardlimit = \ | ||
558 | be64_to_cpu(dqp->q_core.d_blk_hardlimit); \ | ||
559 | __entry->blk_softlimit = \ | ||
560 | be64_to_cpu(dqp->q_core.d_blk_softlimit); \ | ||
561 | __entry->ino_hardlimit = \ | ||
562 | be64_to_cpu(dqp->q_core.d_ino_hardlimit); \ | ||
563 | __entry->ino_softlimit = \ | ||
564 | be64_to_cpu(dqp->q_core.d_ino_softlimit); \ | ||
565 | ), \ | 578 | ), \ |
566 | TP_printk("dev %d:%d id 0x%x flags %s nrefs %u res_bc 0x%llx " \ | 579 | TP_fast_assign( |
567 | "bcnt 0x%llx [hard 0x%llx | soft 0x%llx] " \ | 580 | __entry->dev = dqp->q_mount->m_super->s_dev; |
568 | "icnt 0x%llx [hard 0x%llx | soft 0x%llx]", \ | 581 | __entry->id = dqp->q_core.d_id; |
569 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | 582 | __entry->flags = dqp->dq_flags; |
570 | be32_to_cpu(__entry->id), \ | 583 | __entry->nrefs = dqp->q_nrefs; |
571 | __print_flags(__entry->flags, "|", XFS_DQ_FLAGS), \ | 584 | __entry->res_bcount = dqp->q_res_bcount; |
572 | __entry->nrefs, \ | 585 | __entry->bcount = be64_to_cpu(dqp->q_core.d_bcount); |
573 | __entry->res_bcount, \ | 586 | __entry->icount = be64_to_cpu(dqp->q_core.d_icount); |
574 | __entry->bcount, \ | 587 | __entry->blk_hardlimit = |
575 | __entry->blk_hardlimit, \ | 588 | be64_to_cpu(dqp->q_core.d_blk_hardlimit); |
576 | __entry->blk_softlimit, \ | 589 | __entry->blk_softlimit = |
577 | __entry->icount, \ | 590 | be64_to_cpu(dqp->q_core.d_blk_softlimit); |
578 | __entry->ino_hardlimit, \ | 591 | __entry->ino_hardlimit = |
579 | __entry->ino_softlimit) \ | 592 | be64_to_cpu(dqp->q_core.d_ino_hardlimit); |
593 | __entry->ino_softlimit = | ||
594 | be64_to_cpu(dqp->q_core.d_ino_softlimit); | ||
595 | ), | ||
596 | TP_printk("dev %d:%d id 0x%x flags %s nrefs %u res_bc 0x%llx " | ||
597 | "bcnt 0x%llx [hard 0x%llx | soft 0x%llx] " | ||
598 | "icnt 0x%llx [hard 0x%llx | soft 0x%llx]", | ||
599 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
600 | be32_to_cpu(__entry->id), | ||
601 | __print_flags(__entry->flags, "|", XFS_DQ_FLAGS), | ||
602 | __entry->nrefs, | ||
603 | __entry->res_bcount, | ||
604 | __entry->bcount, | ||
605 | __entry->blk_hardlimit, | ||
606 | __entry->blk_softlimit, | ||
607 | __entry->icount, | ||
608 | __entry->ino_hardlimit, | ||
609 | __entry->ino_softlimit) | ||
580 | ) | 610 | ) |
611 | |||
612 | #define DEFINE_DQUOT_EVENT(name) \ | ||
613 | DEFINE_EVENT(xfs_dquot_class, name, \ | ||
614 | TP_PROTO(struct xfs_dquot *dqp), \ | ||
615 | TP_ARGS(dqp)) | ||
581 | DEFINE_DQUOT_EVENT(xfs_dqadjust); | 616 | DEFINE_DQUOT_EVENT(xfs_dqadjust); |
582 | DEFINE_DQUOT_EVENT(xfs_dqshake_dirty); | 617 | DEFINE_DQUOT_EVENT(xfs_dqshake_dirty); |
583 | DEFINE_DQUOT_EVENT(xfs_dqshake_unlink); | 618 | DEFINE_DQUOT_EVENT(xfs_dqshake_unlink); |
@@ -610,72 +645,75 @@ DEFINE_DQUOT_EVENT(xfs_dqflush_done); | |||
610 | DEFINE_IGET_EVENT(xfs_dquot_dqalloc); | 645 | DEFINE_IGET_EVENT(xfs_dquot_dqalloc); |
611 | DEFINE_IGET_EVENT(xfs_dquot_dqdetach); | 646 | DEFINE_IGET_EVENT(xfs_dquot_dqdetach); |
612 | 647 | ||
648 | DECLARE_EVENT_CLASS(xfs_loggrant_class, | ||
649 | TP_PROTO(struct log *log, struct xlog_ticket *tic), | ||
650 | TP_ARGS(log, tic), | ||
651 | TP_STRUCT__entry( | ||
652 | __field(dev_t, dev) | ||
653 | __field(unsigned, trans_type) | ||
654 | __field(char, ocnt) | ||
655 | __field(char, cnt) | ||
656 | __field(int, curr_res) | ||
657 | __field(int, unit_res) | ||
658 | __field(unsigned int, flags) | ||
659 | __field(void *, reserve_headq) | ||
660 | __field(void *, write_headq) | ||
661 | __field(int, grant_reserve_cycle) | ||
662 | __field(int, grant_reserve_bytes) | ||
663 | __field(int, grant_write_cycle) | ||
664 | __field(int, grant_write_bytes) | ||
665 | __field(int, curr_cycle) | ||
666 | __field(int, curr_block) | ||
667 | __field(xfs_lsn_t, tail_lsn) | ||
668 | ), | ||
669 | TP_fast_assign( | ||
670 | __entry->dev = log->l_mp->m_super->s_dev; | ||
671 | __entry->trans_type = tic->t_trans_type; | ||
672 | __entry->ocnt = tic->t_ocnt; | ||
673 | __entry->cnt = tic->t_cnt; | ||
674 | __entry->curr_res = tic->t_curr_res; | ||
675 | __entry->unit_res = tic->t_unit_res; | ||
676 | __entry->flags = tic->t_flags; | ||
677 | __entry->reserve_headq = log->l_reserve_headq; | ||
678 | __entry->write_headq = log->l_write_headq; | ||
679 | __entry->grant_reserve_cycle = log->l_grant_reserve_cycle; | ||
680 | __entry->grant_reserve_bytes = log->l_grant_reserve_bytes; | ||
681 | __entry->grant_write_cycle = log->l_grant_write_cycle; | ||
682 | __entry->grant_write_bytes = log->l_grant_write_bytes; | ||
683 | __entry->curr_cycle = log->l_curr_cycle; | ||
684 | __entry->curr_block = log->l_curr_block; | ||
685 | __entry->tail_lsn = log->l_tail_lsn; | ||
686 | ), | ||
687 | TP_printk("dev %d:%d type %s t_ocnt %u t_cnt %u t_curr_res %u " | ||
688 | "t_unit_res %u t_flags %s reserve_headq 0x%p " | ||
689 | "write_headq 0x%p grant_reserve_cycle %d " | ||
690 | "grant_reserve_bytes %d grant_write_cycle %d " | ||
691 | "grant_write_bytes %d curr_cycle %d curr_block %d " | ||
692 | "tail_cycle %d tail_block %d", | ||
693 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
694 | __print_symbolic(__entry->trans_type, XFS_TRANS_TYPES), | ||
695 | __entry->ocnt, | ||
696 | __entry->cnt, | ||
697 | __entry->curr_res, | ||
698 | __entry->unit_res, | ||
699 | __print_flags(__entry->flags, "|", XLOG_TIC_FLAGS), | ||
700 | __entry->reserve_headq, | ||
701 | __entry->write_headq, | ||
702 | __entry->grant_reserve_cycle, | ||
703 | __entry->grant_reserve_bytes, | ||
704 | __entry->grant_write_cycle, | ||
705 | __entry->grant_write_bytes, | ||
706 | __entry->curr_cycle, | ||
707 | __entry->curr_block, | ||
708 | CYCLE_LSN(__entry->tail_lsn), | ||
709 | BLOCK_LSN(__entry->tail_lsn) | ||
710 | ) | ||
711 | ) | ||
613 | 712 | ||
614 | #define DEFINE_LOGGRANT_EVENT(tname) \ | 713 | #define DEFINE_LOGGRANT_EVENT(name) \ |
615 | TRACE_EVENT(tname, \ | 714 | DEFINE_EVENT(xfs_loggrant_class, name, \ |
616 | TP_PROTO(struct log *log, struct xlog_ticket *tic), \ | 715 | TP_PROTO(struct log *log, struct xlog_ticket *tic), \ |
617 | TP_ARGS(log, tic), \ | 716 | TP_ARGS(log, tic)) |
618 | TP_STRUCT__entry( \ | ||
619 | __field(dev_t, dev) \ | ||
620 | __field(unsigned, trans_type) \ | ||
621 | __field(char, ocnt) \ | ||
622 | __field(char, cnt) \ | ||
623 | __field(int, curr_res) \ | ||
624 | __field(int, unit_res) \ | ||
625 | __field(unsigned int, flags) \ | ||
626 | __field(void *, reserve_headq) \ | ||
627 | __field(void *, write_headq) \ | ||
628 | __field(int, grant_reserve_cycle) \ | ||
629 | __field(int, grant_reserve_bytes) \ | ||
630 | __field(int, grant_write_cycle) \ | ||
631 | __field(int, grant_write_bytes) \ | ||
632 | __field(int, curr_cycle) \ | ||
633 | __field(int, curr_block) \ | ||
634 | __field(xfs_lsn_t, tail_lsn) \ | ||
635 | ), \ | ||
636 | TP_fast_assign( \ | ||
637 | __entry->dev = log->l_mp->m_super->s_dev; \ | ||
638 | __entry->trans_type = tic->t_trans_type; \ | ||
639 | __entry->ocnt = tic->t_ocnt; \ | ||
640 | __entry->cnt = tic->t_cnt; \ | ||
641 | __entry->curr_res = tic->t_curr_res; \ | ||
642 | __entry->unit_res = tic->t_unit_res; \ | ||
643 | __entry->flags = tic->t_flags; \ | ||
644 | __entry->reserve_headq = log->l_reserve_headq; \ | ||
645 | __entry->write_headq = log->l_write_headq; \ | ||
646 | __entry->grant_reserve_cycle = log->l_grant_reserve_cycle; \ | ||
647 | __entry->grant_reserve_bytes = log->l_grant_reserve_bytes; \ | ||
648 | __entry->grant_write_cycle = log->l_grant_write_cycle; \ | ||
649 | __entry->grant_write_bytes = log->l_grant_write_bytes; \ | ||
650 | __entry->curr_cycle = log->l_curr_cycle; \ | ||
651 | __entry->curr_block = log->l_curr_block; \ | ||
652 | __entry->tail_lsn = log->l_tail_lsn; \ | ||
653 | ), \ | ||
654 | TP_printk("dev %d:%d type %s t_ocnt %u t_cnt %u t_curr_res %u " \ | ||
655 | "t_unit_res %u t_flags %s reserve_headq 0x%p " \ | ||
656 | "write_headq 0x%p grant_reserve_cycle %d " \ | ||
657 | "grant_reserve_bytes %d grant_write_cycle %d " \ | ||
658 | "grant_write_bytes %d curr_cycle %d curr_block %d " \ | ||
659 | "tail_cycle %d tail_block %d", \ | ||
660 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | ||
661 | __print_symbolic(__entry->trans_type, XFS_TRANS_TYPES), \ | ||
662 | __entry->ocnt, \ | ||
663 | __entry->cnt, \ | ||
664 | __entry->curr_res, \ | ||
665 | __entry->unit_res, \ | ||
666 | __print_flags(__entry->flags, "|", XLOG_TIC_FLAGS), \ | ||
667 | __entry->reserve_headq, \ | ||
668 | __entry->write_headq, \ | ||
669 | __entry->grant_reserve_cycle, \ | ||
670 | __entry->grant_reserve_bytes, \ | ||
671 | __entry->grant_write_cycle, \ | ||
672 | __entry->grant_write_bytes, \ | ||
673 | __entry->curr_cycle, \ | ||
674 | __entry->curr_block, \ | ||
675 | CYCLE_LSN(__entry->tail_lsn), \ | ||
676 | BLOCK_LSN(__entry->tail_lsn) \ | ||
677 | ) \ | ||
678 | ) | ||
679 | DEFINE_LOGGRANT_EVENT(xfs_log_done_nonperm); | 717 | DEFINE_LOGGRANT_EVENT(xfs_log_done_nonperm); |
680 | DEFINE_LOGGRANT_EVENT(xfs_log_done_perm); | 718 | DEFINE_LOGGRANT_EVENT(xfs_log_done_perm); |
681 | DEFINE_LOGGRANT_EVENT(xfs_log_reserve); | 719 | DEFINE_LOGGRANT_EVENT(xfs_log_reserve); |
@@ -815,7 +853,7 @@ TRACE_EVENT(name, \ | |||
815 | ), \ | 853 | ), \ |
816 | TP_printk("dev %d:%d ino 0x%llx size 0x%llx new_size 0x%llx " \ | 854 | TP_printk("dev %d:%d ino 0x%llx size 0x%llx new_size 0x%llx " \ |
817 | "offset 0x%llx count %zd flags %s " \ | 855 | "offset 0x%llx count %zd flags %s " \ |
818 | "startoff 0x%llx startblock 0x%llx blockcount 0x%llx", \ | 856 | "startoff 0x%llx startblock %s blockcount 0x%llx", \ |
819 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | 857 | MAJOR(__entry->dev), MINOR(__entry->dev), \ |
820 | __entry->ino, \ | 858 | __entry->ino, \ |
821 | __entry->size, \ | 859 | __entry->size, \ |
@@ -824,7 +862,7 @@ TRACE_EVENT(name, \ | |||
824 | __entry->count, \ | 862 | __entry->count, \ |
825 | __print_flags(__entry->flags, "|", BMAPI_FLAGS), \ | 863 | __print_flags(__entry->flags, "|", BMAPI_FLAGS), \ |
826 | __entry->startoff, \ | 864 | __entry->startoff, \ |
827 | __entry->startblock, \ | 865 | xfs_fmtfsblock(__entry->startblock), \ |
828 | __entry->blockcount) \ | 866 | __entry->blockcount) \ |
829 | ) | 867 | ) |
830 | DEFINE_IOMAP_EVENT(xfs_iomap_enter); | 868 | DEFINE_IOMAP_EVENT(xfs_iomap_enter); |
@@ -897,28 +935,32 @@ TRACE_EVENT(xfs_itruncate_start, | |||
897 | __entry->toss_finish) | 935 | __entry->toss_finish) |
898 | ); | 936 | ); |
899 | 937 | ||
938 | DECLARE_EVENT_CLASS(xfs_itrunc_class, | ||
939 | TP_PROTO(struct xfs_inode *ip, xfs_fsize_t new_size), | ||
940 | TP_ARGS(ip, new_size), | ||
941 | TP_STRUCT__entry( | ||
942 | __field(dev_t, dev) | ||
943 | __field(xfs_ino_t, ino) | ||
944 | __field(xfs_fsize_t, size) | ||
945 | __field(xfs_fsize_t, new_size) | ||
946 | ), | ||
947 | TP_fast_assign( | ||
948 | __entry->dev = VFS_I(ip)->i_sb->s_dev; | ||
949 | __entry->ino = ip->i_ino; | ||
950 | __entry->size = ip->i_d.di_size; | ||
951 | __entry->new_size = new_size; | ||
952 | ), | ||
953 | TP_printk("dev %d:%d ino 0x%llx size 0x%llx new_size 0x%llx", | ||
954 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
955 | __entry->ino, | ||
956 | __entry->size, | ||
957 | __entry->new_size) | ||
958 | ) | ||
959 | |||
900 | #define DEFINE_ITRUNC_EVENT(name) \ | 960 | #define DEFINE_ITRUNC_EVENT(name) \ |
901 | TRACE_EVENT(name, \ | 961 | DEFINE_EVENT(xfs_itrunc_class, name, \ |
902 | TP_PROTO(struct xfs_inode *ip, xfs_fsize_t new_size), \ | 962 | TP_PROTO(struct xfs_inode *ip, xfs_fsize_t new_size), \ |
903 | TP_ARGS(ip, new_size), \ | 963 | TP_ARGS(ip, new_size)) |
904 | TP_STRUCT__entry( \ | ||
905 | __field(dev_t, dev) \ | ||
906 | __field(xfs_ino_t, ino) \ | ||
907 | __field(xfs_fsize_t, size) \ | ||
908 | __field(xfs_fsize_t, new_size) \ | ||
909 | ), \ | ||
910 | TP_fast_assign( \ | ||
911 | __entry->dev = VFS_I(ip)->i_sb->s_dev; \ | ||
912 | __entry->ino = ip->i_ino; \ | ||
913 | __entry->size = ip->i_d.di_size; \ | ||
914 | __entry->new_size = new_size; \ | ||
915 | ), \ | ||
916 | TP_printk("dev %d:%d ino 0x%llx size 0x%llx new_size 0x%llx", \ | ||
917 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | ||
918 | __entry->ino, \ | ||
919 | __entry->size, \ | ||
920 | __entry->new_size) \ | ||
921 | ) | ||
922 | DEFINE_ITRUNC_EVENT(xfs_itruncate_finish_start); | 964 | DEFINE_ITRUNC_EVENT(xfs_itruncate_finish_start); |
923 | DEFINE_ITRUNC_EVENT(xfs_itruncate_finish_end); | 965 | DEFINE_ITRUNC_EVENT(xfs_itruncate_finish_end); |
924 | 966 | ||
@@ -1037,28 +1079,28 @@ TRACE_EVENT(xfs_alloc_unbusy, | |||
1037 | 1079 | ||
1038 | TRACE_EVENT(xfs_alloc_busysearch, | 1080 | TRACE_EVENT(xfs_alloc_busysearch, |
1039 | TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agblock_t agbno, | 1081 | TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agblock_t agbno, |
1040 | xfs_extlen_t len, int found), | 1082 | xfs_extlen_t len, xfs_lsn_t lsn), |
1041 | TP_ARGS(mp, agno, agbno, len, found), | 1083 | TP_ARGS(mp, agno, agbno, len, lsn), |
1042 | TP_STRUCT__entry( | 1084 | TP_STRUCT__entry( |
1043 | __field(dev_t, dev) | 1085 | __field(dev_t, dev) |
1044 | __field(xfs_agnumber_t, agno) | 1086 | __field(xfs_agnumber_t, agno) |
1045 | __field(xfs_agblock_t, agbno) | 1087 | __field(xfs_agblock_t, agbno) |
1046 | __field(xfs_extlen_t, len) | 1088 | __field(xfs_extlen_t, len) |
1047 | __field(int, found) | 1089 | __field(xfs_lsn_t, lsn) |
1048 | ), | 1090 | ), |
1049 | TP_fast_assign( | 1091 | TP_fast_assign( |
1050 | __entry->dev = mp->m_super->s_dev; | 1092 | __entry->dev = mp->m_super->s_dev; |
1051 | __entry->agno = agno; | 1093 | __entry->agno = agno; |
1052 | __entry->agbno = agbno; | 1094 | __entry->agbno = agbno; |
1053 | __entry->len = len; | 1095 | __entry->len = len; |
1054 | __entry->found = found; | 1096 | __entry->lsn = lsn; |
1055 | ), | 1097 | ), |
1056 | TP_printk("dev %d:%d agno %u agbno %u len %u %s", | 1098 | TP_printk("dev %d:%d agno %u agbno %u len %u force lsn 0x%llx", |
1057 | MAJOR(__entry->dev), MINOR(__entry->dev), | 1099 | MAJOR(__entry->dev), MINOR(__entry->dev), |
1058 | __entry->agno, | 1100 | __entry->agno, |
1059 | __entry->agbno, | 1101 | __entry->agbno, |
1060 | __entry->len, | 1102 | __entry->len, |
1061 | __print_symbolic(__entry->found, XFS_BUSY_STATES)) | 1103 | __entry->lsn) |
1062 | ); | 1104 | ); |
1063 | 1105 | ||
1064 | TRACE_EVENT(xfs_agf, | 1106 | TRACE_EVENT(xfs_agf, |
@@ -1152,77 +1194,80 @@ TRACE_EVENT(xfs_free_extent, | |||
1152 | 1194 | ||
1153 | ); | 1195 | ); |
1154 | 1196 | ||
1155 | #define DEFINE_ALLOC_EVENT(name) \ | 1197 | DECLARE_EVENT_CLASS(xfs_alloc_class, |
1156 | TRACE_EVENT(name, \ | 1198 | TP_PROTO(struct xfs_alloc_arg *args), |
1157 | TP_PROTO(struct xfs_alloc_arg *args), \ | 1199 | TP_ARGS(args), |
1158 | TP_ARGS(args), \ | 1200 | TP_STRUCT__entry( |
1159 | TP_STRUCT__entry( \ | 1201 | __field(dev_t, dev) |
1160 | __field(dev_t, dev) \ | 1202 | __field(xfs_agnumber_t, agno) |
1161 | __field(xfs_agnumber_t, agno) \ | 1203 | __field(xfs_agblock_t, agbno) |
1162 | __field(xfs_agblock_t, agbno) \ | 1204 | __field(xfs_extlen_t, minlen) |
1163 | __field(xfs_extlen_t, minlen) \ | 1205 | __field(xfs_extlen_t, maxlen) |
1164 | __field(xfs_extlen_t, maxlen) \ | 1206 | __field(xfs_extlen_t, mod) |
1165 | __field(xfs_extlen_t, mod) \ | 1207 | __field(xfs_extlen_t, prod) |
1166 | __field(xfs_extlen_t, prod) \ | 1208 | __field(xfs_extlen_t, minleft) |
1167 | __field(xfs_extlen_t, minleft) \ | 1209 | __field(xfs_extlen_t, total) |
1168 | __field(xfs_extlen_t, total) \ | 1210 | __field(xfs_extlen_t, alignment) |
1169 | __field(xfs_extlen_t, alignment) \ | 1211 | __field(xfs_extlen_t, minalignslop) |
1170 | __field(xfs_extlen_t, minalignslop) \ | 1212 | __field(xfs_extlen_t, len) |
1171 | __field(xfs_extlen_t, len) \ | 1213 | __field(short, type) |
1172 | __field(short, type) \ | 1214 | __field(short, otype) |
1173 | __field(short, otype) \ | 1215 | __field(char, wasdel) |
1174 | __field(char, wasdel) \ | 1216 | __field(char, wasfromfl) |
1175 | __field(char, wasfromfl) \ | 1217 | __field(char, isfl) |
1176 | __field(char, isfl) \ | 1218 | __field(char, userdata) |
1177 | __field(char, userdata) \ | 1219 | __field(xfs_fsblock_t, firstblock) |
1178 | __field(xfs_fsblock_t, firstblock) \ | 1220 | ), |
1179 | ), \ | 1221 | TP_fast_assign( |
1180 | TP_fast_assign( \ | 1222 | __entry->dev = args->mp->m_super->s_dev; |
1181 | __entry->dev = args->mp->m_super->s_dev; \ | 1223 | __entry->agno = args->agno; |
1182 | __entry->agno = args->agno; \ | 1224 | __entry->agbno = args->agbno; |
1183 | __entry->agbno = args->agbno; \ | 1225 | __entry->minlen = args->minlen; |
1184 | __entry->minlen = args->minlen; \ | 1226 | __entry->maxlen = args->maxlen; |
1185 | __entry->maxlen = args->maxlen; \ | 1227 | __entry->mod = args->mod; |
1186 | __entry->mod = args->mod; \ | 1228 | __entry->prod = args->prod; |
1187 | __entry->prod = args->prod; \ | 1229 | __entry->minleft = args->minleft; |
1188 | __entry->minleft = args->minleft; \ | 1230 | __entry->total = args->total; |
1189 | __entry->total = args->total; \ | 1231 | __entry->alignment = args->alignment; |
1190 | __entry->alignment = args->alignment; \ | 1232 | __entry->minalignslop = args->minalignslop; |
1191 | __entry->minalignslop = args->minalignslop; \ | 1233 | __entry->len = args->len; |
1192 | __entry->len = args->len; \ | 1234 | __entry->type = args->type; |
1193 | __entry->type = args->type; \ | 1235 | __entry->otype = args->otype; |
1194 | __entry->otype = args->otype; \ | 1236 | __entry->wasdel = args->wasdel; |
1195 | __entry->wasdel = args->wasdel; \ | 1237 | __entry->wasfromfl = args->wasfromfl; |
1196 | __entry->wasfromfl = args->wasfromfl; \ | 1238 | __entry->isfl = args->isfl; |
1197 | __entry->isfl = args->isfl; \ | 1239 | __entry->userdata = args->userdata; |
1198 | __entry->userdata = args->userdata; \ | 1240 | __entry->firstblock = args->firstblock; |
1199 | __entry->firstblock = args->firstblock; \ | 1241 | ), |
1200 | ), \ | 1242 | TP_printk("dev %d:%d agno %u agbno %u minlen %u maxlen %u mod %u " |
1201 | TP_printk("dev %d:%d agno %u agbno %u minlen %u maxlen %u mod %u " \ | 1243 | "prod %u minleft %u total %u alignment %u minalignslop %u " |
1202 | "prod %u minleft %u total %u alignment %u minalignslop %u " \ | 1244 | "len %u type %s otype %s wasdel %d wasfromfl %d isfl %d " |
1203 | "len %u type %s otype %s wasdel %d wasfromfl %d isfl %d " \ | 1245 | "userdata %d firstblock 0x%llx", |
1204 | "userdata %d firstblock 0x%llx", \ | 1246 | MAJOR(__entry->dev), MINOR(__entry->dev), |
1205 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | 1247 | __entry->agno, |
1206 | __entry->agno, \ | 1248 | __entry->agbno, |
1207 | __entry->agbno, \ | 1249 | __entry->minlen, |
1208 | __entry->minlen, \ | 1250 | __entry->maxlen, |
1209 | __entry->maxlen, \ | 1251 | __entry->mod, |
1210 | __entry->mod, \ | 1252 | __entry->prod, |
1211 | __entry->prod, \ | 1253 | __entry->minleft, |
1212 | __entry->minleft, \ | 1254 | __entry->total, |
1213 | __entry->total, \ | 1255 | __entry->alignment, |
1214 | __entry->alignment, \ | 1256 | __entry->minalignslop, |
1215 | __entry->minalignslop, \ | 1257 | __entry->len, |
1216 | __entry->len, \ | 1258 | __print_symbolic(__entry->type, XFS_ALLOC_TYPES), |
1217 | __print_symbolic(__entry->type, XFS_ALLOC_TYPES), \ | 1259 | __print_symbolic(__entry->otype, XFS_ALLOC_TYPES), |
1218 | __print_symbolic(__entry->otype, XFS_ALLOC_TYPES), \ | 1260 | __entry->wasdel, |
1219 | __entry->wasdel, \ | 1261 | __entry->wasfromfl, |
1220 | __entry->wasfromfl, \ | 1262 | __entry->isfl, |
1221 | __entry->isfl, \ | 1263 | __entry->userdata, |
1222 | __entry->userdata, \ | 1264 | __entry->firstblock) |
1223 | __entry->firstblock) \ | ||
1224 | ) | 1265 | ) |
1225 | 1266 | ||
1267 | #define DEFINE_ALLOC_EVENT(name) \ | ||
1268 | DEFINE_EVENT(xfs_alloc_class, name, \ | ||
1269 | TP_PROTO(struct xfs_alloc_arg *args), \ | ||
1270 | TP_ARGS(args)) | ||
1226 | DEFINE_ALLOC_EVENT(xfs_alloc_exact_done); | 1271 | DEFINE_ALLOC_EVENT(xfs_alloc_exact_done); |
1227 | DEFINE_ALLOC_EVENT(xfs_alloc_exact_error); | 1272 | DEFINE_ALLOC_EVENT(xfs_alloc_exact_error); |
1228 | DEFINE_ALLOC_EVENT(xfs_alloc_near_nominleft); | 1273 | DEFINE_ALLOC_EVENT(xfs_alloc_near_nominleft); |
@@ -1245,92 +1290,100 @@ DEFINE_ALLOC_EVENT(xfs_alloc_vextent_noagbp); | |||
1245 | DEFINE_ALLOC_EVENT(xfs_alloc_vextent_loopfailed); | 1290 | DEFINE_ALLOC_EVENT(xfs_alloc_vextent_loopfailed); |
1246 | DEFINE_ALLOC_EVENT(xfs_alloc_vextent_allfailed); | 1291 | DEFINE_ALLOC_EVENT(xfs_alloc_vextent_allfailed); |
1247 | 1292 | ||
1248 | #define DEFINE_DIR2_TRACE(tname) \ | 1293 | DECLARE_EVENT_CLASS(xfs_dir2_class, |
1249 | TRACE_EVENT(tname, \ | 1294 | TP_PROTO(struct xfs_da_args *args), |
1295 | TP_ARGS(args), | ||
1296 | TP_STRUCT__entry( | ||
1297 | __field(dev_t, dev) | ||
1298 | __field(xfs_ino_t, ino) | ||
1299 | __dynamic_array(char, name, args->namelen) | ||
1300 | __field(int, namelen) | ||
1301 | __field(xfs_dahash_t, hashval) | ||
1302 | __field(xfs_ino_t, inumber) | ||
1303 | __field(int, op_flags) | ||
1304 | ), | ||
1305 | TP_fast_assign( | ||
1306 | __entry->dev = VFS_I(args->dp)->i_sb->s_dev; | ||
1307 | __entry->ino = args->dp->i_ino; | ||
1308 | if (args->namelen) | ||
1309 | memcpy(__get_str(name), args->name, args->namelen); | ||
1310 | __entry->namelen = args->namelen; | ||
1311 | __entry->hashval = args->hashval; | ||
1312 | __entry->inumber = args->inumber; | ||
1313 | __entry->op_flags = args->op_flags; | ||
1314 | ), | ||
1315 | TP_printk("dev %d:%d ino 0x%llx name %.*s namelen %d hashval 0x%x " | ||
1316 | "inumber 0x%llx op_flags %s", | ||
1317 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
1318 | __entry->ino, | ||
1319 | __entry->namelen, | ||
1320 | __entry->namelen ? __get_str(name) : NULL, | ||
1321 | __entry->namelen, | ||
1322 | __entry->hashval, | ||
1323 | __entry->inumber, | ||
1324 | __print_flags(__entry->op_flags, "|", XFS_DA_OP_FLAGS)) | ||
1325 | ) | ||
1326 | |||
1327 | #define DEFINE_DIR2_EVENT(name) \ | ||
1328 | DEFINE_EVENT(xfs_dir2_class, name, \ | ||
1250 | TP_PROTO(struct xfs_da_args *args), \ | 1329 | TP_PROTO(struct xfs_da_args *args), \ |
1251 | TP_ARGS(args), \ | 1330 | TP_ARGS(args)) |
1252 | TP_STRUCT__entry( \ | 1331 | DEFINE_DIR2_EVENT(xfs_dir2_sf_addname); |
1253 | __field(dev_t, dev) \ | 1332 | DEFINE_DIR2_EVENT(xfs_dir2_sf_create); |
1254 | __field(xfs_ino_t, ino) \ | 1333 | DEFINE_DIR2_EVENT(xfs_dir2_sf_lookup); |
1255 | __dynamic_array(char, name, args->namelen) \ | 1334 | DEFINE_DIR2_EVENT(xfs_dir2_sf_replace); |
1256 | __field(int, namelen) \ | 1335 | DEFINE_DIR2_EVENT(xfs_dir2_sf_removename); |
1257 | __field(xfs_dahash_t, hashval) \ | 1336 | DEFINE_DIR2_EVENT(xfs_dir2_sf_toino4); |
1258 | __field(xfs_ino_t, inumber) \ | 1337 | DEFINE_DIR2_EVENT(xfs_dir2_sf_toino8); |
1259 | __field(int, op_flags) \ | 1338 | DEFINE_DIR2_EVENT(xfs_dir2_sf_to_block); |
1260 | ), \ | 1339 | DEFINE_DIR2_EVENT(xfs_dir2_block_addname); |
1261 | TP_fast_assign( \ | 1340 | DEFINE_DIR2_EVENT(xfs_dir2_block_lookup); |
1262 | __entry->dev = VFS_I(args->dp)->i_sb->s_dev; \ | 1341 | DEFINE_DIR2_EVENT(xfs_dir2_block_replace); |
1263 | __entry->ino = args->dp->i_ino; \ | 1342 | DEFINE_DIR2_EVENT(xfs_dir2_block_removename); |
1264 | if (args->namelen) \ | 1343 | DEFINE_DIR2_EVENT(xfs_dir2_block_to_sf); |
1265 | memcpy(__get_str(name), args->name, args->namelen); \ | 1344 | DEFINE_DIR2_EVENT(xfs_dir2_block_to_leaf); |
1266 | __entry->namelen = args->namelen; \ | 1345 | DEFINE_DIR2_EVENT(xfs_dir2_leaf_addname); |
1267 | __entry->hashval = args->hashval; \ | 1346 | DEFINE_DIR2_EVENT(xfs_dir2_leaf_lookup); |
1268 | __entry->inumber = args->inumber; \ | 1347 | DEFINE_DIR2_EVENT(xfs_dir2_leaf_replace); |
1269 | __entry->op_flags = args->op_flags; \ | 1348 | DEFINE_DIR2_EVENT(xfs_dir2_leaf_removename); |
1270 | ), \ | 1349 | DEFINE_DIR2_EVENT(xfs_dir2_leaf_to_block); |
1271 | TP_printk("dev %d:%d ino 0x%llx name %.*s namelen %d hashval 0x%x " \ | 1350 | DEFINE_DIR2_EVENT(xfs_dir2_leaf_to_node); |
1272 | "inumber 0x%llx op_flags %s", \ | 1351 | DEFINE_DIR2_EVENT(xfs_dir2_node_addname); |
1273 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | 1352 | DEFINE_DIR2_EVENT(xfs_dir2_node_lookup); |
1274 | __entry->ino, \ | 1353 | DEFINE_DIR2_EVENT(xfs_dir2_node_replace); |
1275 | __entry->namelen, \ | 1354 | DEFINE_DIR2_EVENT(xfs_dir2_node_removename); |
1276 | __entry->namelen ? __get_str(name) : NULL, \ | 1355 | DEFINE_DIR2_EVENT(xfs_dir2_node_to_leaf); |
1277 | __entry->namelen, \ | 1356 | |
1278 | __entry->hashval, \ | 1357 | DECLARE_EVENT_CLASS(xfs_dir2_space_class, |
1279 | __entry->inumber, \ | 1358 | TP_PROTO(struct xfs_da_args *args, int idx), |
1280 | __print_flags(__entry->op_flags, "|", XFS_DA_OP_FLAGS)) \ | 1359 | TP_ARGS(args, idx), |
1360 | TP_STRUCT__entry( | ||
1361 | __field(dev_t, dev) | ||
1362 | __field(xfs_ino_t, ino) | ||
1363 | __field(int, op_flags) | ||
1364 | __field(int, idx) | ||
1365 | ), | ||
1366 | TP_fast_assign( | ||
1367 | __entry->dev = VFS_I(args->dp)->i_sb->s_dev; | ||
1368 | __entry->ino = args->dp->i_ino; | ||
1369 | __entry->op_flags = args->op_flags; | ||
1370 | __entry->idx = idx; | ||
1371 | ), | ||
1372 | TP_printk("dev %d:%d ino 0x%llx op_flags %s index %d", | ||
1373 | MAJOR(__entry->dev), MINOR(__entry->dev), | ||
1374 | __entry->ino, | ||
1375 | __print_flags(__entry->op_flags, "|", XFS_DA_OP_FLAGS), | ||
1376 | __entry->idx) | ||
1281 | ) | 1377 | ) |
1282 | DEFINE_DIR2_TRACE(xfs_dir2_sf_addname); | ||
1283 | DEFINE_DIR2_TRACE(xfs_dir2_sf_create); | ||
1284 | DEFINE_DIR2_TRACE(xfs_dir2_sf_lookup); | ||
1285 | DEFINE_DIR2_TRACE(xfs_dir2_sf_replace); | ||
1286 | DEFINE_DIR2_TRACE(xfs_dir2_sf_removename); | ||
1287 | DEFINE_DIR2_TRACE(xfs_dir2_sf_toino4); | ||
1288 | DEFINE_DIR2_TRACE(xfs_dir2_sf_toino8); | ||
1289 | DEFINE_DIR2_TRACE(xfs_dir2_sf_to_block); | ||
1290 | DEFINE_DIR2_TRACE(xfs_dir2_block_addname); | ||
1291 | DEFINE_DIR2_TRACE(xfs_dir2_block_lookup); | ||
1292 | DEFINE_DIR2_TRACE(xfs_dir2_block_replace); | ||
1293 | DEFINE_DIR2_TRACE(xfs_dir2_block_removename); | ||
1294 | DEFINE_DIR2_TRACE(xfs_dir2_block_to_sf); | ||
1295 | DEFINE_DIR2_TRACE(xfs_dir2_block_to_leaf); | ||
1296 | DEFINE_DIR2_TRACE(xfs_dir2_leaf_addname); | ||
1297 | DEFINE_DIR2_TRACE(xfs_dir2_leaf_lookup); | ||
1298 | DEFINE_DIR2_TRACE(xfs_dir2_leaf_replace); | ||
1299 | DEFINE_DIR2_TRACE(xfs_dir2_leaf_removename); | ||
1300 | DEFINE_DIR2_TRACE(xfs_dir2_leaf_to_block); | ||
1301 | DEFINE_DIR2_TRACE(xfs_dir2_leaf_to_node); | ||
1302 | DEFINE_DIR2_TRACE(xfs_dir2_node_addname); | ||
1303 | DEFINE_DIR2_TRACE(xfs_dir2_node_lookup); | ||
1304 | DEFINE_DIR2_TRACE(xfs_dir2_node_replace); | ||
1305 | DEFINE_DIR2_TRACE(xfs_dir2_node_removename); | ||
1306 | DEFINE_DIR2_TRACE(xfs_dir2_node_to_leaf); | ||
1307 | 1378 | ||
1308 | #define DEFINE_DIR2_SPACE_TRACE(tname) \ | 1379 | #define DEFINE_DIR2_SPACE_EVENT(name) \ |
1309 | TRACE_EVENT(tname, \ | 1380 | DEFINE_EVENT(xfs_dir2_space_class, name, \ |
1310 | TP_PROTO(struct xfs_da_args *args, int idx), \ | 1381 | TP_PROTO(struct xfs_da_args *args, int idx), \ |
1311 | TP_ARGS(args, idx), \ | 1382 | TP_ARGS(args, idx)) |
1312 | TP_STRUCT__entry( \ | 1383 | DEFINE_DIR2_SPACE_EVENT(xfs_dir2_leafn_add); |
1313 | __field(dev_t, dev) \ | 1384 | DEFINE_DIR2_SPACE_EVENT(xfs_dir2_leafn_remove); |
1314 | __field(xfs_ino_t, ino) \ | 1385 | DEFINE_DIR2_SPACE_EVENT(xfs_dir2_grow_inode); |
1315 | __field(int, op_flags) \ | 1386 | DEFINE_DIR2_SPACE_EVENT(xfs_dir2_shrink_inode); |
1316 | __field(int, idx) \ | ||
1317 | ), \ | ||
1318 | TP_fast_assign( \ | ||
1319 | __entry->dev = VFS_I(args->dp)->i_sb->s_dev; \ | ||
1320 | __entry->ino = args->dp->i_ino; \ | ||
1321 | __entry->op_flags = args->op_flags; \ | ||
1322 | __entry->idx = idx; \ | ||
1323 | ), \ | ||
1324 | TP_printk("dev %d:%d ino 0x%llx op_flags %s index %d", \ | ||
1325 | MAJOR(__entry->dev), MINOR(__entry->dev), \ | ||
1326 | __entry->ino, \ | ||
1327 | __print_flags(__entry->op_flags, "|", XFS_DA_OP_FLAGS), \ | ||
1328 | __entry->idx) \ | ||
1329 | ) | ||
1330 | DEFINE_DIR2_SPACE_TRACE(xfs_dir2_leafn_add); | ||
1331 | DEFINE_DIR2_SPACE_TRACE(xfs_dir2_leafn_remove); | ||
1332 | DEFINE_DIR2_SPACE_TRACE(xfs_dir2_grow_inode); | ||
1333 | DEFINE_DIR2_SPACE_TRACE(xfs_dir2_shrink_inode); | ||
1334 | 1387 | ||
1335 | TRACE_EVENT(xfs_dir2_leafn_moveents, | 1388 | TRACE_EVENT(xfs_dir2_leafn_moveents, |
1336 | TP_PROTO(struct xfs_da_args *args, int src_idx, int dst_idx, int count), | 1389 | TP_PROTO(struct xfs_da_args *args, int src_idx, int dst_idx, int count), |
diff --git a/fs/xfs/xfs_alloc.c b/fs/xfs/xfs_alloc.c index a1c65fc6d9c4..275b1f4f9430 100644 --- a/fs/xfs/xfs_alloc.c +++ b/fs/xfs/xfs_alloc.c | |||
@@ -2563,43 +2563,41 @@ xfs_alloc_search_busy(xfs_trans_t *tp, | |||
2563 | xfs_mount_t *mp; | 2563 | xfs_mount_t *mp; |
2564 | xfs_perag_busy_t *bsy; | 2564 | xfs_perag_busy_t *bsy; |
2565 | xfs_agblock_t uend, bend; | 2565 | xfs_agblock_t uend, bend; |
2566 | xfs_lsn_t lsn; | 2566 | xfs_lsn_t lsn = 0; |
2567 | int cnt; | 2567 | int cnt; |
2568 | 2568 | ||
2569 | mp = tp->t_mountp; | 2569 | mp = tp->t_mountp; |
2570 | 2570 | ||
2571 | spin_lock(&mp->m_perag[agno].pagb_lock); | 2571 | spin_lock(&mp->m_perag[agno].pagb_lock); |
2572 | cnt = mp->m_perag[agno].pagb_count; | ||
2573 | 2572 | ||
2574 | uend = bno + len - 1; | 2573 | uend = bno + len - 1; |
2575 | 2574 | ||
2576 | /* search pagb_list for this slot, skipping open slots */ | 2575 | /* |
2577 | for (bsy = mp->m_perag[agno].pagb_list; cnt; bsy++) { | 2576 | * search pagb_list for this slot, skipping open slots. We have to |
2577 | * search the entire array as there may be multiple overlaps and | ||
2578 | * we have to get the most recent LSN for the log force to push out | ||
2579 | * all the transactions that span the range. | ||
2580 | */ | ||
2581 | for (cnt = 0; cnt < mp->m_perag[agno].pagb_count; cnt++) { | ||
2582 | bsy = &mp->m_perag[agno].pagb_list[cnt]; | ||
2583 | if (!bsy->busy_tp) | ||
2584 | continue; | ||
2578 | 2585 | ||
2579 | /* | 2586 | bend = bsy->busy_start + bsy->busy_length - 1; |
2580 | * (start1,length1) within (start2, length2) | 2587 | if (bno > bend || uend < bsy->busy_start) |
2581 | */ | 2588 | continue; |
2582 | if (bsy->busy_tp != NULL) { | ||
2583 | bend = bsy->busy_start + bsy->busy_length - 1; | ||
2584 | if ((bno > bend) || (uend < bsy->busy_start)) { | ||
2585 | cnt--; | ||
2586 | } else { | ||
2587 | break; | ||
2588 | } | ||
2589 | } | ||
2590 | } | ||
2591 | 2589 | ||
2592 | trace_xfs_alloc_busysearch(mp, agno, bno, len, !!cnt); | 2590 | /* (start1,length1) within (start2, length2) */ |
2591 | if (XFS_LSN_CMP(bsy->busy_tp->t_commit_lsn, lsn) > 0) | ||
2592 | lsn = bsy->busy_tp->t_commit_lsn; | ||
2593 | } | ||
2594 | spin_unlock(&mp->m_perag[agno].pagb_lock); | ||
2595 | trace_xfs_alloc_busysearch(tp->t_mountp, agno, bno, len, lsn); | ||
2593 | 2596 | ||
2594 | /* | 2597 | /* |
2595 | * If a block was found, force the log through the LSN of the | 2598 | * If a block was found, force the log through the LSN of the |
2596 | * transaction that freed the block | 2599 | * transaction that freed the block |
2597 | */ | 2600 | */ |
2598 | if (cnt) { | 2601 | if (lsn) |
2599 | lsn = bsy->busy_tp->t_commit_lsn; | ||
2600 | spin_unlock(&mp->m_perag[agno].pagb_lock); | ||
2601 | xfs_log_force(mp, lsn, XFS_LOG_FORCE|XFS_LOG_SYNC); | 2602 | xfs_log_force(mp, lsn, XFS_LOG_FORCE|XFS_LOG_SYNC); |
2602 | } else { | ||
2603 | spin_unlock(&mp->m_perag[agno].pagb_lock); | ||
2604 | } | ||
2605 | } | 2603 | } |
diff --git a/fs/xfs/xfs_iget.c b/fs/xfs/xfs_iget.c index 0de36c2a46f1..fa402a6bbbcf 100644 --- a/fs/xfs/xfs_iget.c +++ b/fs/xfs/xfs_iget.c | |||
@@ -91,7 +91,7 @@ xfs_inode_alloc( | |||
91 | ip->i_new_size = 0; | 91 | ip->i_new_size = 0; |
92 | 92 | ||
93 | /* prevent anyone from using this yet */ | 93 | /* prevent anyone from using this yet */ |
94 | VFS_I(ip)->i_state = I_NEW|I_LOCK; | 94 | VFS_I(ip)->i_state = I_NEW; |
95 | 95 | ||
96 | return ip; | 96 | return ip; |
97 | } | 97 | } |
@@ -217,7 +217,7 @@ xfs_iget_cache_hit( | |||
217 | trace_xfs_iget_reclaim(ip); | 217 | trace_xfs_iget_reclaim(ip); |
218 | goto out_error; | 218 | goto out_error; |
219 | } | 219 | } |
220 | inode->i_state = I_LOCK|I_NEW; | 220 | inode->i_state = I_NEW; |
221 | } else { | 221 | } else { |
222 | /* If the VFS inode is being torn down, pause and try again. */ | 222 | /* If the VFS inode is being torn down, pause and try again. */ |
223 | if (!igrab(inode)) { | 223 | if (!igrab(inode)) { |
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index ce278b3ae7fc..391d36b0e68c 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c | |||
@@ -2841,10 +2841,14 @@ xfs_iflush( | |||
2841 | mp = ip->i_mount; | 2841 | mp = ip->i_mount; |
2842 | 2842 | ||
2843 | /* | 2843 | /* |
2844 | * If the inode isn't dirty, then just release the inode | 2844 | * If the inode isn't dirty, then just release the inode flush lock and |
2845 | * flush lock and do nothing. | 2845 | * do nothing. Treat stale inodes the same; we cannot rely on the |
2846 | * backing buffer remaining stale in cache for the remaining life of | ||
2847 | * the stale inode and so xfs_itobp() below may give us a buffer that | ||
2848 | * no longer contains inodes below. Doing this stale check here also | ||
2849 | * avoids forcing the log on pinned, stale inodes. | ||
2846 | */ | 2850 | */ |
2847 | if (xfs_inode_clean(ip)) { | 2851 | if (xfs_inode_clean(ip) || xfs_iflags_test(ip, XFS_ISTALE)) { |
2848 | xfs_ifunlock(ip); | 2852 | xfs_ifunlock(ip); |
2849 | return 0; | 2853 | return 0; |
2850 | } | 2854 | } |
diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c index 6558ffd8d140..6f268756bf36 100644 --- a/fs/xfs/xfs_vnodeops.c +++ b/fs/xfs/xfs_vnodeops.c | |||
@@ -70,7 +70,6 @@ xfs_setattr( | |||
70 | uint commit_flags=0; | 70 | uint commit_flags=0; |
71 | uid_t uid=0, iuid=0; | 71 | uid_t uid=0, iuid=0; |
72 | gid_t gid=0, igid=0; | 72 | gid_t gid=0, igid=0; |
73 | int timeflags = 0; | ||
74 | struct xfs_dquot *udqp, *gdqp, *olddquot1, *olddquot2; | 73 | struct xfs_dquot *udqp, *gdqp, *olddquot1, *olddquot2; |
75 | int need_iolock = 1; | 74 | int need_iolock = 1; |
76 | 75 | ||
@@ -135,16 +134,13 @@ xfs_setattr( | |||
135 | if (flags & XFS_ATTR_NOLOCK) | 134 | if (flags & XFS_ATTR_NOLOCK) |
136 | need_iolock = 0; | 135 | need_iolock = 0; |
137 | if (!(mask & ATTR_SIZE)) { | 136 | if (!(mask & ATTR_SIZE)) { |
138 | if ((mask != (ATTR_CTIME|ATTR_ATIME|ATTR_MTIME)) || | 137 | tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE); |
139 | (mp->m_flags & XFS_MOUNT_WSYNC)) { | 138 | commit_flags = 0; |
140 | tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE); | 139 | code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), |
141 | commit_flags = 0; | 140 | 0, 0, 0); |
142 | if ((code = xfs_trans_reserve(tp, 0, | 141 | if (code) { |
143 | XFS_ICHANGE_LOG_RES(mp), 0, | 142 | lock_flags = 0; |
144 | 0, 0))) { | 143 | goto error_return; |
145 | lock_flags = 0; | ||
146 | goto error_return; | ||
147 | } | ||
148 | } | 144 | } |
149 | } else { | 145 | } else { |
150 | if (DM_EVENT_ENABLED(ip, DM_EVENT_TRUNCATE) && | 146 | if (DM_EVENT_ENABLED(ip, DM_EVENT_TRUNCATE) && |
@@ -295,15 +291,23 @@ xfs_setattr( | |||
295 | * or we are explicitly asked to change it. This handles | 291 | * or we are explicitly asked to change it. This handles |
296 | * the semantic difference between truncate() and ftruncate() | 292 | * the semantic difference between truncate() and ftruncate() |
297 | * as implemented in the VFS. | 293 | * as implemented in the VFS. |
294 | * | ||
295 | * The regular truncate() case without ATTR_CTIME and ATTR_MTIME | ||
296 | * is a special case where we need to update the times despite | ||
297 | * not having these flags set. For all other operations the | ||
298 | * VFS set these flags explicitly if it wants a timestamp | ||
299 | * update. | ||
298 | */ | 300 | */ |
299 | if (iattr->ia_size != ip->i_size || (mask & ATTR_CTIME)) | 301 | if (iattr->ia_size != ip->i_size && |
300 | timeflags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG; | 302 | (!(mask & (ATTR_CTIME | ATTR_MTIME)))) { |
303 | iattr->ia_ctime = iattr->ia_mtime = | ||
304 | current_fs_time(inode->i_sb); | ||
305 | mask |= ATTR_CTIME | ATTR_MTIME; | ||
306 | } | ||
301 | 307 | ||
302 | if (iattr->ia_size > ip->i_size) { | 308 | if (iattr->ia_size > ip->i_size) { |
303 | ip->i_d.di_size = iattr->ia_size; | 309 | ip->i_d.di_size = iattr->ia_size; |
304 | ip->i_size = iattr->ia_size; | 310 | ip->i_size = iattr->ia_size; |
305 | if (!(flags & XFS_ATTR_DMI)) | ||
306 | xfs_ichgtime(ip, XFS_ICHGTIME_CHG); | ||
307 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); | 311 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
308 | } else if (iattr->ia_size <= ip->i_size || | 312 | } else if (iattr->ia_size <= ip->i_size || |
309 | (iattr->ia_size == 0 && ip->i_d.di_nextents)) { | 313 | (iattr->ia_size == 0 && ip->i_d.di_nextents)) { |
@@ -374,9 +378,6 @@ xfs_setattr( | |||
374 | ip->i_d.di_gid = gid; | 378 | ip->i_d.di_gid = gid; |
375 | inode->i_gid = gid; | 379 | inode->i_gid = gid; |
376 | } | 380 | } |
377 | |||
378 | xfs_trans_log_inode (tp, ip, XFS_ILOG_CORE); | ||
379 | timeflags |= XFS_ICHGTIME_CHG; | ||
380 | } | 381 | } |
381 | 382 | ||
382 | /* | 383 | /* |
@@ -393,51 +394,37 @@ xfs_setattr( | |||
393 | 394 | ||
394 | inode->i_mode &= S_IFMT; | 395 | inode->i_mode &= S_IFMT; |
395 | inode->i_mode |= mode & ~S_IFMT; | 396 | inode->i_mode |= mode & ~S_IFMT; |
396 | |||
397 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); | ||
398 | timeflags |= XFS_ICHGTIME_CHG; | ||
399 | } | 397 | } |
400 | 398 | ||
401 | /* | 399 | /* |
402 | * Change file access or modified times. | 400 | * Change file access or modified times. |
403 | */ | 401 | */ |
404 | if (mask & (ATTR_ATIME|ATTR_MTIME)) { | 402 | if (mask & ATTR_ATIME) { |
405 | if (mask & ATTR_ATIME) { | 403 | inode->i_atime = iattr->ia_atime; |
406 | inode->i_atime = iattr->ia_atime; | 404 | ip->i_d.di_atime.t_sec = iattr->ia_atime.tv_sec; |
407 | ip->i_d.di_atime.t_sec = iattr->ia_atime.tv_sec; | 405 | ip->i_d.di_atime.t_nsec = iattr->ia_atime.tv_nsec; |
408 | ip->i_d.di_atime.t_nsec = iattr->ia_atime.tv_nsec; | 406 | ip->i_update_core = 1; |
409 | ip->i_update_core = 1; | ||
410 | } | ||
411 | if (mask & ATTR_MTIME) { | ||
412 | inode->i_mtime = iattr->ia_mtime; | ||
413 | ip->i_d.di_mtime.t_sec = iattr->ia_mtime.tv_sec; | ||
414 | ip->i_d.di_mtime.t_nsec = iattr->ia_mtime.tv_nsec; | ||
415 | timeflags &= ~XFS_ICHGTIME_MOD; | ||
416 | timeflags |= XFS_ICHGTIME_CHG; | ||
417 | } | ||
418 | if (tp && (mask & (ATTR_MTIME_SET|ATTR_ATIME_SET))) | ||
419 | xfs_trans_log_inode (tp, ip, XFS_ILOG_CORE); | ||
420 | } | 407 | } |
421 | 408 | if (mask & ATTR_CTIME) { | |
422 | /* | ||
423 | * Change file inode change time only if ATTR_CTIME set | ||
424 | * AND we have been called by a DMI function. | ||
425 | */ | ||
426 | |||
427 | if ((flags & XFS_ATTR_DMI) && (mask & ATTR_CTIME)) { | ||
428 | inode->i_ctime = iattr->ia_ctime; | 409 | inode->i_ctime = iattr->ia_ctime; |
429 | ip->i_d.di_ctime.t_sec = iattr->ia_ctime.tv_sec; | 410 | ip->i_d.di_ctime.t_sec = iattr->ia_ctime.tv_sec; |
430 | ip->i_d.di_ctime.t_nsec = iattr->ia_ctime.tv_nsec; | 411 | ip->i_d.di_ctime.t_nsec = iattr->ia_ctime.tv_nsec; |
431 | ip->i_update_core = 1; | 412 | ip->i_update_core = 1; |
432 | timeflags &= ~XFS_ICHGTIME_CHG; | 413 | } |
414 | if (mask & ATTR_MTIME) { | ||
415 | inode->i_mtime = iattr->ia_mtime; | ||
416 | ip->i_d.di_mtime.t_sec = iattr->ia_mtime.tv_sec; | ||
417 | ip->i_d.di_mtime.t_nsec = iattr->ia_mtime.tv_nsec; | ||
418 | ip->i_update_core = 1; | ||
433 | } | 419 | } |
434 | 420 | ||
435 | /* | 421 | /* |
436 | * Send out timestamp changes that need to be set to the | 422 | * And finally, log the inode core if any attribute in it |
437 | * current time. Not done when called by a DMI function. | 423 | * has been changed. |
438 | */ | 424 | */ |
439 | if (timeflags && !(flags & XFS_ATTR_DMI)) | 425 | if (mask & (ATTR_UID|ATTR_GID|ATTR_MODE| |
440 | xfs_ichgtime(ip, timeflags); | 426 | ATTR_ATIME|ATTR_CTIME|ATTR_MTIME)) |
427 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); | ||
441 | 428 | ||
442 | XFS_STATS_INC(xs_ig_attrchg); | 429 | XFS_STATS_INC(xs_ig_attrchg); |
443 | 430 | ||
@@ -452,12 +439,10 @@ xfs_setattr( | |||
452 | * mix so this probably isn't worth the trouble to optimize. | 439 | * mix so this probably isn't worth the trouble to optimize. |
453 | */ | 440 | */ |
454 | code = 0; | 441 | code = 0; |
455 | if (tp) { | 442 | if (mp->m_flags & XFS_MOUNT_WSYNC) |
456 | if (mp->m_flags & XFS_MOUNT_WSYNC) | 443 | xfs_trans_set_sync(tp); |
457 | xfs_trans_set_sync(tp); | ||
458 | 444 | ||
459 | code = xfs_trans_commit(tp, commit_flags); | 445 | code = xfs_trans_commit(tp, commit_flags); |
460 | } | ||
461 | 446 | ||
462 | xfs_iunlock(ip, lock_flags); | 447 | xfs_iunlock(ip, lock_flags); |
463 | 448 | ||