aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/printk-formats.txt9
-rw-r--r--arch/alpha/oprofile/common.c22
-rw-r--r--arch/avr32/oprofile/op_model_avr32.c17
-rw-r--r--arch/mips/oprofile/common.c20
-rw-r--r--arch/powerpc/kvm/powerpc.c20
-rw-r--r--arch/powerpc/oprofile/common.c28
-rw-r--r--arch/s390/hypfs/hypfs.h13
-rw-r--r--arch/s390/hypfs/hypfs_diag.c50
-rw-r--r--arch/s390/hypfs/hypfs_vm.c65
-rw-r--r--arch/s390/hypfs/inode.c36
-rw-r--r--arch/s390/oprofile/init.c35
-rw-r--r--arch/x86/oprofile/nmi_int.c18
-rw-r--r--arch/x86/oprofile/op_model_amd.c24
-rw-r--r--drivers/dma/coh901318.c26
-rw-r--r--drivers/misc/ibmasm/ibmasmfs.c26
-rw-r--r--drivers/oprofile/oprof.h3
-rw-r--r--drivers/oprofile/oprofile_files.c26
-rw-r--r--drivers/oprofile/oprofile_perf.c16
-rw-r--r--drivers/oprofile/oprofile_stats.c24
-rw-r--r--drivers/oprofile/oprofile_stats.h3
-rw-r--r--drivers/oprofile/oprofilefs.c44
-rw-r--r--fs/block_dev.c2
-rw-r--r--fs/btrfs/file.c2
-rw-r--r--fs/cifs/file.c2
-rw-r--r--fs/dcache.c13
-rw-r--r--fs/direct-io.c126
-rw-r--r--fs/eventpoll.c31
-rw-r--r--fs/ext4/ext4.h11
-rw-r--r--fs/ext4/file.c2
-rw-r--r--fs/ext4/inode.c28
-rw-r--r--fs/ext4/page-io.c30
-rw-r--r--fs/ext4/super.c16
-rw-r--r--fs/file_table.c6
-rw-r--r--fs/inode.c2
-rw-r--r--fs/namei.c182
-rw-r--r--fs/namespace.c2
-rw-r--r--fs/nfsd/nfs4xdr.c14
-rw-r--r--fs/nilfs2/super.c26
-rw-r--r--fs/ocfs2/aops.c8
-rw-r--r--fs/open.c11
-rw-r--r--fs/super.c18
-rw-r--r--fs/xfs/xfs_aops.c28
-rw-r--r--fs/xfs/xfs_aops.h3
-rw-r--r--include/linux/buffer_head.h2
-rw-r--r--include/linux/fs.h9
-rw-r--r--include/linux/namei.h1
-rw-r--r--include/linux/oprofile.h16
-rw-r--r--kernel/module.c13
-rw-r--r--lib/vsprintf.c82
-rw-r--r--mm/filemap.c2
-rw-r--r--mm/shmem.c7
-rw-r--r--virt/kvm/eventfd.c20
52 files changed, 738 insertions, 502 deletions
diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt
index 3e8cb73ac43c..9552a3299ec9 100644
--- a/Documentation/printk-formats.txt
+++ b/Documentation/printk-formats.txt
@@ -168,6 +168,15 @@ UUID/GUID addresses:
168 Where no additional specifiers are used the default little endian 168 Where no additional specifiers are used the default little endian
169 order with lower case hex characters will be printed. 169 order with lower case hex characters will be printed.
170 170
171dentry names:
172 %pd{,2,3,4}
173 %pD{,2,3,4}
174
175 For printing dentry name; if we race with d_move(), the name might be
176 a mix of old and new ones, but it won't oops. %pd dentry is a safer
177 equivalent of %s dentry->d_name.name we used to use, %pd<n> prints
178 n last components. %pD does the same thing for struct file.
179
171struct va_format: 180struct va_format:
172 181
173 %pV 182 %pV
diff --git a/arch/alpha/oprofile/common.c b/arch/alpha/oprofile/common.c
index b8ce18f485d3..310a4ce1dccc 100644
--- a/arch/alpha/oprofile/common.c
+++ b/arch/alpha/oprofile/common.c
@@ -106,7 +106,7 @@ op_axp_stop(void)
106} 106}
107 107
108static int 108static int
109op_axp_create_files(struct super_block *sb, struct dentry *root) 109op_axp_create_files(struct dentry *root)
110{ 110{
111 int i; 111 int i;
112 112
@@ -115,23 +115,23 @@ op_axp_create_files(struct super_block *sb, struct dentry *root)
115 char buf[4]; 115 char buf[4];
116 116
117 snprintf(buf, sizeof buf, "%d", i); 117 snprintf(buf, sizeof buf, "%d", i);
118 dir = oprofilefs_mkdir(sb, root, buf); 118 dir = oprofilefs_mkdir(root, buf);
119 119
120 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); 120 oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
121 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); 121 oprofilefs_create_ulong(dir, "event", &ctr[i].event);
122 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); 122 oprofilefs_create_ulong(dir, "count", &ctr[i].count);
123 /* Dummies. */ 123 /* Dummies. */
124 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); 124 oprofilefs_create_ulong(dir, "kernel", &ctr[i].kernel);
125 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); 125 oprofilefs_create_ulong(dir, "user", &ctr[i].user);
126 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); 126 oprofilefs_create_ulong(dir, "unit_mask", &ctr[i].unit_mask);
127 } 127 }
128 128
129 if (model->can_set_proc_mode) { 129 if (model->can_set_proc_mode) {
130 oprofilefs_create_ulong(sb, root, "enable_pal", 130 oprofilefs_create_ulong(root, "enable_pal",
131 &sys.enable_pal); 131 &sys.enable_pal);
132 oprofilefs_create_ulong(sb, root, "enable_kernel", 132 oprofilefs_create_ulong(root, "enable_kernel",
133 &sys.enable_kernel); 133 &sys.enable_kernel);
134 oprofilefs_create_ulong(sb, root, "enable_user", 134 oprofilefs_create_ulong(root, "enable_user",
135 &sys.enable_user); 135 &sys.enable_user);
136 } 136 }
137 137
diff --git a/arch/avr32/oprofile/op_model_avr32.c b/arch/avr32/oprofile/op_model_avr32.c
index f74b7809e089..08308be2c02c 100644
--- a/arch/avr32/oprofile/op_model_avr32.c
+++ b/arch/avr32/oprofile/op_model_avr32.c
@@ -97,8 +97,7 @@ static irqreturn_t avr32_perf_counter_interrupt(int irq, void *dev_id)
97 return IRQ_HANDLED; 97 return IRQ_HANDLED;
98} 98}
99 99
100static int avr32_perf_counter_create_files(struct super_block *sb, 100static int avr32_perf_counter_create_files(struct dentry *root)
101 struct dentry *root)
102{ 101{
103 struct dentry *dir; 102 struct dentry *dir;
104 unsigned int i; 103 unsigned int i;
@@ -106,21 +105,21 @@ static int avr32_perf_counter_create_files(struct super_block *sb,
106 105
107 for (i = 0; i < NR_counter; i++) { 106 for (i = 0; i < NR_counter; i++) {
108 snprintf(filename, sizeof(filename), "%u", i); 107 snprintf(filename, sizeof(filename), "%u", i);
109 dir = oprofilefs_mkdir(sb, root, filename); 108 dir = oprofilefs_mkdir(root, filename);
110 109
111 oprofilefs_create_ulong(sb, dir, "enabled", 110 oprofilefs_create_ulong(dir, "enabled",
112 &counter[i].enabled); 111 &counter[i].enabled);
113 oprofilefs_create_ulong(sb, dir, "event", 112 oprofilefs_create_ulong(dir, "event",
114 &counter[i].event); 113 &counter[i].event);
115 oprofilefs_create_ulong(sb, dir, "count", 114 oprofilefs_create_ulong(dir, "count",
116 &counter[i].count); 115 &counter[i].count);
117 116
118 /* Dummy entries */ 117 /* Dummy entries */
119 oprofilefs_create_ulong(sb, dir, "kernel", 118 oprofilefs_create_ulong(dir, "kernel",
120 &counter[i].kernel); 119 &counter[i].kernel);
121 oprofilefs_create_ulong(sb, dir, "user", 120 oprofilefs_create_ulong(dir, "user",
122 &counter[i].user); 121 &counter[i].user);
123 oprofilefs_create_ulong(sb, dir, "unit_mask", 122 oprofilefs_create_ulong(dir, "unit_mask",
124 &counter[i].unit_mask); 123 &counter[i].unit_mask);
125 } 124 }
126 125
diff --git a/arch/mips/oprofile/common.c b/arch/mips/oprofile/common.c
index af763e838fdd..5e5424753b56 100644
--- a/arch/mips/oprofile/common.c
+++ b/arch/mips/oprofile/common.c
@@ -33,7 +33,7 @@ static int op_mips_setup(void)
33 return 0; 33 return 0;
34} 34}
35 35
36static int op_mips_create_files(struct super_block *sb, struct dentry *root) 36static int op_mips_create_files(struct dentry *root)
37{ 37{
38 int i; 38 int i;
39 39
@@ -42,16 +42,16 @@ static int op_mips_create_files(struct super_block *sb, struct dentry *root)
42 char buf[4]; 42 char buf[4];
43 43
44 snprintf(buf, sizeof buf, "%d", i); 44 snprintf(buf, sizeof buf, "%d", i);
45 dir = oprofilefs_mkdir(sb, root, buf); 45 dir = oprofilefs_mkdir(root, buf);
46 46
47 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); 47 oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
48 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); 48 oprofilefs_create_ulong(dir, "event", &ctr[i].event);
49 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); 49 oprofilefs_create_ulong(dir, "count", &ctr[i].count);
50 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); 50 oprofilefs_create_ulong(dir, "kernel", &ctr[i].kernel);
51 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); 51 oprofilefs_create_ulong(dir, "user", &ctr[i].user);
52 oprofilefs_create_ulong(sb, dir, "exl", &ctr[i].exl); 52 oprofilefs_create_ulong(dir, "exl", &ctr[i].exl);
53 /* Dummy. */ 53 /* Dummy. */
54 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); 54 oprofilefs_create_ulong(dir, "unit_mask", &ctr[i].unit_mask);
55 } 55 }
56 56
57 return 0; 57 return 0;
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index f55e14cd1762..07c0106fab76 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -825,39 +825,39 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
825#endif 825#endif
826#ifdef CONFIG_KVM_MPIC 826#ifdef CONFIG_KVM_MPIC
827 case KVM_CAP_IRQ_MPIC: { 827 case KVM_CAP_IRQ_MPIC: {
828 struct file *filp; 828 struct fd f;
829 struct kvm_device *dev; 829 struct kvm_device *dev;
830 830
831 r = -EBADF; 831 r = -EBADF;
832 filp = fget(cap->args[0]); 832 f = fdget(cap->args[0]);
833 if (!filp) 833 if (!f.file)
834 break; 834 break;
835 835
836 r = -EPERM; 836 r = -EPERM;
837 dev = kvm_device_from_filp(filp); 837 dev = kvm_device_from_filp(f.file);
838 if (dev) 838 if (dev)
839 r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]); 839 r = kvmppc_mpic_connect_vcpu(dev, vcpu, cap->args[1]);
840 840
841 fput(filp); 841 fdput(f);
842 break; 842 break;
843 } 843 }
844#endif 844#endif
845#ifdef CONFIG_KVM_XICS 845#ifdef CONFIG_KVM_XICS
846 case KVM_CAP_IRQ_XICS: { 846 case KVM_CAP_IRQ_XICS: {
847 struct file *filp; 847 struct fd f;
848 struct kvm_device *dev; 848 struct kvm_device *dev;
849 849
850 r = -EBADF; 850 r = -EBADF;
851 filp = fget(cap->args[0]); 851 f = fdget(cap->args[0]);
852 if (!filp) 852 if (!f.file)
853 break; 853 break;
854 854
855 r = -EPERM; 855 r = -EPERM;
856 dev = kvm_device_from_filp(filp); 856 dev = kvm_device_from_filp(f.file);
857 if (dev) 857 if (dev)
858 r = kvmppc_xics_connect_vcpu(dev, vcpu, cap->args[1]); 858 r = kvmppc_xics_connect_vcpu(dev, vcpu, cap->args[1]);
859 859
860 fput(filp); 860 fdput(f);
861 break; 861 break;
862 } 862 }
863#endif /* CONFIG_KVM_XICS */ 863#endif /* CONFIG_KVM_XICS */
diff --git a/arch/powerpc/oprofile/common.c b/arch/powerpc/oprofile/common.c
index 4f51025f5b00..c77348c5d463 100644
--- a/arch/powerpc/oprofile/common.c
+++ b/arch/powerpc/oprofile/common.c
@@ -119,7 +119,7 @@ static void op_powerpc_stop(void)
119 model->global_stop(); 119 model->global_stop();
120} 120}
121 121
122static int op_powerpc_create_files(struct super_block *sb, struct dentry *root) 122static int op_powerpc_create_files(struct dentry *root)
123{ 123{
124 int i; 124 int i;
125 125
@@ -128,9 +128,9 @@ static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
128 * There is one mmcr0, mmcr1 and mmcra for setting the events for 128 * There is one mmcr0, mmcr1 and mmcra for setting the events for
129 * all of the counters. 129 * all of the counters.
130 */ 130 */
131 oprofilefs_create_ulong(sb, root, "mmcr0", &sys.mmcr0); 131 oprofilefs_create_ulong(root, "mmcr0", &sys.mmcr0);
132 oprofilefs_create_ulong(sb, root, "mmcr1", &sys.mmcr1); 132 oprofilefs_create_ulong(root, "mmcr1", &sys.mmcr1);
133 oprofilefs_create_ulong(sb, root, "mmcra", &sys.mmcra); 133 oprofilefs_create_ulong(root, "mmcra", &sys.mmcra);
134#ifdef CONFIG_OPROFILE_CELL 134#ifdef CONFIG_OPROFILE_CELL
135 /* create a file the user tool can check to see what level of profiling 135 /* create a file the user tool can check to see what level of profiling
136 * support exits with this kernel. Initialize bit mask to indicate 136 * support exits with this kernel. Initialize bit mask to indicate
@@ -142,7 +142,7 @@ static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
142 * If the file does not exist, then the kernel only supports SPU 142 * If the file does not exist, then the kernel only supports SPU
143 * cycle profiling, PPU event and cycle profiling. 143 * cycle profiling, PPU event and cycle profiling.
144 */ 144 */
145 oprofilefs_create_ulong(sb, root, "cell_support", &sys.cell_support); 145 oprofilefs_create_ulong(root, "cell_support", &sys.cell_support);
146 sys.cell_support = 0x1; /* Note, the user OProfile tool must check 146 sys.cell_support = 0x1; /* Note, the user OProfile tool must check
147 * that this bit is set before attempting to 147 * that this bit is set before attempting to
148 * user SPU event profiling. Older kernels 148 * user SPU event profiling. Older kernels
@@ -160,11 +160,11 @@ static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
160 char buf[4]; 160 char buf[4];
161 161
162 snprintf(buf, sizeof buf, "%d", i); 162 snprintf(buf, sizeof buf, "%d", i);
163 dir = oprofilefs_mkdir(sb, root, buf); 163 dir = oprofilefs_mkdir(root, buf);
164 164
165 oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); 165 oprofilefs_create_ulong(dir, "enabled", &ctr[i].enabled);
166 oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); 166 oprofilefs_create_ulong(dir, "event", &ctr[i].event);
167 oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); 167 oprofilefs_create_ulong(dir, "count", &ctr[i].count);
168 168
169 /* 169 /*
170 * Classic PowerPC doesn't support per-counter 170 * Classic PowerPC doesn't support per-counter
@@ -173,14 +173,14 @@ static int op_powerpc_create_files(struct super_block *sb, struct dentry *root)
173 * Book-E style performance monitors, we do 173 * Book-E style performance monitors, we do
174 * support them. 174 * support them.
175 */ 175 */
176 oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); 176 oprofilefs_create_ulong(dir, "kernel", &ctr[i].kernel);
177 oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); 177 oprofilefs_create_ulong(dir, "user", &ctr[i].user);
178 178
179 oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); 179 oprofilefs_create_ulong(dir, "unit_mask", &ctr[i].unit_mask);
180 } 180 }
181 181
182 oprofilefs_create_ulong(sb, root, "enable_kernel", &sys.enable_kernel); 182 oprofilefs_create_ulong(root, "enable_kernel", &sys.enable_kernel);
183 oprofilefs_create_ulong(sb, root, "enable_user", &sys.enable_user); 183 oprofilefs_create_ulong(root, "enable_user", &sys.enable_user);
184 184
185 /* Default to tracing both kernel and user */ 185 /* Default to tracing both kernel and user */
186 sys.enable_kernel = 1; 186 sys.enable_kernel = 1;
diff --git a/arch/s390/hypfs/hypfs.h b/arch/s390/hypfs/hypfs.h
index f41e0ef7fdf9..79f2ac55253f 100644
--- a/arch/s390/hypfs/hypfs.h
+++ b/arch/s390/hypfs/hypfs.h
@@ -18,26 +18,23 @@
18#define UPDATE_FILE_MODE 0220 18#define UPDATE_FILE_MODE 0220
19#define DIR_MODE 0550 19#define DIR_MODE 0550
20 20
21extern struct dentry *hypfs_mkdir(struct super_block *sb, struct dentry *parent, 21extern struct dentry *hypfs_mkdir(struct dentry *parent, const char *name);
22 const char *name);
23 22
24extern struct dentry *hypfs_create_u64(struct super_block *sb, 23extern struct dentry *hypfs_create_u64(struct dentry *dir, const char *name,
25 struct dentry *dir, const char *name,
26 __u64 value); 24 __u64 value);
27 25
28extern struct dentry *hypfs_create_str(struct super_block *sb, 26extern struct dentry *hypfs_create_str(struct dentry *dir, const char *name,
29 struct dentry *dir, const char *name,
30 char *string); 27 char *string);
31 28
32/* LPAR Hypervisor */ 29/* LPAR Hypervisor */
33extern int hypfs_diag_init(void); 30extern int hypfs_diag_init(void);
34extern void hypfs_diag_exit(void); 31extern void hypfs_diag_exit(void);
35extern int hypfs_diag_create_files(struct super_block *sb, struct dentry *root); 32extern int hypfs_diag_create_files(struct dentry *root);
36 33
37/* VM Hypervisor */ 34/* VM Hypervisor */
38extern int hypfs_vm_init(void); 35extern int hypfs_vm_init(void);
39extern void hypfs_vm_exit(void); 36extern void hypfs_vm_exit(void);
40extern int hypfs_vm_create_files(struct super_block *sb, struct dentry *root); 37extern int hypfs_vm_create_files(struct dentry *root);
41 38
42/* debugfs interface */ 39/* debugfs interface */
43struct hypfs_dbfs_file; 40struct hypfs_dbfs_file;
diff --git a/arch/s390/hypfs/hypfs_diag.c b/arch/s390/hypfs/hypfs_diag.c
index 138893e5f736..5eeffeefae06 100644
--- a/arch/s390/hypfs/hypfs_diag.c
+++ b/arch/s390/hypfs/hypfs_diag.c
@@ -623,8 +623,7 @@ void hypfs_diag_exit(void)
623 * ******************************************* 623 * *******************************************
624 */ 624 */
625 625
626static int hypfs_create_cpu_files(struct super_block *sb, 626static int hypfs_create_cpu_files(struct dentry *cpus_dir, void *cpu_info)
627 struct dentry *cpus_dir, void *cpu_info)
628{ 627{
629 struct dentry *cpu_dir; 628 struct dentry *cpu_dir;
630 char buffer[TMP_SIZE]; 629 char buffer[TMP_SIZE];
@@ -632,30 +631,29 @@ static int hypfs_create_cpu_files(struct super_block *sb,
632 631
633 snprintf(buffer, TMP_SIZE, "%d", cpu_info__cpu_addr(diag204_info_type, 632 snprintf(buffer, TMP_SIZE, "%d", cpu_info__cpu_addr(diag204_info_type,
634 cpu_info)); 633 cpu_info));
635 cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer); 634 cpu_dir = hypfs_mkdir(cpus_dir, buffer);
636 rc = hypfs_create_u64(sb, cpu_dir, "mgmtime", 635 rc = hypfs_create_u64(cpu_dir, "mgmtime",
637 cpu_info__acc_time(diag204_info_type, cpu_info) - 636 cpu_info__acc_time(diag204_info_type, cpu_info) -
638 cpu_info__lp_time(diag204_info_type, cpu_info)); 637 cpu_info__lp_time(diag204_info_type, cpu_info));
639 if (IS_ERR(rc)) 638 if (IS_ERR(rc))
640 return PTR_ERR(rc); 639 return PTR_ERR(rc);
641 rc = hypfs_create_u64(sb, cpu_dir, "cputime", 640 rc = hypfs_create_u64(cpu_dir, "cputime",
642 cpu_info__lp_time(diag204_info_type, cpu_info)); 641 cpu_info__lp_time(diag204_info_type, cpu_info));
643 if (IS_ERR(rc)) 642 if (IS_ERR(rc))
644 return PTR_ERR(rc); 643 return PTR_ERR(rc);
645 if (diag204_info_type == INFO_EXT) { 644 if (diag204_info_type == INFO_EXT) {
646 rc = hypfs_create_u64(sb, cpu_dir, "onlinetime", 645 rc = hypfs_create_u64(cpu_dir, "onlinetime",
647 cpu_info__online_time(diag204_info_type, 646 cpu_info__online_time(diag204_info_type,
648 cpu_info)); 647 cpu_info));
649 if (IS_ERR(rc)) 648 if (IS_ERR(rc))
650 return PTR_ERR(rc); 649 return PTR_ERR(rc);
651 } 650 }
652 diag224_idx2name(cpu_info__ctidx(diag204_info_type, cpu_info), buffer); 651 diag224_idx2name(cpu_info__ctidx(diag204_info_type, cpu_info), buffer);
653 rc = hypfs_create_str(sb, cpu_dir, "type", buffer); 652 rc = hypfs_create_str(cpu_dir, "type", buffer);
654 return PTR_RET(rc); 653 return PTR_RET(rc);
655} 654}
656 655
657static void *hypfs_create_lpar_files(struct super_block *sb, 656static void *hypfs_create_lpar_files(struct dentry *systems_dir, void *part_hdr)
658 struct dentry *systems_dir, void *part_hdr)
659{ 657{
660 struct dentry *cpus_dir; 658 struct dentry *cpus_dir;
661 struct dentry *lpar_dir; 659 struct dentry *lpar_dir;
@@ -665,16 +663,16 @@ static void *hypfs_create_lpar_files(struct super_block *sb,
665 663
666 part_hdr__part_name(diag204_info_type, part_hdr, lpar_name); 664 part_hdr__part_name(diag204_info_type, part_hdr, lpar_name);
667 lpar_name[LPAR_NAME_LEN] = 0; 665 lpar_name[LPAR_NAME_LEN] = 0;
668 lpar_dir = hypfs_mkdir(sb, systems_dir, lpar_name); 666 lpar_dir = hypfs_mkdir(systems_dir, lpar_name);
669 if (IS_ERR(lpar_dir)) 667 if (IS_ERR(lpar_dir))
670 return lpar_dir; 668 return lpar_dir;
671 cpus_dir = hypfs_mkdir(sb, lpar_dir, "cpus"); 669 cpus_dir = hypfs_mkdir(lpar_dir, "cpus");
672 if (IS_ERR(cpus_dir)) 670 if (IS_ERR(cpus_dir))
673 return cpus_dir; 671 return cpus_dir;
674 cpu_info = part_hdr + part_hdr__size(diag204_info_type); 672 cpu_info = part_hdr + part_hdr__size(diag204_info_type);
675 for (i = 0; i < part_hdr__rcpus(diag204_info_type, part_hdr); i++) { 673 for (i = 0; i < part_hdr__rcpus(diag204_info_type, part_hdr); i++) {
676 int rc; 674 int rc;
677 rc = hypfs_create_cpu_files(sb, cpus_dir, cpu_info); 675 rc = hypfs_create_cpu_files(cpus_dir, cpu_info);
678 if (rc) 676 if (rc)
679 return ERR_PTR(rc); 677 return ERR_PTR(rc);
680 cpu_info += cpu_info__size(diag204_info_type); 678 cpu_info += cpu_info__size(diag204_info_type);
@@ -682,8 +680,7 @@ static void *hypfs_create_lpar_files(struct super_block *sb,
682 return cpu_info; 680 return cpu_info;
683} 681}
684 682
685static int hypfs_create_phys_cpu_files(struct super_block *sb, 683static int hypfs_create_phys_cpu_files(struct dentry *cpus_dir, void *cpu_info)
686 struct dentry *cpus_dir, void *cpu_info)
687{ 684{
688 struct dentry *cpu_dir; 685 struct dentry *cpu_dir;
689 char buffer[TMP_SIZE]; 686 char buffer[TMP_SIZE];
@@ -691,32 +688,31 @@ static int hypfs_create_phys_cpu_files(struct super_block *sb,
691 688
692 snprintf(buffer, TMP_SIZE, "%i", phys_cpu__cpu_addr(diag204_info_type, 689 snprintf(buffer, TMP_SIZE, "%i", phys_cpu__cpu_addr(diag204_info_type,
693 cpu_info)); 690 cpu_info));
694 cpu_dir = hypfs_mkdir(sb, cpus_dir, buffer); 691 cpu_dir = hypfs_mkdir(cpus_dir, buffer);
695 if (IS_ERR(cpu_dir)) 692 if (IS_ERR(cpu_dir))
696 return PTR_ERR(cpu_dir); 693 return PTR_ERR(cpu_dir);
697 rc = hypfs_create_u64(sb, cpu_dir, "mgmtime", 694 rc = hypfs_create_u64(cpu_dir, "mgmtime",
698 phys_cpu__mgm_time(diag204_info_type, cpu_info)); 695 phys_cpu__mgm_time(diag204_info_type, cpu_info));
699 if (IS_ERR(rc)) 696 if (IS_ERR(rc))
700 return PTR_ERR(rc); 697 return PTR_ERR(rc);
701 diag224_idx2name(phys_cpu__ctidx(diag204_info_type, cpu_info), buffer); 698 diag224_idx2name(phys_cpu__ctidx(diag204_info_type, cpu_info), buffer);
702 rc = hypfs_create_str(sb, cpu_dir, "type", buffer); 699 rc = hypfs_create_str(cpu_dir, "type", buffer);
703 return PTR_RET(rc); 700 return PTR_RET(rc);
704} 701}
705 702
706static void *hypfs_create_phys_files(struct super_block *sb, 703static void *hypfs_create_phys_files(struct dentry *parent_dir, void *phys_hdr)
707 struct dentry *parent_dir, void *phys_hdr)
708{ 704{
709 int i; 705 int i;
710 void *cpu_info; 706 void *cpu_info;
711 struct dentry *cpus_dir; 707 struct dentry *cpus_dir;
712 708
713 cpus_dir = hypfs_mkdir(sb, parent_dir, "cpus"); 709 cpus_dir = hypfs_mkdir(parent_dir, "cpus");
714 if (IS_ERR(cpus_dir)) 710 if (IS_ERR(cpus_dir))
715 return cpus_dir; 711 return cpus_dir;
716 cpu_info = phys_hdr + phys_hdr__size(diag204_info_type); 712 cpu_info = phys_hdr + phys_hdr__size(diag204_info_type);
717 for (i = 0; i < phys_hdr__cpus(diag204_info_type, phys_hdr); i++) { 713 for (i = 0; i < phys_hdr__cpus(diag204_info_type, phys_hdr); i++) {
718 int rc; 714 int rc;
719 rc = hypfs_create_phys_cpu_files(sb, cpus_dir, cpu_info); 715 rc = hypfs_create_phys_cpu_files(cpus_dir, cpu_info);
720 if (rc) 716 if (rc)
721 return ERR_PTR(rc); 717 return ERR_PTR(rc);
722 cpu_info += phys_cpu__size(diag204_info_type); 718 cpu_info += phys_cpu__size(diag204_info_type);
@@ -724,7 +720,7 @@ static void *hypfs_create_phys_files(struct super_block *sb,
724 return cpu_info; 720 return cpu_info;
725} 721}
726 722
727int hypfs_diag_create_files(struct super_block *sb, struct dentry *root) 723int hypfs_diag_create_files(struct dentry *root)
728{ 724{
729 struct dentry *systems_dir, *hyp_dir; 725 struct dentry *systems_dir, *hyp_dir;
730 void *time_hdr, *part_hdr; 726 void *time_hdr, *part_hdr;
@@ -735,7 +731,7 @@ int hypfs_diag_create_files(struct super_block *sb, struct dentry *root)
735 if (IS_ERR(buffer)) 731 if (IS_ERR(buffer))
736 return PTR_ERR(buffer); 732 return PTR_ERR(buffer);
737 733
738 systems_dir = hypfs_mkdir(sb, root, "systems"); 734 systems_dir = hypfs_mkdir(root, "systems");
739 if (IS_ERR(systems_dir)) { 735 if (IS_ERR(systems_dir)) {
740 rc = PTR_ERR(systems_dir); 736 rc = PTR_ERR(systems_dir);
741 goto err_out; 737 goto err_out;
@@ -743,25 +739,25 @@ int hypfs_diag_create_files(struct super_block *sb, struct dentry *root)
743 time_hdr = (struct x_info_blk_hdr *)buffer; 739 time_hdr = (struct x_info_blk_hdr *)buffer;
744 part_hdr = time_hdr + info_blk_hdr__size(diag204_info_type); 740 part_hdr = time_hdr + info_blk_hdr__size(diag204_info_type);
745 for (i = 0; i < info_blk_hdr__npar(diag204_info_type, time_hdr); i++) { 741 for (i = 0; i < info_blk_hdr__npar(diag204_info_type, time_hdr); i++) {
746 part_hdr = hypfs_create_lpar_files(sb, systems_dir, part_hdr); 742 part_hdr = hypfs_create_lpar_files(systems_dir, part_hdr);
747 if (IS_ERR(part_hdr)) { 743 if (IS_ERR(part_hdr)) {
748 rc = PTR_ERR(part_hdr); 744 rc = PTR_ERR(part_hdr);
749 goto err_out; 745 goto err_out;
750 } 746 }
751 } 747 }
752 if (info_blk_hdr__flags(diag204_info_type, time_hdr) & LPAR_PHYS_FLG) { 748 if (info_blk_hdr__flags(diag204_info_type, time_hdr) & LPAR_PHYS_FLG) {
753 ptr = hypfs_create_phys_files(sb, root, part_hdr); 749 ptr = hypfs_create_phys_files(root, part_hdr);
754 if (IS_ERR(ptr)) { 750 if (IS_ERR(ptr)) {
755 rc = PTR_ERR(ptr); 751 rc = PTR_ERR(ptr);
756 goto err_out; 752 goto err_out;
757 } 753 }
758 } 754 }
759 hyp_dir = hypfs_mkdir(sb, root, "hyp"); 755 hyp_dir = hypfs_mkdir(root, "hyp");
760 if (IS_ERR(hyp_dir)) { 756 if (IS_ERR(hyp_dir)) {
761 rc = PTR_ERR(hyp_dir); 757 rc = PTR_ERR(hyp_dir);
762 goto err_out; 758 goto err_out;
763 } 759 }
764 ptr = hypfs_create_str(sb, hyp_dir, "type", "LPAR Hypervisor"); 760 ptr = hypfs_create_str(hyp_dir, "type", "LPAR Hypervisor");
765 if (IS_ERR(ptr)) { 761 if (IS_ERR(ptr)) {
766 rc = PTR_ERR(ptr); 762 rc = PTR_ERR(ptr);
767 goto err_out; 763 goto err_out;
diff --git a/arch/s390/hypfs/hypfs_vm.c b/arch/s390/hypfs/hypfs_vm.c
index f364dcf77e8e..24908ce149f1 100644
--- a/arch/s390/hypfs/hypfs_vm.c
+++ b/arch/s390/hypfs/hypfs_vm.c
@@ -107,16 +107,15 @@ static void diag2fc_free(const void *data)
107 vfree(data); 107 vfree(data);
108} 108}
109 109
110#define ATTRIBUTE(sb, dir, name, member) \ 110#define ATTRIBUTE(dir, name, member) \
111do { \ 111do { \
112 void *rc; \ 112 void *rc; \
113 rc = hypfs_create_u64(sb, dir, name, member); \ 113 rc = hypfs_create_u64(dir, name, member); \
114 if (IS_ERR(rc)) \ 114 if (IS_ERR(rc)) \
115 return PTR_ERR(rc); \ 115 return PTR_ERR(rc); \
116} while(0) 116} while(0)
117 117
118static int hpyfs_vm_create_guest(struct super_block *sb, 118static int hpyfs_vm_create_guest(struct dentry *systems_dir,
119 struct dentry *systems_dir,
120 struct diag2fc_data *data) 119 struct diag2fc_data *data)
121{ 120{
122 char guest_name[NAME_LEN + 1] = {}; 121 char guest_name[NAME_LEN + 1] = {};
@@ -130,46 +129,46 @@ static int hpyfs_vm_create_guest(struct super_block *sb,
130 memcpy(guest_name, data->guest_name, NAME_LEN); 129 memcpy(guest_name, data->guest_name, NAME_LEN);
131 EBCASC(guest_name, NAME_LEN); 130 EBCASC(guest_name, NAME_LEN);
132 strim(guest_name); 131 strim(guest_name);
133 guest_dir = hypfs_mkdir(sb, systems_dir, guest_name); 132 guest_dir = hypfs_mkdir(systems_dir, guest_name);
134 if (IS_ERR(guest_dir)) 133 if (IS_ERR(guest_dir))
135 return PTR_ERR(guest_dir); 134 return PTR_ERR(guest_dir);
136 ATTRIBUTE(sb, guest_dir, "onlinetime_us", data->el_time); 135 ATTRIBUTE(guest_dir, "onlinetime_us", data->el_time);
137 136
138 /* logical cpu information */ 137 /* logical cpu information */
139 cpus_dir = hypfs_mkdir(sb, guest_dir, "cpus"); 138 cpus_dir = hypfs_mkdir(guest_dir, "cpus");
140 if (IS_ERR(cpus_dir)) 139 if (IS_ERR(cpus_dir))
141 return PTR_ERR(cpus_dir); 140 return PTR_ERR(cpus_dir);
142 ATTRIBUTE(sb, cpus_dir, "cputime_us", data->used_cpu); 141 ATTRIBUTE(cpus_dir, "cputime_us", data->used_cpu);
143 ATTRIBUTE(sb, cpus_dir, "capped", capped_value); 142 ATTRIBUTE(cpus_dir, "capped", capped_value);
144 ATTRIBUTE(sb, cpus_dir, "dedicated", dedicated_flag); 143 ATTRIBUTE(cpus_dir, "dedicated", dedicated_flag);
145 ATTRIBUTE(sb, cpus_dir, "count", data->vcpus); 144 ATTRIBUTE(cpus_dir, "count", data->vcpus);
146 ATTRIBUTE(sb, cpus_dir, "weight_min", data->cpu_min); 145 ATTRIBUTE(cpus_dir, "weight_min", data->cpu_min);
147 ATTRIBUTE(sb, cpus_dir, "weight_max", data->cpu_max); 146 ATTRIBUTE(cpus_dir, "weight_max", data->cpu_max);
148 ATTRIBUTE(sb, cpus_dir, "weight_cur", data->cpu_shares); 147 ATTRIBUTE(cpus_dir, "weight_cur", data->cpu_shares);
149 148
150 /* memory information */ 149 /* memory information */
151 mem_dir = hypfs_mkdir(sb, guest_dir, "mem"); 150 mem_dir = hypfs_mkdir(guest_dir, "mem");
152 if (IS_ERR(mem_dir)) 151 if (IS_ERR(mem_dir))
153 return PTR_ERR(mem_dir); 152 return PTR_ERR(mem_dir);
154 ATTRIBUTE(sb, mem_dir, "min_KiB", data->mem_min_kb); 153 ATTRIBUTE(mem_dir, "min_KiB", data->mem_min_kb);
155 ATTRIBUTE(sb, mem_dir, "max_KiB", data->mem_max_kb); 154 ATTRIBUTE(mem_dir, "max_KiB", data->mem_max_kb);
156 ATTRIBUTE(sb, mem_dir, "used_KiB", data->mem_used_kb); 155 ATTRIBUTE(mem_dir, "used_KiB", data->mem_used_kb);
157 ATTRIBUTE(sb, mem_dir, "share_KiB", data->mem_share_kb); 156 ATTRIBUTE(mem_dir, "share_KiB", data->mem_share_kb);
158 157
159 /* samples */ 158 /* samples */
160 samples_dir = hypfs_mkdir(sb, guest_dir, "samples"); 159 samples_dir = hypfs_mkdir(guest_dir, "samples");
161 if (IS_ERR(samples_dir)) 160 if (IS_ERR(samples_dir))
162 return PTR_ERR(samples_dir); 161 return PTR_ERR(samples_dir);
163 ATTRIBUTE(sb, samples_dir, "cpu_using", data->cpu_use_samp); 162 ATTRIBUTE(samples_dir, "cpu_using", data->cpu_use_samp);
164 ATTRIBUTE(sb, samples_dir, "cpu_delay", data->cpu_delay_samp); 163 ATTRIBUTE(samples_dir, "cpu_delay", data->cpu_delay_samp);
165 ATTRIBUTE(sb, samples_dir, "mem_delay", data->page_wait_samp); 164 ATTRIBUTE(samples_dir, "mem_delay", data->page_wait_samp);
166 ATTRIBUTE(sb, samples_dir, "idle", data->idle_samp); 165 ATTRIBUTE(samples_dir, "idle", data->idle_samp);
167 ATTRIBUTE(sb, samples_dir, "other", data->other_samp); 166 ATTRIBUTE(samples_dir, "other", data->other_samp);
168 ATTRIBUTE(sb, samples_dir, "total", data->total_samp); 167 ATTRIBUTE(samples_dir, "total", data->total_samp);
169 return 0; 168 return 0;
170} 169}
171 170
172int hypfs_vm_create_files(struct super_block *sb, struct dentry *root) 171int hypfs_vm_create_files(struct dentry *root)
173{ 172{
174 struct dentry *dir, *file; 173 struct dentry *dir, *file;
175 struct diag2fc_data *data; 174 struct diag2fc_data *data;
@@ -181,38 +180,38 @@ int hypfs_vm_create_files(struct super_block *sb, struct dentry *root)
181 return PTR_ERR(data); 180 return PTR_ERR(data);
182 181
183 /* Hpervisor Info */ 182 /* Hpervisor Info */
184 dir = hypfs_mkdir(sb, root, "hyp"); 183 dir = hypfs_mkdir(root, "hyp");
185 if (IS_ERR(dir)) { 184 if (IS_ERR(dir)) {
186 rc = PTR_ERR(dir); 185 rc = PTR_ERR(dir);
187 goto failed; 186 goto failed;
188 } 187 }
189 file = hypfs_create_str(sb, dir, "type", "z/VM Hypervisor"); 188 file = hypfs_create_str(dir, "type", "z/VM Hypervisor");
190 if (IS_ERR(file)) { 189 if (IS_ERR(file)) {
191 rc = PTR_ERR(file); 190 rc = PTR_ERR(file);
192 goto failed; 191 goto failed;
193 } 192 }
194 193
195 /* physical cpus */ 194 /* physical cpus */
196 dir = hypfs_mkdir(sb, root, "cpus"); 195 dir = hypfs_mkdir(root, "cpus");
197 if (IS_ERR(dir)) { 196 if (IS_ERR(dir)) {
198 rc = PTR_ERR(dir); 197 rc = PTR_ERR(dir);
199 goto failed; 198 goto failed;
200 } 199 }
201 file = hypfs_create_u64(sb, dir, "count", data->lcpus); 200 file = hypfs_create_u64(dir, "count", data->lcpus);
202 if (IS_ERR(file)) { 201 if (IS_ERR(file)) {
203 rc = PTR_ERR(file); 202 rc = PTR_ERR(file);
204 goto failed; 203 goto failed;
205 } 204 }
206 205
207 /* guests */ 206 /* guests */
208 dir = hypfs_mkdir(sb, root, "systems"); 207 dir = hypfs_mkdir(root, "systems");
209 if (IS_ERR(dir)) { 208 if (IS_ERR(dir)) {
210 rc = PTR_ERR(dir); 209 rc = PTR_ERR(dir);
211 goto failed; 210 goto failed;
212 } 211 }
213 212
214 for (i = 0; i < count; i++) { 213 for (i = 0; i < count; i++) {
215 rc = hpyfs_vm_create_guest(sb, dir, &(data[i])); 214 rc = hpyfs_vm_create_guest(dir, &(data[i]));
216 if (rc) 215 if (rc)
217 goto failed; 216 goto failed;
218 } 217 }
diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
index 7a539f4f5e30..ddfe09b45134 100644
--- a/arch/s390/hypfs/inode.c
+++ b/arch/s390/hypfs/inode.c
@@ -28,8 +28,7 @@
28#define HYPFS_MAGIC 0x687970 /* ASCII 'hyp' */ 28#define HYPFS_MAGIC 0x687970 /* ASCII 'hyp' */
29#define TMP_SIZE 64 /* size of temporary buffers */ 29#define TMP_SIZE 64 /* size of temporary buffers */
30 30
31static struct dentry *hypfs_create_update_file(struct super_block *sb, 31static struct dentry *hypfs_create_update_file(struct dentry *dir);
32 struct dentry *dir);
33 32
34struct hypfs_sb_info { 33struct hypfs_sb_info {
35 kuid_t uid; /* uid used for files and dirs */ 34 kuid_t uid; /* uid used for files and dirs */
@@ -193,9 +192,9 @@ static ssize_t hypfs_aio_write(struct kiocb *iocb, const struct iovec *iov,
193 } 192 }
194 hypfs_delete_tree(sb->s_root); 193 hypfs_delete_tree(sb->s_root);
195 if (MACHINE_IS_VM) 194 if (MACHINE_IS_VM)
196 rc = hypfs_vm_create_files(sb, sb->s_root); 195 rc = hypfs_vm_create_files(sb->s_root);
197 else 196 else
198 rc = hypfs_diag_create_files(sb, sb->s_root); 197 rc = hypfs_diag_create_files(sb->s_root);
199 if (rc) { 198 if (rc) {
200 pr_err("Updating the hypfs tree failed\n"); 199 pr_err("Updating the hypfs tree failed\n");
201 hypfs_delete_tree(sb->s_root); 200 hypfs_delete_tree(sb->s_root);
@@ -302,12 +301,12 @@ static int hypfs_fill_super(struct super_block *sb, void *data, int silent)
302 if (!root_dentry) 301 if (!root_dentry)
303 return -ENOMEM; 302 return -ENOMEM;
304 if (MACHINE_IS_VM) 303 if (MACHINE_IS_VM)
305 rc = hypfs_vm_create_files(sb, root_dentry); 304 rc = hypfs_vm_create_files(root_dentry);
306 else 305 else
307 rc = hypfs_diag_create_files(sb, root_dentry); 306 rc = hypfs_diag_create_files(root_dentry);
308 if (rc) 307 if (rc)
309 return rc; 308 return rc;
310 sbi->update_file = hypfs_create_update_file(sb, root_dentry); 309 sbi->update_file = hypfs_create_update_file(root_dentry);
311 if (IS_ERR(sbi->update_file)) 310 if (IS_ERR(sbi->update_file))
312 return PTR_ERR(sbi->update_file); 311 return PTR_ERR(sbi->update_file);
313 hypfs_update_update(sb); 312 hypfs_update_update(sb);
@@ -334,8 +333,7 @@ static void hypfs_kill_super(struct super_block *sb)
334 kill_litter_super(sb); 333 kill_litter_super(sb);
335} 334}
336 335
337static struct dentry *hypfs_create_file(struct super_block *sb, 336static struct dentry *hypfs_create_file(struct dentry *parent, const char *name,
338 struct dentry *parent, const char *name,
339 char *data, umode_t mode) 337 char *data, umode_t mode)
340{ 338{
341 struct dentry *dentry; 339 struct dentry *dentry;
@@ -347,7 +345,7 @@ static struct dentry *hypfs_create_file(struct super_block *sb,
347 dentry = ERR_PTR(-ENOMEM); 345 dentry = ERR_PTR(-ENOMEM);
348 goto fail; 346 goto fail;
349 } 347 }
350 inode = hypfs_make_inode(sb, mode); 348 inode = hypfs_make_inode(parent->d_sb, mode);
351 if (!inode) { 349 if (!inode) {
352 dput(dentry); 350 dput(dentry);
353 dentry = ERR_PTR(-ENOMEM); 351 dentry = ERR_PTR(-ENOMEM);
@@ -373,24 +371,22 @@ fail:
373 return dentry; 371 return dentry;
374} 372}
375 373
376struct dentry *hypfs_mkdir(struct super_block *sb, struct dentry *parent, 374struct dentry *hypfs_mkdir(struct dentry *parent, const char *name)
377 const char *name)
378{ 375{
379 struct dentry *dentry; 376 struct dentry *dentry;
380 377
381 dentry = hypfs_create_file(sb, parent, name, NULL, S_IFDIR | DIR_MODE); 378 dentry = hypfs_create_file(parent, name, NULL, S_IFDIR | DIR_MODE);
382 if (IS_ERR(dentry)) 379 if (IS_ERR(dentry))
383 return dentry; 380 return dentry;
384 hypfs_add_dentry(dentry); 381 hypfs_add_dentry(dentry);
385 return dentry; 382 return dentry;
386} 383}
387 384
388static struct dentry *hypfs_create_update_file(struct super_block *sb, 385static struct dentry *hypfs_create_update_file(struct dentry *dir)
389 struct dentry *dir)
390{ 386{
391 struct dentry *dentry; 387 struct dentry *dentry;
392 388
393 dentry = hypfs_create_file(sb, dir, "update", NULL, 389 dentry = hypfs_create_file(dir, "update", NULL,
394 S_IFREG | UPDATE_FILE_MODE); 390 S_IFREG | UPDATE_FILE_MODE);
395 /* 391 /*
396 * We do not put the update file on the 'delete' list with 392 * We do not put the update file on the 'delete' list with
@@ -400,7 +396,7 @@ static struct dentry *hypfs_create_update_file(struct super_block *sb,
400 return dentry; 396 return dentry;
401} 397}
402 398
403struct dentry *hypfs_create_u64(struct super_block *sb, struct dentry *dir, 399struct dentry *hypfs_create_u64(struct dentry *dir,
404 const char *name, __u64 value) 400 const char *name, __u64 value)
405{ 401{
406 char *buffer; 402 char *buffer;
@@ -412,7 +408,7 @@ struct dentry *hypfs_create_u64(struct super_block *sb, struct dentry *dir,
412 if (!buffer) 408 if (!buffer)
413 return ERR_PTR(-ENOMEM); 409 return ERR_PTR(-ENOMEM);
414 dentry = 410 dentry =
415 hypfs_create_file(sb, dir, name, buffer, S_IFREG | REG_FILE_MODE); 411 hypfs_create_file(dir, name, buffer, S_IFREG | REG_FILE_MODE);
416 if (IS_ERR(dentry)) { 412 if (IS_ERR(dentry)) {
417 kfree(buffer); 413 kfree(buffer);
418 return ERR_PTR(-ENOMEM); 414 return ERR_PTR(-ENOMEM);
@@ -421,7 +417,7 @@ struct dentry *hypfs_create_u64(struct super_block *sb, struct dentry *dir,
421 return dentry; 417 return dentry;
422} 418}
423 419
424struct dentry *hypfs_create_str(struct super_block *sb, struct dentry *dir, 420struct dentry *hypfs_create_str(struct dentry *dir,
425 const char *name, char *string) 421 const char *name, char *string)
426{ 422{
427 char *buffer; 423 char *buffer;
@@ -432,7 +428,7 @@ struct dentry *hypfs_create_str(struct super_block *sb, struct dentry *dir,
432 return ERR_PTR(-ENOMEM); 428 return ERR_PTR(-ENOMEM);
433 sprintf(buffer, "%s\n", string); 429 sprintf(buffer, "%s\n", string);
434 dentry = 430 dentry =
435 hypfs_create_file(sb, dir, name, buffer, S_IFREG | REG_FILE_MODE); 431 hypfs_create_file(dir, name, buffer, S_IFREG | REG_FILE_MODE);
436 if (IS_ERR(dentry)) { 432 if (IS_ERR(dentry)) {
437 kfree(buffer); 433 kfree(buffer);
438 return ERR_PTR(-ENOMEM); 434 return ERR_PTR(-ENOMEM);
diff --git a/arch/s390/oprofile/init.c b/arch/s390/oprofile/init.c
index 930783d2c99b..04e1b6a85362 100644
--- a/arch/s390/oprofile/init.c
+++ b/arch/s390/oprofile/init.c
@@ -346,16 +346,15 @@ static const struct file_operations timer_enabled_fops = {
346}; 346};
347 347
348 348
349static int oprofile_create_hwsampling_files(struct super_block *sb, 349static int oprofile_create_hwsampling_files(struct dentry *root)
350 struct dentry *root)
351{ 350{
352 struct dentry *dir; 351 struct dentry *dir;
353 352
354 dir = oprofilefs_mkdir(sb, root, "timer"); 353 dir = oprofilefs_mkdir(root, "timer");
355 if (!dir) 354 if (!dir)
356 return -EINVAL; 355 return -EINVAL;
357 356
358 oprofilefs_create_file(sb, dir, "enabled", &timer_enabled_fops); 357 oprofilefs_create_file(dir, "enabled", &timer_enabled_fops);
359 358
360 if (!hwsampler_available) 359 if (!hwsampler_available)
361 return 0; 360 return 0;
@@ -376,17 +375,17 @@ static int oprofile_create_hwsampling_files(struct super_block *sb,
376 * and can only be set to 0. 375 * and can only be set to 0.
377 */ 376 */
378 377
379 dir = oprofilefs_mkdir(sb, root, "0"); 378 dir = oprofilefs_mkdir(root, "0");
380 if (!dir) 379 if (!dir)
381 return -EINVAL; 380 return -EINVAL;
382 381
383 oprofilefs_create_file(sb, dir, "enabled", &hwsampler_fops); 382 oprofilefs_create_file(dir, "enabled", &hwsampler_fops);
384 oprofilefs_create_file(sb, dir, "event", &zero_fops); 383 oprofilefs_create_file(dir, "event", &zero_fops);
385 oprofilefs_create_file(sb, dir, "count", &hw_interval_fops); 384 oprofilefs_create_file(dir, "count", &hw_interval_fops);
386 oprofilefs_create_file(sb, dir, "unit_mask", &zero_fops); 385 oprofilefs_create_file(dir, "unit_mask", &zero_fops);
387 oprofilefs_create_file(sb, dir, "kernel", &kernel_fops); 386 oprofilefs_create_file(dir, "kernel", &kernel_fops);
388 oprofilefs_create_file(sb, dir, "user", &user_fops); 387 oprofilefs_create_file(dir, "user", &user_fops);
389 oprofilefs_create_ulong(sb, dir, "hw_sdbt_blocks", 388 oprofilefs_create_ulong(dir, "hw_sdbt_blocks",
390 &oprofile_sdbt_blocks); 389 &oprofile_sdbt_blocks);
391 390
392 } else { 391 } else {
@@ -396,19 +395,19 @@ static int oprofile_create_hwsampling_files(struct super_block *sb,
396 * space tools. The /dev/oprofile/hwsampling fs is 395 * space tools. The /dev/oprofile/hwsampling fs is
397 * provided in that case. 396 * provided in that case.
398 */ 397 */
399 dir = oprofilefs_mkdir(sb, root, "hwsampling"); 398 dir = oprofilefs_mkdir(root, "hwsampling");
400 if (!dir) 399 if (!dir)
401 return -EINVAL; 400 return -EINVAL;
402 401
403 oprofilefs_create_file(sb, dir, "hwsampler", 402 oprofilefs_create_file(dir, "hwsampler",
404 &hwsampler_fops); 403 &hwsampler_fops);
405 oprofilefs_create_file(sb, dir, "hw_interval", 404 oprofilefs_create_file(dir, "hw_interval",
406 &hw_interval_fops); 405 &hw_interval_fops);
407 oprofilefs_create_ro_ulong(sb, dir, "hw_min_interval", 406 oprofilefs_create_ro_ulong(dir, "hw_min_interval",
408 &oprofile_min_interval); 407 &oprofile_min_interval);
409 oprofilefs_create_ro_ulong(sb, dir, "hw_max_interval", 408 oprofilefs_create_ro_ulong(dir, "hw_max_interval",
410 &oprofile_max_interval); 409 &oprofile_max_interval);
411 oprofilefs_create_ulong(sb, dir, "hw_sdbt_blocks", 410 oprofilefs_create_ulong(dir, "hw_sdbt_blocks",
412 &oprofile_sdbt_blocks); 411 &oprofile_sdbt_blocks);
413 } 412 }
414 return 0; 413 return 0;
diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index 48768df2471a..6890d8498e0b 100644
--- a/arch/x86/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
@@ -403,7 +403,7 @@ static void nmi_cpu_down(void *dummy)
403 nmi_cpu_shutdown(dummy); 403 nmi_cpu_shutdown(dummy);
404} 404}
405 405
406static int nmi_create_files(struct super_block *sb, struct dentry *root) 406static int nmi_create_files(struct dentry *root)
407{ 407{
408 unsigned int i; 408 unsigned int i;
409 409
@@ -420,14 +420,14 @@ static int nmi_create_files(struct super_block *sb, struct dentry *root)
420 continue; 420 continue;
421 421
422 snprintf(buf, sizeof(buf), "%d", i); 422 snprintf(buf, sizeof(buf), "%d", i);
423 dir = oprofilefs_mkdir(sb, root, buf); 423 dir = oprofilefs_mkdir(root, buf);
424 oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled); 424 oprofilefs_create_ulong(dir, "enabled", &counter_config[i].enabled);
425 oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event); 425 oprofilefs_create_ulong(dir, "event", &counter_config[i].event);
426 oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count); 426 oprofilefs_create_ulong(dir, "count", &counter_config[i].count);
427 oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask); 427 oprofilefs_create_ulong(dir, "unit_mask", &counter_config[i].unit_mask);
428 oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel); 428 oprofilefs_create_ulong(dir, "kernel", &counter_config[i].kernel);
429 oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user); 429 oprofilefs_create_ulong(dir, "user", &counter_config[i].user);
430 oprofilefs_create_ulong(sb, dir, "extra", &counter_config[i].extra); 430 oprofilefs_create_ulong(dir, "extra", &counter_config[i].extra);
431 } 431 }
432 432
433 return 0; 433 return 0;
diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
index b2b94438ff05..50d86c0e9ba4 100644
--- a/arch/x86/oprofile/op_model_amd.c
+++ b/arch/x86/oprofile/op_model_amd.c
@@ -454,16 +454,16 @@ static void init_ibs(void)
454 printk(KERN_INFO "oprofile: AMD IBS detected (0x%08x)\n", ibs_caps); 454 printk(KERN_INFO "oprofile: AMD IBS detected (0x%08x)\n", ibs_caps);
455} 455}
456 456
457static int (*create_arch_files)(struct super_block *sb, struct dentry *root); 457static int (*create_arch_files)(struct dentry *root);
458 458
459static int setup_ibs_files(struct super_block *sb, struct dentry *root) 459static int setup_ibs_files(struct dentry *root)
460{ 460{
461 struct dentry *dir; 461 struct dentry *dir;
462 int ret = 0; 462 int ret = 0;
463 463
464 /* architecture specific files */ 464 /* architecture specific files */
465 if (create_arch_files) 465 if (create_arch_files)
466 ret = create_arch_files(sb, root); 466 ret = create_arch_files(root);
467 467
468 if (ret) 468 if (ret)
469 return ret; 469 return ret;
@@ -479,26 +479,26 @@ static int setup_ibs_files(struct super_block *sb, struct dentry *root)
479 ibs_config.max_cnt_op = 250000; 479 ibs_config.max_cnt_op = 250000;
480 480
481 if (ibs_caps & IBS_CAPS_FETCHSAM) { 481 if (ibs_caps & IBS_CAPS_FETCHSAM) {
482 dir = oprofilefs_mkdir(sb, root, "ibs_fetch"); 482 dir = oprofilefs_mkdir(root, "ibs_fetch");
483 oprofilefs_create_ulong(sb, dir, "enable", 483 oprofilefs_create_ulong(dir, "enable",
484 &ibs_config.fetch_enabled); 484 &ibs_config.fetch_enabled);
485 oprofilefs_create_ulong(sb, dir, "max_count", 485 oprofilefs_create_ulong(dir, "max_count",
486 &ibs_config.max_cnt_fetch); 486 &ibs_config.max_cnt_fetch);
487 oprofilefs_create_ulong(sb, dir, "rand_enable", 487 oprofilefs_create_ulong(dir, "rand_enable",
488 &ibs_config.rand_en); 488 &ibs_config.rand_en);
489 } 489 }
490 490
491 if (ibs_caps & IBS_CAPS_OPSAM) { 491 if (ibs_caps & IBS_CAPS_OPSAM) {
492 dir = oprofilefs_mkdir(sb, root, "ibs_op"); 492 dir = oprofilefs_mkdir(root, "ibs_op");
493 oprofilefs_create_ulong(sb, dir, "enable", 493 oprofilefs_create_ulong(dir, "enable",
494 &ibs_config.op_enabled); 494 &ibs_config.op_enabled);
495 oprofilefs_create_ulong(sb, dir, "max_count", 495 oprofilefs_create_ulong(dir, "max_count",
496 &ibs_config.max_cnt_op); 496 &ibs_config.max_cnt_op);
497 if (ibs_caps & IBS_CAPS_OPCNT) 497 if (ibs_caps & IBS_CAPS_OPCNT)
498 oprofilefs_create_ulong(sb, dir, "dispatched_ops", 498 oprofilefs_create_ulong(dir, "dispatched_ops",
499 &ibs_config.dispatched_ops); 499 &ibs_config.dispatched_ops);
500 if (ibs_caps & IBS_CAPS_BRNTRGT) 500 if (ibs_caps & IBS_CAPS_BRNTRGT)
501 oprofilefs_create_ulong(sb, dir, "branch_target", 501 oprofilefs_create_ulong(dir, "branch_target",
502 &ibs_config.branch_target); 502 &ibs_config.branch_target);
503 } 503 }
504 504
diff --git a/drivers/dma/coh901318.c b/drivers/dma/coh901318.c
index 9bfaddd57ef1..31011d2a26fc 100644
--- a/drivers/dma/coh901318.c
+++ b/drivers/dma/coh901318.c
@@ -1339,15 +1339,14 @@ static int coh901318_debugfs_read(struct file *file, char __user *buf,
1339{ 1339{
1340 u64 started_channels = debugfs_dma_base->pm.started_channels; 1340 u64 started_channels = debugfs_dma_base->pm.started_channels;
1341 int pool_count = debugfs_dma_base->pool.debugfs_pool_counter; 1341 int pool_count = debugfs_dma_base->pool.debugfs_pool_counter;
1342 int i;
1343 int ret = 0;
1344 char *dev_buf; 1342 char *dev_buf;
1345 char *tmp; 1343 char *tmp;
1346 int dev_size; 1344 int ret;
1345 int i;
1347 1346
1348 dev_buf = kmalloc(4*1024, GFP_KERNEL); 1347 dev_buf = kmalloc(4*1024, GFP_KERNEL);
1349 if (dev_buf == NULL) 1348 if (dev_buf == NULL)
1350 goto err_kmalloc; 1349 return -ENOMEM;
1351 tmp = dev_buf; 1350 tmp = dev_buf;
1352 1351
1353 tmp += sprintf(tmp, "DMA -- enabled dma channels\n"); 1352 tmp += sprintf(tmp, "DMA -- enabled dma channels\n");
@@ -1357,26 +1356,11 @@ static int coh901318_debugfs_read(struct file *file, char __user *buf,
1357 tmp += sprintf(tmp, "channel %d\n", i); 1356 tmp += sprintf(tmp, "channel %d\n", i);
1358 1357
1359 tmp += sprintf(tmp, "Pool alloc nbr %d\n", pool_count); 1358 tmp += sprintf(tmp, "Pool alloc nbr %d\n", pool_count);
1360 dev_size = tmp - dev_buf;
1361
1362 /* No more to read if offset != 0 */
1363 if (*f_pos > dev_size)
1364 goto out;
1365 1359
1366 if (count > dev_size - *f_pos) 1360 ret = simple_read_from_buffer(buf, count, f_pos, dev_buf,
1367 count = dev_size - *f_pos; 1361 tmp - dev_buf);
1368
1369 if (copy_to_user(buf, dev_buf + *f_pos, count))
1370 ret = -EINVAL;
1371 ret = count;
1372 *f_pos += count;
1373
1374 out:
1375 kfree(dev_buf); 1362 kfree(dev_buf);
1376 return ret; 1363 return ret;
1377
1378 err_kmalloc:
1379 return 0;
1380} 1364}
1381 1365
1382static const struct file_operations coh901318_debugfs_status_operations = { 1366static const struct file_operations coh901318_debugfs_status_operations = {
diff --git a/drivers/misc/ibmasm/ibmasmfs.c b/drivers/misc/ibmasm/ibmasmfs.c
index ce5b75616b45..e8b933111e0d 100644
--- a/drivers/misc/ibmasm/ibmasmfs.c
+++ b/drivers/misc/ibmasm/ibmasmfs.c
@@ -149,8 +149,7 @@ static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode)
149 return ret; 149 return ret;
150} 150}
151 151
152static struct dentry *ibmasmfs_create_file (struct super_block *sb, 152static struct dentry *ibmasmfs_create_file(struct dentry *parent,
153 struct dentry *parent,
154 const char *name, 153 const char *name,
155 const struct file_operations *fops, 154 const struct file_operations *fops,
156 void *data, 155 void *data,
@@ -163,7 +162,7 @@ static struct dentry *ibmasmfs_create_file (struct super_block *sb,
163 if (!dentry) 162 if (!dentry)
164 return NULL; 163 return NULL;
165 164
166 inode = ibmasmfs_make_inode(sb, S_IFREG | mode); 165 inode = ibmasmfs_make_inode(parent->d_sb, S_IFREG | mode);
167 if (!inode) { 166 if (!inode) {
168 dput(dentry); 167 dput(dentry);
169 return NULL; 168 return NULL;
@@ -176,8 +175,7 @@ static struct dentry *ibmasmfs_create_file (struct super_block *sb,
176 return dentry; 175 return dentry;
177} 176}
178 177
179static struct dentry *ibmasmfs_create_dir (struct super_block *sb, 178static struct dentry *ibmasmfs_create_dir(struct dentry *parent,
180 struct dentry *parent,
181 const char *name) 179 const char *name)
182{ 180{
183 struct dentry *dentry; 181 struct dentry *dentry;
@@ -187,7 +185,7 @@ static struct dentry *ibmasmfs_create_dir (struct super_block *sb,
187 if (!dentry) 185 if (!dentry)
188 return NULL; 186 return NULL;
189 187
190 inode = ibmasmfs_make_inode(sb, S_IFDIR | 0500); 188 inode = ibmasmfs_make_inode(parent->d_sb, S_IFDIR | 0500);
191 if (!inode) { 189 if (!inode) {
192 dput(dentry); 190 dput(dentry);
193 return NULL; 191 return NULL;
@@ -612,20 +610,20 @@ static void ibmasmfs_create_files (struct super_block *sb)
612 struct dentry *dir; 610 struct dentry *dir;
613 struct dentry *remote_dir; 611 struct dentry *remote_dir;
614 sp = list_entry(entry, struct service_processor, node); 612 sp = list_entry(entry, struct service_processor, node);
615 dir = ibmasmfs_create_dir(sb, sb->s_root, sp->dirname); 613 dir = ibmasmfs_create_dir(sb->s_root, sp->dirname);
616 if (!dir) 614 if (!dir)
617 continue; 615 continue;
618 616
619 ibmasmfs_create_file(sb, dir, "command", &command_fops, sp, S_IRUSR|S_IWUSR); 617 ibmasmfs_create_file(dir, "command", &command_fops, sp, S_IRUSR|S_IWUSR);
620 ibmasmfs_create_file(sb, dir, "event", &event_fops, sp, S_IRUSR|S_IWUSR); 618 ibmasmfs_create_file(dir, "event", &event_fops, sp, S_IRUSR|S_IWUSR);
621 ibmasmfs_create_file(sb, dir, "reverse_heartbeat", &r_heartbeat_fops, sp, S_IRUSR|S_IWUSR); 619 ibmasmfs_create_file(dir, "reverse_heartbeat", &r_heartbeat_fops, sp, S_IRUSR|S_IWUSR);
622 620
623 remote_dir = ibmasmfs_create_dir(sb, dir, "remote_video"); 621 remote_dir = ibmasmfs_create_dir(dir, "remote_video");
624 if (!remote_dir) 622 if (!remote_dir)
625 continue; 623 continue;
626 624
627 ibmasmfs_create_file(sb, remote_dir, "width", &remote_settings_fops, (void *)display_width(sp), S_IRUSR|S_IWUSR); 625 ibmasmfs_create_file(remote_dir, "width", &remote_settings_fops, (void *)display_width(sp), S_IRUSR|S_IWUSR);
628 ibmasmfs_create_file(sb, remote_dir, "height", &remote_settings_fops, (void *)display_height(sp), S_IRUSR|S_IWUSR); 626 ibmasmfs_create_file(remote_dir, "height", &remote_settings_fops, (void *)display_height(sp), S_IRUSR|S_IWUSR);
629 ibmasmfs_create_file(sb, remote_dir, "depth", &remote_settings_fops, (void *)display_depth(sp), S_IRUSR|S_IWUSR); 627 ibmasmfs_create_file(remote_dir, "depth", &remote_settings_fops, (void *)display_depth(sp), S_IRUSR|S_IWUSR);
630 } 628 }
631} 629}
diff --git a/drivers/oprofile/oprof.h b/drivers/oprofile/oprof.h
index d32ef816337c..d5412060ab0f 100644
--- a/drivers/oprofile/oprof.h
+++ b/drivers/oprofile/oprof.h
@@ -30,10 +30,9 @@ extern struct oprofile_operations oprofile_ops;
30extern unsigned long oprofile_started; 30extern unsigned long oprofile_started;
31extern unsigned long oprofile_backtrace_depth; 31extern unsigned long oprofile_backtrace_depth;
32 32
33struct super_block;
34struct dentry; 33struct dentry;
35 34
36void oprofile_create_files(struct super_block *sb, struct dentry *root); 35void oprofile_create_files(struct dentry *root);
37int oprofile_timer_init(struct oprofile_operations *ops); 36int oprofile_timer_init(struct oprofile_operations *ops);
38#ifdef CONFIG_OPROFILE_NMI_TIMER 37#ifdef CONFIG_OPROFILE_NMI_TIMER
39int op_nmi_timer_init(struct oprofile_operations *ops); 38int op_nmi_timer_init(struct oprofile_operations *ops);
diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
index 84a208dbed93..ee2cfce358b9 100644
--- a/drivers/oprofile/oprofile_files.c
+++ b/drivers/oprofile/oprofile_files.c
@@ -175,7 +175,7 @@ static const struct file_operations dump_fops = {
175 .llseek = noop_llseek, 175 .llseek = noop_llseek,
176}; 176};
177 177
178void oprofile_create_files(struct super_block *sb, struct dentry *root) 178void oprofile_create_files(struct dentry *root)
179{ 179{
180 /* reinitialize default values */ 180 /* reinitialize default values */
181 oprofile_buffer_size = BUFFER_SIZE_DEFAULT; 181 oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
@@ -183,19 +183,19 @@ void oprofile_create_files(struct super_block *sb, struct dentry *root)
183 oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT; 183 oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
184 oprofile_time_slice = msecs_to_jiffies(TIME_SLICE_DEFAULT); 184 oprofile_time_slice = msecs_to_jiffies(TIME_SLICE_DEFAULT);
185 185
186 oprofilefs_create_file(sb, root, "enable", &enable_fops); 186 oprofilefs_create_file(root, "enable", &enable_fops);
187 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666); 187 oprofilefs_create_file_perm(root, "dump", &dump_fops, 0666);
188 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops); 188 oprofilefs_create_file(root, "buffer", &event_buffer_fops);
189 oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size); 189 oprofilefs_create_ulong(root, "buffer_size", &oprofile_buffer_size);
190 oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed); 190 oprofilefs_create_ulong(root, "buffer_watershed", &oprofile_buffer_watershed);
191 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size); 191 oprofilefs_create_ulong(root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
192 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops); 192 oprofilefs_create_file(root, "cpu_type", &cpu_type_fops);
193 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops); 193 oprofilefs_create_file(root, "backtrace_depth", &depth_fops);
194 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops); 194 oprofilefs_create_file(root, "pointer_size", &pointer_size_fops);
195#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX 195#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
196 oprofilefs_create_file(sb, root, "time_slice", &timeout_fops); 196 oprofilefs_create_file(root, "time_slice", &timeout_fops);
197#endif 197#endif
198 oprofile_create_stats_files(sb, root); 198 oprofile_create_stats_files(root);
199 if (oprofile_ops.create_files) 199 if (oprofile_ops.create_files)
200 oprofile_ops.create_files(sb, root); 200 oprofile_ops.create_files(root);
201} 201}
diff --git a/drivers/oprofile/oprofile_perf.c b/drivers/oprofile/oprofile_perf.c
index f3cfa0b9adfa..d5b2732b1b81 100644
--- a/drivers/oprofile/oprofile_perf.c
+++ b/drivers/oprofile/oprofile_perf.c
@@ -138,7 +138,7 @@ static void op_perf_stop(void)
138 op_destroy_counter(cpu, event); 138 op_destroy_counter(cpu, event);
139} 139}
140 140
141static int oprofile_perf_create_files(struct super_block *sb, struct dentry *root) 141static int oprofile_perf_create_files(struct dentry *root)
142{ 142{
143 unsigned int i; 143 unsigned int i;
144 144
@@ -147,13 +147,13 @@ static int oprofile_perf_create_files(struct super_block *sb, struct dentry *roo
147 char buf[4]; 147 char buf[4];
148 148
149 snprintf(buf, sizeof buf, "%d", i); 149 snprintf(buf, sizeof buf, "%d", i);
150 dir = oprofilefs_mkdir(sb, root, buf); 150 dir = oprofilefs_mkdir(root, buf);
151 oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled); 151 oprofilefs_create_ulong(dir, "enabled", &counter_config[i].enabled);
152 oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event); 152 oprofilefs_create_ulong(dir, "event", &counter_config[i].event);
153 oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count); 153 oprofilefs_create_ulong(dir, "count", &counter_config[i].count);
154 oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask); 154 oprofilefs_create_ulong(dir, "unit_mask", &counter_config[i].unit_mask);
155 oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel); 155 oprofilefs_create_ulong(dir, "kernel", &counter_config[i].kernel);
156 oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user); 156 oprofilefs_create_ulong(dir, "user", &counter_config[i].user);
157 } 157 }
158 158
159 return 0; 159 return 0;
diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
index 917d28ebeacd..59659cea4582 100644
--- a/drivers/oprofile/oprofile_stats.c
+++ b/drivers/oprofile/oprofile_stats.c
@@ -38,7 +38,7 @@ void oprofile_reset_stats(void)
38} 38}
39 39
40 40
41void oprofile_create_stats_files(struct super_block *sb, struct dentry *root) 41void oprofile_create_stats_files(struct dentry *root)
42{ 42{
43 struct oprofile_cpu_buffer *cpu_buf; 43 struct oprofile_cpu_buffer *cpu_buf;
44 struct dentry *cpudir; 44 struct dentry *cpudir;
@@ -46,39 +46,39 @@ void oprofile_create_stats_files(struct super_block *sb, struct dentry *root)
46 char buf[10]; 46 char buf[10];
47 int i; 47 int i;
48 48
49 dir = oprofilefs_mkdir(sb, root, "stats"); 49 dir = oprofilefs_mkdir(root, "stats");
50 if (!dir) 50 if (!dir)
51 return; 51 return;
52 52
53 for_each_possible_cpu(i) { 53 for_each_possible_cpu(i) {
54 cpu_buf = &per_cpu(op_cpu_buffer, i); 54 cpu_buf = &per_cpu(op_cpu_buffer, i);
55 snprintf(buf, 10, "cpu%d", i); 55 snprintf(buf, 10, "cpu%d", i);
56 cpudir = oprofilefs_mkdir(sb, dir, buf); 56 cpudir = oprofilefs_mkdir(dir, buf);
57 57
58 /* Strictly speaking access to these ulongs is racy, 58 /* Strictly speaking access to these ulongs is racy,
59 * but we can't simply lock them, and they are 59 * but we can't simply lock them, and they are
60 * informational only. 60 * informational only.
61 */ 61 */
62 oprofilefs_create_ro_ulong(sb, cpudir, "sample_received", 62 oprofilefs_create_ro_ulong(cpudir, "sample_received",
63 &cpu_buf->sample_received); 63 &cpu_buf->sample_received);
64 oprofilefs_create_ro_ulong(sb, cpudir, "sample_lost_overflow", 64 oprofilefs_create_ro_ulong(cpudir, "sample_lost_overflow",
65 &cpu_buf->sample_lost_overflow); 65 &cpu_buf->sample_lost_overflow);
66 oprofilefs_create_ro_ulong(sb, cpudir, "backtrace_aborted", 66 oprofilefs_create_ro_ulong(cpudir, "backtrace_aborted",
67 &cpu_buf->backtrace_aborted); 67 &cpu_buf->backtrace_aborted);
68 oprofilefs_create_ro_ulong(sb, cpudir, "sample_invalid_eip", 68 oprofilefs_create_ro_ulong(cpudir, "sample_invalid_eip",
69 &cpu_buf->sample_invalid_eip); 69 &cpu_buf->sample_invalid_eip);
70 } 70 }
71 71
72 oprofilefs_create_ro_atomic(sb, dir, "sample_lost_no_mm", 72 oprofilefs_create_ro_atomic(dir, "sample_lost_no_mm",
73 &oprofile_stats.sample_lost_no_mm); 73 &oprofile_stats.sample_lost_no_mm);
74 oprofilefs_create_ro_atomic(sb, dir, "sample_lost_no_mapping", 74 oprofilefs_create_ro_atomic(dir, "sample_lost_no_mapping",
75 &oprofile_stats.sample_lost_no_mapping); 75 &oprofile_stats.sample_lost_no_mapping);
76 oprofilefs_create_ro_atomic(sb, dir, "event_lost_overflow", 76 oprofilefs_create_ro_atomic(dir, "event_lost_overflow",
77 &oprofile_stats.event_lost_overflow); 77 &oprofile_stats.event_lost_overflow);
78 oprofilefs_create_ro_atomic(sb, dir, "bt_lost_no_mapping", 78 oprofilefs_create_ro_atomic(dir, "bt_lost_no_mapping",
79 &oprofile_stats.bt_lost_no_mapping); 79 &oprofile_stats.bt_lost_no_mapping);
80#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX 80#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
81 oprofilefs_create_ro_atomic(sb, dir, "multiplex_counter", 81 oprofilefs_create_ro_atomic(dir, "multiplex_counter",
82 &oprofile_stats.multiplex_counter); 82 &oprofile_stats.multiplex_counter);
83#endif 83#endif
84} 84}
diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
index 38b6fc028984..1fc622bd1834 100644
--- a/drivers/oprofile/oprofile_stats.h
+++ b/drivers/oprofile/oprofile_stats.h
@@ -25,10 +25,9 @@ extern struct oprofile_stat_struct oprofile_stats;
25/* reset all stats to zero */ 25/* reset all stats to zero */
26void oprofile_reset_stats(void); 26void oprofile_reset_stats(void);
27 27
28struct super_block;
29struct dentry; 28struct dentry;
30 29
31/* create the stats/ dir */ 30/* create the stats/ dir */
32void oprofile_create_stats_files(struct super_block *sb, struct dentry *root); 31void oprofile_create_stats_files(struct dentry *root);
33 32
34#endif /* OPROFILE_STATS_H */ 33#endif /* OPROFILE_STATS_H */
diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
index 7c12d9c2b230..3f493459378f 100644
--- a/drivers/oprofile/oprofilefs.c
+++ b/drivers/oprofile/oprofilefs.c
@@ -132,9 +132,8 @@ static const struct file_operations ulong_ro_fops = {
132}; 132};
133 133
134 134
135static int __oprofilefs_create_file(struct super_block *sb, 135static int __oprofilefs_create_file(struct dentry *root, char const *name,
136 struct dentry *root, char const *name, const struct file_operations *fops, 136 const struct file_operations *fops, int perm, void *priv)
137 int perm, void *priv)
138{ 137{
139 struct dentry *dentry; 138 struct dentry *dentry;
140 struct inode *inode; 139 struct inode *inode;
@@ -145,7 +144,7 @@ static int __oprofilefs_create_file(struct super_block *sb,
145 mutex_unlock(&root->d_inode->i_mutex); 144 mutex_unlock(&root->d_inode->i_mutex);
146 return -ENOMEM; 145 return -ENOMEM;
147 } 146 }
148 inode = oprofilefs_get_inode(sb, S_IFREG | perm); 147 inode = oprofilefs_get_inode(root->d_sb, S_IFREG | perm);
149 if (!inode) { 148 if (!inode) {
150 dput(dentry); 149 dput(dentry);
151 mutex_unlock(&root->d_inode->i_mutex); 150 mutex_unlock(&root->d_inode->i_mutex);
@@ -159,18 +158,18 @@ static int __oprofilefs_create_file(struct super_block *sb,
159} 158}
160 159
161 160
162int oprofilefs_create_ulong(struct super_block *sb, struct dentry *root, 161int oprofilefs_create_ulong(struct dentry *root,
163 char const *name, unsigned long *val) 162 char const *name, unsigned long *val)
164{ 163{
165 return __oprofilefs_create_file(sb, root, name, 164 return __oprofilefs_create_file(root, name,
166 &ulong_fops, 0644, val); 165 &ulong_fops, 0644, val);
167} 166}
168 167
169 168
170int oprofilefs_create_ro_ulong(struct super_block *sb, struct dentry *root, 169int oprofilefs_create_ro_ulong(struct dentry *root,
171 char const *name, unsigned long *val) 170 char const *name, unsigned long *val)
172{ 171{
173 return __oprofilefs_create_file(sb, root, name, 172 return __oprofilefs_create_file(root, name,
174 &ulong_ro_fops, 0444, val); 173 &ulong_ro_fops, 0444, val);
175} 174}
176 175
@@ -189,50 +188,49 @@ static const struct file_operations atomic_ro_fops = {
189}; 188};
190 189
191 190
192int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root, 191int oprofilefs_create_ro_atomic(struct dentry *root,
193 char const *name, atomic_t *val) 192 char const *name, atomic_t *val)
194{ 193{
195 return __oprofilefs_create_file(sb, root, name, 194 return __oprofilefs_create_file(root, name,
196 &atomic_ro_fops, 0444, val); 195 &atomic_ro_fops, 0444, val);
197} 196}
198 197
199 198
200int oprofilefs_create_file(struct super_block *sb, struct dentry *root, 199int oprofilefs_create_file(struct dentry *root,
201 char const *name, const struct file_operations *fops) 200 char const *name, const struct file_operations *fops)
202{ 201{
203 return __oprofilefs_create_file(sb, root, name, fops, 0644, NULL); 202 return __oprofilefs_create_file(root, name, fops, 0644, NULL);
204} 203}
205 204
206 205
207int oprofilefs_create_file_perm(struct super_block *sb, struct dentry *root, 206int oprofilefs_create_file_perm(struct dentry *root,
208 char const *name, const struct file_operations *fops, int perm) 207 char const *name, const struct file_operations *fops, int perm)
209{ 208{
210 return __oprofilefs_create_file(sb, root, name, fops, perm, NULL); 209 return __oprofilefs_create_file(root, name, fops, perm, NULL);
211} 210}
212 211
213 212
214struct dentry *oprofilefs_mkdir(struct super_block *sb, 213struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name)
215 struct dentry *root, char const *name)
216{ 214{
217 struct dentry *dentry; 215 struct dentry *dentry;
218 struct inode *inode; 216 struct inode *inode;
219 217
220 mutex_lock(&root->d_inode->i_mutex); 218 mutex_lock(&parent->d_inode->i_mutex);
221 dentry = d_alloc_name(root, name); 219 dentry = d_alloc_name(parent, name);
222 if (!dentry) { 220 if (!dentry) {
223 mutex_unlock(&root->d_inode->i_mutex); 221 mutex_unlock(&parent->d_inode->i_mutex);
224 return NULL; 222 return NULL;
225 } 223 }
226 inode = oprofilefs_get_inode(sb, S_IFDIR | 0755); 224 inode = oprofilefs_get_inode(parent->d_sb, S_IFDIR | 0755);
227 if (!inode) { 225 if (!inode) {
228 dput(dentry); 226 dput(dentry);
229 mutex_unlock(&root->d_inode->i_mutex); 227 mutex_unlock(&parent->d_inode->i_mutex);
230 return NULL; 228 return NULL;
231 } 229 }
232 inode->i_op = &simple_dir_inode_operations; 230 inode->i_op = &simple_dir_inode_operations;
233 inode->i_fop = &simple_dir_operations; 231 inode->i_fop = &simple_dir_operations;
234 d_add(dentry, inode); 232 d_add(dentry, inode);
235 mutex_unlock(&root->d_inode->i_mutex); 233 mutex_unlock(&parent->d_inode->i_mutex);
236 return dentry; 234 return dentry;
237} 235}
238 236
@@ -256,7 +254,7 @@ static int oprofilefs_fill_super(struct super_block *sb, void *data, int silent)
256 if (!sb->s_root) 254 if (!sb->s_root)
257 return -ENOMEM; 255 return -ENOMEM;
258 256
259 oprofile_create_files(sb, sb->s_root); 257 oprofile_create_files(sb->s_root);
260 258
261 // FIXME: verify kill_litter_super removes our dentries 259 // FIXME: verify kill_litter_super removes our dentries
262 return 0; 260 return 0;
diff --git a/fs/block_dev.c b/fs/block_dev.c
index c7bda5cd3da7..1173a4ee0830 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1519,7 +1519,7 @@ ssize_t blkdev_aio_write(struct kiocb *iocb, const struct iovec *iov,
1519 1519
1520 blk_start_plug(&plug); 1520 blk_start_plug(&plug);
1521 ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos); 1521 ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos);
1522 if (ret > 0 || ret == -EIOCBQUEUED) { 1522 if (ret > 0) {
1523 ssize_t err; 1523 ssize_t err;
1524 1524
1525 err = generic_write_sync(file, pos, ret); 1525 err = generic_write_sync(file, pos, ret);
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 8e686a427ce2..4d2eb6417145 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1727,7 +1727,7 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
1727 */ 1727 */
1728 BTRFS_I(inode)->last_trans = root->fs_info->generation + 1; 1728 BTRFS_I(inode)->last_trans = root->fs_info->generation + 1;
1729 BTRFS_I(inode)->last_sub_trans = root->log_transid; 1729 BTRFS_I(inode)->last_sub_trans = root->log_transid;
1730 if (num_written > 0 || num_written == -EIOCBQUEUED) { 1730 if (num_written > 0) {
1731 err = generic_write_sync(file, pos, num_written); 1731 err = generic_write_sync(file, pos, num_written);
1732 if (err < 0 && num_written > 0) 1732 if (err < 0 && num_written > 0)
1733 num_written = err; 1733 num_written = err;
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 7e36ae34e947..9d0dd952ad79 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2553,7 +2553,7 @@ cifs_writev(struct kiocb *iocb, const struct iovec *iov,
2553 mutex_unlock(&inode->i_mutex); 2553 mutex_unlock(&inode->i_mutex);
2554 } 2554 }
2555 2555
2556 if (rc > 0 || rc == -EIOCBQUEUED) { 2556 if (rc > 0) {
2557 ssize_t err; 2557 ssize_t err;
2558 2558
2559 err = generic_write_sync(file, pos, rc); 2559 err = generic_write_sync(file, pos, rc);
diff --git a/fs/dcache.c b/fs/dcache.c
index 96655f4f4574..5aa53bc056ba 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -472,7 +472,7 @@ relock:
472 * inform the fs via d_prune that this dentry is about to be 472 * inform the fs via d_prune that this dentry is about to be
473 * unhashed and destroyed. 473 * unhashed and destroyed.
474 */ 474 */
475 if (dentry->d_flags & DCACHE_OP_PRUNE) 475 if ((dentry->d_flags & DCACHE_OP_PRUNE) && !d_unhashed(dentry))
476 dentry->d_op->d_prune(dentry); 476 dentry->d_op->d_prune(dentry);
477 477
478 dentry_lru_del(dentry); 478 dentry_lru_del(dentry);
@@ -727,6 +727,14 @@ restart:
727 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) { 727 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
728 spin_lock(&dentry->d_lock); 728 spin_lock(&dentry->d_lock);
729 if (!dentry->d_lockref.count) { 729 if (!dentry->d_lockref.count) {
730 /*
731 * inform the fs via d_prune that this dentry
732 * is about to be unhashed and destroyed.
733 */
734 if ((dentry->d_flags & DCACHE_OP_PRUNE) &&
735 !d_unhashed(dentry))
736 dentry->d_op->d_prune(dentry);
737
730 __dget_dlock(dentry); 738 __dget_dlock(dentry);
731 __d_drop(dentry); 739 __d_drop(dentry);
732 spin_unlock(&dentry->d_lock); 740 spin_unlock(&dentry->d_lock);
@@ -911,7 +919,8 @@ static void shrink_dcache_for_umount_subtree(struct dentry *dentry)
911 * inform the fs that this dentry is about to be 919 * inform the fs that this dentry is about to be
912 * unhashed and destroyed. 920 * unhashed and destroyed.
913 */ 921 */
914 if (dentry->d_flags & DCACHE_OP_PRUNE) 922 if ((dentry->d_flags & DCACHE_OP_PRUNE) &&
923 !d_unhashed(dentry))
915 dentry->d_op->d_prune(dentry); 924 dentry->d_op->d_prune(dentry);
916 925
917 dentry_lru_del(dentry); 926 dentry_lru_del(dentry);
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 7ab90f5081ee..1782023bd68a 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -127,6 +127,7 @@ struct dio {
127 spinlock_t bio_lock; /* protects BIO fields below */ 127 spinlock_t bio_lock; /* protects BIO fields below */
128 int page_errors; /* errno from get_user_pages() */ 128 int page_errors; /* errno from get_user_pages() */
129 int is_async; /* is IO async ? */ 129 int is_async; /* is IO async ? */
130 bool defer_completion; /* defer AIO completion to workqueue? */
130 int io_error; /* IO error in completion path */ 131 int io_error; /* IO error in completion path */
131 unsigned long refcount; /* direct_io_worker() and bios */ 132 unsigned long refcount; /* direct_io_worker() and bios */
132 struct bio *bio_list; /* singly linked via bi_private */ 133 struct bio *bio_list; /* singly linked via bi_private */
@@ -141,7 +142,10 @@ struct dio {
141 * allocation time. Don't add new fields after pages[] unless you 142 * allocation time. Don't add new fields after pages[] unless you
142 * wish that they not be zeroed. 143 * wish that they not be zeroed.
143 */ 144 */
144 struct page *pages[DIO_PAGES]; /* page buffer */ 145 union {
146 struct page *pages[DIO_PAGES]; /* page buffer */
147 struct work_struct complete_work;/* deferred AIO completion */
148 };
145} ____cacheline_aligned_in_smp; 149} ____cacheline_aligned_in_smp;
146 150
147static struct kmem_cache *dio_cache __read_mostly; 151static struct kmem_cache *dio_cache __read_mostly;
@@ -221,16 +225,16 @@ static inline struct page *dio_get_page(struct dio *dio,
221 * dio_complete() - called when all DIO BIO I/O has been completed 225 * dio_complete() - called when all DIO BIO I/O has been completed
222 * @offset: the byte offset in the file of the completed operation 226 * @offset: the byte offset in the file of the completed operation
223 * 227 *
224 * This releases locks as dictated by the locking type, lets interested parties 228 * This drops i_dio_count, lets interested parties know that a DIO operation
225 * know that a DIO operation has completed, and calculates the resulting return 229 * has completed, and calculates the resulting return code for the operation.
226 * code for the operation.
227 * 230 *
228 * It lets the filesystem know if it registered an interest earlier via 231 * It lets the filesystem know if it registered an interest earlier via
229 * get_block. Pass the private field of the map buffer_head so that 232 * get_block. Pass the private field of the map buffer_head so that
230 * filesystems can use it to hold additional state between get_block calls and 233 * filesystems can use it to hold additional state between get_block calls and
231 * dio_complete. 234 * dio_complete.
232 */ 235 */
233static ssize_t dio_complete(struct dio *dio, loff_t offset, ssize_t ret, bool is_async) 236static ssize_t dio_complete(struct dio *dio, loff_t offset, ssize_t ret,
237 bool is_async)
234{ 238{
235 ssize_t transferred = 0; 239 ssize_t transferred = 0;
236 240
@@ -258,19 +262,36 @@ static ssize_t dio_complete(struct dio *dio, loff_t offset, ssize_t ret, bool is
258 if (ret == 0) 262 if (ret == 0)
259 ret = transferred; 263 ret = transferred;
260 264
261 if (dio->end_io && dio->result) { 265 if (dio->end_io && dio->result)
262 dio->end_io(dio->iocb, offset, transferred, 266 dio->end_io(dio->iocb, offset, transferred, dio->private);
263 dio->private, ret, is_async); 267
264 } else { 268 inode_dio_done(dio->inode);
265 inode_dio_done(dio->inode); 269 if (is_async) {
266 if (is_async) 270 if (dio->rw & WRITE) {
267 aio_complete(dio->iocb, ret, 0); 271 int err;
272
273 err = generic_write_sync(dio->iocb->ki_filp, offset,
274 transferred);
275 if (err < 0 && ret > 0)
276 ret = err;
277 }
278
279 aio_complete(dio->iocb, ret, 0);
268 } 280 }
269 281
282 kmem_cache_free(dio_cache, dio);
270 return ret; 283 return ret;
271} 284}
272 285
286static void dio_aio_complete_work(struct work_struct *work)
287{
288 struct dio *dio = container_of(work, struct dio, complete_work);
289
290 dio_complete(dio, dio->iocb->ki_pos, 0, true);
291}
292
273static int dio_bio_complete(struct dio *dio, struct bio *bio); 293static int dio_bio_complete(struct dio *dio, struct bio *bio);
294
274/* 295/*
275 * Asynchronous IO callback. 296 * Asynchronous IO callback.
276 */ 297 */
@@ -290,8 +311,13 @@ static void dio_bio_end_aio(struct bio *bio, int error)
290 spin_unlock_irqrestore(&dio->bio_lock, flags); 311 spin_unlock_irqrestore(&dio->bio_lock, flags);
291 312
292 if (remaining == 0) { 313 if (remaining == 0) {
293 dio_complete(dio, dio->iocb->ki_pos, 0, true); 314 if (dio->result && dio->defer_completion) {
294 kmem_cache_free(dio_cache, dio); 315 INIT_WORK(&dio->complete_work, dio_aio_complete_work);
316 queue_work(dio->inode->i_sb->s_dio_done_wq,
317 &dio->complete_work);
318 } else {
319 dio_complete(dio, dio->iocb->ki_pos, 0, true);
320 }
295 } 321 }
296} 322}
297 323
@@ -511,6 +537,41 @@ static inline int dio_bio_reap(struct dio *dio, struct dio_submit *sdio)
511} 537}
512 538
513/* 539/*
540 * Create workqueue for deferred direct IO completions. We allocate the
541 * workqueue when it's first needed. This avoids creating workqueue for
542 * filesystems that don't need it and also allows us to create the workqueue
543 * late enough so the we can include s_id in the name of the workqueue.
544 */
545static int sb_init_dio_done_wq(struct super_block *sb)
546{
547 struct workqueue_struct *wq = alloc_workqueue("dio/%s",
548 WQ_MEM_RECLAIM, 0,
549 sb->s_id);
550 if (!wq)
551 return -ENOMEM;
552 /*
553 * This has to be atomic as more DIOs can race to create the workqueue
554 */
555 cmpxchg(&sb->s_dio_done_wq, NULL, wq);
556 /* Someone created workqueue before us? Free ours... */
557 if (wq != sb->s_dio_done_wq)
558 destroy_workqueue(wq);
559 return 0;
560}
561
562static int dio_set_defer_completion(struct dio *dio)
563{
564 struct super_block *sb = dio->inode->i_sb;
565
566 if (dio->defer_completion)
567 return 0;
568 dio->defer_completion = true;
569 if (!sb->s_dio_done_wq)
570 return sb_init_dio_done_wq(sb);
571 return 0;
572}
573
574/*
514 * Call into the fs to map some more disk blocks. We record the current number 575 * Call into the fs to map some more disk blocks. We record the current number
515 * of available blocks at sdio->blocks_available. These are in units of the 576 * of available blocks at sdio->blocks_available. These are in units of the
516 * fs blocksize, (1 << inode->i_blkbits). 577 * fs blocksize, (1 << inode->i_blkbits).
@@ -581,6 +642,9 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio,
581 642
582 /* Store for completion */ 643 /* Store for completion */
583 dio->private = map_bh->b_private; 644 dio->private = map_bh->b_private;
645
646 if (ret == 0 && buffer_defer_completion(map_bh))
647 ret = dio_set_defer_completion(dio);
584 } 648 }
585 return ret; 649 return ret;
586} 650}
@@ -1129,11 +1193,6 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1129 } 1193 }
1130 1194
1131 /* 1195 /*
1132 * Will be decremented at I/O completion time.
1133 */
1134 atomic_inc(&inode->i_dio_count);
1135
1136 /*
1137 * For file extending writes updating i_size before data 1196 * For file extending writes updating i_size before data
1138 * writeouts complete can expose uninitialized blocks. So 1197 * writeouts complete can expose uninitialized blocks. So
1139 * even for AIO, we need to wait for i/o to complete before 1198 * even for AIO, we need to wait for i/o to complete before
@@ -1141,11 +1200,33 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1141 */ 1200 */
1142 dio->is_async = !is_sync_kiocb(iocb) && !((rw & WRITE) && 1201 dio->is_async = !is_sync_kiocb(iocb) && !((rw & WRITE) &&
1143 (end > i_size_read(inode))); 1202 (end > i_size_read(inode)));
1144
1145 retval = 0;
1146
1147 dio->inode = inode; 1203 dio->inode = inode;
1148 dio->rw = rw; 1204 dio->rw = rw;
1205
1206 /*
1207 * For AIO O_(D)SYNC writes we need to defer completions to a workqueue
1208 * so that we can call ->fsync.
1209 */
1210 if (dio->is_async && (rw & WRITE) &&
1211 ((iocb->ki_filp->f_flags & O_DSYNC) ||
1212 IS_SYNC(iocb->ki_filp->f_mapping->host))) {
1213 retval = dio_set_defer_completion(dio);
1214 if (retval) {
1215 /*
1216 * We grab i_mutex only for reads so we don't have
1217 * to release it here
1218 */
1219 kmem_cache_free(dio_cache, dio);
1220 goto out;
1221 }
1222 }
1223
1224 /*
1225 * Will be decremented at I/O completion time.
1226 */
1227 atomic_inc(&inode->i_dio_count);
1228
1229 retval = 0;
1149 sdio.blkbits = blkbits; 1230 sdio.blkbits = blkbits;
1150 sdio.blkfactor = i_blkbits - blkbits; 1231 sdio.blkfactor = i_blkbits - blkbits;
1151 sdio.block_in_file = offset >> blkbits; 1232 sdio.block_in_file = offset >> blkbits;
@@ -1269,7 +1350,6 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1269 1350
1270 if (drop_refcount(dio) == 0) { 1351 if (drop_refcount(dio) == 0) {
1271 retval = dio_complete(dio, offset, retval, false); 1352 retval = dio_complete(dio, offset, retval, false);
1272 kmem_cache_free(dio_cache, dio);
1273 } else 1353 } else
1274 BUG_ON(retval != -EIOCBQUEUED); 1354 BUG_ON(retval != -EIOCBQUEUED);
1275 1355
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 9ad17b15b454..293f86741ddb 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1792,7 +1792,7 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1792{ 1792{
1793 int error; 1793 int error;
1794 int did_lock_epmutex = 0; 1794 int did_lock_epmutex = 0;
1795 struct file *file, *tfile; 1795 struct fd f, tf;
1796 struct eventpoll *ep; 1796 struct eventpoll *ep;
1797 struct epitem *epi; 1797 struct epitem *epi;
1798 struct epoll_event epds; 1798 struct epoll_event epds;
@@ -1802,20 +1802,19 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1802 copy_from_user(&epds, event, sizeof(struct epoll_event))) 1802 copy_from_user(&epds, event, sizeof(struct epoll_event)))
1803 goto error_return; 1803 goto error_return;
1804 1804
1805 /* Get the "struct file *" for the eventpoll file */
1806 error = -EBADF; 1805 error = -EBADF;
1807 file = fget(epfd); 1806 f = fdget(epfd);
1808 if (!file) 1807 if (!f.file)
1809 goto error_return; 1808 goto error_return;
1810 1809
1811 /* Get the "struct file *" for the target file */ 1810 /* Get the "struct file *" for the target file */
1812 tfile = fget(fd); 1811 tf = fdget(fd);
1813 if (!tfile) 1812 if (!tf.file)
1814 goto error_fput; 1813 goto error_fput;
1815 1814
1816 /* The target file descriptor must support poll */ 1815 /* The target file descriptor must support poll */
1817 error = -EPERM; 1816 error = -EPERM;
1818 if (!tfile->f_op || !tfile->f_op->poll) 1817 if (!tf.file->f_op || !tf.file->f_op->poll)
1819 goto error_tgt_fput; 1818 goto error_tgt_fput;
1820 1819
1821 /* Check if EPOLLWAKEUP is allowed */ 1820 /* Check if EPOLLWAKEUP is allowed */
@@ -1828,14 +1827,14 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1828 * adding an epoll file descriptor inside itself. 1827 * adding an epoll file descriptor inside itself.
1829 */ 1828 */
1830 error = -EINVAL; 1829 error = -EINVAL;
1831 if (file == tfile || !is_file_epoll(file)) 1830 if (f.file == tf.file || !is_file_epoll(f.file))
1832 goto error_tgt_fput; 1831 goto error_tgt_fput;
1833 1832
1834 /* 1833 /*
1835 * At this point it is safe to assume that the "private_data" contains 1834 * At this point it is safe to assume that the "private_data" contains
1836 * our own data structure. 1835 * our own data structure.
1837 */ 1836 */
1838 ep = file->private_data; 1837 ep = f.file->private_data;
1839 1838
1840 /* 1839 /*
1841 * When we insert an epoll file descriptor, inside another epoll file 1840 * When we insert an epoll file descriptor, inside another epoll file
@@ -1854,14 +1853,14 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1854 did_lock_epmutex = 1; 1853 did_lock_epmutex = 1;
1855 } 1854 }
1856 if (op == EPOLL_CTL_ADD) { 1855 if (op == EPOLL_CTL_ADD) {
1857 if (is_file_epoll(tfile)) { 1856 if (is_file_epoll(tf.file)) {
1858 error = -ELOOP; 1857 error = -ELOOP;
1859 if (ep_loop_check(ep, tfile) != 0) { 1858 if (ep_loop_check(ep, tf.file) != 0) {
1860 clear_tfile_check_list(); 1859 clear_tfile_check_list();
1861 goto error_tgt_fput; 1860 goto error_tgt_fput;
1862 } 1861 }
1863 } else 1862 } else
1864 list_add(&tfile->f_tfile_llink, &tfile_check_list); 1863 list_add(&tf.file->f_tfile_llink, &tfile_check_list);
1865 } 1864 }
1866 1865
1867 mutex_lock_nested(&ep->mtx, 0); 1866 mutex_lock_nested(&ep->mtx, 0);
@@ -1871,14 +1870,14 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,
1871 * above, we can be sure to be able to use the item looked up by 1870 * above, we can be sure to be able to use the item looked up by
1872 * ep_find() till we release the mutex. 1871 * ep_find() till we release the mutex.
1873 */ 1872 */
1874 epi = ep_find(ep, tfile, fd); 1873 epi = ep_find(ep, tf.file, fd);
1875 1874
1876 error = -EINVAL; 1875 error = -EINVAL;
1877 switch (op) { 1876 switch (op) {
1878 case EPOLL_CTL_ADD: 1877 case EPOLL_CTL_ADD:
1879 if (!epi) { 1878 if (!epi) {
1880 epds.events |= POLLERR | POLLHUP; 1879 epds.events |= POLLERR | POLLHUP;
1881 error = ep_insert(ep, &epds, tfile, fd); 1880 error = ep_insert(ep, &epds, tf.file, fd);
1882 } else 1881 } else
1883 error = -EEXIST; 1882 error = -EEXIST;
1884 clear_tfile_check_list(); 1883 clear_tfile_check_list();
@@ -1903,9 +1902,9 @@ error_tgt_fput:
1903 if (did_lock_epmutex) 1902 if (did_lock_epmutex)
1904 mutex_unlock(&epmutex); 1903 mutex_unlock(&epmutex);
1905 1904
1906 fput(tfile); 1905 fdput(tf);
1907error_fput: 1906error_fput:
1908 fput(file); 1907 fdput(f);
1909error_return: 1908error_return:
1910 1909
1911 return error; 1910 return error;
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 06b488dca666..af815ea9d7cc 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -180,7 +180,6 @@ struct ext4_map_blocks {
180 * Flags for ext4_io_end->flags 180 * Flags for ext4_io_end->flags
181 */ 181 */
182#define EXT4_IO_END_UNWRITTEN 0x0001 182#define EXT4_IO_END_UNWRITTEN 0x0001
183#define EXT4_IO_END_DIRECT 0x0002
184 183
185/* 184/*
186 * For converting uninitialized extents on a work queue. 'handle' is used for 185 * For converting uninitialized extents on a work queue. 'handle' is used for
@@ -196,8 +195,6 @@ typedef struct ext4_io_end {
196 unsigned int flag; /* unwritten or not */ 195 unsigned int flag; /* unwritten or not */
197 loff_t offset; /* offset in the file */ 196 loff_t offset; /* offset in the file */
198 ssize_t size; /* size of the extent */ 197 ssize_t size; /* size of the extent */
199 struct kiocb *iocb; /* iocb struct for AIO */
200 int result; /* error value for AIO */
201 atomic_t count; /* reference counter */ 198 atomic_t count; /* reference counter */
202} ext4_io_end_t; 199} ext4_io_end_t;
203 200
@@ -914,11 +911,9 @@ struct ext4_inode_info {
914 * Completed IOs that need unwritten extents handling and don't have 911 * Completed IOs that need unwritten extents handling and don't have
915 * transaction reserved 912 * transaction reserved
916 */ 913 */
917 struct list_head i_unrsv_conversion_list;
918 atomic_t i_ioend_count; /* Number of outstanding io_end structs */ 914 atomic_t i_ioend_count; /* Number of outstanding io_end structs */
919 atomic_t i_unwritten; /* Nr. of inflight conversions pending */ 915 atomic_t i_unwritten; /* Nr. of inflight conversions pending */
920 struct work_struct i_rsv_conversion_work; 916 struct work_struct i_rsv_conversion_work;
921 struct work_struct i_unrsv_conversion_work;
922 917
923 spinlock_t i_block_reservation_lock; 918 spinlock_t i_block_reservation_lock;
924 919
@@ -1290,8 +1285,6 @@ struct ext4_sb_info {
1290 struct flex_groups *s_flex_groups; 1285 struct flex_groups *s_flex_groups;
1291 ext4_group_t s_flex_groups_allocated; 1286 ext4_group_t s_flex_groups_allocated;
1292 1287
1293 /* workqueue for unreserved extent convertions (dio) */
1294 struct workqueue_struct *unrsv_conversion_wq;
1295 /* workqueue for reserved extent conversions (buffered io) */ 1288 /* workqueue for reserved extent conversions (buffered io) */
1296 struct workqueue_struct *rsv_conversion_wq; 1289 struct workqueue_struct *rsv_conversion_wq;
1297 1290
@@ -1354,9 +1347,6 @@ static inline void ext4_set_io_unwritten_flag(struct inode *inode,
1354 struct ext4_io_end *io_end) 1347 struct ext4_io_end *io_end)
1355{ 1348{
1356 if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) { 1349 if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) {
1357 /* Writeback has to have coversion transaction reserved */
1358 WARN_ON(EXT4_SB(inode->i_sb)->s_journal && !io_end->handle &&
1359 !(io_end->flag & EXT4_IO_END_DIRECT));
1360 io_end->flag |= EXT4_IO_END_UNWRITTEN; 1350 io_end->flag |= EXT4_IO_END_UNWRITTEN;
1361 atomic_inc(&EXT4_I(inode)->i_unwritten); 1351 atomic_inc(&EXT4_I(inode)->i_unwritten);
1362 } 1352 }
@@ -2760,7 +2750,6 @@ extern void ext4_put_io_end_defer(ext4_io_end_t *io_end);
2760extern void ext4_io_submit_init(struct ext4_io_submit *io, 2750extern void ext4_io_submit_init(struct ext4_io_submit *io,
2761 struct writeback_control *wbc); 2751 struct writeback_control *wbc);
2762extern void ext4_end_io_rsv_work(struct work_struct *work); 2752extern void ext4_end_io_rsv_work(struct work_struct *work);
2763extern void ext4_end_io_unrsv_work(struct work_struct *work);
2764extern void ext4_io_submit(struct ext4_io_submit *io); 2753extern void ext4_io_submit(struct ext4_io_submit *io);
2765extern int ext4_bio_write_page(struct ext4_io_submit *io, 2754extern int ext4_bio_write_page(struct ext4_io_submit *io,
2766 struct page *page, 2755 struct page *page,
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 319c9d26279a..3da21945ff1f 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -149,7 +149,7 @@ ext4_file_dio_write(struct kiocb *iocb, const struct iovec *iov,
149 ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos); 149 ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos);
150 mutex_unlock(&inode->i_mutex); 150 mutex_unlock(&inode->i_mutex);
151 151
152 if (ret > 0 || ret == -EIOCBQUEUED) { 152 if (ret > 0) {
153 ssize_t err; 153 ssize_t err;
154 154
155 err = generic_write_sync(file, pos, ret); 155 err = generic_write_sync(file, pos, ret);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 9115f2807515..c79fd7dabe79 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -727,8 +727,12 @@ static int _ext4_get_block(struct inode *inode, sector_t iblock,
727 727
728 ret = ext4_map_blocks(handle, inode, &map, flags); 728 ret = ext4_map_blocks(handle, inode, &map, flags);
729 if (ret > 0) { 729 if (ret > 0) {
730 ext4_io_end_t *io_end = ext4_inode_aio(inode);
731
730 map_bh(bh, inode->i_sb, map.m_pblk); 732 map_bh(bh, inode->i_sb, map.m_pblk);
731 bh->b_state = (bh->b_state & ~EXT4_MAP_FLAGS) | map.m_flags; 733 bh->b_state = (bh->b_state & ~EXT4_MAP_FLAGS) | map.m_flags;
734 if (io_end && io_end->flag & EXT4_IO_END_UNWRITTEN)
735 set_buffer_defer_completion(bh);
732 bh->b_size = inode->i_sb->s_blocksize * map.m_len; 736 bh->b_size = inode->i_sb->s_blocksize * map.m_len;
733 ret = 0; 737 ret = 0;
734 } 738 }
@@ -3024,19 +3028,13 @@ static int ext4_get_block_write_nolock(struct inode *inode, sector_t iblock,
3024} 3028}
3025 3029
3026static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset, 3030static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
3027 ssize_t size, void *private, int ret, 3031 ssize_t size, void *private)
3028 bool is_async)
3029{ 3032{
3030 struct inode *inode = file_inode(iocb->ki_filp);
3031 ext4_io_end_t *io_end = iocb->private; 3033 ext4_io_end_t *io_end = iocb->private;
3032 3034
3033 /* if not async direct IO just return */ 3035 /* if not async direct IO just return */
3034 if (!io_end) { 3036 if (!io_end)
3035 inode_dio_done(inode);
3036 if (is_async)
3037 aio_complete(iocb, ret, 0);
3038 return; 3037 return;
3039 }
3040 3038
3041 ext_debug("ext4_end_io_dio(): io_end 0x%p " 3039 ext_debug("ext4_end_io_dio(): io_end 0x%p "
3042 "for inode %lu, iocb 0x%p, offset %llu, size %zd\n", 3040 "for inode %lu, iocb 0x%p, offset %llu, size %zd\n",
@@ -3046,11 +3044,7 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
3046 iocb->private = NULL; 3044 iocb->private = NULL;
3047 io_end->offset = offset; 3045 io_end->offset = offset;
3048 io_end->size = size; 3046 io_end->size = size;
3049 if (is_async) { 3047 ext4_put_io_end(io_end);
3050 io_end->iocb = iocb;
3051 io_end->result = ret;
3052 }
3053 ext4_put_io_end_defer(io_end);
3054} 3048}
3055 3049
3056/* 3050/*
@@ -3135,7 +3129,6 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
3135 ret = -ENOMEM; 3129 ret = -ENOMEM;
3136 goto retake_lock; 3130 goto retake_lock;
3137 } 3131 }
3138 io_end->flag |= EXT4_IO_END_DIRECT;
3139 /* 3132 /*
3140 * Grab reference for DIO. Will be dropped in ext4_end_io_dio() 3133 * Grab reference for DIO. Will be dropped in ext4_end_io_dio()
3141 */ 3134 */
@@ -3180,13 +3173,6 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
3180 if (ret <= 0 && ret != -EIOCBQUEUED && iocb->private) { 3173 if (ret <= 0 && ret != -EIOCBQUEUED && iocb->private) {
3181 WARN_ON(iocb->private != io_end); 3174 WARN_ON(iocb->private != io_end);
3182 WARN_ON(io_end->flag & EXT4_IO_END_UNWRITTEN); 3175 WARN_ON(io_end->flag & EXT4_IO_END_UNWRITTEN);
3183 WARN_ON(io_end->iocb);
3184 /*
3185 * Generic code already did inode_dio_done() so we
3186 * have to clear EXT4_IO_END_DIRECT to not do it for
3187 * the second time.
3188 */
3189 io_end->flag = 0;
3190 ext4_put_io_end(io_end); 3176 ext4_put_io_end(io_end);
3191 iocb->private = NULL; 3177 iocb->private = NULL;
3192 } 3178 }
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 6625d210fb45..d7d0c7b46ed4 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -123,10 +123,6 @@ static void ext4_release_io_end(ext4_io_end_t *io_end)
123 ext4_finish_bio(bio); 123 ext4_finish_bio(bio);
124 bio_put(bio); 124 bio_put(bio);
125 } 125 }
126 if (io_end->flag & EXT4_IO_END_DIRECT)
127 inode_dio_done(io_end->inode);
128 if (io_end->iocb)
129 aio_complete(io_end->iocb, io_end->result, 0);
130 kmem_cache_free(io_end_cachep, io_end); 126 kmem_cache_free(io_end_cachep, io_end);
131} 127}
132 128
@@ -204,19 +200,14 @@ static void ext4_add_complete_io(ext4_io_end_t *io_end)
204 struct workqueue_struct *wq; 200 struct workqueue_struct *wq;
205 unsigned long flags; 201 unsigned long flags;
206 202
207 BUG_ON(!(io_end->flag & EXT4_IO_END_UNWRITTEN)); 203 /* Only reserved conversions from writeback should enter here */
204 WARN_ON(!(io_end->flag & EXT4_IO_END_UNWRITTEN));
205 WARN_ON(!io_end->handle);
208 spin_lock_irqsave(&ei->i_completed_io_lock, flags); 206 spin_lock_irqsave(&ei->i_completed_io_lock, flags);
209 if (io_end->handle) { 207 wq = EXT4_SB(io_end->inode->i_sb)->rsv_conversion_wq;
210 wq = EXT4_SB(io_end->inode->i_sb)->rsv_conversion_wq; 208 if (list_empty(&ei->i_rsv_conversion_list))
211 if (list_empty(&ei->i_rsv_conversion_list)) 209 queue_work(wq, &ei->i_rsv_conversion_work);
212 queue_work(wq, &ei->i_rsv_conversion_work); 210 list_add_tail(&io_end->list, &ei->i_rsv_conversion_list);
213 list_add_tail(&io_end->list, &ei->i_rsv_conversion_list);
214 } else {
215 wq = EXT4_SB(io_end->inode->i_sb)->unrsv_conversion_wq;
216 if (list_empty(&ei->i_unrsv_conversion_list))
217 queue_work(wq, &ei->i_unrsv_conversion_work);
218 list_add_tail(&io_end->list, &ei->i_unrsv_conversion_list);
219 }
220 spin_unlock_irqrestore(&ei->i_completed_io_lock, flags); 211 spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
221} 212}
222 213
@@ -256,13 +247,6 @@ void ext4_end_io_rsv_work(struct work_struct *work)
256 ext4_do_flush_completed_IO(&ei->vfs_inode, &ei->i_rsv_conversion_list); 247 ext4_do_flush_completed_IO(&ei->vfs_inode, &ei->i_rsv_conversion_list);
257} 248}
258 249
259void ext4_end_io_unrsv_work(struct work_struct *work)
260{
261 struct ext4_inode_info *ei = container_of(work, struct ext4_inode_info,
262 i_unrsv_conversion_work);
263 ext4_do_flush_completed_IO(&ei->vfs_inode, &ei->i_unrsv_conversion_list);
264}
265
266ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags) 250ext4_io_end_t *ext4_init_io_end(struct inode *inode, gfp_t flags)
267{ 251{
268 ext4_io_end_t *io = kmem_cache_zalloc(io_end_cachep, flags); 252 ext4_io_end_t *io = kmem_cache_zalloc(io_end_cachep, flags);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 42337141e79f..049c8a8bdc0e 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -762,9 +762,7 @@ static void ext4_put_super(struct super_block *sb)
762 ext4_unregister_li_request(sb); 762 ext4_unregister_li_request(sb);
763 dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); 763 dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
764 764
765 flush_workqueue(sbi->unrsv_conversion_wq);
766 flush_workqueue(sbi->rsv_conversion_wq); 765 flush_workqueue(sbi->rsv_conversion_wq);
767 destroy_workqueue(sbi->unrsv_conversion_wq);
768 destroy_workqueue(sbi->rsv_conversion_wq); 766 destroy_workqueue(sbi->rsv_conversion_wq);
769 767
770 if (sbi->s_journal) { 768 if (sbi->s_journal) {
@@ -875,14 +873,12 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
875#endif 873#endif
876 ei->jinode = NULL; 874 ei->jinode = NULL;
877 INIT_LIST_HEAD(&ei->i_rsv_conversion_list); 875 INIT_LIST_HEAD(&ei->i_rsv_conversion_list);
878 INIT_LIST_HEAD(&ei->i_unrsv_conversion_list);
879 spin_lock_init(&ei->i_completed_io_lock); 876 spin_lock_init(&ei->i_completed_io_lock);
880 ei->i_sync_tid = 0; 877 ei->i_sync_tid = 0;
881 ei->i_datasync_tid = 0; 878 ei->i_datasync_tid = 0;
882 atomic_set(&ei->i_ioend_count, 0); 879 atomic_set(&ei->i_ioend_count, 0);
883 atomic_set(&ei->i_unwritten, 0); 880 atomic_set(&ei->i_unwritten, 0);
884 INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); 881 INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work);
885 INIT_WORK(&ei->i_unrsv_conversion_work, ext4_end_io_unrsv_work);
886 882
887 return &ei->vfs_inode; 883 return &ei->vfs_inode;
888} 884}
@@ -3995,14 +3991,6 @@ no_journal:
3995 goto failed_mount4; 3991 goto failed_mount4;
3996 } 3992 }
3997 3993
3998 EXT4_SB(sb)->unrsv_conversion_wq =
3999 alloc_workqueue("ext4-unrsv-conversion", WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
4000 if (!EXT4_SB(sb)->unrsv_conversion_wq) {
4001 printk(KERN_ERR "EXT4-fs: failed to create workqueue\n");
4002 ret = -ENOMEM;
4003 goto failed_mount4;
4004 }
4005
4006 /* 3994 /*
4007 * The jbd2_journal_load will have done any necessary log recovery, 3995 * The jbd2_journal_load will have done any necessary log recovery,
4008 * so we can safely mount the rest of the filesystem now. 3996 * so we can safely mount the rest of the filesystem now.
@@ -4156,8 +4144,6 @@ failed_mount4:
4156 ext4_msg(sb, KERN_ERR, "mount failed"); 4144 ext4_msg(sb, KERN_ERR, "mount failed");
4157 if (EXT4_SB(sb)->rsv_conversion_wq) 4145 if (EXT4_SB(sb)->rsv_conversion_wq)
4158 destroy_workqueue(EXT4_SB(sb)->rsv_conversion_wq); 4146 destroy_workqueue(EXT4_SB(sb)->rsv_conversion_wq);
4159 if (EXT4_SB(sb)->unrsv_conversion_wq)
4160 destroy_workqueue(EXT4_SB(sb)->unrsv_conversion_wq);
4161failed_mount_wq: 4147failed_mount_wq:
4162 if (sbi->s_journal) { 4148 if (sbi->s_journal) {
4163 jbd2_journal_destroy(sbi->s_journal); 4149 jbd2_journal_destroy(sbi->s_journal);
@@ -4605,7 +4591,6 @@ static int ext4_sync_fs(struct super_block *sb, int wait)
4605 4591
4606 trace_ext4_sync_fs(sb, wait); 4592 trace_ext4_sync_fs(sb, wait);
4607 flush_workqueue(sbi->rsv_conversion_wq); 4593 flush_workqueue(sbi->rsv_conversion_wq);
4608 flush_workqueue(sbi->unrsv_conversion_wq);
4609 /* 4594 /*
4610 * Writeback quota in non-journalled quota case - journalled quota has 4595 * Writeback quota in non-journalled quota case - journalled quota has
4611 * no dirty dquots 4596 * no dirty dquots
@@ -4641,7 +4626,6 @@ static int ext4_sync_fs_nojournal(struct super_block *sb, int wait)
4641 4626
4642 trace_ext4_sync_fs(sb, wait); 4627 trace_ext4_sync_fs(sb, wait);
4643 flush_workqueue(EXT4_SB(sb)->rsv_conversion_wq); 4628 flush_workqueue(EXT4_SB(sb)->rsv_conversion_wq);
4644 flush_workqueue(EXT4_SB(sb)->unrsv_conversion_wq);
4645 dquot_writeback_dquots(sb, -1); 4629 dquot_writeback_dquots(sb, -1);
4646 if (wait && test_opt(sb, BARRIER)) 4630 if (wait && test_opt(sb, BARRIER))
4647 ret = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL); 4631 ret = blkdev_issue_flush(sb->s_bdev, GFP_KERNEL, NULL);
diff --git a/fs/file_table.c b/fs/file_table.c
index b44e4c559786..322cd37626cb 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -385,6 +385,10 @@ static inline void __file_sb_list_add(struct file *file, struct super_block *sb)
385 */ 385 */
386void file_sb_list_add(struct file *file, struct super_block *sb) 386void file_sb_list_add(struct file *file, struct super_block *sb)
387{ 387{
388 if (likely(!(file->f_mode & FMODE_WRITE)))
389 return;
390 if (!S_ISREG(file_inode(file)->i_mode))
391 return;
388 lg_local_lock(&files_lglock); 392 lg_local_lock(&files_lglock);
389 __file_sb_list_add(file, sb); 393 __file_sb_list_add(file, sb);
390 lg_local_unlock(&files_lglock); 394 lg_local_unlock(&files_lglock);
@@ -450,8 +454,6 @@ void mark_files_ro(struct super_block *sb)
450 454
451 lg_global_lock(&files_lglock); 455 lg_global_lock(&files_lglock);
452 do_file_list_for_each_entry(sb, f) { 456 do_file_list_for_each_entry(sb, f) {
453 if (!S_ISREG(file_inode(f)->i_mode))
454 continue;
455 if (!file_count(f)) 457 if (!file_count(f))
456 continue; 458 continue;
457 if (!(f->f_mode & FMODE_WRITE)) 459 if (!(f->f_mode & FMODE_WRITE))
diff --git a/fs/inode.c b/fs/inode.c
index d6dfb09c8280..93a0625b46e4 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1525,7 +1525,7 @@ static int update_time(struct inode *inode, struct timespec *time, int flags)
1525 * This function automatically handles read only file systems and media, 1525 * This function automatically handles read only file systems and media,
1526 * as well as the "noatime" flag and inode specific "noatime" markers. 1526 * as well as the "noatime" flag and inode specific "noatime" markers.
1527 */ 1527 */
1528void touch_atime(struct path *path) 1528void touch_atime(const struct path *path)
1529{ 1529{
1530 struct vfsmount *mnt = path->mnt; 1530 struct vfsmount *mnt = path->mnt;
1531 struct inode *inode = path->dentry->d_inode; 1531 struct inode *inode = path->dentry->d_inode;
diff --git a/fs/namei.c b/fs/namei.c
index 2c30c84d4ea1..f415c6683a83 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2222,6 +2222,188 @@ user_path_parent(int dfd, const char __user *path, struct nameidata *nd,
2222 return s; 2222 return s;
2223} 2223}
2224 2224
2225/**
2226 * umount_lookup_last - look up last component for umount
2227 * @nd: pathwalk nameidata - currently pointing at parent directory of "last"
2228 * @path: pointer to container for result
2229 *
2230 * This is a special lookup_last function just for umount. In this case, we
2231 * need to resolve the path without doing any revalidation.
2232 *
2233 * The nameidata should be the result of doing a LOOKUP_PARENT pathwalk. Since
2234 * mountpoints are always pinned in the dcache, their ancestors are too. Thus,
2235 * in almost all cases, this lookup will be served out of the dcache. The only
2236 * cases where it won't are if nd->last refers to a symlink or the path is
2237 * bogus and it doesn't exist.
2238 *
2239 * Returns:
2240 * -error: if there was an error during lookup. This includes -ENOENT if the
2241 * lookup found a negative dentry. The nd->path reference will also be
2242 * put in this case.
2243 *
2244 * 0: if we successfully resolved nd->path and found it to not to be a
2245 * symlink that needs to be followed. "path" will also be populated.
2246 * The nd->path reference will also be put.
2247 *
2248 * 1: if we successfully resolved nd->last and found it to be a symlink
2249 * that needs to be followed. "path" will be populated with the path
2250 * to the link, and nd->path will *not* be put.
2251 */
2252static int
2253umount_lookup_last(struct nameidata *nd, struct path *path)
2254{
2255 int error = 0;
2256 struct dentry *dentry;
2257 struct dentry *dir = nd->path.dentry;
2258
2259 if (unlikely(nd->flags & LOOKUP_RCU)) {
2260 WARN_ON_ONCE(1);
2261 error = -ECHILD;
2262 goto error_check;
2263 }
2264
2265 nd->flags &= ~LOOKUP_PARENT;
2266
2267 if (unlikely(nd->last_type != LAST_NORM)) {
2268 error = handle_dots(nd, nd->last_type);
2269 if (!error)
2270 dentry = dget(nd->path.dentry);
2271 goto error_check;
2272 }
2273
2274 mutex_lock(&dir->d_inode->i_mutex);
2275 dentry = d_lookup(dir, &nd->last);
2276 if (!dentry) {
2277 /*
2278 * No cached dentry. Mounted dentries are pinned in the cache,
2279 * so that means that this dentry is probably a symlink or the
2280 * path doesn't actually point to a mounted dentry.
2281 */
2282 dentry = d_alloc(dir, &nd->last);
2283 if (!dentry) {
2284 error = -ENOMEM;
2285 } else {
2286 dentry = lookup_real(dir->d_inode, dentry, nd->flags);
2287 if (IS_ERR(dentry))
2288 error = PTR_ERR(dentry);
2289 }
2290 }
2291 mutex_unlock(&dir->d_inode->i_mutex);
2292
2293error_check:
2294 if (!error) {
2295 if (!dentry->d_inode) {
2296 error = -ENOENT;
2297 dput(dentry);
2298 } else {
2299 path->dentry = dentry;
2300 path->mnt = mntget(nd->path.mnt);
2301 if (should_follow_link(dentry->d_inode,
2302 nd->flags & LOOKUP_FOLLOW))
2303 return 1;
2304 follow_mount(path);
2305 }
2306 }
2307 terminate_walk(nd);
2308 return error;
2309}
2310
2311/**
2312 * path_umountat - look up a path to be umounted
2313 * @dfd: directory file descriptor to start walk from
2314 * @name: full pathname to walk
2315 * @flags: lookup flags
2316 * @nd: pathwalk nameidata
2317 *
2318 * Look up the given name, but don't attempt to revalidate the last component.
2319 * Returns 0 and "path" will be valid on success; Retuns error otherwise.
2320 */
2321static int
2322path_umountat(int dfd, const char *name, struct path *path, unsigned int flags)
2323{
2324 struct file *base = NULL;
2325 struct nameidata nd;
2326 int err;
2327
2328 err = path_init(dfd, name, flags | LOOKUP_PARENT, &nd, &base);
2329 if (unlikely(err))
2330 return err;
2331
2332 current->total_link_count = 0;
2333 err = link_path_walk(name, &nd);
2334 if (err)
2335 goto out;
2336
2337 /* If we're in rcuwalk, drop out of it to handle last component */
2338 if (nd.flags & LOOKUP_RCU) {
2339 err = unlazy_walk(&nd, NULL);
2340 if (err) {
2341 terminate_walk(&nd);
2342 goto out;
2343 }
2344 }
2345
2346 err = umount_lookup_last(&nd, path);
2347 while (err > 0) {
2348 void *cookie;
2349 struct path link = *path;
2350 err = may_follow_link(&link, &nd);
2351 if (unlikely(err))
2352 break;
2353 nd.flags |= LOOKUP_PARENT;
2354 err = follow_link(&link, &nd, &cookie);
2355 if (err)
2356 break;
2357 err = umount_lookup_last(&nd, path);
2358 put_link(&nd, &link, cookie);
2359 }
2360out:
2361 if (base)
2362 fput(base);
2363
2364 if (nd.root.mnt && !(nd.flags & LOOKUP_ROOT))
2365 path_put(&nd.root);
2366
2367 return err;
2368}
2369
2370/**
2371 * user_path_umountat - lookup a path from userland in order to umount it
2372 * @dfd: directory file descriptor
2373 * @name: pathname from userland
2374 * @flags: lookup flags
2375 * @path: pointer to container to hold result
2376 *
2377 * A umount is a special case for path walking. We're not actually interested
2378 * in the inode in this situation, and ESTALE errors can be a problem. We
2379 * simply want track down the dentry and vfsmount attached at the mountpoint
2380 * and avoid revalidating the last component.
2381 *
2382 * Returns 0 and populates "path" on success.
2383 */
2384int
2385user_path_umountat(int dfd, const char __user *name, unsigned int flags,
2386 struct path *path)
2387{
2388 struct filename *s = getname(name);
2389 int error;
2390
2391 if (IS_ERR(s))
2392 return PTR_ERR(s);
2393
2394 error = path_umountat(dfd, s->name, path, flags | LOOKUP_RCU);
2395 if (unlikely(error == -ECHILD))
2396 error = path_umountat(dfd, s->name, path, flags);
2397 if (unlikely(error == -ESTALE))
2398 error = path_umountat(dfd, s->name, path, flags | LOOKUP_REVAL);
2399
2400 if (likely(!error))
2401 audit_inode(s, path->dentry, 0);
2402
2403 putname(s);
2404 return error;
2405}
2406
2225/* 2407/*
2226 * It's inline, so penalty for filesystems that don't use sticky bit is 2408 * It's inline, so penalty for filesystems that don't use sticky bit is
2227 * minimal. 2409 * minimal.
diff --git a/fs/namespace.c b/fs/namespace.c
index a45ba4f267fe..ad8ea9bc2518 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1318,7 +1318,7 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
1318 if (!(flags & UMOUNT_NOFOLLOW)) 1318 if (!(flags & UMOUNT_NOFOLLOW))
1319 lookup_flags |= LOOKUP_FOLLOW; 1319 lookup_flags |= LOOKUP_FOLLOW;
1320 1320
1321 retval = user_path_at(AT_FDCWD, name, lookup_flags, &path); 1321 retval = user_path_umountat(AT_FDCWD, name, lookup_flags, &path);
1322 if (retval) 1322 if (retval)
1323 goto out; 1323 goto out;
1324 mnt = real_mount(path.mnt); 1324 mnt = real_mount(path.mnt);
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index c2a4701d7286..d9454fe5653f 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -1816,10 +1816,7 @@ static __be32 nfsd4_encode_fs_location4(struct nfsd4_fs_location *location,
1816static __be32 nfsd4_encode_path(const struct path *root, 1816static __be32 nfsd4_encode_path(const struct path *root,
1817 const struct path *path, __be32 **pp, int *buflen) 1817 const struct path *path, __be32 **pp, int *buflen)
1818{ 1818{
1819 struct path cur = { 1819 struct path cur = *path;
1820 .mnt = path->mnt,
1821 .dentry = path->dentry,
1822 };
1823 __be32 *p = *pp; 1820 __be32 *p = *pp;
1824 struct dentry **components = NULL; 1821 struct dentry **components = NULL;
1825 unsigned int ncomponents = 0; 1822 unsigned int ncomponents = 0;
@@ -1859,14 +1856,19 @@ static __be32 nfsd4_encode_path(const struct path *root,
1859 1856
1860 while (ncomponents) { 1857 while (ncomponents) {
1861 struct dentry *dentry = components[ncomponents - 1]; 1858 struct dentry *dentry = components[ncomponents - 1];
1862 unsigned int len = dentry->d_name.len; 1859 unsigned int len;
1863 1860
1861 spin_lock(&dentry->d_lock);
1862 len = dentry->d_name.len;
1864 *buflen -= 4 + (XDR_QUADLEN(len) << 2); 1863 *buflen -= 4 + (XDR_QUADLEN(len) << 2);
1865 if (*buflen < 0) 1864 if (*buflen < 0) {
1865 spin_unlock(&dentry->d_lock);
1866 goto out_free; 1866 goto out_free;
1867 }
1867 WRITE32(len); 1868 WRITE32(len);
1868 WRITEMEM(dentry->d_name.name, len); 1869 WRITEMEM(dentry->d_name.name, len);
1869 dprintk("/%s", dentry->d_name.name); 1870 dprintk("/%s", dentry->d_name.name);
1871 spin_unlock(&dentry->d_lock);
1870 dput(dentry); 1872 dput(dentry);
1871 ncomponents--; 1873 ncomponents--;
1872 } 1874 }
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index af3ba0478cdf..7ac2a122ca1d 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -994,23 +994,16 @@ static int nilfs_attach_snapshot(struct super_block *s, __u64 cno,
994 return ret; 994 return ret;
995} 995}
996 996
997static int nilfs_tree_was_touched(struct dentry *root_dentry)
998{
999 return d_count(root_dentry) > 1;
1000}
1001
1002/** 997/**
1003 * nilfs_try_to_shrink_tree() - try to shrink dentries of a checkpoint 998 * nilfs_tree_is_busy() - try to shrink dentries of a checkpoint
1004 * @root_dentry: root dentry of the tree to be shrunk 999 * @root_dentry: root dentry of the tree to be shrunk
1005 * 1000 *
1006 * This function returns true if the tree was in-use. 1001 * This function returns true if the tree was in-use.
1007 */ 1002 */
1008static int nilfs_try_to_shrink_tree(struct dentry *root_dentry) 1003static bool nilfs_tree_is_busy(struct dentry *root_dentry)
1009{ 1004{
1010 if (have_submounts(root_dentry))
1011 return true;
1012 shrink_dcache_parent(root_dentry); 1005 shrink_dcache_parent(root_dentry);
1013 return nilfs_tree_was_touched(root_dentry); 1006 return d_count(root_dentry) > 1;
1014} 1007}
1015 1008
1016int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno) 1009int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno)
@@ -1034,8 +1027,7 @@ int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno)
1034 if (inode) { 1027 if (inode) {
1035 dentry = d_find_alias(inode); 1028 dentry = d_find_alias(inode);
1036 if (dentry) { 1029 if (dentry) {
1037 if (nilfs_tree_was_touched(dentry)) 1030 ret = nilfs_tree_is_busy(dentry);
1038 ret = nilfs_try_to_shrink_tree(dentry);
1039 dput(dentry); 1031 dput(dentry);
1040 } 1032 }
1041 iput(inode); 1033 iput(inode);
@@ -1331,11 +1323,8 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
1331 1323
1332 s->s_flags |= MS_ACTIVE; 1324 s->s_flags |= MS_ACTIVE;
1333 } else if (!sd.cno) { 1325 } else if (!sd.cno) {
1334 int busy = false; 1326 if (nilfs_tree_is_busy(s->s_root)) {
1335 1327 if ((flags ^ s->s_flags) & MS_RDONLY) {
1336 if (nilfs_tree_was_touched(s->s_root)) {
1337 busy = nilfs_try_to_shrink_tree(s->s_root);
1338 if (busy && (flags ^ s->s_flags) & MS_RDONLY) {
1339 printk(KERN_ERR "NILFS: the device already " 1328 printk(KERN_ERR "NILFS: the device already "
1340 "has a %s mount.\n", 1329 "has a %s mount.\n",
1341 (s->s_flags & MS_RDONLY) ? 1330 (s->s_flags & MS_RDONLY) ?
@@ -1343,8 +1332,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
1343 err = -EBUSY; 1332 err = -EBUSY;
1344 goto failed_super; 1333 goto failed_super;
1345 } 1334 }
1346 } 1335 } else {
1347 if (!busy) {
1348 /* 1336 /*
1349 * Try remount to setup mount states if the current 1337 * Try remount to setup mount states if the current
1350 * tree is not mounted and only snapshots use this sb. 1338 * tree is not mounted and only snapshots use this sb.
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 2abf97b2a592..94417a85ce6e 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -565,9 +565,7 @@ bail:
565static void ocfs2_dio_end_io(struct kiocb *iocb, 565static void ocfs2_dio_end_io(struct kiocb *iocb,
566 loff_t offset, 566 loff_t offset,
567 ssize_t bytes, 567 ssize_t bytes,
568 void *private, 568 void *private)
569 int ret,
570 bool is_async)
571{ 569{
572 struct inode *inode = file_inode(iocb->ki_filp); 570 struct inode *inode = file_inode(iocb->ki_filp);
573 int level; 571 int level;
@@ -592,10 +590,6 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
592 590
593 level = ocfs2_iocb_rw_locked_level(iocb); 591 level = ocfs2_iocb_rw_locked_level(iocb);
594 ocfs2_rw_unlock(inode, level); 592 ocfs2_rw_unlock(inode, level);
595
596 inode_dio_done(inode);
597 if (is_async)
598 aio_complete(iocb, ret, 0);
599} 593}
600 594
601/* 595/*
diff --git a/fs/open.c b/fs/open.c
index 7931f76acc2b..8070825b285b 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -485,14 +485,13 @@ out_unlock:
485 485
486SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode) 486SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
487{ 487{
488 struct file * file; 488 struct fd f = fdget(fd);
489 int err = -EBADF; 489 int err = -EBADF;
490 490
491 file = fget(fd); 491 if (f.file) {
492 if (file) { 492 audit_inode(NULL, f.file->f_path.dentry, 0);
493 audit_inode(NULL, file->f_path.dentry, 0); 493 err = chmod_common(&f.file->f_path, mode);
494 err = chmod_common(&file->f_path, mode); 494 fdput(f);
495 fput(file);
496 } 495 }
497 return err; 496 return err;
498} 497}
diff --git a/fs/super.c b/fs/super.c
index 68307c029228..5536a95186e2 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -152,15 +152,9 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags)
152 static const struct super_operations default_op; 152 static const struct super_operations default_op;
153 153
154 if (s) { 154 if (s) {
155 if (security_sb_alloc(s)) { 155 if (security_sb_alloc(s))
156 /* 156 goto out_free_sb;
157 * We cannot call security_sb_free() without 157
158 * security_sb_alloc() succeeding. So bail out manually
159 */
160 kfree(s);
161 s = NULL;
162 goto out;
163 }
164#ifdef CONFIG_SMP 158#ifdef CONFIG_SMP
165 s->s_files = alloc_percpu(struct list_head); 159 s->s_files = alloc_percpu(struct list_head);
166 if (!s->s_files) 160 if (!s->s_files)
@@ -228,6 +222,7 @@ err_out:
228 free_percpu(s->s_files); 222 free_percpu(s->s_files);
229#endif 223#endif
230 destroy_sb_writers(s); 224 destroy_sb_writers(s);
225out_free_sb:
231 kfree(s); 226 kfree(s);
232 s = NULL; 227 s = NULL;
233 goto out; 228 goto out;
@@ -414,6 +409,11 @@ void generic_shutdown_super(struct super_block *sb)
414 409
415 evict_inodes(sb); 410 evict_inodes(sb);
416 411
412 if (sb->s_dio_done_wq) {
413 destroy_workqueue(sb->s_dio_done_wq);
414 sb->s_dio_done_wq = NULL;
415 }
416
417 if (sop->put_super) 417 if (sop->put_super)
418 sop->put_super(sb); 418 sop->put_super(sb);
419 419
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 596ec71da00e..e11d654af786 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -86,14 +86,6 @@ xfs_destroy_ioend(
86 bh->b_end_io(bh, !ioend->io_error); 86 bh->b_end_io(bh, !ioend->io_error);
87 } 87 }
88 88
89 if (ioend->io_iocb) {
90 inode_dio_done(ioend->io_inode);
91 if (ioend->io_isasync) {
92 aio_complete(ioend->io_iocb, ioend->io_error ?
93 ioend->io_error : ioend->io_result, 0);
94 }
95 }
96
97 mempool_free(ioend, xfs_ioend_pool); 89 mempool_free(ioend, xfs_ioend_pool);
98} 90}
99 91
@@ -281,7 +273,6 @@ xfs_alloc_ioend(
281 * all the I/O from calling the completion routine too early. 273 * all the I/O from calling the completion routine too early.
282 */ 274 */
283 atomic_set(&ioend->io_remaining, 1); 275 atomic_set(&ioend->io_remaining, 1);
284 ioend->io_isasync = 0;
285 ioend->io_isdirect = 0; 276 ioend->io_isdirect = 0;
286 ioend->io_error = 0; 277 ioend->io_error = 0;
287 ioend->io_list = NULL; 278 ioend->io_list = NULL;
@@ -291,8 +282,6 @@ xfs_alloc_ioend(
291 ioend->io_buffer_tail = NULL; 282 ioend->io_buffer_tail = NULL;
292 ioend->io_offset = 0; 283 ioend->io_offset = 0;
293 ioend->io_size = 0; 284 ioend->io_size = 0;
294 ioend->io_iocb = NULL;
295 ioend->io_result = 0;
296 ioend->io_append_trans = NULL; 285 ioend->io_append_trans = NULL;
297 286
298 INIT_WORK(&ioend->io_work, xfs_end_io); 287 INIT_WORK(&ioend->io_work, xfs_end_io);
@@ -1292,8 +1281,10 @@ __xfs_get_blocks(
1292 if (create || !ISUNWRITTEN(&imap)) 1281 if (create || !ISUNWRITTEN(&imap))
1293 xfs_map_buffer(inode, bh_result, &imap, offset); 1282 xfs_map_buffer(inode, bh_result, &imap, offset);
1294 if (create && ISUNWRITTEN(&imap)) { 1283 if (create && ISUNWRITTEN(&imap)) {
1295 if (direct) 1284 if (direct) {
1296 bh_result->b_private = inode; 1285 bh_result->b_private = inode;
1286 set_buffer_defer_completion(bh_result);
1287 }
1297 set_buffer_unwritten(bh_result); 1288 set_buffer_unwritten(bh_result);
1298 } 1289 }
1299 } 1290 }
@@ -1390,9 +1381,7 @@ xfs_end_io_direct_write(
1390 struct kiocb *iocb, 1381 struct kiocb *iocb,
1391 loff_t offset, 1382 loff_t offset,
1392 ssize_t size, 1383 ssize_t size,
1393 void *private, 1384 void *private)
1394 int ret,
1395 bool is_async)
1396{ 1385{
1397 struct xfs_ioend *ioend = iocb->private; 1386 struct xfs_ioend *ioend = iocb->private;
1398 1387
@@ -1414,17 +1403,10 @@ xfs_end_io_direct_write(
1414 1403
1415 ioend->io_offset = offset; 1404 ioend->io_offset = offset;
1416 ioend->io_size = size; 1405 ioend->io_size = size;
1417 ioend->io_iocb = iocb;
1418 ioend->io_result = ret;
1419 if (private && size > 0) 1406 if (private && size > 0)
1420 ioend->io_type = XFS_IO_UNWRITTEN; 1407 ioend->io_type = XFS_IO_UNWRITTEN;
1421 1408
1422 if (is_async) { 1409 xfs_finish_ioend_sync(ioend);
1423 ioend->io_isasync = 1;
1424 xfs_finish_ioend(ioend);
1425 } else {
1426 xfs_finish_ioend_sync(ioend);
1427 }
1428} 1410}
1429 1411
1430STATIC ssize_t 1412STATIC ssize_t
diff --git a/fs/xfs/xfs_aops.h b/fs/xfs/xfs_aops.h
index c325abb8d61a..f94dd459dff9 100644
--- a/fs/xfs/xfs_aops.h
+++ b/fs/xfs/xfs_aops.h
@@ -45,7 +45,6 @@ typedef struct xfs_ioend {
45 unsigned int io_type; /* delalloc / unwritten */ 45 unsigned int io_type; /* delalloc / unwritten */
46 int io_error; /* I/O error code */ 46 int io_error; /* I/O error code */
47 atomic_t io_remaining; /* hold count */ 47 atomic_t io_remaining; /* hold count */
48 unsigned int io_isasync : 1; /* needs aio_complete */
49 unsigned int io_isdirect : 1;/* direct I/O */ 48 unsigned int io_isdirect : 1;/* direct I/O */
50 struct inode *io_inode; /* file being written to */ 49 struct inode *io_inode; /* file being written to */
51 struct buffer_head *io_buffer_head;/* buffer linked list head */ 50 struct buffer_head *io_buffer_head;/* buffer linked list head */
@@ -54,8 +53,6 @@ typedef struct xfs_ioend {
54 xfs_off_t io_offset; /* offset in the file */ 53 xfs_off_t io_offset; /* offset in the file */
55 struct work_struct io_work; /* xfsdatad work queue */ 54 struct work_struct io_work; /* xfsdatad work queue */
56 struct xfs_trans *io_append_trans;/* xact. for size update */ 55 struct xfs_trans *io_append_trans;/* xact. for size update */
57 struct kiocb *io_iocb;
58 int io_result;
59} xfs_ioend_t; 56} xfs_ioend_t;
60 57
61extern const struct address_space_operations xfs_address_space_operations; 58extern const struct address_space_operations xfs_address_space_operations;
diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h
index 91fa9a94ae92..d77797a52b7b 100644
--- a/include/linux/buffer_head.h
+++ b/include/linux/buffer_head.h
@@ -36,6 +36,7 @@ enum bh_state_bits {
36 BH_Quiet, /* Buffer Error Prinks to be quiet */ 36 BH_Quiet, /* Buffer Error Prinks to be quiet */
37 BH_Meta, /* Buffer contains metadata */ 37 BH_Meta, /* Buffer contains metadata */
38 BH_Prio, /* Buffer should be submitted with REQ_PRIO */ 38 BH_Prio, /* Buffer should be submitted with REQ_PRIO */
39 BH_Defer_Completion, /* Defer AIO completion to workqueue */
39 40
40 BH_PrivateStart,/* not a state bit, but the first bit available 41 BH_PrivateStart,/* not a state bit, but the first bit available
41 * for private allocation by other entities 42 * for private allocation by other entities
@@ -128,6 +129,7 @@ BUFFER_FNS(Write_EIO, write_io_error)
128BUFFER_FNS(Unwritten, unwritten) 129BUFFER_FNS(Unwritten, unwritten)
129BUFFER_FNS(Meta, meta) 130BUFFER_FNS(Meta, meta)
130BUFFER_FNS(Prio, prio) 131BUFFER_FNS(Prio, prio)
132BUFFER_FNS(Defer_Completion, defer_completion)
131 133
132#define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK) 134#define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
133 135
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e7893523f81f..3b4cd8296e41 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -46,6 +46,7 @@ struct vfsmount;
46struct cred; 46struct cred;
47struct swap_info_struct; 47struct swap_info_struct;
48struct seq_file; 48struct seq_file;
49struct workqueue_struct;
49 50
50extern void __init inode_init(void); 51extern void __init inode_init(void);
51extern void __init inode_init_early(void); 52extern void __init inode_init_early(void);
@@ -63,8 +64,7 @@ struct buffer_head;
63typedef int (get_block_t)(struct inode *inode, sector_t iblock, 64typedef int (get_block_t)(struct inode *inode, sector_t iblock,
64 struct buffer_head *bh_result, int create); 65 struct buffer_head *bh_result, int create);
65typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset, 66typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
66 ssize_t bytes, void *private, int ret, 67 ssize_t bytes, void *private);
67 bool is_async);
68 68
69#define MAY_EXEC 0x00000001 69#define MAY_EXEC 0x00000001
70#define MAY_WRITE 0x00000002 70#define MAY_WRITE 0x00000002
@@ -1328,6 +1328,9 @@ struct super_block {
1328 1328
1329 /* Being remounted read-only */ 1329 /* Being remounted read-only */
1330 int s_readonly_remount; 1330 int s_readonly_remount;
1331
1332 /* AIO completions deferred from interrupt context */
1333 struct workqueue_struct *s_dio_done_wq;
1331}; 1334};
1332 1335
1333/* superblock cache pruning functions */ 1336/* superblock cache pruning functions */
@@ -1804,7 +1807,7 @@ enum file_time_flags {
1804 S_VERSION = 8, 1807 S_VERSION = 8,
1805}; 1808};
1806 1809
1807extern void touch_atime(struct path *); 1810extern void touch_atime(const struct path *);
1808static inline void file_accessed(struct file *file) 1811static inline void file_accessed(struct file *file)
1809{ 1812{
1810 if (!(file->f_flags & O_NOATIME)) 1813 if (!(file->f_flags & O_NOATIME))
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 5a5ff57ceed4..cd09751c71a0 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -58,6 +58,7 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
58 58
59extern int user_path_at(int, const char __user *, unsigned, struct path *); 59extern int user_path_at(int, const char __user *, unsigned, struct path *);
60extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty); 60extern int user_path_at_empty(int, const char __user *, unsigned, struct path *, int *empty);
61extern int user_path_umountat(int, const char __user *, unsigned int, struct path *);
61 62
62#define user_path(name, path) user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW, path) 63#define user_path(name, path) user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW, path)
63#define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path) 64#define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path)
diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
index a4c562453f6b..b2a0f15f11fe 100644
--- a/include/linux/oprofile.h
+++ b/include/linux/oprofile.h
@@ -42,7 +42,6 @@
42#define IBS_FETCH_CODE 13 42#define IBS_FETCH_CODE 13
43#define IBS_OP_CODE 14 43#define IBS_OP_CODE 14
44 44
45struct super_block;
46struct dentry; 45struct dentry;
47struct file_operations; 46struct file_operations;
48struct pt_regs; 47struct pt_regs;
@@ -51,7 +50,7 @@ struct pt_regs;
51struct oprofile_operations { 50struct oprofile_operations {
52 /* create any necessary configuration files in the oprofile fs. 51 /* create any necessary configuration files in the oprofile fs.
53 * Optional. */ 52 * Optional. */
54 int (*create_files)(struct super_block * sb, struct dentry * root); 53 int (*create_files)(struct dentry * root);
55 /* Do any necessary interrupt setup. Optional. */ 54 /* Do any necessary interrupt setup. Optional. */
56 int (*setup)(void); 55 int (*setup)(void);
57 /* Do any necessary interrupt shutdown. Optional. */ 56 /* Do any necessary interrupt shutdown. Optional. */
@@ -125,27 +124,26 @@ void oprofile_add_trace(unsigned long eip);
125 * Create a file of the given name as a child of the given root, with 124 * Create a file of the given name as a child of the given root, with
126 * the specified file operations. 125 * the specified file operations.
127 */ 126 */
128int oprofilefs_create_file(struct super_block * sb, struct dentry * root, 127int oprofilefs_create_file(struct dentry * root,
129 char const * name, const struct file_operations * fops); 128 char const * name, const struct file_operations * fops);
130 129
131int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root, 130int oprofilefs_create_file_perm(struct dentry * root,
132 char const * name, const struct file_operations * fops, int perm); 131 char const * name, const struct file_operations * fops, int perm);
133 132
134/** Create a file for read/write access to an unsigned long. */ 133/** Create a file for read/write access to an unsigned long. */
135int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root, 134int oprofilefs_create_ulong(struct dentry * root,
136 char const * name, ulong * val); 135 char const * name, ulong * val);
137 136
138/** Create a file for read-only access to an unsigned long. */ 137/** Create a file for read-only access to an unsigned long. */
139int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root, 138int oprofilefs_create_ro_ulong(struct dentry * root,
140 char const * name, ulong * val); 139 char const * name, ulong * val);
141 140
142/** Create a file for read-only access to an atomic_t. */ 141/** Create a file for read-only access to an atomic_t. */
143int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root, 142int oprofilefs_create_ro_atomic(struct dentry * root,
144 char const * name, atomic_t * val); 143 char const * name, atomic_t * val);
145 144
146/** create a directory */ 145/** create a directory */
147struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root, 146struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
148 char const * name);
149 147
150/** 148/**
151 * Write the given asciz string to the given user buffer @buf, updating *offset 149 * Write the given asciz string to the given user buffer @buf, updating *offset
diff --git a/kernel/module.c b/kernel/module.c
index 9f5ddae72f44..dc582749fa13 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2549,21 +2549,20 @@ static int copy_module_from_user(const void __user *umod, unsigned long len,
2549/* Sets info->hdr and info->len. */ 2549/* Sets info->hdr and info->len. */
2550static int copy_module_from_fd(int fd, struct load_info *info) 2550static int copy_module_from_fd(int fd, struct load_info *info)
2551{ 2551{
2552 struct file *file; 2552 struct fd f = fdget(fd);
2553 int err; 2553 int err;
2554 struct kstat stat; 2554 struct kstat stat;
2555 loff_t pos; 2555 loff_t pos;
2556 ssize_t bytes = 0; 2556 ssize_t bytes = 0;
2557 2557
2558 file = fget(fd); 2558 if (!f.file)
2559 if (!file)
2560 return -ENOEXEC; 2559 return -ENOEXEC;
2561 2560
2562 err = security_kernel_module_from_file(file); 2561 err = security_kernel_module_from_file(f.file);
2563 if (err) 2562 if (err)
2564 goto out; 2563 goto out;
2565 2564
2566 err = vfs_getattr(&file->f_path, &stat); 2565 err = vfs_getattr(&f.file->f_path, &stat);
2567 if (err) 2566 if (err)
2568 goto out; 2567 goto out;
2569 2568
@@ -2586,7 +2585,7 @@ static int copy_module_from_fd(int fd, struct load_info *info)
2586 2585
2587 pos = 0; 2586 pos = 0;
2588 while (pos < stat.size) { 2587 while (pos < stat.size) {
2589 bytes = kernel_read(file, pos, (char *)(info->hdr) + pos, 2588 bytes = kernel_read(f.file, pos, (char *)(info->hdr) + pos,
2590 stat.size - pos); 2589 stat.size - pos);
2591 if (bytes < 0) { 2590 if (bytes < 0) {
2592 vfree(info->hdr); 2591 vfree(info->hdr);
@@ -2600,7 +2599,7 @@ static int copy_module_from_fd(int fd, struct load_info *info)
2600 info->len = pos; 2599 info->len = pos;
2601 2600
2602out: 2601out:
2603 fput(file); 2602 fdput(f);
2604 return err; 2603 return err;
2605} 2604}
2606 2605
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 739a36366b79..26559bdb4c49 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -26,6 +26,7 @@
26#include <linux/math64.h> 26#include <linux/math64.h>
27#include <linux/uaccess.h> 27#include <linux/uaccess.h>
28#include <linux/ioport.h> 28#include <linux/ioport.h>
29#include <linux/dcache.h>
29#include <net/addrconf.h> 30#include <net/addrconf.h>
30 31
31#include <asm/page.h> /* for PAGE_SIZE */ 32#include <asm/page.h> /* for PAGE_SIZE */
@@ -532,6 +533,81 @@ char *string(char *buf, char *end, const char *s, struct printf_spec spec)
532 return buf; 533 return buf;
533} 534}
534 535
536static void widen(char *buf, char *end, unsigned len, unsigned spaces)
537{
538 size_t size;
539 if (buf >= end) /* nowhere to put anything */
540 return;
541 size = end - buf;
542 if (size <= spaces) {
543 memset(buf, ' ', size);
544 return;
545 }
546 if (len) {
547 if (len > size - spaces)
548 len = size - spaces;
549 memmove(buf + spaces, buf, len);
550 }
551 memset(buf, ' ', spaces);
552}
553
554static noinline_for_stack
555char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_spec spec,
556 const char *fmt)
557{
558 const char *array[4], *s;
559 const struct dentry *p;
560 int depth;
561 int i, n;
562
563 switch (fmt[1]) {
564 case '2': case '3': case '4':
565 depth = fmt[1] - '0';
566 break;
567 default:
568 depth = 1;
569 }
570
571 rcu_read_lock();
572 for (i = 0; i < depth; i++, d = p) {
573 p = ACCESS_ONCE(d->d_parent);
574 array[i] = ACCESS_ONCE(d->d_name.name);
575 if (p == d) {
576 if (i)
577 array[i] = "";
578 i++;
579 break;
580 }
581 }
582 s = array[--i];
583 for (n = 0; n != spec.precision; n++, buf++) {
584 char c = *s++;
585 if (!c) {
586 if (!i)
587 break;
588 c = '/';
589 s = array[--i];
590 }
591 if (buf < end)
592 *buf = c;
593 }
594 rcu_read_unlock();
595 if (n < spec.field_width) {
596 /* we want to pad the sucker */
597 unsigned spaces = spec.field_width - n;
598 if (!(spec.flags & LEFT)) {
599 widen(buf - n, end, n, spaces);
600 return buf + spaces;
601 }
602 while (spaces--) {
603 if (buf < end)
604 *buf = ' ';
605 ++buf;
606 }
607 }
608 return buf;
609}
610
535static noinline_for_stack 611static noinline_for_stack
536char *symbol_string(char *buf, char *end, void *ptr, 612char *symbol_string(char *buf, char *end, void *ptr,
537 struct printf_spec spec, const char *fmt) 613 struct printf_spec spec, const char *fmt)
@@ -1253,6 +1329,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1253 spec.base = 16; 1329 spec.base = 16;
1254 return number(buf, end, 1330 return number(buf, end,
1255 (unsigned long long) *((phys_addr_t *)ptr), spec); 1331 (unsigned long long) *((phys_addr_t *)ptr), spec);
1332 case 'd':
1333 return dentry_name(buf, end, ptr, spec, fmt);
1334 case 'D':
1335 return dentry_name(buf, end,
1336 ((const struct file *)ptr)->f_path.dentry,
1337 spec, fmt);
1256 } 1338 }
1257 spec.flags |= SMALL; 1339 spec.flags |= SMALL;
1258 if (spec.field_width == -1) { 1340 if (spec.field_width == -1) {
diff --git a/mm/filemap.c b/mm/filemap.c
index 4b51ac1acae7..731a2c24532d 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2550,7 +2550,7 @@ ssize_t generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
2550 ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos); 2550 ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos);
2551 mutex_unlock(&inode->i_mutex); 2551 mutex_unlock(&inode->i_mutex);
2552 2552
2553 if (ret > 0 || ret == -EIOCBQUEUED) { 2553 if (ret > 0) {
2554 ssize_t err; 2554 ssize_t err;
2555 2555
2556 err = generic_write_sync(file, pos, ret); 2556 err = generic_write_sync(file, pos, ret);
diff --git a/mm/shmem.c b/mm/shmem.c
index e43dc555069d..526149846d0a 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2615,13 +2615,15 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
2615 * tmpfs instance, limiting inodes to one per page of lowmem; 2615 * tmpfs instance, limiting inodes to one per page of lowmem;
2616 * but the internal instance is left unlimited. 2616 * but the internal instance is left unlimited.
2617 */ 2617 */
2618 if (!(sb->s_flags & MS_NOUSER)) { 2618 if (!(sb->s_flags & MS_KERNMOUNT)) {
2619 sbinfo->max_blocks = shmem_default_max_blocks(); 2619 sbinfo->max_blocks = shmem_default_max_blocks();
2620 sbinfo->max_inodes = shmem_default_max_inodes(); 2620 sbinfo->max_inodes = shmem_default_max_inodes();
2621 if (shmem_parse_options(data, sbinfo, false)) { 2621 if (shmem_parse_options(data, sbinfo, false)) {
2622 err = -EINVAL; 2622 err = -EINVAL;
2623 goto failed; 2623 goto failed;
2624 } 2624 }
2625 } else {
2626 sb->s_flags |= MS_NOUSER;
2625 } 2627 }
2626 sb->s_export_op = &shmem_export_ops; 2628 sb->s_export_op = &shmem_export_ops;
2627 sb->s_flags |= MS_NOSEC; 2629 sb->s_flags |= MS_NOSEC;
@@ -2831,8 +2833,7 @@ int __init shmem_init(void)
2831 goto out2; 2833 goto out2;
2832 } 2834 }
2833 2835
2834 shm_mnt = vfs_kern_mount(&shmem_fs_type, MS_NOUSER, 2836 shm_mnt = kern_mount(&shmem_fs_type);
2835 shmem_fs_type.name, NULL);
2836 if (IS_ERR(shm_mnt)) { 2837 if (IS_ERR(shm_mnt)) {
2837 error = PTR_ERR(shm_mnt); 2838 error = PTR_ERR(shm_mnt);
2838 printk(KERN_ERR "Could not kern_mount tmpfs\n"); 2839 printk(KERN_ERR "Could not kern_mount tmpfs\n");
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index 1550637d1b10..abe4d6043b36 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -291,7 +291,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
291{ 291{
292 struct kvm_irq_routing_table *irq_rt; 292 struct kvm_irq_routing_table *irq_rt;
293 struct _irqfd *irqfd, *tmp; 293 struct _irqfd *irqfd, *tmp;
294 struct file *file = NULL; 294 struct fd f;
295 struct eventfd_ctx *eventfd = NULL, *resamplefd = NULL; 295 struct eventfd_ctx *eventfd = NULL, *resamplefd = NULL;
296 int ret; 296 int ret;
297 unsigned int events; 297 unsigned int events;
@@ -306,13 +306,13 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
306 INIT_WORK(&irqfd->inject, irqfd_inject); 306 INIT_WORK(&irqfd->inject, irqfd_inject);
307 INIT_WORK(&irqfd->shutdown, irqfd_shutdown); 307 INIT_WORK(&irqfd->shutdown, irqfd_shutdown);
308 308
309 file = eventfd_fget(args->fd); 309 f = fdget(args->fd);
310 if (IS_ERR(file)) { 310 if (!f.file) {
311 ret = PTR_ERR(file); 311 ret = -EBADF;
312 goto fail; 312 goto out;
313 } 313 }
314 314
315 eventfd = eventfd_ctx_fileget(file); 315 eventfd = eventfd_ctx_fileget(f.file);
316 if (IS_ERR(eventfd)) { 316 if (IS_ERR(eventfd)) {
317 ret = PTR_ERR(eventfd); 317 ret = PTR_ERR(eventfd);
318 goto fail; 318 goto fail;
@@ -391,7 +391,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
391 lockdep_is_held(&kvm->irqfds.lock)); 391 lockdep_is_held(&kvm->irqfds.lock));
392 irqfd_update(kvm, irqfd, irq_rt); 392 irqfd_update(kvm, irqfd, irq_rt);
393 393
394 events = file->f_op->poll(file, &irqfd->pt); 394 events = f.file->f_op->poll(f.file, &irqfd->pt);
395 395
396 list_add_tail(&irqfd->list, &kvm->irqfds.items); 396 list_add_tail(&irqfd->list, &kvm->irqfds.items);
397 397
@@ -408,7 +408,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
408 * do not drop the file until the irqfd is fully initialized, otherwise 408 * do not drop the file until the irqfd is fully initialized, otherwise
409 * we might race against the POLLHUP 409 * we might race against the POLLHUP
410 */ 410 */
411 fput(file); 411 fdput(f);
412 412
413 return 0; 413 return 0;
414 414
@@ -422,9 +422,9 @@ fail:
422 if (eventfd && !IS_ERR(eventfd)) 422 if (eventfd && !IS_ERR(eventfd))
423 eventfd_ctx_put(eventfd); 423 eventfd_ctx_put(eventfd);
424 424
425 if (!IS_ERR(file)) 425 fdput(f);
426 fput(file);
427 426
427out:
428 kfree(irqfd); 428 kfree(irqfd);
429 return ret; 429 return ret;
430} 430}